
function calltimestamp()  
 {  
     stamp = new Date();  
     var sours;  
        var time;  
     hours = stamp.getHours();  
       
     if (hours >= 18 && hours < 24) {  
         time = " Boa Noite, ";  
     }  
       
     if (hours >= 12 && hours <18) {  
         time = " Boa Tarde, ";  
     }  
       
     if (hours >= 0 && hours <12) {  
         time = " Bom Dia, ";  
     }  
       
     document.write(time);  
 }

function RetornaProtocolo(url){
   if (location.protocol != "https:"){
	   window.location.href = url; 
   }
}


/* $(document).ready(function(){ 
   $('#menu').find('ul:eq(0)> li > span').hover(function(){ 
     $(this).parent().find('ul:eq(0)').slideDown("slow");
      });
      });  
*/ 

/* Funcoes para URL amigáveis - Menu's Busca */

function GoAjax(cod){
   if (cod == 1){
       e = document.getElementById("ErrorInfo");
       e.style.cssText = "";
	   return; 
   }
   if (cod == 2){
       e = document.getElementById("ErrorInfo");
       e.style.cssText = "display:none";
	   return; 
   }
   
   e = document.getElementById("ErrorInfo");
   e.style.cssText = "";
   e.className = "CartMarket1";
   e.innerHTML = "<img src='https://ssl2033.websiteseguro.com/percar/img/loadings/b_loading.gif' />"+" "+" carregando...";
}



function validaInner()
{
   var nome = document.getElementById("pesquisa").value;	
   var categoria = document.getElementById("categoria").value;

   if ((nome == "") && (categoria == "todas"))
   {
	   //document.getElementById("geral").innerHTML = "&nbsp;Por favor, digite o nome do produto que voce deseja procurar."+"<br>"+"&nbsp"+"<br>";
	   alert("Por favor, digite o nome do produto que voce deseja procurar.");
	   document.getElementById("pesquisa").focus();
	   return false;
   }

   if ((nome == ""))
   {
	   //document.getElementById("geral").innerHTML = "&nbsp;Por favor, digite o nome do produto que voce deseja procurar."+"<br>";
	   alert("Por favor, digite o nome do produto que voce deseja procurar.");
	   document.getElementById("pesquisa").focus();
	   return false;
   }
}


function validaNoInner()
{
   var nome = document.getElementById("pesquisa").value;	
   var categoria = document.getElementById("categoria").value;

   if ((nome == "") && (categoria == "todas"))
   {
	   alert("Por favor, digite o nome do produto que voce deseja procurar.");
	   document.getElementById("pesquisa").focus();
	   return false;
   }

   if ((nome == ""))
   {
	   alert("Por favor, digite o nome do produto que voce deseja procurar.");
	   document.getElementById("pesquisa").focus();
	   return false;
   }
}

function ChangeSubject()
{
	var subj = document.getElementById("SLAssunto").value;
    switch (subj)
	{
		  case "info_geral" : document.getElementById("hsubject").value = "Informações Gerais";
		  break;
		  
  		  case "info_comercial" : document.getElementById("hsubject").value = "Informações Comerciais";
		  break;

  		  case "info_produto" : document.getElementById("hsubject").value = "Informações Sobre Produtos";
		  break;

  		  case "sugestao" : document.getElementById("hsubject").value = "Sugestões";
		  break;

  		  case "reclamacao" : document.getElementById("hsubject").value = "Reclamação";
		  break;

	}
}

// funcao que faz contagem de caracteres ... 
function Conta(){
   intCaracteres = 800 - document.getElementById("mensagem").value.length;
   if (intCaracteres > 0) {
      document.getElementById("caracter").value = intCaracteres;
      return true;
   }
   else {
      document.getElementById("caracter").value = 0;
      document.getElementById("mensagem").value = document.getElementById("mensagem").value.substr(0,800)
      return false;
   }
}



/*********************************************************************************************************************************
                                           FUNÇÕES PARA MANIPULAR O CADASTRO DO CLIENTE
*********************************************************************************************************************************/


