$(function () {
    $('#VacanzeLat-Destination').autocomplete("/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'destinations', languageId: 'es'} });
    $('#VoliLat-DepartCity').autocomplete("/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'airports', languageId: 'es', addCountry: 'true'} });
    $('#VoliLat-ArrivalCity').autocomplete("/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'airports_and_cities', languageId: 'es', addCountry: 'true' }, onItemSelect: function (li) { $('#VoliLat-ArrivalCity_SelectedValue').val(li.extra[0]); } });
    $('#HotelLat-destination').autocomplete("/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'cities', languageId: 'es'} });
    $('#VoliHotelLat-DepartCity').autocomplete("/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'airports', languageId: 'es', addCountry: 'true'} });
    $('#VoliHotelLat-ArrivalCity').autocomplete("/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'airports', languageId: 'es', addCountry: 'true'} });
    $('#OstelliLat-destination').autocomplete("/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'cities', languageId: 'es'} });
    $('#Lat-PickUpLocation').autocomplete("/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'airports_no_multiple', languageId: 'es', addCountry: 'true'} });
});

$(function () {
    $("#DepartDate").datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date(), onSelect: function (dateText, inst) {
        $('#ReturnDate').datepicker('option', 'minDate', $.datepicker.parseDate('dd/mm/yy', dateText));
    } 
    });
    $('#DepartDate').datepicker($.datepicker.regional['es']);
});

$(function () {
    $("#ReturnDate").datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
    $("#ReturnDate").datepicker($.datepicker.regional['es']);
});


$(function () {
    $("#Date20").datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
    $("#Date20").datepicker($.datepicker.regional['es']);
});

$(function () {
    $("#Date12").datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date(), onSelect: function (dateText, inst) {
        $('#Date20').datepicker('option', 'minDate', $.datepicker.parseDate('dd/mm/yy', dateText));
    } 
    });
    $("#Date12").datepicker($.datepicker.regional['es']);
});

$(function () {
    $("#DepartDate2").datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date(), onSelect: function (dateText, inst) {
        $('#ReturnDate2').datepicker('option', 'minDate', $.datepicker.parseDate('dd/mm/yy', dateText));
    } 
    });
    $("#DepartDate2").datepicker($.datepicker.regional['es']);
});

$(function () {
    $("#ReturnDate2").datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
    $("#ReturnDate2").datepicker($.datepicker.regional['es']);
});

$(function () {
    $("#CheckInDate").datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
    $("#CheckInDate").datepicker($.datepicker.regional['es']);
});

$(function () {
    $("#DepartDate5").datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date(), onSelect: function (dateText, inst) {
        $('#DepartDate7').datepicker('option', 'minDate', $.datepicker.parseDate('dd/mm/yy', dateText));
    } 
    });
    $("#DepartDate5").datepicker($.datepicker.regional['es']);
});

$(function () {
    $("#DepartDate7").datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
    $("#DepartDate7").datepicker($.datepicker.regional['es']);
});

$(function () {
    $("#PickUpDate").datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date(), onSelect: function (dateText, inst) {
        $('#DropOffDate').datepicker('option', 'minDate', $.datepicker.parseDate('dd/mm/yy', dateText));
    } 
    });
    $("#PickUpDate").datepicker($.datepicker.regional['es']);
});

$(function () {
    $("#DropOffDate").datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
    $("#DropOffDate").datepicker($.datepicker.regional['es']);
});

$(function () {
    $("#DropOffDate").datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
    $("#DropOffDate").datepicker($.datepicker.regional['en-GB']);
});

$(function () {
    $('#ELCFlightsForm').submit(function () {
        var width = screen.availWidth / 2;
        var height = screen.availHeight;
        if ($('input[name=chkHotel]').val() == 'yes') {
            var hotelStr = 'http://www.europelowcost.es/searchalso.aspx?u=http://compara.europelowcost.com/Hotels/Request.aspx?cityid=' + $('#VoliLat-ArrivalCity_SelectedValue').val() + ($('#DepartDate').val() != '' ? '&Date1=' + $('#DepartDate').val() : '') + ($('#ReturnDate').val() != '' ? '&Date2=' + $('#ReturnDate').val() : '') + '&rooms=' + $('#rooms').val() + '&adults=' + $('#adults').val() + '&chields=0&partnerCode=' + $('#partnerCode').val() + '&subCode=' + $('#subCode').val() + '&lang=es';
            hpage = window.open(hotelStr, '', 'status=yes,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,directories=yes,resizable=yes,height=' + height + ',width=' + width);
            hpage.moveTo(0, 0);
            setTimeout(function () { hpage.blur(); this.window.focus(); }, 500);
        }
        if ($('input[name=chkCar]').val() == 'yes') {
            if (!/\([\s\S]*? - (Tutti\s|All\s|Todos\s|Tous\s|Alle\s)[\s\S]*?\)/.test($('#VoliLat-ArrivalCity').val())) {
                var carStr = 'http://www.europelowcost.es/searchalso.aspx?u=http://compara.europelowcost.com/Cars/Request.aspx?PickUpLocation=' + $('#VoliLat-ArrivalCity').val() + '&DriverAge=30&PickUpTime=10AM' + ($('#DepartDate').val() != '' ? '&PickUpDate=' + $('#DepartDate').val() : '') + '&DropOffTime=10AM' + ($('#ReturnDate').val() != '' ? '&DropOffDate=' + $('#ReturnDate').val() : '') + '&partnerCode=' + $('#partnerCode').val() + '&subCode=' + $('#subCode').val() + '&lang=es';
                cpage = window.open(carStr, '', 'status=yes,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,directories=yes,resizable=yes,height=' + height + ',width=' + width);
                cpage.moveTo(width, 0);
                setTimeout(function () { cpage.blur(); this.window.focus(); }, 500);
            }
        }
        return true;
    });
});

