// JavaScript Document

var return_month_index = -1
var return_day_index = -1
var return_time_index = -1
var checkstr = ""
var CountArrange = 0
var is_parent_prof = 1
var indexAirlines = 0
var numero
var select_Airlines_text = "Please select an airline."
var no_preference_text = "No preference"
var departing_date_selected = false

if (self.name == "engine") {

    if (parent.new_user)

        parent.reload_tabs_only("availability", "flights")

    else

        parent.reload_tabs_only("bookings", "flights")

}



function ErrorWindow(cadena) {

    var parameter = cadena

    newWindow = window.open("error.html", "newWin", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=320,height=325")

    if (navigator.appName == "Netscape")

        newWindow.focus()

}



function ReturnTrip() {

    if (return_month_index == -1) {

        for (n = 0; n < document.forms[0].E_MONTH.length; n++) {

            if (document.forms[0].E_MONTH.options[n].selected)

                return_month_index = n

        }

        for (n = 0; n < document.forms[0].E_DAY.length; n++) {

            if (document.forms[0].E_DAY.options[n].selected)

                return_day_index = n

        }



        for (n = 0; n < document.forms[0].E_TIME.length; n++) {

            if (document.forms[0].E_TIME.options[n].selected)

                return_time_index = n

        }



    }

    document.forms[0].E_MONTH.options[return_month_index].selected = true

    document.forms[0].E_DAY.options[return_day_index].selected = true

    document.forms[0].E_TIME.options[return_time_index].selected = true

}



function DefaultReturnTrip() {

    if (return_month_index == -1) {

        for (n = 0; n < document.forms[0].E_MONTH.length; n++) {

            if (document.forms[0].E_MONTH.options[n].defaultSelected)

                return_month_index = n

        }

        for (n = 0; n < document.forms[0].E_DAY.length; n++) {

            if (document.forms[0].E_DAY.options[n].defaultSelected)

                return_day_index = n

        }



        for (n = 0; n < document.forms[0].E_TIME.length; n++) {

            if (document.forms[0].E_TIME.options[n].defaultSelected)

                return_time_index = n

        }



    }

    document.forms[0].E_MONTH.options[return_month_index].selected = true

    document.forms[0].E_DAY.options[return_day_index].selected = true

    document.forms[0].E_TIME.options[return_time_index].selected = true

}

function OnewayTrip() {

    var lengthMonth = document.forms[0].E_MONTH.length

    var lengthDay = document.forms[0].E_DAY.length

    var lengthTime = document.forms[0].E_TIME.length

    if (!(document.forms[0].E_MONTH.selectedIndex == lengthMonth - 1 && document.forms[0].E_DAY.selectedIndex == lengthDay - 1 && document.forms[0].E_TIME.selectedIndex == lengthTime - 1)) {

        return_month_index = document.forms[0].E_MONTH.selectedIndex

        return_day_index = document.forms[0].E_DAY.selectedIndex

        return_time_index = document.forms[0].E_TIME.selectedIndex

        document.forms[0].E_MONTH.options[lengthMonth - 1].selected = true

        document.forms[0].E_DAY.options[lengthDay - 1].selected = true

        document.forms[0].E_TIME.options[lengthTime - 1].selected = true

    }

}



function Check() {

    checkstr = ""

    var myform = document.forms[0]

    var dYearMonthIndex = myform.B_MONTH.selectedIndex

    var dDayIndex = myform.B_DAY.selectedIndex

    var dYearMonthValue = myform.B_MONTH.options[dYearMonthIndex].value

    var dDayValue = myform.B_DAY.options[dDayIndex].value



    var dTimeIndex = myform.B_TIME.selectedIndex

    var dTimeValue = myform.B_TIME.options[dTimeIndex].value

    var dTimeText = myform.B_TIME.options[dTimeIndex].text

    if (dTimeValue == "ANY")

        myform.B_ANY_TIME_1.value = "TRUE"

    else

        myform.B_ANY_TIME_1.value = "FALSE"



    myform.B_DATE_1.value = dYearMonthValue + dDayValue + (dTimeValue == "ANY" ? "0000" : dTimeValue)



    var rYearMonthIndex = myform.E_MONTH.selectedIndex

    var rDayIndex = myform.E_DAY.selectedIndex



    var rTimeIndex = myform.E_TIME.selectedIndex

    var rTimeValue = myform.E_TIME.options[rTimeIndex].value

    var rTimeText = myform.E_TIME.options[rTimeIndex].text

    if (rTimeValue == "ANY")

        myform.B_ANY_TIME_2.value = "TRUE"

    else

        myform.B_ANY_TIME_2.value = "FALSE"



    var rYearMonthValue = myform.E_MONTH.options[rYearMonthIndex].value

    var rDayValue = myform.E_DAY.options[rDayIndex].value



    if (myform.TRIP_TYPE[1].checked)



        myform.B_DATE_2.value = (rYearMonthValue == "XX" ? "" : rYearMonthValue) + (rDayValue == "XX" ? "" : rDayValue) + (rTimeValue == "XX" ? "" : (rTimeValue == "ANY" ? "0000" : rTimeValue))



    if (myform.TRIP_TYPE[1].checked) {

        if ((rYearMonthValue == dYearMonthValue && rDayValue == dDayValue && ((rTimeValue < dTimeValue && dTimeValue < 24) || rTimeValue == 24)) || ((rYearMonthValue == dYearMonthValue) && (rDayValue < dDayValue)) || rYearMonthValue < dYearMonthValue)

            checkstr += "<li> Return date should be later than departure date</li>"

    }



    if (myform.TRIP_TYPE[1].checked) {



        rYear = rYearMonthValue.substring(0, 4)

        rMonth = rYearMonthValue.substring(4, 6)

        checkstr += CheckDates(rMonth, rDayValue, rYear, 1)



    }



    dYear = dYearMonthValue.substring(0, 4)

    dMonth = dYearMonthValue.substring(4, 6)

    checkstr += CheckDates(dMonth, dDayValue, dYear, 0)



    if (myform.B_LOCATION_1.options[myform.B_LOCATION_1.selectedIndex].value == "") {

        checkstr += "<li> You must choose a departure city"

    }



    if (myform.E_LOCATION_1.options[myform.E_LOCATION_1.selectedIndex].value == "") {

        checkstr += "<li> You must choose an arrival city</li>"

    }



    if (checkstr != "") {

        ErrorWindow(checkstr)

        return false

    } else {







        return true

    }

}



function CheckDates(month, day, year, returning) {

    var year = parseInt(year)

    var leap_year = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)

    if (!leap_year && month == "02" && (day == "30" || day == "29")) {

        if (returning == 0)

            return "<li> Invalid departure date.</li>"

        else

            return "<li> Invalid return date.</li>"

    }

    var comp1 = (month == "02" || month == "04" || month == "06" || month == "09" || month == "11")

    var comp2 = (day == "31")

    if (comp1 && comp2) {

        if (returning == 0)

            return "<li> Invalid departure date.</li>"

        else

            return "<li> Invalid return date.</li>"

    } else

        return ""

}



