if (window.addEventListener){
	window.addEventListener("load",applyBehaviors,false);
	window.addEventListener("load",applyBehaviorsSplash,false);
} else if (window.attachEvent) {
	window.attachEvent("onload",applyBehaviors);
	window.attachEvent("onload",applyBehaviorsSplash);
} else {
	window.onload=function(){
    applyBehaviors;
    applyBehaviorsSplash;
  }
}

var topnav = "";
var marketscopemenu = "";
var submenu = "";
var indtabs = "";
var indextab = "";
var tooltip = "";
var topnavli = "";

function applyBehaviors() {
  topnav = document.getElementById("air-topnav");
	marketscopemenu = document.getElementById("AI-marketscope");
	submenu = document.getElementById("AI-marketscope-sub");
	indtabs = document.getElementById("indices-tabs");
	indexchart = document.getElementById("chart-img");
  tooltip = document.getElementById("air-topnav-tooltip");
	var resenter = document.getElementById("research-enter");
  if (topnav) {    
    topnavli = topnav.getElementsByTagName("li");
      for (var i=0;i<topnavli.length;i++) {
    		topnavli[i].onmousedown = function(){
          changeBg(this,'#d7dfec');
        }
    		topnavli[i].onmouseout = function(){
            if(this.id!=="AI-marketscope"){
              changeBg(this,'#1b458a');
            }else if(!submenu){
              changeBg(this,'#1b458a');
            }
            if(tooltip){
              hideTip();
            }
          }
          topnavli[i].onmouseover = function(){
            var liNum=i;
            changeBg(this,'#d7dfec');
            if (submenu && this.id!=="AI-marketscope") {
      				// the if statement above used to also include this condition: && !checkClassOn(marketscopemenu)
              hideMenu();
      			}
            delayTip(this.id);
          }
        }
      }
	if (submenu) {
		var submenuli = submenu.getElementsByTagName("li");
		for (var i=0;i<submenuli.length;i++) {
			if(!checkClassOn(submenuli[i])) {
				submenuli[i].onmousedown = function(){
          changeBg(this,'#5e80ba');
        }
				submenuli[i].onmouseout = function(){
          changeBg(this,'#d7dfec');
        }
        submenuli[i].onmouseover = function(){
          changeBg(this,'#5e80ba');
        }
			}
		}
	}
	if (resenter) {
		resenter.onfocus = clearText;
	}
	if (indtabs) {
		indextab = indtabs.getElementsByTagName("a");
		for (var i=0;i<indextab.length;i++) {
			indextab[i].onclick = chartSwap;	
		}
	}
	if (marketscopemenu&&submenu) {
		var mktsca = marketscopemenu.getElementsByTagName("a");
		if (mktsca.length>0) {
			// the if statement above used to contain the condition:  && !checkClassOn(marketscopemenu)
      mktsca[0].onmouseover = showMenu;
			mktsca[0].onmouseout = timedClose;
			if (submenu) {
				var submenua = submenu.getElementsByTagName("a");
				for (var i=0;i<submenua.length;i++) {
					submenua[i].onmouseover = showMenu;
					submenua[i].onmouseout = timedClose;
				}
			}
		}
	}
}

function checkClassOn(checkObj) {
	if(checkObj) {
		for (var i=0; i<checkObj.attributes.length; i++) {
			if (checkObj.attributes[i].nodeName == "class" && checkObj.attributes[i].nodeValue == "on") {
				return true;
			}
		}
	}
}

function changeBg(obj,bghex) {
  if(!checkClassOn(obj)){
    var aelements = obj.getElementsByTagName("a");
  	if (aelements.length>0) {
  		obj.style.backgroundColor=bghex;
      if(bghex=="#d7dfec"){
        for(var i=0;i<aelements.length;i++){
          aelements[i].style.color="#1b468e";
        }
      } else {
        for(var i=0;i<aelements.length;i++){
          aelements[i].style.color="#fff";
        }
      }
      if(obj.id=="AI-marketscope"){
        if(bghex=="#d7dfec"){
          obj.style.borderLeft="1px solid #95aacb";
          obj.firstChild.style.backgroundPosition="0px -24px";
        } else {
          obj.style.borderLeft="1px solid #25a";
          obj.firstChild.style.backgroundPosition="0px 0px";
        }
      }
  	}
  }
}

