/** 
 * Java script file for helper component
 *
 * @version 2.0.1
 * @author Kalosha Eugene <aristarch@zfort.net>
 */

    var hlpObjectOffset = 30;
    var lastShowedHelper = false;
    
    function ShowHelpInHelper(hlpObject, hlpShow, controlID)
    {
        hlpObjectID = hlpObject;
    	hlpObject = document.getElementById(hlpObject);
    	hlpObject.style.display = hlpShow ? "inline" : "none";
    	
    	if (lastShowedHelper && (document.getElementById(lastShowedHelper)) && (lastShowedHelper != hlpObjectID))
    	{
    	    document.getElementById(lastShowedHelper).style.display = "none";
    	}
    	lastShowedHelper = hlpObjectID;
    	
    	timerID = setTimeout("autoHide('" + hlpObjectID + "')", 10000); 
    	
    	if (hlpShow && controlID && (document.getElementById(hlpObjectID + "_image") == null))
    	{
    	    posX = findPosX(document.getElementById(controlID));
    	    posY = findPosY(document.getElementById(controlID));
    	    hlpObject.style.left = posX + document.getElementById(controlID).offsetWidth + "px";
    	    hlpObject.style.top = posY + "px";
    	}
    	
    	if (hlpShow /*&& (document.getElementById(hlpObjectID + "_image") != null)*/)
    	{
    	    hlpIcon = (document.getElementById(hlpObjectID + "_image") != null) ? document.getElementById(hlpObjectID + "_image") : document.getElementById(controlID);
    	    
    	    posX = findPosX(hlpObject);
    	    isOffsetSituation = false;
    	    if((posX + hlpObject.offsetWidth) >=  getBrowserWidth())
    	    {
    	        offsetLeft = findPosX(hlpIcon);
    	        offsetWidth = hlpObject.offsetWidth;
  	            hlpObject.style.left = (offsetLeft - offsetWidth - hlpObjectOffset) + "px";
   	            hlpObject.style.right = (offsetLeft - hlpObjectOffset) + "px";
    	    }
    	    
    	}
    }
    
    function autoHide(hlpObject)
    {
        document.getElementById(hlpObject).style.display = "none";
    }
    
    function showPopupHelp(helpMessageControl, width, height)
    {
        windowProps = "left=0,top=0,width=" + (width + 30) + ",height=" + (height + 30) + "";
    
        text = "<html><head><title>Preview</title></head><body>" + document.getElementById(helpMessageControl).innerHTML + "<br><br><center><input type='button' value='Close' onclick='window.close()'></center></body></html>";
        preview = window.open("", "preview", windowProps);
        preview.document.open();
        preview.document.write(text);
        preview.document.close();
    }
    
    		// *** Find an element position (http://www.quirksmode.org/js/findpos.html) *** //
    function findPosX(obj)
    {
    	var curleft = 0;
    	if (obj.offsetParent)
    	{
    		while (obj.offsetParent)
    		{
    			curleft += obj.offsetLeft
    			obj = obj.offsetParent;
    		}
    	}
    	else if (obj.x)
    		curleft += obj.x;
    	return curleft;
    }
    
    function findPosY(obj)
    {
    	var curtop = 0;
    	if (obj.offsetParent)
    	{
    		while (obj.offsetParent)
    		{
    			curtop += obj.offsetTop
    			obj = obj.offsetParent;
    		}
    	}
    	else if (obj.y)
    		curtop += obj.y;
    	return curtop;
    }
    	// *** END OF : Find an element position (http://www.quirksmode.org/js/findpos.html) *** //
    	
	function getBrowserWidth()
	{
        if (window.innerWidth)
        {
            return window.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientWidth != 0)
        {
            return document.documentElement.clientWidth;
        }
        else if (document.body)
        {
            return document.body.clientWidth;
        }
        
        return 0;
    }
