currDate = new Date();
var d = currDate.getDate();
var m = currDate.getMonth()+1;
var y = currDate.getFullYear();
monthNames = new Array();
monthNames[1] = "January"
monthNames[2] = "February"
monthNames[3] = "March"
monthNames[4] = "April"
monthNames[5] = "May"
monthNames[6] = "June"
monthNames[7] = "July"
monthNames[8] = "August"
monthNames[9] = "September"
monthNames[10] = "October"
monthNames[11] = "November"
monthNames[12] = "December"

monthMax= new Array(31,31,29,31,30,31,30,31,31,30,31,30,31);

function findMonthIndex(str) {
if (str=="January") return 1
else if (str=="February") return 2
else if (str=="March") return 3
else if (str=="April") return 4
else if (str=="May") return 5
else if (str=="June") return 6
else if (str=="July") return 7
else if (str=="August") return 8
else if (str=="September") return 9
else if (str=="October") return 10
else if (str=="November") return 11
else if (str=="December") return 12
else return m;

}

// date validation part
function inRange (inputStr, lo, hi) {
	var num = parseInt(inputStr, 10)
	if (num<lo || num>hi) {
		return false
	}
	return true
}

function validateArrivalDate() {
var myinput = document.form1.ArrivalMonth.value
//var tMonthName = myinput.substring(0,myinput.indexOf("z"))
var tMonth = findMonthIndex(myinput);
var tYear =(document.form1.ArrivalYear.value)
var input = parseInt(document.form1.ArrivalDay.value, 10)

var monthField = tMonth
// var monthField= parseInt(tMonth, 10)

var top = monthMax[monthField]

if ((monthField==m) && (tYear ==y)){
	if (!inRange(input, d, top)) {
		return false
	} else {
		return true
	}
} else {
	if (!inRange(input, 1, top)) {
		return false
	} else {
		return true

	}
}
}

function validateDepartureDate() {
var myinput = document.form1.DepartureMonth.value
//var tMonthName = myinput.substring(0,myinput.indexOf("z"))
var tMonth = findMonthIndex(myinput);
var tYear =(document.form1.DepartureYear.value)
var input = parseInt(document.form1.DepartureDay.value, 10)
var monthField = tMonth
//var monthField= parseInt(tMonth, 10)

var top = monthMax[monthField]
if ((monthField==m) && (tYear ==y)){
	if (!inRange(input, d, top)) {
		return false
	} else {
		return true
	}
} else {
	if (!inRange(input, 1, top)) {
		return false
	} else {
		return true
	}
}
}
function validateDateDiff() {
	//myinput1=document.forms[0].DepartingMonth.value
	//myinput2=document.forms[0].select.value
	aday= parseInt(document.form1.ArrivalDay.value,10)
	amonth= findMonthIndex(document.form1.ArrivalMonth.value)
	ayear=parseInt(document.form1.ArrivalYear.value)
	dday= parseInt(document.form1.DepartureDay.value,10)
	dmonth= findMonthIndex(document.form1.DepartureMonth.value)
	dyear= parseInt(document.form1.DepartureYear.value)

	if (dyear == ayear) {
		if (dmonth < amonth) {
			return false
		} else if (amonth == dmonth) {
			if (dday < aday) return false
		else return true
		} else {
			return true
		}
	} else return true
}




function isNumber(str, len) {
	pattern= /^[\d]+$/
	if (str.length > len) return false;
	return (str.match(pattern))

}





