var req;
function loadXMLDoc(url){
 req = null;

if (window.XMLHttpRequest) {
 req = new XMLHttpRequest();
 req.onreadystatechange = processReqChange;
 req.open("GET", url, true); 
 req.send(null);

} else if (window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP.4.0");
} catch(e) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP.3.0");
} catch(e) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
req = false;
}
}
}
}
if (req) {
 req.onreadystatechange = processReqChange;
 req.open("GET", url, true);
 req.send();
}
}
}
function processReqChange(){

if(req.readyState == 1) {
document.getElementById("atualiza").innerHTML = "<font class='texto'>Aguarde.......</font>";
}

if (req.readyState == 4) {
if (req.status == 200) {

document.getElementById("atualiza").innerHTML = req.responseText;
} else {
alert("Houve um problema ao obter os dados:\n" + req.statusText);
}
}
}
function subtipos(valor){
loadXMLDoc("subtipos.php?cod_tipo="+valor);
}
function cidades(valor){
if(valor == "") { 
alert('Você precisa escolher um estado primeiro'); 
document.proposta.uf.focus();
} else { 
ajaxHTML("atualiza2","cidades.php?uf="+valor);
}
}
function pula(obj1, dest, num){
if (obj1.value.length==num){
obj2=obj1.form;
destino=eval("obj2."+dest);
destino.focus();
}
}
function pula2(destino){
destino.focus();
}
function checa() { 

if(document.proposta.nome.value !== "") { 
document.proposta.Submit.disabled = false;
} else { 
document.proposta.Submit.disabled = true;
}
}
 function completaTelefone(campo)
 {
      qtdcaracteres = (campo.value).length;
	  telefone = campo.value;

     if(qtdcaracteres == 4)
        campo.value = campo.value + "-";
 }
 function completaCEP(campo)
 {
      qtdcaracteres = (campo.value).length;
	  telefone = campo.value;
     if(qtdcaracteres == 5)
        campo.value = campo.value + "-";
 }
 function numerico(campo) { 

campo.value = campo.value.toLowerCase(); 

var caracteres = "abcdefghijklmnopqrstuvwxyzáéíóúàèìòùâêîôûäëïöüãõ@#$%^&*()_+=~` ç.\/[]{}<>?!|:;,"; 
var retorno  = ""; 

for(i=0;i<caracteres.length;i++) 
   { 
    
   for(j=0;j<campo.value.length;j++) 
      { 
      retorno = campo.value.replace(caracteres.substr(i,1),""); 
      campo.value = retorno; 
      } 
   } 

   
}

function valida_proposta() { 

if(document.proposta.nome.value == "") { 
alert('Digite seu nome');
document.proposta.nome.focus();
proposta.nome.style.backgroundColor = "#fffccc";
proposta.nome.style.borderColor = "#9C2C1F";	
return false;
}

if(document.proposta.email.value == "") { 
alert('Digite seu e-mail');
document.proposta.email.focus();
proposta.email.style.backgroundColor = "#fffccc";
proposta.email.style.borderColor = "#9C2C1F";	
return false;
}

if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(proposta.email.value)))  { 
alert("Preencha seu email corretamente");
document.proposta.email.focus();
proposta.email.style.backgroundColor = "#fffccc";
proposta.email.style.borderColor = "#9C2C1F";
return false;
}
if(document.proposta.mensagem.value == "") { 
alert('Digite sua proposta');
document.proposta.mensagem.focus();
proposta.mensagem.style.backgroundColor = "#fffccc";
proposta.mensagem.style.borderColor = "#9C2C1F";
return false;
}

if(document.proposta.mensagem.value == "Digite sua mensagem aqui") { 
alert('Digite sua mensagem');
document.proposta.mensagem.focus();
proposta.mensagem.style.backgroundColor = "#fffccc";
return false;
}
document.proposta.Submit.disabled = true;
document.proposta.Submit.value = 'Enviando mensagem...';
var conta = 0;
if (conta == 0){
conta++;
return true;
}
else {
alert("O formulário está sendo enviado...!");
return false;
}

document.proposta.submit();
}
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}

function fcs() { document.proposta.nome.focus(); }
function troca(campo){

campo.value = campo.value.toLowerCase();

var estranha = "áéíóúàèìòùâêîôûäëïöüãõ#,?{}^;<>!¨´[]:/'$%^&*()+=~` ç";
var correta  = "aeiouaeiouaeiouaeiouao________________c";
var retorno  = "";

for(i=0;i<estranha.length;i++)
   {
   
   for(j=0;j<campo.value.length;j++)
      {
      retorno = campo.value.replace(estranha.substr(i,1),correta.substr(i,1));
      campo.value = retorno;
      }
   }

  
}
function minuscula(campo) { 
campo.value = campo.value.toLowerCase(); 
}
function maiuscula(campo) { 
campo.value = campo.value.toUpperCase(); 
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			alert('radioObj.value');
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function xtipo3(valor) {
eval("location='?transacao="+valor+"'");
}
function xtipo4(valor) {
var transacao = getCheckedValue(document.forms['busca_avancada'].elements['transacao']);
eval("location='?cod_tipo="+valor+"&transacao="+transacao+"'");
}
function loadTipo(transacao,tipo,preco){
ajaxHTML("tipox","tipos.php?transacao="+transacao+"&tipo="+tipo);
ajaxHTML("precox","precos.php?transacao="+transacao+"&preco="+preco);
}
function loadDorm(cod_tipo,dormitorios){
ajaxHTML("dormitoriox","dormitorios.php?cod_tipo="+cod_tipo+"&dormitorios="+dormitorios);
}
function buscar() {
var transacao   = document.getElementById("transacao").value;
var tipo        = document.getElementById("tipo").value;
var preco       = document.getElementById("preco").value;
var dormitorios = document.getElementById("dormitorios").value;
if(document.getElementById("referencia").value != "" && document.getElementById("referencia").value != "Digite a referência") { var referencia = document.getElementById("referencia").value; }

eval("location='resultado_busca.php?tipo="+tipo+"&transacao="+transacao+"&preco="+preco+"&dormitorios="+dormitorios+"&referencia="+referencia+"'");
}
function valida_contato() {
if(document.getElementById("nome").value == "") { 
alert('Digite seu nome.');
document.getElementById("nome").focus();
return false;
}
if(document.getElementById("email").value == "") { 
alert('Digite seu email.');
document.getElementById("email").focus();
return false;
}
if(document.getElementById("telefone").value == "") { 
alert('Digite seu telefone.');
document.getElementById("telefone").focus();
return false;
}
if(document.getElementById("cidade").value == "") { 
alert('Digite sua cidade.');
document.getElementById("cidade").focus();
return false;
}
if(document.getElementById("mensagem").value == "") { 
alert('Digite sua mensagem.');
document.getElementById("mensagem").focus();
return false;
}
document.getElementById("contato").submit();
}
function valida_newsletter() {
if(document.getElementById("nome").value == "" || document.getElementById("nome").value == " Nome completo ") { 
alert('Digite seu nome.');
document.getElementById("nome").value='';
document.getElementById("nome").focus();
return false;
}
if(document.getElementById("email").value == "" || document.getElementById("email").value == " E-mail ") { 
alert('Digite seu e-mail.');
document.getElementById("email").value='';
document.getElementById("email").focus();
return false;
}
document.newsletter.submit();
}