<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeFile="reportRischioNew.aspx.cs"
    Inherits="reportRischioNew" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Report-->Rischio</title>
    <link href="CSS/tv.css" type="text/css" rel="stylesheet" />
    <link href="CSS/Pagina.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript" src="CSS/script.js"></script>
    <script language="javascript" type="text/javascript" src="css/CheckScript.js"></script>
    <script src="Comuni/Script/Utilita.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        function updateTop() {
            parent.frames['TOP'].document.getElementById('lblNavPath').innerHTML = "<%=pathNav%>";

        }

        function TracciaEventoAudit(boid) {

        }       

    </script>
    <!-- MODIFICA PER GESTIONE STAMPA e POOL SU CLIENT-->
    <script language="javascript" type="text/javascript">     
        
    </script>
    <!-- FINE MODIFICA PER GESTIONE STAMPA e POOL SU CLIENT-->
    <!-- -->
    <link type="text/css" href="jquery-ui-1.8.20.custom/css/ui-lightness/jquery-ui-1.8.20.custom.css"
        rel="stylesheet" />
    <script type="text/javascript" src="jquery-ui-1.8.20.custom/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="jquery-ui-1.8.20.custom/js/jquery-ui-1.8.20.custom.min.js"></script>
    <script src="jquery-ui-1.8.20.custom/alerts-1.1/jquery.alerts.js" type="text/javascript"></script>
    <link href="jquery-ui-1.8.20.custom/alerts-1.1/jquery.alerts.css" rel="stylesheet"
        type="text/css" media="screen" />
    <script type="text/javascript">


        var lstId = null;
        var lstImmagine = null;
        var lstTab = null;
        var lstTesto = null;
        var lstDisable = null;
        var lstSezioni = null;
        var lstTemplate = null;
        var lstIsPATRI = null;
        var lstVincoli = null;
        var lstDatiMulti = null;
        var isSizeImg = true;
        var lstNOPATRI = new Array();
        var perc = 1;
        $(function () {
                    
                   
            if ($("#HFERRORMSG2").attr("value") != "")
                jAlert($("#HFERRORMSG2").attr("value"), "Report di Rischio - Log");
           

            if ($("#HFERRORMSG").attr("value") != "") {              
                $("#mainForm").html("<br><span style=' color: red;  font-family: Tahoma; font-size: 12px; font-weight: bold;display: inline-block;height:466px;width:700px;'>" + $("#HFERRORMSG").attr("value") + "</span>");
                wait2(false);
                return;
            }

            if ($("#HFGENERAPDF").attr("value") != "" && $("#HFRETURN").attr("value") != "") {
                generaPDF("Generator.aspx", $("#HFGENERAPDF").attr("value"));
                $("#HFGENERAPDF").attr("value", "");
                return;
            }

            wait2(true);

            Touch();

            $('#tabs').tabs();
            $('#tabsort').tabs();
            $("#sortable").sortable({
                update: function (event, ui) {
                    SelezionaSeleziona();
                }
            });
            $("#sortable").disableSelection();
            $("#ButSalva").attr("disabled", "disabled").css("opacity", "0.5");
            $("#ButSvuota").attr("disabled", "disabled").css("opacity", "0.5");
            $("#ButStampa").attr("disabled", "disabled").css("opacity", "0.5");
            //*** #HDMENU
            if ($("#HDMENU").attr("value") == "0,*") ChiudiMenu(); else ApriMenu();
            $("#HideMenu").mouseout(CursorDefault);
            $("#HideMenu").mouseover(CursorPointer);
            $("#HideMenu").click(function () {
                if ($("#HDMENU").attr("value") == "0,*") ApriMenu(); else ChiudiMenu();
            });
            function ChiudiMenu() {
                $(window.parent.frames['CORPO']).attr("cols", "0,*");
                $("#HDMENU").attr("value", "0,*")
                $("#PDDLTemplate").css("left", "402px");
                $("#lblTitle").css("width", "893px");
                $(".tabsdiv").css("width", "480px");
                $("#sortablesdiv").css("width", "390px");
                $("#HideMenu").attr("src", "Images/report/_menuchiuso.jpg");
                SizeImg();
            }
            function ApriMenu() {
                $(window.parent.frames['CORPO']).attr("cols", "188,*");
                $("#HDMENU").attr("value", "188,*");
                $("#PDDLTemplate").css("left", "214px");
                $("#lblTitle").css("width", "705px");
                $(".tabsdiv").css("width", "480px");
                $("#sortablesdiv").css("width", "202px");
                $("#HideMenu").attr("src", "Images/report/_menuaperto.jpg");
                SizeImg();
            }
            var selsel = false;
            function SelezionaSeleziona() {
                if (selsel) {
                    $("#DDLTemplate option[value!='Seleziona']").removeAttr('selected');
                    $("#DDLTemplate option[value='Seleziona']").attr('selected', 'selected');
                    $("#ButCarica").attr("disabled", "disabled").css("opacity", "0.5");
                }
            }


            function SIPATRI() {
                for (i = 0; i < lstNOPATRI.length; i++) {
                    var ID = lstNOPATRI[i];
                    $('table#' + ID + ' div').css("opacity", "1");
                    $('table#' + ID + ' img:not(.ModRptA)').css("opacity", "1");
                    $('table#' + ID + ' img.ModRptA').attr("title", "Inserisci la scheda nel report personalizzato");
                    $('table#' + ID + ' img.ModRptA').attr("src", "Images/report/_aggiungi.png");
                    $('table#' + ID + ' img.ModRptA').removeAttr("disabled").css("opacity", "1");

                    $('table#tutte' + ID + ' div').css("opacity", "1");
                    $('table#tutte' + ID + ' img:not(.ModRptA)').css("opacity", "1");
                    $('table#tutte' + ID + ' img.ModRptA').attr("title", "Inserisci la scheda nel report personalizzato");
                    $('table#tutte' + ID + ' img.ModRptA').attr("src", "Images/report/_aggiungi.png");
                    $('table#tutte' + ID + ' img.ModRptA').removeAttr("disabled").css("opacity", "1");
                }
            }
            function NOPATRI() {
                for (i = 0; i < lstNOPATRI.length; i++) {
                    var ID = lstNOPATRI[i];
                    $("table.TempRpt#sid" + ID + " img.TempRptS").click();
                    $('table#' + ID + ' div').css("opacity", "0.5");
                    $('table#' + ID + ' img:not(.ModRptA)').css("opacity", "0.5");
                    $('table#' + ID + ' img.ModRptA').attr("title", "");
                    $('table#' + ID + ' img.ModRptA').attr("src", "Images/report/_noaggiungi.png");
                    $('table#' + ID + ' img.ModRptA').attr("disabled", "disabled");

                    $('table#tutte' + ID + ' div').css("opacity", "0.5");
                    $('table#tutte' + ID + ' img:not(.ModRptA)').css("opacity", "0.5");
                    $('table#tutte' + ID + ' img.ModRptA').attr("title", "");
                    $('table#tutte' + ID + ' img.ModRptA').attr("src", "Images/report/_noaggiungi.png");
                    $('table#tutte' + ID + ' img.ModRptA').attr("disabled", "disabled");
                }
            }
            function SIPATRI_OLD() {
                $("table.ModRpt,table.ModRptTutte").each(function () {
                    if ($('table#' + $(this).attr("ID") + ' img:not(.ModRptA)').attr("src").indexOf("schede-18") > -1 ||
                         $('table#' + $(this).attr("ID") + ' img:not(.ModRptA)').attr("src").indexOf("schede-19") > -1) {
                        $('table#' + $(this).attr("ID") + ' div').css("opacity", "1");
                        $('table#' + $(this).attr("ID") + ' img:not(.ModRptA)').css("opacity", "1");
                        $('table#' + $(this).attr("ID") + ' img.ModRptA').attr("title", "Inserisci la scheda nel report personalizzato");
                        $('table#' + $(this).attr("ID") + ' img.ModRptA').attr("src", "Images/report/_aggiungi.png");
                        $('table#' + $(this).attr("ID") + ' img.ModRptA').removeAttr("disabled").css("opacity", "1");
                    }
                });
            }
            function NOPATRI_OLD() {
                $("table.TempRpt").each(function () {
                    if ($('table.TempRpt#' + $(this).attr("ID") + ' img:not(.TempRptS)').attr("src").indexOf("schede-18") > -1 ||
                         $('table.TempRpt#' + $(this).attr("ID") + ' img:not(.TempRptS)').attr("src").indexOf("schede-19") > -1) {
                        $("table.TempRpt#" + $(this).attr("ID") + " img.TempRptS").click();
                    }
                });
                $("table.ModRpt,table.ModRptTutte").each(function () {
                    if ($('table#' + $(this).attr("ID") + ' img:not(.ModRptA)').attr("src").indexOf("schede-18") > -1 ||
                         $('table#' + $(this).attr("ID") + ' img:not(.ModRptA)').attr("src").indexOf("schede-19") > -1) {
                        $('table#' + $(this).attr("ID") + ' div').css("opacity", "0.5");
                        $('table#' + $(this).attr("ID") + ' img:not(.ModRptA)').css("opacity", "0.5");
                        $('table#' + $(this).attr("ID") + ' img.ModRptA').attr("title", "");
                        $('table#' + $(this).attr("ID") + ' img.ModRptA').attr("src", "Images/report/_noaggiungi.png");
                        $('table#' + $(this).attr("ID") + ' img.ModRptA').attr("disabled", "disabled");
                    }
                });
            }

            $("#rbl_Privacy input[value='Patrimonio']").click(function () {
                if ($(this).attr("checked")) {
                    SIPATRI();
                } else {
                    NOPATRI();
                }
            });
            //***************************************************+
            //*** #HideOpzioni
            $("#HideOpzioni").mouseout(CursorDefault);
            $("#HideOpzioni").mouseover(CursorPointer);
            $("#HideOpzioni").click(function () {
                if ($("#rbl_Privacy").css("display") == "none") {
                    $("#rbl_Privacy").css("display", "block");
                    $("#HideOpzioni").css("background-image", "url(Images/report/_opzaperto.jpg)");
                } else {
                    $("#rbl_Privacy").css("display", "none");
                    $("#HideOpzioni").css("background-image", "url(Images/report/_opzchiuso.jpg)");
                }
                return false;
            });
            $("#rbl_Privacy input").css("vertical-align", "middle");
            $("#HideOpzioni").click();
            //*** #DDLTemplate 
            if ($("#DDLTemplate option:selected").text() != "Seleziona") {
                $("#ButCarica").removeAttr("disabled").css("opacity", "1");
            } else {
                $("#ButCarica").attr("disabled", "disabled").css("opacity", "0.5");
            }
            if (ISDEFAULT($("#DDLTemplate option:selected").text()) ||
                 $("#DDLTemplate option:selected").text() == "Seleziona") {
                $("#ButElimina").attr("disabled", "disabled").css("opacity", "0.5");
            } else {
                $("#ButElimina").removeAttr("disabled").css("opacity", "1");
            }
            $("#DDLTemplate").change(function () {
                if ($("#DDLTemplate option:selected").text() != "Seleziona") {
                    $("#ButCarica").removeAttr("disabled").css("opacity", "1"); ;
                } else {
                    $("#ButCarica").attr("disabled", "disabled").css("opacity", "0.5");

                }
                if (ISDEFAULT($("#DDLTemplate option:selected").text()) ||
                 $("#DDLTemplate option:selected").text() == "Seleziona") {
                    $("#ButElimina").attr("disabled", "disabled").css("opacity", "0.5");
                } else {
                    $("#ButElimina").removeAttr("disabled").css("opacity", "1");
                }
            });



            if (document.documentElement.scrollHeight != 1 && document.documentElement.offsetHeight != 1) {
                $("#sortablesdiv").css("height", document.documentElement.offsetHeight);
                while (document.documentElement.scrollHeight != document.documentElement.offsetHeight) {
                    $("#sortablesdiv").css("height", $("#sortablesdiv").height() - 1);
                    if ($("#sortablesdiv").height() < 200) break;
                }
                $("#sortablesdiv").css("height", $("#sortablesdiv").height() - 7);
                $(".tabsdiv").css("height", $("#sortablesdiv").height());
                $("#HideMenu").css("height", $("#sortablesdiv").height() + 60);
            } else {

                $("#sortablesdiv").css("height", 300);
                $(".tabsdiv").css("height", $("#sortablesdiv").height());
                $("#HideMenu").css("height", $("#sortablesdiv").height() + 60);
            }


            var tt1 = $("#DatiHidden").attr("value");
            if (tt1 == null) {
                wait2(false);
                return;
            }
            tt = tt1.split("var");
            lstId = eval(tt[1]);
            if (lstId == null) {
                wait2(false);
                return;
            }
            lstImmagine = eval(tt[2]);
            lstTab = eval(tt[3]);
            lstTesto = eval(tt[4]);
            lstDisable = eval(tt[5]);
            lstSezioni = eval(tt[6]);
            lstIsPATRI = eval(tt[7]);
            lstVincoli = eval(tt[8]);
            lstDatiMulti = eval(tt[9]);
            lstTemplate = eval(tt[10]);

            var ObjTabs = "<table class='ModRpt' ><tr><td colspan='2' align='right'><img class='ModRptA'  width='30px' height='30px' src='Images/report/_aggiungi.png' /></td></tr><tr><td><img width='118px' height='157px'/></td><td><div ></div></td></tr></table>";
            var ObjSort = "<table class='TempRpt' style='float:left;width:0;height:0;'><tr><td align='right'><img class='TempRptS'  width='30px' height='30px' title='Elimina la scheda dal report personalizzato' src='Images/report/_sottrai.png' /></td></tr><tr><td><img/></td></tr></table>";



            //*** table.ModRpt
            for (i = 0; i < lstId.length; i++) {
                $("#tabs-" + lstTab[i]).append($(ObjTabs).attr("ID", i));
                if (lstIsPATRI[i] == "True") {
                    lstNOPATRI.push(i);
                    lstNOPATRI.push("tutte" + i);
                }
            }
            $(".rr table.ModRpt").each(function () {
                $("#tabs-Tutte").append($(ObjTabs).attr("ID", "tutte" + $(this).attr("id")).removeClass("ModRpt").addClass("ModRptTutte"));
            });
            $('table.ModRpt').each(function () {
                var padre = $(this);
                $('table#' + padre.attr("ID") + ' img:not(.ModRptA)').attr("src", "Images/report/" + lstImmagine[padre.attr("ID")]);
                $('table#' + padre.attr("ID") + ' div').html(lstTesto[padre.attr("ID")]);
                if (lstDisable[padre.attr("ID")].toString() == "False") {
                    $('table#' + padre.attr("ID") + ' img.ModRptA').attr("title", "Inserisci la scheda nel report personalizzato");
                    $('table#' + padre.attr("ID") + ' img.ModRptA').mouseout(CursorDefault);
                    $('table#' + padre.attr("ID") + ' img.ModRptA').mouseover(CursorPointer);
                    $('table#' + padre.attr("ID") + ' img.ModRptA').click(function () {
                        $("#sortable").append($(ObjSort).attr("ID", "sid" + padre.attr("ID")));
                        var imgScheda = $('table#sid' + padre.attr("ID") + ' img:not(.TempRptS)');
                        var imgClick = $('table#sid' + padre.attr("ID") + ' img.TempRptS');
                        imgScheda.attr("src", "Images/report/" + lstImmagine[padre.attr("ID")]);
                        // var title = lstTesto[padre.attr("ID")].replace(/(<([^>]+)>)/ig, '');
                        var title = $(lstTesto[padre.attr("ID")]).text();
                        imgScheda.attr("title", title);

                        if (imgScheda.width() > 0)
                            imgScheda.attr("widthOld", imgScheda.width());
                        else
                            imgScheda.attr("widthOld", "115");

                        if (imgScheda.height() > 0)
                            imgScheda.attr("heightOld", imgScheda.height());
                        else
                            imgScheda.attr("heightOld", "163px");
                        imgScheda.css("width", imgScheda.attr("widthOld") * perc);
                        imgScheda.css("height", imgScheda.attr("heightOld") * perc);
                        imgClick.attr("widthOld", imgClick.width());
                        imgClick.attr("heightOld", imgClick.height());
                        imgClick.css("width", imgClick.attr("widthOld") * perc);
                        imgClick.css("height", imgClick.attr("heightOld") * perc);
                        imgClick.mouseout(CursorDefault);
                        imgClick.mouseover(CursorPointer);
                        imgClick.click(function () {
                            $("table#" + padre.attr("ID")).show("slow");
                            $('table.ModRptTutte#tutte' + padre.attr("ID")).show("slow");
                            $('table#sid' + padre.attr("ID")).remove();
                            SizeImg();
                            if ($('table.TempRpt').length == 0) {
                                $("#ButSalva").attr("disabled", "disabled").css("opacity", "0.5"); ;
                                $("#ButSvuota").attr("disabled", "disabled").css("opacity", "0.5"); ;
                                $("#ButStampa").attr("disabled", "disabled").css("opacity", "0.5"); ;
                            }
                            SelezionaSeleziona();
                        });
                        padre.css("display", "none");
                        $('table.ModRptTutte#tutte' + padre.attr("ID")).css("display", "none");
                        $("#ButSalva").removeAttr("disabled").css("opacity", "1");
                        $("#ButSvuota").removeAttr("disabled").css("opacity", "1");
                        $("#ButStampa").removeAttr("disabled").css("opacity", "1");
                        SizeImg();
                        SelezionaSeleziona();
                    });
                } else {
                    $('table#' + padre.attr("ID") + ' div').css("opacity", "0.5");
                    $('table#' + padre.attr("ID") + ' img:not(.ModRptA)').css("opacity", "0.5");
                    $('table#' + padre.attr("ID") + ' img.ModRptA').attr("title", "");
                    $('table#' + padre.attr("ID") + ' img.ModRptA').attr("src", "Images/report/_noaggiungi.png");


                }
            });
            ///*** table.ModRptTutte
            $('table.ModRptTutte').each(function () {
                var Index = $(this).attr("ID").replace("tutte", "");
                $("table.ModRptTutte#tutte" + Index + " img:not(.ModRptA)").attr("src", $("table.ModRpt#" + Index + " img:not(.ModRptA)").attr("src"));
                $("table.ModRptTutte#tutte" + Index + " div").html($("table.ModRpt#" + Index + " div").html());
                $("table.ModRptTutte#tutte" + Index + " img.ModRptA").attr("title", $("table.ModRpt#" + Index + ' img.ModRptA').attr("title"));
                $("table.ModRptTutte#tutte" + Index).css("opacity", $("table.ModRpt#" + Index).css("opacity"));
                $("table.ModRptTutte#tutte" + Index + " img.ModRptA").click(function () {
                    $("table.ModRpt#" + Index + " img.ModRptA").click();
                });
                if ($("table.ModRptTutte#tutte" + Index + " img.ModRptA").attr("title") != "") {
                    $("table.ModRptTutte#tutte" + Index + " img.ModRptA").mouseout(CursorDefault);
                    $("table.ModRptTutte#tutte" + Index + " img.ModRptA").mouseover(CursorPointer);
                } else {
                    $("table.ModRptTutte#tutte" + Index + " div").css("opacity", "0.5");
                    $("table.ModRptTutte#tutte" + Index + " img:not(.ModRptA)").css("opacity", "0.5");
                    $("table.ModRptTutte#tutte" + Index + " img.ModRptA").attr("src", "Images/report/_noaggiungi.png");
                }

            });
            if (lstTemplate.length > 0) {
                isSizeImg = false;
                for (t = 0; t < lstTemplate.length; t++) {
                    for (i = 0; i < lstId.length; i++) {
                        if (lstTemplate[t] == lstId[i]) {
                            $('table#' + i + ' img.ModRptA').click();
                            break;
                        }
                    }
                }
                isSizeImg = true;
                SizeImg();
            }

            $("#ButSalva").mouseout(CursorDefault);
            $("#ButSalva").mouseover(CursorPointer);
            $("#ButSalva").click(function () {

                var ntest = $("#DDLTemplate option:selected").text() != "Seleziona" ? $("#DDLTemplate option:selected").text() : "";
                if (ISDEFAULT(ntest)) ntest = "";

                jPrompt("Per salvare il modello nell’Archivio Modelli è necessario inserire un nome. Continuare?", ntest, "Report di Rischio - Salva Modelli", function (newText) {
                    var cmd = "inserisci";
                    if (newText != null && (newText == "" || ISDEFAULT(newText))) {
                        jAlert("Caratteri speciali non validi", "Warning");
                        return false;
                    }
                    if (newText != null) {
                        $("#DDLTemplate option").each(function () {
                            if (cmd != "annulla") {
                                var oldText = $(this).text();
                                //                             if (ISDEFAULT(oldText) && TRIMDEFAULT(oldText) == newText) {
                                //                                 jAlert("Non è possibile usare un nome di default", "Warning");
                                //                                 cmd = "annulla";
                                //                             }
                                if (oldText == newText) {
                                    $("#HFNomeTemplate").attr("value", newText);
                                    jConfirm("Un modello con il nome “" + oldText + "” è già presente nell’Archivio Modelli. Sovrascrivere il modello esistente?", "Report di Rischio - Salva Modelli", function (r) {
                                        if (r) doPostBack("ButSalva");
                                    });
                                    cmd = "annulla";
                                }
                            }
                        });
                    } else { cmd = "annulla"; }
                    if (cmd == "annulla")
                        return false;
                    $("#HFNomeTemplate").attr("value", newText);
                    doPostBack("ButSalva");

                });
                return false;
            });
            $("#ButImportaTutto").mouseout(CursorDefault);
            $("#ButImportaTutto").mouseover(CursorPointer);
            $("#ButImportaTutto").click(function () {
                isSizeImg = false;
                $("div.rr:visible table.ModRpt:visible: img.ModRptA:not(:disabled)").click();
                $("div.rr:visible table.ModRptTutte:visible img.ModRptA:not(:disabled)").click();
                isSizeImg = true;
                SizeImg();
                return false;
            });
            $("#ButSvuota").mouseout(CursorDefault);
            $("#ButSvuota").mouseover(CursorPointer);
            $("#ButSvuota").click(function () {
                jConfirm("Eliminare tutte le schede inserite?", "Report di Rischio - Svuota Report", function (r) {
                    if (r) {
                        isSizeImg = false;
                        $("table.TempRpt img.TempRptS").click();
                        perc = 1;
                        isSizeImg = true;
                    }
                });
                return false;
            });
            $("#ButStampa").mouseout(CursorDefault);
            $("#ButStampa").mouseover(CursorPointer);
            $("#ButStampa").click(function () {
                if ($("#HDMENU").attr("value") == "0,*") {
                    $("#HideMenu").click();
                    $("#HDMENU").attr("value", "0,*");

                }
                $("#HFNomeTemplate").attr("value", $("#DDLTemplate option:selected").text());
                PostDatiHidden();
                wait2(true);
                return true;
            });
            $("#ButCarica").mouseout(CursorDefault);
            $("#ButCarica").mouseover(CursorPointer);
            $("#ButCarica").click(function () {
                $("#HFNomeTemplate").attr("value", $("#DDLTemplate option:selected").text());
                PostDatiHidden();
                wait2(true);
                return true;
            });
            $("#ButElimina").mouseout(CursorDefault);
            $("#ButElimina").mouseover(CursorPointer);
            $("#ButElimina").click(function () {
                jConfirm("Eliminare il modello selezionato?", "Report di Rischio - Elimina Modelli", function (r) {
                    if (r) doPostBack("ButElimina");
                });
                return false;
            });

            if ($("#rbl_Privacy input[value='Patrimonio']").attr("disabled") == null &&
             $("#rbl_Privacy input[value='Patrimonio']").attr("checked") == null) {
                //$("#rbl_Privacy input[value='Patrimonio']").click();
                NOPATRI();

            }

            wait2(false);
            if ($("#HFERRORMSG").attr("value") == "1") jAlert("Il modello è stato eliminato correttamente dall’Archivio.", "Report di Rischio - Elimina Modelli");
            if ($("#HFERRORMSG").attr("value") == "2") jAlert("Modello non selezionato.", "Report di Rischio - Elimina Modelli");
            if ($("#HFERRORMSG").attr("value") == "3") jAlert("Errore nella cancellazione.", "Report di Rischio - Elimina Modelli");
            if ($("#HFERRORMSG").attr("value") == "4") jAlert("Il modello è stato salvato correttamente nell’Archivio Modelli.", "Report di Rischio - Salva Modelli");
            if ($("#HFERRORMSG").attr("value") == "5") jAlert("Il modello è stato salvato correttamente nell’Archivio Modelli.", "Report di Rischio - Salva Modelli");
            if ($("#HFERRORMSG").attr("value") == "6") jAlert("Errore nel salvataggio.", "Report di Rischio - Salva Modelli");
            $("#HFERRORMSG").attr("value", "");
            selsel = true;
        });
        function doPostBack(idName) {
            PostDatiHidden();
            $("#" + idName).unbind("click");
            $("#" + idName).click(function () {
                wait2(true);
                return true;
            });
            $("#" + idName).click();
        }
        function wait2(is) {
            if (is) {
                $("#wait2").css("display", "");
            } else {
                $("#wait2").css("display", "none");
            }
        }
        function wait(is) {
            if (is) {
                $("#wait").css("display", "");
            } else {
                $("#wait").css("display", "none");
            }
        }


        function CursorDefault() {

            $(this).css("cursor", "default");
        }
        function CursorPointer() {
            $(this).css("cursor", "pointer");
        }
        function ISDEFAULT(nome) {
            if (nome.length > 3) {
                if (nome.substring(0, 4) == "* - ") return true;
            }
            return false;
        }
        //      function TRIMDEFAULT(nome) {
        //          if (nome.length > 3) {
        //              if (nome.substring(0, 4) == "* - ") return nome.substring(4);
        //          }
        //          return nome;
        //     }

        function PostDatiHidden() {
            $(function () {
                var t = $("#DatiHidden").attr("value");
                //¢ = &cent  
                var charspc1 = ["&cent", "&agrave;", "&egrave;", "&eacute;", "&igrave;", "&ograve;", "&ugrave;", "&Agrave;", "&Egrave;", "&Eacute;", "&Igrave;", "&Ograve;", "&Ugrave;", "&amp;", "&lt;", "&gt;", "&copy;", "&deg;", "&divide;", "&times;", "&iquest;"];
                var charspc2 = ["//g", "/à/g", "/è/g", "/é/g", "/ì/g", "/ò/g", "/ù/g", "/à/g", "/È/g", "/é/g", "/ì/g", "/ò/g", "/ù/g", "/&/g", "/</g", "/>/g", "/©/g", "/°/g", "/÷/g", "/×/g", "/¿/g"];
                for (i = 0; i < charspc1.length; i++)
                    t = t.replace(eval(charspc2[i]), charspc1[i]);
                t = t.substring(0, t.lastIndexOf("var[")) + "var[";
                var tok = "";
                $('#sortable table.TempRpt').each(function () {
                    var msid = $(this).attr("ID").replace("sid", "");
                    t += tok + "'" + lstId[msid] + "'";
                    tok = ",";
                });
                t += "];";
                $("#DatiHidden").attr("value", t);
            });
        }
        function SizeImg() {
            if (!isSizeImg) return;
            perc = 1;
            $("#sortablesdiv img").each(function () {
                $(this).css("width", $(this).attr("widthOld") * perc);
                $(this).css("height", $(this).attr("heightOld") * perc);
            });
            while ($("#sortablesdiv").prop("scrollHeight") > $("#sortablesdiv").height() ||
                     $("#sortablesdiv").prop("scrollWidth") > $("#sortablesdiv").width()) {
                perc = perc <= 0.1 ? 0.1 : perc - 0.1;
                $('#sortablesdiv img').each(function () {
                    $(this).css("width", $(this).attr("widthOld") * perc);
                    $(this).css("height", $(this).attr("heightOld") * perc);
                });
                if (perc <= 0.2) break;
            }
            $("#sortablesdiv img").each(function () {
                $(this).css("width", $(this).attr("widthOld") * perc);
                $(this).css("height", $(this).attr("heightOld") * perc);
            });
        }








        function Touch() {
            $.support.touch = 'ontouchend' in document;
            if (!$.support.touch) return;

            var mouseProto = $.ui.mouse.prototype,
            _mouseInit = mouseProto._mouseInit,
            touchHandled;

            function simulateMouseEvent(event, simulatedType) {
                if (event.originalEvent.touches.length > 1) return;
                event.preventDefault();
                var touch = event.originalEvent.changedTouches[0],
                simulatedEvent = document.createEvent('MouseEvents');
                simulatedEvent.initMouseEvent(
                    simulatedType,    // type
                    true,             // bubbles                    
                    true,             // cancelable                 
                    window,           // view                       
                    1,                // detail                     
                    touch.screenX,    // screenX                    
                    touch.screenY,    // screenY                    
                    touch.clientX,    // clientX                    
                    touch.clientY,    // clientY                    
                    false,            // ctrlKey                    
                    false,            // altKey                     
                    false,            // shiftKey                   
                    false,            // metaKey                    
                    0,                // button                     
                    null              // relatedTarget              
                    );
                event.target.dispatchEvent(simulatedEvent);
            }
            mouseProto._touchStart = function (event) {
                var self = this;
                if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) return;
                touchHandled = true;
                self._touchMoved = false;
                simulateMouseEvent(event, 'mouseover');
                simulateMouseEvent(event, 'mousemove');
                simulateMouseEvent(event, 'mousedown');
            };
            mouseProto._touchMove = function (event) {
                if (!touchHandled) return;
                this._touchMoved = true;
                simulateMouseEvent(event, 'mousemove');
            };
            mouseProto._touchEnd = function (event) {
                if (!touchHandled) return;
                simulateMouseEvent(event, 'mouseup');
                simulateMouseEvent(event, 'mouseout');
                if (!this._touchMoved)
                    simulateMouseEvent(event, 'click');
                touchHandled = false;
            };
            mouseProto._mouseInit = function () {
                var self = this;
                self.element
                    .on('touchstart', $.proxy(self, '_touchStart'))
                    .on('touchmove', $.proxy(self, '_touchMove'))
                    .on('touchend', $.proxy(self, '_touchEnd'));
                _mouseInit.call(self);
            };

        }


        var timerID;
        var queryStringGlobal;
        function generaPDF(url, querystring) {
            bloccaPagina(true);
            queryStringGlobal = querystring;
            window.open(url + "?" + querystring);
            timerID = setInterval('poolInterval()', 1000);
            return;
        }
        function bloccaPagina(boleana) {
            wait(boleana);
        }
        function poolInterval() {
            var ca = document.cookie.split(';');
            for (var i = 0; i < ca.length; i++) {
                var c = ca[i];
                var vcookie = c.split('=');
                if (vcookie[0].replace(/^\s+|\s+$/g, "") == 'endOfJob') {
                    if (vcookie[1] == 1) {
                        clearInterval(timerID);
                        bloccaPagina(false);
                        var url = "reportStampa.aspx?" + queryStringGlobal;
                        window.navigate(url);
                    } else if (vcookie[1] == 2) {
                        clearInterval(timerID);
                        var url = "reportRischioNew.aspx?" + $("#HFRETURN").attr("value");
                        window.navigate(url);
                    }
                    break;
                }
            }
        }



        function checkPresence() {
            var i;
            var found = false;
            var textToFind = trim(document.forms[0].txb_nomeModello.value);

            var lbl_message = document.getElementById('lbl_message');


            if (trim(textToFind) == '') {

                lbl_message.innerText = 'Attenzione. Immettere il nome del modello da salvare.';

                return false;
            }
            else if (textToFind.toUpperCase() == "BASE" || textToFind.toUpperCase() == "COMPLETO") {
                lbl_message.innerText = 'Attenzione. Non è possibile salvare un modello con questo nome, cambiare nome e riprovare con il salvataggio.';
                return false;
            }
            else {

                for (i = 0; i < document.forms[0].ddl_Modello.length; i++) {
                    if (textToFind.toUpperCase() == trim(document.forms[0].ddl_Modello[i].text.toUpperCase())) {
                        found = true;
                    }
                }

                if (found == true) {
                    if (confirm('Un report con questo NOME esiste in archivio. Sovrascriverlo?')) {
                        check_all_in_document(document.forms[0]);
                        return true;
                    }
                    else
                        return false;

                }
                else
                    check_all_in_document(document.forms[0]);
            }
        }

        function trim(stringToTrim) {
            return stringToTrim.replace(/^\s+|\s+$/g, "");
        }

        function CallCheck_all_in_document() {
            check_all_in_document(document.forms[0]);
        }

        function updateTop() {
            parent.frames['TOP'].document.getElementById('lblNavPath').innerHTML = "<%=pathNav%>";

        }

        function TracciaEventoAudit(boid) {

        }  

    </script>
