//---------------------------------------------//
//			SEJA ORIGINAL / BE ORIGINAL			//
//			ISSO SÓ EU TENHO MAGRINHO			//
//	Programador José Eduardo Perotta de Almeida	//
//			perottas1@hotmail.com				//
//				+55 (27) 8836-8760				//
//--------------------------------------------//
function get(elemento){return document.getElementById(elemento);}
var xmlhttp = joseeduardo();
function joseeduardo() {if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if (window.ActiveXObject) {	return new ActiveXObject("Microsoft.XMLHTTP");}}
function EduardoPerotta(oque, eocara){xmlhttp.open("GET", oque, true);
xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState==4){get(eocara).innerHTML = xmlhttp.responseText;}}	
xmlhttp.send(null);}
function EduardoPerotta2(){if (get('codigo').value == "" || get('codigo').value == "buscar por código"){window.alert('Favor informar o código do imóvel que deseja encontrar!');get('codigo').focus();return (false);}else xmlhttp.open("GET", "buscacodigo.asp?codigo=" + get('codigo').value + "&resposta=mini", true);
xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState==4){get('barradireita').innerHTML = xmlhttp.responseText;}}	
xmlhttp.send(null);}
function EduardoPerotta3(){xmlhttp.open("GET", "buscacodigo.asp?codigo=" + get('codigo').value + "&resposta=mini", true);
xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState==4){get('barradireita').innerHTML = xmlhttp.responseText;}}	
xmlhttp.send(null);}
function EduardoPerottaAlmeida(){if (get('seunome').value == "" || get('seuemail').value == "" || get('nomeamigo').value == "" || get('email').value == ""){window.alert('Favor informar seu nome e e-mail, o nome e e-mail do amigo(a)!');get('seunome').focus();return (false);}else if(!/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(get('seuemail').value)){window.alert('O seu e-mail está incorreto\nO e-mail deve ser semelhante à email@email.com!');get('seuemail').focus();return (false);}else if(!/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(get('emailamigo').value)){window.alert('O e-mail do(a) seu(sua) amigo(a) está incorreto\nO e-mail deve ser semelhante à email@email.com!');get('emailamigo').focus();return (false);}else xmlhttp.open("GET", "Scripts/processaindicaimovel.asp?seunome=" + get('seunome').value + "&seuemail=" + get('seuemail').value + "&nomeamigo=" + get('nomeamigo').value + "&emailamigo=" + get('emailamigo').value + "&id=" + get('idimovel').value + "", true);xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState==4){get('respostaindicacao').innerHTML = xmlhttp.responseText; get('boxresposta').style.display='block';}}
xmlhttp.send(null);}
function JoseEduardoPerottaAlmeida(){if (get('nomecontato').value == "" || get('emailcontato').value == "" || get('mensagemcontato').value == ""){window.alert('Favor informar ao menos seu nome, e-mail e a mensagem que deseja enviar!');get('nomecontato').focus();return (false);}else xmlhttp.open("GET", "Scripts/processacontato.asp?nomecontato=" + get('nomecontato').value + "&emailcontato=" + get('emailcontato').value + "&setorcontato=" + get('setorcontato').value + "&telefonecontato=" + get('telefonecontato').value + "&mensagemcontato=" + get('mensagemcontato').value + "", true);xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState==4){get('respostacontato').innerHTML = xmlhttp.responseText; get('boxrespostacontato').style.display='block';}}	
xmlhttp.send(null);}
function JoseEduardoPerottadeAlmeida(){if (get('nomecontato').value == "" || get('emailcontato').value == "" || get('mensagemcontato').value == ""){window.alert('Favor informar ao menos seu nome, e-mail e a mensagem que deseja enviar!');get('nomecontato').focus();return (false);}else xmlhttp.open("GET", "Scripts/processacontato.asp?nomecontato=" + get('nomecontato').value + "&emailcontato=" + get('emailcontato').value + "&setorcontato=" + get('setorcontato').value + "&telefonecontato=" + get('telefonecontato').value + "&mensagemcontato=" + get('mensagemcontato').value + "", true);xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState==4){get('respostacontato').innerHTML = xmlhttp.responseText; get('boxrespostacontato').style.display='block';}}	
xmlhttp.send(null);}
function validacaonewsletter(){if (get('nome').value == "" || get('nome').value == "cadastre seu nome"){window.alert('Favor informar seu nome!');get('nome').focus();return (false);}else if (get('email').value == "" || get('email').value == "cadastre seu e-mail"){window.alert('Favor informar seu e-mail!');get('email').focus();return (false);}else if (!/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(get('email').value)){window.alert('O e-mail fornecido está incorreto\nO e-mail deve ser semelhante à email@email.com!');get('email').focus();return (false);}else xmlhttp.open("GET", "Scripts/processanews.asp?nome=" + get('nome').value + "&email=" + get('email').value + "", true);xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState==4){get('respostanewsletter').innerHTML = xmlhttp.responseText; get('boxrespostanewsletter').style.display='block';}}
xmlhttp.send(null);}
function encontra(){xmlhttp.open("GET", "Scripts/processabusca.asp?finalidade=" + get('finalidade').value + "&tipo=" + get('tipo').value + "&ddormitorio=" + get('ddormitorio').value + "&vminimo=" + get('vminimo').value + "&vmaximo=" + get('vmaximo').value + "&bairro=" + get('bairro').value + "", true);xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState==4){get('barradireita').innerHTML = xmlhttp.responseText;}}	
xmlhttp.send(null);}
function encontrac(){xmlhttp.open("GET", "Scripts/processabuscac.asp?codigo=" + get('codigo').value + "", true);xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState==4){get('barradireita').innerHTML = xmlhttp.responseText;}}	
xmlhttp.send(null);}
function encontrablivre(){xmlhttp.open("GET", "Scripts/processabuscablivre.asp?blivre=" + get('blivre').value + "", true);xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState==4){get('barradireita').innerHTML = xmlhttp.responseText;}}	
xmlhttp.send(null);}

