function $(object_id)
{
	return document.getElementById(object_id);
}

function mostra(objeto, tipo) {
	try
	{
		el = document.getElementById(objeto);
		el.style.display = tipo;
	} catch(erro)
	{
		//alert(objeto);
	}
}

function esconde(objeto)
{
	$(objeto).style.display = 'none';
	$(objeto).value='';
}

function esconde2(objeto) {
	document.getElementById('email').value='';
	elemento = 'document.getElementById(\'' + objeto + '\')';
	if(elemento) eval(elemento).style.display = 'none';
}

// Funcao para mostrar os campos convenientes
function mostraPeloSelectTipo(valor,objeto) {
	if (document.formBusca.imoveis_categoria.value == valor){
		mostraObjeto(objeto)
	}
}
function mostraPeloSelectNegocio(valor,objeto) {
	if (document.formBusca.imoveis_tipo.value == valor){
		mostraObjeto(objeto)
	}
}
function mostraPeloSelectDois(valor,objeto) {
	if (document.formCorretor.cada_pessoa.value == valor){
		mostraObjeto(objeto)
	}
}
// Funcao para mostrar os campos convenientes



// Funcao para mostrar os campos convenientes
function mostraPeloSelectTipo2(valor,objeto) {
	if (document.formBuscaAvancada.imoveis_categoria2.value == valor){
		mostraObjeto(objeto)
	}
}
function mostraPeloSelectNegocio2(valor,objeto) {
	if (document.formBuscaAvancada.imoveis_tipo2.value == valor){
		mostraObjeto(objeto)
	}
}
function mostraPeloSelectDois2(valor,objeto) {
	if (document.formBuscaAvancada.cada_pessoa2.value == valor){
		mostraObjeto(objeto)
	}
}
// Funcao para mostrar os campos convenientes








// Funcoes para mostrar ou ocultar objetos
function mostraObjeto(objeto) {
	elemento = 'document.getElementById(\'' + objeto + '\')';
	eval(elemento).style.display = 'inline';
}

function escondeObjeto(objeto) {
	elemento = 'document.getElementById(\'' + objeto + '\')';
	eval(elemento).style.display = 'none';

	//elemento.value='';
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
preloadFlag = true;

// formata um campo de CPF
// usar no input: onKeydown="JavaScript:FormataCPF(this,event);"
function MascaraCPF (Campo, teclapres) {
	 var tecla = teclapres.keyCode;
	 var vr = new String(Campo.value);
	 vr = vr.replace(".", "");
	 vr = vr.replace(".", "");
	 vr = vr.replace(".", "");
	 vr = vr.replace(".", "");
	 vr = vr.replace(".", "");
	 vr = vr.replace("-", "");
	 vr = vr.replace("-", "");
	 vr = vr.replace("-", "");
	 vr = vr.replace("-", "");
	 vr = vr.replace("-", "");
	 tam = vr.length + 1;
	 if (tecla != 9 && tecla != 8) {
	  	if(tam > 3 && tam < 5){
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
	  	}
	  if(tam > 6 && tam < 8) {
	   		Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.' + vr.substr(6, tam);
	  	}
	  if(tam > 9 && tam < 11) {
	   		Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.' + vr.substr(6, 3) + '-' + vr.substr(9, 11);
	  	}
	 }
}

// Formata um campo de CNPJ
// usar no input: onKeydown="JavaScript:FormataCNPJ(this,event);"
function FormataCNPJ(Campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
	}
}

