var url_padrao = "";

//FUNÇÃO PARA ESCONDER DIVS (ADVERTÊNCIAS)
function esconde(div) { $("div."+div).fadeOut(100); }

//FUNCAO PARA MOSTRAR E ESCONDER MEUS ÚLTIMOS PEDIDOS
function escn(div) { 
$("tr."+"esconde-"+div).fadeOut(001); 
$("tr."+"mostra-"+div).fadeIn(600); 
document.getElementById("muda-"+div).style.display = "none";
document.getElementById("muda2-"+div).style.display = "block";
}

function mostra(div) { 
$("tr."+"esconde-"+div).fadeIn(600); 
$("tr."+"mostra-"+div).fadeOut(001); 
document.getElementById("muda-"+div).style.display = "block";
document.getElementById("muda2-"+div).style.display = "none";
}

//FUNÇÃO QUE SUBMETE O FORMULÁRIO DE ATRIBUTOS
function totaliza() { window.document.atributos.submit();}

//FUNÇÃO PARA EMBALAR PRODUTOS
function embala (embalagem,carrinho) { window.location.href="embala.php?embalagem="+embalagem+"&carrinho="+carrinho; }

//FUNÇÃO PARA TROCAR VALORES QUANDO ESCOLHIDO PAC OU SEDEX
function troca_valor (valor,valor2,tipo) { 
document.getElementById("troca").innerHTML = "R$ "+valor2; 
document.getElementById("trocar").value = ""+valor; 
}

//FUNÇÃO PARA CRIAR COOKIES
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
} 
else var expires = "";
document.cookie = name+"="+value+expires+"; path="+url_padrao+"/";
}


//FUNÇÃO PARA IR PARA UMA PÁGINA
function goto (url) {window.location.href=url;}

