﻿// -----------------------------------------------------------------------------------------
//             BEGIN DLookup() 
// -----------------------------------------------------------------------------------------
var oDocDL = document;
var ctl_2_change;
var ctlChanged = false;
var MSIE = true;
var id2change;
var caption2Change;
var lookupPage = "/LookupLabel/LookupLabel.aspx";

function itemClick(id, value) {
    id2change.value = id;
    caption2Change.value = value;
    if (window.fnc != undefined && window.isDirty) { window.setTimeout(window.fnc, 100); }
    DLookup();
}
function deleteValue() {
    id2change.value = "0";
    caption2Change.value = "";
    id2change = null;
    caption2Change = null;
    ctlChanged = false;
    removeUtilityFrameDL();
    window.isDirty = true;
    if (window.fnc != undefined) { window.setTimeout(window.fnc, 100); }
}


function DLookup(e, control, ds, dv, dt, cli, fv, _w, showInDoc, functionToExecute, orderBy, showAll) {
    if (functionToExecute != "" && functionToExecute != undefined) { window.fnc = functionToExecute; }
    if (navigator.appName != "Microsoft Internet Explorer") { MSIE = false; };
    if (control != undefined) {
        caption2Change = control;
        var ctlName = control.id;
        id2change = document.getElementById(ctlName.substr(0, ctlName.length - 2));

        if (showInDoc == "") { oDocDL = document; } else { oDocDL = parent.frames[showInDoc].document; parent.frames[showInDoc].targetDoc = document }

        if (oDocDL.getElementById("iUtyDL") == undefined) {
            createUtilityFrameDL("about:blank", showInDoc, _w)
        }
        else {
            //id2change.value='0';
            //caption2Change='';
            try {
                //if (window.fnc != undefined) { window.setTimeout(window.fnc, 100); }
            }
            catch (e) { }
            id2change = null;
            caption2Change = null;
            ctlChanged = false;
            removeUtilityFrameDL();
            return;
        }

        var xFrame = oDocDL.getElementById("iUtyDL");

        if (xFrame.style.visibility == "hidden") {
            var bounds = Sys.UI.DomElement.getBounds(control);
            if (fv != '') {
                if (oDocDL.getElementById(cli + "_" + fv) != undefined) {
                    fv = fv + ":" + oDocDL.getElementById(cli + "_" + fv).value;
                }
                else {
                    fv = fv + ":" + oDocDL.getElementById(fv).value;
                }
            }
            if (xpAlias == undefined) {
                if (xFrame.src != lookupPage + "?ds=" + ds + "&dv=" + dv + "&dt=" + dt + "&fv=" + fv + "&ob=" + orderBy + "&sa=" + showAll) {
                    xFrame.src = lookupPage + "?ds=" + ds + "&dv=" + dv + "&dt=" + dt + "&fv=" + fv + "&ob=" + orderBy + "&sa=" + showAll;
                }
            }
            else {
                if (xFrame.src != lookupPage + "?ds=" + ds + "&dv=" + dv + "&dt=" + dt + "&fv=" + fv + "&ob=" + orderBy + "&pid=" + xpAlias + "&sa=" + showAll) {
                    xFrame.src = lookupPage + "?ds=" + ds + "&dv=" + dv + "&dt=" + dt + "&fv=" + fv + "&ob=" + orderBy + "&pid=" + xpAlias + "&sa=" + showAll;
                }
            }
            if (showInDoc == "") {
                xFrame.style.top = (bounds.y + bounds.height) + "px";
            }
            else {
                xFrame.style.top = "0px";
            }
            xFrame.style.left = bounds.x + "px";

            if (_w == "240px") {
                    xFrame.style.width = bounds.width + "px";
            }
            else { xFrame.style.width = _w }

            xFrame.style.visibility = "";
            xFrame.style.display = "inline";
            xFrame.focus();
        }


    }
    else {
        if (ctl_2_change != undefined && ctlChanged) {
            document.getElementById(ctl_2_change).value = '0';
            document.getElementById(ctl_2_change + "_lbl").value = ''
        }
        else {
            try {
                //if(window.fnc!=undefined){alert("4");execJs();}
            }
            catch (e) { }
        }
        ctl_2_change = null;
        ctlChanged = false;
        removeUtilityFrameDL();
    }
}

function getAbsoluteLeft(oNode) {
    var oCurrentNode = oNode;
    var iLeft = 0;
    while (oCurrentNode.tagName != "BODY") {
        iLeft += oCurrentNode.offsetLeft;
        oCurrentNode = oCurrentNode.offsetParent;
        if (oCurrentNode == undefined) { return iLeft + 2; }
    }
    return iLeft + 2;
}


