// JavaScript Buscador Avanzado

function envia(){
	document.cerca_hotel.detall.value=0;
	document.cerca_hotel.submit();
}

function enviaSoloNombres()
{
	
	document.cerca_hotel.detall.value="soloNombres";
	document.cerca_hotel.submit();
}

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;

function isDisabledIni(date) 
{
	var today = new Date();

	// Es menor a hoy
	if (date.getTime() < (today.getTime()-DAY))
	{	
		return true;
	}

	// Es mayor a un año
	if (((date.getTime() - today.getTime()) / DAY) > 366)
	{
		return true;
	}

	return false;
}

function isDisabledFi(date) 
{
//    var today = new Date();
	
	fecha_inicial = document.cerca_hotel.DataIni.value;
	var today = new Date( fecha_inicial.substr(3,2) +'/'+ fecha_inicial.substr(0,2) +'/'+ fecha_inicial.substr(6,4) );

	// Es menor a hoy
	if (date.getTime() < (today.getTime()+1))
	{	
		return true;
	}

	// Es mayo a un año
	if (((date.getTime() - today.getTime()) / DAY) > 15)
	{
		return true;
	}

	return false;
}

function closeCalendar(cal) 
{
    cal.hide();
	posarNits();
	return true;
}

function SumarDies(fechaIni,num){
	var msPorDia = 24 * 60 * 60 * 1000
	var fechaFin = Date.parse(fechaIni)+(msPorDia*num);
	var fechaFinNew = new Date(fechaFin);
	var Fdia=fechaFinNew.getDate();
	if (Fdia < 10 ) {
		Fdia = '0' + Fdia;
	}
	var Fmes=fechaFinNew.getMonth()+1;
	if (Fmes < 10 ) {
		Fmes = '0' + Fmes;
	}
	var Fany=fechaFinNew.getYear();
	if (Fany < 1000) { //Modificació necessària per Firefox
		Fany+=1900
	}	
	document.cerca_hotel.DataFi.value = Fdia +'/'+ Fmes +'/'+ Fany;
	var fechaFinDia = new Date( Fmes +'/'+ Fdia +'/'+ Fany );
	//document.getElementById('divDiaSortida').innerHTML = weekDay[fechaFinDia.getDay()];
	document.cerca_hotel.numNits.value = num;
}

function posarNits(){
	fecha_inicial = document.cerca_hotel.DataIni.value;
	fecha_final = document.cerca_hotel.DataFi.value;
	var fechaIni = new Date( fecha_inicial.substr(3,2) +'/'+ fecha_inicial.substr(0,2) +'/'+ fecha_inicial.substr(6,4) );
	var fechaFin = new Date( fecha_final.substr(3,2) +'/'+ fecha_final.substr(0,2) +'/'+ fecha_final.substr(6,4) );
	msPorDia = 24 * 60 * 60 * 1000
	NumNits = Math.round((fechaFin - fechaIni) / msPorDia)
	//document.getElementById('divDiaEntrada').innerHTML = weekDay[fechaIni.getDay()];
	if (isNaN(NumNits) || NumNits<1){
		SumarDies(fechaIni,1);
	}else if (NumNits>15){
		alert(document.getElementByName('mensaje_error').value);
		SumarDies(fechaIni,15);
	} else {
		document.cerca_hotel.numNits.value = NumNits;
		//document.getElementById('divDiaSortida').innerHTML = weekDay[fechaFin.getDay()];
	}
}

function cambiaFiltroFlash(valueSel)
{	
	
}

function cambiaListadoAtractivos(IdZona)
{   
	objUL = document.getElementById("listaAtractivosTuristicos");
	arrChild = objUL.getElementsByTagName("li")
	
	for(i = 0; i < arrChild.length; i++)
	{
		objElem = arrChild[i];
		if ((IdZona == -1) || (objElem.id.indexOf("ditri" + IdZona + "_") > 0) )
			objElem.style.display = "block";
		else 
			objElem.style.display = "none";
	}
	
}

