// JavaScript Document

// função para modificar os botões do submenu das franquias
function func_change_button (secao, buttonNr, over){
	d = document;
	if (over){
		if (secao=="morana") {
			d.getElementById(secao+"Button"+buttonNr).style.background = "#CCCCCC";
		} else if (secao=="balone") {
			d.getElementById(secao+"Button"+buttonNr).style.background = "#992087";
		} else if (secao=="jinjinwok"){
			d.getElementById(secao+"Button"+buttonNr).style.background = "#DEDD21";
		}
		d.getElementById("cantoEsquerdo"+buttonNr).src = "/grupo-ornatus/v1/br/_img/gif/img-bt-"+secao+"-canto-esquerdo1.gif";
		d.getElementById("cantoDireito"+buttonNr).src = "/grupo-ornatus/v1/br/_img/gif/img-bt-"+secao+"-canto-direito1.gif";
	} else {
		d.getElementById(secao+"Button"+buttonNr).style.background = "#333333";
		d.getElementById("cantoEsquerdo"+buttonNr).src = "/grupo-ornatus/v1/br/_img/gif/img-bt-"+secao+"-canto-esquerdo.gif";
		d.getElementById("cantoDireito"+buttonNr).src = "/grupo-ornatus/v1/br/_img/gif/img-bt-"+secao+"-canto-direito.gif";
	}
}
//[INICIO] função para executar rollover
function func_swapImg (imgID, imgPath){
	document.getElementById(imgID).src = imgPath;
}
//[FIM] função para executar rollover

//[INICIO] função para abrir um submenu
function func_showLayer (layer){
	var d = document;
	totalSubmenu = 4;
	for (i=1; i<=totalSubmenu; i++){
		d.getElementById('submenu'+i).style.display = 'none';
		if (layer == i) {
			d.getElementById('submenu'+i).style.display = '';
		} 
	}
}
//[FIM] função para abrir um submenu

//[INICIO] funcao muda de campo
function mudaCampo(qtdeDigitos, campoAtual, campoFoco){
	var qtdeCampoAtual = document.getElementById(campoAtual).value.length
	if(qtdeCampoAtual >= qtdeDigitos){
		document.getElementById(campoFoco).focus()
	}
}
//[FIM] funcao muda de campo

//[INICIO]
function limpaCampo(valor){
	var campoAtual = valor;
	var valorCampo = document.getElementById(campoAtual).value;
	
	if((valorCampo == "DD")||(valorCampo == "DDI")||(valorCampo == "DDD")||(valorCampo == "MM")||(valorCampo == "AAAA")){
    	document.getElementById(campoAtual).value="";
	}else{
		document.getElementById(campoAtual).select();
	}
}
//[FIM]

//[INICIO] função para abrir e esconder as respostas da página faq
function func_abrirResposta(respostaNr){
	d = document;
	totalRespostas = 13;
	for (i=1; i <= totalRespostas; i++){
		if (i == respostaNr){
			eval("d.getElementById('resposta"+i+"').style.display='';");
			eval("d.getElementById ('ico_seta"+i+"').src='/co-piloto/v1/img/gif/icon_seta_azul_down.gif';");
		} else {
			eval("d.getElementById('resposta"+i+"').style.display='none';");
			eval("d.getElementById ('ico_seta"+i+"').src='/co-piloto/v1/img/gif/icon_seta_azul.gif';");
		}
	}
}
//[FIM] função para abrir e esconder as respostas da página faq

//[INICIO] Função para validar o BOX de login
function validaLoginBox(formParam, urlParam){
	dc = document.loginBox;
	var caracteres = new Array ("<", ">", "/", "'", "*", "&", "(", ")", "#", "|", "!", "?", ";", ":", "<", "'", "=", ",");
	if (dc.cmpUsuario.value == ""){
		alert ("Preencha o seu nome de usuário");
		dc.cmpUsuario.focus ();
		return false;
	}
	if (dc.cmpSenha.value == ""){
		alert ("Preencha a senha corretamente");
		dc.cmpSenha.focus();
		return false;
	}
	for (i=0; i < caracteres.length; i++){
		if (dc.cmpUsuario.value.indexOf (caracteres[i]) >= 0 || dc.cmpSenha.value.indexOf (caracteres[i]) >= 0){
			alert ("Não é permitido usar caracteres especiais nos campos login/senha.");
			return false;
		}
	}
	document.loginBox.submit()
}
//[FIM] Função para validar o BOX de login

//Script Função ajax que detecta o navegador
function getBrowser() {
	if (window.XMLHttpRequest) { 
		a=new XMLHttpRequest(); //Objeto nativo (FF/Safari/Opera7.6+)
	} else {
		try { 
			a=new ActiveXObject("Msxml2.XMLHTTP");  //activeX (IE5.5+/MSXML2+)
		}   
		catch(e) {
			try { 
				a=new ActiveXObject("Microsoft.XMLHTTP"); //activeX (IE5+/MSXML1)
			}   
			catch(e) { /* O navegador nÃ£o tem suporte */ 
				a=false; 
			}
		}
	} 
	return a;
}
//Fim do Scrip Função ajax que detecta o navegador

