// This script written by Abdul Hafeez and Khaleequu-ur-Rehman.
// AHK Soft have copyright of this script.
// URL: http://www.ahksoft.com
// JavaScript Document for Multiheathrowcars.
// This script for New Taxi Hire page

//Return Check status validation ==============================================================
	function returnstatus()
	{
		if (document.frm_newtaxi.frm_return.checked == true)
		{
			document.getElementById("AHK_Return_01").className="show";
			document.getElementById("AHK_Return_02").className="show";
			document.getElementById("AHK_Return_03").className="show";
		}
		else
		{
			document.getElementById("AHK_Return_01").className="hide";
			document.getElementById("AHK_Return_02").className="hide";
			document.getElementById("AHK_Return_03").className="hide";
		}
	}

//Agrement check validation =====================================================================
	function val_Agreement(agreechecked)
	{
		if (agreechecked.checked)
			return true;
		else
		{
			alert("You must be checked agreement."); return false;
		}
		
	}
//Min to Max Character validation ==================================
function val_minmaxchar(AHK_String, Min, Max, Field_Name)
	{
		if ( AHK_String.value.length<Min || AHK_String.value.length>Max )
		{
			alert("Invalid " + Field_Name);	AHK_String.focus();	return false;
		}
		else
			return true;
	}
//Only Max Character validation ==================================
	function val_maxchar(AHK_String, Max, Field_Name)
	{
		if ( AHK_String.value.length>Max )
		{
			alert("Invalid " + Field_Name);	AHK_String.focus();	return false;
		}
		else
			return true;
	}
//General Combo Box value test AHK_ComboVal validation ==================================
	function val_Gen_ComboBox(AHK_ComboVal, Field_Name, NoneValue)
	{
		//alert(AHK_ComboVal.value);
		if ( AHK_ComboVal.value == NoneValue )
		{
			alert("Invalid " + Field_Name);	AHK_ComboVal.focus(); return false;
		}
		else
			return true;
	}
//---------------------------------------------------------------------------------------------

//Date validation =====================================================================
	function val_Invalid_Date(var_Dateday, var_month, Field_Name)
	{
		if (var_Dateday.value != "ahk" && var_month.value != "ahk"	)
		{
			return true;
		}
		else
		{
			alert("Please Select "+Field_Name+" properly");	var_Dateday.focus();return false;
		}
	}
//Check Invalid time ======================================
	function val_Invalid_Time(var_hour, var_minute, Field_Name)
	{
		if(var_hour.value !="ahk" && var_minute.value !="ahk")
		{
			return true;
		}
		else
		{
			//alert("Invalid pickup-time ");
			alert("Please Select "+Field_Name+" properly");var_hour.focus();return false;
		}
	}
	function val_ReturnDate(var_Dateday, var_month, Field_Name)
	{
		if (document.frm_newtaxi.frm_return.checked == true)
		{
			if (var_Dateday.value != "ahk" && var_month.value != "ahk"	)
			{
				return true;	
			}
			else
			{
				alert("Please Select "+Field_Name+" properly");var_Dateday.focus();return false;
			}
		}
		else
			return true;
	}
//Check Return Invalid time ======================================
	function val_ReturnTime(var_hour, var_minute, Field_Name)
	{
		if (document.frm_newtaxi.frm_return.checked == true)
		{
			if(var_hour.value !="ahk" && var_minute.value !="ahk")
			{
				return true;
			}
			else
			{
				//alert("Invalid Drop-off time ");
				alert("Please Select "+Field_Name+" properly");var_hour.focus();return false;
			}
		}
		else
			return true;
	}




//Any Numbers validation =====================================================================
	function isNumberFloat(inputString)	{  return (!isNaN(parseInt(inputString))) ? false : true;	}
//Mobile validation =====================================================================
	function val_mob(var_mobile)
	{
		if (var_mobile.value.length < 8 ||  var_mobile.value.length > 18)
		{
			alert("Please, enter valid mobile mumber.");
			var_mobile.focus();
			return false;    
		}
		else if (isNumberFloat(var_mobile.value) )
		{	alert("You must be enter in numeric form only.");
			var_mobile.focus();
			return false;
		}
		else
		{	return true;}
	}
//Email validation =====================================================================
	function val_email(var_email)
	{
		if (
			var_email.value.length < 6 || 
			var_email.value.indexOf("@") == -1 || 
			var_email.value.indexOf(".") == -1  ||
			var_email.value.indexOf(" ") != -1 
			)
		{
			alert("Please, enter valid email address. ");
			var_email.focus();
			return false;    
		}
		else if (var_email.value.indexOf("@")<3)
		{
			alert("This email address seems wrong. Please,"
			+" check the prefix and '@' sign.");
			var_email.focus();
		}
		else
			return true;
	}

