﻿// START SLIDER - SEMPRE DOPO "GALLERY"
$(function () { 




 

    // START SLIDER - SEMPRE DOPO "GALLERY"        
    // CARICAMENTO VALORI INIZIALI SLIDER Prezzi    
    // mantenimento dei filtri dopo il back del browser
    var prezzoDa = $('#hdnPrezzoDa').val();
    var prezzoA = $('#hdnPrezzoA').val();
    if (prezzoDa == '0' && prezzoA == '1000000') {
        prezzoDa = arrLimitiFiltri[0];
        prezzoA = arrLimitiFiltri[1];
    }

    $("#amount1").html('<span>' + prezzoDa + ' €</span>');
    $("#amount2").html('<span>' + prezzoA + ' €</span>');

    //document.getElementById("hdnPrezzoDa").value = arrLimitiFiltri[0];
    //document.getElementById("hdnPrezzoA").value = arrLimitiFiltri[1];
    //Visualizzo lo slider solo se i limiti sono diversi
    if (arrLimitiFiltri[0] != arrLimitiFiltri[1]) {

        $("#slider-range").slider({
            step: 100,
            range: true,
            min: arrLimitiFiltri[0],
            max: arrLimitiFiltri[1],
            values: [prezzoDa, prezzoA],
            stop: function (event, ui) {
                $.ajax({
                    url: "loading.html",
                    cache: false,
                    success: function (html) {
                        $("#filterWaiting").append(html);
                        document.getElementById("filterWaiting").style.display = '';
                        EstraiFiltratoPaginato(1);
                        calltooltip();
                    }
                });
            },
            slide: function (event, ui) {
                $("#amount1").html('<span>' + ui.values[0] + ' €</span>');
                $("#amount2").html('<span>' + ui.values[1] + ' €</span>');
                document.getElementById("PrezzoDa").value = ui.values[0];
                document.getElementById("PrezzoA").value = ui.values[1];
                $('#hdnPrezzoDa').val(ui.values[0]);
                $('#hdnPrezzoA').val(ui.values[1]);
            }
        });


    }



    // CARICAMENTO VALORI INIZIALI SLIDER Struttura

    // mantenimento dei filtri dopo il back del browser
    var stelleDa = $('#hdnStelleDa').val();
    var stelleA = $('#hdnStelleA').val();
    if (stelleDa == '1' && stelleA == '5') {
        stelleDa = arrLimitiFiltri[2];
        stelleA = arrLimitiFiltri[3];
    }

    html_sx = "";
    // Stelle piene
    for (i = 0; i < stelleDa; i++) {
        html_sx += "<img src=\"../image/shoulder/slider/icon_star.gif\">";
    }
    // Stelle vuote
    for (i = stelleDa; i < 5; i++) {
        html_sx += "<img src=\"../image/shoulder/slider/icon_star_empty.gif\">";
    }
    // Butta nel div
    document.getElementById("debugStarSx").innerHTML = "da " + stelleDa + " " + html_sx;
    document.getElementById("hdnStelleDa").value = stelleDa;

    // Crea stelle destra			
    html_dx = "";
    // Stellle piene
    for (i = 0; i < stelleA; i++) {
        html_dx += "<img src=\"../image/shoulder/slider/icon_star.gif\">";
    }
    // Stelle vuote
    for (i = stelleA; i < 5; i++) {
        html_dx += "<img src=\"../image/shoulder/slider/icon_star_empty.gif\">";
    }
    // Butta nel div
    document.getElementById("debugStarDx").innerHTML = html_dx + " a " + stelleA;
    document.getElementById("hdnStelleA").value = stelleA;

    //Visualizzo lo slider solo se i limiti sono diversi
    if (arrLimitiFiltri[2] != arrLimitiFiltri[3]) {

        $("#slider-range2").slider({
            step: 1,
            range: true,
            min: arrLimitiFiltri[2],
            max: arrLimitiFiltri[3],
            values: [stelleDa, stelleA],
            stop: function (event, ui) {
                $.ajax({
                    url: "loading.html",
                    cache: false,
                    success: function (html) {
                        $("#filterWaiting").append(html);
                        document.getElementById("filterWaiting").style.display = '';
                        EstraiFiltratoPaginato(1);
                        calltooltip();
                    }
                });
            },
            slide: function (event, ui) {

                // Crea stelle sinistra
                html_sx = "";
                // Stellle piene
                for (i = 0; i < ui.values[0]; i++) {
                    html_sx += "<img src=\"../image/shoulder/slider/icon_star.gif\">";
                }
                // Stelle vuote
                for (i = ui.values[0]; i < 5; i++) {
                    html_sx += "<img src=\"../image/shoulder/slider/icon_star_empty.gif\">";
                }
                // Butta nel div
                document.getElementById("debugStarSx").innerHTML = "da " + ui.values[0] + " " + html_sx;
                document.getElementById("StelleDa").value = ui.values[0];

                // Crea stelle destra			
                html_dx = "";
                // Stellle piene
                for (i = 0; i < ui.values[1]; i++) {
                    html_dx += "<img src=\"../image/shoulder/slider/icon_star.gif\">";
                }
                // Stelle vuote
                for (i = ui.values[1]; i < 5; i++) {
                    html_dx += "<img src=\"../image/shoulder/slider/icon_star_empty.gif\">";
                }
                // Butta nel div
                document.getElementById("debugStarDx").innerHTML = html_dx + " a " + ui.values[1];
                document.getElementById("StelleA").value = ui.values[1];

                // mantenimento filtri
                $('#hdnStelleDa').val(ui.values[0]);
                $('#hdnStelleA').val(ui.values[1]);

            }
        });
    }


    // CARICAMENTO VALORI INIZIALI SLIDER Consigliate
    // MIN:
    html_sx = "";

    // mantenimento dei filtri dopo il back del browser
    var votoDa = $('#hdnVotoDa').val();
    var votoA = $('#hdnVotoA').val();
    if (votoDa == '1' && votoA == '5') {
        votoDa = arrLimitiFiltri[4];
        votoA = arrLimitiFiltri[5];
    }

    // Pallini piene
    for (i = 0; i < votoDa; i++) {
        html_sx += "<img src=\"../image/shoulder/slider/icon_vote.gif\">";
    }
    // Pallini vuote
    for (i = votoDa; i < 4; i++) {
        html_sx += "<img src=\"../image/shoulder/slider/icon_vote_empty.gif\">";
    }
    document.getElementById("debugVoteSx").innerHTML = "da " + votoDa + " " + html_sx;
    document.getElementById("hdnVotoDa").value = votoDa;
    // MAX:
    // Crea pallini destra			
    html_dx = "";
    // Pallini piene
    for (i = 0; i < votoA; i++) {
        html_dx += "<img src=\"../image/shoulder/slider/icon_vote.gif\">";
    }
    // Pallini vuote
    for (i = votoA; i < 4; i++) {
        html_dx += "<img src=\"../image/shoulder/slider/icon_vote_empty.gif\">";
    }
    document.getElementById("debugVoteDx").innerHTML = html_dx + " a " + votoA;
    document.getElementById("hdnVotoA").value = votoA;

    if (arrLimitiFiltri[4] != arrLimitiFiltri[5]) {
        //Visualizzo lo slider solo se i limiti sono diversi
        $("#slider-range3").slider({
            step: 1,
            range: true,
            min: arrLimitiFiltri[4],
            max: arrLimitiFiltri[5],
            values: [votoDa, votoA],
            stop: function (event, ui) {
                $.ajax({
                    url: "loading.html",
                    cache: false,
                    success: function (html) {
                        $("#filterWaiting").append(html);
                        document.getElementById("filterWaiting").style.display = '';
                        EstraiFiltratoPaginato(1);
                        calltooltip();
                    }
                });
            },
            slide: function (event, ui) {
                // Crea pallini sinistra			
                html_sx = "";
                // Pallini piene
                for (i = 0; i < ui.values[0]; i++) {
                    html_sx += "<img src=\"../image/shoulder/slider/icon_vote.gif\">";
                }
                // Pallini vuote
                for (i = ui.values[0]; i < 4; i++) {
                    html_sx += "<img src=\"../image/shoulder/slider/icon_vote_empty.gif\">";
                }
                // Butta nel div
                document.getElementById("debugVoteSx").innerHTML = "da " + ui.values[0] + " " + html_sx;
                document.getElementById("VotoDa").value = ui.values[0];

                // Crea pallini destra			
                html_dx = "";
                // Pallini piene
                for (i = 0; i < ui.values[1]; i++) {
                    html_dx += "<img src=\"../image/shoulder/slider/icon_vote.gif\">";
                }
                // Pallini vuote
                for (i = ui.values[1]; i < 4; i++) {
                    html_dx += "<img src=\"../image/shoulder/slider/icon_vote_empty.gif\">";
                }
                // Butta nel div
                document.getElementById("debugVoteDx").innerHTML = html_dx + " a " + ui.values[1];
                document.getElementById("VotoA").value = ui.values[1];


                // mantenimento filtri
                $('#hdnVotoDa').val(ui.values[0]);
                $('#hdnVotoA').val(ui.values[1]);
            }
        });
    }

});