var tipTimer;
function delayTip(objId){
  tipTimer=setTimeout('showTip(\''+objId+'\')',700);
}

function showTip(objId){
  xAry=[
    {x:281,tip:"Market analysis, news and intelligence"},
    {x:331,tip:"Equity research and tools"},
    {x:386,tip:"Fund research and tools"},
    {x:440,tip:"Fixed-Income research and tools"},
    {x:490,tip:"Variable Annuities"},
    {x:537,tip:"Sectors &amp; Industries"},
    {x:598,tip:"S&amp;P Equity Indices data"},
    {x:478,tip:"Tools for client communications"},
    {x:541,tip:"Portfolio, equity, and market alerts"},
    {x:607,tip:"Separately-managed accounts"}
  ];
  if(tooltip){
		for(var i=0;i<topnavli.length;i++){
      if(objId==topnavli[i].id){
        tooltip.style.left = xAry[i].x+"px";
        tooltip.innerHTML=xAry[i].tip;
      }
      tooltip.style.display="inline";
    }
  }
}

function hideTip(){
  clearTimeout(tipTimer);
  tooltip.style.display="none";
}

var hidedelay = "500";
var closeTmr = "";

function timedClose() {
  closeTmr = setTimeout('hideMenu()',hidedelay);
}

function showMenu() {
	clearTimeout(closeTmr);
	submenu.style.visibility = "visible";
}

function hideMenu() {
	submenu.style.visibility = "hidden";
  changeBg(marketscopemenu,'#1b458a');
}

function clearText() {
	this.value = "";
}

function chartSwap() {
	if (indexchart) {
		var offPos = new Array();
		offPos["inx"] = "0px -17px";
		offPos["indu"] = "-61px 0px";
		offPos["compx"] = "-119px 0px";
		if (this.id=="inx") {
			this.style.backgroundPosition = "0px 0px";
			indextab[1].style.backgroundPosition = offPos["indu"];
			indextab[2].style.backgroundPosition = offPos["compx"];
			rowSwap(1);
		} else if (this.id=="indu") {
			this.style.backgroundPosition = "-61px -17px";
			indextab[0].style.backgroundPosition = offPos["inx"];
			indextab[2].style.backgroundPosition = offPos["compx"];
			rowSwap(2);
		} else if (this.id=="compx") {
			this.style.backgroundPosition = "-119px -34px";
			indextab[0].style.backgroundPosition = offPos["inx"];
			indextab[1].style.backgroundPosition = offPos["indu"];
			rowSwap(3);
		}
		var chartAry = new Array();
		chartAry[0] = new Image();
		chartAry[0].src = "http://charts.prophet.net/servlet/ChartServer?symbol=$"+this.id+"&width=180&height=123&duration=6m&frequency=1d&service=sandp&scheme=sandp";
		indexchart.src=chartAry[0].src;
	}
}

function rowSwap(cur) {
	var mpRows = document.getElementById("market-prices").getElementsByTagName("tr");
	for (var i=0; i<mpRows.length; i++) {
		mpRows[i].style.backgroundColor = "#eed";
	}
	mpRows[cur].style.backgroundColor = "#fff";
}

function ximg(a,src){
	if (a.firstChild){
    img=a.firstChild;
		if (typeof(img.tagName)=="undefined"){
			img=a.getElementsByTagName("img")[0];
		}
	}
	if (img.tagName){
		if (img.tagName.toLowerCase()=="img"){
			if (typeof(a.outsrc)=="undefined" && typeof(src)!="undefined"){
				a.outsrc=img.src;
			}
			img.src=typeof(src)=="undefined"?a.outsrc:src;
		}
	}
}

var centerheads = "";
var featuresvis = 0;


