function mudacor(ref,cor)
{
  ref.style.backgroundColor=cor;
}

function tirarBorda(nome_campo)
{
	document.getElementById(nome_campo).style.border="solid 1px #ccc";
}

function tirarDivNome(nome_div)
{
	var doc = document.frmContato;
	if(doc.nome.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function tirarDivEmail(nome_div)
{
	var doc = document.frmContato;
	
	if(doc.email.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function tirarDivDDD(nome_div)
{
	var doc = document.frmContato;

	if(doc.ddd.value.length == 2)
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function tirarDivTelefone(nome_div)
{
	var doc = document.frmContato;

	if(doc.telefone.value.length == 8)
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function tirarDivEmpresa(nome_div)
{
	var doc = document.frmContato;

	if(doc.empresa.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function avaliaContato()
{
	var doc = document.frmContato;
	var ddd = 2;
	var telefone = 8

	if(doc.nome.value == "")
	{
		doc.nome.focus();
		//var div = document.getElementById("erro");
		//div.innerHTML = "Informe o nome de contato";
		document.getElementById("nome").style.border='solid 2px #ff0000';
		document.getElementById("nome").style.background='#f1f1f1';
		return false;
	}

	if(!validaEmail(doc.email.value))
	{
		doc.email.focus();
		//var div = document.getElementById("erro2");
		//div.innerHTML = "E-Mail inv&aacute;lido";
		document.getElementById("email").style.border='solid 2px #ff0000';
		document.getElementById("email").style.background='#f1f1f1';
		return false;
	}

	if(doc.ddd.value.length < ddd)
	{
		doc.ddd.focus();
		//var div = document.getElementById("erro3");
		//div.innerHTML = "Informe o DDD da sua regi&atilde;o";
		document.getElementById("ddd").style.border='solid 2px #ff0000';
		document.getElementById("ddd").style.background='#f1f1f1';
		return false;
	}

	if(doc.telefone.value.length < telefone)
	{
		doc.telefone.focus();
		//var div = document.getElementById("erro4");
		//div.innerHTML = "Informe o telefone";
		document.getElementById("telefone").style.border='solid 2px #ff0000';
		document.getElementById("telefone").style.background='#f1f1f1';
		return false;
	}
	
	if(doc.empresa.value == "")
	{
		doc.empresa.focus();
		//var div = document.getElementById("erro5");
		//div.innerHTML = "Informe a empresa";
		document.getElementById("empresa").style.border='solid 2px #ff0000';
		document.getElementById("empresa").style.background='#f1f1f1';
		return false;
	}
}

function avaliaLogin()
{
	var doc = document.frmLogin;
	
	if(!validaEmail(doc.email.value))
	{
		alert("Informe o e-mail corretamente");
		doc.email.focus();
		document.getElementById("email").style.border='solid 2px #ff0000';
		document.getElementById("email").style.background='#f1f1f1';
		return false;
	}

	if(doc.senha.value == "")
	{
		alert("Informe a senha");
		doc.senha.focus();
		document.getElementById("senha").style.border='solid 2px #ff0000';
		document.getElementById("senha").style.background='#f1f1f1';
		return false;
	}
}

function enviar_carrinho(opcao, prod)
{
	//OPÇAO EXCLUIR SELECIONADA
	if(opcao == "E")
	{
		document.frmCarrinho.op.value = "excluir";
		document.frmCarrinho.action = "loja_carrinho.php";
		document.frmCarrinho.submit();
	}//FECHA IF
	
	//OPÇAO ATUALIZAR SELECIONADA
	if(opcao == "A")
	{
		document.frmCarrinho.op.value = "atualizar";
		document.frmCarrinho.action = "loja_carrinho.php";
		document.frmCarrinho.submit();
	}//FECHA IF
	
	//OPÇAO FINALIZAR SELECIONADA
	if(opcao == "F")
	{
		document.frmCarrinho.op.value = "finalizar";
		document.frmCarrinho.action = "loja_carrinho_final.php";
		document.frmCarrinho.submit();
	}//FECHA IF
  
}//FECHA FUNCTION

function printWindow()
{
   bV = parseInt(navigator.appVersion);
   
   if (bV >= 4)
   { 
	   window.print();
   }
}

function Numero(par_tecla)
{
     var var_tecla = par_tecla.keyCode ? par_tecla.keyCode : par_tecla.which;
     
	 /* Tecla Backspace */
     if (var_tecla == 8)
          {return true;}

	 /* Tecla Tab */
     if (var_tecla == 9)
          {return true;}

	 /* Tecla Left */
     if (var_tecla == 37)
          {return true;}

	 /* Tecla Right */
     if (var_tecla == 39)
          {return true;}

	 /* Tecla Delete */

     if (var_tecla == 46)
          {return true;}

	 /* Teclas Numéricas */
     if (var_tecla > 47 && var_tecla < 58) 
          {return true;}

     return false;
}

function somente_txt(par_tecla)
{
     var var_tecla = par_tecla.keyCode ? par_tecla.keyCode : par_tecla.which;

     /* Tecla Backspace */
     if (var_tecla == 8)
          {return true;}

	 /* Tecla Tab */
     if (var_tecla == 9)

          {return true;}

	 /* Tecla Space */
     if (var_tecla == 32)
          {return true;}

     /* Tecla Left */
     if (var_tecla == 37)
          {return true;}

	 /* Tecla Right */
     if (var_tecla == 39)
          {return true;}

	 /* Tecla Delete */
     if (var_tecla == 46)
          {return true;}

     /* Teclas a-z e A-Z */
     if ((var_tecla > 64 && var_tecla < 91) || (var_tecla > 96 && var_tecla < 123))
          {return true;}

     /* Teclas acentuadas e cidilha */
     if ((var_tecla > 191 && var_tecla < 221) || (var_tecla > 223 && var_tecla < 253))
          {return true;}
          
     return false;
}

function clearDefault(el) 
{
  if (el.defaultValue==el.value) el.value = ""
}

function Limpar(valor, validos) 
{
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++)
	{
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0)
		{
			result += aux;
		}
	}
	return result;
}

function Formata(campo,tammax,teclapres,decimal) 
{
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal
	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
	
	if (tecla == 8 ){ tam = tam - 1 ; }
	
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
	{
		if ( tam <= dec ){ campo.value = vr ; }
		if ( (tam > dec) && (tam <= 5) ){
		campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 6) && (tam <= 8) ){
		campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 9) && (tam <= 11) ){
		campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 12) && (tam <= 14) ){
		campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 15) && (tam <= 17) ){
		campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ; }
	} 
}

function FormataCEP(evt) 
{
	vr = (navigator.appName == 'Netscape') ?evt.target.value : evt.srcElement.value;
	if(vr.length == 5) vr = vr+"-";
	return vr;
}

function FormataTEL(evt) 
{
	vr = (navigator.appName == 'Netscape') ?evt.target.value : evt.srcElement.value;
	if(vr.length == 4) vr = vr+"-";
	return vr;
}

function validaCPF(s)
{
	var i;
	
	//s = limpa_string(s);
	if (s.length != 11) {
		return false;
	}

	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;

	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(10-i);
	}

        if (d1 == 0) return false;

	d1 = 11 - (d1 % 11);

	if (d1 > 9) d1 = 0;

	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++)
	{

		d1 += c.charAt(i)*(11-i);

	}

	d1 = 11 - (d1 % 11);

	if (d1 > 9) d1 = 0;

	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}



