// JavaScript Document
function GetInputDate(t)
{
	if(!t.length) return null;
	if(!t.match(/!|\//)) return null;
	var rgt=t.split(/!|\//);
	//alert(rgt[0]);
	
	if(rgt[0]>31 || rgt[0]<1 || rgt[0].length>2 ) 
		return null;
	else if(rgt[1]>12 || rgt[1]<1 || rgt[1].length>2 ) 
		return null;
	else if(rgt[2]>2050 || rgt[2]<2008 || rgt[2].length>4 ) 
		return null;
	else
		return 1;	
}

function gotosearch()
{		
		var d = new Date();
		//alert(document.frmflightsearch.r1[0].value);
		//alert(d);
	
		var leavefrom=document.frmflightsearch.txt_leavefrom.value;
		var goto=document.frmflightsearch.txt_goto.value;
		var depdate=document.frmflightsearch.txt_depdate.value;
		
		var seprator="/";
		var arr_depdate=depdate.split(seprator);
		var dep_date=arr_depdate[0];
		var dep_month=arr_depdate[1];
		var dep_year=arr_depdate[2];
		var dep_time=document.frmflightsearch.sel_deptime.value;
	
		var return_date=document.frmflightsearch.txt_returndate.value;
		var arr_returndate=return_date.split(seprator);
		var return_date=arr_returndate[0];
		var return_month=arr_returndate[1];
		var return_year=arr_returndate[2];
		var return_time=document.frmflightsearch.sel_returntime.value;
		//var rooms=document.frmflightsearch.sel_rooms.value;
		var rooms;
		var adult=document.frmflightsearch.sel_adults.value;
		var children=document.frmflightsearch.sel_children.value;
		var senior=document.frmflightsearch.sel_senior.value;
		var infant=document.frmflightsearch.sel_infant.value;
		var newdepdate = dep_month + "/" + dep_date + "/" + dep_year;
		var newreturndate = return_month + "/" + return_date + "/" + return_year;
		var endDate = new Date(newdepdate);
		var endreturnDate=  new Date(newreturndate);
		var flighttype;
		var airline1 = document.frmflightsearch.airline1.value;
		var classService = document.frmflightsearch.classService.value;
		var eOutboundFlexibilityFare = document.frmflightsearch.eOutboundFlexibilityFare.checked;
		var eInboundFlexibilityFare = document.frmflightsearch.eInboundFlexibilityFare.checked;
		var OutboundFlexibility = document.frmflightsearch.OutboundFlexibility.value;
		var InboundFlexibility = document.frmflightsearch.InboundFlexibility.value;
		
		for(var i=0;i<=5;i++)
		{
			if(document.frmflightsearch.r1[i].checked)
			{
				flighttype=document.frmflightsearch.r1[i].value;
			}
		}
		
		if(document.frmflightsearch.txt_leavefrom.value == '')
		{
			alert('Please enter Leaving from.');
			document.frmflightsearch.txt_leavefrom.focus();
			return false;
		}
		if(document.frmflightsearch.txt_goto.value == '')
		{
			alert('Please enter Going to.');
			document.frmflightsearch.txt_goto.focus();
			return false;
		}
		if(document.frmflightsearch.txt_depdate.value == 'dd/mm/yyyy')
		{
			alert('Please select Departing Date.');
			return false;
		}
		if(document.frmflightsearch.txt_returndate.value == 'dd/mm/yyyy')
		{
			alert('Please select Returning Date.');
			return false;
		}
		
		//alert(flighttype);
		
		if(d > endDate)
		{
				alert("Please ensure that the Departing Date is greater than  the Current Date.");
				document.frmflightsearch.txt_depdate.focus();
				return false;
		}
		
		if(d > endreturnDate)
		{
				alert("Please ensure that the Returning Date is greater than  the Current Date.");
				document.frmflightsearch.txt_returndate.focus();
				return false;
		}
		
		if(endDate > endreturnDate)
		{
				alert("Please ensure that the Returning Date is greater than  the  Departing Date.");
				document.frmflightsearch.txt_returndate.focus();
				return false;
		}
		//alert("HI > "+ GetInputDate(document.frmflightsearch.txt_depdate.value));
		/*if(GetInputDate(newdepdate)!=1)
		{
			alert('Departing Date format is not valid.');
			return false;
		}
		if(GetInputDate(endreturnDate)!=1)
		{
			alert('Returning Date format is not valid.');
			return false;
		}*/
		
		if(document.frmflightsearch.hd_session_set.value == '')
		{
				if(document.frmflightsearch.r_chkuser[0].checked == false && document.frmflightsearch.r_chkuser[1].checked == false)
				{
						alert('Please select Are you an existing user?');
						return false;
				}
				
				if(document.frmflightsearch.r_chkuser[0].checked == true)
				{
					
						if(document.frmflightsearch.vEmail.value == "")
						{
							alert("Please fill email address");
							document.frmflightsearch.vEmail.focus();
							return false;
						}
						if(!isEmail(document.frmflightsearch.vEmail.value))
						{
							alert("Please fill Proper E-mail Address");
							document.frmflightsearch.vEmail.focus();
							return false;
						}
						if(document.frmflightsearch.Vpassword.value == "")
						{
							alert("Please fill customer password");
							document.frmflightsearch.Vpassword.focus();
							return false;
						}
						if(document.frmflightsearch.Vpassword.value.length < 6)
						{
							alert("Please fill customer password atleast 6 charcter long");
							document.frmflightsearch.Vpassword.value == '';
							document.frmflightsearch.Vpassword.focus();
							return false;
						}
					
						var status="yes";
						var username=document.frmflightsearch.vEmail.value;
						var pwd=document.frmflightsearch.Vpassword.value;
						
						
						location.href = "search_flight.php?leavefrom="+leavefrom+"&goto="+goto+"&depdate="+dep_date+"&dep_month="+dep_month+"&dep_year="+dep_year+"&dep_time="+
						dep_time+"&return_date="+return_date+"&return_month="+return_month+"&return_year="+return_year+"&return_time="+return_time+"&adult="
						+adult+"&children="+children+"&senior="+senior+"&infant="+infant+"&eOutboundFlexibilityFare="+eOutboundFlexibilityFare+"&eInboundFlexibilityFare="+eInboundFlexibilityFare+"&OutboundFlexibility="+OutboundFlexibility+"&InboundFlexibility="+InboundFlexibility+"&InboundFlexibility="+InboundFlexibility+"&flighttype="+flighttype+"&airline1="+airline1+"&classService="+classService
						+"&status="+status+"&username="+username+"&pwd="+pwd;  
					
				}
				
				if(document.frmflightsearch.r_chkuser[1].checked == true)
				{
						
						if(document.frmflightsearch.txt_name.value == "")
						{
							alert("Please fill customer name");
							document.frmflightsearch.txt_name.focus();
							return false;
						}
						if(document.frmflightsearch.txt_email.value == "")
						{
							alert("Please fill customer email");
							document.frmflightsearch.txt_email.focus();
							return false;
						}
						if(!isEmail(document.frmflightsearch.txt_email.value))
						{
							alert("Please fill proper email address");
							document.frmflightsearch.txt_email.focus();
							return false;
						}
						if(document.frmflightsearch.txt_pwd.value == "")
						{
							alert("Please fill customer password");
							document.frmflightsearch.txt_pwd.focus();
							return false;
						}
						if(document.frmflightsearch.txt_pwd.value.length < 6)
						{
							alert("Please fill customer password atleast 6 charcter long");
							document.frmflightsearch.vPassword.value == '';
							document.frmflightsearch.vPassword.focus();
							return false;
						}
						if(document.frmflightsearch.txt_telno.value == "")
						{
							alert("Please fill telephone number");
							document.frmflightsearch.txt_telno.focus();
							return false;
						}
						if(document.frmflightsearch.r_contact[0].checked == false && document.frmflightsearch.r_contact[1].checked == false )
						{
							alert("Please select any ContactPreference.");
							return false;
						}
						
						var status="no";
						var name=document.frmflightsearch.txt_name.value;
						var email=document.frmflightsearch.txt_email.value;
						var npwd=document.frmflightsearch.txt_pwd.value;
						var telno=document.frmflightsearch.txt_telno.value;
						if(document.frmflightsearch.r_contact[0].checked == true)
						{
								var eContactPreference='Tel';
						}
						else
						{
								var eContactPreference='Site';
						}
						if(document.frmflightsearch.ch_emailupdate.checked == true)
						{
								var emailupdate='Yes';
						}
						else
						{
								var emailupdate='No';
						}
						
				
						location.href = "search_flight.php?leavefrom="+leavefrom+"&goto="+goto+"&depdate="+dep_date+"&dep_month="+dep_month+"&dep_year="+dep_year+"&dep_time="+
						dep_time+"&return_date="+return_date+"&return_month="+return_month+"&return_year="+return_year+"&return_time="+return_time+"&adult="
						+adult+"&children="+children+"&senior="+senior+"&infant="+infant+"&eOutboundFlexibilityFare="+eOutboundFlexibilityFare+"&eInboundFlexibilityFare="+eInboundFlexibilityFare+"&OutboundFlexibility="+OutboundFlexibility+"&InboundFlexibility="+InboundFlexibility+"&InboundFlexibility="+InboundFlexibility+"&flighttype="+flighttype+"&airline1="+airline1+"&classService="+classService+
						"&status="+status+"&name="+name+"&email="+email+"&npwd="+npwd+"&telno="+telno+"&eContactPreference="+eContactPreference+
						"&emailupdate="+emailupdate;  
				}
		}
		else
		{
						location.href = "search_flight.php?leavefrom="+leavefrom+"&goto="+goto+"&depdate="+dep_date+"&dep_month="+dep_month+"&dep_year="+dep_year+"&dep_time="+
						dep_time+"&return_date="+return_date+"&return_month="+return_month+"&return_year="+return_year+"&return_time="+return_time+"&adult="
						+adult+"&children="+children+"&senior="+senior+"&infant="+infant+"&eOutboundFlexibilityFare="+eOutboundFlexibilityFare+"&eInboundFlexibilityFare="+eInboundFlexibilityFare+"&OutboundFlexibility="+OutboundFlexibility+"&InboundFlexibility="+InboundFlexibility+"&InboundFlexibility="+InboundFlexibility+"&flighttype="+flighttype+"&airline1="+airline1+"&classService="+classService;  
		}
		return false;
		
}


function gotosearchnext()
{

		var d=new Date();
		//alert(document.frmflightsearch.r1[0].value);
	
		var leavefrom=document.frmflightsearch.txt_leavefrom.value;
		var goto=document.frmflightsearch.txt_goto.value;
		var depdate=document.frmflightsearch.txt_depdate.value;
		var seprator="/";
		var arr_depdate=depdate.split(seprator);
		var dep_date=arr_depdate[0];
		var dep_month=arr_depdate[1];
		var dep_year=arr_depdate[2];
		var dep_time=document.frmflightsearch.sel_deptime.value;
		var return_date=document.frmflightsearch.txt_returndate.value;
		var arr_returndate=return_date.split(seprator);
		var return_date=arr_returndate[0];
		var return_month=arr_returndate[1];
		var return_year=arr_returndate[2];
		var return_time=document.frmflightsearch.sel_returntime.value;
		//var rooms=document.frmflightsearch.sel_rooms.value;
		var rooms;
		var adult=document.frmflightsearch.sel_adults.value;
		var children=document.frmflightsearch.sel_children.value;
		var senior=document.frmflightsearch.sel_senior.value;
		var infant=document.frmflightsearch.sel_infant.value;
		var newdepdate=dep_month + "/" + dep_date + "/" + dep_year;
		var newreturndate=return_month + "/" + return_date + "/" + return_year;
		var endDate = new Date(newdepdate);
		var endreturnDate=  new Date(newreturndate);
		var flighttype;
		var airline1 = '';
		var classService = '';
		var eOutboundFlexibilityFare = document.frmflightsearch.eOutboundFlexibilityFare.value;
		var eInboundFlexibilityFare = document.frmflightsearch.eInboundFlexibilityFare.value;
		var OutboundFlexibility = document.frmflightsearch.OutboundFlexibility.value;
		var InboundFlexibility = document.frmflightsearch.InboundFlexibility.value;
		
		for(var i=0;i<=5;i++)
		{
			if(document.frmflightsearch.r1[i].checked)
			{
				flighttype=document.frmflightsearch.r1[i].value;
			}
		}
		//alert(flighttype);
		if(endDate<d)
		{
				alert("Please ensure that the Departing Date is greater than  the Current Date.");
				document.frmflightsearch.txt_depdate.focus();
				return false;
		}
		
		if(endreturnDate<d)
		{
				alert("Please ensure that the Returning Date is greater than  the Current Date.");
				document.frmflightsearch.txt_returndate.focus();
				return false;
		}
		
		if(endreturnDate < endDate)
		{
				alert("Please ensure that the Returning Date is greater than  the  Departing Date.");
				document.frmflightsearch.txt_returndate.focus();
				return false;
		}
		if(document.frmflightsearch.hd_session_set.value == '')
		{
				
				if(document.frmflightsearch.r_chkuser[0].checked == false && document.frmflightsearch.r_chkuser[1].checked == false)
				{
						alert('Please select Are you an existing user?');
						return false;
				}
				if(document.frmflightsearch.r_chkuser[0].checked == true)
				{
					
						if(document.frmflightsearch.vEmail.value == "")
						{
							alert("Please fill email address");
							document.frmflightsearch.vEmail.focus();
							return false;
						}
						if(!isEmail(document.frmflightsearch.vEmail.value))
						{
							alert("Please fill Proper E-mail Address");
							document.frmflightsearch.vEmail.focus();
							return false;
						}
						if(document.frmflightsearch.Vpassword.value == "")
						{
							alert("Please fill customer password");
							document.frmflightsearch.Vpassword.focus();
							return false;
						}
						if(document.frmflightsearch.Vpassword.value.length < 6)
						{
							alert("Please fill customer password atleast 6 charcter long");
							document.frmflightsearch.Vpassword.value == '';
							document.frmflightsearch.Vpassword.focus();
							return false;
						}
					
						var status="yes";
						var username=document.frmflightsearch.vEmail.value;
						var pwd=document.frmflightsearch.Vpassword.value;
						
						
						location.href = "search_flight.php?leavefrom="+leavefrom+"&goto="+goto+"&depdate="+dep_date+"&dep_month="+dep_month+"&dep_year="+dep_year+"&dep_time="+
						dep_time+"&return_date="+return_date+"&return_month="+return_month+"&return_year="+return_year+"&return_time="+return_time+"&adult="
						+adult+"&children="+children+"&senior="+senior+"&infant="+infant+"&flighttype="+flighttype+"&eOutboundFlexibilityFare="+eOutboundFlexibilityFare+"&eInboundFlexibilityFare="+eInboundFlexibilityFare+"&OutboundFlexibility="+OutboundFlexibility+"&InboundFlexibility="+InboundFlexibility+"&InboundFlexibility="+InboundFlexibility+"&airline1="+airline1+"&classService="+classService
						+"&status="+status+"&username="+username+"&pwd="+pwd+"&page=search";  
					
				}
				if(document.frmflightsearch.r_chkuser[1].checked == true)
				{
						
						if(document.frmflightsearch.txt_name.value == "")
						{
							alert("Please fill customer name");
							document.frmflightsearch.txt_name.focus();
							return false;
						}
						if(document.frmflightsearch.txt_email.value == "")
						{
							alert("Please fill customer email");
							document.frmflightsearch.txt_email.focus();
							return false;
						}
						if(!isEmail(document.frmflightsearch.txt_email.value))
						{
							alert("Please fill proper email address");
							document.frmflightsearch.txt_email.focus();
							return false;
						}
						if(document.frmflightsearch.txt_pwd.value == "")
						{
							alert("Please fill customer password");
							document.frmflightsearch.txt_pwd.focus();
							return false;
						}
						if(document.frmflightsearch.txt_pwd.value.length < 6)
						{
							alert("Please fill customer password atleast 6 charcter long");
							document.frmflightsearch.vPassword.value == '';
							document.frmflightsearch.vPassword.focus();
							return false;
						}
						if(document.frmflightsearch.txt_telno.value == "")
						{
							alert("Please fill telephone number");
							document.frmflightsearch.txt_telno.focus();
							return false;
						}
						if(document.frmflightsearch.r_contact[0].checked == false && document.frmflightsearch.r_contact[1].checked == false )
						{
							alert("Please select any ContactPreference.");
							return false;
						}
						
						var status="no";
						var name=document.frmflightsearch.txt_name.value;
						var email=document.frmflightsearch.txt_email.value;
						var npwd=document.frmflightsearch.txt_pwd.value;
						var telno=document.frmflightsearch.txt_telno.value;
						if(document.frmflightsearch.r_contact[0].checked == true)
						{
								var eContactPreference='Tel';
						}
						else
						{
								var eContactPreference='Site';
						}
						if(document.frmflightsearch.ch_emailupdate.checked == true)
						{
								var emailupdate='Yes';
						}
						else
						{
								var emailupdate='No';
						}
						
				
						location.href = "search_flight.php?leavefrom="+leavefrom+"&goto="+goto+"&depdate="+dep_date+"&dep_month="+dep_month+"&dep_year="+dep_year+"&dep_time="+
						dep_time+"&return_date="+return_date+"&return_month="+return_month+"&return_year="+return_year+"&return_time="+return_time+"&adult="
						+adult+"&children="+children+"&senior="+senior+"&infant="+infant+"&flighttype="+flighttype+"&airline1="+airline1+"&classService="+classService+
						"&status="+status+"&name="+name+"&email="+email+"&npwd="+npwd+"&telno="+telno+"&eContactPreference="+eContactPreference+"&eOutboundFlexibilityFare="+eOutboundFlexibilityFare+"&eInboundFlexibilityFare="+eInboundFlexibilityFare+"&OutboundFlexibility="+OutboundFlexibility+"&InboundFlexibility="+InboundFlexibility+
						"&emailupdate="+emailupdate+"&page=search";   
				}
		}
		else
		{
						location.href = "search_flight.php?leavefrom="+leavefrom+"&goto="+goto+"&depdate="+dep_date+"&dep_month="+dep_month+"&dep_year="+dep_year+"&dep_time="+
						dep_time+"&return_date="+return_date+"&return_month="+return_month+"&return_year="+return_year+"&return_time="+return_time+"&adult="
						+adult+"&children="+children+"&senior="+senior+"&infant="+infant+"&flighttype="+flighttype+"&airline1="+airline1+"&classService="+classService+"&eOutboundFlexibilityFare="+eOutboundFlexibilityFare+"&eInboundFlexibilityFare="+eInboundFlexibilityFare+"&OutboundFlexibility="+OutboundFlexibility+"&InboundFlexibility="+InboundFlexibility+"&page=search";    
		}		
		return false;
		
}


function hotelsearch()
{
	alert('hotelsearch');
}

function carsearch()
{
	//alert('carsearch');
}

function flighthotelsearch()
{
	//alert('flighthotelsearch');
}

function flighthotelcarsearch()
{
	//alert('flighthotelcarsearch');
}

function flightcarsearch()
{
	//alert('flightcarsearch');
}

function displayroombox(totalrows,elementname)
{
	//alert(totalrows);
	
	if(elementname=='RoomTable')
	{
		
		for(var j=0;j<totalrows;j++)
		{
			//alert(j);
			//document.getElementById('acco'+j).style.display = '';		
		}
	}
}
