/**
* Filename.......: help.js
* Project........: Generic EPSS script
* Last Modified..: $Date: 2007/04/20 $
* CVS Revision...: $Revision: 3.1 $
* Copyright......: C.C.L. Zodan.nl
*/

/**
* Global variables
*/
	dynHelp_layers          = new Array();
	dynHelp_mouseoverStatus = false;
	dynHelp_mouseX          = 0;
	dynHelp_mouseY          = 0;

/**
* The calendar constructor
*
* @access public
* @param string objName      Name of the object that you create
* @param string callbackFunc Name of the callback function
* @param string OPTIONAL     Optional layer name
* @param string OPTIONAL     Optional images path
*/
	function dynHelp(objName, myHTML)
	{
		/**
        * Properties
        */
		// Todays date
		this.today          = new Date();
		this.date           = this.today.getDate();
		this.month          = this.today.getMonth();
		this.year           = this.today.getFullYear();

		this.objName        = objName;
		this.html			= myHTML;
		this.imagesPath     = arguments[3] ? arguments[3] : 'img/';
		this.layerID        = arguments[4] ? arguments[4] : 'dynHelp_layer_' + dynHelp_layers.length;

		this.offsetX        = arguments[2] ? arguments[2] : 0;
		this.offsetY        = 0;

		this.useMonthCombo  = true;
		this.useYearCombo   = true;
		this.yearComboRange = 5;

		this.currentMonth   = this.month;
		this.currentYear    = this.year;

		/**
        * Public Methods
        */
		this.show              = dynHelp_show;
		this.writeHTML         = dynHelp_writeHTML;

		// Accessor methods
		this.setOffset         = dynHelp_setOffset;
		this.setOffsetX        = dynHelp_setOffsetX;
		this.setOffsetY        = dynHelp_setOffsetY;
		this.setImagesPath     = dynHelp_setImagesPath;

		/**
        * Private methods
        */
		// Layer manipulation
		this._getLayer         = dynHelp_getLayer;
		this._hideLayer        = dynHelp_hideLayer;
		this._showLayer        = dynHelp_showLayer;
		this._setLayerPosition = dynHelp_setLayerPosition;
		this._setHTML          = dynHelp_setHTML;

		// Miscellaneous
		this._mouseover        = dynHelp_mouseover;

		/**
        * Constructor type code
        */
		dynHelp_layers[dynHelp_layers.length] = this;
		this.writeHTML();
	}

/**
* Shows the calendar, or updates the layer if
* already visible.
*
* @access public
* @param integer month Optional month number (0-11)
* @param integer year  Optional year (YYYY format)
*/
	function dynHelp_show()
	{
		// Variable declarations to prevent globalisation
		var html;

		html = '<div class="closebar"><a href="javascript: ' + this.objName + '._hideLayer()"><img src="' + this.imagesPath + 'close.gif" border="0" alt="plaatje: help aflsuiten" title="klik hier om de help te sluiten" /></a>HELP</div>';
		html += this.html;


		this._setHTML(html);
		if (!arguments[0] && !arguments[1]) {
			this._showLayer();
			this._setLayerPosition();
		}
	}

/**
* Writes HTML to document for layer
*
* @access public
*/
	function dynHelp_writeHTML()
	{
		if (is_ie5up || is_nav6up || is_gecko) {
			document.write('<a href="javascript: ' + this.objName + '.show()"><img class="helpbutton" src="' + this.imagesPath + 'help.gif" border="0" /></a>');
			document.write('<div class="dynHelp" id="' + this.layerID + '" onmouseover="' + this.objName + '._mouseover(true)" onmouseout="' + this.objName + '._mouseover(false)"></div>');
		}
	}

/**
* Sets the offset to the mouse position
* that the calendar appears at.
*
* @access public
* @param integer Xoffset Number of pixels for vertical
*                        offset from mouse position
* @param integer Yoffset Number of pixels for horizontal
*                        offset from mouse position
*/
	function dynHelp_setOffset(Xoffset, Yoffset)
	{
		this.setOffsetX(Xoffset);
		this.setOffsetY(Yoffset);
	}

/**
* Sets the X offset to the mouse position
* that the calendar appears at.
*
* @access public
* @param integer Xoffset Number of pixels for horizontal
*                        offset from mouse position
*/
	function dynHelp_setOffsetX(Xoffset)
	{
		this.offsetX = Xoffset;
	}

/**
* Sets the Y offset to the mouse position
* that the calendar appears at.
*
* @access public
* @param integer Yoffset Number of pixels for vertical
*                        offset from mouse position
*/
	function dynHelp_setOffsetY(Yoffset)
	{
		this.offsetY = Yoffset;
	}
	
/**
* Sets the images path
*
* @access public
* @param string path Path to use for images
*/
	function dynHelp_setImagesPath(path)
	{
		this.imagesPath = path;
	}


/**
* Returns the layer object
*
* @access private
*/
	function dynHelp_getLayer()
	{
		var layerID = this.layerID;

		if (document.getElementById(layerID)) {

			return document.getElementById(layerID);

		} else if (document.all(layerID)) {
			return document.all(layerID);
		}
	}

/**
* Hides the calendar layer
*
* @access private
*/
	function dynHelp_hideLayer()
	{
		this._getLayer().style.visibility = 'hidden';
	}

/**
* Shows the calendar layer
*
* @access private
*/
	function dynHelp_showLayer()
	{
		this._getLayer().style.visibility = 'visible';
	}

/**
* Sets the layers position
*
* @access private
*/
	function dynHelp_setLayerPosition()
	{
		this._getLayer().style.top  = (dynHelp_mouseY + this.offsetY) + 'px';
		this._getLayer().style.left = (dynHelp_mouseX + this.offsetX) + 'px';
	}

/**
* Sets the innerHTML attribute of the layer
*
* @access private
*/
	function dynHelp_setHTML(html)
	{
		this._getLayer().innerHTML = html;
	}


/**
* onMouse(Over|Out) event handler
*
* @access private
* @param boolean status Whether the mouse is over the
*                       calendar or not
*/
	function dynHelp_mouseover(status)
	{
		dynHelp_mouseoverStatus = status;
		return true;
	}

/**
* onMouseMove event handler
*/
	dynHelp_oldOnmousemove = document.onmousemove ? document.onmousemove : new Function;

	document.onmousemove = function ()
	{
		if (is_ie5up || is_nav6up || is_gecko) {
			if (arguments[0]) {
				dynHelp_mouseX = arguments[0].pageX;
				dynHelp_mouseY = arguments[0].pageY;
			} else {
				dynHelp_mouseX = event.clientX + document.body.scrollLeft;
				dynHelp_mouseY = event.clientY + document.body.scrollTop;
				arguments[0] = null;
			}
	
			dynHelp_oldOnmousemove();
		}
	}

/**
* Callbacks for document.onclick
*/
	dynHelp_oldOnclick = document.onclick ? document.onclick : new Function;

	document.onclick = function ()
	{
		if (is_ie5up || is_nav6up || is_gecko) {
			if(!dynHelp_mouseoverStatus){
				for(i=0; i<dynHelp_layers.length; ++i){
					dynHelp_layers[i]._hideLayer();
				}
			}
	
			dynHelp_oldOnclick(arguments[0] ? arguments[0] : null);
		}
	}