function FormataDATA(evt) 
{
	vr = (navigator.appName == 'Netscape') ?evt.target.value : evt.srcElement.value;
	if(vr.length == 2) vr = vr+"/";
	if(vr.length == 5) vr = vr+"/";
	return vr;
}

function validaEmail(mailField){

	var re = new RegExp;
	re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var arr = re.exec(mailField);
	if (arr == null){
		return false
	}
	else{
		return true
	}
}

//Limita caracteres em text area 
function Caracteres(objeto)
{
        var limite = 500;
        tamanho = objeto.value.length;

        if (tamanho>limite) {
  objeto.value = objeto.value.substring(0,limite);
  alert(erro);
        } else {
  document.getElementById('restantes').innerHTML = (limite-objeto.value.length);
        }
}

function changeFormCliente(tipo)
{
	if(tipo == "0")
	{
		document.getElementById("tb_fisica").style.display = "block";
		document.getElementById("tb_juridica").style.display = "none";
	}
	else if(tipo == "1")
	{
		document.getElementById("tb_fisica").style.display = "block";
		document.getElementById("tb_juridica").style.display = "block";
	}
	else
	{
		alert("Tipo Incorreto");
	}
}

/****************** mostra conteudo ************************************/



var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)

var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)



var contractsymbol='[-] ' //HTML for contract symbol. For image, use: <img src="whatever.gif">