//[INICIO] função para validar o Email
function validaEmail(email){
	if(email.value == ""){
		alert("informe seu E-mail!!")
		email.focus();
		return false;
	}
		if(email.value.indexOf("@", email.value.indexOf("@") + 1 ) != -1) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf(".") < 1) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf(" ") != -1) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf(".@") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf("@.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf(".com.br.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf("/") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf("[") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf("]") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf("(") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf(")") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		if(email.value.indexOf("..") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			return false;
		}
		return true;
}
//[FIM] função para validar o Email

//Script para validação do CPF
function validacpf(campo){   
	var i; 
	s = campo; 

	if(s.value ==""){
		alert("Preencha o campo CPF");
		s.focus();
		return false;
	}

	var c = s.value.substr(0,9); 
	var dv = s.value.substr(9,2); 
	var d1 = 0; 
	for (i = 0; i < 9; i++){	  
		d1 += c.charAt(i)*(10-i); 
	} 
  
	if (d1 == 0){   
		alert("CPF Invalido") 
		return false; 
	}	 
  
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
		if (dv.charAt(0) != d1) 
		{ 
  
		alert("CPF Invalido") 
		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){ 
			alert("CPF Invalido") 
			return false; 
  		} 
	return true; 
} 
	
function verificaDig(){
	tx = document.frmCli.txtCpf.value; 
	var a = tx.substr(0,1);
	var b = tx.substr(1,1);
	var c = tx.substr(2,1);
	var d = tx.substr(3,1);
	var e = tx.substr(4,1);
	var f = tx.substr(5,1);
	var g = tx.substr(6,1);
	var h = tx.substr(7,1);
	var i = tx.substr(8,1); 
	var j = tx.substr(9,1);
	var k = tx.substr(10,1);
	//alert(b+"="+c)
	if(a==b && b==c && c==d && d==e && e==f && f==g && g==h && h==i && i==j && j==k){
		alert("CPF Invalido")
	}
}
//Fim do script para validacao do CPF


//Script para validação do CNPJ
function validaCNPJ(CNPJID) {
	CNPJ = CNPJID.value;
	erro = new String;
	//if (CNPJ.length < 18) erro += "É necessario preencher corretamente o numero do CNPJ! \n\n";
	/*if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
	if (erro.length == 0) erro += "É necessario preencher corretamente o numero do CNPJ! \n\n";
	}*/
	//substituir os caracteres que nao sao numeros
	if(document.layers && parseInt(navigator.appVersion) == 4){
		x = CNPJ.substring(0,2);
		x += CNPJ.substring(3,6);
		x += CNPJ.substring(7,10);
		x += CNPJ.substring(11,15);
		x += CNPJ.substring(16,18);
		CNPJ = x;
	} else {
		CNPJ = CNPJ.replace(".","");
		CNPJ = CNPJ.replace(".","");
		CNPJ = CNPJ.replace("-","");
		CNPJ = CNPJ.replace("/","");
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas numeros! \n\n";
		var a = [];
		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])){
		erro +="Digito verificador com problema!";
	}
	if (erro.length > 0){
		alert(erro);
		return false;
	} else {
		//alert("CNPJ valido!");
	}
		return true;
	}
//FIM Script para validação do CNPJ

//[INICIO] função para validar DDD
function validaDDD (campo){
	DDD = campo;
	if (DDD.value == ""){
		alert ("Preencha o campo DDD");
		DDD.focus();
		return false;
	} else if (isNaN(DDD.value)){
		alert ("Utilize apenas números no campo DDD");
		DDD.select();
		return false;
	} else if (DDD.value.length < 2){
		alert ("DDD inválido")
		DDD.select();
		return false;
	}
	return true;
}
//[FIM] função para validar DDD

//[INICIO] validador de CEP em dois campos diferentes
function validaCEP (campo1, campo2){
	CEP1 = campo1;
	CEP2 = campo2;
	if (CEP1.value == ""){
		alert ("Preencha o campo CEP");
		CEP1.focus();
		return false;
	}
	if (isNaN (CEP1.value)){
		alert ("Utilize apenas números no campo CEP");
		CEP1.select();
		return false;
	}
	if (CEP1.value.length < 5){
		alert ("CEP inválido");
		CEP1.select();
		return false;
	}
	if (CEP2.value != ""){
		if (isNaN (CEP2.value)){
			alert ("Utilize apenas números no campo CEP");
			CEP2.select()();
			return false;
		}
		if (CEP2.value.length < 3){
			alert ("CEP inválido");
			CEP2.select();
			return false;
		}
	}
	return true;
}
//[FIM] validador de CEP em dois campos diferentes

//[INICIO] função para validar o formulário de contato
/*function validaForm (){
	var dc = document.form1;
	if (dc.cmpSetor.value == ""){
		alert ("Selecione o setor para o qual deseja enviar a mensagem");
		dc.cmpSetor.focus ();
		return false;
	}
	if (dc.cmpNome.value == ""){
		alert ("Preencha o campo nome");
		dc.cmpNome.focus ();
		return false;
	}
	if (!validaEmail (dc.cmpEmail)){
		return false;
	}
	if (dc.cmpCidade.value == ""){
		alert ("Preencha o campo Cidade");
		dc.cmpCidade.focus ();
		return false;
	}
	if (dc.cmpUF.value == ""){
		alert ("Selecione a sigla correspondente ao seu Estado");
		dc.cmpUF.focus ();
		return false;
	}
	DDD = dc.cmpDDD.value;
	Tel = dc.cmpTelefone.value;
	if (DDD.length < 2){
		alert ("Preencha corretamente o DDD");
		dc.cmpDDD.focus ();
		return false;
	}
	if (Tel.length < 7){
		alert ("Preencha corretamente o seu número de Telefone");
		dc.cmpTelefone.focus ();
		return false;
	}
	if (dc.cmpAssunto.value == ""){
		alert ("Preencha o campo Assunto");
		dc.cmpAssunto.focus ();
		return false;
	}
	if (dc.cmpMsn.value == ""){
		alert ("Digite sua mensagem");
		dc.cmpMsn.focus ();
		return false;
	}
	dc.submit();
}*/
//[FIM] função para validar o formulário de contato

