function urlgoto(loc){
	 // loc is the relative path your wish to redirect to
	 var b = document.getElementsByTagName('base');
	 if (b && b[0] && b[0].href) {
	   if (b[0].href.substr(b[0].href.length-1) == '/' && loc.charAt(0) == '/')
		 loc = loc.substr(1);
	   loc = b[0].href + loc;
	 }
	 location.href = loc;
}

function filtrar(url){
	
	var sub = document.getElementById('sub');
	var qual = sub.options[sub.selectedIndex].value;
	if(qual.value != -1){
		urlgoto("categoria/" + url + qual);		
	} else {
		urlgoto("categoria/" + url);		
	}

}

function mudou_distrito(valor){
	document.getElementById("chtml").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	document.getElementById("fhtml").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	xajax_mudou_distrito(valor);
}
function mudou_concelho(valor){
	document.getElementById("fhtml").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	var v2 = document.getElementById("distrito").options[document.getElementById("distrito").selectedIndex].value;
	xajax_mudou_concelho(v2, valor);
}
function processar_registo(valor){
	document.getElementById("rloading").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	document.getElementById("botao").disabled = true;
	xajax_processar_registo(xajax.getFormValues('form_registo'));
}

function processar_login(){
	document.getElementById("erros_login").style.display = 'none';
	document.getElementById("botao_entrar").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	xajax_processar_login(xajax.getFormValues('formulario_login'));
}

function trim(valor)
{
return valor.replace(/^\s*/, "").replace(/\s*$/, "");
}

function processar_comentario(){
	var seleccionou = document.getElementById("recomendavasim").checked || document.getElementById("recomendavanao").checked;
	var texto = document.getElementById("caixa_texto_comentario").value;
	
	if(!seleccionou){
		alert("Por favor indique se recomenda ou não o estabelecimento.");
		return;
	}
	if(trim(texto).length == 0){
		alert("Por favor indique as razões da sua recomendação.");
		return;
	}
	document.getElementById("adicionar_comentario").submit();
}

function abrirURL(url){
	
	window.open(url, '');
	
}

function pesquisar(){
	
	var texto = document.getElementById("input_pesquisa").value;
	
	if(trim(texto).length <= 3){
		alert("Por favor preencha um termo de pesquisa com mais de 3 caracteres.");
		return;
	}
	
	urlgoto('area/pesquisa/'+encodeURIComponent(texto));
}

function pesquisar_estabelecimentos(p, inf){
	
	document.getElementById("resultados").innerHTML = '<img src="imagens/icon_loading.gif" class="bullet" />A pesquisar... Por favor aguarde...';
	
 	xajax_pesquisar_estabelecimentos(p, inf);
	
}

function pesquisar_reservas(d, inf, ordenar, ordem){
	
	document.getElementById("resultados").innerHTML = '<img src="imagens/icon_loading.gif" class="bullet" />A pesquisar... Por favor aguarde...';
	
 	xajax_pesquisar_reservas(d, inf, ordenar, ordem);
	
}

function pesquisar_reservas2(){
	
	document.getElementById("resultados").innerHTML = '<img src="imagens/icon_loading.gif" class="bullet" />A pesquisar... Por favor aguarde...';
	var d = document.getElementById('distrito').options[document.getElementById('distrito').selectedIndex].value;
	var ordenar = document.getElementById('ordenar').options[document.getElementById('ordenar').selectedIndex].value;
	var ordem = document.getElementById('ordem').options[document.getElementById('ordem').selectedIndex].value;
	
 	xajax_pesquisar_reservas(d, 0, ordenar, ordem);
	
}

function processar_recuperar(){
	document.getElementById("rloading").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	document.getElementById("botao").disabled = true;
	xajax_processar_recuperar(xajax.getFormValues('form_recuperar'));
}

function processar_password(){
	
	document.getElementById("rloading").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	document.getElementById("botao").disabled = true;
	xajax_processar_password(xajax.getFormValues('form_password'));
	
}
function processar_perfil(){
	
	document.getElementById("rloading").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	document.getElementById("botao").disabled = true;
	xajax_processar_perfil(xajax.getFormValues('form_alterar_perfil'));
	
}
function faq(id){
	
	document.getElementById(id).style.display = (document.getElementById(id).style.display == 'block') ? 'none' : 'block';
	
}
function checkEnter(e){
	
	var character;
	
	if(e && e.which){ 
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode;
	}
	
	if(characterCode == 13){ ;
		pesquisar();
		return false;
	} else {
		return true;
	}

}

function processar_contacto(){
	
	document.getElementById("rloading").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	document.getElementById("botao").disabled = true;
	xajax_processar_contacto(xajax.getFormValues('form_contactos'));
	
}
function processar_sugestao(){
	
	document.getElementById("rloading").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	document.getElementById("botao").disabled = true;
	xajax_processar_sugestao(xajax.getFormValues('form_sugestao'));
	
}

function getgoto(loc){
	 // loc is the relative path your wish to redirect to
	 var b = document.getElementsByTagName('base');
	 if (b && b[0] && b[0].href) {
	   if (b[0].href.substr(b[0].href.length-1) == '/' && loc.charAt(0) == '/')
		 loc = loc.substr(1);
	   loc = b[0].href + loc;
	 }
	 return loc;
}

function abrirHotel(id){
	
	window.open(getgoto('abrir/'+id), '', 'width=700, height=500, resizable=yes, scrollbars=yes');
	
}

function mudar_pagina_user(user, inf){
	
	document.getElementById("recomendacoes_user").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	document.getElementById("paginacao_user").innerHTML = "";
	xajax_getRecomendacoes(user, inf);
	
}

function Tooltip(marker, text, padding){
	this.marker_ = marker;
	this.text_ = text;
	this.padding_ = padding;
}

function processar_mais_info(){
	
	document.getElementById("rloading").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	document.getElementById("botao").disabled = true;
	xajax_processar_mais_info(xajax.getFormValues('form_mais_info'));
	
}


function processar_reserva(){
	
	document.getElementById("rloading").innerHTML = "<img src=\"imagens/icon_loading.gif\" />";
	document.getElementById("botao").disabled = true;
	xajax_processar_reserva(xajax.getFormValues('form_reserva'));
	
}