<!-- BEGIN
/**
 * Do form date validation script for dd-mm-yyyy.
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "-";
var minYear=2010;
var maxYear=2100;


function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){

	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)

	chkyear= year + '';		// -- adding the  + '' makes a string )instead of number) so that they can be joined end on end below
	chkmonth= month + '';
	chkday= day + '';
	
	if(chkmonth.length == 1) { chkmonth = "0" + chkmonth; }
	if(chkday.length == 1) { chkday = "0" + chkday; }

	var chkDate = chkyear + chkmonth + chkday;

	window.passthroDate = chkyear + chkmonth + chkday;	// Makes variable "global" by writing "window." in front. (Note : do not write "var" in front!)
	window.passthroY = chkyear;
	window.passthroM = chkmonth;
	window.passthroD = chkday;



	var todaysdate = Number(document.resform.todaysdate.value);

	if(chkDate < todaysdate){
		alert(" " + chkday + "-" + chkmonth + "-" + chkyear + " is in the past!\n_________________________________________\n\n " + chkday + "-" + chkmonth + "-" + chkyear + " est dans le passé!")
		return false
	}



	if (pos1==-1 || pos2==-1){
		alert("The date formats must be 'dd-mm-yyyy',  e.g. '31-12-2007'\n\n_________________________________________\n\nLa forme des dates doit etre 'dd-mm-yyyy',  ex. '31-12-2007'")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid 'month'\n_________________________________________\n\nVeuillez saisir un 'mois' valide")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid 'day'\n_________________________________________\n\nVeuillez saisir un 'jour' valide")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear +"\n_________________________________________\n\nVeuillez saisir un année valide entre "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date \n\n(Date format: dd-mm-yyyy,  e.g. 31-12-2007\n\n_________________________________________\n\nVeuillez saisir une date valide\n\n(Forme de la date: dd-mm-yyyy,  ex. 31-12-2007")
		return false
	}

return true
}


function ValidateDates(){

	var dta=document.resform.arrive
	var dtd=document.resform.depart


	if (isDate(dta.value)==false) {
		dta.focus()
		return false

	} else 



	arriveDate = Number(window.passthroDate);	// Format = yyyymmdd

	arrD = window.passthroD;
	arrM = window.passthroM - 1;	// in JavaScript Months are 0-11 , so must subtract 1 from passthroM to get correct javascript value for month
	arrY = window.passthroY;
	
	var arrinDays = new Date(arrY, arrM, arrD) 

	if (isDate(dtd.value)==false) {
		dtd.focus()
		return false

	} else 



	departDate = Number(window.passthroDate);	// Format = yyyymmdd

	depD = window.passthroD;
	depM = window.passthroM - 1;	// in JavaScript Months are 0-11 , so must subtract 1 from passthroM to get correct javascript value for month
	depY = window.passthroY;
	
	var depinDays = new Date(depY, depM, depD); 


	if (arriveDate >= departDate) {
		alert("The departure date is before or the same as the arrival date!\n\nPlease correct the dates....\n\n_________________________________________________\n\nLa date de départ est antérieure ou la même que la date d'arrivée!\n\nS'il vous plaît corriger les dates....")
		document.resform.depart.focus()
		return false

	} else  


		// -- Check the stay is no longer than 30 days 

		var one_day = 1000*60*60*24;	// Get 1 day in milliseconds

		// Calculate difference between the two dates, and convert to days
		// Date.getTime() is a prebuilt JS method that returns the time elapsed from January 1st, 1970 to the current Date instance, in milliseconds

		depinDays = Math.floor( (depinDays.getTime() / one_day));	// Rounds "down" so as only to include "completed" nights
		arrinDays = Math.floor( (arrinDays.getTime() / one_day));

		var resaLength = depinDays - arrinDays;	// Round down so as only to count "completed" nights

//		alert(resaLength + " nights");

		if(resaLength > 30) {

		alert("There is a maximum stay length of 30 nights per reservation. (You have requested " + resaLength + " nights.) \n\nPlease send two separate reservations if you wish to stay longer than 30 nights. Thank you.\n___________________________________________________________________________\n\nIl s'agit d'une longueur maximale de séjour de 30 nuits par réservation. (Vous avez demandé  " + resaLength + " nuits.) \n\nS'il vous plaît d'envoyer deux réservations distinctes si vous souhaitez rester plus de 30 nuits. Merci.");
		document.resform.depart.focus();
		return false

	} else {

  	  return true

	}

}


// END -->