function getYear(d) {
return (d < 1000) ? d + 1900 : d;
}

function isDate (year, month, day) {
// month argument must be in the range 1 - 12
month = month - 1; // javascript month range : 0- 11
var tempDate = new Date(year,month,day);
if ( (getYear(tempDate.getYear()) == year) &&
(month == tempDate.getMonth()) &&
(day == tempDate.getDate()) )
return true;
else
return false
}

function getDate(strDate){	  
	day = strDate.substring(0,2);
	month = strDate.substring(3,5);
	year = strDate.substring(6,10);
	d = new Date();
	d.setDate(day);
	d.setMonth(month);
	d.setFullYear(year); 
	return d;  
}

function compare(date_1, date_2){
	diff = date_1.getTime() - date_2.getTime();
	return (diff==0?diff:diff/Math.abs(diff));
}

function SubmitForm()
{

var DateArrivee = document.search.dayArrivee.value+'/'+document.search.monthArrivee.value+'/'+document.search.yearArrivee.value;
var DateDepart = document.search.dayDepart.value+'/'+document.search.monthDepart.value+'/'+document.search.yearDepart.value;


if ( compare(getDate(DateArrivee),getDate(DateDepart)) == 1 )
{
	alert('date d\'arrivée est inferieure à la la date de départ');
	return;
}

var dayArrivee = document.search.dayArrivee.value;
var monthArrivee = document.search.monthArrivee.value;
var yearArrivee = document.search.yearArrivee.value;

var dayDepart = document.search.dayDepart.value;
var monthDepart = document.search.monthDepart.value;
var yearDepart = document.search.yearDepart.value;

var DateDabutSession = document.search.DateDebutSession.value;
var DateFinSession = document.search.DateFinSession.value;

if ( (isDate(yearArrivee,monthArrivee,dayArrivee) == false) || (isDate(yearDepart,monthDepart,dayDepart) == false) )
{
	alert('Les dates de resérvation sont invalides.');
	return;
}


if ( DateDabutSession.length != 0 || DateFinSession.length != 0 )
{
	if ( DateArrivee != DateDabutSession ||  DateDepart != DateFinSession )
	{
		var r=confirm("Le changement de date annulera votre réservation en cours.");
		if (r==true) 
		{
			window.open('../../publish/reservation/validerreservation.asp?validateAction=annuler&DateArrivee='+DateArrivee+'&DateDepart='+DateDepart,'_self');
			return;
		}
	}
	else
	{
		document.getElementById('hid').src ='../reservation/SetSession.asp?dayArrivee='+dayArrivee+'&monthArrivee='+monthArrivee+'&yearArrivee='+yearArrivee+'&dayDepart='+dayDepart+'&monthDepart='+monthDepart+'&yearDepart='+yearDepart;
		var t = setTimeout('window.open("../../publish/reservation/reservationchambre.asp?DateArrivee='+DateArrivee+'&DateDepart='+DateDepart+'&NbrChambre='+document.search.NbrChambre.value+'&FormAction=search&FormName=search&headerReservation=1","_self")',500)
	}
}
else
{
		document.getElementById('hid').src ='../reservation/SetSession.asp?dayArrivee='+dayArrivee+'&monthArrivee='+monthArrivee+'&yearArrivee='+yearArrivee+'&dayDepart='+dayDepart+'&monthDepart='+monthDepart+'&yearDepart='+yearDepart;
		var t = setTimeout('window.open("../../publish/reservation/reservationchambre.asp?DateArrivee='+DateArrivee+'&DateDepart='+DateDepart+'&NbrChambre='+document.search.NbrChambre.value+'&FormAction=search&FormName=search&headerReservation=1","_self")',500)
}
};

function SubmitFormRes()
{

	window.open("../../publish/reservation/reservationchambre.asp?DateArrivee="+DateArrivee+"&DateDepart="+DateDepart+"&NbrChambre="+document.search.NbrChambre.value+"&FormAction=search&FormName=search&headerReservation=1",'_self');

};

function SubmitFormResa()
{
var DateArrivee = document.initReservationtraite.DateArrivee.value;
var DateDepart = document.initReservationtraite.DateDepart.value;

	window.open("../../publish/reservation/reservationchambre.asp?DateArrivee="+DateArrivee+"&DateDepart="+DateDepart+"&NbrChambre="+document.initReservationtraite.NbrChambreInfo.value+"&FormAction=search&FormName=search&headerReservation=1",'_self');
}
function AjouterList(thisCheckbox)
{

var IDProduitAjouter = ""; 

		if (thisCheckbox.checked==true) 
		{
			document.listproduit.produitsAjoute.value = document.listproduit.produitsAjoute.value + thisCheckbox.value+'@';
			MajNbrSelected();
		}
		else
		{	produitSeleccted = document.listproduit.produitsAjoute.value		
				if (produitSeleccted.indexOf(thisCheckbox.value) != 0 )
				{
					document.listproduit.produitsAjoute.value = document.listproduit.produitsAjoute.value.replace(thisCheckbox.value + '@','')
					MajNbrSelected();
				}
				if ( (produitSeleccted.indexOf(thisCheckbox.value) == 0 ) && (thisCheckbox.value != "") )
				{
					document.listproduit.produitsAjoute.value = document.listproduit.produitsAjoute.value.replace(thisCheckbox.value + '@','')
					MajNbrSelected();
				}
		}

};

function MajNbrSelected()
{
var count = 0
	count = document.listproduit.produitsAjoute.value.split('@');
	document.getElementById("nSelected").innerHTML = count.length-1;
}


function check_Valider() 
{
var IDQuitsEnc = ""; 

			document.listproduit.FormAction.value = 'valider';
			document.listproduit.submit();

}
