﻿
// funzione di pageload intercettata dall'asp.net in caso di Ajax;
// inserire qui l'inizializzazione di tutte le funzioni javascript bloccate dall'Ajax
function pageLoad() {
    if (typeof inizializzaCluetip == 'function') {
        inizializzaCluetip();
    }
}

//funzione il popup di avviso
function modal(testo) {

    $.blockUI({
        message: '<div id="div_info" class="div-infoSuccesso">' +
                    '<table>' +
                        '<tr>' +
                            '<td style="width: 35px">' +
                                '<div id="div_infoIcona">' +
                                '</div>' +
                            '</td>' +
                            '<td>' +
                                '<div id="div_infoDescrizione">' + testo +
                                '</div>' +
                            '</td>' +
                        '</tr>' +
                    '</table>' +
                '</div>',
        fadeIn: 700,
        fadeOut: 700,
        timeout: 3000,
        showOverlay: false,
        centerY: true,
        centerX: true,
        css: {
            width: '370px',
            left: '50%',
            'margin-left': '-185px',
            'text-align':'left'
        }
    });
}


//funzione per il popup modal di errore
function modalError(titolo, testo) {

    $.blockUI({
        message: '<div id="div_info" class="div-infoErrore">' +
                    '<table>' +
                        '<tr>' +
                            '<td style="width: 35px">' +
                                '<div id="div_infoIcona">' +
                                '</div>' +
                            '</td>' +
                            '<td>' +
                                '<div id="div_infoTitolo">' + titolo +
                                '</div>' +
                            '</td>' +
                        '</tr>' +
                        '<tr style="margin-top:10px;">' +
                            '<td></td>' +
                            '<td>' +
                                '<div id="div_infoDescrizione">' + testo +
                                '</div>' +
                            '</td>' +
                        '</tr>' +
                    '</table>' +
                    '<div class="div_infoChiudi"><span id="span_chiudi_modal_error">chiudi</span></div>' +
                '</div>',
        centerY: true,
        centerX: true,
        css: {
            width: '370px',
            cursor: 'default',
            left: '50%',
            'margin-left': '-185px',
            'text-align':'left'
        }
    });

    $('#span_chiudi_modal_error').click($.unblockUI);
}



//funzione per capire se l'utente ha premuto OK o Annulla nei confirm di Telerik
//se l'utente ha clickato OK fa postbak altrimenti no
window.blockConfirm = function (text, mozEvent, oWidth, oHeight, callerObj, oTitle) {
    var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually
    //Cancel the event
    ev.cancelBubble = true;
    ev.returnValue = false;
    if (ev.stopPropagation) ev.stopPropagation();
    if (ev.preventDefault) ev.preventDefault();

    //Determine who is the caller
    var callerObj = ev.srcElement ? ev.srcElement : ev.target;

    //Call the original radconfirm and pass it all necessary parameters
    if (callerObj) {
        //Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again.
        var callBackFn = function (arg) {
            if (arg) {
                callerObj["onclick"] = "";
                if (callerObj.click) {
                    callerObj.click(); //Works fine every time in IE, but does not work for links in Moz
                } else if (callerObj.tagName == "A") {
                    //We assume it is a link button! 
                    try {
                        eval(callerObj.href)
                    }
                    catch (e) { }
                } else if (callerObj.parentNode.click) {
                    callerObj.parentNode.click();
                } else if (callerObj.parentNode.tagName == "A") {
                    try {
                        eval(callerObj.parentNode.href)
                    }
                    catch (e) { }
                }
            }
        }
        radconfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);
    }
    return false;
}






//
//  Funzioni jcarosel INIZIO
//  
function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function () {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function () {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function () {
        carousel.stopAuto();
    }, function () {
        carousel.startAuto();
    });
};
function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
};

/*      FUNZIONI JCAROSEL CATEGORIE PRODOTTI IN HOME PAGE      */
function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    var oggetto = mycarousel_getItemHTML(mycarousel_itemList[idx - 1]);
    //         oggetto.aToolTip({
    //             tipContent: item.title,
    //             xOffset: -330,
    //             yOffset: -10
    //         });
    carousel.add(i, oggetto);
};
function mycarousel_getItemHTML(item) {
    //alt="' + item.title + '"
    if (!(item == null)) {
        var str = ''
        str += '<div class="float_left prodotto_slide">'
        str += '    <a href="' + item.link_url + '">'
        str += '        <img src="' + item.url + '" style="width:75px; height:75px;" title="' + item.title + '"  />'
        str += '    </a>'
        str += '</div>';

        return str;
    }
};

