
function hidemessage()
{document.getElementById("messagediv").innerHTML="";}
function showcomboifhidden()
{if(document.getElementById("cal_div").style.visibility=="hidden"){showcombo();}}
function dropdatestatus()
{
	if ((document.frmf.usage.selectedIndex=="3")||(document.frmf.usage.selectedIndex=="4")){document.getElementById('dropoff').style.display="block";document.getElementById('dropoff1').style.display="block";document.frmf.dropoffdate.value="yyyy-mm-dd";}
	else
	{document.getElementById('dropoff').style.display="none";document.getElementById('dropoff1').style.display="none";}
	
	
}

function advbooking()
{
//alert("hi");
	var  arrFromDate = document.frmf.pickupdate.value.split("-");
	var useFromDate=new Date(arrFromDate[0], arrFromDate[1]-1, arrFromDate[2]);
	var now = new Date();
	var dateplus2 = now.getDate()+2;
	var today = new Date(now.getFullYear(),now.getMonth(),dateplus2);
	if(useFromDate <= today) {alert("Sorry we only provide online booking facility for a minimum of two days advance booking. For urgent queries please contact our customer support desk now at (416) 323-9898."); return false;}
	
}

function seeDates()
{
var time1=document.frmf.checkin_time.value.split(" ");
var time2=document.frmf.checkout_time.value.split(" ");

var t1=time1[0].split(":");
var t2=time2[0].split(":");
if(t1[0]=="12"){t1[0]-=12;}
if (time1[1]=="PM"){t1[0]+=12;}
if(t2[0]=="12"){t2[0]-=12;}
if (time2[1]=="PM"){t2[0]+=12;}
var timevalue1 = Number((t1[0]*100)+t1[1]);
var timevalue2 = Number((t2[0]*100)+t2[1]);
//alert(timevalue1);
	
	
chkform();	
}

function chkform()
{
	if(document.frmf.city_name.value=="select")
			{
				alert("Please choose a city.");
				document.frmf.city_name.focus();
				return false;
			}
	
	
	if (document.frmf.usage.value=="select")
			{
				alert("Please choose the type of requirement.");
				document.frmf.usage.focus();
				return false;
			}
	if(document.frmf.pickupdate.value=="yyyy-mm-dd")
			{
				alert("Please enter a pick up date.");
				document.frmf.pickupdate.focus();
				return false;
			}
	if(document.getElementById('dropoff1').style.display!="none")
	{
	if(document.frmf.dropoffdate.value=="yyyy-mm-dd")
			{
				alert("Please enter drop off date.");
				document.frmf.dropoffdate.focus();
				return false;
			}
	}
	if(document.frmf.checkin_time.value=="select")
			{
				alert("Please enter enter your prefered pick up time.");
				document.frmf.checkin_time.focus();
				return false;
			}
	if(document.frmf.checkout_time.value=="select")
			{
				alert("Please enter your preferred drow off time.");
				document.frmf.checkout_time.focus();
				return false;
			}
	
	if(document.frmf.iresidein.value=="0")
			{
				alert("Please enter your country of residence.");
				document.frmf.iresidein.focus();
				return false;
			}
	
	checkdates1();
}

