

function PopDays(){
	var i;
	for (i=1;i<32;i++){
		document.write('<option value=' + i + '>' + i + '</option>');
	}
}

function PopMonthYears(){
	var i;
	var today=new Date();
	var year=today.getYear();
	var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

	for (i=0;i<16;i++){
		if (m_names[i]=='Jan' && i>1){
			year=year+1
		}
		document.write('<option value="' + m_names[i] + ' ' + year + '">' + m_names[i] + ' ' + year + '</option>');
	}
}


function SelectDays(Outward,AddDays){
	var i;
	var today=new Date();	
	today.setDate(today.getDate()+AddDays);	
	var selectthis=today.getDate();
	if (Outward){
		document.bookonline.departureday.selectedIndex=selectthis-1;
	}
	else{
		document.bookonline.returnday.selectedIndex=selectthis-1;
	}
}


function SelectMonthYear(Outward,AddDays){
	var i;
	var today=new Date();
	var loop;
	var oOptions;
	var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");	
	today.setDate(today.getDate()+AddDays);	
	var selectthis=m_names[today.getMonth()] + ' ' + today.getYear();
	if (Outward){
		oOptions=document.bookonline.departuremonthyear.options;
		for (loop=0;loop<oOptions.length;loop++){
			if (oOptions[loop].value==selectthis){
			document.bookonline.departuremonthyear.selectedIndex=loop;
			break;
			}
		}
	}
	else{
		oOptions=document.bookonline.returnmonthyear.options;
		for (loop=0;loop<oOptions.length;loop++){
			if (oOptions[loop].value==selectthis){
			document.bookonline.returnmonthyear.selectedIndex=loop;
			break;
			}
		}
	}
}


function ChangeDestinations(SelectThis){
	if ((versionType != 'u') || (versionType == 'e' && versionNum > 3) || (versionType == 'n' && versionNum > 4)){
		if (document.bookonline.origin.selectedIndex == -1){
			var origin = "NIL";
		}
		else{
			var origin = document.bookonline.origin.options[document.bookonline.origin.selectedIndex].value.substring(0,3);
		}		
		if (origin != 'NIL'){
			var FromArray = eval('From' + origin);
			var DestinationList = document.bookonline.destination.options;			
			DestinationList.length = 1;			
			for (loop=0; loop < FromArray.length; loop++){
				DestinationList[loop] = new Option(eval(FromArray[loop]));
				DestinationList[loop].value = FromArray[loop];
			}			
			DestinationList.selectedIndex = 0;
			if (SelectThis!=''){
				//reselect
				for (loop=0; loop < DestinationList.length; loop++){
					if (DestinationList[loop].value.substring(0,3)==SelectThis){
						DestinationList.selectedIndex = loop;
					}
				}
			}
		}
	}
}


function showreturn(){
	if (document.bookonline.returntrip.checked){
		document.bookonline.returnday.disabled =false;
		document.bookonline.returnmonthyear.disabled =false;
		//document.bookonline.returntime.disabled =false;
		ChangeDepartureDate();
	}
	else{
		document.bookonline.returnday.disabled =true;
		document.bookonline.returnmonthyear.disabled =true;
		//document.bookonline.returntime.disabled =true;
	}
}


var day=1;
var monthyear=0;
var source=0;
var requirements=1;

function makeArray0() {
    for (i = 0; i<makeArray0.arguments.length; i++)
        this[i] = makeArray0.arguments[i];
}


function y2k(number){
	return (number < 1000) ? number + 1900 : number; 
}


