// JavaScript Document
//****************************************************
//*   Idea: Help Object                              *
//*   Methods: o.show(object,e), o.hide(object)      *
//*            o.addItem('text1')                    *
//*   Procedure: hideAll()                           *
//****************************************************

function helpObject()
{
        this.layerList = new Array();
        this.formList = new Array();
        this.width=300; //width of helpbox;
        this. height=30; //height of helpbox
        this.zindex = 101;
        helpObject.prototype.showHelp = showHelp;
        helpObject.prototype.hideHelp = hideHelp;
        helpObject.prototype.hideAll = hideAll;
        helpObject.prototype.AddHelp = AddHelp;
        helpObject.prototype.DelHelp = DelHelp;
        helpObject.prototype.hideForms = hideForms;
        helpObject.prototype.showForms = showForms;
        Array.prototype.IsInArray = IsInArray;
        Array.prototype.arraySeek = arraySeek;
}
function showHelp(object,e)
{

	var coords = new getCoords(e);

	var scr = new getScreenDim()

	if ((coords.posx + this.width)>scr.maxX)
	{
	        x = scr.maxX - this.width - 0
	}
	else
	{
	        x = coords.posx - 0
	}
	if ((coords.posy + this.height)>(coords.maxY + scr.maxY))
	{
	        y = (coords.maxY + scr.maxY)  - 10  - this.height


	}else{
	        y = coords.posy + 10
	}
    self.status = 'max:' + coords.maxY + '  y:'+ coords.posy
	helpObj = new getObj(object);
	helpObj.style.left = x+'px';
	helpObj.style.top = y+'px';
	helpObj.style.zindex = this.zindex;
	helpObj.style.visibility = 'visible'

}

function getObj(name)
{
  if (document.getElementById)
  {
          this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
        this.obj = document.all[name];
        this.style = document.all[name].style;
  }
  else if (document.layers)
  {
           this.obj = document.layers[name];
           this.style = document.layers[name];
  }
}
function getCoords(e)
{
        var posx = 0;
        var posy = 0;
        if (!e) var e = window.event;
        if (e.pageX || e.pageY)
        {
                this.posx = e.pageX;
                this.maxX = 0;
                this.posy = e.pageY;
                this.maxY = e.pageY;
        }
        else if (e.clientX || e.clientY)
        {
                this.posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
                this.maxX = document.body.scrollLeft + document.documentElement.scrollLeft;
                this.posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
                this.maxY = document.body.scrollTop + document.documentElement.scrollTop;
        }
}
function getScreenDim()
{
        var maxX,maxY;
        if (self.innerHeight) // all except Explorer
        {
            this.maxX = self.innerWidth;
            this.maxY = self.innerHeight;

        }
        else if (document.documentElement && document.documentElement.clientHeight)
            // Explorer 6 Strict Mode
        {
            this.maxX = document.documentElement.clientWidth;
            this.maxY = document.documentElement.clientHeight;

        }
        else if (document.body) // other Explorers
        {
            this.maxX = document.body.clientWidth;
            this.maxY = document.body.clientHeight;

        }
}


function hideHelp(object) {
    helpObj = new getObj(object);
    helpObj.style.visibility = 'hidden'
}

function AddHelp()
{
        argc = arguments.length;
        argv = arguments;
        if (argc == 1)
        {
                if (this.layerList.IsInArray(argv[0]))
                {
                        alert('Item of this name already exists')
                }
                else
                {
                        this.layerList[this.layerList.length] = document.getElementById(argv[0]);
                }
        }
        if (argc == 2)
        {
                if (argv[1] == 'form')
                {
                        if (this.formList.IsInArray(argv[0]))
                        {
                                alert('Form of this name already exists')
                        }
                        else
                        {
                                this.formList[this.formList.length] = argv[0];
                        }
                }
        }
}
function DelHelp (Item)
{
        argc = arguments.length;
        argv = arguments;
        if (argc == 1)
        {
                if (!this.layerList.IsInArray(argv[0]))
                {
                        alert('Help item '+Item+' does not exist');
                        return(false)
                }
                else
                {
                        this.layerList.splice(this.layerList.arraySeek(argv[0]),1)
                }
        }
        if (argc == 2)
        {
                if(argv[1]=='form')
                {
                        if (!this.formList.IsInArray(argv[0]))
                        {
                                alert('Help item '+Item+' does not exist');
                                return(false)
                        }
                        else
                        {
                                this.formList.splice(this.formList.arraySeek(argv[0]),1)
                        }
                }
        }

}


function hideAll()
{
        for (c=0;c<this.layerList.length;c++)
        {
                hideHelp(this.layerList[c])
        }
        this.showForms();
}

function hideForms()
{
        for (c=0;c<this.formList.length;c++)
        {
                hideHelp(this.formList[c])
        }
}
function showForms()
{
        for (c=0;c<this.formList.length;c++)
        {
                showObject(this.formList[c])
        }
}
function showObject(object)
{
    helpObj = new getObj(object);
    helpObj.style.visibility = 'visible'

}
function IsInArray(Item)
{
        var isIn = false;
        for (c=0;c<this.length;c++)
        {
                if (this[c] == Item)
                {
                        isIn = true;
                        break;
                }
        }
        return(isIn);
}
function arraySeek(Item)
{
        var index = -1;
        for (c=0;c<this.length;c++)
        {
                if (this[c] == Item)
                {
                        index = c;
                        break;
                }
        }
        return(index);
}

function noRtClick(e,msg)
{
        if (e.button == 2)
        {
                alert(msg);
        }
}