function contatoGetCidadeByEstado(){
	
	var estado 	= document.getElementById("estado");
	var ajax 	= new Ajax();
	var params 	= "";
	var loading = document.getElementById("ajax-cidade");
	var html 	= "";
	
	params = "idEstado="+estado.value;
	params+= "&id=cidade";
	params+= "&name=cidade";
	params+= "&onchange=contatoGetBairroByCidade";
	params+= "&nameDefault=-- cidade --";
	params+= "&all=true";
	
	html += "<select disabled>";
	html += "<option>carregando..</option>";
	html += "</select>";
	
	loading.innerHTML = html;
	ajax.load("POST", "site/ajax/select-cidades.php", params, "ajax-cidade");
	
	contatoGetBairroByCidade();
}



function contatoGetBairroByCidade(){
	
	var ajax 	= new Ajax();
	var cidade 	= document.getElementById("cidade");
	var params	= "";
	var loading = document.getElementById("ajax-bairro");
	var html 	= "";
	
	html += "<select disabled>";
	html += "<option>carregando..</option>";
	html += "</select>";
	
	loading.innerHTML = html;
	
	if( cidade == null )
		reload("contatoGetBairroByCidade()", 1);
	else {
		
		params = "idCidade="+cidade.value;
		params+= "&id=bairro";
		params+= "&name=bairro";
		
		ajax.load("POST", "site/ajax/select-bairros.php", params, "ajax-bairro");
	}
}



function imovelGetBairroByCidade(){
	
	var ajax 	= new Ajax();
	var cidade 	= document.getElementById("imovel-cidade");
	var params	= "";
	var loading = document.getElementById("imovel-bairro-ajax");
	var html 	= "";
	
	html += "<select disabled>";
	html += "<option>carregando..</option>";
	html += "</select>";
	
	loading.innerHTML = html;
	
	params = "idCidade="+cidade.value;
	params+= "&id=imovel-bairro";
	params+= "&name=imovel-bairro";
		
	ajax.load("POST", "site/ajax/select-bairros.php", params, "imovel-bairro-ajax");
	
}



function imovelGetValores(){
	
	var ajaxIni			= new Ajax();
	var ajaxFim			= new Ajax();
	var loadingIni 		= document.getElementById("imovel-ajax-valor-ini");
	var loadingFim 		= document.getElementById("imovel-ajax-valor-fim");
	var tipoOperacao	= document.getElementById("imovel-negociacao");
	var paramsIni		= "";
	var paramsFim		= "";
	var html 			= "";
	
	
	if( tipoOperacao.value == 0 ){
		html = "<select disabled>";
		html += "<option>valor inicial</option>";
		html += "</select>";
		loadingIni.innerHTML = html;
		
		html = "<select disabled>";
		html += "<option>valor final</option>";
		html += "</select>";
		loadingFim.innerHTML = html;
	}
	else {
			
		html += "<select disabled>";
		html += "<option>carregando..</option>";
		html += "</select>";
		
		paramsIni = "name=imovel-valor-ini";
		paramsIni+= "&id=imovel-valor-ini";
		paramsIni+= "&string=de";
		paramsIni+= ( tipoOperacao.value == 1 ? "&aluguel" : "&venda" );
		
		paramsFim = "name=imovel-valor-fim";
		paramsFim+= "&id=imovel-valor-fim";
		paramsFim+= "&string=até";
		paramsFim+= ( tipoOperacao.value == 1 ? "&aluguel" : "&venda" );
		
		loadingIni.innerHTML = html;
		loadingFim.innerHTML = html;
	
		ajaxIni.load("GET", "site/ajax/select-valores.php", paramsIni, "imovel-ajax-valor-ini");
		ajaxFim.load("GET", "site/ajax/select-valores.php", paramsFim, "imovel-ajax-valor-fim");
	}
}


function enviaFrmContato() {
	
	var nome 		= document.getElementById("nome");
	var email		= document.getElementById("email");
	var estado		= document.getElementById("estado");
	var cidade		= document.getElementById("cidade");
	var tipoImovel 	= document.getElementById("imovel-tipoImovel");
	var iCidade		= document.getElementById("imovel-cidade");
	var iOperacao	= document.getElementById("imovel-negociacao");
	var msg			= "";
	
	if( nome.value.length < 4 )
		msg += " - Nome\n";
	if( email.value.length < 5 )
		msg += " - E-mail\n";
				
	if( msg != "" ){
		alert("Preencha corretamente os campos:\n\n"+msg);
	}
	else {
		if( !is_mail(email.value) )
			alert("E-mail inválido");
		else {
			document.frmContato.submit();
		}
	}
	
}