// Javascript
// Flyfo Air Canada


function getZeroPadded(input, len) {
	retString = new String(input);
	while (retString.length < len)
		retString = "0" + retString;
	return retString;
}

function initFlightStatus(){
	var MonthDays = new Array('31', '28', '31', '30','31', '30', '31', '31', '30', '31', '30', '31');
	var today = new Date();
    
	curYear=today.getFullYear();
     	
	if (( ( (curYear % 4)==0 && (curYear % 100)!=0 ) || (curYear % 400)==0)) { 
		 MonthDays[1] = '29'; 
	} 
	else{ 
		MonthDays[1] = '28';
	} 
	
	thismonth=today.getMonth();
	month = months[thismonth][0];
	thisDay = today.getDate();
	var yesterdayVal="";
	var tomorrowVal="";
	
	if(thisDay == 1){
		yesterdayVal = getZeroPadded(MonthDays[thismonth-1],2) + "/" + getZeroPadded(thismonth,2) + "/" + curYear;
		
		opt = new Option(months[thismonth-1][0]+" "+MonthDays[thismonth-1],yesterdayVal);
	}
	else {
		yesterdayVal = getZeroPadded(thisDay-1,2) + "/" + getZeroPadded(today.getMonth()+1,2) + "/" + curYear;
		
		opt = new Option(month+" "+(thisDay-1),yesterdayVal);
	}
	
	document.flightInfoPlanitgo.B_DATE.options[0]=opt;
	
	var todayVal =  getZeroPadded(thisDay,2) + "/" + getZeroPadded(today.getMonth()+1,2) + "/" + curYear;
	
	opt = new Option(month+" "+(thisDay),todayVal);
	
	document.flightInfoPlanitgo.B_DATE.options[1]=opt;
	
	if (thisDay+1 > parseInt(MonthDays[thismonth])){
		tomorrowVal = getZeroPadded(1,2) + "/" + getZeroPadded(today.getMonth()+2,2) + "/" + curYear;
		
		opt = new Option(months[thismonth+1][0]+" "+1,tomorrowVal);
	
	} else{
		tomorrowVal = getZeroPadded(thisDay+1,2) + "/" + getZeroPadded(today.getMonth()+1,2) + "/" + curYear ;
		
		opt = new Option(month+" "+(thisDay+1),tomorrowVal);	
	}
	document.flightInfoPlanitgo.B_DATE.options[2]=opt;
	document.flightInfoPlanitgo.B_DATE.selectedIndex=1;
}

function checkNumericValueWithlength(field, length) {
    var i = 0;
    var t = field.value;
    var x = new Number(t);

    if (t == "" || t.search(" ") != -1 || t.length > length || x.toString() == "NaN") {
	    if ((document.flightInfoPlanitgo.PAGE_TYPE != null)) {

			
				
		}
		document.getElementById("flight_e").style.display='block';
		document.getElementById("inpage").style.display='block';
		document.getElementById("inpageUser").style.display='block';
		document.getElementById("ip-flight").style.display='block';	
        field.select();
        field.focus();
        return false;
    }
    return true;
}

var FlightNumberLength = 4;

function flifoValidate(form) {
	return checkNumericValueWithlength(form.FLIGHT_NUMBER,FlightNumberLength);
}

//Set the COUNTRY and MARKET form values to be submitted to Planitgo for the underlying flight info on ACO
function setFlightinfoFormFields() {
		
		document.flightInfoPlanitgo.USERID.value = "GUEST";
		document.flightInfoPlanitgo.EXTERNAL_ID.value = "GUEST";
		document.flightInfoPlanitgo.COUNTRY.value = "US";
		document.flightInfoPlanitgo.MARKET.value = "US";

}

//Set the COUNTRY and MARKET form values to be submitted to Planitgo for the underlying flight info on ACO
function submitHomeFlightinfo(form) {
	if (form.FLIGHT_NUMBER.value == "") {
			document.getElementById("flight_e").style.display='block';
			document.getElementById("inpage").style.display='block';
			document.getElementById("inpageUser").style.display='block';
			document.getElementById("ip-flight").style.display='block';
	    	return false;
    }
	
	setFlightinfoFormFields();
	
	if (flifoValidate(document.flightInfoPlanitgo)){
		aWin=window.open('','Wait','width=800,height=640,top=50,left=50,resizable,scrollbars'); 
		aWin.focus();
		//if (formActionValue){
			//document.flightInfoPlanitgo.action = formActionValue;
		//}
		document.flightInfoPlanitgo.target="Wait";
		//return true;
	}
	else
		return false; 
}

function submitAgentsFlightinfo() {
	if (flifoValidate(document.flightInfoPlanitgo)){
		bWin=window.open('','WaitWindow','width=500,height=350,top=50,left=50,resizable,scrollbars');
		bWin.focus();
		document.flightInfoPlanitgo.target="WaitWindow";
		return true;
	}
	else
		return false; 
}

function initFunction(){
}


