// JavaScript Document
var caminhoImgCarregando = '<img alt="Indicator" src="painel_controle/painel/images/spinner.gif" align="left" />&nbsp;Carregando';

var redirecionar = function(url) {
	document.location.href = url;
};

var renderizaCarregando = function(elemento) {
	if ($("#" + elemento).get(0)) {
		document.getElementById(elemento).innerHTML = caminhoImgCarregando;
	}
};

var renderizaConteudo = function(elemento, html) {
	if ($("#" + elemento).get(0)) {
		document.getElementById(elemento).innerHTML = html;
	}
};

var Formulario = function() {
};
Formulario.prototype = {

	_url : '',

	_parametros : null,

	_resultContainer : '',

	_spinner : '',

	submeter : function() {
		var containerResult = this._resultContainer;
		var spinner = this._spinner;
		$.ajax( {
			type : "POST",
			url : this._url,
			data : this._parametros,
			success : function(msg) {
				renderizaConteudo(containerResult, msg);
			},
			error : function(msg) {
				alert("Erro: " + msg.responseText);
			},
			beforeSend : function() {
				renderizaCarregando(spinner);
			}
		});
	},

	redirecionar : function() {
		var spinner = this._spinner;
		$.ajax( {
			type : "POST",
			url : this._url,
			data : this._parametros,
			success : function(url) {
				redirecionar(url);
			},
			error : function(msg) {
				alert("Erro: " + msg.responseText);
			},
			beforeSend : function() {
				renderizaCarregando(spinner);
			}
		});
	}
};

var LinkListaImovel = function() {
};
LinkListaImovel.prototype = new Formulario();
LinkListaImovel.prototype.Listar = function(tipo) {
	this._url = 'ajax/ajax.imoveis.php';
	this._parametros = {
		setDados : 'SERCH',
		urlRedirecionamento : '?p=listaimoveis',
		serch_tpNegocio : tipo,
		serch_tpImovel : 'todos',
		serch_cidade : 'todas',
		serch_bairro : 'todos',
		serch_valor : 'todas'
	};
	this._spinner = 'spinnerpesquisa';
	this.redirecionar();
};
var _lkListaImovel = new LinkListaImovel();

var PesquisaImovel = function() {
};
PesquisaImovel.prototype = new Formulario();
PesquisaImovel.prototype.Serch = function() {

	if (document.form_pesq_imoveis.pesq_tpNegocio.value == "--") {
		alert("Informe o Tipo de Neg&oacute;cio");
		return false;
	}

	this._url = 'ajax/ajax.imoveis.php';
	this._parametros = {
		setDados : 'SERCH',
		urlRedirecionamento : '?p=listaimoveis',
		serch_tpNegocio : document.form_pesq_imoveis.pesq_tpNegocio.value,
		serch_tpImovel : document.form_pesq_imoveis.pesq_tpImovel.value,
		serch_cidade : document.form_pesq_imoveis.pesq_cidades.value,
		serch_bairro : document.form_pesq_imoveis.pesq_bairros.value,
		serch_valor : document.form_pesq_imoveis.pesq_preco.value
	};
	this._spinner = 'spinnerpesquisa';
	this.redirecionar();
};
var _pesq = new PesquisaImovel();

/*
 * CLASSE PARA ENVIAR EMAIL DE CONTATO
 * */
var FaleConosco = function(){};
FaleConosco.prototype = new Formulario();
FaleConosco.prototype.Enviar = function(){
	this._url             = 'ajax/ajax.faleconosco.php';
	this._spinner         = 'spinnerfaleconosco';
	this._resultContainer = 'spinnerfaleconosco'; 
	this._parametros = {
		fc_nome       : document.form_faleconosco.fc_nome.value,
		fc_email      : document.form_faleconosco.fc_email.value,
		fc_cidade     : document.form_faleconosco.fc_cidade.value,
		fc_foneddd    : document.form_faleconosco.fc_foneddd.value,
		fc_fonenumero : document.form_faleconosco.fc_fonenumero.value,
		fc_celddd     : document.form_faleconosco.fc_celddd.value,
		fc_celnumero  : document.form_faleconosco.fc_celnumero.value,
		fc_assunto    : document.form_faleconosco.fc_assunto.value,
		fc_mensagem   : document.form_faleconosco.fc_mensagem.value
	};
	this.submeter();
};
var _faleconosco = new FaleConosco();

/*
 * CLASSE PARA FORMULARIO "QUERO VENDER OU ALUGAR"
 * */
