﻿/* 
    This javascript class is used to show a popup login div on the same page.
*/
var InPagePopupCurrentEl = null;

//This global scope method shows/hides the in page popup
function ShowInPagePopup(Tag, Div)
{
        if(Tag == 1) //HIDE the inpage popup
        {
            //hide page overlay
			document.getElementById("InPageDiv1").style.display = "none";
			
			//show "select" elements on the page again
            ToggleSeeThruItems("visible");
            
            //hide the currently showing in page popup
            if(InPagePopupCurrentEl)InPagePopupCurrentEl.style.display = "none";
            
            //set hidden field indicating the popup is now hidden
            if(document.forms[0].LoginDlg)document.forms[0].LoginDlg.value = 'N';
        }
        else if(Tag == 0) //SHOW the inpage popup
        {
            //set the page overlay to the total height of the page
            GetBlackDivHeight();
            
            //get the window scroll top
            var scrOfY = 0;
            if( typeof( window.pageYOffset ) == 'number' ) 
            {
                //Netscape compliant
                scrOfY = window.pageYOffset;
            } 
            else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
            {
                //DOM compliant
                scrOfY = document.body.scrollTop;
            } 
            else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
            {
                //IE6 standards compliant mode
                scrOfY = document.documentElement.scrollTop;
            }
        
            //set popup dom referance
            var divName = (Div != null) ? Div : "LoginDiv";
            InPagePopupCurrentEl = document.getElementById(divName);
            
            //set the popup top location
            InPagePopupCurrentEl.style.top = scrOfY + 100 + 'px';
            
            //show page overlay
			document.getElementById("InPageDiv1").style.display = "block";
			
			//set the page content to a low z-index (so it's sure to be under the overlay)
			if(document.getElementById("maincontent"))
			    document.getElementById("maincontent").style.zIndex = "80";
			
			//hide "select" elements on the page so they don't show through the overlay in older browsers
			ToggleSeeThruItems("hidden");
			
			//show the in page popup
            InPagePopupCurrentEl.style.display = "block";
            
            //set the window focus to the first input field
            FocusFirstTextbox("divLoginInput");
            
            //set hidden field indicating the popup is now showing
            if(document.forms[0].LoginDlg)document.forms[0].LoginDlg.value = 'Y';
        }              
    }
    
    function GetBlackDivHeight()
    {
        var height = 0;
        var docElHeight = 0;
        var bodyHeight = 0;
        var crnrDiv = findObjPos(document.getElementById("LowerRightCornerDiv"),"Y");
        
        if(self.innerHeight != null)
            height = self.innerHeight;
        
        if(document.documentElement.clientHeight != null)
            docElHeight = document.documentElement.clientHeight;
          
        if(document.body.clientHeight != null);
            bodyHeight = document.body.clientHeight;
        
        if(crnrDiv > bodyHeight)
            bodyHeight = crnrDiv;
        
        if(bodyHeight > docElHeight)
            docElHeight = bodyHeight;
        
        if(docElHeight > height)
            height = docElHeight;
        
        var InPageDivObj = document.getElementById("InPageDiv1");
        InPageDivObj.style.height = height + 'px';
    }
    
    function getFullHeight() 
	{
		if (window.innerHeight!=window.undefined) return window.innerHeight;
		if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
		if (document.body) return document.body.clientHeight; 
		return undefined; 
	}
    
    function ToggleSeeThruItems(Visibility)
    {
        try
        {
            var Count = 0;
            if(Visibility == "hidden")
            {
                for(i=0; i < PageForm.elements.length; i++)
                {
                    try
                    {
                        if(PageForm.elements[i].type.indexOf("select") >= 0 &&
                           PageForm.elements[i].id.indexOf("InPageRegDiv") < 0 &&
                           PageForm.elements[i].style.visibility != "hidden")
                        {
	                        PageForm.elements[i].style.visibility = Visibility;
	                        HiddenItem[Count] =  PageForm.elements[i];
	                        Count++;
	                    }
                    }
                    catch(e)
                    {} 
                }
            }
            else
            {
                for(i=0;i<HiddenItem.length; i++)
                {
                    HiddenItem[i].style.visibility = Visibility;
                }
                HiddenItem.length = 0;
            }
        }
        catch(ex)
        {
        } 
    }
    
    function FocusFirstTextbox(divWrapper)
    {    
        // Set focus to first TextBox, icp#
        var sTag;
        var divRegInput = document.getElementById(divWrapper);
        if(divRegInput != null)
        {
            for(var i=0; i < divRegInput.childNodes.length; i++)
            {
                sTag = new String(divRegInput.childNodes[i].tagName);
                if(sTag.toUpperCase() == "INPUT")
                {
                    divRegInput.childNodes[i].focus();
                    break;
                }
            }
        }
    }  