function FormataReal(nvalor){
nvalor = nvalor.replace(".","");
nvalor = nvalor.replace(",",".");
return nvalor;
}
function FormataRealn(nvalor){
nvalor = nvalor.replace(".",",");
nvalor = nvalor.replace(",",".");
return nvalor;
}
function FormataValor(objeto,teclapres,tammax,decimais) 
{
	var tecla			= teclapres.keyCode;
	var tamanhoObjeto	= objeto.value.length;
	if ((tecla == 8) && (tamanhoObjeto == tammax))
	{
		tamanhoObjeto = tamanhoObjeto - 1 ;
	}
    if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax))
	{
		vr	= objeto.value;
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( ",", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		tam	= vr.length;
		if (tam < tammax && tecla != 8)
		{
			tam = vr.length + 1 ;
		}
		if ((tecla == 8) && (tam > 1))
		{
			tam = tam - 1 ;
			vr = objeto.value;
			vr = vr.replace( "/", "" );
			vr = vr.replace( "/", "" );
			vr = vr.replace( ",", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
		}
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
		{
			if (decimais > 0)
			{
				if ( (tam <= decimais) )
				{ 
					objeto.value = ("0," + vr) ;
				}
				if( (tam == (decimais + 1)) && (tecla == 8))
				{
					objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;	
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0"))
				{
					objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0"))
				{
				    objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ; 
				}
				if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			 	if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			}
			else if(decimais == 0)
			{
				if ( tam <= 3 )
				{ 
			 		objeto.value = vr ;
				}
				if ( (tam >= 4) && (tam <= 6) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 7) && (tam <= 9) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 10) && (tam <= 12) )
				{
			 		if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}

				if ( (tam >= 13) && (tam <= 15) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
				}			
			}
		}
	}
	else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46))
		{
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
}
function manipulaelemento(objetotela, acao) {
	var objetotela = get(objetotela);
	if (acao == "o"){objetotela.style.display = "none";} // oculta
	if (acao == "e"){objetotela.style.display = "block";} // exibe
	if (acao == "l"){objetotela.value = "";} // limpa value
}