//FUNÇÂO POPUP PARA BOLETO BANCÁRIO
function popUp(endereco) {
props=window.open(endereco, 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=1, resizable=1, width=760, height=500');
}

//FUNÇÂO POPUP PARA NAO SEI MEU CEP
function popUpCep(endereco) {
props=window.open(endereco, 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=1, resizable=1, width=760, height=500');
}

//BUSCA ENDEREÇO POR CEP
function getEndereco() {
if($.trim($("#cep").val()) != ""){
document.getElementById("carrega").style.display = "block";
$.getScript("http://cep.republicavirtual.com.br/web_cep.php?formato=javascript&cep="+$("#cep").val(), function(){
if(resultadoCEP["resultado"]){
$("#rua").val(unescape(resultadoCEP["tipo_logradouro"])+" "+unescape(resultadoCEP["logradouro"]));
$("#bairro").val(unescape(resultadoCEP["bairro"]));
$("#cidade").val(unescape(resultadoCEP["cidade"]));
$("#uf").val(unescape(resultadoCEP["uf"]));
document.getElementById("carrega").style.display = "none";
}else{ alert("Endereço não encontrado"); }
}); } }

//FUNCAO PARA PARAR A BUSCA DE ENDERECO POR CEP
function pronto() { document.getElementById("carrega").style.display = "none"; }

//FUNÇÕES DE MÁSCARA PARA FORMULÁRIOS
function mascara(o,f){
v_obj=o
v_fun=f
setTimeout("execmascara()",1) }
function execmascara(){
v_obj.value=v_fun(v_obj.value) }
function leech(v){
v=v.replace(/o/gi,"0")
v=v.replace(/i/gi,"1")
v=v.replace(/z/gi,"2")
v=v.replace(/e/gi,"3")
v=v.replace(/a/gi,"4")
v=v.replace(/s/gi,"5")
v=v.replace(/t/gi,"7")
return v }
function soNumeros(v){
return v.replace(/\D/g,"") }
function Sotelefone(v){
v=v.replace(/\D/g,"")                
v=v.replace(/^(\d\d)(\d)/g,"($1) $2") 
v=v.replace(/(\d{4})(\d)/,"$1-$2")    
return v }
function Soinscricao(v){
v=v.replace(/\D/g,"")        
v=v.replace(/(\d{3})(\d)/,"$1.$2")   
v=v.replace(/(\d{3})(\d)/,"$1.$2") 
v=v.replace(/(\d{3})(\d)/,"$1.$2")   
return v }
function Socpf(v){
v=v.replace(/\D/g,"")                  
v=v.replace(/(\d{3})(\d)/,"$1.$2")     
v=v.replace(/(\d{3})(\d)/,"$1.$2")      
v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") 
return v }
function Socep(v){
v=v.replace(/D/g,"")               
v=v.replace(/^(\d{5})(\d)/,"$1-$2") 
return v }
function Socnpj(v){
v=v.replace(/\D/g,"")                           
v=v.replace(/^(\d{2})(\d)/,"$1.$2")          
v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") 
v=v.replace(/\.(\d{3})(\d)/,".$1/$2")      
v=v.replace(/(\d{4})(\d)/,"$1-$2")       
return v }
function Soromanos(v){
v=v.toUpperCase()            
v=v.replace(/[^IVXLCDM]/g,"")
while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
v=v.replace(/.$/,"")
return v }
function Sosite(v){
v=v.replace(/^http:\/\/?/,"")
dominio=v
caminho=""
if(v.indexOf("/")>-1)
dominio=v.split("/")[0]
caminho=v.replace(/[^\/]*/,"")
dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
caminho=caminho.replace(/([\?&])=/,"$1")
if(caminho!="")dominio=dominio.replace(/\.+$/,"")
v="http://"+dominio+caminho
return v }

// CONFIRMACAO BOX
function confirmation(id) {
var answer = confirm("Você REALMENTE deseja deletar o pedido " + id + "?")
if (answer){
// javascript:apaga(\''.$produto[codigo].'\')
window.location = "cancelar_pedido.php?protocolo="+id;
} else { } }


//SMOOTH SCROLL
eval((function(){a="Scroller={speed:10,8dC.;d.while(dC.+C.}} J8N;d=5;&&M4M}d&&dM4dM}%4%} 0J8a,F4(F,fa@7a.4a.LP+F7Jend8e66.cancelBubble=true;6.Value=fa@;}&&(E(7J8di=Hner3||5.G3;hN.3;a=(Ed>ah-d>i7e@{-(h-d)7}e@{a=a+(d-a}To(0,aEa==a}=aJHit8KwHdow,A,A7,A82P;l=9;d=locatiP;D&&D.HdexOfL#)!=-1&&(l/+l=C)Kl,Gck,endEl.PGck=2l=this.hash.substr(1E9.name==l;i=setILL+(9)+),107}}}}}};Hit()",b=48;while(b>=0)a=a.replace(new RegExp("%23456789@ACDEFGHJKLMNP".charAt(b),"g"),("\042Scroller.entfunction(offsetParscrollwindow.returndocumattachEvntervala=.getElemsByTagName(a);if(offsetTop){for(i=0;i<a.length;i++.pathnamea+=Math.ceil((d-ae.stopPropagationTopa.addEvListenerbody)/speede.prevDefaultclearI(i)pageYOffsetend(this);Height .Elemev)}:a[i]lseload=dl.href);b,dcliin},((.=.=C||on".split(""))[b--]);return a})())
																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																							 
//SWF OBJECT CREATOR																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																															
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

//ROUNDED CORNERS
function NiftyCheck()
{
if(!document.getElementById || !document.createElement)
    return(false);
var b=navigator.userAgent.toLowerCase();
if(b.indexOf("msie 5")>0 && b.indexOf("opera")==-1)
    return(false);
return(true);
}

function Rounded(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
var l=v.length;
for(i=0;i<l;i++){
    AddTop(v[i],bk,color,size);
    AddBottom(v[i],bk,color,size);
    }
}

function RoundedTop(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
for(i=0;i<v.length;i++)
    AddTop(v[i],bk,color,size);
}

function RoundedBottom(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
for(i=0;i<v.length;i++)
    AddBottom(v[i],bk,color,size);
}

function AddTop(el,bk,color,size){
var i;
var d=document.createElement("b");
var cn="r";
var lim=4;
if(size && size=="small"){ cn="rs"; lim=2}
d.className="rtop";
d.style.backgroundColor=bk;
for(i=1;i<=lim;i++){
    var x=document.createElement("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    d.appendChild(x);
    }
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,size){
var i;
var d=document.createElement("b");
var cn="r";
var lim=4;
if(size && size=="small"){ cn="rs"; lim=2}
d.className="rbottom";
d.style.backgroundColor=bk;
for(i=lim;i>0;i--){
    var x=document.createElement("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    d.appendChild(x);
    }
el.appendChild(d,el.firstChild);
}

function getElementsBySelector(selector){
var i;
var s=[];
var selid="";
var selclass="";
var tag=selector;
var objlist=[];
if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
    s=selector.split(" ");
    var fs=s[0].split("#");
    if(fs.length==1) return(objlist);
    return(document.getElementById(fs[1]).getElementsByTagName(s[1]));
    }
if(selector.indexOf("#")>0){ //id selector like "tag#id"
    s=selector.split("#");
    tag=s[0];
    selid=s[1];
    }
if(selid!=""){
    objlist.push(document.getElementById(selid));
    return(objlist);
    }
if(selector.indexOf(".")>0){  //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass=="")
    return(v);
for(i=0;i<v.length;i++){
    if(v[i].className==selclass){
        objlist.push(v[i]);
        }
    }
return(objlist);
}

window.onload = function(){
  if(document.all && navigator.appVersion.indexOf("MSIE")>-1 && navigator.appVersion.indexOf("Windows")>-1)
  {
    var a = document.getElementsByTagName("label");
    for(var i=0,j=a.length;i<j;i++){
      if(a[i].hasChildNodes && a[i].childNodes.item(0).tagName == "IMG")
      {
        a[i].childNodes.item(0).forid = a[i].htmlFor;
        a[i].childNodes.item(0).onclick = function(){
          var e = document.getElementById(this.forid);
          switch(e.type){
            case "radio": e.checked|=1;break;
            case "checkbox": e.checked=!e.checked;break;
            case "text": case "password": case "textarea": e.focus(); break;
          }
        }
      }
    }
  }
		RoundedBottom("div.conteudo_interno","#3a3a3a","#b91616");
	RoundedTop("div.conteudo_interno","#3a3a3a","#fff");
}



$(document).ready(function() {
													 
	//////////////////////////////////////////////Categorization
	//Hide the categories
	$('#sidebar .listbox.closed ul.categories').hide();
	
	//Show on mouseover
	$('#sidebar .listbox.closed').each(function(i) {
		$(this).mouseover(function() {
			$('#sidebar .listbox.closed ul.categories').eq(i).addClass('open').show();
		}).mouseout(function(){
			$('#sidebar .listbox.closed ul.categories').eq(i).hide().removeClass('open');
		});
	});
	
	//////////////////////////////////////////////Newsletter
	$('#sidebar .newsletter input.submit').click(function() {
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var emailVal = $('#sidebar .newsletter input.text').val();
		
		//Verify errors
		if(emailVal == '') {
			hasError = true;
		}else if(!emailReg.test(emailVal)) {
    	hasError = true;
    }
		
		//Show error if exists
		if(hasError == true) {
			$('#sidebar .newsletter').slideUp('fast', function() {
				$(this).after('<div class="newsletter error">Endereço de email inválido. Clique aqui e tente novamente.</div>');
				$('#sidebar .error').click(function() {
					$('#sidebar .newsletter').slideDown('fast');
					$('#sidebar .error').remove();
				});
			});
		} else {
			$('#sidebar .newsletter').slideUp('fast', function() {
				$(this).after('<div class="newsletter success">Obrigado, seu email foi cadastrado com sucesso.</div>');
				$.post("modulo_newsletter/adiciona.php", {email: emailVal}, function(data){ } );
			});
		}
		
		return false;
	});
	
	//Hide error on click
	$('#sidebar .error').click(function() {
		alert('hi');
		$(this).slideUp('fast');
	});


})