function voltar() {
	if (document.getElementById('pesq').value =="com")
		document.getElementById('pesquisa_escritorios').submit();
	else	
		document.getElementById('pesquisa_imoveis').submit();
}


function pagAnterior(imovel_id, tipo) {

	document.getElementById('id').value = imovel_id;

	if(tipo=="renda")
		document.getElementById('pesquisa_imoveis').action = "/venda-casas/alugar-casa.jsp";
	if(tipo=="com")
		document.getElementById('pesquisa_imoveis').action = "/escritorios-lojas/comprar-alugar.jsp";
	else
		document.getElementById('pesquisa_imoveis').action = "/venda-casas/comprar-casa.jsp";
		
	document.getElementById('pesquisa_imoveis').submit();
}

function verMaisInfo(imovel_id, tipo) {

	try{
		document.getElementById('id').value = imovel_id;
	}catch(e){}
	try{
		document.getElementById('page').value = "detalhes";
	}catch(e){}
	
	if(tipo=="renda")
		document.getElementById('pesquisa_imoveis').action = "/venda-casas/alugar-casa.jsp";
	else if(tipo=="com")
		document.getElementById('pesquisa_imoveis').action = "/escritorios-lojas/comprar-alugar.jsp";
	else
		document.getElementById('pesquisa_imoveis').action = "/venda-casas/comprar-casa.jsp";
		
	document.getElementById('pesquisa_imoveis').submit();
}

function validaPedidoInfo(){
	document.getElementById('nome_erro').innerHTML = "";
	document.getElementById('telefone_email_erro').innerHTML = "";
	document.getElementById('assunto_erro').innerHTML = "";
	document.getElementById('mensagem_erro').innerHTML = "";
		
	document.getElementById('nome').className = "";
	document.getElementById('telefone').className = "";
	document.getElementById('email').className = "";
	document.getElementById('assunto').className = "";
	document.getElementById('mensagem').className = "";
		
	document.getElementById('nome_erro').style.height = "0";        
	document.getElementById('telefone_email_erro').style.height = "0px";        
	document.getElementById('assunto_erro').style.height = "0px";        
	document.getElementById('mensagem_erro').style.height = "0px";        
	
	boolPesquisaValida = true;
	
	if(isEmptyString(document.getElementById('nome').value)){
		document.getElementById('nome_erro').innerHTML = "Por favor, preencha o nome.";
		document.getElementById('nome').className = "inputs_erro";
		boolPesquisaValida = false;
	}
	
	if(isEmptyString(document.getElementById('telefone').value) && isEmptyString(document.getElementById('email').value)){
		document.getElementById('telefone_email_erro').innerHTML = "Por favor, preencha o telefone ou o email.";
		document.getElementById('telefone').className = "inputs_erro";
		document.getElementById('email').className = "inputs_erro";
		boolPesquisaValida = false;
	}
	
	if(!isEmptyString(document.getElementById('telefone').value) && (!isInt(document.getElementById('telefone').value) || document.getElementById('telefone').value.length < 9)){
		document.getElementById('telefone_email_erro').innerHTML = "Por favor, preencha o telefone correctamente.";
		document.getElementById('telefone').className = "inputs_erro";
		boolPesquisaValida = false;
	}
	
	if(!isEmptyString(document.getElementById('email').value) && !isEmail(document.getElementById('email').value)){
		document.getElementById('telefone_email_erro').innerHTML = "Por favor, preencha o email correctamente.";
		document.getElementById('email').className = "inputs_erro";
		boolPesquisaValida = false;
	}
	
	assuntoChecked = false;	
	arrFormElements = document.getElementById('pedido_info').elements;
	formElementsLength = arrFormElements.length;

	for(i=0; i!=formElementsLength; i++){
		if(arrFormElements[i].name == "assunto" && arrFormElements[i].checked == true){
			assuntoChecked = true
		}
	}
	
	if(assuntoChecked == false){
		document.getElementById('assunto_erro').innerHTML = "Por favor, escolha o assunto.";
		boolPesquisaValida = false;
	}
	
/*
	if(isEmptyString(document.getElementById('mensagem').value)){
		document.getElementById('mensagem_erro').innerHTML = "Por favor, preencha a mensagem.";
		document.getElementById('mensagem').className = "inputs_erro";
		boolPesquisaValida = false;
	}
*/
	
	return boolPesquisaValida;
}

function pedidoSent() {
	document.getElementById("divFeedback").innerHTML = 
		"<div class=\"inputs_erro\" style=\"text-align:left;\"><strong>" +
		"O seu pedido de contacto foi enviado com sucesso.<br />Brevemente ser&aacute; contactado pelo profissional respons&aacute;vel pela comercialização deste im&oacute;vel." +
		"</strong></div>";
}

function pedidoNotSent() {
	document.getElementById("divFeedback").innerHTML = 
		"<div class=\"inputs_erro\" style=\"text-align:left;\"><strong>" +
		"Ocorreu um erro no envio do seu pedido de contacto.<br />Por favor, tente mais tarde." +
		"</strong></div>";
}

function enviarAmigoSent() {
	document.getElementById("divFeedbackEnviarAmigo").innerHTML = 
		"<br/><div class=\"inputs_erro\" style=\"text-align:center; padding:10px;\"><strong>" +
		"Imóvel enviado com sucesso." +
		"</strong></div>";
		
	hideBlockDiv('div_enviar_amigo');
}

function enviarAmigoNotSent() {
	document.getElementById("divFeedbackEnviarAmigo").innerHTML = 
		"<br/><div class=\"inputs_erro\" style=\"text-align:center; padding:10px;\"><strong>" +
		"Ocorreu um erro no envio do imóvel.<br />Por favor, tente mais tarde." +
		"</strong></div>";
		
	hideBlockDiv('div_enviar_amigo');
}
