Ajax = ({
	buscaImoveis: function(div) {
		var parametros = 'page=0&atual=1&per_page=6&div='+div+'&tipoImovel='+$('#tipoImovel').val()+'&tipoBairro='+$('#tipoBairro').val()+'&minQuartos='+$('#minQuartos').val()+'&maxQuartos='+$('#maxQuartos').val()+'&precoMin='+$('#precoMin').val()+'&precoMax='+$('#precoMax').val();
		
		$('#'+div).fadeOut(500, function() {
			$.ajax({
				url: 'includes/funcoes.php?modulo=paginacaoBuscaImov',
				type: 'POST',
				data: parametros,
				success: function(retorno) {
					$('#'+div).fadeIn(200).html(retorno);
				}
			});
		});
		
		return false;
	},
	buscaImoveisComprar: function(div) {		
		var parametros = 'page=0&atual=1&per_page=6&div='+div+'&tipoImovel='+$('#tipoImovel').val()+'&tipoBairro='+$('#tipoBairro').val()+'&minQuartos='+$('#minQuartos').val()+'&maxQuartos='+$('#maxQuartos').val()+'&precoMin='+$('#precoMin').val()+'&precoMax='+$('#precoMax').val();
		
		window.location.href = 'comprar.php?'+parametros;
		return false;
	},
	paginacaoBuscaImov: function(page, atual, dir, per_page, div, mod, tipoImovel, tipoBairro, minQuartos, maxQuartos, precoMin, precoMax){
		if (dir == 1) {
			page = page + per_page;
			atual = atual + 1;
		}else if(dir == 0) {			
			page = page - per_page;
			atual = atual - 1;		
		}
		
		var parametros = 'page='+page+'&atual='+atual+'&per_page='+per_page+'&div='+div+'&tipoImovel='+tipoImovel+'&tipoBairro='+tipoBairro+'&minQuartos='+minQuartos+'&maxQuartos='+maxQuartos+'&precoMin='+precoMin+'&precoMax='+precoMax;		
		
		$('#'+div).fadeOut(500, function() {
			$.ajax({
				 url: 'includes/funcoes.php?modulo='+mod,
				 type: 'POST',
				 data: parametros,
				 success: function(retorno) {
				 	$('#'+div).fadeIn(200).html(retorno);
			 	 }
			});
		});
		return false;
	},
	buscaCod: function(mod, div) {
		var parametros = 'page=0&atual=1&per_page=6&div='+div+'&tipoImovel=&tipoBairro=&minQuartos=&maxQuartos=&precoMin=&precoMax=&buscaCod=s&cod='+$('#codImov').val();
				
		$('#'+div).fadeOut(500, function() {
			$.ajax({
				 url: 'includes/funcoes.php?modulo='+mod,
				 type: 'POST',
				 data: parametros,
				 success: function(retorno) {
				 	$('#'+div).fadeIn(200).html(retorno);
			 	 }
			});
		});
		return false;
	},
	buscaCodComprar: function(mod, div) {
		var parametros = 'page=0&atual=1&per_page=6&div='+div+'&tipoImovel=&tipoBairro=&minQuartos=&maxQuartos=&precoMin=&precoMax=&buscaCod=s&cod='+$('#codImov').val();
		
		window.location.href = 'comprar.php?'+parametros;		
		return false;
	},
	regiao: function(id, div) {
		var parametros = 'id='+id;
		
		$('#'+div).fadeOut(500, function() {
			$.ajax({
				 url: 'includes/funcoes.php?modulo=regiao',
				 type: 'POST',
				 data: parametros,
				 success: function(retorno) {
				 	$('#'+div).fadeIn(200).html(retorno);
			 	 }
			});
		});
		return false;
	},
	newsletter: function() {
		var nome = $('#nomenews').val();
		var email = $('#emailnews').val();
		var testaremail = checkMail(email);
		var data = $('#datanews').val();
		
		var nomeStatus = false;
		var emailStatus = false;
		var dataStatus = false;

		if((nome == '') || (nome == 'NOME:')) {			
			$('.nomenews').append('<div id="msg_erro_nomenews" onmouseover="$(\'#msg_erro_nomenews\').remove();" style="position:absolute;left:60px;top:20px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			nomeStatus = true;
		}
		
		if ((email == '') || (email == 'E-MAIL:')) {			
	 		$('.emailnews').append('<div id="msg_erro_emailnews" onmouseover="$(\'#msg_erro_emailnews\').remove();" style="position:absolute;left:60px;top:50px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
	 	}else if (!testaremail){
		   	$('.emailnews').append('<div id="msg_erro_emailnews" onmouseover="$(\'#msg_erro_emailnews\').remove();" style="position:absolute;left:60px;top:50px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">E-mail inválido.</span></div>');
		}else{
			emailStatus = true;
		}
		
		if((data == '') || (data == 'DD/MM/AAAA')) {			
			$('.datanews').append('<div id="msg_erro_datanews" onmouseover="$(\'#msg_erro_datanews\').remove();" style="position:absolute;left:-20px;top:80px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			dataStatus = true;
		}
		
		if(nomeStatus && emailStatus && dataStatus) {
			var parametros = 'nome='+escape(nome)+'&email='+escape(email)+'&data='+data;
			
			$.ajax({
				url: 'includes/funcoes.php?modulo=newsletter',
				type: 'POST',
				data: parametros,
				success: function(retorno) {
					$('#nomenews').val('NOME:');
					$('#emailnews').val('E-MAIL:');		
					$('#datanews').val('DD/MM/AAAA');
					$('#retornoNews').html(retorno);
				}
			});
		}		
		return false;
	},
	fale: function() {
		var nome = $('#nomeFale').val();
		var email = $('#emailFale').val();
		var testaremail = checkMail(email);
		var assunto = $('#assuntoFale').val();
		var msg = $('#mensagemFale').val();
		
		var nomeStatus = false;
		var emailStatus = false;
		var msgStatus = false;
		
		if(nome == '') {
			$('.nomeFale').append('<div id="msg_erro_nomeFale" onmouseover="$(\'#msg_erro_nomeFale\').remove();" style="position:absolute;left:100px;top:100px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			nomeStatus = true;
		}
		
		if (email == '') {
	 		$('.emailFale').append('<div id="msg_erro_emailFale" onmouseover="$(\'#msg_erro_emailFale\').remove();" style="position:absolute;left:100px;top:134px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
	 	}else if (!testaremail){
		   	$('.emailFale').append('<div id="msg_erro_emailFale" onmouseover="$(\'#msg_erro_emailFale\').remove();" style="position:absolute;left:100px;top:134px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">E-mail inválido.</span></div>');
		}else{
			emailStatus = true;
		}
		
		if(msg == '') {
			$('.mensagemFale').append('<div id="msg_erro_mensagemFale" onmouseover="$(\'#msg_erro_mensagemFale\').remove();" style="position:absolute;left:100px;top:202px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			msgStatus = true;
		}		
		
		if(nomeStatus && emailStatus && msgStatus) {
			var parametros = 'acao=enviar&nome='+escape(nome)+'&email='+escape(email)+'&assunto='+escape(assunto)+'&msg='+escape(msg);
			
			$.ajax({
				url: 'includes/funcoes.php?modulo=fale',
				type: 'POST',
				data: parametros,
				success: function(retorno) {
					$('#nomeFale').val('');
					$('#emailFale').val('');
					$('#assuntoFale').val('');
					$('#mensagemFale').val('');
					$('#retornoFale').html(retorno);
				}
			});
		}
		return false;
	},
	limparFale: function() {
		$('#nomeFale').val('');
		$('#emailFale').val('');
		$('#assuntoFale').val('');
		$('#mensagemFale').val('');
	},
	trabalhe: function() {
		var nome = $('#nomeTrabalhe').val();
		var email = $('#emailTrabalhe').val();
		var testaremail = checkMail(email);
		var tel = $('#telTrabalhe').val();
		var end = $('#enderecoTrabalhe').val();
		var cid = $('#cidadeTrabalhe').val();
		var exp = $('#descTrabalhe').val();
		var curric = $('#arquivoTrab').val();
		
		var nomeStatus = false;
		var emailStatus = false;
		var endStatus = false;
		var cidStatus = false;
		var expStatus = false;
		var curricStatus = false;
		
		if(nome == '') {
			$('.nomeTrabalhe').append('<div id="msg_erro_nomeTrabalhe" onmouseover="$(\'#msg_erro_nomeTrabalhe\').remove();" style="position:absolute;left:100px;top:100px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			nomeStatus = true;
		}
		
		if (email == '') {
	 		$('.emailTrabalhe').append('<div id="msg_erro_emailTrabalhe" onmouseover="$(\'#msg_erro_emailTrabalhe\').remove();" style="position:absolute;left:100px;top:134px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
	 	}else if (!testaremail){
		   	$('.emailTrabalhe').append('<div id="msg_erro_emailTrabalhe" onmouseover="$(\'#msg_erro_emailTrabalhe\').remove();" style="position:absolute;left:100px;top:134px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">E-mail inválido.</span></div>');
		}else{
			emailStatus = true;
		}
		
		if(end == '') {
			$('.enderecoTrabalhe').append('<div id="msg_erro_enderecoTrabalhe" onmouseover="$(\'#msg_erro_enderecoTrabalhe\').remove();" style="position:absolute;left:100px;top:202px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			endStatus = true;
		}
		
		if(cid == '') {
			$('.cidadeTrabalhe').append('<div id="msg_erro_cidadeTrabalhe" onmouseover="$(\'#msg_erro_cidadeTrabalhe\').remove();" style="position:absolute;left:100px;top:236px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			cidStatus = true;
		}
		
		if(exp == '') {
			$('.descTrabalhe').append('<div id="msg_erro_descTrabalhe" onmouseover="$(\'#msg_erro_descTrabalhe\').remove();" style="position:absolute;left:100px;top:270px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			expStatus = true;
		}
		
		if(curric == '') {
			$('.arquivoTrab').append('<div id="msg_erro_arquivoTrab" onmouseover="$(\'#msg_erro_arquivoTrab\').remove();" style="position:absolute;left:100px;top:390px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			curricStatus = true;
		}
				
		if(nomeStatus && emailStatus && endStatus && cidStatus && expStatus && curricStatus) {			
			var parametros = 'modulo=trabalhe&acao=enviar&nome='+escape(nome)+'&email='+escape(email)+'&tel='+tel+'&end='+escape(end)+'&cid='+escape(cid)+'&exp='+escape(exp)+'&curric='+escape(curric);
			
			$.ajaxFileUpload({				
				url:'includes/funcoes.php?'+parametros,
				secureuri:false,
				fileElementId:'arquivoTrab',
				dataType: 'json',
				success: function (data, status) {
					if(typeof(data.error) != 'undefined') {
						if(data.error != '') {
							//alert(data.error);							
							$('#retornoTrab').html(data.error);
						}else {
							//alert(data.msg);
							$('#retornoTrab').html(data.msg);							
						}
					}
				},
				error: function (data, status, e) {
					//alert(e);					
					$('#retornoTrab').html(e);
				}
			});
			/*$('#nomeTrabalhe').val('');					        
			$('#emailTrabalhe').val('');*/
			$('#telTrabalhe').val('');
			/*$('#enderecoTrabalhe').val('');
			$('#cidadeTrabalhe').val('');
			$('#descTrabalhe').val('');
			$('#arquivoTrab').val('');*/
			return false;
		}else {
			return false;
		}
	},
	trabalhe2: function() {
		var nome = $('#nomeTrabalhe').val();
		var email = $('#emailTrabalhe').val();
		var testaremail = checkMail(email);
		var tel = $('#telTrabalhe').val();
		var end = $('#enderecoTrabalhe').val();
		var cid = $('#cidadeTrabalhe').val();
		var exp = $('#descTrabalhe').val();
		var curric = $('#arquivoTrab').val();
		
		var nomeStatus = false;
		var emailStatus = false;
		var endStatus = false;
		var cidStatus = false;
		var expStatus = false;
		var curricStatus = false;
		
		if(nome == '') {
			$('.nomeTrabalhe').append('<div id="msg_erro_nomeTrabalhe" onmouseover="$(\'#msg_erro_nomeTrabalhe\').remove();" style="position:absolute;left:100px;top:100px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			nomeStatus = true;
		}
		
		if (email == '') {
	 		$('.emailTrabalhe').append('<div id="msg_erro_emailTrabalhe" onmouseover="$(\'#msg_erro_emailTrabalhe\').remove();" style="position:absolute;left:100px;top:134px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
	 	}else if (!testaremail){
		   	$('.emailTrabalhe').append('<div id="msg_erro_emailTrabalhe" onmouseover="$(\'#msg_erro_emailTrabalhe\').remove();" style="position:absolute;left:100px;top:134px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">E-mail inválido.</span></div>');
		}else{
			emailStatus = true;
		}
		
		if(end == '') {
			$('.enderecoTrabalhe').append('<div id="msg_erro_enderecoTrabalhe" onmouseover="$(\'#msg_erro_enderecoTrabalhe\').remove();" style="position:absolute;left:100px;top:202px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			endStatus = true;
		}
		
		if(cid == '') {
			$('.cidadeTrabalhe').append('<div id="msg_erro_cidadeTrabalhe" onmouseover="$(\'#msg_erro_cidadeTrabalhe\').remove();" style="position:absolute;left:100px;top:236px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			cidStatus = true;
		}
		
		if(exp == '') {
			$('.descTrabalhe').append('<div id="msg_erro_descTrabalhe" onmouseover="$(\'#msg_erro_descTrabalhe\').remove();" style="position:absolute;left:100px;top:270px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			expStatus = true;
		}
		
		if(curric == '') {
			$('.arquivoTrab').append('<div id="msg_erro_arquivoTrab" onmouseover="$(\'#msg_erro_arquivoTrab\').remove();" style="position:absolute;left:100px;top:390px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			curricStatus = true;
		}
				
		if(nomeStatus && emailStatus && endStatus && cidStatus && expStatus && curricStatus) {
			document.forms[0].submit();			
			return true;
		}else {
			return false;
		}
	},
	limparTrab: function() {
		$('#nomeTrabalhe').val('');
		$('#emailTrabalhe').val('');
		$('#telTrabalhe').val('');
		$('#enderecoTrabalhe').val('');
		$('#cidadeTrabalhe').val('');
		$('#descTrabalhe').val('');
		$('#arquivoTrab').val('');
	},
	servico: function(form) {
		var nome = $('#nomeServ').val();
		var email = $('#emailServ').val();
		var testaremail = checkMail(email);
		var tel = $('#telServ').val();
		var end = $('#endServ').val();
		var cidUF = $('#cidUFServ').val();
		var desc = $('#descServ').val();
		
		var nomeStatus  = false;
		var emailStatus = false;
		var endStatus   = false;
		var cidUFStatus = false;		
		var descStatus  = false;
		
		if(nome == '') {
			$('.nomeServ').append('<div id="msg_erro_nomeServ" onmouseover="$(\'#msg_erro_nomeServ\').remove();" style="position:absolute;left:100px;top:100px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			nomeStatus = true;
		}
		
		if (email == '') {
	 		$('.emailServ').append('<div id="msg_erro_emailServ" onmouseover="$(\'#msg_erro_emailServ\').remove();" style="position:absolute;left:100px;top:134px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
	 	}else if (!testaremail){
		   	$('.emailServ').append('<div id="msg_erro_emailServ" onmouseover="$(\'#msg_erro_emailServ\').remove();" style="position:absolute;left:100px;top:134px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">E-mail inválido.</span></div>');
		}else{
			emailStatus = true;
		}		
		
		if(end == '') {
			$('.endServ').append('<div id="msg_erro_endServ" onmouseover="$(\'#msg_erro_endServ\').remove();" style="position:absolute;left:100px;top:202px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			endStatus = true;
		}
		
		if(cidUF == '') {
			$('.cidUFServ').append('<div id="msg_erro_cidUFServ" onmouseover="$(\'#msg_erro_cidUFServ\').remove();" style="position:absolute;left:100px;top:236px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			cidUFStatus = true;
		}
		
		if(desc == '') {
			$('.descServ').append('<div id="msg_erro_descServ" onmouseover="$(\'#msg_erro_descServ\').remove();" style="position:absolute;left:100px;top:270px;width:95px;height:18px;border: 1px solid #000;"><span style="font-size:10px; color:#fc6910;">Campo obrigat&oacute;rio.</span></div>');
		}else {
			descStatus = true;
		}
		
		if(nomeStatus && emailStatus && endStatus && cidUFStatus && descStatus) {
			var parametros = 'acao=enviar&nome='+escape(nome)+'&email='+escape(email)+'&tel='+escape(tel)+'&end='+escape(end)+'&cidUF='+escape(cidUF)+'&desc='+escape(desc)+'&form='+form;
						
			$.ajax({
				url: 'includes/funcoes.php?modulo=servico',
				type: 'POST',
				data: parametros,
				success: function(retorno) {
					$('#nomeServ').val('');
					$('#emailServ').val('');
					$('#telServ').val('');
					$('#endServ').val('');
					$('#cidUFServ').val('');
					$('#descServ').val('');
					$('#retornoServico').html(retorno);
				}
			});
		}
				
		return false;
	},
	limparServico: function() {
		$('#nomeServ').val('');
		$('#emailServ').val('');
		$('#telServ').val('');
		$('#endServ').val('');
		$('#cidUFServ').val('');
		$('#descServ').val('');
		
		return false;
	},
	detalheImovel: function(id) {		
		window.location.href = 'detalheimovel.php?id='+id;
		
		return false;
	},	
	limpar: function(tipo) {
		var parametros = 'tipo='+tipo;
		$.ajax({
			url: 'includes/funcoes.php?modulo=limpar',
			type: 'post',
			data: parametros,
			success: function(retorno) {
				$('#campos').html(retorno);
			}
		});
	}
});

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string") {
        if(er.test(mail)) {
        	return true;
        }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
        	return true;
        }
    }else{
    	return false;
    }
}
