function volta_busca(){
	window.document.getElementById('tablela_tudo').innerHTML = '';
}

function funciona(){
	window.document.getElementById('tablela_tudo').innerHTML = '';
	window.document.getElementById('tablela_tudo').src = 'busca_resultado.php';
	//window.document.all('tabela_tudo').style.display = 'none';
	//style="visibility:hidden"
}
	
function voltar(){
	var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[0];
	
	if (getFFVersion != "Firefox"){
		//window.document.getElementById('tabela_tudo').style.display = 'inline';
		window.document.getElementById('tablela_tudo').innerHTML = '';
		window.document.getElementById('pessoa1').innerHTML = '';
	}
}
	
	var url = window.document.location.href;
	var xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);

function ajax_do(url) {
        if (url.substring(0, 4) != 'http'){
                url = base_url + url;
		}
		
	var jsel = window.document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
		jsel.language = 'JavaScript';
        jsel.src = url;
    	window.document.body.appendChild(jsel);
}

function paginacao_kurole( x ){
	caminho = "busca_resultado_s.php?"+x;		
	//document.write(caminho);
	window.ajax_do(caminho);
}

function urlcompleta(){
	var doc = window.document.form3;
				
	var valorLocacao;
	if (doc.Locacao.checked || doc.Locacao.value == 'L'){
		valorLocacao = "&Locacao="+doc.Locacao.value+"&";
	}else{
		valorLocacao = '';
	}
				
	var valorVenda;
		if (doc.Venda.checked || doc.Venda.value == 'V'){
			valorVenda = "&Venda="+doc.Venda.value+"&";
		}else{
			valorVenda = '';
		}	
				
	var valortipo_imovel;
	for(i=0; i < doc.tipo_imovel.length; i++) {
		if(doc.tipo_imovel[i].selected) {
			valortipo_imovel = doc.tipo_imovel[i].value;
		}
	}
				
			var valorcidade;
				
				for(i=0; i < doc.cidade.length; i++) {
					if(doc.cidade[i].selected) {
						valorcidade = doc.cidade[i].value;
					}
				}
				
			var valoredificio;
				
				for(i=0; i < doc.edificio.length; i++) {
					if(doc.edificio[i].selected) {
						valoredificio = doc.edificio[i].value;
					}
				}

			var valorbairros;
				
				for(i=0; i < doc.bairros.length; i++) {
					if(doc.bairros[i].selected) {
						valorbairros = doc.bairros[i].value;
					}
				}
				
			var valordormitorio;
				
				for(i=0; i < doc.dormitorio.length; i++) {
					if(doc.dormitorio[i].selected) {
						valordormitorio = doc.dormitorio[i].value;
					}
				}	
				
			var valorvmi;
				
				for(i=0; i < doc.vmi.length; i++) {
					if(doc.vmi[i].selected) {
						valorvmi = doc.vmi[i].value;
					}
				}	
				
				var valorvma;
				
				for(i=0; i < doc.vma.length; i++) {
					if(doc.vma[i].selected) {
						valorvma = doc.vma[i].value;
					}
				}													
		
		var caminho;
		caminho = "busca_resultado_s.php?&tipo_imovel="+valortipo_imovel+valorLocacao+valorVenda+"&cidade="+valorcidade+"&edificio="+valoredificio+"&bairros="+valorbairros+"&dormitorio="+valordormitorio+"&vmi="+valorvmi+"&vma="+valorvma;		
		caminho_tudo = caminho;
		//document.write(caminho);
		window.parent.ajax_do(caminho);
	}
	
	function mostra_areas_e_imoveis_para_investidores( caminho2 ){
		window.ajax_do( caminho2 );
		}
	
function tudo( Y ){
	var altura_exibir = window.screen.height;
	window.open( Y , '', 'height='+altura_exibir+', width=770, cellspadding=no, cellspacing=no, scrollbars=yes');
	}
	
