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

<!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></title>
   <%--  <meta http-equiv="X-UA-Compatible" content="IE=8" />--%>
    
   
    
     <link type="text/css" href="./jquery-ui-1.8.20.CSEI/css/ui-lightness/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
     <link href="./jquery-ui-1.8.20.CSEI/alerts-1.1/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" />
     <link href="./jquery-ui-1.8.20.CSEI/alerts-1.1/jquery.Dialog1.css" rel="stylesheet" type="text/css" media="screen" />
     <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
     <script type="text/javascript" src="./jquery-ui-1.8.20.CSEI/js/jquery-1.7.2.min.js"></script>
     <script type="text/javascript" src="./jquery-ui-1.8.20.CSEI/js/jquery-ui-1.8.20.custom.min.js"></script>
     <script src="./jquery-ui-1.8.20.CSEI/alerts-1.1/jquery.alerts.js" type="text/javascript"></script>
     <script src="./jquery-ui-1.8.20.CSEI/alerts-1.1/jquery.Dialog1.js" type="text/javascript"></script>
     <script src="./jquery-ui-1.8.20.CSEI/alerts-1.1/jquery.popupwindow.js"></script>

    <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 () {
            jTooltipObj();
            jTooltip('img');

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

            if ($("#HFERRORMSG").attr("value") == "101") {
                $("#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;
            }



            wait2(true);

            Touch();

            $('#tabs').tabs();
            $('#tabsort').tabs();
            $("#sortable").sortable({
                update: function (event, ui) {
                    //SelezionaSeleziona();
                }
            });

            $("#sortable-2").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");



            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", "Seleziona Scheda");
                    $('table#' + ID + ' img.ModRptA').attr("src", "Images/report/_aggiungi2.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", "Seleziona Scheda");
                    $('table#tutte' + ID + ' img.ModRptA').attr("src", "Images/report/_aggiungi2.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/_noaggiungi2.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/_noaggiungi2.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", "Seleziona Scheda");
                        $('table#' + $(this).attr("ID") + ' img.ModRptA').attr("src", "Images/report/_aggiungi2.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/_noaggiungi2.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() < 400) break;
                }
                $("#sortablesdiv").css("height", $("#sortablesdiv").height() - 7);
                $(".tabsdiv").css("height", $("#sortablesdiv").height());

            } else {

                $("#sortablesdiv").css("height", 500);
                $(".tabsdiv").css("height", $("#sortablesdiv").height());

            }


            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' valign='top' ><img class='ModRptA'  width='19px' height='19px' src='Images/report/_aggiungi2.png' /></td><td><img height='118px' width='157px'/></td><td><div ></div></td></tr></table>";
            var ObjSort = "<table class='TempRpt' style='float:left;width:0;height:0;'><tr><td align='right' valign='top' ><img class='TempRptS'  width='19px' height='19px' title='Elimina Scheda' src='Images/report/_sottrai2.png' /></td><td><img height='118px' width='157px' /></td></tr></table>";
            var ObjTabsMulti = "";

            //*** table.ModRpt
            for (i = 0; i < lstId.length; i++) {
                if (lstVincoli[i].indexOf("&hide") == -1)
                    $("#tabs-" + lstTab[i]).append($(ObjTabs).attr("ID", i));
            }

            $('#tabs a').click(function () {
                GetImportaTutto();
            });


            $(".rr table.ModRpt").each(function () {
                var t = $(this).clone();
                $("#tabs-Tutte").append(t.attr("ID", "tutte" + $(this).attr("id")).removeClass("ModRpt").addClass("ModRptTutte"));
            });

            $('table.ModRpt').each(function () {
                var Index = $(this).attr("ID");
                var padre = $(this);
                var contx = $("table#" + padre.attr("ID") + " , table#tutte" + padre.attr("ID"));
                $("img:not(.ModRptA)", contx).attr("src", "Images/report/" + lstImmagine[Index]);
                $("div", contx).html(lstTesto[Index]);

                if (lstVincoli[Index].indexOf("&disable") == -1) {
                    //if (lstDisable[Index] == "False") {
                    var modrpta = $("img.ModRptA", contx);
                    modrpta.attr("title", "Seleziona Scheda");
                    modrpta.mouseout(CursorDefault);
                    modrpta.mouseover(CursorPointer);

                    modrpta.click(function () {
                        if ($(this).css("opacity") != "1") return;
                        if (lstSezioni[Index] == '136' || lstSezioni[Index] == '135') {
                            $("#sortable-2").append($(ObjSort).attr("ID", "sid" + Index));
                        }
                        else {
                            $("#sortable").append($(ObjSort).attr("ID", "sid" + Index));
                        }
                        var imgScheda = $('table#sid' + Index + ' img:not(.TempRptS)');
                        var imgClick = $('table#sid' + Index + ' img.TempRptS');
                        imgScheda.attr("src", "Images/report/" + lstImmagine[Index]);

                        var title = $(lstTesto[Index]).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#" + Index).show("slow");
                            $('table.ModRptTutte#tutte' + Index).show("slow");
                            $('table#sid' + Index).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");
                            }
                            GetImportaTutto();
                        });

                        padre.css("display", "none");
                        $('table.ModRptTutte#tutte' + Index).css("display", "none");
                        $("#ButSalva").removeAttr("disabled").css("opacity", "1");
                        $("#ButSvuota").removeAttr("disabled").css("opacity", "1");
                        $("#ButStampa").removeAttr("disabled").css("opacity", "1");
                        SizeImg();
                        jTooltip('img');
                        GetImportaTutto();
                        imgScheda.attr("value", "");
                        if (lstDatiMulti[Index] != "") {
                            wait3(true);
                            // Modifica ES 20181012 per Estero-Negozi-Uffici
                            // jDialog1(lstDatiMulti[Index], "<b>Scheda di dettaglio dell\'abitazioni</b>", "Abitazioni", "Seleziona le abitazioni per la quali vuoi creare e stampare la scheda di dettaglio:", function (totrows, selectrows, valuerows) {
                            jDialog1(lstDatiMulti[Index], "<b>Scheda di dettaglio fabbricati</b>", "Fabbricati", "Seleziona i fabbricati per i quali vuoi stampare le schede di dettaglio:", function (totrows, selectrows, valuerows) {
                                if (selectrows != 0) {
                                    var title = $(lstTesto[Index]).text();
                                    title = selectrows + " di " + totrows + " " + title;
                                    imgScheda.attr("title", title);
                                    imgScheda.attr("value", valuerows);
                                    imgScheda.attr("allrows", ( totrows - selectrows == 0) ? 'S' : 'N');                                    
                                    jTooltip('img');
                                } else imgClick.click();
                                wait3(false);
                            });
                        }
                    });
                } else {
                    $("div", contx).css("color", "#909090");
                    $("img.ModRptA", contx).css("opacity", "0.5");
                    $("img.ModRptA", contx).attr("title", "");
                    $("img.ModRptA", contx).attr("src", "Images/report/_noaggiungi2.png");
                    $("img.ModRptA", contx).attr('disabled', 'disabled');
                }
            });




            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();
            }


            $("#tabsortli").click(function () {
                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?", "Nome Modello", ntest, "Salvataggio modello", 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 (oldText == newText) {
                                    $("#HFNomeTemplate").attr("value", newText);
                                    jConfirm("Un modello con il nome “" + oldText + "” è già presente nell’Archivio Modelli. Sovrascrivere il modello esistente?", "Salvataggio modello", 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?", "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 () {
                wait(true);
                var merr = ControlloVincoli();
                if (merr != "") {
                    jAlert(merr, "Warning Report");
                    wait(false);
                } else {
                    var sUrl = "";
                    var sAppIDCatasto = "";
                    var sIDCatasto = "";
                    $('#sortable table.TempRpt').each(function () {
                        var msid = $(this).attr("ID").replace("sid", "");
                        sUrl += "&s=" + lstSezioni[msid];
                    });
                    if (sUrl != "") {
                        sUrl += "&s=137";
                    }
                    $('#sortable-2 table.TempRpt').each(function () {
                        var msid = $(this).attr("ID").replace("sid", "");
                        sUrl += "&s=" + lstSezioni[msid];
                        if (lstDatiMulti[msid] != "") {
                            var sUrl2 = encodeURIComponent($("img:not(.TempRptS)", $(this)).attr("value"));
                            for (i = 0; i < sUrl2.split('.').length; i++) {
                                sAppIDCatasto = sUrl2.split('.')[i];
                                if (sAppIDCatasto.toString().indexOf("%25%25%25") > -1) {
                                    //sUrl += "&ic=" + sIDCatasto.split('.')[i];
                                    //sIDCatasto = sAppIDCatasto.toString().split('.')[i];
                                    //sIDCatasto = sIDCatasto.toString().replace("%25%25%25", ".");

                                    sIDCatasto = sAppIDCatasto.toString().replace("%25%25%25", ".");
                                    sUrl += "&ic=" + sIDCatasto.toString();
                                }
                                else
                                    sUrl += "&ic=" + sAppIDCatasto.toString();
                                
                                //sUrl += "&ccpb=" + sUrl2.split('.')[i + 1];
                            }
                        }
                    });
                    sUrl = "ReportGeneratorWs.aspx?" + sUrl;
                    $.popupWindow(sUrl, {
                        onUnload: function () {
                            wait(false);
                        }
                    });
                }
                return false;
            });



            $("#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("Attenzione. Si è deciso di eliminare il modello “" + $("#DDLTemplate option:selected").text() + "” dall’Archivio Modelli. Continuare?", "Eliminazione modello", 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();
            }

            jTooltip('img');

            wait2(false);
            if ($("#HFERRORMSG").attr("value") == "1") jAlert("Il modello è stato eliminato correttamente dall’Archivio.", "Elimina Modelli");
            if ($("#HFERRORMSG").attr("value") == "2") jAlert("Modello non selezionato.", "Elimina Modelli");
            if ($("#HFERRORMSG").attr("value") == "3") jAlert("Errore nella cancellazione.", "Elimina Modelli");
            if ($("#HFERRORMSG").attr("value") == "4") jAlert("Il modello è stato salvato correttamente nell’Archivio Modelli.", "Salva Modelli");
            if ($("#HFERRORMSG").attr("value") == "5") jAlert("Il modello è stato salvato correttamente nell’Archivio Modelli.", "Salva Modelli");
            if ($("#HFERRORMSG").attr("value") == "6") jAlert("Errore nel salvataggio.", "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 wait3(is) {
            $("#wait3").css("opacity", "0.5");
            if (is) {
                $("#wait3").css("display", "");                
            } else { 
                $("#wait3").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 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]  ;                    
                    if (lstDatiMulti[msid] != "") 
                        t += '.' + $("img:not(.TempRptS)", $(this)).attr("value");                    
                    t += "'";
                    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.05;
                $('#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 GetImportaTutto() {
            if ($("img.ModRptA[disabled!=disabled]", "table.ModRpt:visible,table.ModRptTutte:visible").length > 0) 
                 $("#ButImportaTutto").removeAttr("disabled").css("opacity", "1");
            else $("#ButImportaTutto").attr("disabled", "disabled").css("opacity", "0.5");
        }
        function ControlloVincoli() {
            var merr = "";
            $('#sortable-2 table.TempRpt').each(function () {
                var msid = $(this).attr("ID").replace("sid", "");                
                if (lstDatiMulti[msid] != "") {
                    var allrows = encodeURIComponent($("img:not(.TempRptS)", $(this)).attr("allrows"));
                    if (allrows == 'S' ) { 
                        $('#sortable-2 table.TempRpt').each(function () {
                                var msid = $(this).attr("ID").replace("sid", "");
                                var v1 = lstVincoli[msid].split('&');
                                for (i = 0; i < v1.length; i++) {
                                    var v2 = v1[i].split('_');
                                    if (v2[0]== "SEN") {                      
                                             merr =  v2[1];                                        
                                    }
                                }
                        });
                    }
                }                
            });
           return merr;
        }

       
        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 myWindowPDF = null;
        var timerID;
        var queryStringGlobal;
        function generaPDF(url, querystring) {
            wait(true);
            queryStringGlobal = querystring;
            myWindowPDF = window.open(url + "?" + querystring);
            timerID = setInterval('poolInterval()', 1000);
            return;
        }

        function poolInterval() {
            //           try { 
            //            if (myWindowPDF.document == null);
            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] == 2) {
                        clearInterval(timerID);
                        var url = "SalvaNucleiFamiliari.aspx?" + $("#HFRETURN").attr("value");
                        //window.navigate(url);
                        location.href = url;

                    }
                    break;
                }
            }
            //            } catch (ex) {
            //                clearInterval(timerID);
            //                var url = "reportNucleiFamiliari.aspx?" + $("#HFRETURN").attr("value");
            //                window.navigate(url);
            //            }
        }



        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 TracciaEventoAudit(boid) {

        }

        function Esci() {
            var urlesci = "./SeiEsci.aspx";
            if (window.navigate) {
                window.navigate(urlesci);
            }
            else {
                location.assign(urlesci);
            }

        }

       

    </script>