var expandsymbol='[+] ' //HTML for expand symbol.





if (document.getElementById){

document.write('<style type="text/css">')

document.write('.switchcontent{display:none;}')

document.write('</style>')

}



function getElementbyClass(rootobj, classname){

var temparray=new Array()

var inc=0

var rootlength=rootobj.length

for (i=0; i<rootlength; i++){

if (rootobj[i].className==classname)

temparray[inc++]=rootobj[i]

}

return temparray

}



function sweeptoggle(ec){

var thestate=(ec=="expand")? "block" : "none"

var inc=0

while (ccollect[inc]){

ccollect[inc].style.display=thestate

inc++

}

revivestatus()

}





function contractcontent(omit){

var inc=0

while (ccollect[inc]){

if (ccollect[inc].id!=omit)

ccollect[inc].style.display="none"

inc++

}

}



function expandcontent(curobj, cid){

var spantags=curobj.getElementsByTagName("SPAN")

var showstateobj=getElementbyClass(spantags, "showstate")

if (ccollect.length>0){

if (collapseprevious=="yes")

contractcontent(cid)

document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"

if (showstateobj.length>0){ //if "showstate" span exists in header

if (collapseprevious=="no")

showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol

else

revivestatus()

}

}

}



function revivecontent(){

contractcontent("omitnothing")

selectedItem=getselectedItem()

selectedComponents=selectedItem.split("|")

for (i=0; i<selectedComponents.length-1; i++)

document.getElementById(selectedComponents[i]).style.display="block"

}



function revivestatus(){

var inc=0

while (statecollect[inc]){

if (ccollect[inc].style.display=="block")

statecollect[inc].innerHTML=contractsymbol

else

statecollect[inc].innerHTML=expandsymbol

inc++

}

}



function get_cookie(Name) { 

var search = Name + "="

var returnvalue = "";

if (document.cookie.length > 0) {

offset = document.cookie.indexOf(search)

if (offset != -1) { 

offset += search.length

end = document.cookie.indexOf(";", offset);

if (end == -1) end = document.cookie.length;

returnvalue=unescape(document.cookie.substring(offset, end))

}

}

return returnvalue;

}



function getselectedItem(){

if (get_cookie(window.location.pathname) != ""){

selectedItem=get_cookie(window.location.pathname)

return selectedItem

}

else

return ""

}



function saveswitchstate(){

var inc=0, selectedItem=""

while (ccollect[inc]){

if (ccollect[inc].style.display=="block")

selectedItem+=ccollect[inc].id+"|"

inc++

}



document.cookie=window.location.pathname+"="+selectedItem

}



function do_onload(){

uniqueidn=window.location.pathname+"firsttimeload"

var alltags=document.all? document.all : document.getElementsByTagName("*")

ccollect=getElementbyClass(alltags, "switchcontent")

statecollect=getElementbyClass(alltags, "showstate")

if (enablepersist=="on" && ccollect.length>0){

document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 

firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load

if (!firsttimeload)

revivecontent()

}

if (ccollect.length>0 && statecollect.length>0)

revivestatus()

}



if (window.addEventListener)

window.addEventListener("load", do_onload, false)

else if (window.attachEvent)

window.attachEvent("onload", do_onload)

else if (document.getElementById)

window.onload=do_onload



if (enablepersist=="on" && document.getElementById)

window.onunload=saveswitchstate