function formataTelefone(obj) {

	// Verificacao da string geral
	var checkstr = "0123456789() -";

	// Verificacao apenas dos numeros
	var checkstr2 = "0123456789";

	// Variavel temporaria para guardar
	var temp = '';

	// Loop por toda a string para verificar se e' valida e retorna apenas os itens validos
	for (i = 0; i < obj.value.length; i++) {
		if (checkstr.indexOf(obj.value.substr(i, 1)) >= 0) {
			temp = temp + obj.value.substr(i,1);
		}
	}

	// Salva a string valida no campo
	obj.value = temp;

	// Verifica o tamanho para formatar corretamente
	switch (obj.value.length) {
    	case 1:
	        obj.value = "(" + obj.value;
    	    break;
	    case 3:
    	    obj.value = obj.value + ") ";
        	break;
	    case 9:
    	    obj.value = obj.value + "-";
        	break;
	}

	// Limpa a variavel temporaria para fazer a verificacao final de validade, por posicoes
	temp = '';

	// Loop para verificar a validade de cada posicao
	for (i = 0; i < obj.value.length; i++) {
		if (i==0 && obj.value.substr(i, 1) == '(') {
			temp = temp + obj.value.substr(i,1);
		} else if (i==3 && obj.value.substr(i, 1) == ')') {
			temp = temp + obj.value.substr(i,1);
		} else if (i==4 && obj.value.substr(i, 1) == ' ') {
			temp = temp + obj.value.substr(i,1);
		} else if (i==9 && obj.value.substr(i, 1) == '-') {
			temp = temp + obj.value.substr(i,1);
		} else if (i!=3 && i!=4 && i!=9 && checkstr2.indexOf(obj.value.substr(i, 1)) >= 0) {
			temp = temp + obj.value.substr(i,1);
		}
	}

	// Salva no input
	obj.value = temp;
}

function FormataData(Campo, teclapres) {
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	tam = vr.length + 1;

	if (tecla != 9 && tecla != 8)
 	{
		if (tam > 2 && tam < 5)
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
		if (tam >= 5)
			Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,4);
	}
}

function FormataDataDiaMes(Campo, teclapres) {
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	tam = vr.length + 1;

	if (tecla != 9 && tecla != 8)
 	{
		if (tam > 2 && tam < 5)
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
		if (tam >= 5)
			Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2);
	}
}

function montarAluguelCompraVenda(valor) {
	campo_select = eval("document.forms['formBusca'].imoveis_subtipo");
	campo_select.options.length = 0;

	if (valor.value == '2'){
		campo_select.options[0] = new Option("Residencial", 1);
		campo_select.options[1] = new Option("Comercial", 2);
		campo_select.options[2] = new Option("Temporada", 3);
		campo_select.options[3] = new Option("Rural", 4);
		TipoNegocio = "Aluguel"
	} else {
		campo_select.options[0] = new Option("Residencial", 1);
		campo_select.options[1] = new Option("Comercial", 2);
		campo_select.options[2] = new Option("Rural", 4);
		campo_select.options[3] = new Option("Lançamento", 5);
		TipoNegocio = "CompraVenda"
	}
	montarSubTipo(campo_select.options[0].value);
}

