//Botao rollover
function func_btMenu( nomeBt, nomeImg){
		document.getElementById(""+nomeBt+"").src = nomeImg;
}

//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

//Script para validacao de formulario, conforme necessario incluir mais "If's" para validar mais campos
function validaForm(){
	var dc = document.form
	if(dc.campo1.value==""){
			alert("Preencha o campo campo1")
			dc.campo1.focus()
			return false;
	}
	
	if(dc.campo2.value==""){
			alert("Preencha o campo campo2")
			dc.campo2.focus()
			return false;
	}
}
//Fim script para validar formulario

//Script para validacao de email
function validaEmail(email){
	if(email.value == ""){
		alert("Please, fill up the E-mail field.")
		email.focus();
		return false;
	}
		if(email.value.indexOf("@", email.value.indexOf("@") + 1 ) != -1) {
			alert("E-mail seems not to be correct.");
			email.select();
			return false;
		}
		if(email.value.indexOf(".") < 1) {
			alert("E-mail seems not to be correct.");
			email.select();
			return false;
		}
		if(email.value.indexOf(" ") != -1) {
			alert("E-mail seems not to be correct.");
			email.select();
			return false;
		}
		if(email.value.indexOf(".@") > 0) {
			alert("E-mail seems not to be correct.");
			email.select();
			return false;
		}
		if(email.value.indexOf("@.") > 0) {
			alert("E-mail seems not to be correct.");
			email.select();
			return false;
		}
		if(email.value.indexOf(".com.br.") > 0) {
			alert("E-mail seems not to be correct.");
			email.select();
			return false;
		}
		if(email.value.indexOf("/") > 0) {
			alert("E-mail seems not to be correct.");
			email.select();
			return false;
		}
		if(email.value.indexOf("[") > 0) {
			alert("E-mail seems not to be correct.");
			email.select();
			return false;
		}
		if(email.value.indexOf("]") > 0) {
			alert("E-mail seems not to be correct.");
			email.select();
			return false;
		}
		if(email.value.indexOf("(") > 0) {
			alert("E-mail seems not to be correct.");
			email.select();
			return false;
		}
		if(email.value.indexOf(")") > 0) {
			alert("E-mail seems not to be correct.");
			email.select();
			return false;
		}
		if(email.value.indexOf("..") > 0) {
			alert("E-mail seems not to be correct.");
			email.select();
			return false;
		}
		return true;
}

function valida(){
	var dc = document.form1
	if(dc.cmpNome.value==""){
		alert("Please, fill up the name field.")
		dc.cmpNome.focus()
		return false;
	}
	//valida Email
	var ss = validaEmail(dc.email);
	if (ss==false){
		return false;
	}
	
	if(dc.cmpAssunto.value==""){
		alert("Please, fill up the subject field.")
		dc.cmpAssunto.focus()
		return false;
	}
	
	if(dc.cmpMensagem.value==""){
		alert ("You have typed no message.\n"+
			   "Please, fill up the message text area.");
		dc.cmpMensagem.focus()
		return false;
	}
	
	/*valida  CPF
	var varCpf = validacpf(dc.cpf);
	if(varCpf == false){
		return false;
	}*/
}		
//Fim do Script para validacao de email

function validaNewsLetter(){
	var dc = document.form1
	if (dc.nltNome.value == ""){
		alert ("Please, fill up the Your Name field.");
		dc.nltNome.focus ();
		return false;
	}
	if (dc.nltEmail.value == ""){
		alert ("Please, fill up the E-mail field.");
		dc.nltEmail.focus ();
		return false;
	}
	if (!validaEmail(dc.nltEmail)){
		return false;
	}
	if (dc.mm.value != ""){
		
	
		if (dc.mm.value <=0 || dc.mm.value >=13){
			alert ("Invalid month.\n"+
				   "The number must be between 01 and 12.");
			dc.mm.select();
			return false;
		}
	}
	if (dc.dd.value != ""){

		if (dc.dd.value <=0 || dc.dd.value >= 32){
			alert ("Invalid day.\n"+
				   "The number must be between 01 and 31.");
			dc.dd.select ();
			return false;
		}
	}
	/*if (dc.yyyy.value == ""){
		alert ("Please, fill the year field.");
		dc.yyyy.value.focus();
		return false;
	}*/
}
		
//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
//Script funcao ajax que interage
function lojas(estados){
	valor = document.getElementById("estados").value;
	//ajax = redirect();
	ajax = getBrowser();
	if(ajax){
		ajax.open("GET","/website/lojas_ajax.asp?acao=Cidades&n="+valor, true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState != 4){
				//divID.innerHTML = "Carregando...";
				document.getElementById("divID").innerHTML = "Carregando...";
				//document.getElementById("divID").childNodes[0].nodeValue = "Carregando..."
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200) {
					// divID.innerHTML = ajax.responseText;
					 document.getElementById("divID").innerHTML =  ajax.responseText;
					 //document.getElementById("divID").childNodes[0].nodeValue = ajax.responseText;
       			} else {
         			//alert(ajax.statusText);
					//divID.innerHTML = "Não encontrado!"
					document.getElementById("divID").innerHTML = "Não encontrado!"
					//document.getElementById("divID").childNodes[0].nodeValue = "Não encontrado!";
      			}
			}
		}
		ajax.send(null);
	}
}
//Fim do Script funcao ajax que interage