function applyBehaviorsSplash() {
  var centercol = document.getElementById("air-centercol");
  if (centercol) {    
		var centerheads = centercol.getElementsByTagName("h2");
		for (var i=0; i<centerheads.length; i++) {
			var headsmore = centerheads[i].getElementsByTagName("a");
			headsmore[0].onmouseover = showFeatures;
			headsmore[0].onmouseout = showFeatures;
		}
  }
}

function showFeatures() {
	var featuresdiv = this.parentNode.parentNode.parentNode.getElementsByTagName("div")[0];
	if (featuresdiv != null){
	  if (featuresvis==0) {
		  featuresdiv.style.visibility = "visible";
		  featuresvis = 1;
	  } else {
		  featuresdiv.style.visibility = "hidden";
		  featuresvis = 0;
	  }
	}
}

/*-------  contentLink.jsp functions start here  -----*/
  var windowAtts = "menubar=no,resizable=yes,scrollbars=yes,toolbar=no,status=no,height=500,width=700";
	function isAllowedCharForInt(c){
  	    return ((c>= "0") && (c <= "9"));
	}

	function isAPosNumber(inputVal){
		for (var i=0;i<inputVal.length;i++){
		    if (!isAllowedCharForInt(inputVal.charAt(i)))
		    	return false;
		}
 	   	return true;
	}
function News(ticker,type,urlParam){

       news = window.open("/SP/editorial/NewsList.do?"+urlParam+"&pagename="+type+"&sp_popup=YES&ticker="+ticker,"NewsPage",windowAtts);
       news.focus();
}
function NewsByName(name,type,urlParam){

       if (type == 'Stock')
          news = window.open("/SP/common/GenSearch.do?"+urlParam+"&pagename="+type+"&sp_popup=YES&display=stocknews&company="+name,"NewsPage",windowAtts);
       else
          news = window.open("/SP/common/GenSearch.do?"+urlParam+"&pagename="+type+"&sp_popup=YES&display=fundnews&company="+name,"NewsPage",windowAtts);
       news.focus();
}
function Stat(ticker,urlParam){
   stats = window.open("/SP/cp2/cp2.do?"+urlParam+"&pagename=ProfileData&ticker="+ticker,"StatisticsPage",windowAtts);
   stats.focus();
}
function StatByName(name,urlParam){
   stats = window.open("/SP/common/GenSearch.do?"+urlParam+"&pagename=ProfileData&sp_popup=YES&display=stats&company="+name,"StatisticsPage",windowAtts);
   stats.focus();
}
function Quote(ticker,urlParam)
{
      var urlString="/SP/cp2/cp2.do?"+urlParam+"&ticker="+ticker+"&pagename=CompanyQuote&sp_popup=YES";
      if (document.form2.assetClass[document.form2.assetClass.selectedIndex].value == 'FND')
          urlString="/SP/gfs/Quotes.do?"+urlParam+"&sp_popup=YES&ticker="+ticker;
      quote = window.open(urlString ,"QuotePage",windowAtts);
       quote.focus();
}
function QuoteByName(name,urlParam)
{
      var urlString="/SP/common/GenSearch.do?"+urlParam+"&company="+name+"&display=stockquotes&sp_popup=YES&pagename=CompanyQuote";
      if (document.form2.assetClass[document.form2.assetClass.selectedIndex].value == 'FND')
          urlString="/SP/common/GenSearch.do?"+urlParam+"&company="+name+"&display=fundquotes&sp_popup=YES&pagename=CompanyQuote";
      quote = window.open(urlString ,"QuotePage",windowAtts);
       quote.focus();
}
function Quote_with_CUSIP(cusip,urlParam)
{

    //alert("inside Quote_with_CUSIP");
    var urlString="/SP/cp2/cp2.do?"+urlParam+"&pagename=CompanyQuote&cusip=" + cusip;
    quote = window.open(urlString ,"QuotePage",windowAtts);
    quote.focus();

}



function marketscope(pVal,urlParam)
{

// This function is used for some legacy calls to marketscope() from certain xsl pages.


location.href="/SP/marketscope/Marketscope.do?"+urlParam+"&pagename=P." + pVal;
}