function Check2() {

    if (Check())

        document.AIR_ENTRY_FORM.submit()

}



function GenerateMonthSelect(selectName) {

    var start = new Date;



    document.write('<select name="' + selectName + '" class="book-year">');



    var month = start.getMonth() + 1;

    var year = start.getFullYear();



    for (var i = 0; i < 13; i++) {



        var value = "" + year + (month < 10 ? "0" + month : month);



        var display = GetShortMonth(month) + " " + year;



        document.write('<option value="' + value + '">' + display + '</option>');



        month = month + 1;



        if (month == 13) {

            month = 1;

            year = year + 1;

        }

    }



    document.write('</select> ');

}



function GenerateDaySelect(selectName) {

    var start = new Date;



    document.write('<select name="' + selectName + '" class="book-date">');



    for (var i = 1; i <= 31; i++) {
        var i_as_string;

        if (i < 10) {
            i_as_string = '0' + i;
        } else {
            i_as_string = i;
        }

        document.write('<option value="' + i_as_string + '"' + (start.getDate() == i ? " selected" : "") + '>' + i + '</option>');

    }

    document.write('</select> ');
}



function GetShortMonth(month) {

    if (month == 1) return "Jan";

    if (month == 2) return "Feb";

    if (month == 3) return "Mar";

    if (month == 4) return "Apr";

    if (month == 5) return "May";

    if (month == 6) return "Jun";

    if (month == 7) return "Jul";

    if (month == 8) return "Aug";

    if (month == 9) return "Sep";

    if (month == 10) return "Oct";

    if (month == 11) return "Nov";

    if (month == 12) return "Dec";

}

