// JavaScript Document

// MOUSE OVER DE IMAGENS EM MENUS ...
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->


// CARREGA E EXECUTA O OBJETO AJAX

try{
xmlhttp = new XMLHttpRequest();}catch(ee){try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
catch(E){xmlhttp = false;}}}

function destaqueCarregaImg(img){
	document.getElementById('destaqueImgMaior').innerHTML = '<img src="'+img+'">';
}

//// Destaque

function SelecionaDestaque(cod) {
	for (var i=1;i<=4;i++) {
		if (document.getElementById('home-destaque-'+i)) {
 			document.getElementById('home-destaque-'+i).className='destaque_off';
 			document.getElementById('home-destaque-conteudo-'+i).style.display='none';
			if (i==cod) {
				document.getElementById('home-destaque-'+i).className='destaque_on';
	 			document.getElementById('home-destaque-conteudo-'+i).style.display='block';
			}
		
		}
	}

}

/// CADASTRO - USUÁRIO SITE

// pop-up cep
function abrirPopup(){
	var page = "verifycep.asp?cepverify="+document.getElementById('cep').value;
	window.open(page,'cep','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=400');

}

//valida o cpf
  function remove(str, sub) {
    i = str.indexOf(sub);
    r = "";
    if (i == -1) return str;
    r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
    return r;
  }
 function validarCPF(){
    var cpf = document.formcadastro.cpfcnpj.value;
    var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
    var valid
    valid = document.formcadastro.cpfcnpj;
    if(!filtro.test(cpf)){
      window.alert("CPF inválido!!!\n\n É necessarios preencher corretamente o numero do CPF.");
 	valid.focus();
      document.formcadastro.cpfcnpj.value="";
 	 return false;
 	 
    }
    
    cpf = remove(cpf, ".");
    cpf = remove(cpf, "-");
     
    if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
 	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
 	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
 	  cpf == "88888888888" || cpf == "99999999999"){
 	  window.alert("CPF inválido. Tente novamente.");
 	  valid.focus();
      document.formcadastro.cpfcnpj.value="";
 	  return false;
    }
 
    soma = 0;
    for(i = 0; i < 9; i++)
    	 soma += parseInt(cpf.charAt(i)) * (10 - i);
    resto = 11 - (soma % 11);
    if(resto == 10 || resto == 11)
 	 resto = 0;
    if(resto != parseInt(cpf.charAt(9))){
      window.alert("CPF inválido!!!\n\n É necessario preencher corretamente o número do CPF.");
 	 valid.focus();
      document.formcadastro.cpfcnpj.value="";
 	 return false;
    }
    soma = 0;
    for(i = 0; i < 10; i ++)
 	 soma += parseInt(cpf.charAt(i)) * (11 - i);
    resto = 11 - (soma % 11);
    if(resto == 10 || resto == 11)
 	 resto = 0;
    if(resto != parseInt(cpf.charAt(10))){
      window.alert("CPF inválido!!!\n\n É necessario preencher corretamente o número do CPF.");
 	 valid.focus();
      document.formcadastro.cpfcnpj.value="";
 	 return false;
    }
    return true;
  }


 //function confirmaSenha(){
  //	  if (document.formcadastro.senha.value != document.formcadastro.confirma.value )
 //	  {
//	     alert('A Confirmação é diferente da senha preenchida.');
//		 document.formcadastro.senha.value="";
//		 document.formcadastro.confirma.value="";
//		 document.formcadastro.senha.focus();
//		 return false;
//	  }
//	      return true;
 //}



// valida form

function validaCPFresp(){ 
  
    var cpf = document.formcadastro.cpfresp.value;
    var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
    var valid
    valid = document.formcadastro.cpfresp;
    if(!filtro.test(cpf)){
//      window.alert("CPF inválido!!!\n\n É necessarios preencher corretamente o numero do CPF.");
// 	valid.focus();
      document.formcadastro.cpfresp.value="";
 	 return false;
 	 
    }
    
    cpf = remove(cpf, ".");
    cpf = remove(cpf, "-");
     
    if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
 	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
 	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
 	  cpf == "88888888888" || cpf == "99999999999"){
// 	  window.alert("CPF inválido!");
// 	  valid.focus();
      document.formcadastro.cpfresp.value="";
 	  return false;
    }
 
    soma = 0;
    for(i = 0; i < 9; i++)
    	 soma += parseInt(cpf.charAt(i)) * (10 - i);
    resto = 11 - (soma % 11);
    if(resto == 10 || resto == 11)
 	 resto = 0;
    if(resto != parseInt(cpf.charAt(9))){
//      window.alert("CPF inválido!");
// 	 valid.focus();
      document.formcadastro.cpfresp.value="";
 	 return false;
    }
    soma = 0;
    for(i = 0; i < 10; i ++)
 	 soma += parseInt(cpf.charAt(i)) * (11 - i);
    resto = 11 - (soma % 11);
    if(resto == 10 || resto == 11)
 	 resto = 0;
    if(resto != parseInt(cpf.charAt(10))){
//      window.alert("CPF inválido!");
// 	 valid.focus();
      document.formcadastro.cpfresp.value="";
 	 return false;
    }
    return true;
  }


