//Validation.js

var reqError = new Array();
reqError[1] ="Please Select a country.\n";
//reqError[11] ="Set the No. of Rooms.\n";
//reqError[12] = "Set the No. of Adults.\n";
reqError[13] = "No of Adults must be greater or equal to No of Rooms";
reqError[14] = "Invalid Children's Age\n";
popupwindow=null;


	var ErrDate1="Please enter Arrival / Departure Dates."
	var ErrDate2="Please enter a valid Arrival Date."
	var ErrDate3="The Date entered is in the past. Please enter a valid Arrival Date."
	var ErrDate3a="Sorry, we could process reservations that are at least 3 days prior to date of arrival."
	var ErrDate4="Please enter a valid Departure Date."
	var ErrDate5="Your period of stay should be less than 31 days stay."
	var ErrDate6="The Departure Date should be later than the Arrival Date."

function validDate(year, month, day) {
	var tempDate = new Date(year, month, day)
	return tempDate.getDate() == day
}

//submit the form
function checkDate(form) {
	//Arrival date valid?
	if (!validDate(cInYear[cInYear.selectedIndex].text, cInMonth.selectedIndex, cInDay.selectedIndex+1)) {
		alert(ErrDate2)
		cInDay.focus()
		return	false
	}
	var todayDate = new Date()
	var checkinDate= new Date(eval(cInYear[cInYear.selectedIndex].text), cInMonth.selectedIndex, cInDay.selectedIndex+1, 0,1,0)

	//var mDiff=	Date.UTC(checkinDate) - Date.UTC(currentDate)
	todayDate.setHours(0)
	todayDate.setMinutes(0)
	todayDate.setSeconds(0)

	// Date is in the past?
	if (checkinDate < todayDate) {
		alert(ErrDate3)
		cInDay.focus()
		return	false}

	todayDate.setDate(todayDate.getDate()+skipDate-1)
	todayDate.setMinutes(0)
	checkinDate.setMinutes(0)
	if (checkinDate < todayDate) {
		alert(ErrDate3a)
		cInDay.focus()
		return	false}

	//Departure Date Valid?
	if (!validDate(cOutYear[cOutYear.selectedIndex].text, cOutMonth.selectedIndex, cOutDay.selectedIndex+1)) {
		alert(ErrDate4)
		cOutDay.focus()
		return	false}

	// Departure - Arrival >1 year?
	var msDifference = Date.UTC(cOutYear[cOutYear.selectedIndex].text, cOutMonth.selectedIndex, cOutDay.selectedIndex+1) - Date.UTC(cInYear[cInYear.selectedIndex].text, cInMonth.selectedIndex, cInDay.selectedIndex+1)
	if (msDifference > 2592000000) {  //31 days in milliseconds
		alert(ErrDate5)
		cOutDay.focus()
		return	false}

	// Departure < Arrival?
	if (msDifference <= 0) {
		alert(ErrDate6)
		cOutDay.focus()
		return	false}
//	form.submit()
popup()
return true

}

function checkrq(which) {
var pass=true
	if (!checkDate(which)){
		return false
	}else{
	which.arrival.value = (eval(which.arrival2.selectedIndex+"+1"))+"/"+which.arrival1[which.arrival1.selectedIndex].text+"/"+which.arrival3[which.arrival3.selectedIndex].text
	which.departure.value = (eval(which.depart2.selectedIndex+"+1"))+"/"+which.depart1[which.depart1.selectedIndex].text+"/"+which.depart3[which.depart3.selectedIndex].text
	}

	if (document.images) 
	{
		var t=0;
		for (i=0;i<which.length;i++) 
		{
			var tempobj=which.elements[i]
			if(!tempobj.name.indexOf("Availability1:txtAgeOfChild")){
				if(tempobj.value < 1 || isNaN(tempobj.value)|| (tempobj.value.indexOf("."))>=0){
					pass=false
					t=14
					break
				}
			}
			if(!tempobj.name.indexOf("adult")){
				if(cAdult.selectedIndex < cUnit.selectedIndex){
					pass=false
					t=13
					break
				}
			}

		}
	}
	if (!pass) 
	{
		alert(reqError[t])
		tempobj.focus()

		return false
	}
	return true
}

function popup(){
   //popupwindow = window.open('http://www.holidaycity.com/hcrs/search/wait.html',
   //'waitwindow','width=350,height=263,top=200,left=200')
}

function popup1(){
   //popupwindow = window.open('http://www.holidaycity.com/hcrs/search/wait1.html',
   //'waitwindow','width=350,height=263,top=200,left=200')
}

function closepopup(){
if (popupwindow!=null)
   popupwindow.close()
}