//[INICIO] função para validar o formulário de indique este site
function validaIndique (){
	var dc = document.form1;
	/*if (dc.cmpNomeAmigo1.value == ""){
		alert ("Preencha pelo menos um campo Nome do destinatário");
		dc.cmpNomeAmigo1.focus();
		return false;
	}
	if (dc.cmpEmailAmigo1.value == ""){
		alert ("Preencha pelo menos um campo Email do destinatário");
		dc.cmpEmailAmigo1.focus();
		return false;
	} else if(!validaEmail(dc.cmpEmailAmigo1)) {
		return false;		
	}
	if (dc.cmpNomeAmigo2.value != ""){
		if (dc.cmpEmailAmigo2.value == ""){
			alert ("Preencha o campo Email do destinatário");
			dc.cmpEmailAmigo2.focus();
			return false;
		} else if (!validaEmail (dc.cmpEmailAmigo2)){
			return false;
		}
	}
	if (dc.cmpEmailAmigo2.value != "" && dc.cmpNomeAmigo2.value == ""){
		alert ("Preencha o campo Nome do destinatário")
		dc.cmpNomeAmigo2.focus();
		return false;
	}
	if (dc.cmpNomeAmigo3.value != ""){
		if (dc.cmpEmailAmigo3.value == ""){
			alert ("Preencha o campo Email do destinatário");
			dc.cmpEmailAmigo3.focus();
			return false;
		} else if (!validaEmail (dc.cmpEmailAmigo3)){
			return false;
		}
	}
	if (dc.cmpEmailAmigo3.value != "" && dc.cmpNomeAmigo3.value == ""){
		alert ("Preencha o campo Nome do destinatário")
		dc.cmpNomeAmigo3.focus();
		return false;
	}
	if (dc.cmpNome.value == ""){
		alert ("Preencha o campo Nome");
		dc.cmpNome.focus();
		return false;
	}
	if (dc.cmpEmail.value == ""){
		alert ("Preencha o campo Email");
		dc.cmpEmail.focus();
		return false;
	} else if (!validaEmail (dc.cmpEmail)){
		return false;
	}*/
	dc.submit();
}
//[FIM] função para validar o formulário de indique este site

//[INICIO] função para validar o formulário de contato
function validaFormSuporte (){
	var dc = document.form1;
	/*if (dc.cmpNome.value == ""){
		alert ("Preencha o campo nome");
		dc.cmpNome.focus ();
		return false;
	}
	if (!validaEmail (dc.cmpEmail)){
		return false;
	}
	if (dc.cmpCidade.value == ""){
		alert ("Preencha o campo Cidade");
		dc.cmpCidade.focus ();
		return false;
	}
	if (dc.cmpUF.value == ""){
		alert ("Selecione a sigla correspondente ao seu Estado");
		dc.cmpUF.focus ();
		return false;
	}
	if (dc.cmpMsn.value == ""){
		alert ("Digite sua mensagem");
		dc.cmpMsn.focus ();
		return false;
	}*/
	dc.submit();
}
//[FIM] função para validar o formulário de contato

//[INICIO] função para trocar as divs do formulario de cadastro
function func_changeForm (param){ //pf -> pessoa física || pj -> pessoa jurídica
	d = document;
	if (param == "pf"){
		d.getElementById("form_pf").style.display='';
		d.getElementById("form_pj").style.display='none';
	} 
	if (param == "pj"){
		d.getElementById("form_pf").style.display='none';
		d.getElementById("form_pj").style.display='';
	}
}
//[FIM] função para trocar as divs do formulario de cadastro