// valida cnpj

function ValidarCNPJ(ObjCnpj){
    var cnpj = ObjCnpj.value;
    var valida = new Array(6,5,4,3,2,9,8,7,6,5,4,3,2);
    var dig1= new Number;
    var dig2= new Number;
    
    exp = /\.|\-|\//g
    cnpj = cnpj.toString().replace( exp, "" ); 
    var digito = new Number(eval(cnpj.charAt(12)+cnpj.charAt(13)));
        
    for(i = 0; i<valida.length; i++){
        dig1 += (i>0? (cnpj.charAt(i-1)*valida[i]):0);    
        dig2 += cnpj.charAt(i)*valida[i];    
    }
    dig1 = (((dig1%11)<2)? 0:(11-(dig1%11)));
    dig2 = (((dig2%11)<2)? 0:(11-(dig2%11)));
    
    if(((dig1*10)+dig2) != digito || cnpj == "00000000000000")    
		document.formcadastro.cpfcnpj.value="";
		if (cnpj == "00000000000000" ){
		document.formcadastro.cpfcnpj.value="";
		return false;
		}
		if (cnpj == "11111111111111" ){
		document.formcadastro.cpfcnpj.value="";
		return false;
		}
		if (cnpj == "22222222222222" ){
		document.formcadastro.cpfcnpj.value="";
		return false;
		}
		if (cnpj == "33333333333333" ){
		document.formcadastro.cpfcnpj.value="";
		return false;
		}
		if (cnpj == "44444444444444" ){
		document.formcadastro.cpfcnpj.value="";
		return false;
		}
		if (cnpj == "55555555555555" ){
		document.formcadastro.cpfcnpj.value="";
		return false;
		}
		if (cnpj == "66666666666666" ){
		document.formcadastro.cpfcnpj.value="";
		return false;
		}
		if (cnpj == "77777777777777" ){
		document.formcadastro.cpfcnpj.value="";
		return false;
		}
		if (cnpj == "88888888888888" ){
		document.formcadastro.cpfcnpj.value="";
		return false;
		}
		if (cnpj == "99999999999999" ){
		document.formcadastro.cpfcnpj.value="";
		return false;
		}
}


//validação senha
function confirmaUpSenha(){
	if (document.formaltsenha.senha_new.value != document.formaltsenha.conf_senha.value )
	{
	 alert('A Confirmação é diferente da senha preenchida.');
	 document.formaltsenha.senha_new.value="";
	 document.formaltsenha.conf_senha.value="";
	 document.formaltsenha.senha_new.focus();
	 return false;
	}
	return true;
 }
 
  function confirmaSenha(){
	if (document.formcadastro.senha.value != document.formcadastro.confirma.value )
	{
	 alert('A Confirmação é diferente da senha preenchida.');
	 document.formcadastro.senha.value="";
	 document.formcadastro.confirma.value="";
	 document.formcadastro.senha.focus();
	 return false;
	}
	return true;
 }
	
	function valEmail2(){
	if (document.formcadastro.email2.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
	{
		//alert("Preencha um email válido.");
		document.formcadastro.email2.value="";
		document.formcadastro.email2.value="";
//		document.formcadastro.email2.focus();
		return false;
	}
	return true;
	}

//Validar campos do formulario contato anuncio
   function validaContatoAnuncio()
   {
      if (document.formContato.interessado.value == '')
	  {
	     alert('Preencha seu nome.');
		 document.formContato.interessado.focus();
		 return false;
	  }
	  if (document.formContato.email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
	  {
		  alert("Preencha seu Email.");
		  document.formContato.email.focus();
		  return false;
	  }
      if (document.formContato.fone.value == '')
	  {
	     alert('Preencha seu telefone.');
		 document.formContato.fone.focus();
		 return false;
	  }
      if (document.formContato.mensagem.value == '')
	  {
	     alert('Preencha a mensagem.');
		 document.formContato.mensagem.focus();
		 return false;
	  }
	  return true;
   }

maxL=400;
function taLimit(taObj) {
	if (taObj.value.length==maxL) return false;
	return true;
}

function taCount(taObj,Cnt) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) objCnt.innerText=maxL-objVal.length;
	return true;
}
function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}