function createUtilityFrameDL(sUrl, showInDoc, iWidth) {
    if (showInDoc == "") {
        oDocDL = document;
    }
    else
        oDocDL = parent.frames[showInDoc].document;

    var i = oDocDL.createElement("IFRAME");
    i.id = "iUtyDL";
    i.style.visibility = "hidden";
    i.style.display = "none";
    i.style.position = "absolute"
    i.style.zIndex = "10001"
    //if(iWidth!=""){i.style.width=iWidth;}else{i.style.width="250px";}
    i.style.width = iWidth;
    i.style.height = "200px"
    if (MSIE) {
        var namedItem
        namedItem = oDocDL.createAttribute("frameborder");
        namedItem.value = "0";
        i.attributes.setNamedItem(namedItem);

        namedItem = oDocDL.createAttribute("marginheight");
        namedItem.value = "0";
        i.attributes.setNamedItem(namedItem);

        namedItem = oDocDL.createAttribute("marginwidth");
        namedItem.value = "0";
        i.attributes.setNamedItem(namedItem);

        namedItem = oDocDL.createAttribute("scrolling");
        namedItem.value = "auto";
        i.attributes.setNamedItem(namedItem);
    }
    i.style.frameBorder = "0"
    //i.style.borderStyle = "solid"
    //i.style.borderColor = "#ABC1DE"
    //i.style.borderWidth = "1px"
    //i.style.backgroundColor = "#ffffff"
    i.src = sUrl;
    oDocDL.body.appendChild(i);
}
function removeUtilityFrameDL(refresh) {
    if (oDocDL.getElementById("iUtyDL") != undefined) {
        oDocDL.body.removeChild(oDocDL.getElementById("iUtyDL"));
        if (refresh == true) { oDocDL.location.reload(); }
        oDocDL = null;
    }
}

function execJs() {
    var dj_global = this;
    if (window.execScript) {
        if (window.isDirty) {
            window.isDirty = false;
            try {
                window.execScript(window.fnc, "javascript"); return null;
            }
            catch (e) {
                alert("La funzione javascript " + window.fnc + " non esiste oppure ha restituito un errore.");
            }
        }
    }
    else {
        try {
            return dj_global.eval ? dj_global.eval(window.fnc) : eval(window.fnc);
        }
        catch (e) {
            //alert(e);
            alert("La funzione javascript " + window.fnc + " non esiste oppure ha restituito un errore." + e.message);
        }
    }
}





function addNew() {
    var ctl = oDocDL.getElementById("AddNew");

    if (ctl.style.visibility == "hidden") {
        ctl.style.display = "inline";
        ctl.style.visibility = "";
        var ctln = oDocDL.getElementById("NewValue")
        ctln.focus();
        ctln.onkeydown = function() {
            this.value = "";
            this.onmousedown = null;
            this.onkeydown = null;
        }
        ctln.onmousedown = function() {
            this.value = "";
            this.onmousedown = null;
            this.onkeydown = null;
        }
        ctln.onblur = function() {
            if (this.value == "") {
                this.value = "Inserire qui il nuovo valore";
                this.onkeydown = function() {
                    this.value = "";
                    this.onmousedown = null;
                    this.onkeydown = null;
                }
                this.onmousedown = function() {
                    this.value = "";
                    this.onmousedown = null;
                    this.onkeydown = null;
                }
            }
        }
    }
    else {
        ctl.style.display = "none";
        ctl.style.visibility = "hidden";
    }
}
function mDOver(ctl) {
    try {
        ctl.filters.item("DXImageTransform.Microsoft.gradient").Enabled = true;
        ctl.style.borderColor = "#B6D1FF"
    } catch (e) { }
}
function mDOut(ctl) {
    if (ctl.className == "DLr") {
        try {
            ctl.filters.item("DXImageTransform.Microsoft.gradient").Enabled = false
            ctl.style.borderTopColor = "#F5F8FD"
            ctl.style.borderBottomColor = "#E4F1FA"
            ctl.style.borderLeftColor = "#F5F8FD"
            ctl.style.borderRightColor = "#F5F8FD"
        } catch (e) { }
    }
    else {
        try {
            ctl.filters.item("DXImageTransform.Microsoft.gradient").Enabled = false
            ctl.style.borderTopColor = "#FFFFFF"
            ctl.style.borderBottomColor = "#E4F1FA"
            ctl.style.borderLeftColor = "#FFFFFF"
            ctl.style.borderRightColor = "#FFFFFF"
        } catch (e) { }
    }
}
function jLoad() {
    oDocDL.onmouseover = function() {
        if (event.srcElement.tagName == "DIV") {
            mDOver(event.srcElement);
        }
    }
    document.onmouseout = function() {
        if (event.srcElement.tagName == "DIV") {
            mDOut(event.srcElement);
        }
    }
    document.getElementById("search").focus();
}

// -----------------------------------------------------------------------------------------
// -----------------------   END DLookup()  ------------------------------------------------
// -----------------------------------------------------------------------------------------