$(function () {
    $('#txt_depart_date').datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date(),
        onSelect: function (dateText, inst) {
            $('#txt_return_date').datepicker('option', 'minDate', $.datepicker.parseDate('dd/mm/yy', dateText));
        }
    });
    $('#txt_depart_date').datepicker($.datepicker.regional['es']);
    $('#txt_return_date').datepicker({ showOn: 'both', buttonText: 'Selecciona la fecha', buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
    $('#txt_return_date').datepicker($.datepicker.regional['es']);
});
$(function () {
    $('#txt_depart').blur(function () {
        if ($(this).val().length == 0) {
            $('#depart_code').val('');
            $(this).val('Cualquier lugar');
        }
    }).click(function () {
        $(this).val('');
    });
});

$(function () {
    $('#chk_weekend').removeAttr('checked');
    $('#rbtn_months').attr('checked', 'checked');
    $('#ddl_months option:eq(0)').attr('selected', 'selected');
});

$(function () {
    $('#ddl_continent').change(function () {
        var selCo = $('#ddl_continent > option:selected').attr('value');
        if (selCo != '') {
            $.ajax({
                url: '/wsexportdata/getsuggest.aspx?q=' + selCo + '&limit=50&languageId=es&data_type=json_countries',
                type: 'GET',
                success: function (json) {
                    $('#ddl_country > option[value!=""]').remove();
                    var expression = '(' + json + ')';
                    var countries = eval(expression);
                    for (var cn in countries.country) {
                        $('#ddl_country').append('<option value="' + countries.country[cn].code + '">' + countries.country[cn].name + '</option>');
                    }
                    $('#ddl_country').removeAttr('disabled');
                    $('#ddl_city').attr('disabled', 'disabled');
                    $('#ddl_city option:eq(0)').attr('selected', 'selected');
                }
            });
        }
        else {
            $('#ddl_country').attr('disabled', 'disabled');
            $('#ddl_country option:eq(0)').attr('selected', 'selected');
            $('#ddl_city').attr('disabled', 'disabled');
            $('#ddl_city option:eq(0)').attr('selected', 'selected');
        }
    });
    $('#ddl_country').change(function () {
        var selCn = $('#ddl_country > option:selected').attr('value');
        if (selCn != '') {
            $.ajax({
                url: '/wsexportdata/getsuggest.aspx?q=' + selCn + '&limit=50&languageId=es&data_type=json_airports_countries',
                type: 'GET',
                success: function (json) {
                    $('#ddl_city > option[value!=""]').remove();
                    var expression = '(' + json + ')';
                    var airports = eval(expression);
                    for (var a in airports.airport) {
                        $('#ddl_city').append('<option value="' + airports.airport[a].code + '">' + airports.airport[a].name + '</option>');
                    }
                    $('#ddl_city').removeAttr('disabled');
                }
            });
        }
        else {
            $('#ddl_city').attr('disabled', 'disabled');
            $('#ddl_city option:eq(0)').attr('selected', 'selected');
        }
    });
});

$(document).ready(function () {
    $.ajax({
        url: '/wsexportdata/getsuggest.aspx?q=&limit=10&languageId=es&data_type=json_continents',
        type: 'GET',
        success: function (json) {
            var expression = '(' + json + ')';
            var continents = eval(expression);
            for (var c in continents.continent) {
                $('#ddl_continent').append('<option value="' + continents.continent[c].code + '">' + continents.continent[c].name + '</option>');
            }
        }
    });
    $('#txt_depart').autocomplete("/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'airports_and_countries', languageId: 'es' }, onItemSelect: function (li) { $('#depart_code').val(li.extra[0]); } });
});