//Email validation of both=====================================================================
	function val_validation_email(var_email_1,var_email_2 )
	{
		if (val_email(var_email_1) && val_email(var_email_2) )
		{
			if (var_email_1.value != var_email_2.value )
			{
				alert("both email address not matched");
				var_email_2.focus();
				return false;
			}
				return true;
		}
		else
			return false;
	}



// below code use less at the moment...........................
function set_valuemonth(var_month)
{
				if (var_month ==  "Jan" ) AHK_month = 1;		
			else if (var_month ==  "Feb" ) AHK_month = 2;
			else if (var_month ==  "Mar" ) AHK_month = 3;
			else if (var_month ==  "Apr" ) AHK_month = 4;
			else if (var_month ==  "May" ) AHK_month = 5;
			else if (var_month ==  "Jun" ) AHK_month = 6;
			else if (var_month ==  "Jul" ) AHK_month = 7;
			else if (var_month ==  "Aug" ) AHK_month = 8;
			else if (var_month ==  "Sep" ) AHK_month = 9;
			else if (var_month ==  "Oct" ) AHK_month = 10;
			else if (var_month ==  "Nov" ) AHK_month = 11;
			else if (var_month ==  "Dec" ) AHK_month = 12;
			return AHK_month;	
}

function DateTime_Validate()
{
	var Cur_DateTime = new Date();
	var Pickup_DateTime = new Date();

	Cur_DateTime.setDate(document.frm_newtaxi.cur_dateday.value);
	Cur_DateTime.setMonth(document.frm_newtaxi.cur_month.value-1); 
	Cur_DateTime.setYear(document.frm_newtaxi.cur_year.value); 
	Cur_DateTime.setHours(document.frm_newtaxi.cur_hour.value);
	Cur_DateTime.setMinutes(document.frm_newtaxi.cur_minute.value); 

	var pickup_select_year = document.frm_newtaxi.pick_month.value;
	var pickup_select_MonthName = document.frm_newtaxi.pick_month.value;
	var pickup_select_month = set_valuemonth(pickup_select_MonthName.substring(0,3));

	Pickup_DateTime.setDate(document.frm_newtaxi.pick_day.value);//-SetDay value of 1 to 31.  
	Pickup_DateTime.setMonth(pickup_select_month-1); //-Setmonth in value of 0 to 11. 
	Pickup_DateTime.setYear(pickup_select_year.substring(4,8)); //-Setyearinstance as 4 digit numer.
	Pickup_DateTime.setHours(document.frm_newtaxi.pick_hour.value); //-Set hours value of 0 to 23. 
	Pickup_DateTime.setMinutes(document.frm_newtaxi.pick_minute.value);//Setminutes valueof 0 to 59.

	//alert(Cur_DateTime+" __ " + Pickup_DateTime);
	if (Cur_DateTime >= Pickup_DateTime)
	{	alert("Your Pickup Date is invalid by UK Current Date and Time.");
		return false;
	}else{
		//alert("true");
		return true;
	}
}

function ReturnDateTime_Validate()
{

	if (document.frm_newtaxi.frm_return.checked == true)
	{
		var Pickup_DateTime = new Date();
		var Return_DateTime = new Date();
	
		var pickup_select_year = document.frm_newtaxi.pick_month.value;
		var pickup_select_MonthName = document.frm_newtaxi.pick_month.value;
		var pickup_select_month = set_valuemonth(pickup_select_MonthName.substring(0,3));
	
		Pickup_DateTime.setDate(document.frm_newtaxi.pick_day.value);//-SetDay value of 1 to 31.  
		Pickup_DateTime.setMonth(pickup_select_month-1); //-Setmonth in value of 0 to 11. 
		Pickup_DateTime.setYear(pickup_select_year.substring(4,8)); //-Set year 4 digit numer.
		Pickup_DateTime.setHours(document.frm_newtaxi.pick_hour.value); //-Set hours value 0 to 23. 
		Pickup_DateTime.setMinutes(document.frm_newtaxi.pick_minute.value);//Set minutes 0 to 59.
	
		var return_select_year = document.frm_newtaxi.ret_month.value;
		var return_select_MonthName = document.frm_newtaxi.ret_month.value;
		var return_select_month = set_valuemonth(return_select_MonthName.substring(0,3));
	
		Return_DateTime.setDate(document.frm_newtaxi.ret_day.value);//-SetDay value of 1 to 31.  
		Return_DateTime.setMonth(return_select_month-1); //-Setmonth in value of 0 to 11. 
		Return_DateTime.setYear(return_select_year.substring(4,8)); //-Set year 4 digit numer.
		Return_DateTime.setHours(document.frm_newtaxi.ret_hour.value); //-Set hours 0 to 23. 
		Return_DateTime.setMinutes(document.frm_newtaxi.ret_minute.value);//Set minutes 0 to 59.

		//alert(Return_DateTime+" __ " + Pickup_DateTime);
		if (Return_DateTime <= Pickup_DateTime)
		{
			alert("Invalid Return Date OR Pickup Date check sequence.");
			return false;
		}else{
			return true;
			//alert("true");
		}
	}
	else
		return true;
//toGMTString() - Convert date to GMT format in a form similar to "Fri, 29 Sep 2000 06:23:54 GMT".
	//setSeconds(value) - Set the seconds in the date object with a value of 0 through 59. 
	//setTime(value) - Sets time on the basis of number of milliseconds since January 1, 1970. The below 
	//example sets the date object to one hour in the future. 
	//var expdate = futdate.getTime()
	//expdate += 3600*1000 //expires in 1 hour(milliseconds) 
	//futdate.setTime(expdate)
	// mysite.substring(0,3) //mysite.substring(4,8)
}
