function setup_dest() {
    var dep_airport = document.forms[0].dep_airport.options[document.forms[0].dep_airport.selectedIndex];
    var cur_dest_airport_val = document.forms[0].dest_airport.options[document.forms[0].dest_airport.selectedIndex].value;
    var descriptions = new Array();

    descriptions["nosel"] = "-- Select Airport --";
    //	descriptions["OOM"] = "Cooma, Cooma, NSW";
    descriptions["NAA"] = "Narrabri, Narrabri, NSW";
    descriptions["NTL"] = "Newcastle, Williamtown, NSW";
   // descriptions["IVR"] = "Inverell, Inverell, NSW";
    descriptions["SYD"] = "Sydney, Kingsford Smith, NSW";
	descriptions["DGE"] = "Mudgee, Mudgee, NSW";
	descriptions["OOM"] = "Snowy Mountains, Cooma, NSW";

    var airports = "nosel,NTL,NAA,SYD,DGE,OOM".split(',');


    //	if (dep_airport.value == 'OOM') {
    //		airports = "nosel,NTL".split(',');		
    //	}

   // if (dep_airport.value == 'IVR') {
  //      airports = "nosel,NTL,SYD".split(',');
  //  }

    if (dep_airport.value == 'NTL') {
        // removed cooma route
        //airports = "nosel,IVR,OOM,SYD".split(',');
        // airports = "nosel,IVR,SYD".split(',');
        airports = "nosel,SYD".split(',');
    }

    if (dep_airport.value == 'SYD') {
        //airports = "nosel,IVR,NTL,NAA".split(',');
        airports = "nosel,NTL,NAA,DGE,OOM".split(',');
    }

    if (dep_airport.value == 'NAA') {
        airports = "nosel,SYD".split(',');
    }  
	
    if (dep_airport.value == 'DGE') {
        airports = "nosel,SYD".split(',');
    } 	
	
    if (dep_airport.value == 'OOM') {
        airports = "nosel,SYD".split(',');
    } 

    // populate select box

    document.forms[0].dest_airport.options.length = 0;
    document.forms[0].dest_airport.options.length = airports.length;

    for (var i = 0; i < airports.length; i++) {
        if (airports[i] != 'nosel') {
            document.forms[0].dest_airport.options[i].value = airports[i];
        }

        document.forms[0].dest_airport.options[i].text = descriptions[airports[i]];

        if (airports[i] == cur_dest_airport_val) {
            document.forms[0].dest_airport.options.selectedIndex = i;
        }
    }
}

function setup_passengers() {
    var selected_adult = document.forms[0].num_adult.selectedIndex;
    var selected_child = document.forms[0].num_child.selectedIndex;



    document.forms[0].num_adult.options.length = 0;
    document.forms[0].num_adult.options.length = 4 - selected_child;

    document.forms[0].num_child.options.length = 0;
    document.forms[0].num_child.options.length = 4 - selected_adult;


    for (var i = 0; i < 4; i++) {
        if (i < (4 - selected_child)) {
            document.forms[0].num_adult.options[i].value = i + 1;
            document.forms[0].num_adult.options[i].text = i + 1;
        }

        document.forms[0].num_adult.options.selectedIndex = selected_adult;

        if (i < (4 - selected_adult)) {
            document.forms[0].num_child.options[i].value = i;
            document.forms[0].num_child.options[i].text = i;
        }

        document.forms[0].num_child.options.selectedIndex = selected_child;
    }
}