function montarSubTipo(valor){
	//if(local=="onload"){valor=valor}else{valor=valor.value}
	//Residencial
	if (valor == '1'){
		campo_select = eval("document.forms['formBusca'].imoveis_categoria");
		campo_select.options.length = 0;

		campo_select.options[0] = new Option("Apartamentos", 1);
		campo_select.options[1] = new Option("Casa", 2);
		campo_select.options[2] = new Option("Sobrado", 3);
		campo_select.options[3] = new Option("Kitinete", 4);
		campo_select.options[4] = new Option("Loft", 5);
		campo_select.options[5] = new Option("Apart Hotel", 6);
		campo_select.options[6] = new Option("Cobertura Single", 7);
		campo_select.options[7] = new Option("Cobertura Duplex", 8);
		campo_select.options[8] = new Option("Cobertura Triplex", 9);
		campo_select.options[9] = new Option("Chalé", 10);

		TipoNegocioAluguelCompra = "Residencial";
	}
	//Comercial
	if (valor == '2'){
		campo_select = eval("document.forms['formBusca'].imoveis_categoria");
		campo_select.options.length = 0;

		campo_select.options[0] = new Option("Sala Comercial", 11);
		campo_select.options[1] = new Option("Ponto Comercial", 12);
		campo_select.options[2] = new Option("Galpão", 13);
		campo_select.options[3] = new Option("Posto de Combústivel", 14);
		campo_select.options[4] = new Option("Área Industrial", 15);
		campo_select.options[5] = new Option("Hotel/Motel", 16);
		campo_select.options[6] = new Option("Prédio Comercial", 17);

		if(TipoNegocio == "CompraVenda"){
			campo_select.options[7] = new Option("Lojas", 21);
		}

		TipoNegocioAluguelCompra = "Comercial";
	}
	//Temporada
	if (valor == '3'){
		campo_select = eval("document.forms['formBusca'].imoveis_categoria");
		campo_select.options.length = 0;

		campo_select.options[0] = new Option("Apartamento", 1);
		campo_select.options[1] = new Option("Casas", 2);
		campo_select.options[2] = new Option("Kitinete", 4);
		campo_select.options[3] = new Option("Sobrado", 3);
		campo_select.options[4] = new Option("Pousada", 18);
		campo_select.options[5] = new Option("Cobertura Single", 7);
		campo_select.options[6] = new Option("Cobertura Duplex", 8);
		campo_select.options[7] = new Option("Cobertura Triplex", 9);
		campo_select.options[8] = new Option("Chalé", 10);

		TipoNegocioAluguelCompra = "Temporada";
	}
	//Rural
	if (valor == '4'){
		campo_select = eval("document.forms['formBusca'].imoveis_categoria");
		campo_select.options.length = 0;

		campo_select.options[0] = new Option("Fazenda", 19);
		campo_select.options[1] = new Option("Sítio/Chácara", 20);

		TipoNegocioAluguelCompra = "Rural";
	}
	//Lançamento
	if (valor == '5'){
		campo_select = eval("document.forms['formBusca'].imoveis_categoria");
		campo_select.options.length = 0;

		campo_select.options[0] = new Option("Apartamento", 1);
		campo_select.options[1] = new Option("Casas/Condominios", 2);
		campo_select.options[2] = new Option("Loteamento", 22);
		campo_select.options[3] = new Option("Loft", 5);
		campo_select.options[4] = new Option("Chalé", 10);
		campo_select.options[5] = new Option("Sala Comercial", 11);
		campo_select.options[6] = new Option("Kitinete", 4);

		TipoNegocioAluguelCompra = "Rural";
	}
	//tipoCategoria(campo_select.options[0].value, 'onload');
}
























function montarAluguelCompraVenda2(valor) {
	campo_select = eval("document.forms['formBuscaAvancada'].imoveis_subtipo2");
	campo_select.options.length = 0;

	if (valor.value == '2'){
		campo_select.options[0] = new Option("Residencial", 1);
		campo_select.options[1] = new Option("Comercial", 2);
		campo_select.options[2] = new Option("Temporada", 3);
		campo_select.options[3] = new Option("Rural", 4);
		TipoNegocio = "Aluguel"
	} else {
		campo_select.options[0] = new Option("Residencial", 1);
		campo_select.options[1] = new Option("Comercial", 2);
		campo_select.options[2] = new Option("Rural", 4);
		campo_select.options[3] = new Option("Lançamento", 5); //imoveis_subtipo = 5
		TipoNegocio = "CompraVenda"
	}
	/*for(i=0; i < campo_select.options.length; i++) {
		alert(eval('campo_select.options['+i+'].selected'));
	}*/

	montarSubTipo2(campo_select.options[0].value);
}