function textSelect(form){
    //form.textfield.select();
    //form.textfield.focus();
}
function populateTextBox(form){
    if (form.assetClass.options[form.assetClass.selectedIndex].value == "MSP")
       form.textfield.value = 'Enter Page Number';
    else{
       form.textfield.value = 'Enter '+form.searchBy.options[form.searchBy.selectedIndex].text;
    }
    textSelect(form);
    
}

function populateSearchBox(form)
{
//	alert(form.assetClass.options[form.assetClass.selectedIndex].text);
	var val = form.assetClass.options[form.assetClass.selectedIndex].value;
	//alert("val="+val);

	if (val == "STK")
	{
               form.toGet.disabled=false;
               form.searchBy.disabled=false;  		
 		           form.searchBy.length=2;
		           form.searchBy.options[0].text="Ticker";
		           form.searchBy.options[1].text="Company Name";
               document.getElementById('retrieveLabel').style.color = '#40556D';
               document.getElementById('retrieveLabel').style.marginTop = '3px';        
               document.getElementById('searchByLabel').style.color = '#40556D';
               document.getElementById('searchByLabel').style.marginTop = '3px';                           
               form.toGet.length=4;
               form.toGet.options[0].text="Quote";
               form.toGet.options[1].text="News";
               form.toGet.options[2].text="Company Statistics";
               form.toGet.options[3].text="Report";
               form.searchBy.options[0].selected = true;
	}
	else if (val == "FND")
	{
               form.toGet.disabled=false;
               form.searchBy.disabled=false; 		
		           form.searchBy.length=2;  //change to 3 if adding CUSIP back in.
		           form.searchBy.options[0].text="Ticker";
		           form.searchBy.options[1].text="Fund Name";
               document.getElementById('retrieveLabel').style.color = '#40556D';
               document.getElementById('retrieveLabel').style.marginTop = '3px'; 
               document.getElementById('searchByLabel').style.color = '#40556D';
               document.getElementById('searchByLabel').style.marginTop = '3px';                                       
               form.toGet.length=3;
               form.toGet.options[0].text="Quote";
               form.toGet.options[1].text="News";
                //form.toGet.options[2].text="Chart";
               form.toGet.options[2].text="Report";
               form.searchBy.options[0].selected = true;
	}
	else if (val == "BND")
	{
               form.toGet.disabled=false;
               form.searchBy.disabled=false;  		
		           form.searchBy.length=2;
		           form.searchBy.options[0].text="CUSIP"
		           form.searchBy.options[1].text="Issuer Name";
               document.getElementById('retrieveLabel').style.color = '#40556D';
               document.getElementById('retrieveLabel').style.marginTop = '3px';    
               document.getElementById('searchByLabel').style.color = '#40556D';
               document.getElementById('searchByLabel').style.marginTop = '3px';                                     
               form.toGet.length=1;
               form.toGet.options[0].text = "Report";
               form.toGet.options[0].selected = true;
               form.searchBy.options[0].selected = true;
	}
  else if (val == "VAN"){
               form.toGet.disabled=false;
               form.searchBy.disabled=false;     	
          	   form.searchBy.length=3;
               form.searchBy.options[0].text = "Company Name";
		           form.searchBy.options[1].text="Policy"
		           form.searchBy.options[2].text="Sub Account";
               document.getElementById('retrieveLabel').style.color = '#40556D';
               document.getElementById('retrieveLabel').style.marginTop = '3px';    
               document.getElementById('searchByLabel').style.color = '#40556D';
               document.getElementById('searchByLabel').style.marginTop = '3px';                                    
               
                form.toGet.length=1;
                form.toGet.options[0].text="Report";
                form.searchBy.options[0].selected = true;
        }
  else if (val == "MSP"){
               //form.searchBy.length=1;
               //form.toGet.length=1;
               //form.searchBy.options[0].text = "Page Number";
               //form.toGet.options[0].text = "Page";
               form.toGet.selectedIndex=-1;
               form.searchBy.selectedIndex=-1;
               form.toGet.disabled=true;
               form.searchBy.disabled=true;
               document.getElementById('retrieveLabel').style.color = '#7B8B9E';
               document.getElementById('retrieveLabel').style.marginTop = '3px';    
               document.getElementById('searchByLabel').style.color = '#7B8B9E';
               document.getElementById('searchByLabel').style.marginTop = '3px';                                                    
        }
        //form.searchBy.options[0].selected = true;
        populateTextBox(form);
}