//[INICIO] função para validar o formulario de cadastro
function validaCadastro (){
	dc = document.form1;
	/*if (document.getElementById("pf").checked){
		if (dc.PFcmpNome.value == ""){
			alert ("Preencha o campo nome");
			dc.PFcmpNome.focus();
			return false;
		}
		if (dc.PFcmpSobrenome.value == ""){
			alert ("Preencha o campo Sobrenome");
			dc.PFcmpSobrenome.focus();
			return false;
		}
		if (!validaEmail(dc.PFcmpEmail)){
			return false;
		}
		if (!validacpf(dc.PFcmpCPF)){
			return false;
		}
		if (!document.getElementById("PFradMasculino").checked && !document.getElementById("PFradFeminino").checked){
			alert ("Marque um dos campos: Masculino ou Feminino");
			dc.PFcmpSexo.focus ();
			return false;
		}  
		if (dc.PFcmpUsuario.value == ""){
			alert ("Preencha o campo usuário");
			dc.PFcmpUsuario.focus();
			return false;
		}
		if (dc.PFcmpSenha.value == ""){
			alert ("Preencha o campo senha");
			dc.PFcmpSenha.focus();
			return false;
		}
		if (dc.PFcmpConfirmSenha.value == ""){
			alert ("Redigite sua senha no campo Confirme sua senha");
			dc.PFcmpConfirmSenha.focus ();
			return false;
		}
		if (dc.PFcmpSenha.value != dc.PFcmpConfirmSenha.value){
			alert ("A senha do campo Confirme sua senha deve ser a mesma do campo Senha");
			dc.PFcmpConfirmSenha.select();
			return false;
		}
		if (dc.PFcmpDia.value == ""){
			alert ("Escolha o dia correspondente ao seu nascimento");
			dc.PFcmpDia.focus();
			return false;
		}
		if (dc.PFcmpMes.value == ""){
			alert ("Escolha o mês correspondente ao seu nascimento");
			dc.PFcmpMes.focus();
			return false;
		}
		if (dc.PFcmpAno.value == ""){
			alert ("Escolha o ano correspondente ao seu nascimento");
			dc.PFcmpAno.focus();
			return false;
		}
		if (!validaCEP(dc.PFcmpCEP1, dc.PFcmpCEP2)){
			return false;
		}
		if (dc.PFcmpEndereco.value == ""){
			alert ("Preencha o campo Endereço");
			dc.PFcmpEndereco.focus();
			return false;
		}
		if (dc.PFcmpBairro.value == ""){
			alert ("Preencha o campo Bairro");
			dc.PFcmpBairro.focus();
			return false;
		}
		if (dc.PFcmpCidade.value == ""){
			alert ("Preencha o campo Cidade");
			dc.PFcmpCidade.focus();
			return false;
		}
		if (dc.PFcmpUF.value == ""){
			alert ("Selecione a sigla correspondente ao seu Estado");
			dc.PFcmpUF.focus();
			return false;
		}
		if (!validaDDD(dc.PFcmpDDD)){
			return false;
		}
		if (dc.PFcmpTelefone.value == ""){
			alert ("Preencha o campo Telefone");
			dc.PFcmpTelefone.focus();
			return false;
		}
	}
	if (document.getElementById("pj").checked){
		if (dc.PJcmpNome.value == ""){
			alert ("Preencha o campo nome");
			dc.PJcmpNome.focus();
			return false;
		}
		if (!validaEmail(dc.PJcmpEmail)){
			return false;
		}
		if (!validaCNPJ(dc.PJcmpCNPJ)){
			return false;
		}
		if (dc.PJcmpUsuario.value == ""){
			alert ("Preencha o campo usuário");
			dc.PJcmpUsuario.focus();
			return false;
		}
		if (dc.PJcmpSenha.value == ""){
			alert ("Preencha o campo senha");
			dc.PJcmpSenha.focus();
			return false;
		}
		if (dc.PJcmpConfirmSenha.value == ""){
			alert ("Redigite sua senha no campo Confirme sua senha");
			dc.PJcmpConfirmSenha.focus ();
			return false;
		}
		if (dc.PJcmpSenha.value != dc.PJcmpConfirmSenha.value){
			alert ("A senha do campo Confirme sua senha deve ser a mesma do campo Senha");
			dc.PJcmpConfirmSenha.select();
			return false;
		}
		if (dc.PJcmpDia.value == ""){
			alert ("Escolha o dia correspondente ao seu nascimento");
			dc.PJcmpDia.focus();
			return false;
		}
		if (dc.PJcmpMes.value == ""){
			alert ("Escolha o mês correspondente ao seu nascimento");
			dc.PJcmpMes.focus();
			return false;
		}
		if (dc.PJcmpAno.value == ""){
			alert ("Escolha o ano correspondente ao seu nascimento");
			dc.PJcmpAno.focus();
			return false;
		}
		if (!validaCEP(dc.PJcmpCEP1, dc.PJcmpCEP2)){
			return false;
		}
		if (dc.PJcmpEndereco.value == ""){
			alert ("Preencha o campo Endereço");
			dc.PJcmpEndereco.focus();
			return false;
		}
		if (dc.PJcmpBairro.value == ""){
			alert ("Preencha o campo Bairro");
			dc.PJcmpBairro.focus();
			return false;
		}
		if (dc.PJcmpCidade.value == ""){
			alert ("Preencha o campo Cidade");
			dc.PJcmpCidade.focus();
			return false;
		}
		if (dc.PJcmpUF.value == ""){
			alert ("Selecione a sigla correspondente ao seu Estado");
			dc.PJcmpUF.focus();
			return false;
		}
		if (!validaDDD(dc.PJcmpDDD)){
			return false;
		}
		if (dc.PJcmpTelefone.value == ""){
			alert ("Preencha o campo Telefone");
			dc.PJcmpTelefone.focus();
			return false;
		}
	}*/
	dc.submit();
}
//[FIM] função para validar o formulario de cadastro

//[INICIO] função para validar o formulário de login que está na página login
function validaFormPageLogin() {
	dc = document.form1;
	var caracteres = new Array ("<", ">", "/", "'", "*", "&", "(", ")", "#", "|", "!", "?", ";", ":", "<", "'", "=", ",");
	for (i=0; i < caracteres.length; i++){
		if (dc.cmpUsuario.value.indexOf (caracteres[i]) >= 0 || dc.cmpSenha.value.indexOf (caracteres[i]) >= 0){
			alert ("Não é permitido usar caracteres especiais nos campos Usuário/senha.");
			return false;
		}
	}
	dc.submit();
}
//[FIM] função para validar o formulário de login que está na página login