function test(cod){
	var url = 'tudo_imovel.php?imoveis=tudo&codigo='+cod;
	var d = $('pessoa1');
	/*d.update('<script>window.ajax_do("'+url+'")</script>');*/
	window.ajax_do(url);
	d.hide();
	d.show();
	d.addClassName('active');
}

function kurole_cadastro(x){	
	/*
	if (x.nome.value.length < 2 ){
		alert('Preencha o campo nome!');
		x.nome.focus();
		return false;
	}
	*/
	if (x.prop_cep.value.length < 8 ){
		alert('Preencha o CEP do proprietário!');
		x.prop_cep.focus();
		return false;
	}
	if (x.prop_cidade.value == "" ){
		alert('Preencha a CIDADE do proprietário!');
		x.prop_cidade.focus();
		return false;
	}
	if (x.prop_estado.value == "" ){
		alert('Preencha o ESTADO do proprietário!');
		x.prop_estado.focus();
		return false;
	}
	
	if (x.prop_bairro.value == "" ){
		alert('Preencha o BAIRRO do proprietário!');
		x.prop_bairro.focus();
		return false;
	}
	if (x.prop_numero.value == "" ){
		alert('Preencha o NÚMERO do proprietário!');
		x.prop_numero.focus();
		return false;
	}
	
	if ((!x.locacao.checked) && (!x.venda.checked)){
		alert('O imóvel é para locaçao ou venda?');
		return false;
	}
	if ((x.valor_venda.value == '') && (x.valor_aluguel.value == '')){
		alert('É obrigatório colocar um valor para operaçao escolhida!');
		return false;
	}
	
	if (x.cep.value.length < 8 ){
		alert('Preencha o CEP do imóvel!');
		x.cep.focus();
		return false;
	}
	if (x.cidade_estado.value == "" ){
		alert('Preencha a CIDADE do imóvel!');
		x.cidade_estado.focus();
		return false;
	}
	if (x.estado.value == "" ){
		alert('Preencha o ESTADO do imóvel!');
		x.estado.focus();
		return false;
	}
	
	if (x.bairro.value == "" ){
		alert('Preencha o BAIRRO do imóvel!');
		x.bairro.focus();
		return false;
	}
	if (x.numero.value == "" ){
		alert('Preencha o NÚMERO do imóvel!');
		x.numero.focus();
		return false;
	}
	window.document.getElementById('bt_enviar').innerHTML = '<img src="imagens/loader.gif"><br><font color=green><b>enviando...</b></font>';
}

function Limpar(valor, validos) {
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
	aux = validos.indexOf(valor.substring(i, i+1));
	if (aux>=0) {
	result += aux;
	}
	}
	return result;
}

function Formata_VALOR(campo,tammax,teclapres,decimal) {
	
	var tecla = teclapres.keyCode;

	var vr = Limpar(campo.value,"0123456789");
	var tam = vr.length;
	var dec=decimal
	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
	
	if (tecla == 8 )
	{ tam = tam - 1 ; }
	
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
	{
	
	if ( tam <= dec )
	{ campo.value = vr ; }

	if ( (tam > dec) && (tam <= 5) ){
	campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 6) && (tam <= 8) ){
	campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
	}
	
	if ( (tam >= 9) && (tam <= 11) ){
		campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 12) && (tam <= 14) ){
		campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 15) && (tam <= 17) ){
		campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
	}	

}

//////////////////////////////////////////////////// Adicionado dia 02/02/2012 por Renan /////////////////////////////////////////////////

function proximo_campo_cep(cep_next,cep_final){
	var campo = document.getElementById(cep_final);
	if (cep_next.length == 5){
		alert(campo);
		campo.focus();
		campo.value = '';
	}
}
	
function proximo_campo_cep_2(cep_next){
	if (cep_next.length == 3){
		window.document.forms[0].numero.focus();
		retorna_cep_cadastrese(document.forms[0].cep_1.value+document.forms[0].cep_2.value);
	}
}
