﻿
    function SearchHelper(pBlnShow, pTxtSearch, pLblSearch)
    {
        var lObjSearchTxt;
        var lObjSearchLbl;
        var lBlnShowLabel = false;
        
        // Get the objects
        lObjSearchTxt = document.getElementById(pTxtSearch);
        lObjSearchLbl = document.getElementById(pLblSearch);

        if(lObjSearchTxt != null && lObjSearchLbl != null)
        {
            if(pBlnShow && lObjSearchTxt.value == "")
            {
                // Show the label
                lBlnShowLabel = true;
            }
        }
        
        if(lObjSearchLbl != null)
        {
            // Show or Hide the label
            if(lBlnShowLabel)
            {
                lObjSearchLbl.className = "searchInsideLabel";
            }
            else
            {
                lObjSearchLbl.className = "hideLabel";
            }
        }
    }


    function AdjustNavigation(navLink, subMenuItem, topMenuItem)
    {
	    var objTopNavLink = document.getElementById(navLink);
	    var objSubMenu = document.getElementById(subMenuItem);
	    var objTopNavItem = document.getElementById(topMenuItem);

        if(objTopNavLink != null && objSubMenu != null && objTopNavItem != null)
        {
	        var subPadding = 0;
	        var leftTopMenu = findPosX(objTopNavItem);
	        var widthSubMenu = objSubMenu.offsetWidth;
	        var rightTopMenu = findPosX(objTopNavItem) + objTopNavItem.offsetWidth;
	        var widthWindow = document.body.clientWidth;
	        var rightSubMenu = findPosX(objTopNavLink) + objSubMenu.offsetWidth;
	        var rightSubDiff = widthWindow - rightSubMenu;
	        var rightMarginSub = objSubMenu.offsetWidth - objTopNavItem.offsetWidth;
	        var middleMarginSub = rightMarginSub / 2;
	        var leftMiddleSubMenu = leftTopMenu + (middleMarginSub * -1);
	        var rightMidleSubMenu = rightTopMenu + middleMarginSub;

	        // Check if the sub menu is off the right side
	        if(rightSubDiff < 0)
	        {
		        // Check if the item can be centered
		        if(leftMiddleSubMenu > 0 && rightMidleSubMenu < widthWindow)
		        {
			        subPadding = middleMarginSub * -1;
		        }
		        else if(leftTopMenu > rightMarginSub)
		        {
			        subPadding = rightMarginSub * -1;
		        }
		        else if(widthSubMenu < widthWindow)
		        {
			        // Check if the alignment should come the left side
			        if(widthWindow - leftTopMenu > leftTopMenu)
			        {
				        var leftFudgeSubMenu = leftTopMenu;
				        leftFudgeSubMenu -= 1;

				        subPadding = leftFudgeSubMenu * -1;
			        }
			        else
			        {
				        var leftFudgeSubMenu = widthSubMenu - (widthWindow - leftTopMenu);
				        leftFudgeSubMenu += 1;

				        subPadding = leftFudgeSubMenu * -1;
			        }
		        }
	        }

	        if(objSubMenu.style.marginLeft == "")
		        objSubMenu.style.marginLeft == "0px"

	        if(parseInt(objSubMenu.style.marginLeft) != parseInt(subPadding))
		        objSubMenu.style.marginLeft = subPadding + "px";
        }
    }


    function findPosX(obj)
    {
        var curleft = 0;
        
        if(obj.offsetParent)
        while(1)
        {
            curleft += obj.offsetLeft;
            if(!obj.offsetParent)
            break;
            obj = obj.offsetParent;
        }
        else if(obj.x)
            curleft += obj.x;
        
        return curleft;
    }

    function openWin(w,h,page,s) 
	{
		var thisPlatform
		var thisBrowser
		var win
		
			
		//sniffing for browser and platform
		thisBrowser = navigator.userAgent
		thisPlatform = navigator.platform;
		
		if (thisPlatform == "MacPPC") {
			if (thisBrowser.indexOf("MSIE") != -1) {
				win=window.open(page , "POP", "width=" + w + ",height=" + h + ",left=0,top=0,toolbar=no,scrollbars=" + s)
			} else {
				win=window.open(page , "POP", "width=" + w + ",height=" + h + ",left=0,top=0,toolbar=no,scrollbars=" + s)
			}
		} else {
			win=window.open(page , "POP", "width=" + w + ",height=" + h + ",left=0,top=0,toolbar=no,scrollbars=" + s)
		}
		 
		win.focus();
	}    
    function Popup(page)
    {
        var OpenWin;
        OpenWin = window.open(page, '', 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=10,height=10');
        close();
    }

    function onPopup(page) {
	    OpenWin = this.open(page, "CtrlWindow", "toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=yes,width=640,height=575,left=100,top=24");
    }
    
  function closeGoBack(pStrReferrerUrl)
      {
        var lObjShadow = parent.document.getElementById('sb-content');        
        
        if(lObjShadow != null && typeof parent.Shadowbox != "undefined")
			parent.Shadowbox.close();
        else
        {
            if (pStrReferrerUrl != "")
                window.location.href = pStrReferrerUrl;
	        else
		        window.close();
        }
    }
