function moveArrow(where, who, motore) {
    $('.middle-inside', '.middle-gradient').css('display', 'none');
    $('#' + motore).css('display', '');
    $('li', '#menu-sezioni').each(function (i) {
        $(this).attr('id', $(this).attr('id').replace(/Sel/g, ''));
    });
    $('#' + who).attr('id', who + 'Sel');
}

function showMotoreMini(who, motore) {
    $('.middle-inside', '#motore-laterale').css('display', 'none');
    $('#' + motore).css('display', '');
    $('li', '#menu-motore-laterale').each(function (i) {
        $(this).attr('id', $(this).attr('id').replace(/Sel/g, ''));
    });
    $('#' + who).attr('id', who + 'Sel');
}

function selTab(counter, whichTab) {
    if (document.getElementById(whichTab)) {
        var toSel = document.getElementById(whichTab);
        //alert(toSel.style.backgroundPosition);
        toSel.className = 'sel';
        toSel.style.backgroundPosition = '0 0';

        var toShow = document.getElementById(whichTab + 'Content');
        toShow.style.display = '';
    }
    if (whichTab.indexOf('Top') > -1) {
        toSel.className = 'HdrTop sel';
        unSelTabTop(counter, whichTab);
    }
    else {
        unSelTab(counter, whichTab);
    }
}

function unSelTab(counter, whichTab) {
    for (i = 1; i <= counter; i++) {
        if (document.getElementById('tab' + i)) {
            var getIDTab = document.getElementById('tab' + i);
            var getIDTabToShow = document.getElementById('tab' + i + 'Content');

            if (getIDTab.id != whichTab) {
                getIDTab.className = 'unsel';
                getIDTab.style.backgroundPosition = '0 -29px';
            }
            if (getIDTabToShow.id != (whichTab + 'Content')) {
                getIDTabToShow.style.display = 'none';
            }
        }
    }
}

function unSelTabTop(counter, whichTab) {	
	for (i = 1; i <= counter; i++) {		
		if (document.getElementById('tab'+i+'Top')) {
			var getIDTab = document.getElementById('tab'+i+'Top');
			var getIDTabToShow = document.getElementById('tab'+i+'TopContent');
			
			if(getIDTab.id != whichTab) {
				getIDTab.className = 'HdrTop unsel';
				getIDTab.style.backgroundPosition = '0 -29px';
			}
			if(getIDTabToShow.id != (whichTab+'Content')) {
				getIDTabToShow.style.display = 'none';
			}
		}
	}
}

function SetupRoundTrip(inputDate) {
	var getDateReturn = document.getElementById(inputDate);
	getDateReturn.style.display = '';
}
	
function SetupOneWay(inputDate) {
	var getDateReturn = document.getElementById(inputDate);
	getDateReturn.style.display = 'none';		
}

$('.include-search').live('click',function(){
	if($(this).prev().hasClass('jqTransformChecked')) {
		$(this).val('no');
	}
	else {
		$(this).val('yes');
	}		
});

$(function(){
	$('#VacanzeLat-Destination').click(function(){ $(this).val(''); });	
	$('#VoliLat-DepartCity').click(function(){ $(this).val(''); });	
	$('#VoliLat-ArrivalCity').click(function(){ $(this).val(''); });		
	$('#HotelLat-destination').click(function(){ $(this).val(''); });	
	$('#VoliHotelLat-DepartCity').click(function(){ $(this).val(''); });
	$('#VoliHotelLat-ArrivalCity').click(function(){ $(this).val(''); });
	$('#OstelliLat-destination').click(function(){ $(this).val(''); });	
	$('#Lat-PickUpLocation').click(function(){ $(this).val(''); });
});

$(function(){
	$('#Leonardo_Navigation-Logo').html('<a title="Visita Leonardo.it" href="http://www.leonardo.it" target="_blank"><span>Leonardo.it</span></a>').css('background-image', 'url("http://www.europelowcost.com/images/LeonardoLogoGrey.png")');
});