function formResult(urlParam)
{
if (document.form2.textfield.value == ""){
  alert("Please enter " + form2.searchBy.options[form2.searchBy.selectedIndex].text);
  return;
}

var cat = document.form2.assetClass.options[document.form2.assetClass.selectedIndex].value;
var searchBy = document.form2.searchBy.options[document.form2.searchBy.selectedIndex].text;
var toGet = document.form2.toGet.options[document.form2.toGet.selectedIndex].text;
var inputVal = document.form2.textfield.value;
//alert("cat="+cat+", searchBy="+searchBy+", toGet="+toGet+", inputVal="+inputVal);

if (cat == "BND"){
	var field='';
	if (searchBy == 'CUSIP') field= 'cusip';
	else field='companyName';
	location.href="/SP/bond/SearchResults.do?"+urlParam+"&fromSearch=Y&showNoRpt=N&display=report&breadCrumbs=&"+field+"="+inputVal
	return;
}
if (cat == "STK"){
       if (toGet == "Report")
           if (searchBy == "Ticker")
             location.href="/SP/spreports/StockReport.do?"+urlParam+"&issueType=stock&multiPageAlways=YES&type=URL&searchpage=combo&onlyTickerSearch=YES&company="+inputVal;
           else location.href="/SP/spreports/StockReport.do?"+urlParam+"&companySearch=YES&issueType=stock&multiPageAlways=YES&type=URL&searchpage=combo&company="+inputVal;
       else if (toGet == "Company Statistics")
             if (searchBy == 'Ticker')
                Stat(inputVal,urlParam);
             else StatByName(inputVal,urlParam);
       else if (toGet == "Quote")
             if (searchBy == 'Ticker')
             	Quote(inputVal,urlParam);
             else
                QuoteByName(inputVal,urlParam);
       else if (toGet == "News")
          if (searchBy == 'Ticker')
             News(inputVal,'Stock',urlParam);
          else
             NewsByName(inputVal,'Stock',urlParam);
       else if(toGet == "Chart")
             alert("Stock Chart not available yet");
       return;
}
if (cat == "FND"){
  	if (toGet == "Report")
             location.href="/SP/spreports/MutualFundReport.do?"+urlParam+"&issueType=fund&ref=FundSimple&multiPageAlways=YES&type=URL&searchpage=combo&company="+inputVal;
	else if (toGet == "Quote")
            if (searchBy == "Ticker")
              Quote(inputVal,urlParam);
            else QuoteByName(inputVal,urlParam);
        else if (toGet == "News")
          if (searchBy == 'Ticker')
             News(inputVal,'Fund',urlParam);
          else
             NewsByName(inputVal,'Fund',urlParam);
	else if (toGet == "Chart")
             alert("Fund Chart not available yet");
       return;
}
if (cat == "VAN"){
     	//alert("Variable Annuity links not available yet");
       if (searchBy == 'Company Name')
        location.href="/SP/va/company.do?"+urlParam+"&searchString="+inputVal.toUpperCase();
       else if (searchBy == 'Policy')
        location.href="/SP/va/policy.do?"+urlParam+"&searchString="+inputVal.toUpperCase()+"&criteria=POL";
       else if (searchBy == 'Sub Account')
        location.href="/SP/va/subaccount.do?"+urlParam+"&criteria=SUB&searchString="+inputVal.toUpperCase();
       return;
}
if (cat == "MSP"){
          location.href="/SP/marketscope/Marketscope.do?"+urlParam+"&pagename=P."+inputVal;
}

}