﻿
/*
    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 csgIFrame(opContainerDivID, opHeaderDivID, opHeaderDivImgID, opIFrameID, opTop, opLeft, opHeight, opWidth)
{
    var oDiv;
    //global used in properties/methods/events
    var oCsgIFrame = this;
    this.isPostBackFromParent = true;
    /****************************************************************************************
    properties
    ****************************************************************************************/
    //need the container Div
    this.containerDiv = document.getElementById(opContainerDivID);
    if (!this.containerDiv)
    {
        alert("The container DIV " + opContainerDivID + " was not found.");
        return;
    }
    this.containerDiv.className = "csgIFrameDivContainer";
    if (this.containerDiv.style.display != "block")
    {
        if (opTop) { this.containerDiv.style.top = opTop; }
        if (opLeft) { this.containerDiv.style.left = opLeft; }
        if (opHeight) { this.containerDiv.style.height = opHeight; }
        if (opWidth) { this.containerDiv.style.width = opWidth; }
    }
    //need the header Div
    this.headerDiv = document.getElementById(opHeaderDivID);
    if (!this.headerDiv)
    {
        alert("The header DIV " + opHeaderDivID + " was not found.");
        return;
    }
    this.headerDiv.className = "csgIFrameDivHeader";
    //need the header Div Img
    this.headerDivImg = document.getElementById(opHeaderDivImgID);
    if (!this.headerDivImg)
    {
        alert("The header DIV Img " + opHeaderDivImgID + " was not found.");
        return;
    }
    this.headerDivImg.className = "csgIFrameDivHeaderImg";
//    this.headerDivImg.src = oCsgIFrame.imagePath + "csgIframeClose.gif";
    this.headerDivImg.src = __imagesPath + "csgIframeClose.gif";
    this.headerDivImg.alt = "Close this window.";
    //need the iframe
    this.iFrame = document.getElementById(opIFrameID);
    if (!this.iFrame)
    {
        alert("The IFrame " + opIFrameID + " not found.");
        return;
    }
    this.iFrame.className = "csgIFrame";
    if (opHeight) { this.iFrame.style.height = opHeight; }
    if (opWidth) { this.iFrame.style.width = opWidth; }
    //
    this.moving = false;
    this.offsetX = false;
    this.offsetY = false;
    /****************************************************************************************
    header div events
    ****************************************************************************************/
    //onmouseout
    this.onMouseOut = function() { oCsgIFrame.moving = false; }
    this.headerDiv.onmouseout = oCsgIFrame.onMouseOut;
    //onmousedown
    this.onMouseDown = function()
    {
        oCsgIFrame.moving = true;
        oCsgIFrame.offsetY = event.clientY - (oCsgIFrame.containerDiv.style.top).replace("px","");
        oCsgIFrame.offsetX = event.clientX - (oCsgIFrame.containerDiv.style.left).replace("px","");
    }
    this.headerDiv.onmousedown = oCsgIFrame.onMouseDown;
    //onmouseup
    this.onMouseUp = function() { oCsgIFrame.moving = false; }
    this.headerDiv.onmouseup = oCsgIFrame.onMouseUp;
    //onmousemove
    this.onMouseMove = function() { if (oCsgIFrame.moving == true) { oCsgIFrame.moveTheDiv(); } }
    this.headerDiv.onmousemove = oCsgIFrame.onMouseMove;
    //onclick
    this.headerDivOnClick = function()
    {
        if (ocsgPage.headerDivOnClick) { ocsgPage.headerDivOnClick(oCsgIFrame); }
    }
    this.headerDiv.onclick = oCsgIFrame.headerDivOnClick;
    /****************************************************************************************
    header div img events
    ****************************************************************************************/
    //onmouseover
//    this.headerDivImgOnMouseOver = function() { oCsgIFrame.headerDivImg.src = oCsgIFrame.imagePath + "csgIFrameCloseSelected.gif"; }
    this.headerDivImgOnMouseOver = function() { oCsgIFrame.headerDivImg.src = __imagesPath + "csgIFrameCloseSelected.gif"; }
    this.headerDivImg.onmouseover = oCsgIFrame.headerDivImgOnMouseOver;
    //onmouseout
//    this.headerDivImgOnMouseOut = function() { oCsgIFrame.headerDivImg.src = oCsgIFrame.imagePath + "csgIFrameClose.gif"; }
    this.headerDivImgOnMouseOut = function() { oCsgIFrame.headerDivImg.src = __imagesPath + "csgIFrameClose.gif"; }
    this.headerDivImg.onmouseout = oCsgIFrame.headerDivImgOnMouseOut;
    //onclick
    this.headerDivImgOnClick = function()
    {
        oCsgIFrame.hide();
    }
    this.headerDivImg.onclick = oCsgIFrame.headerDivImgOnClick;
    /****************************************************************************************
    iframe events
    ****************************************************************************************/
    //onclick
    this.iFrameOnClick = function()
    {
        if (ocsgPage.iFrameOnClick) { ocsgPage.iFrameOnClick(oCsgIFrame); }
    }
    this.iFrame.contentWindow.document.onclick = oCsgIFrame.iFrameOnClick;
    /****************************************************************************************
    methods
    ****************************************************************************************/
    this.moveTheDiv = function()
    {
        var iTop;
        var iLeft;
        var iOffsetTop;
        var iOffsetLeft;
        oCsgIFrame.containerDiv.style.top = event.clientY - oCsgIFrame.offsetY;
        oCsgIFrame.containerDiv.style.left = event.clientX - oCsgIFrame.offsetX;
        document.selection.empty();
    }
    this.show = function() { oCsgIFrame.containerDiv.style.display = "block"; }
    this.hide = function() { oCsgIFrame.containerDiv.style.display = "none"; }
    this.isVisible = function() { return (oCsgIFrame.containerDiv.style.display == "block") }
    //setCaption(<spCaption>)
    //11/06/2009
    this.setCaption = function(spCaption)
    {
        try { oCsgIFrame.headerDivImg.nextSibling.innerText = spCaption; }
        catch (e) {}
    }
}