//[INICIO] Função para excluir registro
function func_excluir(textoParam, urlParam){
	if(textoParam != ""){
		if(confirm(textoParam)==true){
			window.location = urlParam
		}
	}else{
		window.location = urlParam	
	}
}
//[FIM] Função para excluir registro

//[INICIO] Função para calcular o frete
function func_acoesCarrinho(urlParam){
	document.form1.action = urlParam
	document.form1.submit();
}
//[FIM] Função para calcular o frete

//[INICIO] função para enviar os formularios
function func_submit(formParam, urlParam){
	document.getElementById(formParam).action = urlParam
	document.getElementById(formParam).submit();
}
//[FIM] função para enviar os formularios


//[INICIO] Script funcao ajax que interage
function func_verificaCep(){
	cep1 = document.getElementById("cmpCEP1").value;
	cep2 = document.getElementById("cmpCEP2").value;
	//alert(cep1+"\n"+cep2)
	ajax = getBrowser();
	if(ajax){
		ajax.open("GET","/_ajax/ajax.asp?acao=verificaCEP&cmpCEP1="+cep1+"&cmpCEP2="+cep2, true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState != 4){
				//document.getElementById("divID").innerHTML = "Carregando...";
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200) {
					if(ajax.responseText != "erro"){
						//alert(ajax.responseText)
						var ajaxText = ajax.responseText;
						var splDados = ajaxText.split("|");
						document.getElementById("cmpEndereco").value = func_caracter(splDados[0]);
						document.getElementById("cmpBairro").value = splDados[1];
						document.getElementById("cmpCidade").value = func_caracter(splDados[2]);
						document.getElementById("cmpUF").value = splDados[3];
					}else{
						alert("CEP inválido!")	
					}
       			} else {
					//document.getElementById("divID").innerHTML = "Não encontrado!"
					alert("Não encontrado!");
      			}
			}
		}
		ajax.send(null);
	}
}
//[FIM] Fim do Script funcao ajax que interage

//[INICIO] cobertura do GPS
function cobertura(){
	valor = document.getElementById("cmpUF").value;
	//ajax = redirect();
	ajax = getBrowser();
	if(ajax){
		ajax.open("GET","/co-piloto/v1/_ajax/func_ajax.asp?acao=cobertura&n="+valor, true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState != 4){
				//divID.innerHTML = "Carregando...";
				document.getElementById("cobertura_results").innerHTML = "Carregando...";
				//document.getElementById("divID").childNodes[0].nodeValue = "Carregando..."
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200) {
					// divID.innerHTML = ajax.responseText;
					 document.getElementById("cobertura_results").innerHTML =  ajax.responseText;
					 //document.getElementById("divID").childNodes[0].nodeValue = ajax.responseText;
       			} else {
         			//alert(ajax.statusText);
					//divID.innerHTML = "Não encontrado!"
					document.getElementById("cobertura_results").innerHTML = "Não encontrado!"
					 //document.getElementById("divID").childNodes[0].nodeValue = "Não encontrado!";
      			}
			}
		}
		ajax.send(null);
	}
}
//[FIM] cobertura do GPS

function func_caracter(strString){
	
	//possibilidades
	//ãÃáÁàÀâÂäÄ / éÉèÈêÊëË / íÍìÌïÏ / õÕóÓòÒôÔöÖ / úÚùÙûÛüÜ / çÇ
	//a A
	
	var strFormatString = strString.replace("&atilde;","ã");
	strFormatString = strFormatString.replace("&Atilde;","Ã");
	strFormatString = strFormatString.replace("&aacute;","á");
	strFormatString = strFormatString.replace("&Aacute;","Á");
	strFormatString = strFormatString.replace("&agrave;","à");
	strFormatString = strFormatString.replace("&Agrave;","À");
	strFormatString = strFormatString.replace("&acirc;","â");
	strFormatString = strFormatString.replace("&Acirc;","Â");
	strFormatString = strFormatString.replace("&auml;","ä");
	strFormatString = strFormatString.replace("&Auml;","Ä");
	
	strFormatString = strFormatString.replace("&eacute;","é");
	strFormatString = strFormatString.replace("&Eacute;","É");
	strFormatString = strFormatString.replace("&egrave;","è");
	strFormatString = strFormatString.replace("&Egrave;","È");
	strFormatString = strFormatString.replace("&ecirc;","ê");
	strFormatString = strFormatString.replace("&Ecirc;","Ê");
	strFormatString = strFormatString.replace("&euml;","ë");
	strFormatString = strFormatString.replace("&Euml;","Ë");
	
	strFormatString = strFormatString.replace("&iacute;","í");
	strFormatString = strFormatString.replace("&Iacute;","Í");
	strFormatString = strFormatString.replace("&igrave;","ì");
	strFormatString = strFormatString.replace("&Igrave;","Ì");
	strFormatString = strFormatString.replace("&icirc;","î");
	strFormatString = strFormatString.replace("&Icirc;","Î");
	strFormatString = strFormatString.replace("&iuml;","ï");
	strFormatString = strFormatString.replace("&Iuml;","Ï");
	
	strFormatString = strFormatString.replace("&otilde;","õ");
	strFormatString = strFormatString.replace("&Otilde;","Õ");
	strFormatString = strFormatString.replace("&oacute;","ó");
	strFormatString = strFormatString.replace("&Oacute;","Ó");
	strFormatString = strFormatString.replace("&ograve;","ò");
	strFormatString = strFormatString.replace("&Ograve;","Ò");
	strFormatString = strFormatString.replace("&ocirc;","ô");
	strFormatString = strFormatString.replace("&Ocirc;","Ô");
	strFormatString = strFormatString.replace("&ouml;","ö");
	strFormatString = strFormatString.replace("&Ouml;","Ö");
	
	strFormatString = strFormatString.replace("&uacute;","ú");
	strFormatString = strFormatString.replace("&Uacute;","Ú");
	strFormatString = strFormatString.replace("&ugrave;","ù");
	strFormatString = strFormatString.replace("&Ugrave;","Ù");
	strFormatString = strFormatString.replace("&ucirc;","û");
	strFormatString = strFormatString.replace("&Ucirc;","Û");
	strFormatString = strFormatString.replace("&uuml;","ü");
	strFormatString = strFormatString.replace("&Uuml;","Ü");
	
	strFormatString = strFormatString.replace("&ccedil;","ç");
	strFormatString = strFormatString.replace("&Ccedil;","Ç");
	strFormatString = strFormatString.replace("&ordm;","º");
	strFormatString = strFormatString.replace("&ordf;","ª");
	
	return strFormatString;
	
}