//funcao para disparar o cadastro do cliente
function SubmitCad(cod){
	 if (cod == 1){
			 window.location.href = "#ErrorInfo";
			 var error = false;
	         var e = document.getElementById("ErrorInfo");
			 var etipo = document.getElementById("tipo_pessoa");
   		     e.style.cssText = ""; 
			 e.className = "CartMarket1";
			 e.innerHTML = "<img src='https://ssl2033.websiteseguro.com/percar/img/loadings/b_loading.gif' />"+" "+" carregando...";

         if (etipo.value == 'PF'){//pessoa fisica
              if (document.getElementById("edtNomeCli").value == ""){
				  document.getElementById("edtNomeCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("edtSobreNomeCli").value == ""){
				  document.getElementById("edtSobreNomeCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("edtCPFCli").value == ""){
				  document.getElementById("edtCPFCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("edtDiaDtCli").value == ""){
				  document.getElementById("edtDiaDtCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("edtMesDtCli").value == ""){
				  document.getElementById("edtMesDtCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("edtAnoDtCli").value == ""){
				  document.getElementById("edtAnoDtCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("SlSexo").value == ""){
				  document.getElementById("SlSexo").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }

		 }else if (etipo.value == 'PJ'){

              if (document.getElementById("edtRazaoCli").value == ""){
				  document.getElementById("edtRazaoCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }

              if (document.getElementById("edtContatoCli").value == ""){
				  document.getElementById("edtContatoCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }

              if (document.getElementById("edtCGCCli").value == ""){
				  document.getElementById("edtCGCCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }

		 }

              if ( (document.getElementById("edtPassCli").value == "") || (document.getElementById("edtConfPassCli").value == "") ){
				  document.getElementById("edtPassCli").style.cssText = "border:solid 1px #FF0000";
				  document.getElementById("edtConfPassCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("edtPassCli").value != document.getElementById("edtConfPassCli").value){
				  document.getElementById("edtPassCli").style.cssText = "border:solid 1px #FF0000";
				  alert("A confirmação de senha não confere com a senha digitada!"); 
				  error = true;
			  }

              if (document.getElementById("SlTipoEnd").value == ""){
				  document.getElementById("SlTipoEnd").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }
			 
              if (document.getElementById("edtEndCli").value == ""){
                   document.getElementById("edtEndCli").style.cssText = "border:solid 1px #FF0000";
				   error = true;
              }

              if (document.getElementById("edtBairrCli").value == ""){
                   document.getElementById("edtBairrCli").style.cssText = "border:solid 1px #FF0000";
				   error = true;
              }

              if (document.getElementById("edtCidCli").value == ""){
                   document.getElementById("edtCidCli").style.cssText = "border:solid 1px #FF0000";
				   error = true;
              }

              if (document.getElementById("SlEstado").value == ""){
                   document.getElementById("SlEstado").style.cssText = "border:solid 1px #FF0000";
				   error = true;
              }

              if (document.getElementById("SlPais").value == "#"){
                   document.getElementById("SlPais").style.cssText = "border:solid 1px #FF0000";
				   error = true;
              }

              if (document.getElementById("edtTelCli1").value == ""){
                   document.getElementById("edtTelCli1").style.cssText = "border:solid 1px #FF0000";
				   error = true;
              }
			  
			  if (error){
			      e.className = "error_found1";
                  e.innerHTML = "<img src='https://ssl2033.websiteseguro.com/percar/img/errors/warning.gif' style='padding:2px;' /><span style='padding:7px;position:absolute;'>Os campos que estão marcados são obrigatórios.</span>";
                  return;
			  }
			
              url = "https://ssl2033.websiteseguro.com/percar/cadastro/result_cadastro/";
			  document.novoCliente.setAttribute("action",url);
			  document.novoCliente.submit();

	 }
}


// funcao para validar o formulario de contato do fale conosco 
function ValidaFormulario()
{
	if (document.getElementById("edtNome").value == "")
	{
		alert("Por favor, informe o seu nome.");
		document.getElementById("edtNome").focus();
		return false;
	}
	
  if (document.getElementById("email").value.indexOf('@',0) == -1 || document.getElementById("email").value.indexOf('.',0) == -1 )   {
		alert("Insira um email válido!");
		document.getElementById("email").focus();
		return false;

   }
   
   	if (document.getElementById("edtFone").value == "")
	{
		alert("Por favor, informe o seu telefone.");
		document.getElementById("edtFone").focus();
		return false;
	}

   	if (document.getElementById("mensagem").value.length == 0)
	{
		alert("O campo mensagem não pode esta vazio!.");
		document.getElementById("mensagem").focus();
		return false;
	}

}

// funcao de redirecionamento geral normal
function redirect()
{
   window.history.go(-1);
}


function redireciona(url)
{
    window.location.href=url;	
}

// funcao que retorna a seguranca de uma senha 
function checa_seguranca(pass, campo){
        var senha = document.getElementById(pass).value;
        var entrada = 0;
        var resultado;
		
		
        
        if(senha.length < 9){
                entrada = entrada - 1;
        }
        
        if(!senha.match(/[a-z_]/i) || !senha.match(/[0-9]/)){
                entrada = entrada - 1;
        }
        
        if(!senha.match(/\W/)){
                entrada = entrada - 1;
        }
        
        if(entrada == 0){
			
                resultado = 'Nível da senha: <font color=\'#99C55D\'>EXCELENTE</font>';
				document.getElementById(campo).innerHTML = "<img src='../img/loadings/b_loading.gif' />";
        } else if(entrada == -1){
			    document.getElementById(campo).innerHTML = "<img src='../img/loadings/b_loading.gif' />";
                resultado = 'Nível da senha: <font color=\'#7F7FFF\'>BOM</font>';
        } else if(entrada == -2){
			    document.getElementById(campo).innerHTML = "<img src='../img/loadings/b_loading.gif' />";
                resultado = 'Nível da senha: <font color=\'#FF5F55\'>BAIXA</font>';
        } else if(entrada == -3){
			    document.getElementById(campo).innerHTML = "<img src='../img/loadings/b_loading.gif' />";
                resultado = 'Nível da senha: <font color=\'#A04040\'>MUITO BAIXA</font>';
        }
        
        document.getElementById(campo).innerHTML = resultado;
		
        
        return;
}



// funcao que trava o click com o botao direito do usuario
function click(e) {
  if (navigator.appName == 'Netscape'
           && e.which == 3) {
      alert("no right click please")
      return false;
      }
   else {
      if (navigator.appName == 'Microsoft Internet Explorer'
          && event.button==2)
         alert("no right click please")
         return false;
         }
  	   
   return true;
 }




//funcao simples para breve validacao de dados no form "cliente"
function validate()
{
   if (document.getElementById("email").value != "")
	{
	    if ((document.getElementById("email").value.indexOf('@',0) == -1 || document.getElementById("email").value.indexOf('.',0) == -1 ))
		{
			alert("Por favor, digite um E-mail válido!");
			document.getElementById("email").focus();
			GoAjax(2);
			return false;
	    }
	}else{
			GoAjax(1);
			e = document.getElementById("ErrorInfo");
			e.className = "error_found1";
			e.innerHTML = "<img src='../../img/errors/warning.gif' style='padding:2px;' /><span style='padding:7px;position:absolute;'>Preencha o campo E-mail antes de continuar!</span>";
			return false
		
	}
  
  if (document.getElementById("pass").value != "")
  {	
	var valpass = document.getElementById("pass").value.length;
	  if (valpass < 6){
		  document.getElementById("pass").value = "";
		  document.getElementById("pass").focus();
		  GoAjax(1);
		  e = document.getElementById("ErrorInfo");
		  e.className = "error_found1";
		  e.innerHTML = "<img src='../../img/errors/warning.gif' style='padding:2px;' /><span style='padding:7px;position:absolute;'>Digite uma senha com no mínimo 6 dígitos!</span>";
		  return false;
	  }
  }else{
			GoAjax(1);
			e = document.getElementById("ErrorInfo");
			e.className = "error_found1";
			e.innerHTML = "<img src='../../img/errors/warning.gif' style='padding:2px;' /><span style='padding:7px;position:absolute;'>Preencha o campo senha antes de continuar!</span>";
			return false
  }
} 




// funcao que valida o formulário de cliente nao cadastrado!!!!
function validate_not_cli()
{
   if (document.getElementById("email1").value != "")
	{
	    if ((document.getElementById("email1").value.indexOf('@',0) == -1 || document.getElementById("email1").value.indexOf('.',0) == -1 ))
		{
			document.getElementById("email1").focus();
			GoAjax(1);
			e = document.getElementById("ErrorInfo");
			e.className = "error_found1";
			e.innerHTML = "<img src='../../img/errors/warning.gif' style='padding:2px;' /><span style='padding:7px;position:absolute;'>Por favor, digite um E-mail válido!</span>";
			return false
	    }
	}else{
			GoAjax(1);
			e = document.getElementById("ErrorInfo");
			e.className = "error_found1";
			e.innerHTML = "<img src='../../img/errors/warning.gif' style='padding:2px;' /><span style='padding:7px;position:absolute;'>Preencha o campo E-mail antes de continuar!</span>";
			return false
		
	}
  
  if (document.getElementById("cep").value != "")
  {	
	var valcep = document.getElementById("cep").value.length;
	  if (valcep < 8)
	  {
		 document.getElementById("cep").value = "";
		 document.getElementById("cep").focus();
		 GoAjax(1);
		 e = document.getElementById("ErrorInfo");
    	 e.className = "error_found1";
		 e.innerHTML = "<img src='../../img/errors/warning.gif' style='padding:2px;' /><span style='padding:7px;position:absolute;'>Digite um número de CEP, ou deixe em branco.</span>";
		 return false
	  }
  }
} 




// funcao window.open personalizada
function open_window(width, height, nome, scrollbars) {
 var top; var left;
  top = ( (screen.height/2) - (height/2) )
  left = ( (screen.width/2) - (width/2) )
  window.open('',nome,'width='+width+',height='+height+',scrollbars='+scrollbars+   ',toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}





// de acordo com o usuario, clicando no ckIECli ira habilitar ou desabilitar o ckIECli

function fEnableDisableIsento( bolIsChecked, tbxIEId ){

    var isento;
	var tbxIE = document.getElementById( tbxIEId );
	tbxIE.disabled = bolIsChecked;
	tbxIE.style.background = !bolIsChecked ? "#FFFFFF" : "silver";
	tbxIE.value = bolIsChecked ? "" : tbxIE.value;

}

function transform_cep(Campo, teclapres)
			{
				var tecla = teclapres.keyCode;
				var vr = new String(Campo.value);
				vr = vr.replace("-", "");
				tam = vr.length + 1;
				if (tecla != 8)
				{
					if (tam == 6)
						Campo.value = vr.substr(0, 5) + '-' + vr.substr(5, 5);
				}
			}
			
			
/* Funções para validar entrada de duplicidade de dados - CPF, CNPJ - AJAX */			
function CkDuplilDocs(tipo_doc,doc,elemento,campo){

  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }//FIM TRY AJAX
	  
	  if (ajax){
		     var e = document.getElementById(elemento);
		  
			 ajax.open("POST", "ckduplil.php", true);
			 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			 ajax.onreadystatechange = function() {
 						 if(ajax.readyState == 1) {
						    e.innerHTML = "<img src='https://ssl2033.websiteseguro.com/percar/img/loadings/gray_loading.gif' align='absmiddle'/>";
						 }
 						 if(ajax.readyState == 4) {
							e.innerHTML = ajax.responseText;
						 }
			 }//Fim Function ReadyChange
		        var params = "doc="+doc+"&tipodoc="+tipo_doc;
		        ajax.send(params);
	  }
	
}
			
			
/*********************************************************************************************************************************
                                                     FUNÇÔES ALTERAÇÂO DE CADASTRO - SSL
*********************************************************************************************************************************/
		
function SetErrorInfoAjax(){
	alert(""); 
	return false;
}
	
	
// funcao que verifica se o cliente é PF ou PJ {Form de Alteração de Cadastro}
function VerificaPFPJ(tipo){
  var pessoa = ""; 

  if (tipo == "PF"){
	 pessoa = "PF";
  }else if (tipo == "PJ"){
	  pessoa = "PJ";
  }else if (tipo == '') {
	  pessoa = "NULL";
  }
  
    if (pessoa == "PF"){
	    e = document.getElementById("rdCustomer_Fisica");
		e.setAttribute("checked","checked");
		habilitaGrupo('F');
	}else if (pessoa == "PJ"){
	    e = document.getElementById("rdCustomer_Juridica");
		e.setAttribute("checked","checked");
		habilitaGrupo('J');
	}
}
	
	
//funcao que verifica se o cliente é MASCULINO ou FEMININO {Form Alteração de Cadastro}
function VerificaMF(tipo){
	     if (tipo == 'M'){
			 $("#SlSexo").val("Masculino"); 
		 }else if (tipo == 'F'){
			  $("#SlSexo").val("Feminino");  
		 }
}  
		
//funcao tipo endereco
function VerificaTipoEndereco(tipo){
   if (tipo == 'R'){
	    $("#SlTipoEnd").val("Residencial");
   }else if (tipo == 'C'){
	    $("#SlTipoEnd").val("Comercial");
   }
}


//funcao estado
function VerificaEstado(uf){
	    $("#SlEstado").val(uf);
}
		
function VerificaPais(cod){
	    $("#SlPais").val(cod);
}
	
	
//Verifica erros alteração do cadastro 
function SubmitAltCad(cod){
		     if (cod == 1){
			 window.location.href = "#ErrorInfo";
			 var error = false;
	         var e = document.getElementById("ErrorInfo");
			 var etipo = document.getElementById("tipo_pessoa");
   		     e.style.cssText = ""; 
			 e.className = "CartMarket1";
			 e.innerHTML = "<img src='https://ssl2033.websiteseguro.com/percar/img/loadings/b_loading.gif' />"+" "+" carregando...";

         if (etipo.value == 'PF'){//pessoa fisica
              if (document.getElementById("edtNomeCli").value == ""){
				  document.getElementById("edtNomeCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("edtSobreNomeCli").value == ""){
				  document.getElementById("edtSobreNomeCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("edtCPFCli").value == ""){
				  document.getElementById("edtCPFCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("edtDiaDtCli").value == ""){
				  document.getElementById("edtDiaDtCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("edtMesDtCli").value == ""){
				  document.getElementById("edtMesDtCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("edtAnoDtCli").value == ""){
				  document.getElementById("edtAnoDtCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }


              if (document.getElementById("SlSexo").value == ""){
				  document.getElementById("SlSexo").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }

		 }else if (etipo.value == 'PJ'){

              if (document.getElementById("edtRazaoCli").value == ""){
				  document.getElementById("edtRazaoCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }

              if (document.getElementById("edtContatoCli").value == ""){
				  document.getElementById("edtContatoCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }

              if (document.getElementById("edtCGCCli").value == ""){
				  document.getElementById("edtCGCCli").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }

		 }

              if (document.getElementById("SlTipoEnd").value == ""){
				  document.getElementById("SlTipoEnd").style.cssText = "border:solid 1px #FF0000";
				  error = true;
			  }
			 
              if (document.getElementById("edtEndCli").value == ""){
                   document.getElementById("edtEndCli").style.cssText = "border:solid 1px #FF0000";
				   error = true;
              }

              if (document.getElementById("edtBairrCli").value == ""){
                   document.getElementById("edtBairrCli").style.cssText = "border:solid 1px #FF0000";
				   error = true;
              }

              if (document.getElementById("edtCidCli").value == ""){
                   document.getElementById("edtCidCli").style.cssText = "border:solid 1px #FF0000";
				   error = true;
              }

              if (document.getElementById("SlEstado").value == ""){
                   document.getElementById("SlEstado").style.cssText = "border:solid 1px #FF0000";
				   error = true;
              }

              if (document.getElementById("SlPais").value == "#"){
                   document.getElementById("SlPais").style.cssText = "border:solid 1px #FF0000";
				   error = true;
              }

              if (document.getElementById("edtTelCli1").value == ""){
                   document.getElementById("edtTelCli1").style.cssText = "border:solid 1px #FF0000";
				   error = true;
              }
			  
			  if (error){
			      e.className = "error_found1";
                  e.innerHTML = "<img src='https://ssl2033.websiteseguro.com/percar/img/errors/warning.gif' style='padding:2px;' /><span style='padding:7px;position:absolute;'>Os campos que estão marcados são obrigatórios.</span>";
                  return;
			  }
			
			  url = "https://ssl2033.websiteseguro.com/percar/Cliente.Portal/MeuCadastro/result_cadastro/";
			  document.FrmAlteraCadCliente.setAttribute("action",url);
			  document.FrmAlteraCadCliente.submit();

		 }
}
		
/*********************************************************************************************************************************/		
		
// pula o campo da data : by Marcos A. Fincotto			
function goProx(obj,prox)
{
 if (navigator.appName == 'Netscape') 
 {
     switch (obj.value.length)
	 {
        case 2-1:
           prox.focus();
        case 4-1:
           prox.focus();
  
     }
 }
 
 else 
 
 if (navigator.appName == 'Microsoft Internet Explorer') 
 {
     switch (obj.value.length)
	 {
        case 2:
	         prox.focus();
        case 4:
	         prox.focus();
     }
	
 }
 
 else
									   
 if (navigator.appName == 'Opera') 
 {
     switch (obj.value.length)
	 {
        case 2:
	         prox.focus();
        case 4:
	         prox.focus();
     }


 }
 
   else
     
    switch (obj.value.length)
	 {
        case 2:
	         prox.focus();
        case 4:
	         prox.focus();
     }

 }

//*******************************************************************************************************************
//*******************************************************************************************************************
                                 // FUNÇÕES DE FORMATAÇÃO E VALIDAÇÃO DE DOCUMENTOS
								 //  Edited by Marcos A. Fincotto
//*******************************************************************************************************************
//*******************************************************************************************************************


// funcao responsável por inserir o valor já formatado como CEP no campo CEP
function fone(obj,prox) {
switch (obj.value.length) {
    case 1:
        obj.value = "(" + obj.value;
        break;
    case 3:
        obj.value = obj.value + ")";
        break;    
    case 8:
        obj.value = obj.value + "-";
        break;    
    case 13:
        prox.focus();
        break;
}
}


function formata_data(obj,prox) {
switch (obj.value.length) {
    case 2:
        obj.value = obj.value + "/";
        break;
    case 5:
        obj.value = obj.value + "/";
        break;
    case 9:
        prox.focus();
        break;
}
}


function Apenas_Numeros(caracter)
{
  var nTecla = 0;
  if (document.all) {
      nTecla = caracter.keyCode;
  } else {
      nTecla = caracter.which;
  }
  if ((nTecla> 47 && nTecla <58)
  || nTecla == 8 || nTecla == 127
  || nTecla == 0 || nTecla == 9  // 0 == Tab
  || nTecla == 13) { // 13 == Enter
      return true;
  } else {
      return false;
  }
}

// pega um certo número de CPF e o valida !
// retorna um valor booleano	

function validaCPF(cpf)
{
   erro = new String;

    if (cpf.value.length == 11)
    {    
            cpf.value = cpf.value.replace('.', '');
            cpf.value = cpf.value.replace('.', '');
            cpf.value = cpf.value.replace('-', '');

            var nonNumbers = /\D/;
    
            if (nonNumbers.test(cpf.value))
            {
                    cpf.value = "";
            }
            else
            {
                    if (cpf.value == "00000000000" ||
                            cpf.value == "11111111111" ||
                            cpf.value == "22222222222" ||
                            cpf.value == "33333333333" ||
                            cpf.value == "44444444444" ||
                            cpf.value == "55555555555" ||
                            cpf.value == "66666666666" ||
                            cpf.value == "77777777777" ||
                            cpf.value == "88888888888" ||
                            cpf.value == "99999999999") {
                            
                            erro = "Por favor, digite um número de CPF válido."
                    }
    
                    var a = [];
                    var b = new Number;
                    var c = 11;

                    for (i=0; i<11; i++){
                            a[i] = cpf.value.charAt(i);
                            if (i < 9) b += (a[i] * --c);
                    }
    
                    if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
                    b = 0;
                    c = 11;
    
                    for (y=0; y<10; y++) b += (a[y] * c--);
    
                    if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
    
                    if ((cpf.value.charAt(9) != a[9]) || (cpf.value.charAt(10) != a[10])) {
                        erro = "Por favor, digite um número de CPF válido.";
                        
                    }
            }
    }
    else
    {
        if(cpf.value.length == 0)
            return false
        else
            erro = "Por favor, digite um número de CPF válido.";
    }
    if (erro.length > 0) {
            alert(erro);
            document.getElementById("edtCPFCli").value = "";
			return false;
	}     
    return true;    
}

//envento onkeyup
function maskCPF(CPF) {
    var evt = window.event;
    kcode=evt.keyCode;
    if (kcode == 8) return;
    if (CPF.value.length == 3) { CPF.value = CPF.value + '.'; }
    if (CPF.value.length == 7) { CPF.value = CPF.value + '.'; }
    if (CPF.value.length == 11) { CPF.value = CPF.value + '-'; }
}


// evento onBlur
function formataCPF(CPF)
{
    with (CPF)
    {
        value = value.substr(0, 3) + '.' +
                value.substr(3, 3) + '.' +
                value.substr(6, 3) + '-' +
                value.substr(9, 2);
    }
}


function retiraFormatacao(CPF)
{
    with (CPF)
    {
        value = value.replace (".","");
        value = value.replace (".","");
        value = value.replace ("-","");
        value = value.replace ("/","");
    }
}

function validar(obj) { 
var s = (obj.value);
var tam=(s).length;

if (s == "")
{
  return false;
}

if (!(tam==14)){ 
alert('Por favor, digite um CNPJ válido!' ); 
document.getElementById("edtCGCCli").value = "";
document.getElementById("edtCGCCli").focus(); 
return false;
}


if (tam==14){
if(!validaCNPJ(s)){ 
alert('Número de CNPJ inválido!' ); 
document.getElementById("edtCGCCli").value = "";
document.getElementById("edtCGCCli").focus(); 
return false;
}
return true;
}
}


// função para validar CNPJ de um formulário ...

function validaCNPJ(CNPJ) {
var a = new Array();
var b = new Number;
var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
for (i=0; i<12; i++){
a[i] = CNPJ.charAt(i);
b += a[i] * c[i+1];
}
if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
b = 0;
for (y=0; y<13; y++) {
b += (a[y] * c[y]);
}
if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
return false;
}
return true;
}



/************************************************************************************************************

                                      FUNCAO PESSOA FÍSICA / JURÍDICA
									  Desenvolvida por: Marcos A. Fincotto
									  by: MAF
 
************************************************************************************************************/

function habilitaGrupo(valor) {

  // Elementos do formulario pessoa física ... 
  
  var elemento1 = document.getElementById("edtFormaTratCli");
  var elemento2 = document.getElementById("edtNomeCli");
  var elemento3 = document.getElementById("edtSobreNomeCli");
  var elemento4 = document.getElementById("edtCPFCli");
  var elemento5 = document.getElementById("edtRGCli");
  var elemento6 = document.getElementById("edtDiaDtCli");
  var elemento7 = document.getElementById("edtMesDtCli");
  var elemento8 = document.getElementById("edtAnoDtCli");
  var elemento9 = document.getElementById("SlSexo");
  
  // Elementos do formulario pessoa juridica...
  
  var elemento10 = document.getElementById("edtRazaoCli");
  var elemento11 = document.getElementById("edtContatoCli");
  var elemento12 = document.getElementById("edtCGCCli");
  var elemento13 = document.getElementById("edtIECli");
  var elemento14 = document.getElementById("ckIECli");
  
  
  
  if (valor=='F')
    {
        elemento1.removeAttribute("disabled");
		elemento2.removeAttribute("disabled");
		elemento3.removeAttribute("disabled");
		elemento4.removeAttribute("disabled");
		elemento5.removeAttribute("disabled");
		elemento6.removeAttribute("disabled");
		elemento7.removeAttribute("disabled");
		elemento8.removeAttribute("disabled");
		elemento9.removeAttribute("disabled");
		
		elemento10.setAttribute("disabled","disabled");
		elemento11.setAttribute("disabled","disabled");
		elemento12.setAttribute("disabled","disabled");
		elemento13.setAttribute("disabled","disabled");
		elemento14.setAttribute("disabled","disabled");
	     document.getElementById('tipo_pessoa').value = 'PF';
	   elemento1.focus();
    }
    else if (valor=='J') 
    {
        elemento1.setAttribute("disabled","disabled");
	   	elemento2.setAttribute("disabled","disabled");
		elemento3.setAttribute("disabled","disabled");
		elemento4.setAttribute("disabled","disabled");
		elemento5.setAttribute("disabled","disabled");
		elemento6.setAttribute("disabled","disabled");
		elemento7.setAttribute("disabled","disabled");
		elemento8.setAttribute("disabled","disabled");
		elemento9.setAttribute("disabled","disabled");
		
		elemento10.removeAttribute("disabled");
		elemento11.removeAttribute("disabled");
		elemento12.removeAttribute("disabled");
		elemento13.removeAttribute("disabled");
		elemento14.removeAttribute("disabled");
		 document.getElementById('tipo_pessoa').value = 'PJ';
		elemento10.focus();
    }
    
}

// funcao responsavel por setar qual tipo de pessoa esta comprando !!!

function verify()
{
	var pass;
	var cpass;

 if (document.getElementById('rdCustomer_Fisica').checked == false)   
    {
 	   if (document.getElementById('rdCustomer_Juridica').checked == false)
	   {
	     alert("É preciso selecionar o tipo de pessoa, Física ou Jurídica!");
		  document.getElementById('rdCustomer_Fisica').focus();
	      return false;
	   }
	
    }
	
	
	if (document.getElementById('rdCustomer_Juridica').checked == true)
    {
	 	   document.getElementById('tipo_pessoa').value = 'PJ';
    }
	 
	if (document.getElementById('rdCustomer_Fisica').checked == true)
    {
    	   document.getElementById('tipo_pessoa').value = 'PF';
    }
	 
	
	
	// sbfuncao que ira verificar o status do campo IE
    if (document.getElementById("ckIECli").checked == true)
	{
	       document.getElementById('isento').value = 'isento';
    }
	   
	   
    if (document.getElementById("ckIECli").checked == false)
	{
	 
		if (document.getElementById("edtIECli").value == "")
		{
			document.getElementById('isento').value = 'nIsento_Vazio';
		}
		else
		{
		   document.getElementById('isento').value = 'Isento_OK';
		}
	  
	 
    }
	

//subfuncao que retornara erro da senha no form novocliente
 if (document.getElementById("edtPassCli").value != "")
  {	
	var valpass = document.getElementById("edtPassCli").value.length;
	  if (valpass < 6)
	  {  
	     document.getElementById("hpass").value = 'n_cpassm6';
		 
	  }
  }
  
  
  pass = document.getElementById("edtPassCli").value;
  cpass = document.getElementById("edtConfPassCli").value;
  
 if (cpass != "") 
 {
    if (pass != cpass)
    {
    	 document.getElementById("hpass").value = 'n_vcpass';  
    }

	if (pass == cpass)
	{
	   document.getElementById("hpass").value = 'OK';
	}
 }


 if (pass == "") 
 {
  	 document.getElementById("hpass").value = 'n_passvazio';  
 }

  

}


// funcao para ver se a pagina ainda esta com campos faltando
function paramError()
{
  if (document.getElementById("herror").value == -2)
  {
     if (navigator.appName == "Microsoft Internet Explorer" )
	  {
          	document.getElementById("msgRetorno").innerHTML = 'Houve um erro ao tentar fazer o cadastro.';
        	document.getElementById("imgerror").style.cssText = 'background: url(https://ssl2033.websiteseguro.com/percar/img/icon-warning.gif) no-repeat; position:absolute;width:50px;height:50px;margin-left:-15px;margin-top:-15px;';
	        document.getElementById("voltar").innerHTML = "<input type='hidden' value=''>"; 
	  }
	  else
	  {
		  	document.getElementById("msgRetorno").innerHTML = 'Houve um erro ao tentar fazer o cadastro.';
	        document.getElementById("imgerror").style.cssText = 'background: url(https://ssl2033.websiteseguro.com/percar/img/icon-warning.gif) no-repeat;position:absolute;width:50px;height:50px;margin-left:-15px;margin-top:-15px;';
	        document.getElementById("btVoltar").setAttribute("type","hidden");
	        document.getElementById("setas").setAttribute("type","hidden");
	  }
  }

 if (document.getElementById("herror").value == -1)
  {
	document.getElementById("msgRetorno").innerHTML = 'Os seguintes erros foram encontrados.';
	document.getElementById("imgerror").style.cssText = 'background: url(https://ssl2033.websiteseguro.com/percar/img/icon-warning.gif) no-repeat; position:absolute;width:50px;height:50px;margin-left:-15px;margin-top:-15px;';
  }
  
  if (document.getElementById("herror").value == 0)
  {
	  
   	document.getElementById("msgRetorno").innerHTML = 'O seu cadastro foi efetuado com sucesso.';
	document.getElementById("imgerror").style.cssText = 'background: url(https://ssl2033.websiteseguro.com/percar/img/icons/file_up_to_date.gif) no-repeat;position:absolute;';
	document.getElementById("voltar").innerHTML = "<input type='hidden' value=''>"; 
	
  }


}


// funcao para validar o formulario de requisicao de senha
function validate_request()
{
  if (document.getElementById("email").value == "")
  {
	  alert("O campo email deve ser preenchido!");
	  document.getElementById("email").focus();
	  return false;
  }
  
  if (document.getElementById("email").value != "")
	{
	    if ((document.getElementById("email").value.indexOf('@',0) == -1 || document.getElementById("email").value.indexOf('.',0) == -1 ))
		{
			alert('Por favor, digite um E-mail válido!');
			document.getElementById("email").value = "";
			document.getElementById("email").focus();
			return false
	    }
	}

	
}



						/* **** ALTERAÇÃO DE VISAO DOS PRODUTOS EM TABELAS E LISTAS **** 
						 *
						 *    Funcões Responsáveis por trocar a visualização
						 *         dos produtos entre tabela e lista
						 *
						 ***************************************************************
						*/

function altera_modo_visao(visao)
{
   if (visao == 'lista'){ 
      document.getElementById("lookup").innerHTML = "<img src=\"http://percar.com.br/img/modos exibicao/mod_table_selected.gif\" title=\"Visão dos Produtos em Tabela\" onclick=\"altera_modo_visao('tabela');\" align=\"absbottom\" /><img src=\"http://percar.com.br/img/modos exibicao/mod_list_selected.gif\" title=\"Visão dos Produtos em Lista\"  onclick=\"altera_modo_visao('lista');\" align=\"absbottom\" />";
	}
	

	
  if (visao == 'tabela'){
     document.getElementById("lookup").innerHTML = "<img src=\"http://percar.com.br/img/modos exibicao/mod_list_selected2.gif\"    title=\"Visão dos Produtos em Tabela\" onclick= \"altera_modo_visao('tabela');\" align=\"absbottom\" /><img src=\"http://percar.com.br/img/modos exibicao/mod_table_selected2.gif\" title=\"Visão dos Produtos em Lista\"  onclick=\"altera_modo_visao('lista');\" align=\"absbottom\" />";
  }	  
  
      document.getElementById("loading").innerHTML = "Loading...";
      var subcat = document.getElementById("subcat").value;
 	  var url = "?q="+subcat+"&view="+visao;
	  window.location.href=url;
 }  
  
  
function carrega_subcat(){
    var cat = document.getElementById("cat").value; 
	document.getElementById("subcat_span").innerHTML = "<strong>"+cat+"</strong>"; 
}
  
/*********************************************************************************************************************************
													    SALVA EMAIL MARKETING
*********************************************************************************************************************************/
function SalvaInformacoes(bt_click){
	 var conf = document.getElementById('confirm');
	 var nome = document.getElementById('edNome');
	 var email = document.getElementById('edEmail');
	 var bt_click = document.getElementById(bt_click);
	 var market = document.getElementById('market');
	 if (!conf.checked){
		  alert('Por favor, clique em \"Quero receber ofertas exclusivas da Percar Atacadista.\" para continuar.');
		  return false;
	 }
	 if (nome.value == ''){
		alert('Digite seu nome para continuar.');
		nome.focus();
		nome.style.cssText = "border:solid 1px #FF0000";
    	return false;
	 }
	 if (email.value == ''){
		alert('Digite seu email para continuar.');
		email.value = "";
		email.focus();
		email.style.cssText = "border:solid 1px #FF0000";
		return false;
	 }else{
		 if ((email.value.indexOf('@',0) == -1 || email.value.indexOf('.',0) == -1 ))
		{
			alert('Por favor, digite um E-mail válido!');
			email.value = "";
			email.focus();
			email.style.cssText = "border:solid 1px #FF0000";
			return false;
	    }
	 }
	  try {
			 ajax = new ActiveXObject("Microsoft.XMLHTTP");
	      } 
		  catch(e) {
		 try {
				ajax = new ActiveXObject("Msxml2.XMLHTTP");
			 }
		 catch(ex) {
			try {
				   ajax = new XMLHttpRequest();
			}
			catch(exc) {
			   alert("Sr. Cliente, verificamos que o seu browser não possui suporte para Ajax, pedimos que verifique.");
			   ajax = null;
			}
		 }
	  }
	  
	  if (ajax){
		   ajax.open("POST", "http://www.percar.com.br/includes/addEmail.php", true);
		   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		   ajax.onreadystatechange = function(){
				if (ajax.readyState == 1){
					bt_click.setAttribute("disabled","disabled");
					market.style.cssText = "border-right:solid 1px #D9D9D9;border-left:solid 1px #D9D9D9;text-align:center;";
					market.innerHTML = "<img src='https://ssl2033.websiteseguro.com/percar/img/loadings/b_loading.gif' />"+" "+"  carregando...";
				}  
				if (ajax.readyState == 4 && ajax.status == 200){
					var dados = ajax.responseXML;
					dataArray = dados.getElementsByTagName("status");
					if (dataArray.length == 1){
						resultado = dataArray[0].childNodes[0].data;
						market.innerHTML = resultado;
					}else if (dataArray.length > 1){
						dataArray2 = dados.getElementsByTagName("descricao");
						status = dataArray[0].childNodes[0].data;
						descricao = dataArray2[0].childNodes[0].data;
						if ( (status == '1') || (status == '2') || (status == '3') )
						  market.innerHTML = "<img src='../img/Cliente.Portal.Images/Sucess.gif' align='absmiddle' />&nbsp;"+descricao
						else if ( (status == '8') || (status == '9') )
						  market.innerHTML = "<img src='../img/Cliente.Portal.Images/query_error.png' align='absmiddle' />&nbsp;"+descricao;
						bt_click.removeAttribute("disabled")
                    }
                }
		  }
		  var params = "nome="+nome.value+"&email="+email.value;
		  ajax.send(params); 
	}
}



/**************
 Prévia do carrinho de compras
********/
function prevCart(){
  var market = document.getElementById('prevCart');
  market.className = "prev_cart_2";
  market.innerHTML = "Teste de Exibição";
  alert('foi...');
}


function OpenPoPup(){
  window.open('http://www.percar.com.br/Cliente.Portal/Pagamento/PopUpCreditCardInfo.php' ,'autoajuda','width=466,height=450,status=no,scrollbars=yes,top=50,left=50');	
}













