//---------------------------------------Funções em geral-----------------------------------------



function carregar_troller(){
	var url;
	url = 'cep_form.asp?cep='+document.cad_usuarios.cep.value;
		//document.tracking.destinatario.options.length = 0;
		//addItem(document.tracking.destinatario2,"Aguarde...carregando","",false,document.tracking.destinatario2.length)
		cep.location = url;
		//tracking.Teste.Cidades.focus()
}






function formatar(src, mask){
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
		if (texto.substring(0,1) != saida) 
		{
			src.value += texto.substring(0,1);
		}
	}


function checaCadastro(){
	with(document.frmenvtra){
		if(nome.value == ""){
			alert("Digite seu nome");
			nome.focus();
			return(false);			
		}

		if(email.value == ""){
			alert("Digite um e-mail");
			email.focus();
			return(false);
		}else{
			 if(email.value.search("@") == -1 || email.value.search(".") == -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();
				email.select();
				return false;
				}
					if(email.value.indexOf(" ") != -1) {
						alert("O e-mail informado parece não estar correto.");
						email.focus();
						email.select();
						return false;
					}
						if(email.value.indexOf("zipmeil.com") > 0) {
							alert("O e-mail informado parece não estar correto.");
							email.focus();
							email.select();
							return false;
						}
							if(email.value.indexOf("hotmeil.com") > 0) {
								alert("O e-mail informado parece não estar correto.");
								email.focus();
								email.select();
								return false;
							}

								if(email.value.indexOf(".@") > 0) {
									alert("O e-mail informado parece não estar correto.");
									email.focus();
									email.select();
									return false;
								}
									if(email.value.indexOf("@.") > 0) {
										alert("O e-mail informado parece não estar correto.");
										email.focus();
										email.select();
										return false;
									}
										if(email.value.indexOf(".com.br.") > 0) {
											alert("O e-mail informado parece não estar correto.");
											email.focus();
											email.select();
											return false;
										}
											if(email.value.indexOf("/") > 0) {
												alert("O e-mail informado parece não estar correto.");
												email.focus();
												email.select();
												return false;
											}
												if(email.value.indexOf("[") > 0) {
													alert("O e-mail informado parece não estar correto.");
													email.focus();
													email.select();
													return false;
												}
													if(email.value.indexOf("]") > 0) {
														alert("O e-mail informado parece não estar correto.");
														email.focus();
														email.select();
														return false;
													}
											if(email.value.indexOf("(") > 0) {
												alert("O e-mail informado parece não estar correto.");
												email.focus();
												email.select();
												return false;
											}
										if(email.value.indexOf(")") > 0) {
											alert("O e-mail informado parece não estar correto.");
											email.focus();
											email.select();
											return false;
										}
								if(email.value.indexOf("..") > 0) {
									alert("O e-mail informado parece não estar correto.");
									email.focus();
									email.select();
									return false;
								}
		if(contato.value == ""){
			alert("Digite Contato");
			contato.focus();
			return(false);
		}
		if(descreva.value == ""){
			alert("Descreva sua relação com a Marca Gato Preto");
			descreva.focus();
			return(false);
		}			
		if (nome.value.length < 10){
			alert('Número de Caracteres inválidos para a propriedade Nome');
			nome.focus();
			return(false);
			}
}		
	}
}


function combo()
{
	var f = document.frmContato;
//	if(f.area[f.area.selectedIndex].value == ''){
	if(f.area[0].selected == true){
	alert('Selecione uma Área');
	f.area.focus();
	return(false);}	
}




function ImprimirMapa(){
	var Mapa=window.open('imprimir_mapa.asp','Mapa','width=460,height=500,top=0,left=0,scrollbars=no');
	if (Mapa.focus != null) Mapa.focus();
}

function Mapa(){
	var Leading=window.open('mapa.htm','LEADING','width=460,height=500,top=5,left=5,scrollbars=no');
	if (Leading.focus != null) Leading.focus();
}

function PoliticaSite(){
	var politica=window.open('politica.htm','politica','width=400,height=400,top=5,left=5,scrollbars=yes');
	if (politica.focus != null) politica.focus();
}

function TermoUso(){
	var termo=window.open('termo.htm','termo','width=400,height=400,top=5,left=5,scrollbars=yes');
	if (termo.focus != null) termo.focus();
}


VerifiqueTAB=true;
function Mostra(quem, tammax) {
	if ( (quem.value.length == tammax) && (VerifiqueTAB) ) {
		var i=0,j=0, indice=-1;
		for (i=0; i<document.forms.length; i++) {
			for (j=0; j<document.forms[i].elements.length; j++) {
				if (document.forms[i].elements[j].name == quem.name) {
					indice=i;
					break;
				}
			}
			if (indice != -1)
		         break;
		}
		for (i=0; i<=document.forms[indice].elements.length; i++) {
			if (document.forms[indice].elements[i].name == quem.name) {
				while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
						(i < document.forms[indice].elements.length) ) {
							i++;
				}
				document.forms[indice].elements[(i+1)].focus();
				VerifiqueTAB=false;
				break;
			}
		}
	}
}

function PararTAB(quem) 
{ 
   VerifiqueTAB=false; 
} 

//<!-- -->

function ChecarTAB() 
{ 
   VerifiqueTAB=true; 
} 


function valida_CPF(obj){
//alert(obj);
	obj2 = obj.replace('.','');
	obj2 = obj2.replace('.','');	
	obj2 = obj2.replace('-','');	
//	alert(obj2);
s = obj2;
 if (isNaN(s)) {
 alert('CPF Inválido');
 document.all.cpf.focus();
  return false;
 }
 var i;
 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){
 alert('CPF Inválido');
 document.all.cpf.focus(); 
  return false;
 }         
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;         
 if (dv.charAt(0) != d1) {
 alert('CPF Inválido');
 document.all.cpf.focus(); 
  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 Inválido');
 document.all.cpf.focus(); 
	 return false;
    }
    return true;
} 
function val_cnpj()
{
//			alert(document.all.cnpj.value);
			d = document.all.cnpj;
			cnpj = document.all.cnpj.value;

				 erro = new String;
                 if (cnpj.length < 18)
				 alert("É necessario preencher corretamente o número do CNPJ!");
//				 document.all.cnpj.focus();
                 if ((cnpj.charAt(2) != ".") || (cnpj.charAt(6) != ".") || (cnpj.charAt(10) != "/") || (cnpj.charAt(15) != "-")){
                 if (erro.length == 0)
				 alert("É necessário preencher corretamente o número do CNPJ!");
//				 document.all.cnpj.focus();
                 }
                 //substituir os caracteres que não são números
                 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))
				 alert("A verificação de CNPJ suporta apenas números!");
//				 document.all.cnpj.focus();				 
                 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])){
                         alert("Dígito verificador com problema!");
						 return false;
        }
				 
}