</head>
<body onload="updateTop();">
    <form id="mainForm" runat="server">
    <!-- MODIFICA PER GESTIONE STAMPA e POOL SU CLIENT-->
    <div id="wait" style="display: none; background-color: white; z-index: 3000; position: absolute;
        height: 350px; width: 788px; left: 0px; top: 0px;">
        <asp:Label ID="LBwait" runat="server" Text="ATTENDERE IL COMPLETAMENTO DELLA GENERAZIONE DEL REPORT PREGO...."
            Width="697px" BackColor="#E0E0E0" Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black"
            Style="z-index: 3001; position: absolute; left: 0px; top: 196px;" Font-Bold="True"></asp:Label>
    </div>
    <div id="wait2" style="background-color: white; z-index: 3000; position: absolute;
        height: 350px; width: 788px; left: 0px; top: 0px;">
        <asp:Label ID="LBwait2" runat="server" Text="ATTENDERE IL COMPLETAMENTO OPERAZIONE PREGO..."
            Width="697px" BackColor="#E0E0E0" Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black"
            Style="z-index: 3001; position: absolute; left: 0px; top: 196px;" Font-Bold="True"></asp:Label>
    </div>
    <!-- FINE MODIFICA PER GESTIONE STAMPA e POOL SU CLIENT-->
    <div id="selectorPanel">
        <asp:Label ID="lblTitle" runat="server" CssClass="stateTitle" Style="left: 0px; position: absolute"
            Width="700px">Report di Rischio</asp:Label>
        <asp:Panel ID="rbl_PrivacyPanell" Style="position: absolute; left: 15px; top: 33px;
            background-color: #DCDCDC; z-index: 1000;" runat="server">
            <asp:CheckBoxList ID="rbl_Privacy" runat="server" Style="background-color: #DCDCDC;
                z-index: 1000;">
                <asp:ListItem Value="Nominativa" Text="Crea Reportistica nominativa     "></asp:ListItem>
                <asp:ListItem Value="Patrimonio" Text="Includi patrimonio altri Istituti"></asp:ListItem>
            </asp:CheckBoxList>
            <asp:Button ID="HideOpzioni" runat="server" OnClientClick="return false;" title="Opzioni"
                Style="background-image: url(Images/report/_opzchiuso.JPG); width: 160px; height: 22px;
                border: 0; outline: 0;" />
        </asp:Panel>
        <table id="PDDLTemplate" style="z-index: 1; left: 214px; position: absolute; top: 30px;">
            <tr>
                <td style="vertical-align: middle">
                    <span style="font-size: 13px;">Modelli&nbsp;</span>
                </td>
                <td>
                    <asp:DropDownList ID="DDLTemplate" runat="server" Width="200px" Style="height: 22px;">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:Button ID="ButCarica" runat="server" Style="background-image: url(Images/report/_butcarica.JPG);
                        width: 75px; height: 22px; border: 0" OnClick="ButCarica_Click" />
                </td>
                <td>
                    <asp:Button ID="ButSalva" runat="server" Style="background-image: url(Images/report/_butsalva.JPG);
                        width: 75px; height: 22px; border: 0" OnClick="ButSalva_Click" />
                </td>
                <td>
                    <asp:Button ID="ButElimina" runat="server" Style="background-image: url(Images/report/_butelimina.JPG);
                        width: 75px; height: 22px; border: 0" OnClick="ButElimina_Click" />
                </td>
            </tr>
        </table>
        <table cellpadding="0" cellspacing="0" style="left: 0px; position: absolute; top: 60px;">
            <tr>
                <td>
                    <img id="HideMenu" title="" width="15px" height="350px" src="Images/report/_menuchiuso.jpg" />
                </td>
                <td>
                    <div id="tabs">
                        <ul>
                            <li><a href="#tabs-1">Sintesi</a></li><li><a href="#tabs-2">Rischio Mercato</a></li><li>
                                <a href="#tabs-3">Rischio Credito</a></li><li><a href="#tabs-4">Schede informative</a></li><li>
                                    <a href="#tabs-Tutte">Tutte</a></li></ul>
                        <div style="text-align: right">
                            <asp:Button ID="ButImportaTutto" runat="server" Style="background-image: url(Images/report/_butimportatutto.JPG);
                                width: 100px; height: 22px; border: 0" OnClientClick="return false;" /></div>
                        <div class="tabsdiv" style="overflow: auto; height: 286px;">
                            <div class="rr" id="tabs-1">
                            </div>
                            <div class="rr" id="tabs-2">
                            </div>
                            <div class="rr" id="tabs-3">
                            </div>
                            <div class="rr" id="tabs-4">
                            </div>
                            <div class="rr" id="tabs-Tutte">
                            </div>
                        </div>
                    </div>
                </td>
                <td>
                    <div id="tabsort">
                        <ul>
                            <li><a href="#tabsort-1">Report</a></li></ul>
                        <div style="text-align: right">
                            <asp:Button ID="ButSvuota" runat="server" Style="background-image: url(Images/report/_butsvuota.JPG);
                                width: 75px; height: 22px; border: 0;" /><asp:Button ID="ButStampa" runat="server"
                                    OnClientClick="javascript:check_all_in_document_stampa(document.forms[0]);TracciaEventoAudit('2104');return"
                                    OnClick="ButStampa_Click" Style="background-image: url(Images/report/_butstampa.JPG);
                                    width: 75px; height: 22px; border: 0;" /></div>
                        <div id="sortablesdiv" style="overflow: auto; height: 555px;">
                            <div id="sortable">
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <asp:HiddenField ID="HiddenFieldSezioni" runat="server" />
    <asp:HiddenField ID="HiddenFieldStampa" runat="server" />
    <asp:HiddenField ID="DatiHidden" runat="server" />
    <asp:HiddenField ID="HFNomeTemplate" runat="server" />
    <asp:HiddenField ID="HFOPZTerzi" runat="server" Value="N" />
    <asp:HiddenField ID="HFOPZNominat" runat="server" Value="N" />
    <asp:HiddenField ID="HFidCliente" runat="server" />
    <asp:HiddenField ID="HDMENU" runat="server" Value="0,*" />
    <asp:HiddenField ID="HFERRORMSG" runat="server" Value="" />
    <asp:HiddenField ID="HFERRORMSG2" runat="server" Value="" />
    <asp:HiddenField ID="HFRETURN" runat="server" Value="" />
    <asp:HiddenField ID="HFGENERAPDF" runat="server" Value="" />
    </form>
</body>
</html>