﻿function categorie(idcat) {
var totale=categ;

for(i=0;i<categ;i++) {
//document.getElementById("cat" + i).style.display='none';
mostra_div("cat" + i, '1');
}

//document.getElementById("cat" + idcat).style.display='inline';
//$("#cat" + idcat).show("slow");

mostra_div("cat" + idcat, '0');

}


function slidedown(div, maxH) {

    $("#" + div).animate({ "height": maxH });
    mostra_div("corpoM", "0");
    mostra_div_fade("logo2", "0");
}

function mostra_div(idDiv,forza) {
        if ((document.getElementById(idDiv).style.display == "none" || document.getElementById(idDiv).style.display == "") && forza=="0") {
              $("#" + idDiv).show("slow");
    } else {
    
   if (document.getElementById(idDiv).style.display == "block" || forza=="1") {
       $("#" + idDiv).hide("slow");
   }
    }
}

function mostra_div_fade(idDiv, forza) {
    if ((document.getElementById(idDiv).style.display == "none" || document.getElementById(idDiv).style.display == "") && forza == "0") {
        $("#" + idDiv).fadeIn("slow");
    } else {

        if (document.getElementById(idDiv).style.display == "block" || forza == "1") {
            $("#" + idDiv).fadeOut("slow");
        }
    }
}



function messaggioS(mex, tipo) {
var colore="";
var testo="";
var sfondo="";

    switch (tipo) {

        case "INFO":

            colore = "#FFF";
            sfondo = "#2a9ce7";
            testo = "<img src=\"/images/info_mex.png\" alt=\"\" /> Informazione";
            break;

        case "ERRORE":

            colore = "#FFF";
            sfondo = "#b13434";
            testo = "<img src=\"/images/info_errore.png\" alt=\"\" /> Errore di Sistema";
            break;

        case "SIST":
            colore = "#FFF";
            sfondo = "#5c821d";
            testo = "<img src=\"/images/info_sistema.png\" alt=\"\" /> Messaggio di Sistema";
            break;
            
        case "CRITIC":
            colore="#FFF";
            sfondo="#ff8e09";
            testo = "<img src=\"/images/info_critic.png\" alt=\"\" /> Avviso";
            break;
                       
    }

    document.getElementById("titolo_messaggio_sistema_id").style.color = colore;
    document.getElementById("titolo_messaggio_sistema_id").style.backgroundColor = sfondo;
    document.getElementById("titolo_messaggio_sistema_id").innerHTML = testo;

    document.getElementById("messaggi_sistema").style.marginTop = "0px";

    var add = 200;
    var scrTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
       
    document.getElementById("messaggi_sistema").style.marginTop = (parseFloat(scrTop) + add) + "px";

      document.getElementById("messaggio_sistema").innerHTML = mex ;
    mostra_div('messaggi_sistema', '0');
}


function mostraFeedback() {

    document.getElementById("feedBackArticolo").style.marginTop = "0px";

    var add = -50;
    var scrTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;

    document.getElementById("feedBackArticolo").style.marginTop = (parseFloat(scrTop) + add) + "px";

    mostra_div('feedBackArticolo', '0');
}


function confDelCarrello() {
    var mes = confirm("Eliminare l'elemento selezionato?");
    if (mes) {
        return true;
       // xx //creo un errore per far funzionare il submit
        }else {
        return false;
        }
    }


    function confSvuot() {
        
        var mes = confirm("Svuotare il carrello?");
        if (mes) {
            return true;
        } else {
            return false;
        }
    }



    function confOrdd() {

        var mes = confirm("Eseguire l'Ordine?");
        if (mes) {
            return true;
        } else {
            return false;
        }
    }


    function confDelOrdine() {

        var mes = confirm("Annullare l'Ordine?");
        if (mes) {
            return true;
        } else {
            return false;
        }
    }



    function confDelAvv() {

        var mes = confirm("Annullare l'avviso di giacenza per questo prodotto?");
        if (mes) {
            return true;
        } else {
            return false;
        }
    }


    function confDelPref() {

        var mes = confirm("Eliminare questo prodotto dai preferiti?");
        if (mes) {
            return true;
        } else {
            return false;
        }
    }



    function confDelCom() {

        var mes = confirm("Eliminare questa Comunicazione?");
        if (mes) {
            return true;
        } else {
            return false;
        }
    }


    function filtro_lista(idsel) {
        var azione = $("#" + idsel ).val();

        
        mostra_div("filtro_prezzo", 1);
        
        mostra_div("filtro_marca", 1);
        
        
        switch (azione) {

            case "prezzo":
                {
                    mostra_div("filtro_prezzo",0);
                    break;
                }

            case "marca":
                {
                    mostra_div("filtro_marca",0);
                    break;
                }


        }

    }



    function flip(az,idel) {

        if (az == 0) {
            document.getElementById(idel).src = "/images/coco/logoN2.png";
        }

        if (az == 1) {
            document.getElementById(idel).src = "/images/coco/logoN_c.png";
        }

    }





    function mostraordine(idOrd) {
        window.open("/dettagli_ordine.aspx?id=" + idOrd, "", "width=840,height=500,scrollbars=yes", true);
    }



    function menu_admin(voce) {

   
        var vociM = new Array();
        vociM.push("gest_articoli");
        vociM.push("gest_ordini");
        vociM.push("gest_clienti");
        vociM.push("gest_skdett");
        vociM.push("gest_admins");
        vociM.push("gest_categorie");
        vociM.push("gest_sedi");
        vociM.push("gest_marche");
        vociM.push("gest_sconti");

        for (i = 0; i < vociM.length; i++) {
            
            mostra_div(vociM[i], 1);

        }


        mostra_div(voce, 0);

    }



    function carica_pagina(url, destinaz) {
        $.ajax({
            url: url,
            success: function (data) {
               $('#' + destinaz).html(data);
            }
        });

        //setTimeout("alert( $('#" + destinaz + "').html());", 5000);
    }

    var action = 0;
    var richiesta = "";
    function cerca_cliente() {

        var valore = $('#sconti_cliente_ric').val();

        if (valore.length > 2) {

            $('#clienti_lista').html('<div class=""elemento"">Attendere....</div>');

            if (action == 0) {
                richiesta = "Y";
                mostra_div('clienti_lista', '0');
            } else {
            richiesta = "N";
        }

                carica_pagina('/lista_clienti_ajax.aspx?q=' + valore + "&r=" + richiesta, 'clienti_lista');
                action = 1;
            } else {
                mostra_div('clienti_lista','1');
            $('#clienti_lista').html('');
            action = 0;
        }

    }



    function seleziona_cliente(id,den) {
        $('#sconti_cliente_ric').val(den);
    $('#sconti_idcliente').val(id);
    mostra_div('clienti_lista', '1');
    action = 0;
    $('#clienti_lista').html('');
    //setTimeout("alert('" + $('#sconti_idcliente').val() + "');", 1000);

    }

    var URL_IMMAGINE = "";
    var xyz;
    function setValoreIMG(desti, urlIMG, mittent, totIMGS) {

        URL_IMMAGINE = urlIMG;

        xyz.setValue(urlIMG);

        xyz.focus();

       for (i = 0; i <= totIMGS - 1; i++) {
           document.getElementById('IMM_' + i).style.border = "0px";
       }

       document.getElementById('IMM_' + mittent).style.border = "1px solid red";
   }


   function nuova_img() {
       window.open("/admin_img_home_upload.aspx", "", "width=300, height=100;");
   }

   function elimina_img(img) {
       window.open("/admin_img_home_delete.aspx?img=" + img, "", "width=300, height=100;");
   }
