﻿
/*
    Computer Science Group, LLC
    225-766-2397 office
    225-205-0263 cell
    darrell@computersciencegroup.com
    Copyright © 2008 Computer Science Group, LLC, All rights reserved.
*/

function csgIFrameManager(opParentKey_id)
{
    //global used in properties/methods/events
    var oCsgIFrameManager = this;
    /****************************************************************************************
    properties
    ****************************************************************************************/
    this.iFrameArray = new Array();
    this.parentKey_id = opParentKey_id;
    /****************************************************************************************
    methods
    ****************************************************************************************/
    //bringDivToFront(<opCsgIFrame>)
    //08/27/2008
    this.bringDivToFront = function(opCsgIFrame)
    {
        if (opCsgIFrame.isVisible() == true)
        {
            for (var i=0; i<oCsgIFrameManager.iFrameArray.length; i++)
            {
                if ((oCsgIFrameManager.iFrameArray[i].containerDiv.id == opCsgIFrame.containerDiv.id) || (oCsgIFrameManager.iFrameArray[i].headerDiv.id == opCsgIFrame.headerDiv.id))
                {
                    oCsgIFrameManager.iFrameArray[i].containerDiv.style.zIndex = 100;
                    
                    if (oCsgIFrameManager.iFrameArray[i].isVisible() == false) { oCsgIFrameManager.iFrameArray[i].show(); }
                }
                else
                {
                    oCsgIFrameManager.iFrameArray[i].containerDiv.style.zIndex = 10;
    //                if (oCsgIFrameManager.iFrameArray[i].isVisible() == false) { oCsgIFrameManager.iFrameArray[i].show(); }
                }
            }
        }
    }
    //toolBarClick(<opCsgIFrame>)
    //08/27/2008
    this.toolBarClick = function(opCsgIFrame)
    {
        var oGridHidden;
        if (opCsgIFrame.isVisible() == true) { oCsgIFrameManager.bringDivToFront(opCsgIFrame); }
        else
        {
            if (oCsgIFrameManager.csgGrid)
            {
                oGridHidden = oCsgIFrameManager.csgGrid.getGridHiddenField(oCsgIFrameManager.parentKey_id);
                if (oGridHidden) { oCsgIFrameManager.postBackIFrame(opCsgIFrame, oGridHidden.value, true); }
            }
            else
            {
                if (opCsgIFrame.isVisible() == false) { opCsgIFrame.show(); }
            }
            oCsgIFrameManager.bringDivToFront(opCsgIFrame);
        }
    }
    //postBackAllFrames()
    //12/09/2008
    this.postBackAllFrames = function()
    {
        var oGridHidden;
        if (oCsgIFrameManager.parentKey_id)
        {
            oGridHidden = oCsgIFrameManager.csgGrid.getGridHiddenField(oCsgIFrameManager.parentKey_id);
            if (oGridHidden)
            {
                for (var i=0; i<oCsgIFrameManager.iFrameArray.length; i++)
                {
                    if (oCsgIFrameManager.iFrameArray[i].isPostBackFromParent == true)
                    {
                        if (oCsgIFrameManager.iFrameArray[i].isVisible() == true)
                        {
                            oCsgIFrameManager.postBackIFrame(oCsgIFrameManager.iFrameArray[i], oGridHidden.value, true);
                        }
                    }
                }
            }
        }
    }
    //postBackIFrame(<opCsgIFrame>, <opValue>, <opShow>)
    //08/27/2008
    this.postBackIFrame = function(opCsgIFrame, opValue, opShow)
    {
        var orowsCount;
        var orowNumber;
        var ogridIndex;
        var oContentWindowCsgGrid;
        var oHidden;
        var oGridHidden;
        var oContentWindow;
        if ((opCsgIFrame.isVisible() == true) || (opShow == true))
        {
            //iframe window
            oContentWindow = opCsgIFrame.iFrame.contentWindow;
            if (oContentWindow)
            {
                //iframe grid
                oContentWindowCsgGrid = oContentWindow.window.ocsgGrid;
                if (oContentWindowCsgGrid)
                {
                    //grid hidden field for <oCsgIFrameManager.parentKey_id>
                    oGridHidden = oContentWindow.document.getElementById(oContentWindowCsgGrid.gridID + "_" + oCsgIFrameManager.parentKey_id);
                    if (oGridHidden)
                    {
                        //set the grid hidden field <oCsgIFrameManager.parentKey_id> value to the same as the <oCsgIFrameManager.parentKey_id> on this page
                        oGridHidden.value = opValue;
                    }
                    oHidden = oContentWindow.document.getElementById(oCsgIFrameManager.parentKey_id);
                    //the hidden field used in the c# updates
                    if (oHidden)
                    {
                        //set the hidden field <oCsgIFrameManager.parentKey_id> value to the same as the <oCsgIFrameManager.parentKey_id> on this page
                        //so it will be available to c#
                        oHidden.value = opValue;
                    }
                    orowsCount = oContentWindow.document.getElementById("__" + oContentWindowCsgGrid.gridID + "_rowsCount");
                    if (orowsCount) { orowsCount.value = "0"; }
                    //always reset the row number to 1, grid index to zero
                    ogridIndex = oContentWindow.document.getElementById("__" + oContentWindowCsgGrid.gridID + "_gridIndex");
                    if (ogridIndex) { ogridIndex.value = "1"; }
                    orowNumber = oContentWindow.document.getElementById("__" + oContentWindowCsgGrid.gridID + "_rowNumber");
                    if (orowNumber) { orowNumber.value = "1"; }
                    //initialize controls on iframe window
                    oContentWindowCsgGrid.initializeControls();
                    //postback iframe window
                    oContentWindowCsgGrid.postBack();
                    //show the iframe (maybe)
                    if (opShow == true) { opCsgIFrame.show(); }
                }
                else { if (opShow == true) { opCsgIFrame.show(); } }
            }
        }
    }
}