$(function () {
    $('.ui-blue-icon').click(function () { $('#hp_more_parameters').click(); });
    $('#hp_more_parameters').click(function () {
        $('.ui-blue-icon').toggleClass('ui-icon-minusthick');
        $('.more-parameters').toggle();
        return false;
    });
});
$(function () {
    for (var i = 0; i < 5; i++) {
        var date = new Date();
        var month = i + date.getMonth();
        var year = date.getFullYear();
        if (month >= 12) {
            month -= 12;
            year++;
        }
        date.setMonth(month);
        date.setFullYear(year);
        var value = (month < 10 ? '0' : '') + (month + 1) + '/' + year;
        var text = $.datepicker.formatDate('MM yy', date);
        $('#ddl_months').append('<option value="' + value + '">' + text + '</option>');
    }
    $('#rbtn_months').click(function () {
        $('.months').css('display', '');
        $('.days').css('display', 'none');
    });
    $('#rbtn_days').click(function () {
        $('.months').css('display', 'none');
        $('.days').css('display', '');
    });
    $('#ddl_months').change(function () {
        if ($(this).val() != "") {
            $('.weekends').show();
        }
        else {
            $('.weekends').hide();
            $('#chk_weekend').removeAttr('checked');
            $('.weekend-dates').hide();
        }
    });
    $('#chk_weekend').click(function () {
        if ($(this).is(':checked')) {
            $('.weekend-dates').show();
        }
        else {
            $('.weekend-dates').hide();
        }
    });
    $('#lbl_country_dep_trigger').live('click', function () {
        $('#pCountryDepHidden').slideToggle();
    });
    $('#lbl_country_arr_trigger').live('click', function () {
        $('#pCountryArrHidden').slideToggle();
    });
    $('.img-trigger').live('click', function () { $(this).next().click(); });
    $('.country-airports-trigger').live('click', function () {
        $(this).next().slideToggle('slow', function () {
            if ($(this).css('display') == 'none') {
                $(this).prev().prev().removeClass('ui-icon-circle-arrow-n');
            }
            else {
                $(this).prev().prev().addClass('ui-icon-circle-arrow-n');
            }
        });
    });
    $('.update-trigger').live('click', function () {
        $(this).parent().css('display', 'none').next().css('display', '');
    });
});
function airlineError(e) {
    e.src = 'http://www.europelowcost.com/images/no-airline.jpg';
}
function SelectText(element) {
    var text = document.getElementById(element);
    if ($.browser.msie) {
        var range = document.body.createTextRange();
        range.moveToElementText(text);
        range.select();
    } else if ($.browser.mozilla || $.browser.opera) {
        var selection = window.getSelection();
        var range = document.createRange();
        range.selectNodeContents(text);
        selection.removeAllRanges();
        selection.addRange(range);
    } else if ($.browser.safari) {
        var selection = window.getSelection();
        selection.setBaseAndExtent(text, 0, text, 1);
    }
}
$(function () {
    $('.expand-trace').click(function () {
        $(this).parents('.url-row').find('.value').toggleClass('compact');
    });
});
$(function () {
    $('.partner-trigger').live('click', function () {
        var options = {};
        $(this).parents('.wrapper').find('.more-partners').toggle('blind', options, 500);
        return false;
    });
    $('.img-partner-trigger').live('click', function () {
        $(this).prev().click();
    });
});
$(function () {
    $('.close', '#detailsPanel').live('click', function () {
        $(this).parents('#detailsPanel').empty();
        $('#detailsBackground').hide();
        return false;
    });
});
$(function () {
    $('#btn_stop_search').live('click', function () {
        clearTimeout(tmps);
    });
});
function scrollOrderBar(direction) {
    var ul = $('#filters-breadcrumb');
    var offset = parseInt($(ul).css('margin-left').replace('px', ''), 10);
    var add = 50;

    if (direction == 'next') {
        add *= -1;
    }
    if ($('li:last', ul).position().top == 0) {
        $('#order-next > img').attr('src', 'http://www.europelowcost.com/images/right-arrow-scroll-disabled.gif');
        if (direction == 'next') {
            return;
        }
        if (direction == 'prev' && ($('li:last', ul).position().left + add) > $('.filters-sel-container').width()) {
            $('#order-next > img').attr('src', 'http://www.europelowcost.com/images/right-arrow-scroll.gif');
        }
    }
    else {
        if ($('li:last', ul).position().left + add <= 0) {
            $('#order-next > img').attr('src', 'http://www.europelowcost.com/images/right-arrow-scroll-disabled.gif');
        }
        else {
            $('#order-next > img').attr('src', 'http://www.europelowcost.com/images/right-arrow-scroll.gif');
        }
    }
    if (offset == 0 || offset + add >= 0) {
        $('#order-prev > img').attr('src', 'http://www.europelowcost.com/images/left-arrow-scroll-disabled.gif');
        if (offset + add < 0 && direction == 'next') {
            $('#order-prev > img').attr('src', 'http://www.europelowcost.com/images/left-arrow-scroll.gif');
        }
        if (offset == 0 && direction == 'prev') {
            return;
        }
        if (offset > 0 || offset + add > 0) {
            $(ul).css('margin-left', '0px');
            return;
        }
    }
    else {
        $('#order-prev > img').attr('src', 'http://www.europelowcost.com/images/left-arrow-scroll.gif');
    }
    offset += add;
    $(ul).animate({ marginLeft: offset });
}