function By_Fullname_set_valuemonth(var_month)
{
			if (var_month ==  "January" ) AHK_month = 1;		
			else if (var_month ==  "February" ) AHK_month = 2;
			else if (var_month ==  "March" ) AHK_month = 3;
			else if (var_month ==  "April" ) AHK_month = 4;
			else if (var_month ==  "May" ) AHK_month = 5;
			else if (var_month ==  "June" ) AHK_month = 6;
			else if (var_month ==  "July" ) AHK_month = 7;
			else if (var_month ==  "August" ) AHK_month = 8;
			else if (var_month ==  "September" ) AHK_month = 9;
			else if (var_month ==  "October" ) AHK_month = 10;
			else if (var_month ==  "November" ) AHK_month = 11;
			else if (var_month ==  "December" ) AHK_month = 12;
			return AHK_month;	
}
//Current Date validation =====================================================================
	function val_Cur_Date(var_Dateday, var_month, var_year, cur_dateday, cur_month, cur_year)
	{
		AHK_day   = var_Dateday.value; 		AHK_year =  var_year.value;
		AHK_month = set_valuemonth(var_month.value);
//		alert(AHK_day +AHK_month+AHK_year+"==="+cur_dateday.value+cur_month.value+cur_year.value);
		//			alert(AHK_year+" < "+cur_year.value+"--"+AHK_month+" < "+cur_month.value+"--"+AHK_day+" < "+cur_dateday.value);
		if (	(AHK_year < cur_year.value) ||
				(AHK_year == cur_year.value && AHK_month < cur_month.value)	||
	(AHK_year == cur_year.value && AHK_month == cur_month.value && AHK_day < cur_dateday.value )
			)
		{
			alert("Invalid Date, Selected date is expire than Current/Pickup Date");return false;
			var_Dateday.focus();			
		}
		else
			return true;

//		if (AHK_year == cur_year.value && AHK_month < cur_month.value)
//		{alert("Invalid Date, select date is expire than current month");return false;}
//	if (AHK_year == cur_year.value && AHK_month == cur_month.value && AHK_day < cur_dateday.value )
//		{alert("Invalid Date, select date is expire than current date");return false;}
//		else
//			return true;
	}


//Optional Return date and time status==============use above functions================
	function val_optional_date_time()
	{ // here we use current mean pickup date and time.
		alert("you are in login option");
		return true;
	}

//Optional Date validation =====================================================================
	function val_OP_Val_Date(var_Dateday, var_month, var_year, Field_Name)
	{
	if (var_Dateday.value != "ahk" || var_month.value != "ahk" || var_year.value != "ahk"	)
	{
		if (var_Dateday.value != "ahk" && var_month.value != "ahk" && var_year.value != "ahk"	)
		{	AHK_day   = var_Dateday.value; 		AHK_year =  var_year.value;
			if (var_month.value ==  "January" ) AHK_month = 1;		
			else if (var_month.value ==  "February" ) AHK_month = 2;
			else if (var_month.value ==  "March" ) AHK_month = 3;
			else if (var_month.value ==  "April" ) AHK_month = 4;
			else if (var_month.value ==  "May" ) AHK_month = 5;
			else if (var_month.value ==  "June" ) AHK_month = 6;
			else if (var_month.value ==  "July" ) AHK_month = 7;
			else if (var_month.value ==  "August" ) AHK_month = 8;
			else if (var_month.value ==  "September" ) AHK_month = 9;
			else if (var_month.value ==  "October" ) AHK_month = 10;
			else if (var_month.value ==  "November" ) AHK_month = 11;
			else if (var_month.value ==  "December" ) AHK_month = 12;
			var AHK_leap = 28;
			if ( AHK_year%4 == 0){		AHK_leap = 29;		}
			if (AHK_month == 2 )
				{	AHK_days_assign = AHK_leap;}
			else if (AHK_month == 4 || AHK_month == 6 || AHK_month == 9 || AHK_month == 11 )
				{	AHK_days_assign = 30;}
			else
				{ AHK_days_assign = 31;}
			if (AHK_day > AHK_days_assign)
			{	alert ("Invalid Date, check days in month or leap year");	return false;}
			else{return true;}
		}
		else
		{
			alert("Please Select " + Field_Name + " properly");
			var_Dateday.focus();
			return false;
			}
	}
	else{return true;}
	}

