// JavaScript Document

<!--
function do_reservation()
{
	if (validate())
	{
		document.frm_Reservations.wait_timeout.value = 0; //loadtimeout.toString();
		document.frm_Reservations.submit();
	}
}

function validate()
{
	var errorcount = 0;
	var msg = "___________________________________\n\n";
	msg += "You must enter correct information into the following fields for this form to be submitted:\n\n";	
	var err_org_dest;
	var err_departing_date;
	var err_numpax;
	var adults, childs, infants;
	var ADSegs, ADTktPerSeg;
	
	err_org_dest = false;

	if(errorcount == 0)
	{
		if (document.frm_Reservations.origin.value == document.frm_Reservations.destination.value)
		{
 			msg += "Origin and Destination must be different\n\n";
			err_org_dest = true;
			errorcount++;
		}
		if(document.frm_Reservations.destination.value == "MAN" || document.frm_Reservations.destination.value == "BHX" || document.frm_Reservations.destination.value == "LHR" || document.frm_Reservations.origin.value == "MAN" || document.frm_Reservations.origin.value == "BHX" || document.frm_Reservations.origin.value == "LHR")
		{
			if (document.frm_Reservations.origin.value != "ISB" && (document.frm_Reservations.destination.value == "MAN" || document.frm_Reservations.destination.value == "BHX" || document.frm_Reservations.destination.value == "LHR"))
			{
 				msg += "At the moment, flights to England only fly from Islamabad.\n\n";
				err_org_dest = true;
				errorcount++;
			}
			if (!err_org_dest && document.frm_Reservations.destination.value != "ISB" && (document.frm_Reservations.origin.value == "MAN" || document.frm_Reservations.origin.value == "BHX" || document.frm_Reservations.origin.value == "LHR"))
			{
 				msg += "At the moment, flights from England only fly to Islamabad.\n\n";
				err_org_dest = true;
				errorcount++;
			}
		}
		else if (document.frm_Reservations.origin.value != "KHI" && document.frm_Reservations.destination.value != "KHI")
		{
			if (document.frm_Reservations.origin.value == "DXB" && document.frm_Reservations.destination.value != "KHI" && document.frm_Reservations.destination.value != 'ISB' && document.frm_Reservations.destination.value != "LHE"  && document.frm_Reservations.destination.value != "PEW")
			{
 				msg += "At the moment, flights from Dubai only fly to Karachi, Islamabad, Lahore, and Peshawar.\n\n";
				err_org_dest = true;
				errorcount++;
			}
			if(document.frm_Reservations.destination.value == "DXB" && document.frm_Reservations.origin.value != "KHI" && document.frm_Reservations.origin.value != "ISB" && document.frm_Reservations.origin.value != "LHE"  && document.frm_Reservations.origin.value != "PEW")
			{
 				msg += "At the moment, flights to Dubai only fly from Karachi, Islamabad, Lahore, and Peshawar.\n\n";
				err_org_dest = true;
				errorcount++;
			}
			if (document.frm_Reservations.origin.value == "SHJ" && document.frm_Reservations.destination.value != "LYP" && document.frm_Reservations.destination.value != 'ISB' && document.frm_Reservations.destination.value != "LHE"  && document.frm_Reservations.destination.value != "PEW")
			{
 				msg += "At the moment, flights from Sharjah only fly to Islamabad, Lahore, Peshawar, and Faisalabad.\n\n";
				err_org_dest = true;
				errorcount++;
			}
			if(document.frm_Reservations.destination.value == "SHJ" && document.frm_Reservations.origin.value != "LYP" && document.frm_Reservations.origin.value != "ISB" && document.frm_Reservations.origin.value != "LHE"  && document.frm_Reservations.origin.value != "PEW")
			{
 				msg += "At the moment, flights to Sharjah only fly from Islamabad, Lahore, Peshawar, and Faisalabad.\n\n";
				err_org_dest = true;
				errorcount++;
			}
			if (!err_org_dest && document.frm_Reservations.origin.value != "DXB" && document.frm_Reservations.destination.value != "DXB" && document.frm_Reservations.origin.value != "SHJ" && document.frm_Reservations.destination.value != "SHJ")
			{
 				msg += "Domestic flights must either leave from or go to Karachi.\n\n";
				err_org_dest = true;
				errorcount++;
			}
		}
		else if (document.frm_Reservations.origin.value == "SHJ" || document.frm_Reservations.destination.value == "SHJ")
		{
 				msg += "At the moment, flights ";
				if(document.frm_Reservations.origin.value == "SHJ")
 					msg += "from Sharjah only fly to";
 				else
 					msg += "to Sharjah only fly from";
 				msg += " Islamabad, Lahore, Peshawar, and Faisalabad.\n\n";
				err_org_dest = true;
				errorcount++;
		}
		var current_date = new Date();

		var departing_date = new Date();
		departing_date.setDate(document.frm_Reservations.departing_day.value);
		departing_date.setMonth(document.frm_Reservations.departing_month.value - 1);
		departing_date.setDate(document.frm_Reservations.departing_day.value);

		if (departing_date < current_date)
		{
			departing_date.setYear(current_date.getFullYear() + 1);	
		}
		document.frm_Reservations.departing_date.value = departing_date.getMonth() + 1 + "/" + departing_date.getDate() + "/" + departing_date.getFullYear();
	
		var returning_date = new Date();
		returning_date.setDate(document.frm_Reservations.returning_day.value);
		returning_date.setMonth(document.frm_Reservations.returning_month.value - 1);
		returning_date.setDate(document.frm_Reservations.returning_day.value);
	
		if (returning_date < current_date)
		{
			returning_date.setYear(current_date.getFullYear() + 1);	
		}
		if (returning_date < departing_date)
		{
			returning_date.setYear(departing_date.getFullYear() + 1);	
		}
		document.frm_Reservations.returning_date.value = returning_date.getMonth() + 1 + "/" + returning_date.getDate() + "/" + returning_date.getFullYear();

		if (checkMaxDaysDiff(current_date, departing_date, "325", ""))
		{
 			msg += "The selected outbound departure date has already passed.\n - Please revise your outbound departure date and try again.\n\n";
			err_departing_date = true;
			errorcount++;
		}
		else if (checkMaxDaysDiff(current_date, returning_date, "325", ""))
		{
 			msg += "Your dates appear to be out of sequence or too far in the future.\n - Please check your itinerary is correct and try again.\n\n";
			err_departing_date = true;
			errorcount++;
		}
		adults = new Number(document.frm_Reservations.adults.value);
		childs = new Number(document.frm_Reservations.children.value);
		infants = new Number(document.frm_Reservations.infants.value);
		if((adults + childs + infants) <= 0)
		{
 			msg += "You have not specified the number of pasengers travelling.\n\n";
			err_numpax = true;
			errorcount++;
		}
		else if((adults + childs) > 6)
		{
 			msg += "You have specified more than the allowed number of pasengers.\n - Please make sure there are no more than six pasengers (adults and children).\n\n";
			err_numpax = true;
			errorcount++;
		}
		if(infants > adults)
		{
 			msg += "You have specified more than the allowed number of infants.\n - Please make sure there are not more infants than adults.\n\n";
			err_numpax = true;
			errorcount++;
		}

	}
	msg += "___________________________________";
	
	if (errorcount > 0)
		alert(msg);

	if (err_org_dest){document.frm_Reservations.origin.focus();}
	else if (err_departing_date){document.frm_Reservations.departing_day.focus();}
	else if(err_numpax) {document.frm_Reservations.adults.focus();}

	return (errorcount == 0);
}

function getRadioOption(radiobtn)
{
	var cnt = -1;
	for (var i=radiobtn.length-1; i > -1; i--)
	{
		if (radiobtn[i].checked)
		{
			cnt = i; 
			i = -1;
		}
	}
	if (cnt > -1)
		return radiobtn[cnt].value;
	else
		return null;
}

//-->
