	function checkdate(bdDay, dbMonth, dbYear)
	{
		if(!IsValidDate(bdDay, dbMonth, dbYear)) 
		{
			return false;
		}
		return true;
	}

	function DaysInMonth(CMonth,CYear)
	{
		 var intMonth = parseInt(CMonth);
		 var intYear = parseInt(CYear);
		 if ((intMonth == 4) ||
		  (intMonth == 6) ||
		  (intMonth == 9) ||
		  (intMonth == 11))
		  return 30;
		 if (intMonth==2) {  // Leap year stuff
		  if ((intYear % 400)==0) return 29;
		  if ((intYear % 100)==0) return 28;
		  if ((intYear % 4)==0) return 29;
		  return 28;
		 }
		 return 31;
	}

	function IsDate(CDay, CMonth, CYear)
	{
		if ((CDay <= 0) || (CDay > 31) ||
		(CMonth <= 0) || (CMonth > 12) ||
		(CYear <= 0))
		return false;
		var intDay = parseInt(CDay);
		var intMonth = parseInt(CMonth);
		var intYear = parseInt(CYear);
		if (intDay <= DaysInMonth(intMonth, intYear)) return true;
		return false;
	}

	function IsValidDate(CDay, CMonth, CYear)
	{
		if(!IsDate(CDay, CMonth, CYear)) 
		{
			alert("Please select valid date");
			return false;
		}
		Today = new Date();
		DayBeforeYesterday = new Date((Today.getTime() - 172800000));
		Hours = Today.getHours();
		Minutes = Today.getMinutes()+1;
		Seconds = Today.getSeconds();
		StartDate= new Date(CYear,(CMonth - 1),CDay,Hours,Minutes,Seconds);
		if (StartDate<Today) 
		{ 
			alert("Date must be above current date!");
			return false;
		}
		return true;
	}

	function checkEmail(myForm)
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value))
		{
			return (true);
		}
		alert("Invalid e-mail address! please re-enter");
		return (false);
	}

	function trim(inputString) 
	{
		if (typeof inputString != "string") { return inputString; }
		var retValue = inputString;
		var ch = retValue.substring(0, 1);
		while (ch == " ") 
		{ 
			retValue = retValue.substring(1, retValue.length);
			ch = retValue.substring(0, 1);
		}
		ch = retValue.substring(retValue.length-1, retValue.length);
		while (ch == " ") 
		{
			retValue = retValue.substring(0, retValue.length-1);
			ch = retValue.substring(retValue.length-1, retValue.length);
		}
		while (retValue.indexOf("  ") != -1) 
		{ 
			retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
		}
		return retValue; 
	} 

	function checkTourCriteria(mf)
	{
		if(mf.tyear.value!="" && mf.tmonth.value!="" && mf.tdays.value!="")
		{
			if(!checkdate(mf.tdays.value, mf.tmonth.value, mf.tyear.value))
			{
				mf.tyear.focus();
				return false;
			}
		}
		if(mf.tduration.value=="")
		{
			alert("Please enter tour duration");
			mf.tduration.focus();
			return false;
		}
		if(isNaN(mf.tduration.value))
		{
			alert("Please enter tour duration in numbers only");
			mf.tduration.focus();
			return false;
		}
		if(mf.adults.value=="")
		{
			alert("Please select number of adults");
			mf.adults.focus();
			return false;
		}
		return true;
	}
	
	function checkTourPsgInfo(mf)
	{
		var i;
		// adults info
		if(mf.adults.value!="")
		{
			for(i=1;i<=mf.adults.value;i++)
			{
				adultstr = "adult" + i;
				adultagestr = "adultage" + i;
				adname = document.getElementById(adultstr).value;
				adage = document.getElementById(adultagestr).value;
				if(adname=="")
				{
					alert("Please enter adult name");
					document.getElementById(adultstr).focus();
					return false;
				}
				if(adage=="")
				{
					alert("Please enter adult age");
					document.getElementById(adultagestr).focus();
					return false;
				}
				if(isNaN(adage))
				{
					alert("Please enter adult age in numbers only");
					document.getElementById(adultagestr).focus();
					return false;
				}
				if(adage<=12)
				{
					alert("Adult age must be above 12 years");
					document.getElementById(adultagestr).focus();
					return false;
				}
			}
		}
		// child info
		if(mf.childs.value!="")
		{
			for(i=1;i<=mf.childs.value;i++)
			{
				adultstr = "child" + i;
				adultagestr = "childage" + i;
				adname = document.getElementById(adultstr).value;
				adage = document.getElementById(adultagestr).value;
				if(adname=="")
				{
					alert("Please enter child name");
					document.getElementById(adultstr).focus();
					return false;
				}
				if(adage=="")
				{
					alert("Please enter child age");
					document.getElementById(adultagestr).focus();
					return false;
				}
				if(isNaN(adage))
				{
					alert("Please enter child age in numbers only");
					document.getElementById(adultagestr).focus();
					return false;
				}
				if(adage>12 || adage<4)
				{
					alert("Child age must be 4 to 12 years");
					document.getElementById(adultagestr).focus();
					return false;
				}
			}
		}
		// infants info
		if(mf.infants.value!="")
		{
			for(i=1;i<=mf.infants.value;i++)
			{
				adultstr = "infant" + i;
				adultagestr = "infantage" + i;
				adname = document.getElementById(adultstr).value;
				adage = document.getElementById(adultagestr).value;
				if(adname=="")
				{
					alert("Please enter infant name");
					document.getElementById(adultstr).focus();
					return false;
				}
				if(adage=="")
				{
					alert("Please enter infant age");
					document.getElementById(adultagestr).focus();
					return false;
				}
				if(isNaN(adage))
				{
					alert("Please enter infant age in numbers only");
					document.getElementById(adultagestr).focus();
					return false;
				}
				if(adage>3 || adage<0)
				{
					alert("Infant age must be upto 3 years");
					document.getElementById(adultagestr).focus();
					return false;
				}
			}
		}
		if(mf.customertype.value=="")
		{
			alert("Please select customer type");
			mf.customertype.focus();
			return false
		}
		return true;
	}

	function checkTourBookInfo(mf)
	{
		if(mf.name.value=="")
		{
			alert("Please enter name");
			mf.name.focus();
			return false;
		}
		if(mf.address.value=="")
		{
			alert("Please enter address");
			mf.address.focus();
			return false;
		}
		if(mf.city.value=="")
		{
			alert("Please enter city");
			mf.city.focus();
			return false;
		}
		if(mf.state.value=="")
		{
			alert("Please enter state");
			mf.state.focus();
			return false;
		}
		if(mf.country.value=="")
		{
			alert("Please enter country");
			mf.country.focus();
			return false;
		}
		if(mf.zipcode.value=="")
		{
			alert("Please enter zip code");
			mf.zipcode.focus();
			return false;
		}
		if(mf.phone.value=="")
		{
			alert("Please enter telephone number");
			mf.phone.focus();
			return false;
		}
		var valid= "+-()1234567890 ";
		if (mf.phone.value !="")
		{
			var string = mf.phone.value
			var length = string.length;
			for(var i=0;i<=length;i++)
			{
				var substring = string.substr(i,1);
				if(valid.indexOf(substring)== -1)
				{
					alert("Please enter valid telephone number");
					mf.phone.select()
					return(false)
				}
			}
		}
		if(trim(mf.email.value)=="")
		{ 
			alert("Please enter your e-mail address");
			mf.email.focus();
			return false;
		}
		if(checkEmail(mf)==false)
		{
			mf.email.focus();
			return false; 
		}
		if(mf.customertype.value==2)
		{
			if(mf.payment_type.value=="")
			{
				alert("Please select payment method");
				mf.payment_type.focus();
				return false;
			}
		}
		return true;;
	}

	function checkLogin(mf)
	{
		if(mf.aguserid.value=="")
		{
			alert("Please enter username");
			mf.aguserid.focus();
			return false;
		}
		if(mf.aguserpass.value=="")
		{
			alert("Please enter password");
			mf.aguserpass.focus();
			return false;
		}
		return true;
	}

	function openurl(imgfile)
	{
		window.open(imgfile,'prod','width=700,height=481,status=no, scrollbars=yes')
	}
	
	function checkCompLogin(mf)
	{
		if(mf.cmpuserid.value=="")
		{
			alert("Please enter company account number");
			mf.cmpuserid.focus();
			return false;
		}
		if(mf.cmpuserpass.value=="")
		{
			alert("Please enter password");
			mf.cmpuserpass.focus();
			return false;
		}
		return true;
	}

	function checkBookNow(mf)
	{
		if(mf.adults.value=="" || mf.adults.value=="0")
		{
			alert("Please enter number of adults");
			mf.adults.focus();
			return false;
		}
		if(isNaN(mf.adults.value))
		{
			alert("Please enter number of adults in numeric only");
			mf.adults.focus();
			return false;
		}
		if(mf.childs.value!="")
		{
			if(isNaN(mf.childs.value))
			{
				alert("Please enter number of child in numeric only");
				mf.childs.focus();
				return false;
			}
		}
		if(mf.infants.value!="")
		{
			if(isNaN(mf.infants.value))
			{
				alert("Please enter number of infants in numeric only");
				mf.infants.focus();
				return false;
			}
		}
		return true;
	}
	