//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 = 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 ((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() {
		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) {
    setFlightinfoFormFields();

    aWin = window.open('', 'Wait', 'width=850,height=600,top=50,left=50,resizable,scrollbars'); 
	aWin.focus();
	document.flightInfoPlanitgo.target="Wait";
}

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; 
}