//[INICIO] Script funcao ajax que abre respostas
function func_resposta(pergunta){
	for (i=1; i<=16; i++){
		if (i==pergunta){
			document.getElementById("funcoes_subtitulo_qdr"+i).className = "funcoes_subtitulo_qdr_dn";
		} else {
			document.getElementById("funcoes_subtitulo_qdr"+i).className = "funcoes_subtitulo_qdr_up";
		}
	}
	ajax = getBrowser();
	if(ajax){
		ajax.open("GET","/co-piloto/v1/_ajax/func_ajax.asp?conteudo=item"+pergunta, true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState != 4){
				document.getElementById("funcoes_item"+pergunta).innerHTML = "Carregando...";
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200) {
					for (i = 1; i <= 16; i++){
						if (i != pergunta)
							document.getElementById("funcoes_item"+i).style.display = 'none';
						else
							document.getElementById("funcoes_item"+i).style.display = '';
					}
					document.getElementById("funcoes_item"+pergunta).innerHTML = ajax.responseText;
       			} else {
					//document.getElementById("divID").innerHTML = "Não encontrado!"
					alert("Erro! Não foi possível carregar a resposta");
      			}
			}
		}
		ajax.send(null);
	}
}
//[FIM] Script funcao ajax que abre respostas

//[INICIO] Check cadastro
function func_checkCadastro(extCmpNome, extDivNome, campo, nomeBT){
	//alert(extCmpNome+"\n"+extDivNome+"\n"+campo+"\n"+nomeBT)
	valor = document.getElementById(extCmpNome).value;
	var divUser;
	var divEmail;
	ajax = getBrowser();
	if(ajax){
		ajax.open("GET","/co-piloto/v1/_ajax/func_ajax.asp?acao=checkCadastro&vlrCampo="+valor+"&campo="+campo, true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState != 4){
				//document.getElementById(extCmpNome).innerHTML = "Carregando...";
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200) {
					var check = ajax.responseText;
					if(check == "1"){ //já existe o email
						document.getElementById(extDivNome).style.display = ''
						document.getElementById(extDivNome).innerHTML = "E-mail já existe"
						document.getElementById(nomeBT).style.display = 'none'
						divEmail = "aberto"

					}else if(check == "2"){ //já existe o usuario
						document.getElementById(extDivNome).style.display = ''
						document.getElementById(extDivNome).innerHTML = "Usuário já existe"
						document.getElementById(nomeBT).style.display = 'none'
						 divUser = "aberto"
						
					}else{
						if(campo == "email"){
							divEmail = ""	
						}
						if(campo == "usuario"){
							divUser = ""
						}
						if(divEmail != "aberto" && divUser != "aberto"){
							//alert(divEmail+"\n"+divUser)
							document.getElementById(nomeBT).style.display = ''
						}
						document.getElementById(extDivNome).style.display = 'none'
					}
       			} else {
					document.getElementById(extCmpNome).value = ajax.responseText;
      			}
			}
		}
		ajax.send(null);
	}
}
//[FIM] Check cadastro

//[INICIO] onde_encontrar.asp
function lojas(estados){
	valor = document.getElementById("estados").value;
	document.getElementById("ondeEncontrar_results").style.display = 'none'
	ajax = getBrowser();
	if(ajax){
		ajax.open("GET","/co-piloto/v1/_ajax/func_ajax.asp?acao=ondeEncontrar&n="+valor, true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState != 4){
				document.getElementById("idCidade").innerHTML = "Carregando...";
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200) {
					 document.getElementById("idCidade").innerHTML =  ajax.responseText;
       			} else {
					document.getElementById("idCidade").innerHTML = ajax.responseText;
      			}
			}
		}
		ajax.send(null);
	}
}