function checkForm(local) {

str = local.Firstname.value
if ((str=="") || (!isString(str))) {
	alert("Your first name has not been entered \n or has been entered incorrectly")
	document.form1.Firstname.focus();
	document.form1.Firstname.select();
	return false
} 

str = local.Lastname.value
if ((str=="") || (!isString(str))) {
	alert("Your last name has not been entered \n or has been entered incorrectly")
	document.form1.Lastname.focus();
	document.form1.Lastname.select();
	return false
} 

str = local.Address.value
if ((str == "") ) {
	alert("Please enter your address")
	document.form1.Address.focus();
	document.form1.Address.select();
	return false
}

str = local.Office.value
if ((str =="") || (!isPhone(str))) {
	alert("Your office telephone number has not been entered \n or has been entered incorrectly")
	document.form1.Office.focus();
	document.form1.Office.select();
	return false
}

str = local.Home.value
if ((str != "") && (!isPhone(str))) {
	alert("Your home telephone number has \n been entered incorrectly")
	document.form1.Home.focus();
	document.form1.Home.select();
	return false
}

str = local.Mobile.value
if ((str != "") && (!isPhone(str))) {
	alert("Your mobile phone number has \n been entered incorrectly")
	document.form1.Mobile.focus();
	document.form1.Mobile.select();
	return false
}

str = local.Fax.value
if ((str != "") && (!isPhone(str))) {
	alert("Your fax number has \n been entered incorrectly")
	document.form1.Fax.focus();
	document.form1.Fax.select();
	return false
}

str = local.Email.value
if ((str != "") && (!isEmail(str)))  {
     alert("Your email address has not been entered \n or has been entered incorrectly")
     document.form1.Email.focus();
	 document.form1.Email.select();
     return false ;	                      
   }



   
   
str = local.Type.value
if((!document.form1.Type[0].checked) && (!document.form1.Type[1].checked) && (!document.form1.Type[2].checked)){
	alert("Please select a room type")
	document.form1.Type[0].focus();
	return false;
	}
	
str = local.no1.value	
if ((document.form1.Type[0].checked)&&(str == "")){
	alert("Please enter a valid value for number of rooms");
	document.form1.no1.focus();
	document.form1.no1.select();
	return false;	
}

if((str != "") && (!isNumber(str))){
	alert("Please enter a valid value for number of rooms");
	document.form1.no1.focus();
	document.form1.no1.select();
	return false
	}




str = local.no2.value	
if ((document.form1.Type[1].checked)&&(str == "")){
	alert("Please enter a valid value for number of rooms");
	document.form1.no2.focus();
	document.form1.no2.select();
	return false;	
}

if((str != "") && (!isNumber(str))){
	alert("Please enter a valid value for number of rooms");
	document.form1.no2.focus();
	document.form1.no2.select();
	return false
	}
	

	
   
   
   
   
	
	str = local.Adults.value;	
	if((str != "") && (!isNumber(str))){
	alert("Please enter a valid value for number of adults");
	document.form1.Adults.focus();
	document.form1.Adults.select();
	return false
	}
	
	str = local.Children.value;	
	if((str != "") && (!isNumber(str))){
	alert("Please enter a valid value for number of children");
	document.form1.Children.focus();
	document.form1.Children.select();
	return false
	}

    if((!document.form1.Children.value =="") && (document.form1.Adults.value=="")){	
	alert("Adult(s) must accompany children");
	document.form1.Adults.focus()
	return false
    }
	
	
	
	
   if((!document.forms[0].Mealplan[0].checked) && (!document.forms[0].Mealplan[1].checked)){
	alert("Please select the meal plan")
	document.form1.Mealplan[0].focus();
	return false;
	
	}
   
   
   
//Arrival date
if  (!validateArrivalDate()) {
	alert("Arrival date is invalid.");
	document.form1.ArrivalDay.focus()
	return false
}

//Departure date
if (!validateDepartureDate()) {
		alert("Departure date is invalid");
		document.form1.DepartureDay.focus()
		return false
	}	
		
		//Date difference
 if (!validateDateDiff()) {
		alert("Arrival date must be before departure date.");
		document.form1.ArrivalDay.focus()
		return false
	}


   
return true
}


function isString(str) {
	pattern = /^[a-zA-Z\s]+$/ 
	if (!str.match(pattern)) return false
	else return true;
}


function isPhone(str) {
	pattern = /^[0-9\s\+\,\\\/\(\)\-]+$/
	if (!str.match(pattern)) return false
	else return true;
}

function isEmail(str) {	 
	pattern = /^.+\@.+\..+$/
	if (!str.match(pattern))   return false
	else return true;

}	

function isNumber(str) {
	pattern= /^[0-9\s]+$/
	if (!str.match(pattern)) return false
	else return true;
}

<!--
	function openWindow(pPos)
	{
		whereto = A_Images[A_Positions[pPos].CurImage].Link
		
		var newWin = window.open(whereto, "lademasiada", "screenX=200,screenY=100,top=112,left=225,width=390,height=295,resizable=0,scrollbars=1,dependent=1")
	}
function openMap(whereto)
	{
		var newWin = window.open(whereto, "lademasiada", "screenX=200,screenY=100,top=112,left=225,width=340,height=425,resizable=0,scrollbars=1,dependent=1")
	}
	
function openGallery(whereto)
	{
		var newWin = window.open(whereto, "lademasiada", "screenX=40,screenY=40,top=15,left=10,width=760,height=500,resizable=0,scrollbars=1,dependent=1")
	}
	
//-->