function PriceFilter() {
    var stepValue = 10;
    var minPrice = $("#minprice_hidden").val();
    var maxPrice = $("#maxprice_hidden").val();
    var selminPrice = $("#selminprice_hidden").val();
    var selmaxPrice = $("#selmaxprice_hidden").val();

    if (minPrice == undefined || maxPrice == undefined || selminPrice == undefined || selmaxPrice == undefined)
        return;


    $('#slider').slider({
        min: minPrice.length == 0 ? 0 : parseInt(minPrice, 10),
        max: maxPrice.length == 0 ? 1000 : parseInt(maxPrice, 10),
        values: [(selminPrice.length == 0 ? 250 : parseInt(selminPrice, 10)), (selmaxPrice.length == 0 ? 750 : parseInt(selmaxPrice, 10))],
        range: true,
        step: stepValue,
        slide: function (event, ui) {
            if (ui.values[1] - ui.values[0] < 10) {
                return false;
            }

            var tmpMin = GetMinPrice(parseInt(ui.values[0], 10), parseInt(minPrice, 10));
            var tmpMax = GetMaxPrice(parseInt(ui.values[1], 10), parseInt(maxPrice, 10));

            $("#selminprice_hidden").val(tmpMin);
            $("#selmaxprice_hidden").val(tmpMax);
            $("#lblminprice").text(tmpMin);
            $("#lblactualprice").text(tmpMax);
        },
        stop: function (event, ui) {

            var tmpMin = GetMinPrice(parseInt(ui.values[0], 10), parseInt(minPrice, 10));
            var tmpMax = GetMaxPrice(parseInt(ui.values[1], 10), parseInt(maxPrice, 10));

            $("#selminprice_hidden").val(tmpMin);
            $("#selmaxprice_hidden").val(tmpMax);
            $("#lblminprice").text(tmpMin);
            $("#lblactualprice").text(tmpMax);
            $("#isSelprice_hidden").val("true");
            WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$main_content$serp_filters$UC_sliderFilterPrice$filter_trigger", "", true, "", "", false, true));
        }
    });
}

function GetMaxPrice(sliderPrice, maxPrice) {
    var tmpMax = maxPrice < sliderPrice ? maxPrice : sliderPrice;
    tmpMax = (maxPrice - tmpMax) < 10 ? maxPrice : tmpMax;
    return tmpMax;
}

function GetMinPrice(sliderPrice, minPrice) {
    var tmpMin = minPrice > sliderPrice ? minPrice : sliderPrice;
    tmpMin = (tmpMin - minPrice) < 10 ? minPrice : tmpMin;
    return tmpMin;
}

$(function () {
    var parent = "#serp-search-box";
    var motori = $('.middle-inside', parent);
    $(motori).each(function (index, val) {
        SetSearchFormPost(index + 1);
    });
});



function SetSearchFormPost(idMotore) {
    var parent = '#motore' + idMotore;
    $('.btnGo', parent).click(function () {
        var form = $('#divForm form');
        var postBackUrl = $('#postBackUrl', parent).val();
        var arrInputs = $("input[type=text], input[type=hidden][name!='postBackUrl'], input[type=checkbox]:checked, input[type=radio]:checked, select", parent);
        $(arrInputs).each(function (index, value) {
            $(form).append('<input type="hidden" name="' + $(this).attr('name') + '" value="' + $(this).val() + '" />');
        });
        $(form).append('<input type="hidden" name="timestamp" value="' + new Date().getTime() + '" />');
        $(form).attr('action', postBackUrl);
        $(form).submit();
        return false;
    });
}

$(function () {
    $('#no-results-modify').live('click', function () {
        $('a.searchform').click();
        return false;
    });
});


function InitChart(currencyCode) {

    currencyCode = currencyCode == '' ? '\u20AC' : currencyCode;
    currencyCode = currencyCode == '€' ? '\u20AC' : currencyCode;
    currencyCode = currencyCode == '£' ? '\u00A3' : currencyCode;
    currencyCode = currencyCode == '$' ? '\u0024' : currencyCode;

    var options = {
        chart: {
            renderTo: 'graphic-container',
            defaultSeriesType: 'column',
            borderColor: '#AAAAAA',
            borderWidth: 1,
            spacingBottom: 5,
            spacingTop: 20
        },
        credits: {
            enabled: false
        },
        title: {
            text: '',
            style: {
                fontSize: '12px'
            }
        },
        xAxis: {
            categories: [],
            title: {
                text: ''
            },
            labels: {
                formatter: function () {
                    var splitted = this.value.split('-');
                    return splitted[0] + "<br/>" + splitted[1];
                }
            }
        },
        legend: {
            enabled: false
        },
        yAxis: {
            min: 0,
            title: {
                text: ''
            }
        },
        tooltip: {
            formatter: function () {
                var value = '<span style="font-size:13px;color:#4572A7;">' + this.point.da + ' - ' + this.point.aa + '</span> <span style="font-size:13px;color:#4572A7;font-weight:bold;">' + this.y + ' '  + currencyCode + '</span><br/>';
                value += '<span>' + this.point.gd + '</span> <span>' + this.point.gdt + ' \u203A\u203A ' + this.point.gat + '</span><br/>';
                value += '<span>' + this.point.rd + '</span> <span>' + this.point.rdt + ' \u203A\u203A ' + this.point.rat + '</span><br/>';
                value += '<span>' + this.point.an + '</span><br/>';
                value += '<span>' + this.point.of + '</span>';
                return value;
            },
            style: {
                fontSize: '11px'
            }
        },
        plotOptions: {
            series: {
                cursor: 'pointer',
                events: {
                    click: function (event) {
                        window.open(event.point.lb);
                    }
                }
            }
        },
        series: []
    };

    return options;
}
