// JavaScript Document
function modifie_datearrivee()
{
				var da = document.idForm.datearrivee.value ;
				var fd = document.idForm.fromday ;
				var fm = document.idForm.frommonth ;
				var fy = document.idForm.fromyear ;
				var tab = da.split("/");
				//alert(da);
				fd.value = tab[0] ;
				fm.value = tab[1] ;
				fy.value = tab[2] ;
				
				compter_nbnuits();
}			

function modifie_datedepart()
{
				var dd = document.idForm.datedepart.value ;
				var td = document.idForm.today ;
				var tm = document.idForm.tomonth ;
				var ty = document.idForm.toyear ;
				var tab = dd.split("/");
				//alert(dd);
				td.value = tab[0] ;
				tm.value = tab[1] ;
				ty.value = tab[2] ;
			
				compter_nbnuits();				
}
		
function compter_nbnuits()
{
				//arrivee
				var fd = document.idForm.fromday.value ;
				var fm = document.idForm.frommonth.value ;
				var fy = document.idForm.fromyear.value ;
				
				//depart
				var td = document.idForm.today.value ;
				var tm = document.idForm.tomonth.value ;
				var ty = document.idForm.toyear.value ;
				
				if ( td != "" && fd != "" )
				{		
					var datearrivee		= new Date(fy+"/"+fm+"/"+fd);
					var datedepart 		= new Date(ty+"/"+tm+"/"+td);

					var one_day = 1000*60*60*24;
					var nbjours = Math.ceil( (datedepart.getTime() - datearrivee.getTime( ) ) / (one_day) );
		
					document.idForm.nbdays.value = (nbjours<0)?0:nbjours ;									
				}
}
			
function estInferieur(pda,pdd)
{
				var tabda = pda.split("/");		
				var tabdd = pdd.split("/");			
				var da = new Date(tabda[2]+"/"+tabda[1]+"/"+tabda[0]);
				var dd = new Date(tabdd[2]+"/"+tabdd[1]+"/"+tabdd[0]);
				var one_day = 1000*60*60*24;
				var nbjours = Math.ceil( (dd.getTime() - da.getTime( ) ) / (one_day) );				
				return (nbjours<=0)?1:0;		
}
			
function estInferieurAuj(daty)
{
				var tab = daty.split("/");							
				var one_day = 1000*60*60*24;
				var dat = new Date(tab[2]+"/"+tab[1]+"/"+tab[0]);
				var auj = new Date();
				var nbjours = Math.ceil( (dat.getTime() - auj.getTime( ) ) / (one_day) );				
				return (nbjours<0)?1:0;		
}
			
function test_resa()
{
				if ( document.idForm.datearrivee.value == "" || estInferieurAuj( document.idForm.datearrivee.value ) == 1 )
				{
					alert("Please specify dates\nExpress reservation\nCheck-in date superior or equal date now");
					return false ;
				}
				if ( document.idForm.datedepart.value == "" || estInferieur( document.idForm.datearrivee.value, document.idForm.datedepart.value ) == 1 )
				{
					alert("Please specify dates\nExpress reservation\nCheck-out date superior check-out date");
					return false ;
				}				
				/*if ( document.idForm.nbdays.value == 0 )
				{
					alert("Veuillez bien specifier les dates");
					return false ;
				}*/
				
				var  verif = /^[1-4]$/
				if ( verif.exec(document.idForm.adulteresa.value) == null )
				{
					alert("Adults number (1 to 4) ");
					document.idForm.adulteresa.value = "" ;
					document.idForm.adulteresa.focus();
					return false;
				}
				hhotelDispoprice(document.idForm);
}
