﻿function login()
{
    if (document.getElementById('login_all').style.display == 'block')
    {
        document.getElementById('login_all').style.display = 'none';
        if (document.getElementById('lang_all').style.display == 'block')
        {
            document.getElementById('location').style.display = 'none';
        }
        else
        {
            document.getElementById('location').style.display = 'block';
        }
    }
    else
    {
        document.getElementById('login_all').style.display = 'block';
        document.getElementById('location').style.display = 'none';
    }
}
function anxlang()
{
    if (document.getElementById('lang_all').style.display == 'block')
    {
        document.getElementById('lang_all').style.display = 'none';
        if (document.getElementById('login_all').style.display == 'block')
        {
            document.getElementById('location').style.display = 'none';
        }
        else
        {
            document.getElementById('location').style.display = 'block';
        }
    }
    else
    {
        document.getElementById('lang_all').style.display = 'block';
        document.getElementById('location').style.display = 'none';
    }
}
function generate_country_list()
{
    c_sel = document.getElementById('banner_country');
    c_sel.length = 0;
    country = "1010";
    if (readCookie("country") != null)
        country = readCookie("country");
    Country_tbl = Country_tbl.sort(compareName);
    var specialCountriesRedirect = false;
    
    for (i = 0; i < Country_tbl.length; i++)
    {
        c_sel.options[c_sel.options.length] = new Option(Country_tbl[i][1], Country_tbl[i][0]);
        if (Country_tbl[i][0] == country && Country_tbl[i][3] != 'LU' && Country_tbl[i][3] != 'EE' && !specialCountriesRedirect) 
        {
            c_sel.options[c_sel.options.length - 1].selected = true;
        }
        else if ((Country_tbl[i][3] == 'LU' && readCookie("country_sel") == 'LU') || (Country_tbl[i][3] == 'EE' && readCookie("country_sel") == 'EE')) 
        {
            c_sel.options[c_sel.options.length - 1].selected = true;
            specialCountriesRedirect = true;
        } 
    }
    generate_lang_list()
}
function generate_lang_list()
{
    c_sel = document.getElementById('banner_country');
    l_sel = document.getElementById('banner_lang');

    l_sel.length = 0;
    lang_sel = c_sel.selectedIndex;
    for (i = 0; i < Country_tbl[lang_sel][2].length; i++)
    {
        Country_tbl[lang_sel][2].sort(compareLang);
        text = Country_tbl[lang_sel][2][i];
        for (j = 0; j < Lang_tbl.length; j++)
        {
            if (Country_tbl[lang_sel][2][i] == Lang_tbl[j][0])
                text = Lang_tbl[j][1];
        }
        l_sel.options[l_sel.options.length] = new Option(text, Country_tbl[lang_sel][2][i]);
        if (readCookie("anxlang") != null)
        {
            if (Country_tbl[lang_sel][2][i].toUpperCase() == readCookie("anxlang").toUpperCase())
                l_sel.options[l_sel.options.length - 1].selected = true;
        }
    }
}
function compareName(a, b)
{
    a1 = a[1].toLowerCase();
    b1 = b[1].toLowerCase();
    if (escape(a1.substring(0, 1)) == '%u0142')
    {
        if ("l" < b1.substring(0, 1)) return -1;
        else return 1;
    }
    if (a1 < b1)
        return -1;
    else
        return 1;
}
function compareLang(a, b)
{
    a1 = a;
    b1 = b;
    for (j = 0; j < Lang_tbl.length; j++)
    {
        if (a == Lang_tbl[j][0]) a1 = Lang_tbl[j][1];
        if (b == Lang_tbl[j][0]) b1 = Lang_tbl[j][1];
    }
    if (a1 < b1) return -1;
    else return 1;
}
function change_lang()
{
    document.Language._lang.value = document.getElementById('banner_lang').value;
    document.Language._cid.value = document.getElementById('banner_country').value;

    lang_sel = document.getElementById('banner_country').selectedIndex;

    document.getElementById('country_flag').src = '/portal/img/flag_' + Country_tbl[lang_sel][3] + '.gif';
    document.getElementById('country_name').innerHTML = Country_tbl[lang_sel][1];



    for (i = 0; i < Lang_tbl.length; i++)
    {
        if (Lang_tbl[i][0] == document.getElementById('banner_lang').value)
            document.getElementById('lang_name').innerHTML = Lang_tbl[i][1];
    }
    eraseCookie("country");
    createCookie("country", document.getElementById('banner_country').value);
    eraseCookie("anxlang");
    createCookie("anxlang", document.getElementById('banner_lang').value);
    eraseCookie("country_sel");
    createCookie("country_sel", Country_tbl[lang_sel][3]);

    window.location.href = '/default.aspx?_lang=' + document.getElementById('banner_lang').value + '&_cid=' + document.getElementById('banner_country').value;
}
function set_default_lang()
{
    lang_sel = document.getElementById('banner_country').selectedIndex;
    document.getElementById('country_flag').src = '/Portal/img_LOT/flag_' + Country_tbl[lang_sel][3] + '.gif';
    document.getElementById('country_name').innerHTML = Country_tbl[lang_sel][1];
    for (i = 0; i < Lang_tbl.length; i++)
    {
        if (Lang_tbl[i][0] == document.getElementById('banner_lang').value)
            document.getElementById('lang_name').innerHTML = Lang_tbl[i][1];
    }
}
function anxLogout()
{
    var lang = document.Language._lang.value;
    var country = readCookie("country");
    if (!readCookie("country"))
    {
        country = '1010';
    }
    location.replace('/Default.aspx?_cmd=LOT_IBE_Logout&_lang=' + lang + '&_cid=' + country);
}
function anxLogin(user, pass, remember)
{
    Form = document.Login;
    var loc = window.location.pathname;
    n = loc.indexOf("Portal");
    var lang = 'pl';
    if (n != -1)
    {
        lang = loc.substring(n + 2, n + 4);
        Form._lang.value = lang;
    }
    Form.login.value = user;
    Form.password.value = pass;
    if (remember)
        Form.rememberme.value = remember;
    Form.submit()
}
function eraseCookie(name)
{
    try
    {
        document.cookie = name + '=; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/'
    }
    catch (e) { createCookie(name, "", -1); }
}
function createCookie(name, value)
{
    ToDay = new Date();
    ToDay.setTime(Expires = (24 * 60 * 60 * 1000 * 365) + ToDay.getTime());
    Expires = (ToDay.toGMTString());
    document.cookie = name + "=" + value + "; path=/;EXPIRES=" + Expires;
}
function readCookie(name)
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++)
    {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
function choice_way(way)
{
    if (way == 'return')
    {
        document.getElementById('way_return').className = 'sel';
        document.getElementById('way_single').className = 'nsel';
        document.getElementById('retdate').style.display = 'block';
        document.getElementById('retdate_label').style.display = 'block';
        document.getElementById('retcal').style.display = 'block';
        document.mainForm.elements['flight-type'].value = 'return';
    }
    else
    {
        document.getElementById('way_return').className = 'nsel';
        document.getElementById('way_single').className = 'sel';
        document.getElementById('retdate').style.display = 'none';
        document.getElementById('retdate_label').style.display = 'none';
        document.getElementById('retcal').style.display = 'none';
        document.mainForm.elements['flight-type'].value = 'single';
    }
}
function show_hide(id, max_id, name, name2)
{
    for (i = 1; i <= max_id; i++)
    {
        document.getElementById(name + i).style.display = 'none';
        document.getElementById(name2 + i).className = 'nsel';
    }
    document.getElementById(name + id).style.display = 'block';
    document.getElementById(name2 + id).className = 'sel';
}
function set_class(class_value, new_class, remove)
{
    class_value_split = class_value.split(" ");
    class_value = "";
    for (i = 0; i < class_value_split.length; i++)
    {
        if (class_value_split[i] != remove && class_value_split[i] != new_class)
        {
            class_value += class_value_split[i] + " ";
        }
    }
    class_value += new_class;
    return class_value;
}
function set_start_form(way)
{
    document.getElementById('car_button').className = set_class(document.getElementById('car_button').className, 'nsel', 'sel');
    document.getElementById('plane_button').className = set_class(document.getElementById('plane_button').className, 'nsel', 'sel');
    document.getElementById('ins_button').className = set_class(document.getElementById('ins_button').className, 'nsel', 'sel');
    document.getElementById('hotel_button').className = set_class(document.getElementById('hotel_button').className, 'nsel', 'sel');
    document.getElementById('form_plane').style.display = 'none';
    document.getElementById('form_car').style.display = 'none';
    document.getElementById('form_ins').style.display = 'none';
    document.getElementById('form_hotel').style.display = 'none';
    if (way == 'plane' || way == 'car' || way == 'ins' || way == 'hotel')
    {
        document.getElementById(way + '_button').className = set_class(document.getElementById(way + '_button').className, 'sel', 'nsel');
        document.getElementById('form_' + way).style.display = 'block';
    }
    else
    {
        document.getElementById('plane_button').className = set_class(document.getElementById('plane_button').className, 'sel', 'nsel');
        document.getElementById('form_plane').style.display = 'block';
    }
    if (way == 'plane')
        active_form = 'mainForm';
    else if (way == 'car')
        active_form = 'carForm';
    else if (way == 'ins')
        active_form = 'insForm';
    /*document.getElementById('plane_button').className = 'sel';
    document.getElementById('form_plane').style.display = 'block';
    active_form = 'mainForm';*/
}
function set_car_data() 
{
    Form = document.forms['carForm'];
    
    if (Form.CarClass.value == "")
    {
        Form.vcs.disabled = true;
        Form.CarClass.disabled = true;
    }
    else
    {
        Form.vcs.disabled = false;
        Form.CarClass.disabled = false;
    }

    Form.pickupdate.value = Form.CarDateFromDay.value + '.' + Form.CarDateFromMonthYear.value;
    Form.dropoffdate.value = Form.CarDateToDay.value + '.' + Form.CarDateToMonthYear.value;
   
    var ISOoutDate = "" + Form.CarDateFromMonthYear.value.substring(3, 7) + Form.CarDateFromMonthYear.value.substring(0, 2) + Form.CarDateFromDay.value + "";
    var ISOretDate = "" + Form.CarDateToMonthYear.value.substring(3, 7) + Form.CarDateToMonthYear.value.substring(0, 2) + Form.CarDateToDay.value + "";
    
    
    var cookie_string = "";
    var formTable = ['CarDateFromDay', 'CarDateToDay', 'pickup', 'dropoff', 'CarDateFromMonthYear', 'CarDateToMonthYear', 'pickuptime', 'dropofftime', 'CarClass', 'CarType', 'GearBox', 'ac'];
    for (i = 0; i < formTable.length; i++)
    {
        cookie_string += formTable[i] + "=" + Form.elements[formTable[i]].value + "||";
    }
    eraseCookie("anxstart_car_value");
    createCookie("anxstart_car_value", cookie_string);
    eraseCookie("StartType");
    createCookie("StartType", "car");

    $('#err12').hide();
    $('#err10').hide();
    $('#err11').hide();

    if (parseFloat(ISOoutDate) > parseFloat(ISOretDate))
    {
        $('#err12').show();
        return false;
    }
    
    if (parseFloat(ISOoutDate + Form.pickuptime.value) < parseFloat(ISOtoday))
    {
        $('#err11').show();
        return false;
    }
    
    if (parseFloat(ISOoutDate) == parseFloat(ISOretDate) && (parseFloat(Form.pickuptime.value) > parseFloat(Form.dropofftime.value)))
    {
        $('#err10').show();
        return false;
    }
    
    CarSaveDataToCookie();
    document.carForm.submit();
    ShowLoader(1,4);
}
function checkPax(name)
{
    Form = document.mainForm;
    document.getElementById('err1').style.display = "none";
    document.getElementById('err2').style.display = "none";
    document.getElementById('err3').style.display = "none";

    var ADT = parseInt(Form.paxADT.value);
    var CHD = parseInt(Form.paxCHD.value);
    var SRC = parseInt(Form.paxSRC.value);
    var INF = parseInt(Form.paxINF.value);
    var ELSE = 0;
    if (name == 'paxADT')
    {
        ELSE = CHD + INF + SRC;
    }
    if (name == 'paxCHD')
    {
        ELSE = ADT + INF + SRC;
    }
    if (name == 'paxSRC')
    {
        ELSE = CHD + INF + ADT;
    }
    if (name == 'paxINF')
    {
        ELSE = CHD + ADT + SRC;
    }
    if (ADT == 0 && SRC == 0)
    {
        document.getElementById('err1').style.display = "block";
        Form.elements[name].selectedIndex = 1;
    }
    if (INF > ADT + SRC)
    {
        document.getElementById('err1').style.display = "none";
        document.getElementById('err2').style.display = "block";
        if (name == 'paxINF')
        {
            Form.paxINF.selectedIndex = ADT + SRC;
        }
        else if (name == 'paxADT')
        {
            Form.paxADT.selectedIndex = INF - SRC;
        }
        else if (name == 'paxSRC')
        {
            Form.paxSRC.selectedIndex = INF - ADT;
        }
    }
    if (ADT + CHD + SRC + INF > 9)
    {
        document.getElementById('err1').style.display = "none";
        document.getElementById('err2').style.display = "none";
        document.getElementById('err3').style.display = "block";
        if (name == 'paxINF')
            Form.elements[name].selectedIndex = Math.min(9 - ELSE, Form.paxINF.selectedIndex);
        else
            Form.elements[name].selectedIndex = 9 - ELSE;
    }
}
function checkInsPax(name)
{
    Form = document.insForm;
    document.getElementById('inserr1').style.display = "none";
    document.getElementById('inserr2').style.display = "none";
    document.getElementById('inserr3').style.display = "none";

    var ADT = parseInt(Form.paxADT.value);
    var CHD = parseInt(Form.paxCHD.value);
    var SRC = parseInt(Form.paxSRC.value);
    var INF = parseInt(Form.paxINF.value);
    var ELSE = 0;
    if (name == 'paxADT')
    {
        ELSE = CHD + INF + SRC;
    }
    if (name == 'paxCHD')
    {
        ELSE = ADT + INF + SRC;
    }
    if (name == 'paxSRC')
    {
        ELSE = CHD + INF + ADT;
    }
    if (name == 'paxINF')
    {
        ELSE = CHD + ADT + SRC;
    }
    if (ADT == 0 && SRC == 0)
    {
        document.getElementById('inserr1').style.display = "block";
        Form.elements[name].selectedIndex = 1;
    }
    if (INF > ADT + SRC)
    {
        document.getElementById('inserr1').style.display = "none";
        document.getElementById('inserr2').style.display = "block";
        if (name == 'paxINF')
        {
            Form.paxINF.selectedIndex = ADT + SRC;
        }
        else if (name == 'paxADT')
        {
            Form.paxADT.selectedIndex = INF - SRC;
        }
        else if (name == 'paxSRC')
        {
            Form.paxSRC.selectedIndex = INF - ADT;
        }
    }
    if (ADT + CHD + SRC + INF > 9)
    {
        document.getElementById('inserr1').style.display = "none";
        document.getElementById('inserr2').style.display = "none";
        document.getElementById('inserr3').style.display = "block";
        if (name == 'paxINF')
            Form.elements[name].selectedIndex = Math.min(9 - ELSE, Form.paxINF.selectedIndex);
        else
            Form.elements[name].selectedIndex = 9 - ELSE;
    }
}
var tblYears = new Array(2006, 2007, 2008, 2009, 2010);        // List of years
var tblDayEnds = new Array(6);
tblDayEnds[0] = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);    // Number of days in each moth in each year
tblDayEnds[1] = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
tblDayEnds[2] = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
tblDayEnds[3] = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
tblDayEnds[4] = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
tblDayEnds[5] = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var returncheck = 1;
function makeYearMonthOptions(form, field, selectedMonth, selectedYear)
{
    if (selectedYear > 3000) selectedYear -= 1900;
    var selectedMonthYear = parseFloat(selectedMonth) + '.' + selectedYear;
    var yearIndex = tblYears.length;
    var makeTextString = '';
    var makeValueString = '';
    var makeMonth = '';
    var optionsCounter = 0;
    for (var i = 0; parseFloat(tblYears[i]) <= (parseFloat(nowYear) + 1); i++)     // Setting one year forward
    {
        if (parseFloat(tblYears[i]) >= parseFloat(nowYear))
        {
            var j = 0;
            if (tblYears[i] == nowYear) j = (parseFloat(nowMonth) - 1);
            var maxj = 12;
            if (parseFloat(tblYears[i]) == (parseFloat(nowYear) + 1)) maxj = nowMonth;
            for (j; j < maxj; j++)
            {
                newj = j + 1;
                if (newj < 10) makeMonth = '0' + newj;          // Making 2 signs for month
                else makeMonth = newj;
                makeTextString = tblMonthsName[j] + '.' + tblYears[i];
                makeValueString = makeMonth + '.' + tblYears[i];
                document.forms[form].elements[field].options[document.forms[form].elements[field].options.length] = new Option(makeValueString, makeTextString);
                if (selectedMonthYear == ((j + 1) + '.' + tblYears[i])) document.forms[form].elements[field].options[optionsCounter].selected = true;
                optionsCounter++;
            }
        }
    }
}
function makeDayOptions(selectedDay, selectedMonth, selectedYear, form, field)
{
    Form = document.forms[form];
    Form.elements[field].length = 0;
    if (selectedYear > 3000) selectedYear -= 1900;
    selectedDay = parseFloat(selectedDay);
    selectedMonth = parseFloat(selectedMonth);
    selectedYear = parseFloat(selectedYear);
    var month = new Date;
    var day = nowDay;
    var year = nowYear;
    month = nowMonth;
    var yearIndex = 0;
    for (var i = 0; i != tblYears.length; i++)
    {
        if (tblYears[i] == selectedYear) yearIndex = i;
    }
    var numberOfDays = tblDayEnds[yearIndex][selectedMonth - 1];
    for (var i = 0; i < Form.elements[field].length; i++)
    {
        var lastIndex = Form.elements[field].length - 1;
        Form.elements[field].options[lastIndex] = null;
    }
    var makeDay = '';
    var dayNumber = 0;
    var k = 0;
    if (selectedMonth == month && selectedYear == year)
    {
        var k = day;
        k--;
    }
    if (selectedMonth == month && selectedYear != year)
    {
        var numberOfDays = day;
        numberOfDays--;
    }

    for (var i = k; i < numberOfDays; i++)
    {
        makeDay = '';
        dayNumber = i + 1;
        if ((i + 1) < 10) makeDay = '0' + dayNumber;
        else makeDay = dayNumber;
        Form.elements[field].options[i - k] = new Option;
        Form.elements[field].options[i - k].value = makeDay;
        Form.elements[field].options[i - k].text = makeDay;
        if (selectedDay == makeDay) Form.elements[field].options[i - k].selected = true;
    }
}
function ifChange(monthYear, day, form, dayNameField, dayNumbersField, updateDays)
{
    var tblMonthYear = new Array;
    tblMonthYear = monthYear.split('.');
    if (updateDays)
    {
        makeDayOptions(day, tblMonthYear[0], tblMonthYear[1], form, dayNumbersField)
    }
    setNewDates('depDateMonthYear', 'out', 'mainForm');
    setNewDates('retDateMonthYear', 'ret', 'mainForm');
    day = document.forms[form].elements[dayNumbersField].value;
   

}
function setNewDates(optionMonthYear, hidden, form)
{
    try
    {
        var newDateString = document.forms[form].elements[optionMonthYear][document.forms[form].elements[optionMonthYear].selectedIndex].value;
        document.forms[form].elements[hidden + 'dateMM'].value = newDateString.substring(0, 2);
        document.forms[form].elements[hidden + 'dateyyyy'].value = newDateString.substring(3, 7);
    }
    catch (e) { }
}
function changeReturnIfEarlier(depMonthYear, retMonthYear, outDayNumber, retDayNumber, depDayName, retDayName, form, field) { }
function changeOriginIfAfter(depMonthYear, retMonthYear, outDayNumber, retDayNumber, depDayName, retDayName, form, field) { }
function setFliFo()
{
    var ie = 0; ns = 0; gecko = 0; opera = 0;
    var agent = navigator.userAgent;
    var browser = navigator.appName;
    var version = parseInt(navigator.appVersion);
    agent = agent.toLowerCase();
    browser = browser.charAt(0);
    if (agent.indexOf('gecko') != -1) { gecko = true; }
    if (agent.indexOf('opera') != -1) { opera = true; }
    if (browser == "N" && version < 5) { ns = true; } else { ie = true; }
    ns6 = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
    var mainDate = new Date();
    mainDate.setDate(mainDate.getDate() - 2)
    for (i = 0; i <= 2; i++)
    {
        mainDate.setDate(mainDate.getDate() + 1)
        var MM = parseFloat(mainDate.getMonth()) + parseFloat(1)
        if (MM < 10) { MM = '0' + MM; }
        dd = mainDate.getDate();
        if (dd < 10) { dd = '0' + dd; }
        if (ns || ns6 || opera)
            var yyyy = mainDate.getYear() + 1900;
        else
            var yyyy = mainDate.getYear();
        date = dd + '.' + MM + '.' + yyyy;
        yyyy = String(yyyy).substring(2, 4);
        text = dd + '.' + MM + '.' + yyyy;
        document.getElementById('FliFo').options[document.getElementById('FliFo').options.length] = new Option(text, date);
    }
    document.getElementById('FliFo').options[1].selected = true;
}
function set_dates()
{
    Form = document.flightForm;
    dd = Form.date.options[Form.date.selectedIndex].value.substring(0, 2);
    MM = Form.date.options[Form.date.selectedIndex].value.substring(3, 5);
    yyyy = Form.date.options[Form.date.selectedIndex].value.substring(6, 10);
    Form.dd.value = dd;
    Form.MM.value = MM;
    Form.yyyy.value = yyyy;
}
function Flight_submit()
{
    Form = document.flightForm;
    var number = Form.flight_number.value;
    if (number.substring(0, 2) == 'LO' || number.substring(0, 2) == 'lo' || number.substring(0, 2) == 'Lo' || number.substring(0, 2) == 'lO')
        number = Form.flight_number.value.substring(2)
    if (isFinite(number) && number != '' && number.length > 0)
    {
        Form.flight_number.value = number;
        Form.submit()
    }
    else
    {
        document.getElementById('flight_number').className = "label error";
    }
}
function check_option()
{
    Form = document.mainForm;
    Form._cmd.value = 'Availability';
    Form.search_type.value = "Z";
    if (document.getElementById('way_single').className == 'sel' || document.getElementById('way_return').className == 'sel')
    {
        for (i = 0; i < Form.search_type_radio.length; i++)
        {
            if (Form.search_type_radio[i].value == "D" && Form.search_type_radio[i].checked == true)
            {
                Form._cmd.value = 'PoweredAvail';
                Form.view_type.value = 'schedule';
                Form.search_type.value = "D";
            }
            else if (Form.search_type_radio[i].value == "E" && Form.search_type_radio[i].checked == true)
            {
                Form._cmd.value = 'Calendar';
                Form.search_type.value = "E";
            }
            else if (Form.search_type_radio[i].value == "S" && Form.search_type_radio[i].checked == true)
            {
                Form._cmd.value = 'PoweredAvail';
                Form.search_type.value = "S";
            }
        }
    }
    if (Form.elements['flight-type'].value == 'single')
    {
        Form._car.value = false;
        try
        {
            Form.dcoc.disabled = true;
            Form.dage.disabled = true;
        } catch (e) { }
    }
    else if (Form.allow_car.value == 'true')
    {
        Form._car.value = true;
        try
        {
            Form.dcoc.disabled = false;
            Form.dage.disabled = false;
        } catch (e) { }
    }
    if (Form._car.value && Form.paxADT.value < 1)
    {
        Form._car.value = false;
        try
        {
            Form.dcoc.disabled = true;
            Form.dage.disabled = true;
        } catch (e) { }
    }
    try
    {
        var fromDate = new Date();
        fromDate = fromDate.setFullYear(Form.outdateyyyy.value, parseFloat(Form.outdateMM.value) - 1, Form.outdatedd.value);
        var toDate = new Date();
        toDate = toDate.setFullYear(Form.retdateyyyy.value, parseFloat(Form.retdateMM.value) - 1, Form.retdatedd.value);
        if (((Math.round((toDate - fromDate) / (24 * 60 * 60 * 1000)) * 1) > 30) && Form.elements['flight-type'].value == 'return')
        {
            Form._ins.value = false;
        }
        else if (Form.allow_ins.value == "true")
        {
            Form._ins.value = true;
        }
    }
    catch (e) { }
}
function hide_return()
{
    Form = document.mainForm;
    var search = false;
    for (i = 0; i < Form.search_type.length; i++)
    {
        if (Form.search_type.value == "Z")
            search = true;
    }
    if (search)
    {
        Form.retdatedd.disabled = true;
        Form.retDateMonthYear.disabled = true;
        Form.retDateDayName.disabled = true;
        document.getElementById('promo_code_span').style.display = "none";
        document.getElementById('promo_code_text').style.display = "none";
        document.getElementById('promo_code_input').disabled = true;
        Form.elements['flight-type'].value = 'single';
        Form.retdatedd.disabled = true;
        Form.retDateMonthYear.disabled = true;
        Form.retDateDayName.disabled = true;
    }
    else
    {
        document.getElementById('promo_code_input').disabled = false;
        document.getElementById('promo_code_span').style.display = "block";
        document.getElementById('promo_code_text').style.display = "block";
        Form.elements['flight-type'].value == 'return';
        Form.retdatedd.disabled = false;
        Form.retDateMonthYear.disabled = false;
        Form.retDateDayName.disabled = false;
    }
}
function submit()
{
    Form = document.mainForm;
    var ISOoutDate = "" + Form.outdateyyyy.value + Form.outdateMM.value + Form.outdatedd.value + "";
    var ISOretDate = "" + Form.retdateyyyy.value + Form.retdateMM.value + Form.retdatedd.value + "";
    search_option = false;
    for (i = 0; i < Form.search_type.length; i++)
    {
        if (Form.search_type.value == 'Z')
            search_option = true;
    }
    if (Form.elements['flight-type'].value == 'single' || search_option)
        ISOretDate = 99999999;
    for (i = 1; i < 9; i++)
    {
        try { document.getElementById('err' + i).style.display = "none"; } catch (e) { }
    }
    if (parseFloat(ISOoutDate) <= parseFloat(ISOretDate))
    {
        if (Form.origin.value == Form.destination.value)
        {
            document.getElementById('err6').style.display = "block";
        }
        else if (Form._cid.value == '')
        {
            document.getElementById('err4').style.display = "block";
        }
        else if (document.getElementById('promo_code_input').value.substring(0, 4).toUpperCase() == 'INTE' && Form._cid.value != '1010')
        {
            document.getElementById('err7').style.display = "block";
        }
        else if (document.getElementById('promo_code_input').value.substring(0, 4).toUpperCase() == 'INTE' && ((parseFloat(Form.paxADT.value) + parseFloat(Form.paxSRC.value) + parseFloat(Form.paxCHD.value) + parseFloat(Form.paxINF.value)) > 1))
        {
            document.getElementById('err8').style.display = "block";
        }
        else
        {
            if (Form.elements['flight-type'].value == 'single')
            { submit_data(); }
            Form.submit();
            document.getElementById('content').style.display = 'none';
            document.getElementById('refresh').style.display = 'block';
        }
    }
    else
    {
        document.getElementById('err5').style.display = "block";
    }
}
function set_month_year()
{
    Form = document.mainForm;
    try
    {
        Form.retdateMM.value = document.mainForm.elements['retDateMonthYear'].value.substring(0, 2)
        Form.retdateyyyy.value = document.mainForm.elements['retDateMonthYear'].value.substring(3, 7)
    }
    catch (e) { }
    Form.outdateMM.value = Form.elements['depDateMonthYear'].value.substring(0, 2)
    Form.outdateyyyy.value = Form.elements['depDateMonthYear'].value.substring(3, 7)

    var cookie_string = "search_option=" + Form.search_type.value + "||";
    var formTable = ['outdatedd', 'outdateMM', 'outdateyyyy', 'depDateMonthYear', 'retdatedd', 'retdateMM', 'retdateyyyy', 'retDateMonthYear', 'flight-type', 'origin', 'destination'];
    for (i = 0; i < formTable.length; i++)
    {
        cookie_string += formTable[i] + "=" + Form.elements[formTable[i]].value + "||";
    }
    cookie_string += "paxADT=" + Form.elements['paxADT'].selectedIndex + "||";
    cookie_string += "paxCHD=" + Form.elements['paxCHD'].selectedIndex + "||";
    cookie_string += "paxSRC=" + Form.elements['paxSRC'].selectedIndex + "||";
    cookie_string += "paxINF=" + Form.elements['paxINF'].selectedIndex + "||";
    cookie_string += "cabinClass=" + Form.cabinClass.options[Form.cabinClass.selectedIndex].value + "||";
    eraseCookie("StartFlightValue");
    createCookie("StartFlightValue", cookie_string);
    eraseCookie("StartType");
    createCookie("StartType", "plane");
}
function submit_data()
{
    Form = document.mainForm;
    Form.retdatedd.disabled = false;
    Form["retdatedd"].value = Form["outdatedd"].value;
    Form["retdateMM"].value = Form["outdateMM"].value;
    Form["retdateyyyy"].value = Form["outdateyyyy"].value;
}
function set_default_data()
{
    Form = document.mainForm;
    var cookie_string = readCookie("StartFlightValue");
    var cookie_tbl = new Array();
    var day_dep = '';
    var day_ret = '';
    if (cookie_string)
    {
        cookie_tbl = cookie_string.split("||");
        for (i = 1; i < cookie_tbl.length - 1; i++)
        {
            cookie_tbl[i] = cookie_tbl[i].split("=");
            if (cookie_tbl[i][0] == "flight-type" && cookie_tbl[0][1] != 'Z')
            {
                choice_way(cookie_tbl[i][1]);
            }
            else if (cookie_tbl[i][0] == "flight-type" && cookie_tbl[0][1] == 'Z')
            {
                choice_way('return');
            }
            if (cookie_tbl[i][0] == "outdatedd")
            {
                set_select("mainForm", cookie_tbl[i][0], cookie_tbl[i][1]);
                day_dep = cookie_tbl[i][1];
            }
            else if (cookie_tbl[i][0] == "retdatedd")
            {
                set_select("mainForm", cookie_tbl[i][0], cookie_tbl[i][1]);
                day_ret = cookie_tbl[i][1];
            }
            else if (cookie_tbl[i][0] == "depDateMonthYear")
            {
                set_select("mainForm", cookie_tbl[i][0], cookie_tbl[i][1]);
                makeDayOptions(day_dep, cookie_tbl[i][1].substring(0, 2), cookie_tbl[i][1].substring(3, 7), "mainForm", "outdatedd")
            }
            else if (cookie_tbl[i][0] == "retDateMonthYear")
            {
                set_select("mainForm", cookie_tbl[i][0], cookie_tbl[i][1]);
                makeDayOptions(day_ret, cookie_tbl[i][1].substring(0, 2), cookie_tbl[i][1].substring(3, 7), "mainForm", "retdatedd")
            }
            else if (cookie_tbl[i][0] == "planOption")
            {

            }
            else
            {
                document.mainForm.elements[cookie_tbl[i][0]].value = cookie_tbl[i][1];
            }
            if (cookie_tbl[i][0] == "origin")
            {
                checkData(document.getElementById('OriginList'), document.getElementById('DestinationList'));
                //PopulateDropDown('DestinationList', '' ,document.getElementById('OriginList').options[document.getElementById('OriginList').selectedIndex].value);
            }
        }
    }
    Form.outdateMM.value = Form.elements['depDateMonthYear'].value.substring(0, 2)
    Form.outdateyyyy.value = Form.elements['depDateMonthYear'].value.substring(3, 7)
    Form.retdateMM.value = Form.elements['retDateMonthYear'].value.substring(0, 2)
    Form.retdateyyyy.value = Form.elements['retDateMonthYear'].value.substring(3, 7)
    var cookie_string = readCookie("anxstart_car_value");
    var cookie_tbl = new Array();
    if (cookie_string)
    {
        cookie_tbl = cookie_string.split("||");
        for (i = 0; i < cookie_tbl.length - 1; i++)
        {
            cookie_tbl[i] = cookie_tbl[i].split("=");
            if (cookie_tbl[i][0] == "outdatedd")
            {
                set_select("carForm", cookie_tbl[i][0], cookie_tbl[i][1]);
                day_dep = cookie_tbl[i][1];
            }
            else if (cookie_tbl[i][0] == "retdatedd")
            {
                set_select("carForm", cookie_tbl[i][0], cookie_tbl[i][1]);
                day_ret = cookie_tbl[i][1];
            }
            else if (cookie_tbl[i][0] == "depDateMonthYear")
            {
                set_select("carForm", cookie_tbl[i][0], cookie_tbl[i][1]);
                makeDayOptions(day_dep, cookie_tbl[i][1].substring(0, 2), cookie_tbl[i][1].substring(3, 7), "carForm", "outdatedd")
            }
            else if (cookie_tbl[i][0] == "retDateMonthYear")
            {
                set_select("carForm", cookie_tbl[i][0], cookie_tbl[i][1]);
                makeDayOptions(day_ret, cookie_tbl[i][1].substring(0, 2), cookie_tbl[i][1].substring(3, 7), "carForm", "retdatedd")
            }
            else
            {
                document.carForm.elements[cookie_tbl[i][0]].value = cookie_tbl[i][1];
            }
        }
    }
    Form.retdatedd.disabled = false;
    Form.retDateMonthYear.disabled = false;
    Form.retDateDayName.disabled = false;
    generate_lang_list();
}
function set_select(form, name, value)
{
    for (j = 0; j < document.forms[form].elements[name].length; j++)
    {
        if (document.forms[form].elements[name].options[j].value == value)
            document.forms[form].elements[name].options[j].selected = true;
    }
}
function date_root(which, form)
{
    var date = new Date();
    date.setYear(nowYear);
    date.setMonth(nowMonth - 1);
    date.setDate(nowDay);
    if (which == 'out')
        date.setDate(date.getDate() + 10);
    if (which == 'ret')
        date.setDate(date.getDate() + 20);
    dd = date.getDate();
    MM = date.getMonth() + 1;
    yyyy = date.getYear();
    if (yyyy < 1900)
        yyyy += 1900;

    dd = parseFloat(dd)
    MM = parseFloat(MM)
    yyyy = parseFloat(yyyy)
    if (which == 'out')
    {
        makeYearMonthOptions(form, 'depDateMonthYear', MM, yyyy);
        makeDayOptions(dd, MM, yyyy, form, 'outdatedd');
    }
    if (which == 'ret')
    {
        makeYearMonthOptions(form, 'retDateMonthYear', MM, yyyy);
        makeDayOptions(dd, MM, yyyy, form, 'retdatedd');
        setNewDates('depDateMonthYear', 'out', form);
        setNewDates('retDateMonthYear', 'ret', form);
    }
}
function setNewDates(optionMonthYear, hidden, form)
{
    try
    {
        var newDateString = document.forms[form].elements[optionMonthYear][document.forms[form].elements[optionMonthYear].selectedIndex].value;
        document.forms[form].elements[hidden + 'dateMM'].value = newDateString.substring(0, 2);
        document.forms[form].elements[hidden + 'dateyyyy'].value = newDateString.substring(3, 7);
    }
    catch (e) { }
}
// insurance Stand Alone
function PopulateCountryList(dropdownID, country_name)
{
    // country_name= Array("PL","Polska","IT","W�ochy");
    currentMarket = document.forms['insForm'].elements['dcoc'].value; // current market is default selected country for insurances
    ddCountry = document.getElementById(dropdownID);
    for (i = 0; i < country_name.length; i += 2)
    {
        ddCountry.options[i / 2] = new Option(country_name[i + 1] + ' [' + country_name[i] + ']', country_name[i]);
        if (country_name[i] == currentMarket)
        {
            ddCountry.options[i / 2].selected = true;
        }
    }
    return true;
}
function set_insurance_data()
{
    Form = document.forms['insForm'];

    Form.insStartDate.value = Form.InsuranceDateFromDay.value + '.' + Form.InsuranceDateFromMonthYear.value;
    Form.insEndDate.value = Form.InsuranceDateToDay.value + '.' + Form.InsuranceDateToMonthYear.value;

    var ISOStartDate = "" + Form.InsuranceDateFromMonthYear.value.substring(3, 7) + Form.InsuranceDateFromMonthYear.value.substring(0, 2) + Form.InsuranceDateFromDay.value + "";
    var ISOEndDate = "" + Form.InsuranceDateToMonthYear.value.substring(3, 7) + Form.InsuranceDateToMonthYear.value.substring(0, 2) + Form.InsuranceDateToDay.value + "";
    
    var cookie_string = "";
    var formTable = ['InsuranceDateFromDay', 'InsuranceDateToDay', 'InsuranceDateFromMonthYear', 'InsuranceDateToMonthYear', 'depCountryList', 'retCountryList'];

    for (i = 0; i < formTable.length; i++)
    {
        cookie_string += formTable[i] + "=" + Form.elements[formTable[i]].value + "||";
    }
    eraseCookie("anxstart_ins_value");
    createCookie("anxstart_ins_value", cookie_string);
    eraseCookie("StartType");
    createCookie("StartType", "ins");

    document.getElementById('insDateError').style.display = "none";

    if (parseFloat(ISOStartDate) > parseFloat(ISOEndDate))
    {
        document.getElementById('insDateError').style.display = "block";
        return false;
    }
    
    ShowLoader();
    InsuranceSaveDataToCookie();
    document.forms['insForm'].submit();
}