var dtCh= "-";
var minYear=2008;
var maxYear=2010;

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 strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=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)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : YYYY-mm-dd")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function checkdates1()
{
//alert("hi");
var  arrFromDate = document.frmf.pickupdate.value.split("-");
	var  arrToDate = document.frmf.dropoffdate.value.split("-");
		
	if (!isDate(document.frmf.pickupdate.value)){alert("invalid date. enter a proper date using the calendar.");document.frmf.pickupdate.value="";return false;}
	if(document.getElementById('dropoff1').style.display!="none")
	{
		if (!isDate(document.frmf.dropoffdate.value)){alert("invalid date. enter a proper date using the calendar.");document.frmf.dropoffdate.value="";return false;}
	}
	
	var useFromDate=new Date(arrFromDate[0], arrFromDate[1]-1, arrFromDate[2]);
	var useToDate=new Date(arrToDate[0], arrToDate[1]-1, arrToDate[2]);
	
	var now = new Date();
	var dateplus2 = now.getDate()+2;
	var today = new Date(now.getFullYear(),now.getMonth(),dateplus2);
	if(useFromDate <= today) {alert("Sorry we only provide online booking facility for a minimum of two days advance booking. For urgent queries please contact our customer support desk now at (416) 323-9898."); return false;}
	if(useFromDate > useToDate){alert("The Departure date must not precede Return date ");return false;}

	if(document.frmf.country.value=="India")
	{
		//alert("India");
		document.frmf.action="booking_request.php";
	}
	else
	{
		//alert("other");
		document.frmf.action="booking-request.php";
	}
	//document.getElementById("scrh").style.display="none";
	//document.getElementById('srch').style.display="none";
	//document.getElementById("flash").style.display="block";
	document.frmf.submit();
	
	//document.getElementById("flash").style.display="block";
	//window.parent.location="flight-reservation.php";
	
}
var dtCh1= "/";
function isDate1(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh1)
	var pos2=dtStr.indexOf(dtCh1,pos1+1)
	var strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=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)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : DD/MM/YYYY")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh1,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh1))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function chhdates()
{
//alert("hi");
var  arrFromDate1 = document.carfrm.pickupdate.value.split("/");
	var  arrToDate1 = document.carfrm.dropoffdate.value.split("/");
		
	if (!isDate1(document.carfrm.pickupdate.value))
	{
		alert("invalid date. enter a proper date using the calendar.");
		document.carfrm.pickupdate.value="";
		return false;
	}
	
		if (!isDate1(document.carfrm.dropoffdate.value))
		{alert("invalid date. enter a proper date using the calendar.");document.carfrm.dropoffdate.value="";return false;}
	
	
	var useFromDate=new Date(arrFromDate1[0], arrFromDate1[1]-1, arrFromDate1[2]);
	var useToDate=new Date(arrToDate1[0], arrToDate1[1]-1, arrToDate1[2]);
	
	var now = new Date();
	var dateplus2 = now.getDate()+2;
	var today = new Date(now.getFullYear(),now.getMonth(),dateplus2);
	if(useFromDate <= today) 
	{
		alert("Sorry we only provide online booking facility for a minimum of two days advance booking. For urgent queries please contact our customer support desk now at (416) 323-9898."); 
		return false;
	}
	if(useFromDate > useToDate)
	{
		alert("The Departure date must not precede Return date ");
	return false;
	}
	else
	{
		document.carfrm.submit();
	}
}
function carconform()
{
	
	if(document.carfrm.pickupdate.value=="yyyy-mm-dd")
			{
				alert("Please enter a pick up date.");
				document.carfrm.pickupdate.focus();
				return false;
			}
	if(document.carfrm.dropoffdate.value=="yyyy-mm-dd")
			{
				alert("Please enter a drop date.");
				document.carfrm.dropoffdate.focus();
				return false;
			}
	
	if(document.carfrm.checkin_time.value=='midnight')
		{
		alert('Please Choose Pickup time');
		document.carfrm.checkin_time.focus();
		return false;
		}
	if(document.carfrm.checkout_time.value=='midnight')
		{
		alert('Please Choose Drop time');
		document.carfrm.checkout_time.focus();
		return false;
		}
		document.carfrm.action="booking_process.php";
		document.carfrm.submit();

}
function valid_email()
			{	   	
				
					var emailval=document.frmf.email.value;
					var ret=CheckMails(emailval)
					if(ret==false)
					{
						document.frmf.email.focus();
						//alert("Please Enter a Valid Email ");
						return false
					}
				return true;
			}


function valid_phone(obj)
			{
				if(obj.value!="")
				{
					var phone_number = obj.value;
					var ret = checkInternationalPhone(phone_number);
					//alert(ret);
					if(ret == false)
					{
						alert("Enter a Valid Phone Number");
						//obj.value="";
						obj.focus();
						return false;
					}
					else
					{
						return true;
					}
				}
				//alert("in`side function") ;
			}