function montarSubTipo2(valor){
	//if(local=="onload"){valor=valor}else{valor=valor.value}
	//Residencial
	if (valor == '1'){
		campo_select = eval("document.forms['formBuscaAvancada'].imoveis_categoria2");
		campo_select.options.length = 0;

		campo_select.options[0] = new Option("Apartamentos", 1);
		campo_select.options[1] = new Option("Casa", 2);
		campo_select.options[2] = new Option("Sobrado", 3);
		campo_select.options[3] = new Option("Kitinete", 4);
		campo_select.options[4] = new Option("Loft", 5);
		campo_select.options[5] = new Option("Apart Hotel", 6);
		campo_select.options[6] = new Option("Cobertura Single", 7);
		campo_select.options[7] = new Option("Cobertura Duplex", 8);
		campo_select.options[8] = new Option("Cobertura Triplex", 9);
		campo_select.options[9] = new Option("Chalé", 10);

		TipoNegocioAluguelCompra = "Residencial";
	}
	//Comercial
	if (valor == '2'){
		campo_select = eval("document.forms['formBuscaAvancada'].imoveis_categoria2");
		campo_select.options.length = 0;

		campo_select.options[0] = new Option("Sala Comercial", 11);
		campo_select.options[1] = new Option("Ponto Comercial", 12);
		campo_select.options[2] = new Option("Galpão", 13);
		campo_select.options[3] = new Option("Posto de Combústivel", 14);
		campo_select.options[4] = new Option("Área Industrial", 15);
		campo_select.options[5] = new Option("Hotel/Motel", 16);
		campo_select.options[6] = new Option("Prédio Comercial", 17);

		if(TipoNegocio == "CompraVenda"){
			campo_select.options[7] = new Option("Lojas", 21);
		}

		TipoNegocioAluguelCompra = "Comercial";
	}
	//Temporada
	if (valor == '3'){
		campo_select = eval("document.forms['formBuscaAvancada'].imoveis_categoria2");
		campo_select.options.length = 0;

		campo_select.options[0] = new Option("Apartamento", 1);
		campo_select.options[1] = new Option("Casas", 2);
		campo_select.options[2] = new Option("Kitinete", 4);
		campo_select.options[3] = new Option("Sobrado", 3);
		campo_select.options[4] = new Option("Pousada", 18);
		campo_select.options[5] = new Option("Cobertura Single", 7);
		campo_select.options[6] = new Option("Cobertura Duplex", 8);
		campo_select.options[7] = new Option("Cobertura Triplex", 9);
		campo_select.options[8] = new Option("Chalé", 10);

		TipoNegocioAluguelCompra = "Temporada";
	}
	//Rural
	if (valor == '4'){
		campo_select = eval("document.forms['formBuscaAvancada'].imoveis_categoria2");
		campo_select.options.length = 0;

		campo_select.options[0] = new Option("Fazenda", 19);
		campo_select.options[1] = new Option("Sítio/Chácara", 20);

		TipoNegocioAluguelCompra = "Rural";
	}
	//Lançamento
	if (valor == '5'){
		campo_select = eval("document.forms['formBuscaAvancada'].imoveis_categoria2");
		campo_select.options.length = 0;

		campo_select.options[0] = new Option("Apartamento", 1);
		campo_select.options[1] = new Option("Casas/Condominios", 2);
		campo_select.options[2] = new Option("Loteamento", 22);
		campo_select.options[3] = new Option("Loft", 5);
		campo_select.options[4] = new Option("Chalé", 10);
		campo_select.options[5] = new Option("Sala Comercial", 11);
		campo_select.options[6] = new Option("Kitinete", 4);

		TipoNegocioAluguelCompra = "Rural";
	}
	//tipoCategoria(campo_select.options[0].value, 'onload');
}


function lista_termos(faz)
{
	campo_pai = $("id_termos_de_uso");
//alert(campo_pai.offsetTop + ' ' + campo_pai.offsetLeft);
//alert(campo_pai.pageX);
	opc = $("id_termos_de_uso_opc");

	opc.style.top = campo_pai.offsetTop+'px';
	opc.style.left = (campo_pai.offsetLeft-2)+'px';
	opc.style.display = faz;

}

function popup(arquivo ,width ,heigth ,name)
{
	window.open(''+arquivo+'', ''+name+'', "location=0,status=0,scrollbars=0, width=" + width + ", height=" + heigth + "")
}
