// JavaScript Document

// Un dia més a entrada!

/*var arad=new Date();
var ara=new Date(arad.getTime()+3600*24*1000*1);
var despres=new Date(arad.getTime()+3600*24*1000*2);
ara=ara.getDate()+"-"+(ara.getMonth()+1)+"-"+ara.getFullYear();
despres=despres.getDate()+"-"+(despres.getMonth()+1)+"-"+despres.getFullYear();
document.formulario.fechainicio.value=ara;*/



function updateNits() {
	dif=document.formulario.fechainicio.value;
	nits=document.formulario.nits;
	
	tauladif=/([0-9]+)-([0-9]+)-([0-9]+)/i.exec(dif);
	
	difd=new Date(tauladif[3],tauladif[2]-1,tauladif[1],0,0,0);
	
	dffd=new Date(difd.getTime()+(parseInt(nits.selectedIndex)+1)*86400000);

	document.formulario.fechafinal.value=dffd.getDate()+"-"+(dffd.getMonth()+1)+"-"+dffd.getFullYear();
}

function updateSortida() {
	dif=document.formulario.fechainicio.value;
	dff=document.formulario.fechafinal.value;

	tauladif=/([0-9]+)-([0-9]+)-([0-9]+)/i.exec(dif);
	tauladff=/([0-9]+)-([0-9]+)-([0-9]+)/i.exec(dff);

	difd=new Date(tauladif[3],tauladif[2]-1,tauladif[1],0,0,0);
	dffd=new Date(tauladff[3],tauladff[2]-1,tauladff[1],0,0,0);
	
	document.formulario.nits.selectedIndex=Math.ceil((dffd.getTime()-difd.getTime())/86400000)-1;
}

function reserves () {
	document.formulario.action="#";

	//var tipus="onescreen";
	var tipus="istay";
	
	// HotelID
	hotelidfield=document.formulario.hotels;
	var jsHotelID=hotelidfield[hotelidfield.selectedIndex].value;

	// 1.	DateIn in the format of MM/DD/YYYY Length
	dif=document.formulario.fechainicio.value;
	dff=document.formulario.fechafinal.value;

	tauladif=/([0-9]+)-([0-9]+)-([0-9]+)/i.exec(dif);
	tauladff=/([0-9]+)-([0-9]+)-([0-9]+)/i.exec(dff);

	difd=new Date(tauladif[3],tauladif[2]-1,tauladif[1],0,0,0);
	dffd=new Date(tauladff[3],tauladff[2]-1,tauladff[1],0,0,0);


	// DateIn
	var jsDateIn=tauladif[2]+"/"+tauladif[1]+"/"+tauladif[3];

	// Length
	var jsLength=Math.ceil((dffd-difd)/86400000);

	// Adults
	adultsfield=document.formulario.Adults;
	var jsAdults=adultsfield[adultsfield.selectedIndex].value;

	// Children
	childrenfield=document.formulario.Children;
	var jsChildren=childrenfield[childrenfield.selectedIndex].value;

	// Rooms
	roomsfield=document.formulario.Rooms;
	var jsRooms=roomsfield[roomsfield.selectedIndex].value;

	
	// Language ID

	taulaIdiomes=new Array();
	taulaIdiomes[0]=20;
	taulaIdiomes[1]=2;
	taulaIdiomes[2]=20;
	taulaIdiomes[3]=1;
	taulaIdiomes[4]=3;

	var jsLanguageID=taulaIdiomes[parseInt(document.formulario.idiomareserves.value)];
	
	if (jsHotelID!='seleccionar') {
		window.open('http://reservations.ihotelier.com/'+tipus+".cfm?HotelID="+jsHotelID+"&DateIn="+jsDateIn+"&Length="+jsLength+"&Adults="+jsAdults+"&Children="+jsChildren+"&Rooms="+jsRooms+"&LanguageID="+jsLanguageID);
	} else {
		alert(document.formulario.msgSelectHotel.value);
		return false;
	}
	
	

}