//Seleciona a loja
function lojas_2(buscaLoja){
	valor = document.getElementById("buscaLoja").value;
	document.getElementById("ondeEncontrar_results").style.display = ''
	ajax = getBrowser();
	if(ajax){
		ajax.open("GET","/co-piloto/v1/_ajax/func_ajax.asp?acao=Loja&n="+valor, true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState == 1){
				document.getElementById("ondeEncontrar_results").innerHTML = "Carregando...";
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200) {
					 document.getElementById("ondeEncontrar_results").innerHTML = ajax.responseText;
       			} else {
					document.getElementById("ondeEncontrar_results").innerHTML= ajax.responseText;
      			}
			}
		}
		ajax.send(null);
	}
}
//[FIM] onde_encontrar.asp

//[INICIO] Seleciona o romaneio do meus pedidos
function func_mostraRomaneio(divID, nPedido, imgSeta){
	//alert(divID+"\n"+nPedido+"\n"+imgSeta)
	ajax = getBrowser();
	if(ajax){
		
		document.getElementById(imgSeta).src = "/co-piloto/v1/img/gif/icon_seta_azul_down.gif";
		
		ajax.open("GET","/co-piloto/v1/_ajax/func_ajax.asp?acao=meusPedidos&numero_pedido="+nPedido, true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState == 1){
				document.getElementById(divID).innerHTML = "Carregando...";
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200) {
					 document.getElementById(divID).innerHTML = ajax.responseText;
       			} else {
					 document.getElementById(divID).innerHTML= ajax.responseText;
      			}
			}
		}
		ajax.send(null);
	}
}
//[FIM] Seleciona o romaneio do meus pedidos

//[INICIO] Seleciona o endereço (entrega.asp)
function func_checkEndereco(){
	cmpCEP1 = document.getElementById("cmpCEP1").value;
	cmpCEP2 = document.getElementById("cmpCEP2").value;
	
	//ajax = redirect();
	ajax = getBrowser();
	if(ajax){
		ajax.open("GET","/co-piloto/v1/_ajax/func_ajax.asp?acao=checkEndereco&cmpCEP1="+cmpCEP1+"&cmpCEP2="+cmpCEP2, true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState != 4){
				document.getElementById("divID").innerHTML = "Carregando...";
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200) {
					 document.getElementById("divID").innerHTML =  ajax.responseText;

       			} else {
					document.getElementById("divID").innerHTML = ajax.responseText;

      			}
			}
		}
		ajax.send(null);
	}
}
//[FIM] Seleciona o endereço (entrega.asp)

//[INICIO] Seleciona o endereço (entrega.asp)
function func_registarCoPiloto(){
	
	//ajax = redirect();
	ajax = getBrowser();
	if(ajax){
		ajax.open("GET","/co-piloto/v1/_ajax/func_ajax.asp?acao=formRegistrarCoPiloto", true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState != 4){
				document.getElementById("divAparecForm").innerHTML = "Carregando...";
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200) {
					 document.getElementById("divAparecForm").innerHTML =  ajax.responseText;

       			} else {
					document.getElementById("divAparecForm").innerHTML = ajax.responseText;

      			}
			}
		}
		ajax.send(null);
	}
}
//[FIM] Seleciona o endereço (entrega.asp)


//[INICIO] função para validar o formulario de meus dados
function validaCadastroMeusDados (){
	dc = document.form1;

	if (dc.cmpNome.value == ""){
		alert ("Preencha o campo nome");
		dc.cmpNome.focus();
		return false;
	}
	if (!validaEmail(dc.cmpEmail)){
		return false;
	}
	//VALIDA O CNPJ OU CPF
	if(dc.tipoDoc.value == "cnpj"){
		if (!validaCNPJ(dc.documento)){
			return false;
		}
	}else{
		if (dc.documento.value == ""){
			alert ("Preencha o campo CPF");
			dc.documento.focus();
			return false;
		}
	}
	//FIM
	if (dc.cmpUsuario.value == ""){
		alert ("Preencha o campo usuário");
		dc.cmpUsuario.focus();
		return false;
	}
	/*if (dc.cmpSenha.value == ""){
		alert ("Preencha o campo senha");
		dc.cmpSenha.focus();
		return false;
	}*/
	/*if (dc.cmpConfirmSenha.value == ""){
		alert ("Redigite sua senha no campo Confirme sua senha");
		dc.cmpConfirmSenha.focus ();
		return false;
	}*/
	
	if(dc.cmpSenha.value != ""){
		if (dc.cmpSenha.value != dc.cmpConfirmSenha.value){
			alert ("A senha do campo Confirme sua senha deve ser a mesma do campo Senha");
			dc.cmpConfirmSenha.select();
			return false;
		}
	}
	
	if (dc.cmpDia.value == ""){
		alert ("Escolha o dia correspondente ao seu nascimento");
		dc.cmpDia.focus();
		return false;
	}
	if (dc.cmpMes.value == ""){
		alert ("Escolha o mês correspondente ao seu nascimento");
		dc.cmpMes.focus();
		return false;
	}
	if (dc.cmpAno.value == ""){
		alert ("Escolha o ano correspondente ao seu nascimento");
		dc.cmpAno.focus();
		return false;
	}
	if (!validaCEP(dc.cmpCEP1, dc.cmpCEP2)){
		return false;
	}
	if (dc.cmpEndereco.value == ""){
		alert ("Preencha o campo Endereço");
		dc.cmpEndereco.focus();
		return false;
	}
	if (dc.cmpBairro.value == ""){
		alert ("Preencha o campo Bairro");
		dc.cmpBairro.focus();
		return false;
	}
	if (dc.cmpCidade.value == ""){
		alert ("Preencha o campo Cidade");
		dc.cmpCidade.focus();
		return false;
	}
	if (dc.cmpUF.value == ""){
		alert ("Selecione a sigla correspondente ao seu Estado");
		dc.cmpUF.focus();
		return false;
	}
	if (!validaDDD(dc.cmpDDD)){
		return false;
	}
	if (dc.cmpTelefone.value == ""){
		alert ("Preencha o campo Telefone");
		dc.cmpTelefone.focus();
		return false;
	}
	
	dc.submit();
}
//[FIM] função para validar o formulario de meus dados

