function change_image(image,width,height,id)
{
	document.getElementById(id).src="images/"+image;
	document.getElementById(id).width=width;
	document.getElementById(id).height=height;
}
function swap_image(image,width,height,id)
{
	document.getElementById(id).src="../images/"+image;
	document.getElementById(id).width=width;
	document.getElementById(id).height=height;
}



function disable()
{
	//alert("ji");
	if(document.frmf.trip[0].checked==true)
	{
	document.frmf.inbound_date.disabled=true;
	document.frmf.inbound_time.disabled=true;
	}
	else if(document.frmf.trip[1].checked==true)//(document.frm.trip[1].selected==true)
	{
	document.frmf.inbound_date.disabled=false;
	document.frmf.inbound_time.disabled=false;
	}
	
	

}
function show()
{
	if(!document.frm.check.checked)
	{
		document.getElementById('drop1').style.display="";
		document.getElementById('drop2').style.display="";
	}
	else
	{
		document.getElementById('drop1').style.display="none";
		document.getElementById('drop2').style.display="none";
		
	}
}



function validate_form(thisform)
{
	with (thisform)
	{
		if (validate_email(email,"Not a valid e-mail address!")==false)
  		{
  			email.focus();
  			return false;
  		}
		document.frmf.action="reservation-details.php";
		document.frmf.submit();
	}	
}
function resident_check()
{
	if(!document.frm.resident.checked)
	{
		//document.frm.country.style.visibility="visible";
		document.frm.country.style.display="";
	}
	else
	{
		//document.frm.country.style.visibility="hidden";
		document.frm.country.style.display="none";
	}
}
function checklogin()
{
	if(document.form1.agency.value=="")
	{
		alert("Username can not be blank.");
		document.form1.agency.focus();
		return false;
	}
	if(document.form1.password.value=="")
	{
		alert("Password can not be blank.");
		document.form1.password.focus();
		return false;
	}
	
}


function chkform()
{
	
	
	if(document.frmf.country.value=="select")
			{
				alert("Please choose a Country.");
				document.frmf.country.focus();
				return false;
			}
	
	if( (document.getElementById('citydiv1').style.display=="block")&&(document.frmf.city_name1.value=="") )
			{
				alert("Please choose a city.");
				document.frmf.city_name1.focus();
				return false;
			}
	
	//document.frms.city_name=document.frmf.city_dys.value;
	if( (document.getElementById('citydiv2').style.display=="block")&&(document.frmf.city_name2.value=="select"))
			{
				alert("Please enter a City.");
				document.frmf.city_name2.focus();
				return false;
			}
	
	if(document.frmf.pickupdate.value=="")
			{
				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=="")
			{
				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.resident.focus();
				return false;
			}
	if 
	(document.getElementById('citydiv2').style.display=="none")
	{
		//alert(document.frmf.city_name1.value);
		document.frmf.city_name.value=document.frmf.city_name1.value;}
	else
	{document.frmf.city_name.value=document.frmf.city_name2.value;}
	checkdates1();
}
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="cars/car-reservation-i.php";
	}
	else
	{
		//alert("other");
		document.frmf.action="cars/car-reservation.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 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
}