function resetFiltri() {

    //PREZZO
    $("#amount1").val(arrLimitiFiltri[0] + ' €');
    $("#amount2").val(arrLimitiFiltri[1] + ' €');
    document.getElementById("PrezzoDa").value = arrLimitiFiltri[0];
    document.getElementById("PrezzoA").value = arrLimitiFiltri[1];
    //resetto graficamente gli slider
    $("#slider-range").slider('values', 0, arrLimitiFiltri[0]);
    $("#slider-range").slider('values', 1, arrLimitiFiltri[1]);


    //STELLE
    // Crea stelle sinistra
    html_sx = "";
    // Stelle piene
    for (i = 0; i < arrLimitiFiltri[2]; i++) {
        html_sx += "<img src=\"../image/shoulder/slider/icon_star.gif\">";
    }
    // Stelle vuote
    for (i = arrLimitiFiltri[2]; i < 5; i++) {
        html_sx += "<img src=\"../image/shoulder/slider/icon_star_empty.gif\">";
    }
    // Butta nel div
    document.getElementById("debugStarSx").innerHTML = "da " + arrLimitiFiltri[2] + " " + html_sx;
    document.getElementById("StelleDa").value = arrLimitiFiltri[2];

    // Crea stelle destra			
    html_dx = "";
    // Stellle piene
    for (i = 0; i < arrLimitiFiltri[3]; i++) {
        html_dx += "<img src=\"../image/shoulder/slider/icon_star.gif\">";
    }
    // Stelle vuote
    for (i = arrLimitiFiltri[3]; i < 5; i++) {
        html_dx += "<img src=\"../image/shoulder/slider/icon_star_empty.gif\">";
    }
    // Butta nel div
    document.getElementById("debugStarDx").innerHTML = html_dx + " a " + arrLimitiFiltri[3];
    document.getElementById("StelleA").value = arrLimitiFiltri[3];
    //resetto graficamente gli slider
    $("#slider-range2").slider('values', 0, arrLimitiFiltri[2]);
    $("#slider-range2").slider('values', 1, arrLimitiFiltri[3]);


    //CONSIGLIATE
    // MIN:
    html_sx = "";
    // Pallini piene
    for (i = 0; i < arrLimitiFiltri[4]; i++) {
        html_sx += "<img src=\"../image/shoulder/slider/icon_vote.gif\">";
    }
    // Pallini vuote
    for (i = arrLimitiFiltri[4]; i < 4; i++) {
        html_sx += "<img src=\"../image/shoulder/slider/icon_vote_empty.gif\">";
    }
    document.getElementById("debugVoteSx").innerHTML = "da " + arrLimitiFiltri[4] + " " + html_sx;
    document.getElementById("VotoDa").value = arrLimitiFiltri[4];
    // MAX:
    // Crea pallini destra			
    html_dx = "";
    // Pallini piene
    for (i = 0; i < arrLimitiFiltri[5]; i++) {
        html_dx += "<img src=\"../image/shoulder/slider/icon_vote.gif\">";
    }
    // Pallini vuote
    for (i = arrLimitiFiltri[5]; i < 4; i++) {
        html_dx += "<img src=\"../image/shoulder/slider/icon_vote_empty.gif\">";
    }
    document.getElementById("debugVoteDx").innerHTML = html_dx + " a " + arrLimitiFiltri[5];
    document.getElementById("VotoA").value = arrLimitiFiltri[5];
    //resetto graficamente gli slider
    $("#slider-range3").slider('values', 0, arrLimitiFiltri[4]);
    $("#slider-range3").slider('values', 1, arrLimitiFiltri[5]);


    //TRATTAMENTO
    for (i = 0; i < 100; i++) {
        if (document.getElementById('chkTrattamento_' + i) != null) {
            document.getElementById('chkTrattamento_' + i).checked = false;
        }
        else {
            break;
        }
    }


    //SINGOLA
    document.getElementById('Camera_Singola').checked = false;


    //QUADRUPLA
    document.getElementById('Camera_Quadrupla').checked = false;

    //LAST MINUTE
    document.getElementById('Solo_Last_Minute').checked = false;

    //DURATA
    for (i = 0; i < 100; i++) {
        if (document.getElementById('chkDurata_' + i) != null) {
            document.getElementById('chkDurata_' + i).checked = false;
        }
        else {
            break;
        }
    }

    //Richiamo caricamento tutti i risultati senza filtri.
    $.ajax({
        url: "loading.html",
        cache: false,
        success: function (html) {
            $("#filterWaiting").append(html);
            document.getElementById("filterWaiting").style.display = '';
            EstraiPaginato(1);
            calltooltip();
            document.getElementById("filterWaiting").style.display = 'none';
        }
    });

}


function callFilterWaitingDiv(view) {
    if (view) {
        //alert("true: " + view);
        document.getElementById("filterWaiting").style.display = '';
    } else {
        //alert("false: " + view)
        document.getElementById("filterWaiting").style.display = 'none';
    }
}