var QueroVender = function(){};
QueroVender.prototype = new Formulario();
QueroVender.prototype.Enviar = function(){
	var c_comochegouanos, c_imovelexclusivo;
	
	if (document.getElementById('oi_comochegouanosJornal').checked) {
		c_comochegouanos = 'Jornal';
	} else
		if (document.getElementById('oi_comochegouanosTV').checked) {
			c_comochegouanos = 'TV';
		} else
			if (document.getElementById('oi_comochegouanosRadio').checked) {
				c_comochegouanos = 'Rádio';
			} else
				if (document.getElementById('oi_comochegouanosAmigos').checked) {
					c_comochegouanos = 'Amigos';
				} else
					if (document.getElementById('oi_comochegouanosInternet').checked) {
						c_comochegouanos = 'Internet';
					} else
					    c_comochegouanos = 'Outros';					
	
	c_imovelexclusivo = (document.getElementById('oi_imovelexclusivoSim').checked ? 'Sim' : 'Não');
	
	
	this._url             = 'ajax/ajax.querovender.php';
	this._spinner         = 'spinnerquerovenderoualugar';
	this._resultContainer = 'spinnerquerovenderoualugar'; 
	this._parametros = {
		dp_nome       : document.form_querovenderoualugar.dp_nome.value,	
		dp_email      : document.form_querovenderoualugar.dp_email.value,
		dp_foneddd    : document.form_querovenderoualugar.dp_foneddd.value,
		dp_fonenumero : document.form_querovenderoualugar.dp_fonenumero.value,
		dp_celddd     : document.form_querovenderoualugar.dp_celddd.value,
		dp_celnumero  : document.form_querovenderoualugar.dp_celnumero.value,				
		dp_endereco   : document.form_querovenderoualugar.dp_endereco.value,
		dp_cidade     : document.form_querovenderoualugar.dp_cidade.value,
		dp_estado     : document.form_querovenderoualugar.dp_estado.value,
		dp_cepp1      : document.form_querovenderoualugar.dp_cepp1.value,
		dp_cepp2      : document.form_querovenderoualugar.dp_cepp2.value,
		
		di_tpneg         : document.form_querovenderoualugar.di_tpneg.value,
		di_tpimovel      : document.form_querovenderoualugar.di_tpimovel.value,
		di_areautil      : document.form_querovenderoualugar.di_areautil.value,
		di_areatotal     : document.form_querovenderoualugar.di_areatotal.value,
		di_nrdormitorios : document.form_querovenderoualugar.di_nrdormitorios.value,
		di_nrgaragens    : document.form_querovenderoualugar.di_nrgaragens.value,
		di_valorimovel   : document.form_querovenderoualugar.di_valorimovel.value,
		di_endereco      : document.form_querovenderoualugar.di_endereco.value,
		di_cidade        : document.form_querovenderoualugar.di_cidade.value,
		di_estado        : document.form_querovenderoualugar.di_estado.value,
		di_bairro        : document.form_querovenderoualugar.di_bairro.value,
		di_obsevacoes    : document.form_querovenderoualugar.di_obsevacoes.value,
		
		oi_comochegouanos  : c_comochegouanos,
		oi_imovelexclusivo : c_imovelexclusivo,
		oi_comentario      : document.form_querovenderoualugar.oi_comentario.value
	};
	this.submeter();
};
var _querovender = new QueroVender();


var PagFotos = function() {
};
PagFotos.prototype = {

	_nrFotoAtual : 0,

	_qtdFotos : null,

	_listaFotos : new Array(),

	_displayContador : null,

	_caminhoPastaFotos : null,

	setNrFotoAtual : function(nr) {
		this._nrFotoAtual = nr;
	},

	setListaFotos : function(lista) {
		this._listaFotos = lista;
		this._qtdFotos = lista.length;
	},

	setDisplayContador : function(display) {
		this._displayContador = display;
	},

	setCaminhoPastaFotos : function(caminho) {
		this._caminhoPastaFotos = caminho;
	},

	proxima : function() {
		if (this._nrFotoAtual < this._qtdFotos - 1) {
			this._nrFotoAtual++;
		} else {
			this._nrFotoAtual = 0;
		}
		this.mostraFoto();
	},

	anterior : function() {
		if (this._nrFotoAtual > 0) {
			this._nrFotoAtual--;
		} else {
			this._nrFotoAtual = this._qtdFotos - 1;
		}
		this.mostraFoto();
	},

	mostraFoto : function() {
		if (this._qtdFotos > 0) {
			document.getElementById(this._displayContador).innerHTML = this._nrFotoAtual + 1;
			document.getElementById("fotopaginacao").src = this._caminhoPastaFotos
			+ 'thumbs/'	+ this._listaFotos[this._nrFotoAtual];
			document.getElementById("fotopaginacaovisual").href = this._caminhoPastaFotos
			+ this._listaFotos[this._nrFotoAtual];			
		}
	}
};
var _pagFotos = new PagFotos();