/* ------------  HOTEL ---------  */
function choose_room(id, form)
{
    document.getElementById('hotel_err').style.display = 'none';
    document.getElementById('hotel_room_err').style.display = 'none';
    document.getElementById('hotelCHDageLabel').style.display = 'none';
    document.getElementById('hotelCHDage').style.display = 'none';

    if (document.getElementById('hotel_paxCHD').options[document.getElementById('hotel_paxCHD').selectedIndex].value == 1)
    {
        if (document.getElementById('room_1').value > 0 || document.getElementById('room_2').value > 1)
        {
            document.getElementById('hotel_err').style.display = 'block';
        }
        document.getElementById('room_1').value = 0;
        document.getElementById('room_2').value = 1;
        document.getElementById('hotelCHDageLabel').style.display = 'block';
        document.getElementById('hotelCHDage').style.display = 'block';
    }
    if (document.getElementById('room_1').options[document.getElementById('room_1').selectedIndex].value == 0 && document.getElementById('room_2').options[document.getElementById('room_2').selectedIndex].value == 0)
    {
        document.getElementById('hotel_room_err').style.display = 'block';
        document.getElementById(id).selectedIndex = 1;
    }
    document.getElementById('hotel_paxADT').value = parseFloat(document.getElementById('room_1').options[document.getElementById('room_1').selectedIndex].value) + parseFloat(2 * document.getElementById('room_1').options[document.getElementById('room_2').selectedIndex].value);
}
function hotel_submit(form, form2)
{
    var valid = true;
    if (document.forms[form].paxCHD.value > 0)
    {
        document.forms[form2].r1.value = 'DRP1';
        document.forms[form2].r2.value = '';

    }
    else if (document.forms[form].room_1.value > 0 && document.forms[form].room_2.value > 0)
    {
        document.forms[form2].r1.value = 'SR' + document.forms[form].room_1.value;
        document.forms[form2].r2.value = 'DR' + document.forms[form].room_2.value;

    }
    else if (document.forms[form].room_1.value > 0 && document.forms[form].room_2.value == 0)
    {
        document.forms[form2].r1.value = 'SR' + document.forms[form].room_1.value;
        document.forms[form2].r2.value = '';

    }
    else if (document.forms[form].room_1.value == 0 && document.forms[form].room_2.value > 0)
    {
        document.forms[form2].r1.value = 'DR' + document.forms[form].room_2.value;
        document.forms[form2].r2.value = '';
    }

    document.forms[form2].cin.value = document.forms[form].outdatedd.value + '.' + document.forms[form].depDateMonthYear.value;
    document.forms[form2].cout.value = document.forms[form].retdatedd.value + '.' + document.forms[form].retDateMonthYear.value;
    document.forms[form2].CHDAGE.value = document.forms[form].CHDAGE.value;
    document.forms[form2].cat.value = document.forms[form].cat.value;
    document.forms[form2].tlc.value = document.forms[form].tlcFormSSIM.value;
    if (document.getElementById('hotelFreeFlowTextRadio').checked == true)
    {
        document.forms[form2].hotelFreeFlowText.value = document.forms[form].hotelFreeFlowText.value;
    }
    else
    {
        document.forms[form2].hotelFreeFlowText.value = '';
    }
    
    Form = document.forms[form];

    var ISOStartDate = "" + Form.depDateMonthYear.value.substring(3, 7) + Form.depDateMonthYear.value.substring(0, 2) + Form.outdatedd.value + "";
    var ISOEndDate = "" + Form.retDateMonthYear.value.substring(3, 7) + Form.retDateMonthYear.value.substring(0, 2) + Form.retdatedd.value + "";

    if (Form.hotelFreeFlowText.value != '' || document.getElementById('tlcRadio').checked == true)
    {
        document.getElementById('hotelDestinationError').style.display = "none";
    }
    else
    {
        valid = false;
        document.getElementById('hotelDestinationError').style.display = "block";
    }

    if (parseFloat(ISOStartDate) < parseFloat(ISOEndDate))
    {
        document.getElementById('hotelDateError').style.display = "none";
    }
    else
    {
        valid = false;
        document.getElementById('hotelDateError').style.display = "block";
    }

    if (valid)
    {
        document.forms[form2].submit()
    }

    var cookie_string = "";
    var formTable = ['hotelFreeFlowTextRadio', 'tlcRadio', 'tlcFormSSIM', 'outdatedd', 'depDateMonthYear', 'retdatedd', 'retDateMonthYear', 'room_1','room_2', 'hotel_paxADT', 'hotel_paxCHD', 'hotel_cat'];
    
    for (i = 0; i < formTable.length; i++)
    {
        cookie_string += formTable[i] + "=" + Form.elements[formTable[i]].value + "||";
    }
    
    eraseCookie("StartHotelValue");
    createCookie("StartHotelValue", cookie_string);
    eraseCookie("StartType");
    createCookie("StartType", "hotel");
}
