//Javascript
//FlyFo Home

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 = curYear + getZeroPadded(thismonth,2) + getZeroPadded(MonthDays[thismonth-1],2) + "0900";
		
		opt = new Option(months[thismonth-1][0]+" "+MonthDays[thismonth-1],yesterdayVal);
	}
	else {
		yesterdayVal = curYear + getZeroPadded(today.getMonth()+1,2) + getZeroPadded(thisDay-1,2) + "0900";
		
		opt = new Option(month+" "+(thisDay-1),yesterdayVal);
	}
	
	document.flightInfoPlanitgo.B_DATE.options[0]=opt;
	
	var todayVal = curYear + getZeroPadded(today.getMonth()+1,2) + getZeroPadded(thisDay,2) + "0900";
	
	opt = new Option(month+" "+(thisDay),todayVal);
	
	document.flightInfoPlanitgo.B_DATE.options[1]=opt;
	
	if (thisDay+1 > parseInt(MonthDays[thismonth])){
		tomorrowVal = curYear + getZeroPadded(today.getMonth()+2,2) + getZeroPadded(1,2) + "0900";
		
		opt = new Option(months[thismonth+1][0]+" "+1,tomorrowVal);
	
	} else{
		tomorrowVal = curYear + getZeroPadded(today.getMonth()+1,2) + getZeroPadded(thisDay+1,2) + "0900";
		
		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 ((parent.window.location.href.indexOf('home.html') != -1) || (document.flightInfoPlanitgo.PAGE_TYPE != null)) {

				alert("Please enter a valid flight number.");
				
		}	
        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() {
	//var signOnCookie = getCookie("AC-Signon-Cookie");
	//var sessionCookie = getCookie("AC-Session-Cookie");
	//if (signOnCookie && sessionCookie) {
		//var signOnCookieValue = signOnCookie.split('^');
		//var sessionCookieValue = sessionCookie.split('^');
		//document.flightInfoPlanitgo.USERID.value = signOnCookieValue[0];
		//document.flightInfoPlanitgo.EXTERNAL_ID.value = sessionCookieValue[0];
	//}else{
		document.flightInfoPlanitgo.USERID.value = "GUEST";
		document.flightInfoPlanitgo.EXTERNAL_ID.value = "GUEST";
	//}	

	//if (checkLangCookie('new_lang_pref')=="us") {
		document.flightInfoPlanitgo.COUNTRY.value = "US";
		document.flightInfoPlanitgo.MARKET.value = "US";
	//} else {
		//document.flightInfoPlanitgo.COUNTRY.value = "CA";
		//document.flightInfoPlanitgo.MARKET.value = "CA";
	//}
}

//Set the COUNTRY and MARKET form values to be submitted to Planitgo for the underlying flight info on ACO
function submitHomeFlightinfo(formActionValue) {
	setFlightinfoFormFields();
	if (flifoValidate(document.flightInfoPlanitgo)){
		aWin=window.open('','Wait','width=577,height=350,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; 
}



