$(function(){
    $('#VacanzeLat-Destination').autocomplete("http://www.europelowcost.fr/lowcostplanet/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'destinations', languageId: 'fr'} });
    $('#VoliLat-DepartCity').autocomplete("http://www.europelowcost.fr/lowcostplanet/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'airports', languageId: 'fr', addCountry: 'true'} });
    $('#VoliLat-ArrivalCity').autocomplete("http://www.europelowcost.fr/lowcostplanet/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'airports_and_cities', languageId: 'fr', addCountry: 'true' }, onItemSelect: function (li) { $('#VoliLat-ArrivalCity_SelectedValue').val(li.extra[0]); } });
    $('#HotelLat-destination').autocomplete("http://www.europelowcost.fr/lowcostplanet/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'cities', languageId: 'fr'} });
    $('#VoliHotelLat-DepartCity').autocomplete("http://www.europelowcost.fr/lowcostplanet/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'airports', languageId: 'fr', addCountry: 'true'} });
    $('#VoliHotelLat-ArrivalCity').autocomplete("http://www.europelowcost.fr/lowcostplanet/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'airports', languageId: 'fr', addCountry: 'true'} });
    $('#OstelliLat-destination').autocomplete("http://www.europelowcost.fr/lowcostplanet/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'cities', languageId: 'fr'} });
    $('#Lat-PickUpLocation').autocomplete("http://www.europelowcost.fr/lowcostplanet/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'airports_no_multiple', languageId: 'fr', addCountry: 'true'} });
});

$(function() {
	$("#DepartDate").datepicker({showOn: 'both',buttonText: unescape("S%E1lectionner une date"), 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['fr']);
    $("#ReturnDate").datepicker({ showOn: 'both', buttonText: unescape("S%E1lectionner une date"), buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
    $("#ReturnDate").datepicker($.datepicker.regional['fr']);
});

$(function() {
    $("#Date12").datepicker({ showOn: 'both', buttonText: unescape("S%E1lectionner une date"), buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date(), onSelect: function (dateText, inst) {
        var dateMin = $.datepicker.parseDate('dd/mm/yy', dateText);
        dateMin.setDate(dateMin.getDate() + 1);
		$('#Date20').datepicker('option', 'minDate', dateMin);
	} });
	$("#Date12").datepicker($.datepicker.regional['fr']);
	$("#Date20").datepicker({ showOn: 'both', buttonText: unescape("S%E1lectionner une date"), buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
	$("#Date20").datepicker($.datepicker.regional['fr']);
});

$(function () {
    $("#Date2").datepicker({ showOn: 'both', buttonText: unescape("S%E1lectionner une date"), buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date(), onSelect: function (dateText, inst) {
        var dateMin = $.datepicker.parseDate('dd/mm/yy', dateText);
        dateMin.setDate(dateMin.getDate() + 1);
        $('#Date3').datepicker('option', 'minDate', dateMin);
    } 
    });
    $("#Date2").datepicker($.datepicker.regional['fr']);
    $("#Date3").datepicker({ showOn: 'both', buttonText: unescape("S%E1lectionner une date"), buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
    $("#Date3").datepicker($.datepicker.regional['fr']);
});

$(function() {
    $("#DepartDate2").datepicker({ showOn: 'both', buttonText: unescape("S%E1lectionner une date"), buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date(), onSelect: function (dateText, inst) {
        var dateMin = $.datepicker.parseDate('dd/mm/yy', dateText);
        dateMin.setDate(dateMin.getDate() + 1);
		$('#ReturnDate2').datepicker('option', 'minDate', dateMin);
	} });
	$("#DepartDate2").datepicker($.datepicker.regional['fr']);
});

$(function() {
	$("#ReturnDate2").datepicker({showOn: 'both',buttonText: unescape("S%E1lectionner une date"), buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date()});
	$("#ReturnDate2").datepicker($.datepicker.regional['fr']);
});	

$(function() {
	$("#CheckInDate").datepicker({showOn: 'both',buttonText: unescape("S%E1lectionner une date"), buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date()});
	$("#CheckInDate").datepicker($.datepicker.regional['fr']);
});

$(function() {
	$("#DepartDate5").datepicker({showOn: 'both',buttonText: unescape("S%E1lectionner une date"), 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['fr']);
	$("#DepartDate7").datepicker({ showOn: 'both', buttonText: unescape("S%E1lectionner une date"), buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
	$("#DepartDate7").datepicker($.datepicker.regional['fr']);
});

$(function() {
	$("#PickUpDate").datepicker({showOn: 'both',buttonText: unescape("S%E1lectionner une date"), 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['fr']);
	$("#DropOffDate").datepicker({ showOn: 'both', buttonText: unescape("S%E1lectionner une date"), buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
	$("#DropOffDate").datepicker($.datepicker.regional['fr']);
});

$(function(){
	$('#ELCFlightsForm').submit(function(){
		var width = screen.availWidth / 2;
		var height = screen.availHeight;
		if($('input[name=chkHotel]').val() == 'yes') {
		    var hotelStr = 'http://www.europelowcost.fr/hotels/offres-hotels.aspx?cityid=' + $('#VoliLat-ArrivalCity_SelectedValue').val() + ($('#DepartDate').val() != '' ? '&Date1=' + $('#DepartDate').val() : '') + ($('#ReturnDate').val() != '' ? '&Date2=' + $('#ReturnDate').val() : '') + '&rooms=1&Adults=' + $('#Adults').val() + '&chields=0&partnerCode=' + $('#partnerCode').val() + '&subCode=' + $('#subCode').val() + '&lang=fr';
			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.fr/voitures/offres-location-voitures.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=fr';
				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: unescape("S%E1lectionner une date"), 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['fr']);
    $('#txt_return_date').datepicker({ showOn: 'both', buttonText: unescape("S%E1lectionner une date"), buttonImage: 'http://www.europelowcost.com/images/calendar.gif', buttonImageOnly: true, numberOfMonths: 2, showButtonPanel: true, minDate: new Date() });
    $('#txt_return_date').datepicker($.datepicker.regional['fr']);
});
$(function () {
    $('#txt_depart').blur(function () {
        if ($(this).val().length == 0) {
            $('#depart_code').val('');
            $(this).val('Partout');
        }
    }).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: 'http://www.europelowcost.fr/lowcostplanet/wsexportdata/getsuggest.aspx?q=' + selCo + '&limit=50&languageId=fr&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: 'http://www.europelowcost.fr/lowcostplanet/wsexportdata/getsuggest.aspx?q=' + selCn + '&limit=50&languageId=fr&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');
        }
    });
});

function populateContinents () {
    $.ajax({
        url: 'http://www.europelowcost.fr/lowcostplanet/wsexportdata/getsuggest.aspx?q=&limit=10&languageId=fr&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("http://www.europelowcost.fr/lowcostplanet/wsexportdata/getsuggest.aspx", { delay: 20, minChars: 3, matchContains: true, maxItemsToShow: 100, extraParams: { data_type: 'airports_and_countries', languageId: 'fr' }, onItemSelect: function (li) { $('#depart_code').val(li.extra[0]); } });
}

$(function () {
    $('.airlinedetailsjt').live('click', function () {
        var airline = $(this).html();
        var offset = $(this).offset();
        $.ajax({
            type: 'GET',
            url: 'http://www.europelowcost.fr/flights_pages/flights_serp_airline_details.aspx?lang=fr&airline=' + airline,
            success: function (data) {
                $('#detailsBackground').show();
                var offset_window = offset.top;
                if ((offset_window + 200) > $(document).height()) {
                    offset_window = offset.top - 200;
                }
                $('#detailsPanel').empty().html(data).css('margin-top', offset_window).css('left', '30%').fadeIn(1500);
            }
        });
    });
    $('.jtdetails').live('click', function () {
        var fid = $(this).parents('.extra-info').find('input.fid').val();
        var offset = $(this).offset();
        $.ajax({
            type: 'GET',
            url: 'http://www.europelowcost.fr/flights_pages/flights_serp_details.aspx?lang=fr&f=' + fid,
            success: function (data) {
                $('#detailsBackground').show();
                var offset_window = offset.top;
                if ((offset_window + 300) > $(document).height()) {
                    offset_window = offset.top - 300;
                }
                $('#detailsPanel').empty().html(data).css('margin-top', offset_window).css('left', '30%').fadeIn(1500);
            }
        });
    });
    $('.jtemail').live('click', function () {
        var fid = $(this).parents('.extra-info').find('input.fid').val();
        var pcode = $('#results_pCode').val();
        var scode = $('#results_sCode').val();
        var link = 'http://www.europelowcost.fr/flights_pages/flights_serp_send_offers.aspx?lang=fr&f=' + fid + '&partnerCode=' + pcode + '&subCode=' + scode;

        window.open(link, 'Mail', 'width=650,height=330,status,location');
    });
});

var addthis_config = {
    ui_language: "fr",
    ui_cobrand: "Europelowcost"
}
