﻿// headerfooter JScript File
    
 function initBoxQuote(AutoBox,AutoDropDown)
   { 
     CheckOSBrowser();             //check the Browser
     var allcache = new Array();
     var pos = new Array();
     initCache(allcache,pos);   
     var qs_server = 'http://quote.morningstar.com/switch.html?ticker=';   
     var mybox = new AutoCompleteBox(AutoBox,AutoDropDown,qs_server,allcache,pos,true);
     return mybox; 
    }
    
    
function srchTerm(sSearchType)
{
	if (sSearchType == "search") {
	    document.searchForm.SrchTerm.value = document.searchForm.sSrchTerm.value;
  	    document.searchForm.action = "http://search.morningstar.com/MstarSrch/MstarSrch2.aspx";
  	    document.searchForm.submit();
	}
	else if (sSearchType == "searchFooter") {
	    document.searchFormFooter.SrchTerm.value = document.searchFormFooter.sSrchTerm.value;
  	    document.searchFormFooter.action = "http://search.morningstar.com/MstarSrch/MstarSrch2.aspx";
  	    document.searchFormFooter.submit();
	} 

}
function ClearSearchBox(sSearchType)
{
	if (sSearchType == "search")
	{
        document.searchForm.sSrchTerm.color="#FFFFFF";
		document.searchForm.sSrchTerm.value = "";
	}
	else //(sSearchType == "searchFooter")
	{
        document.searchFormFooter.sSrchTerm.color="#FFFFFF";
		document.searchFormFooter.sSrchTerm.value = "";
	}
}


function GetXmlHttpObject(){
  var xmlHttp=null;
  try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }catch (e){    
    // Internet Explorer
    try{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e){
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

function getSiteFooter(id,obj)
{
    var oRequest=GetXmlHttpObject();  
    if (oRequest==null){
        alert ("Your browser does not support AJAX!");
        return;
    } 
    
    var url = "/GHeaderFooter/footer.ashx?site=" + id;
    //alert(url);
    oRequest.open("GET",url,true);      
    oRequest.onreadystatechange = function(){    
      if (oRequest.readyState == 4)
      {                      
            var txt = oRequest.responseText;    
            //alert (txt);  
            if (id =="siteDirectoryContent")
            { 
                var oFooterDiv = document.getElementById("siteDirectoryContent"); 
            }
            else if (id =="siteMapContent")
            { 
                var oFooterDiv = document.getElementById("siteMapContent"); 
            }
            else if (id =="productsContent")
            { 
                var oFooterDiv = document.getElementById("productsContent"); 
            }
            
            oFooterDiv.innerHTML = txt;  
      }                   
    }  
    oRequest.send(null);  
    swapout(id,obj);	            
}
function swapout(id,obj)
{ 
	idlookup(id);
	activate(obj);
}


//swaps out link states-----------------------------------------------------------------------------------------------
var linkIDs=new Array('nav1','nav2','nav3'); //array of links
function turnofflinks(id) {document.getElementById(id).className='f_sdirtab';} //changes links to off mode
function offalllinks() {for (var i=0;i<linkIDs.length;i++) {turnofflinks(linkIDs[i]);}}

//turns on selected link
//first it reverts the links to off mode
//then sets the one pressed into on mode
function activate(obj) {if (obj.className=='f_sdirtab') {offalllinks(obj); obj.className='f_sdirtabOn';}}
//--------------------------------------------------------------------------------------------------------------------

function idlookup(id) 
{	
	if(document.getElementById(id).style.display != 'block')
		doton(id);
}

function turnoffimages(id) {document.getElementById(id).style.display='none';} //changes content boxes to off mode
function offallimages() {for (var i=0;i<imageIDs.length;i++) {turnoffimages(imageIDs[i]);}} //function to set all content boxes to off mode

function doton(id) {
	offallimages();
	document.getElementById(id).style.display='block';
	//var opacityTween = new OpacityTween(document.getElementById(id),Tween.strongEaseInOut, 0, 100, .75);
	//opacityTween.start();
}
//-------------------------------------------------------------------------------------------------------------------

/* for site directory }*/
function turnon(id) 
{  
  for (var i=1;i<=12;i++)
    {
     document.getElementById("Tabmenu" + i).className="sdir_menu";
          document.getElementById("menu" + i).style.display = "none";

     }
    document.getElementById("Tab" + id).className="sdir_menuOn";
    document.getElementById(id).style.display = "block";
}

function showDropdown(evt,el)
{
   if(el == null)
       el = document.ulEle
   var display = el.getElementsByTagName("UL")[0].style.display;
   if(display == "none" || display == "")
   {
       el.getElementsByTagName("UL")[0].style.display="block";
       if(el.setCapture)
          el.setCapture(false);
       else
       {
          document.addEventListener("click",showDropdown,true);
          window.captureEvents(Event.CLICK);
       }
       document.ulEle = el;
   }
   else
   {
       el.getElementsByTagName("UL")[0].style.display="none";
       if(el.setCapture)
          el.releaseCapture();
       else
       {
          document.removeEventListener("click",showDropdown,true);
          window.releaseEvents(Event.CLICK);
          evt.cancelBubble = true;
       }
       //when click another dropdown, we should show the clicked dropdown.
       var srcEle = (evt.srcElement?evt.srcElement:evt.target); 
       if(srcEle.className == "pmddh1") srcEle = srcEle.parentNode;
       if(srcEle.className != "pmdd1") return;
       if(srcEle == el) return;
       showDropdown(null,srcEle);
   }
}    

//turn on main nav and subnav 
function GHF_Nav(nav, subnav)
{
    var navEle = document.getElementById("MH_tab" + nav);
    if (navEle != null)
    {
        navEle.className += "On";
    }
}

 //for footer sitemap
 function FFQTRedirect() { 
    var url = document.ffqtlist.ffqtselect.options[document.ffqtlist.ffqtselect.selectedIndex].value;
	if ((url != "^") && (url != ""))
	window.location = url;	
}
 