//[INICIO]
function validaSerial(){
	document.formSerial.submit();	
}
//[FIM]


//[INICIO] função ajax para verificar País no formulário
//criando variável global para poder reutilizar o codigo em outra posição do form
var localSite = "";
var paginaProcessa = "";
var conteudo = "";
var numeroVezes = 1;

function verificaPais(valor)
{
//Instânciando o objeto xmlHTTP
ajax=getBrowser();

//Fazendo a consistencia do objeto
if (ajax==null)
  {
    alert ("Seu navegador não suporta AJAX!");
	return;
  }

//Página de processamento que gera o resultado para o objeto xmlHTTP
var url=paginaProcessa+valor+"&conteudo="+conteudo+"&numero="+numeroVezes;

//Setando a chamada para uma função que direcionara a saida quando estiver pronto o processamento
ajax.onreadystatechange=ajaxCarregado;

//Metodos de chamada à página de processamento
ajax.open("GET",url,true);
ajax.send(null);

}

function ajaxCarregado()
{
  if(ajax.readyState != 4){
      document.getElementById(localSite).innerHTML="Carregando...";	  
  }  	
  if (ajax.readyState == 4)
  {
    if(ajax.status == 200) {	  
      document.getElementById(localSite).innerHTML=ajax.responseText;
	}else{
      document.getElementById(localSite).innerHTML=ajax.responseText;		
	}
  }
}

function trocaPais(str,str2,str3,str4)
{
    var nome = str;
	var valor = str2;

	if(valor == "Brasil" && nome == "cmpPaisEndereco"){
		document.forms[0].cmpDDITel.value = "55";
	}
    if(valor != "Brasil" && nome == "cmpPaisEndereco")
	{
		document.forms[0].cmpDDITel.value = "DDI";
	}

	
	if(nome == "cmpPaisEndereco"){
	  paginaProcessa = "/grupo-ornatus/v1/br/_ajax/ficha-franquia-pais-origem.asp?valor=";
	  localSite = "FichaQualPais1";
	  conteudo = str3;
	  numeroVezes = str4;
	  verificaPais(valor);
	}else{
	  paginaProcessa = "/grupo-ornatus/v1/br/_ajax/ficha-franquia-pais-destino.asp?valor=";
	  localSite = "FichaQualPais2";
	  conteudo = str3;
	  numeroVezes = str4;
	  verificaPais(valor);
	}

}
//[FIM]

//[INICIO] função clone para solucionar bug ajax que nunca para de carregar
function verificaPais2(valor)
{
//Instânciando o objeto xmlHTTP
ajax2=getBrowser();

//Fazendo a consistencia do objeto
if (ajax2==null)
  {
    alert ("Seu navegador não suporta AJAX!");
	return;
  }

//Página de processamento que gera o resultado para o objeto xmlHTTP
var url="/grupo-ornatus/v1/br/_ajax/ficha-franquia-pais-origem.asp?valor=";
url= url+valor+"&conteudo="+conteudo+"&numero=2";

//Setando a chamada para uma função que direcionara a saida quando estiver pronto o processamento
ajax2.onreadystatechange=ajaxCarregado2;

//Metodos de chamada à página de processamento
ajax2.open("GET",url,true);
ajax2.send(null);

}

function ajaxCarregado2()
{
  if(ajax2.readyState != 4){
      document.getElementById("FichaQualPais1").innerHTML="Carregando...";	  
  }  	
  if (ajax2.readyState == 4)
  {
    if(ajax2.status == 200) {	  
      document.getElementById("FichaQualPais1").innerHTML=ajax2.responseText;
	}else{
      document.getElementById("FichaQualPais1").innerHTML=ajax2.responseText;		
	}
  }
}

function trocaPais2(str,str2,str3,str4)
{
    var nome = str;
	var valor = str2;
	  conteudo = str3;
	  verificaPais2(valor);

}
//[FIM]


//[INICIO] função exibeCampos
function exibeCampos(str,str2)
{
  if(str == 0){
	document.getElementById(str2).style.display = "none";
  }else{
	document.getElementById(str2).style.display = "inline";
  }
}
//[FIM]

//[INICIO] função que permite apenas números
function soNumeros()
{
   var Keycode = window.event.keyCode;
    if ((Keycode > 47 && Keycode < 58) || (Keycode > 95 && Keycode < 106) || (Keycode == 8) || (Keycode == 9) || (Keycode == 46) || (Keycode == 37) || (Keycode == 38) || (Keycode == 39) || (Keycode == 36) || (Keycode == 35)) { 

      return true;
    }else{
	  return false;
    }
}
//[FIM]