function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MRP_over(src,clrOver)
{
	if (!src.contains(event.fromElement))
	{
		src.style.cursor = 'hand';
		src.bgColor = clrOver;
	}
}

function MRP_out(src,clrIn)
{
	if (!src.contains(event.toElement))
	{
		src.style.cursor = 'default';
		src.bgColor = clrIn;
	}
}

function ValidaContato(){
	if (document.formContato.nome.value == ""){
		alert("Digite o seu nome"); document.formContato.nome.focus(); 
		return (false); 
	}
	if (document.formContato.email.value == ""){
		alert("Digite o seu e-mail"); document.formContato.email.focus(); 
		return (false)
	}
	if (document.formContato.assunto.value == ""){
		alert("Digite o assunto"); document.formContato.assunto.focus(); 
		return (false)
	}
	if (document.formContato.mensagem.value == ""){
		alert("Digite a mensagem"); document.formContato.mensagem.focus(); 
		return (false)
	}
	return (true);
}

function ValidaAnuncie(){
	if (document.formAnuncie.nome.value == ""){
		alert("Digite o seu nome"); document.formAnuncie.nome.focus(); 
		return (false); 
	}
	if (document.formAnuncie.telefone.value == ""){
		alert("Digite o seu telefone"); document.formAnuncie.telefone.focus(); 
		return (false); 
	}
	if (document.formAnuncie.email_from.value == ""){
		alert("Digite o seu e-mail"); document.formAnuncie.email_from.focus(); 
		return (false)
	}
	if (document.formAnuncie.cidade.value == ""){
		alert("Digite a cidade do imóvel"); document.formAnuncie.cidade.focus(); 
		return (false)
	}
	if (document.formAnuncie.endereco.value == ""){
		alert("Digite o endereço do imóvel"); document.formAnuncie.endereco.focus(); 
		return (false)
	}
	if (document.formAnuncie.bairro.value == ""){
		alert("Digite o bairro do imóvel"); document.formAnuncie.bairro.focus(); 
		return (false)
	}
	if (document.formAnuncie.valor.value == ""){
		alert("Digite o valor do imóvel"); document.formAnuncie.valor.focus(); 
		return (false)
	}
	if (document.formAnuncie.area.value == ""){
		alert("Digite a área do imóvel"); document.formAnuncie.area.focus(); 
		return (false)
	}
	if (document.formAnuncie.descricao.value == ""){
		alert("Digite uma breve descrição do imóvel"); document.formAnuncie.descricao.focus(); 
		return (false)
	}
return (true);
}

function ValidaDetalhes(){
	if (document.formDetalhes.imovel.value == ""){
		alert("Digite o código do imóvel"); document.formDetalhes.imovel.focus(); 
		return (false); 
	}
	if (document.formDetalhes.nome.value == ""){
		alert("Digite o seu nome"); document.formDetalhes.nome.focus(); 
		return (false)
	}
	if (document.formDetalhes.email.value == ""){
		alert("Digite o seu e-mail"); document.formDetalhes.email.focus(); 
		return (false)
	}
	if (document.formDetalhes.mensagem.value == ""){
		alert("Digite a sua proposta"); document.formDetalhes.mensagem.focus(); 
		return (false)
	}
	return (true);
}

function Dados(valor) {
      //verifica se o browser tem suporte a ajax
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
	  //se tiver suporte ajax
	  if(ajax) {
	     //deixa apenas o elemento 1 no option, os outros são excluídos
		 document.forms[0].buscaBairro.options.length = 1;
	     
		 idOpcao  = document.getElementById("opcoes");
		 
	     ajax.open("POST", "Select.Bairros.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 
		 ajax.onreadystatechange = function() {
            //enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1) {
			   idOpcao.innerHTML = "Carregando...!";   
	        }
			//após ser processado - chama função processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXML(ajax.responseXML);
			   }
			   else {
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   idOpcao.innerHTML = "Primeiro selecione a cidade";
			   }
            }
         }
		 //passa o código do estado escolhido
	     var params = "cidade="+valor;
         ajax.send(params);
   }
}
   
function processXML(obj){
      //pega a tag cidade
      var dataArray   = obj.getElementsByTagName("bairro");
      
	  //total de elementos contidos na tag cidade
	  if(dataArray.length > 0) {
	     //percorre o arquivo XML paara extrair os dados
         for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//contéudo dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
			var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;
			
	        idOpcao.innerHTML = "Selecione o bairro";
			
			//cria um novo option dinamicamente  
			var novo = document.createElement("option");
			    //atribui um ID a esse elemento
			    novo.setAttribute("id", "opcoes");
				//atribui um valor
			    novo.value = codigo;
				//atribui um texto
			    novo.text  = descricao;
				//finalmente adiciona o novo elemento
				document.forms[0].buscaBairro.options.add(novo);
		 }
	  }
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "Primeiro selecione a cidade";
  }	  
}
