﻿//// GridDialogHelp Class -------------------------------------------

//Properties
GridDialogHelp.prototype.divHelpDialog;
GridDialogHelp.prototype.imgClose;
GridDialogHelp.prototype.spnText;
GridDialogHelp.prototype.imgOpen; //the question mark icon outside the dialog

//Methods
GridDialogHelp.prototype.hide = function ()
{
    this.divHelpDialog.style.visibility = 'hidden';
}

//leave innerHtml blank to keep the default text
GridDialogHelp.prototype.show = function (event, innerHtml)
{
    if(innerHtml != '') 
    {
        //never used, but I wanted to plan ahead a bit
        //for having a single pop up with different text depending
        //on what you click or something
        this.spnText.innerHtml = innerHtml; //this won't work in firefox, need function to do a check and use innerContent
    }

    //we want to align with the right hand edge of the 
    //parent element of the ? icon
    //first get the style of the parent element
    var openingParent = this.imgOpen.parentNode;
    var openingParentStyle = getStyle(openingParent);

    //now get the new left and top style settings based on the placement of the parent
    var newTop = findPosY(openingParent);
    var newLeft = findPosX(openingParent);
    newLeft += pixelsToNum(openingParentStyle.width);
    if(openingParentStyle.paddingLeft)
    {
        newLeft += pixelsToNum(openingParentStyle.paddingLeft);
    }
    if(openingParentStyle.paddingRight)
    {
        newLeft += pixelsToNum(openingParentStyle.paddingRight);
    }
    
    //also figure out the height on the fly
    var newHeight = pixelsToNum(openingParentStyle.height);
    
    this.divHelpDialog.style.top = newTop + 'px';
    this.divHelpDialog.style.left = newLeft + 'px';
    this.divHelpDialog.style.height = newHeight + 'px';
    this.divHelpDialog.style.visibility = 'visible';
    
}

// GridDialogHelp object constructor
//note: could find the img and span tags from the div id, then constructor would just have one arg
function GridDialogHelp(divHelpDialogId, imgCloseId, spnTextId, imgOpenId)
{
    this.divHelpDialog = elm(divHelpDialogId);
    this.imgClose = elm(imgCloseId);
    this.spnText = elm(spnTextId);
    this.imgOpen = elm(imgOpenId);
    
    function assignEventHandlers(currObj) // Creates a new closure so that inside each event handler "this" means the GridDialogGoogleExport object, not the event target
    {
        if(document.addEventListener)
        {
            currObj.imgClose.addEventListener('click', function(event) {currObj.hide(); }, false);
            currObj.imgOpen.addEventListener('click', function(event) {currObj.show(event, ''); }, false);
        }
        else if(document.attachEvent) // IE
        {
            currObj.imgClose.attachEvent('onclick', function(event) {currObj.hide(); }, false);
            currObj.imgOpen.attachEvent('onclick', function(event) {currObj.show(event, ''); }, false);
        }
    };
    assignEventHandlers(this);
}

//// End of GridDialogHelp Class -------------------------------------------