</head>
<body style="overflow: hidden;">
    <form id="mainForm" runat="server">
   
  
    <table style="z-index:100;left: 0px; top: 0px;position: absolute;width:850px; border-bottom: 1px solid #598395 !important"  cellspacing="0" cellpadding="0">
    <tr>
        <td align="left" style="font-size:14px;font-weight:bold;">&nbsp;&nbsp;Mappatura preliminare - crea report<div id="test"></div></td>
        <td align="right">        
    
        <img  src="Images/report/chiudiX.png" style="cursor: pointer;" title="Chiudi" onclick="Esci();" alt="" />
        </td>
    </tr></table>       
     
    <div id="wait" style="display: none; background-color: white; z-index: 5; position: absolute;
        height: 900px; width: 900px; left: 0px; top: 0px;">
        <asp:Button ID="Button1" runat="server"  style="z-index: 6;font-size:14px; position: absolute; left: 10px; top: 196px;width:850px;text-align:center;"
        Text="ATTENDERE LA STAMPA DEL REPORT..." />         
    </div>
    <div id="wait2" style="background-color: white; z-index: 3; position: absolute;
        height: 900px; width: 900px; left: 0px; top: 0px;">        
        <asp:Button ID="Button2" runat="server"  style="z-index: 4;font-size:14px; position: absolute; left: 10px; top: 196px;width:850px;text-align:center;"
        Text="ATTENDERE IL COMPLETAMENTO OPERAZIONE PREGO..." />
    </div>   
   <div id="wait3" style="opacity:0.5;display: none;background-color: white; z-index: 2; position: absolute;
        height: 900px; width: 900px; left: 0px; top: 0px;">        
       
    </div> 
    
  
    <!-- FINE MODIFICA PER GESTIONE STAMPA e POOL SU CLIENT-->

    <div id="selectorPanel">      
    <br /><br /><br />
        <table id="PDDLTemplate" style="width:850px">
            <%--<tr>
                <td style="width:50%"></td>
                <td style="vertical-align: middle;font-size:12px;">
                     Modelli&nbsp; 
                </td>
                <td>
                    <asp:DropDownList ID="DDLTemplate" runat="server" Width="200px" Style="height: 22px;"></asp:DropDownList>
                </td>
                <td>
                    <asp:Button ID="ButCarica" runat="server" Text="carica"  OnClick="ButCarica_Click" />
                </td>
                <td>
                    <asp:Button ID="ButSalva" runat="server" Text="salva"  OnClick="ButSalva_Click" />
                </td>
                <td>
                    <asp:Button ID="ButElimina" runat="server" Text="elimina"  OnClick="ButElimina_Click" />
                </td>
            </tr>--%>
        </table>


        <table cellpadding="0" cellspacing="0" style="width:850px;" >
            <tr>
                
                <td Width="550px">
                    <div id="tabs">
                        <ul>
                            <li><a href="#tabs-1" style="text-align:center;height:40px;width:110px;">sintesi</a></li>
                            <li><a href="#tabs-2" style="text-align:center;height:40px;width:110px;">dettaglio</a></li> 
                            <li><a href="#tabs-3" style="text-align:center;height:40px;width:110px;">schede PB</a></li>                        
                            <li><a href="#tabs-Tutte" style="text-align:center;height:40px;width:110px;">tutte</a></li>
                        </ul>
                        <p style="text-align: right;" >
                            <asp:Button ID="ButImportaTutto"   Text="inserisci tutte"  style="width:150px;font-size:12px;" runat="server" OnClientClick="return false;" />
                        </p>
                        <div class="tabsdiv" style="overflow: auto; height: 310px;">
                            <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-Tutte"></div>
                        </div>
                    </div>
                </td>
                <td>
                    <div id="tabsort">
                        <ul  >
                            <li><a href="#sortable"  id="tabsortli"  style="text-align:center;height:40px;width:55px;">Report cliente</a></li> 
                            <li><a href="#sortable-2" style="text-align:center;height:40px;width:55px;">schede PB</a></li>
                         </ul>
                        <p style="text-align: right">
                            <asp:Button ID="ButSvuota"  style="font-size:12px;" Text="svuota" runat="server"   />
                            <asp:Button ID="ButStampa"  style="font-size:12px;" runat="server"
                                                              Text="stampa"   /></p>
                        <div id="sortablesdiv" style="overflow: auto; height: 0px;width: 300px;">
                            <div id="sortable">     </div>
                            <div id="sortable-2">    </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="HFERRORMSG" runat="server" Value="" />    
    <asp:HiddenField ID="HFRETURN" runat="server" Value="" />
    <asp:HiddenField ID="HFGENERAPDF" runat="server" Value="" />
    </form>
</body>
</html>