function ChangeDepartureDate(){
	var days = new makeArray0(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    var firstDay;
    firstDay = new Date('1 ' + document.bookonline.departuremonthyear.options[document.bookonline.departuremonthyear.selectedIndex].value);
	var Month;
	var Year;
	Month=firstDay.getMonth();
	Year=y2k(firstDay.getYear());

	var todayd;
    var beginday;
    var beginmonth;
    var beginyear;
    todayd=new Date();
    beginday=todayd.getDate();
    beginmonth=todayd.getMonth();
    beginyear=todayd.getYear();
    
    if (beginday>days[beginmonth]){
		beginday=beginday-days[beginmonth];
		beginmonth=todayd.getMonth()+1;
    	if (beginmonth<todayd.getMonth()){
			beginyear=todayd.getYear()+1
		}
	}
    if ((document.bookonline.departureday.value<beginday && beginmonth==Month && Year==beginyear) || (Month<beginmonth && (Year<beginyear || Year==beginyear))){
		alert("Your departure date is too early please pick a later date");
	}
	else{
		if (document.bookonline.departuremonthyear.selectedIndex > document.bookonline.returnmonthyear.selectedIndex){
			if (document.bookonline.returntrip.checked){
				document.bookonline.returnmonthyear.selectedIndex=document.bookonline.departuremonthyear.selectedIndex;
			}
		}
		if (document.bookonline.departuremonthyear.selectedIndex == document.bookonline.returnmonthyear.selectedIndex){
			if (document.bookonline.departureday.selectedIndex > document.bookonline.returnday.selectedIndex){
				if (document.bookonline.returntrip.checked){
					document.bookonline.returnday.selectedIndex=document.bookonline.departureday.selectedIndex;
				}
			}
		}
	}
}


function ChangeReturnDate(){
	if (document.bookonline.departuremonthyear.selectedIndex > document.bookonline.returnmonthyear.selectedIndex){
		//document.bookonline.departuremonthyear.selectedIndex=document.bookonline.returnmonthyear.selectedIndex;
		}
	if (document.bookonline.departuremonthyear.selectedIndex == document.bookonline.returnmonthyear.selectedIndex){
		if (document.bookonline.departureday.selectedIndex > document.bookonline.returnday.selectedIndex){
			//document.bookonline.departureday.selectedIndex=document.bookonline.returnday.selectedIndex;
		}
	}
}


function setselection(settype){
	if (document.bookonline.origin.value!="XXX"){
		//var sURL;	
		//sURL="http://customer.videcom.com/safiairways/checkrequirements.asp";
		//sURL=sURL + "?origin=" + document.bookonline.origin.value;
		//sURL=sURL + "&destination=" + document.bookonline.destination.value;
		//sURL=sURL + "&departureday=" + document.bookonline.departureday.value;
		//sURL=sURL + "&departuremonthyear=" + document.bookonline.departuremonthyear.value;
		//sURL=sURL + "&returnday=" + document.bookonline.returnday.value;
		//sURL=sURL + "&returnmonthyear=" + document.bookonline.returnmonthyear.value;
		//sURL=sURL + "&numberofadults=" + document.bookonline.numberofadults.value;
		//sURL=sURL + "&numberofchildren=" + document.bookonline.numberofchildren.value;
		//sURL=sURL + "&numberofinfantswithoutseats=" + document.bookonline.numberofinfantswithoutseats.value;
		//sURL=sURL + "&mode=''";
		//sURL=sURL + "&faretype=" + settype;
		//sURL=sURL + "&sourcepage=requirements.asp";
		//if (document.bookonline.returntrip.checked==true)
		//{
			//sURL=sURL + "&returntrip=on";
		//}
		//else
		//{
			//sURL=sURL + "&returntrip=off";
		//}
		//launch(sURL,700,900);

		document.bookonline.faretype.value=settype;
		document.bookonline.submit();
	}
	else{
		window.alert("Please choose a from and to first.");
	}
}


function ShowReturnRequirements(){
	if (document.getElementById('returntrip').checked){
		document.getElementById('returnmonthyear').disabled=false;
		document.getElementById('returnday').disabled=false;
	}
	else {
		document.getElementById('returnmonthyear').disabled=true;
		document.getElementById('returnday').disabled=true;
	}
}


function ChangeFilteredDestinations(sFormName,SelectThis){
	var loop;
	if (document[sFormName].origin.selectedIndex==-1){
		var origin = 'NIL';
	}
	else{
		var origin = document[sFormName].origin.options[document[sFormName].origin.selectedIndex].value.substring(0,3);
	}
	if (origin != 'NIL'){
		var sListDestination = eval('From' + origin);
		var FromArray=sListDestination.split(',');
		var DestinationList = document[sFormName].destination.options;
		DestinationList.length = 0;
		if (FromArray.length==0){
			DestinationList[0] = new Option('No destinations');
			DestinationList[0].value = 'Nodestinations';
		}
		else{
			for (loop=0; loop < FromArray.length; loop++){
				DestinationList[loop] = new Option(eval(FromArray[loop]));
				DestinationList[loop].value = FromArray[loop];
			}
		}
		DestinationList.selectedIndex=0;
		if (SelectThis!=''){
			for (loop=0; loop < DestinationList.length; loop++){
				if (DestinationList[loop].value.substring(0,3)==SelectThis){
					DestinationList.selectedIndex = loop;
				}
			}
		}
	}
}


function isNS2(){
	return ((self.navigator.appName=='Netscape') && (parseInt(self.navigator.appVersion,10)<3));
}


function launch(u, h, w){
	if (isNS2()) return;
	var PopUpWindow;
	if (PopUpWindow != null)
		if(PopUpWindow.closed != true)
	PopUpWindow.close();
	PopUpWindow = window.open(u, "PopUpWindow" ,"toolbar=no,directories=no,status=yes,scrollbars=yes,resizable=yes,resize=yes,menubar=no,left=" + ((screen.width/2)-(w/2)) + ",top=" + ((screen.Height/2)-(h/2)) + ",height=' + h + ',width=' + w");
}

function checkOriginDestination(){

	/*if (document.bookonline.origin.selectedIndex == 0)
		alert("Please choose origin!")
	else if (document.bookonline.destination.selectedIndex == 0)		
		alert("Please choose destination!")
	else if (document.bookonline.origin.selectedIndex == document.bookonline.destination.selectedIndex)
		alert("The origin & destination must be diffrent!")
	else*/
	document.bookonline.submit();
	window.open('http://booking.safiairways.aero/checkrequirements.asp' , 'safiairways');
		
}