/*      FUNZIONI JCAROSEL CATEGORIE PRODOTTI IN CONFIGURATORE      */
function mycarouselCategorie_itemVisibleInCallback(carousel, item, i, state, evt) {
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    var oggetto = mycarouselCategorie_getItemHTML(mycarousel_itemList[idx - 1]);
    carousel.add(i, oggetto);
};
function mycarouselCategorie_getItemHTML(item) {
    if (!(item == null)) {
        var str = ''
        str += '<a href="' + item.link_url + '"   >'; //
        str += '    <img src="' + item.url + '" title="' + item.title + '"  />';
        str += '</a>';
        str += '<a href="' + item.link_url + '" style="bottom: 5px;position: absolute;height: 32px;" >' + item.title + '</a>';

        return str;
    }
};


/*      FUNZIONI JCAROSEL FAMIGLIE PRODOTTI IN SCHEDA PRODOTTO      */
function mycarouselFamiglie_itemVisibleInCallback(carousel, item, i, state, evt) {
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    var oggetto = mycarouselFamiglie_getItemHTML(mycarousel_itemList[idx - 1]);
    carousel.add(i, oggetto);
};
function mycarouselFamiglie_getItemHTML(item) {
    if (!(item == null)) {
        var str = ''
        str += '<a href="' + item.link_url + '" style="height: 160px;width:160px;margin: 5px 10px; background-color: white;" >';
        str += '    <img src="' + item.url + '" title="' + item.title + '"  />';
        str += '</a>';
        str += '<a href="' + item.link_url + '">' + item.title + '</a>';

        return str;
    }
};

//
//  Funzioni jcarosel FINE
//  





// Fine Funzioni Slider Prodotti
function start_SlideBanner() {
    var flag = 0;
    var permanenza_foto = 4000;
    var numero_foto = myPhotoBanner.length;
    if (numero_foto > 0) {
        contatore_fotoPrincipale = 0;
        contatore_fotoNext = 1;
        contatore_fotoPrev = numero_foto - 1;

        //imposto le prime due foto
        $('img[id$="Image_LogoSuperiore"]').attr("src", myPhotoBanner[contatore_fotoPrincipale]);
        $('img[id$="Image_fadeNext"]').attr("src", myPhotoBanner[contatore_fotoNext]);

        setTimeout('galleriaAutomatica(' + contatore_fotoPrincipale + ',' + contatore_fotoNext + ',' + contatore_fotoPrev + ',' + permanenza_foto + ',' + flag + ')', permanenza_foto);
    }
}
//INIZIO - funzione che cambia le foto automaticamente
function galleriaAutomatica(contatore_fotoPrincipale, contatore_fotoNext, contatore_fotoPrev, permanenza_foto, flag) {
    // flag 0 nascondo immagine sopra, flag 1 visualizzo immagine sopra
    var numero_foto = myPhotoBanner.length;
    var velocita_effetto = 1000;

    $('img[id$="Image_fadeNext"]').css("display", "");

    contatore_fotoPrincipale += 1;
    contatore_fotoNext += 1;
    contatore_fotoPrev += 1;
    if (contatore_fotoPrincipale == numero_foto) {
        contatore_fotoPrincipale = 0;
    }
    if (contatore_fotoNext == numero_foto) {
        contatore_fotoNext = 0;
    }
    if (contatore_fotoPrev == numero_foto) {
        contatore_fotoPrev = 0;
    }
    if (flag == 0) {
        //nascondi quella con z-index: 1 e mostra quella con z-index 0
        $('img[id$="Image_LogoSuperiore"]').animate({ opacity: 0 }, velocita_effetto, function () {
            $('img[id$="Image_LogoSuperiore"]').attr("src", myPhotoBanner[contatore_fotoNext]);
        });

        flag = 1;
    } else {
        flag = 0;
        //mostra quella con z-index: 1
        $('img[id$="Image_LogoSuperiore"]').animate({ opacity: 1 }, velocita_effetto, function () {
            $('img[id$="Image_fadeNext"]').attr("src", myPhotoBanner[contatore_fotoNext]);
        });


    }

    setTimeout('galleriaAutomatica(' + contatore_fotoPrincipale + ',' + contatore_fotoNext + ',' + contatore_fotoPrev + ',' + permanenza_foto + ',' + flag + ')', permanenza_foto);
}
//FINE - funzione che cambia le foto automaticamente



