// JavaScript Document

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];}}
}

window.onload=function(){
	MM_preloadImages('imagens/loader.gif');	
}

function mostra_foto(Y, X, Z){
	//alert(Y);
	var nova = Y.split('\\');
	var nova_barra = '';
	for (i=0; i< nova.length; i++){
		nova_barra += nova[i]+'\\';
	}

	var novo_split = nova_barra.substr(0, Y.length);

   window.document.getElementById(X).innerHTML='<img src="file:///'+novo_split+'" width=105>';
}
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 ) ;}
	}	

}

function mostra_esconde_form(id1, id2){
	if(document.getElementById(id1).style.display == 'none' || document.getElementById(id1).style.display == ''){
		document.getElementById(id1).style.display = 'block';
		document.getElementById(id2).style.display = 'none';
	}else{
		document.getElementById(id1).style.display = 'none';
		document.getElementById(id2).style.display = 'none';
	}
}


function selecionaAbas(x, id1, id2, id3){
	var opcao1 		= document.getElementById(id1);
	var opcao2 		= document.getElementById(id2);
	var opcao3 		= document.getElementById(id3);
	var pesquisa	= document.getElementById('pesquisa');
	
	if(x == 0){
		pesquisa.style.backgroundImage= "url(imagens/background_pesquisa.png)";
	}else if(x == 1){
		pesquisa.style.backgroundImage = "url(imagens/background_pesquisa2.png)";
	}else{
		pesquisa.style.backgroundImage = "url(imagens/background_pesquisa3.png)";
	}
	
	//alert(pesquisa.style.backgroundImage);
	
/*
	alert(opcao1.id);
	alert(opcao1.style.display);
*/


	if(opcao1.style.display == "none"){
		
		opcao1.style.display = "block";
		opcao2.style.display = "none";
		opcao3.style.display = "none";
	}


/*
	alert(opcao1.id);
	alert(opcao1.style.display);
*/

}



















