
window.pgManager = new function () {
    this.managers = {};
    this.window = document.open();

    this.windowLoad = function (windowName) {
        if (!this.managable(windowName))
            return;
        if (this.managers[windowName]) {
            this.managers[windowName].showDiv();
        }
        else {
            this.createManager(windowName);
            this.managers[windowName].showDiv();
        }
    }

    this.windowUnload = function (windowName) {
        if (!this.managable(windowName) || !this.managers[windowName])
                    return;
        this.managers[windowName].closeDiv();
    }


    this.managable = function (windowName) {
        return (window.frames[windowName] != null);
    }

    this.createManager = function (windowName) {
        this.managers[windowName] = new progressBar(document.getElementById(windowName));
    }
}


// progressBar *****************************************
function progressBar(container) {
    this.panel = null;
    this.utils = new cUtils();
    this.container = container;
    this.init = function (container) {
        this.panel = document.createElement("DIV");
        this.panel.className = 'ajaxProgress';
        var image = document.createElement("img");
        image.src = "/b/i/ajax-loader-big.gif";
        this.panel.appendChild(image);
        container.parentNode.insertBefore(this.panel, container);
        this.showDiv();
    }
    this.resize = function () {
        var size = this.utils.getBounds(this.container);
        this.panel.style.top = size.top;
        this.panel.style.left = size.left;
        this.panel.style.width = size.width;
        this.panel.style.height = size.height;

        this.panel.childNodes[0].style.marginTop = Math.floor((size.height - 66) / 2) + 'px';
    }
    this.closeDiv = function () {
        this.resize();
        this.panel.style.display = '';
    }
    this.showDiv = function () {
        this.panel.style.display = 'none';
    }
    this.init(container);
}
//**************************************************************

function doNavigate_CrmMaster(frName, url) {


    //    if (url.indexOf("?") == -1)
    //        var u = "?";
    //    else
    //        var u = "&";
    // window.pgManager.windowUnloadAll();
    if (frName == "") {
        document.location.href = url; //  + "" + u + "un=" + Date.parse(new Date());
    }
    else {
        var fr = findFrame(window.frames, frName);
        fr.document.location.href = url; //  + "" + u + "un=" + Date.parse(new Date());
    }
}

function findFrame(framesCollection, frName) {
    //    if (window.pgManager)
    //        window.pgManager.windowUnload(frName);
    var fr = framesCollection[frName];
    if (!fr) {
        for (var i = 0; i < framesCollection.length; i++) {
            fr = framesCollection[i].frames[frName]
            if (fr)
                return fr; // break;
        }
        if (!fr && (frName.indexOf('Left') != -1 || frName.indexOf('Right') != -1) && (frName.indexOf('Top') != -1 || frName.indexOf('Bottom') != -1) && framesCollection.length > 3) {
            var frIndex = framesCollection.length - 4 + (frName.indexOf('Left') != -1 ? 0 : 1) + (frName.indexOf('Top') != -1 ? 0 : 1) * 2;
            fr = framesCollection[frIndex];
        }
    }
    return fr;
}

// Reload frame using POST query
function reloadFrm(frameName, argument) {
    var fr = findFrame(top.frames, frameName);
    if (argument == '')
        fr.__doPostBack("reload", ""); // return;
    if (fr && fr.__doPostBack) {
        if (!fr.WebForm_OnSubmit)
            fr.WebForm_OnSubmit = function () { return true; }
        if (argument != null)
            fr.__doPostBack("reload", argument);
        else
            fr.__doPostBack("reload", "");
    }
}

//********************************************************************

cSlussen = function(){}
cSlussen.prototype = {
    // Current theme
    Theme: "SlussColors2",

    // Show customer details in new window
    oCus_Win: function (kprosAllCusID, kcrmLisID) {
        open("/admin/all/allCustomer_Details_Form.aspx?fromPage=popup&prosAllCusID=" + kprosAllCusID + "&crmLisID=" + kcrmLisID,
            null, "menubar=no,toolbar=no,scrollbars=yes,width=1000px,height=700px,resizable=yes");
        return false;
    },
    Cus_FRM: function (kprosAllCusID, kcrmLisID, obj) {
       top.doNavigate_CrmMaster('_FRM_CrmMaster_Right_Bottom_Default', '/admin/all/allCustomer_Details_Form.aspx?prosAllCusID=' + kprosAllCusID + "&crmLisID=" + kcrmLisID);
    },

    // Show person details in new window
    oPer_Win: function (kprosAllCusID, kprosAllPerID, kcrmLisID) {
        open("/admin/all/allPerson_Details_Form.aspx?fromPage=popup&prosAllPerID=" + kprosAllPerID + "&prosAllCusID=" + kprosAllCusID + "&crmLisID=" + kcrmLisID,
            null, "menubar=no,toolbar=no,scrollbars=yes,width=1000px,height=700px,resizable=yes");
        return false;
    },
    Per_FRM: function (kprosAllCusID, kprosAllPerID, kcrmLisID, obj) {
        top.doNavigate_CrmMaster('_FRM_CrmMaster_Right_Bottom_Default', '/admin/all/allPerson_Details_Form.aspx?prosAllCusID=' + kprosAllCusID + '&prosAllPerID=' + kprosAllPerID + "&crmLisID=" + kcrmLisID + "");

    },


    cusInfo_FRM: function (kprosAllCusID, kcrmLisID, obj) {
        top.doNavigate_CrmMaster('_FRM_CrmMaster_Right_Bottom_Default', '/admin/crm/crmCustomerInfo_CustomerInfo_List.aspx?prosAllCusID=' + kprosAllCusID + "&crmLisID=" + kcrmLisID);

    },

    Invoice_FRM: function (kprosAllCusID, kcrmLisID, obj) {
        top.doNavigate_CrmMaster('_FRM_CrmMaster_Right_Bottom_Default', '/admin/finances/admInvoice_CustomerInvoices_List.aspx?prosAllCusID=' + kprosAllCusID + "&crmLisID=" + kcrmLisID);

    },

    Order_FRM: function (kprosAllCusID, kcrmLisID, obj) {
        top.doNavigate_CrmMaster('_FRM_CrmMaster_Right_Bottom_Default', '/admin/finances/proOrder_CustomerOrder_List.aspx?prosAllCusID=' + kprosAllCusID + "&crmLisID=" + kcrmLisID);

    },

    OpenUrl: function (url) {
        if (url.substr(0, 4) != "http")
            url = "http://" + url;
        open(url, "_blank");
    },
    OpenUrlT: function (url, specs) {
        if (specs.length < 1)
            specs = "menubar=no,toolbar=no,scrollbars=yes,width=1000px,height=700px,resizable=yes";
        open(url, null, specs);
        //return false;
    }
    ,
    OpenUrlTx: function (url) {

        myWindow = open(url, null, "menubar=no,toolbar=no,scrollbars=yes,width=1000px,height=700px,resizable=yes");
        myWindow.focus()
       // return false;
    }


};

// creating instance of cSlussen
JS_S = new cSlussen();