//[INICIO] função para preencha comboBox ou Select
function funcBuscaCidade(){
	valor = document.getElementById("estado").value;
	var cmpCidade = document.getElementById("cidade")
	var i;
	ajax = getBrowser();
	if(ajax){
		ajax.open("GET","/v2/_ajax/func_ajax.asp?acao=buscaCidade&estado="+valor, true);
		ajax.onreadystatechange = function(){
			if(ajax.readyState != 4){
				for(i=0; i < cmpCidade.length; i++){
					cmpCidade.options[0] = null	
				}
				cmpCidade.options[0] = new Option("Loading...","Loading...");
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200) {
					 cmpCidade.options[0] = new Option("Selecione a cidade","")
					 //colocando o ajax.responseText no comboBox;
					 var lCity = eval(ajax.responseText)
					 for(i=0; i<lCity.length;i++){
						 lCity[i] = unescape(lCity[i]);
					 	cmpCidade.options[cmpCidade.options.length] = new Option(lCity[i],lCity[i]);
					 }
       			} else {
					cmpCidade.options[0] = new Option("Erro ao selecionar...","vazio");
      			}
			}
		}
		ajax.send(null);
	}
}
//[FIM] função para preencha comboBox ou Select

//[início] função para abrir layers
var totalDesc = 0   //total de sublayers da div description
var totalStruct = 4 //total de sublayers da div structure
var totalSup = 7    //total de sublayers da div support
var totalMaps = 2   //total de sublayers da div maps_mapbase
function abreHide(top, param){
/*
top = opcao principal -> description, structure, support
param = layers internos as opcoes principais
*/
var ss = Array ("description", "structure", "support")
	if (top == "description"){
		for (i=0; i<3; i++){
			if (ss[i] == top){
				document.getElementById(ss[i]).style.display = '';
				document.getElementById('toplink'+i).className='toplink_lock';
				continue;
			}else{
				document.getElementById(ss[i]).style.display = 'none';
				document.getElementById('toplink'+i).className='toplink';
			}
		}
		for (i=1; i<=totalDesc; i++){
			if (i!=param){
				document.getElementById('layer'+i).style.display = 'none';
				document.getElementById('sublinkds'+i).className='sublink';
			}else{
			document.getElementById('layer'+i).style.display = '';
			document.getElementById('sublinkds'+i).className = 'sublink_lock';
			}
		}
	}
	if (top == "structure"){
		for (i=0; i<3; i++){
			if (ss[i] == top){
				document.getElementById(ss[i]).style.display = '';
				document.getElementById('toplink'+i).className='toplink_lock';
				continue;
			}else{
				document.getElementById(ss[i]).style.display = 'none';
				document.getElementById('toplink'+i).className='toplink';
			}
		}
		for (i=1; i<=totalStruct; i++){
			if (i!=param){
				document.getElementById('layer'+i).style.display = 'none';
				document.getElementById('sublinkst'+i).className='sublink';
			}else{
			document.getElementById('layer'+i).style.display = '';
			document.getElementById('sublinkst'+i).className = 'sublink_lock';
			}
		}
	}
	if (top == "support"){
		for (i=0; i<3; i++){
			if (ss[i] == top){
				document.getElementById(ss[i]).style.display = '';
				document.getElementById('toplink'+i).className='toplink_lock';
				continue;
			}else{
				document.getElementById(ss[i]).style.display = 'none';
				document.getElementById('toplink'+i).className='toplink';
			}
		}
		for (i=1; i<=totalSup; i++){
			if (i!=param){
				document.getElementById('sup'+i).style.display = 'none';
				document.getElementById('sublinksp'+i).className='sublink';
			}else{
			document.getElementById('sup'+i).style.display = '';
			document.getElementById('sublinksp'+i).className = 'sublink_lock';
			}
		}
	}
	if (top == "maps"){
		for (i=1; i<=totalMaps; i++){
			if (i!=param){
				document.getElementById('layer'+i).style.display = 'none';
				document.getElementById('sublinkmp'+i).className='maplink';
				document.getElementById('ggmaps'+i).style.display = 'none';
			}else{
			document.getElementById('layer'+i).style.display = '';
			document.getElementById('sublinkmp'+i).className = 'maplink_lock';
			document.getElementById('ggmaps'+i).style.display = '';
			}
		}
	}
}
//[fim] função para abrir layers
