﻿// JScript File
// Created by Victoria Romero 12/2006
//This file contains the logic that will display Top nav overlays on the site
//It also assings css styles to cells and links in the top nav

function ShowOverlay(url, tabselected)
{   
    _closeOverlay = false; //set flag to open popup
    if (_overlayStatus == "off")
    {
        if (_PopupContent != tabselected)
        {
            
            makeRequest(url + _contentId[tabselected]);
        }
        else
        {
             
            //popup is populated so just show
            if(!_closeOverlay)
            {
                SF_overlay(document.getElementById("tdnav"+ tabselected), 'popup', 'bottomright');
            }
        }          
     }
   
}

//AJAX CALL FUNCTIONS
    function makeRequest(url) 
    {
        var http_request = false;
        if (window.XMLHttpRequest) 
        { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) 
            {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } 
        else if (window.ActiveXObject) 
        { // IE
            try 
            {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) 
            {
                try 
                {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) 
        {
            //alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function() { alertContents(http_request); };
        http_request.open('GET', url, true);
        http_request.send(null);

    }

    function alertContents(http_request) 
    {
        if (http_request.readyState == 4) 
        {
            if (http_request.status == 200 ) 
            {
                if (http_request.responseText.length > 4)
                {
                    
                    document.getElementById("popup").innerHTML = http_request.responseText;
                    _PopupContent = _tabSelected;
                    if (!_closeOverlay)
                    {
                        SF_overlay(document.getElementById("tdnav" + _tabSelected), 'popup', 'bottomright');
                    }
                }
            } 
            else 
            {
                //alert('There was a problem with the request. Status:' + http_request.status);
            }
        }
    }




function getposOffset(overlay, offsettype)
{
    var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
    var parentEl=overlay.offsetParent;
    while (parentEl!=null)
    {
        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
        parentEl=parentEl.offsetParent;
    }
    return totaloffset;
}

function SF_overlay(curobj, subobjstr, opt_position)
{
    if (document.getElementById)
    {
        var subobj=document.getElementById(subobjstr)
    
        subobj.style.visibility  = "hidden";
        subobj.style.display="block";
    
        var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
        var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
        subobj.style.left=xpos+"px"
        subobj.style.top=ypos+"px"
         _overlayStatus ="on";
     
        subobj.style.visibility  = "visible";
    
        return false
    }
    else
    {
        return true
    }
 
}

function SF_overlayclose(subobj, ivalue)
{
   if (_closeOverlay)       
    {
        if(t >= ivalue)
        {
            t=0;
            document.getElementById(subobj).style.display="none";
             _overlayStatus ="off";
             _closeOverlay = false;
        }
        else
        {
            setTimeout( "SF_overlayclose('"+subobj+"', '" + ivalue + "');",1000);
        }
        t = t+1;
        
    }
    else
    {
        t=0;
    }   
  
}



//check variable to overwrite popup behavior

function SF_overlay_MouseOver(iTdID)
{
   
        if (_showPopup[iTdID] == 1)
        {
            
            //set mouseover events in td and link
            document.getElementById("tdnav" + iTdID).className = 'TopNavPopup';
            document.getElementById("anav" + iTdID).className = 'TopNavPopup';
            _tabSelected = iTdID;
            ShowOverlay(_url, _tabSelected);
            
       }
       
  
}

function SF_overlay_MouseOut(iTdID)
{
    if (_showPopup[iTdID] == 1)
    {
        document.getElementById("tdnav" + iTdID).className = 'TopNavPopup';
        document.getElementById("anav" + iTdID).className = 'TopNavPopup';
        _closeOverlay=true;
        SF_overlayclose('popup',1);
    }

}




