//window.onload=template_init;

// Body onload functions
function template_init(){
    channel_init();
    addRR();

    var watchlistCheck = document.getElementById("mnc_watchlist");
    var marketNewsCheck = document.getElementById("market-news-mod");

    if(watchlistCheck && typeof(initWatchlist) != "undefined" && initWatchlist==1)
        ensureUploadScriptIsLoaded(portURL + AOL_StockQuotesWatchList +'&callback=mnc_watchlist');
    if(marketNewsCheck){
        tabCount=last-2;
        first=1;
        ensureUploadScriptIsLoaded('http://portal.pf.aol.com/jsonmfus/ws?service=symslist&exchange=USA&symbols=' + marketNewsStocks + '&callback=buildArrayInit');
    }

}

if (window.addEventListener)
    window.addEventListener('load',template_init,false);
else
    window.attachEvent("onload",template_init);

function buildArrayInit(obj) {
    buildArray(obj);
    displaySymbolData(last);
    select_tabs(first);
    paginationData = tabCount + " of " + arrMarketData.length;
    document.getElementById("carouselPagination").innerHTML = paginationData;
} // end buildArrayInit

// end of body On load functions


function sendLinkEvent()
{
}

// Feed Module Mouse Over Popup Functions - Starts
function createPop()
{
    var popRef = document.createElement("p");
    popRef.className = 'feedPop';
    popRef.setAttribute('id','feedPop');
    document.body.appendChild(popRef);
    popRef.style.display = 'none';
   
}

function showPop(e,trgElement,textPopup)
{
    var elHt = trgElement.offsetHeight;//this is the element height
    var elWt = trgElement.offsetWidth;//this is the element height
    createPop();
	posY = findMousePos(e)
    if(document.getElementById('feedPop').style.display.indexOf('none')==0)
    {
        popRef = document.getElementById('feedPop');
        var txtNode = document.createTextNode(textPopup);
	var arrPos = findPos(trgElement);
	popRef.style.display = "block";
	popRef.style.left = arrPos[0] + "px";
    popRef.style.top = parseInt(posY+elHt/2)+ "px";
       
        try
        {
            popRef.removeChild(popRef.firstChild);
        }
        catch(e){}
        popRef.appendChild(txtNode);
    }
}

function hidePop()
{
    try
    {
        var popRef = document.getElementById('feedPop');
        document.body.removeChild(popRef);
        popRef=null;
    }catch(e){}
}

function findPos(obj)
{
    var curleft = curtop = 0;
    if (obj.offsetParent)
    {
        curleft = obj.offsetLeft;
        curtop = obj.offsetTop;
        while (obj = obj.offsetParent)
        {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
    }
    else if(obj.x)curleft+=obj.x;

    if(document.all)
     	curleft-=document.getElementsByTagName("body")[0].offsetLeft;
    
    if(navigator.userAgent.indexOf('Safari')!=-1)
	curleft-=document.getElementsByTagName("body")[0].offsetLeft;

    return [curleft,curtop];
}

function findMousePos(e) {
	var posY = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posY = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posY = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	return posY;
}
// Feed Module Mouse Over Popup Functions - Ends

/* OnlineOpinion (S3tS,1424b) / custom_var_static added */ 
/* This product and other products of OpinionLab, Inc. are protected by U.S. Patent No. 6606581, 6421724, 6785717 B1 and other patents pending. */
var custom_var_static,_sp='%3A\\/\\/',_rp='%3A//',_poE=0.0, _poX=0.0,_sH=screen.height,_d=document,_w=window,_ht=escape(_w.location.href),_hr=_d.referrer,_tm=(new Date()).getTime(),_kp=0,_sW=screen.width; _d.onkeypress=_fK;function _fK(_e){if(!_e)_e=_w.event;var _k=(typeof _e.which=='number')?_e.which:_e.keyCode;if((_kp==15&&_k==12))_w.open('https://secure.opinionlab.com/pageviewer/pv_controlboard.html?url='+_fC(_ht),'PageViewer','height=529,width=705,screenX='+((_sW-705)/2)+',screenY='+((_sH-529)/2)+',top='+((_sH-529)/2)+',left='+((_sW-705)/2)+',status=yes,toolbar=no,menubar=no,location=no,resizable=yes');_kp=_k};function _fC(_u){_aT=_sp+',\\/,\\.,-,_,'+_rp+',%2F,%2E,%2D,%5F';_aA=_aT.split(',');for(i=0;i<5;i++){eval('_u=_u.replace(/'+_aA[i]+'/g,_aA[i+5])')}return _u};function O_LC2(){_w.open('https://secure.opinionlab.com/ccc01/comment_card.asp?time1='+_tm+'&time2='+(new Date()).getTime()+'&prev='+_fC(escape(_hr))+'&referer='+_fC(_ht)+'&height='+_sH+'&width='+_sW+'&custom_var='+custom_var_static,'comments','width=535,height=192,screenX='+((_sW-535)/2)+',screenY='+((_sH-192)/2)+',top='+((_sH-192)/2)+',left='+((_sW-535)/2)+',resizable=yes,copyhistory=yes,scrollbars=no')};function _fPe(){if(Math.random()>=1.0-_poE){O_LC2();_poX=0.0}};function _fPx(){if(Math.random()>=1.0-_poX)O_LC()};window.onunload=_fPx;function O_GoT(_p){_d.write('<a href=\'javascript:O_LC2()\'>'+_p+'</a>');_fPe()}

function chportfolio(formName,ctrlName,formSubmit) {
	var formName = 'document.'+formName+'.'+ctrlName;
	if (formSubmit == 0) {var ctrlValue = eval(formName).options[eval(formName).selectedIndex].value;}
	window.open(ctrlValue);
}

function nav_focus (formname,fieldname) {
	document.forms[formname].elements[fieldname].focus();
}

function popup_window(url,width,height){
	var features="status=0,menubar=0,location=0,toolbar=0";
	if (!isNaN(parseInt(width))){features+=",width="+width;}
	if (!isNaN(parseInt(height))){features+=",height="+height;}
	if (typeof(window.screenLeft)!="undefined"){
		features+=",left="+window.screenLeft;
		features+=",left="+Math.round(window.screenLeft+((document.body.clientWidth/2)-(width/2)));
	} else if (typeof(window.screenX)!="undefined"){
		features+=",left="+Math.round(window.screenX+((window.outerWidth/2)-(width/2)));
	}
	if (typeof(window.screenTop)!="undefined"){
		features+=",top="+window.screenTop;
		features+=",top="+Math.round(window.screenTop+150);
	} else if (typeof(window.screenY)!="undefined"){
		features+=",top="+Math.round(window.screenY+((window.outerHeight-window.innerHeight)+150));
	}
	var popupWin=window.open(url,"popupWin",features);
	if (popupWin.focus){popupWin.focus();}
}


// for photo gallery module
var activeButton, playingForward, playingBackward, photoPlayer, playControlActive, storyControlActive, maxStory
var timeDelay = 10
var autoPlay = "on"
var playDirection = "forward"
var x = 0
var offImg = new Array("info_btn_1_off-pf","info_btn_2_off-pf","info_btn_3_off-pf","info_btn_4_off-pf","info_btn_5_off-pf","info_btn_6_off-pf","info_btn_7_off-pf","info_btn_8_off-pf","info_btn_9_off-pf","info_btn_10_off-pf","info_btn_11_off-pf","info_btn_12_off-pf","info_btn_prev_off-pf","info_btn_pause_off-pf","info_btn_next_off-pf")
var onImg = new Array("info_btn_1_on-pf","info_btn_2_on-pf","info_btn_3_on-pf","info_btn_4_on-pf","info_btn_5_on-pf","info_btn_6_on-pf","info_btn_7_on-pf","info_btn_8_on-pf","info_btn_9_on-pf","info_btn_10_on-pf","info_btn_11_on-pf","info_btn_12_on-pf","info_btn_prev_on-pf","info_btn_pause_on-pf","info_btn_next_on-pf")

function photoLead_playPhotos(seconds,onOff,direction){
	if (document.getElementById("photoGalleryParent")){
		if (seconds!=undefined){timeDelay = seconds}
		timeDelay = timeDelay * 1000
		if (typeof(maxStory)=="undefined"){
			maxStory = 0;
			while (document.getElementById("pic"+maxStory)){
				maxStory++;
			}
		}
		if (onOff!=undefined){autoPlay=onOff.toLowerCase()}
		else{autoPlay=autoPlay.toLowerCase()}
		if (direction!=undefined){playDirection=direction.toLowerCase();}
		else{playDirection=playDirection.toLowerCase();}
		if (playDirection=="forward"){
			playingForward=true
			playingBackward=false
			playControlActive=14
		} else {
			playingForward=false
			playingBackward=true
			playControlActive=12
		}
		if (autoPlay=="on"){photoLead_startTimer()}
		else (photoLead_changePhotoStory(1))
	}
}

function photoLead_startTimer(){
	if (playingForward==true){
		if (document.getElementById("pic14")){document.getElementById("pic14").src = "http://cdn.channel.aol.com/ch_pf/" + onImg[14]}
		if (document.getElementById("photostory" + (x+1)) && document.getElementById("pic" + x)){x=x+1}
		else{maxStory=x; x=1;}
	}
	if (playingBackward==true){
		if (document.getElementById("pic12")){document.getElementById("pic12").src = "http://cdn.channel.aol.com/ch_pf/" + onImg[12]}
		x=x-1;
		if (x<1){x=maxStory}
	}
	if (document.getElementById("titledefault") && document.getElementById("photo" + x + "title") && document.getElementById("photo" + x + "title").innerHTML!=""){document.getElementById("titledefault").innerHTML=document.getElementById("photo" + x + "title").innerHTML}
	if (document.getElementById("photodefault") && document.getElementById("photostory" + x + "photo") && document.getElementById("photostory" + x + "photo").innerHTML!=""){document.getElementById("photodefault").innerHTML=document.getElementById("photostory" + x + "photo").innerHTML}
	if (document.getElementById("textdefault") && document.getElementById("photostory" + x + "text") && document.getElementById("photostory" + x + "text").innerHTML!=""){document.getElementById("textdefault").innerHTML=document.getElementById("photostory" + x + "text").innerHTML}
	if (document.getElementById("linkWrapperDefault") && document.getElementById("linkWrapper" + x) && document.getElementById("linkWrapper" + x).innerHTML!=""){document.getElementById("linkWrapperDefault").innerHTML=document.getElementById("linkWrapper" + x).innerHTML}
	storyControlActive=x-1;
	photoLead_makeActive(x);
	photoPlayer=setTimeout("photoLead_startTimer()", timeDelay);
}

function photoLead_stopTimer(){
	if (playingForward==true && document.getElementById("pic14")){document.getElementById("pic14").src = "http://cdn.channel.aol.com/ch_pf/" + offImg[14]}
	if (playingBackward==true && document.getElementById("pic12")){document.getElementById("pic12").src = "http://cdn.channel.aol.com/ch_pf/" + offImg[12]}
	playingForward=false;
	playingBackward=false;
	playControlActive=-1;
	if (photoPlayer){clearTimeout(photoPlayer);}
	else {if (photoPlayer==undefined && document.getElementById("pic13")){document.getElementById("pic13").src = "http://cdn.channel.aol.com/ch_pf/" + offImg[13]}}
}

function photoLead_rollover(buttonID,buttonNumber,buttonState){
	if (document.getElementById(buttonID)){
		switch (buttonState){
			case "on":
				document.getElementById(buttonID).src = "http://cdn.channel.aol.com/ch_pf/" + onImg[buttonNumber];
				break;
			case "off":
				if (activeButton!=buttonNumber && playControlActive!=buttonNumber && storyControlActive!=buttonNumber){
					document.getElementById(buttonID).src = "http://cdn.channel.aol.com/ch_pf/" + offImg[buttonNumber];
				}
				break;
		}
	}
}

function photoLead_makeActive(isActiveNum){
	activeButton = isActiveNum - 1;
	if (activeButton==13){}
	else{
		for (i=0;i<15;i++){
			if (playingForward==true && i!=14 && document.getElementById("pic" + i)){document.getElementById("pic" + i).src = "http://cdn.channel.aol.com/ch_pf/" + offImg[i]}
			else if (playingBackward==true && i!=12 && document.getElementById("pic" + i)){document.getElementById("pic" + i).src = "http://cdn.channel.aol.com/ch_pf/" + offImg[i]}
			else if (playingForward==false && playingBackward==false && document.getElementById("pic" + i)){document.getElementById("pic" + i).src = "http://cdn.channel.aol.com/ch_pf/" + offImg[i]}
		}
	}
	if (document.getElementById("pic" + activeButton)){document.getElementById("pic" + activeButton).src = "http://cdn.channel.aol.com/ch_pf/" + onImg[activeButton]}
}

function photoLead_changePhotoStory(photStorNumber){
	if (photStorNumber>maxStory){photStorNumber=maxStory}
	storyControlActive=photStorNumber-1;
	x=photStorNumber;
	photoLead_makeActive(photStorNumber);
	if (document.getElementById("titledefault") && document.getElementById("photo" + photStorNumber + "title") && document.getElementById("photo" + photStorNumber + "title").innerHTML!=""){document.getElementById("titledefault").innerHTML=document.getElementById("photo" + photStorNumber + "title").innerHTML}
	if (document.getElementById("photodefault") && document.getElementById("photostory" + photStorNumber + "photo") && document.getElementById("photostory" + photStorNumber + "photo").innerHTML!=""){document.getElementById("photodefault").innerHTML=document.getElementById("photostory" + photStorNumber + "photo").innerHTML}
	if (document.getElementById("textdefault") && document.getElementById("photostory" + photStorNumber + "text") && document.getElementById("photostory" + photStorNumber + "text").innerHTML!=""){document.getElementById("textdefault").innerHTML=document.getElementById("photostory" + photStorNumber + "text").innerHTML}
	if (document.getElementById("linkWrapperDefault") && document.getElementById("linkWrapper" + photStorNumber) && document.getElementById("linkWrapper" + photStorNumber).innerHTML!=""){document.getElementById("linkWrapperDefault").innerHTML=document.getElementById("linkWrapper" + photStorNumber).innerHTML}
}

function toggleChart (divID, img) {
    //first turn all buttons off

    var one = document.getElementById("tab1");
    one.style.backgroundImage="url(http://cdn.digitalcity.com/ch_pf/taboff)";
    document.getElementById("chartFooter").innerHTML=tab1FlblLnk;

    if (document.getElementById("tab2") != null) {
        var two = document.getElementById("tab2");
        two.style.backgroundImage="url(http://cdn.digitalcity.com/ch_pf/taboff)";
        document.getElementById("chartFooter").innerHTML=tab2FlblLnk;
    }
    if (document.getElementById("tab3") != null) {
        var three = document.getElementById("tab3");
        three.style.backgroundImage="url(http://cdn.digitalcity.com/ch_pf/taboff)";
        document.getElementById("chartFooter").innerHTML=tab3FlblLnk;
    }
    if (document.getElementById("tab4") != null) {
        var four = document.getElementById("tab4");
        four.style.backgroundImage="url(http://cdn.digitalcity.com/ch_pf/taboff)";
        document.getElementById("chartFooter").innerHTML=tab4FlblLnk;
    }
    if (document.getElementById("tab5") != null) {
        var five = document.getElementById("tab5");
        five.style.backgroundImage="url(http://cdn.digitalcity.com/ch_pf/taboff)";
        document.getElementById("chartFooter").innerHTML=tab5FlblLnk;
    }
    if (document.getElementById("tab6") != null) {
        var six = document.getElementById("tab6");
        six.style.backgroundImage="url(http://cdn.digitalcity.com/ch_pf/taboff)";
        document.getElementById("chartFooter").innerHTML=tab6FlblLnk;
    }

    var element = document.getElementById(divID);
    var bitmap = "url(http://cdn.digitalcity.com/ch_pf/" + img + ")";
    element.style.backgroundImage=bitmap;

    var imageLink = null;
    var urlLink   = null;

    switch (divID)      {
        case "tab1" : imageLink = tab1
                      urlLink = tab1FlblLnk
            break;
        case "tab2" : imageLink = tab2
                      urlLink = tab2FlblLnk
            break;
        case "tab3" : imageLink = tab3
                      urlLink = tab3FlblLnk
            break;
        case "tab4" : imageLink = tab4
                      urlLink = tab4FlblLnk
            break;
        case "tab5" : imageLink = tab5
                      urlLink = tab5FlblLnk
            break;
        case "tab6" : imageLink = tab6
                      urlLink = tab6FlblLnk
            break;
    }

    document.getElementById("chartImage").style.backgroundImage = "url(" + imageLink.replace(/\(/g,"%28") +")";
    document.getElementById("chartFooter").innerHTML = urlLink;
}

// for use in the header 

function goQuotes(daform)
{
    if (!validateSym(daform.sym.value)) {
        alert("There are characters in the symbol that are not allowed.");
        return;
    }
   
    var exch = daform.exch.value;
    var sym = whichEncode(daform.sym.value);
    var url = "http://finance.aol.com/usw/quotes/quotesandnews" + "?sym=" + sym + "&exch=" + exch;

    window.location = url;
}

function validateSym(str) {
    var invalids = ":<";

    for (i=0; i<invalids.length; i++) {
        if (str.indexOf(invalids.charAt(i)) >= 0) {
            return false;
        }
    }
    return true;
}

function whichEncode(fld) {
	//if (fld == "") return false;
	var encodedField = "";
	var s = fld;
	if (typeof encodeURIComponent == "function")
	{
		// Use JavaScript built-in function
		// IE 5.5+ and Netscape 6+ and Mozilla
		encodedField = encodeURIComponent(s);
	}
	else 
	{
		// Need to mimic the JavaScript version
		// Netscape 4 and IE 4 and IE 5.0 etc
		encodedField = encodeURIComponentNew(s);
	}
	return encodedField;
}

//Functions for Boxley buttons
function artzOvr(o){
    o.className = o.className.substr(0,15) + " " + o.className.substr(8,15) + "Hov"
}

function artzOff(o){
    o.className = o.className.substr(0,15)
}


function artzClk(o){
    o.className = o.className.substr(0,15) + " " + o.className.substr(8,15) + "Clk"
}

// NEWS MAKER
var nm_a,nm_b,nm_r,nm_s,nm_f=11;
var nm_cur=new Array();

function p(j){return document.getElementById(j)}
function o(j){return document.getElementById(j).style}

function nm_init(mod){
	var nm_max=1,f;
	nm_r=.5/20*1000;
	nm_s=10/20;
	nm_cur[mod]=1;
	while(p(mod+"."+nm_max)){nm_max++;}
	nm_max--;
	p(mod+".cou").innerHTML="1/"+nm_max;
	o(mod+".nav").visibility="visible";
	f=function nm_pre(){
		if(nm_f>=10){
			var n=nm_cur[mod]-1;
			if(!n)n=nm_max;
			p(mod+"."+n).innerHTML=p(mod+"."+n).innerHTML.replace(/AOL:/i,"");
			cf(mod+"."+nm_cur[mod],mod+"."+n);
			nm_cur[mod]=n;
			p(mod+".cou").innerHTML=n+"/"+nm_max;
		}
                return false; 
	}
	p(mod+".pre").onclick=f;
	f=function nm_nex(){
		if(nm_f>=10){
			var n=nm_cur[mod]+1;
			if(n>nm_max)n=1;
			p(mod+"."+n).innerHTML=p(mod+"."+n).innerHTML.replace(/AOL:/i,"");
			cf(mod+"."+nm_cur[mod],mod+"."+n);
			nm_cur[mod]=n;
			p(mod+".cou").innerHTML=n+"/"+nm_max;
		}
		return false;
	}
	p(mod+".nex").onclick=f;
}
function cf(c,d){
	nm_a=o(c);nm_b=o(d);
	nm_b.display="block";
	nm_f=0;
	df();
}
function df(){
	nm_a.opacity=((10-nm_f)/10);nm_a.filter="alpha(opacity:"+(10-nm_f)*10+")";
	nm_b.opacity=(nm_f/10);nm_b.filter="alpha(opacity:"+nm_f*10+")";
	nm_f+=nm_s;
	if(nm_f<10)setTimeout("df()",nm_r);
	else nm_a.display="none";
}

//For Bill Manager

function chkBillMgr(form) {
  var err = "";
  var stripped = "";
  var emptyString = /^\s*$/;
  var allEmpty = 0;
  var elem = document.getElementById(err);
  formName=form.name;
  err="errMsg_" + formName.substring(formName.indexOf("_")+1,formName.length);
  for (i=1;i<form.length;i+=2) {
      form[i].value = form[i].value.replace(/[\$]/g, "");
      if (!document.getElementById) return true;
      var elem = document.getElementById(err);
      if (!elem.firstChild) return true;
      if (!emptyString.test(form[i].value)) {
	  allEmpty++;
          stripped = form[i].value.replace(/[\.\-\+\ ]/g, "");
          if (isNaN(parseInt(stripped))) {
              elem.firstChild.nodeValue = "Please enter numerical values only.";
              elem.className = "errorMsg";
              return false;
         }
	 if (!form[i-1].checked) {
              elem.firstChild.nodeValue = "Please select corresponding checkbox.";
              elem.className = "errorMsg";
              return false;
	 }
      } else if ((emptyString.test(form[i].value)) && (form[i-1].checked)) {
         elem.firstChild.nodeValue = "Please include an Amount.";
         elem.className = "errorMsg";
         return false;
      }
  }
  if (allEmpty==0) {
      elem.firstChild.nodeValue = "Please enter a value.";
      elem.className = "errorMsg";
      return false;
  }
  return true;
}

function addRR() {
 var url = window.location.href;
   if (url.indexOf("rr.com") > -1) {
       var d = document;
       var b  = d.getElementsByTagName("body")[0];
       var rr = document.createElement("div");
       so_applyStyleString(rr,"background:url(http://cdn.channel.aol.com/ch_global/rr_hdr_bg.gif) top right no-repeat; width:756px;");
       var rra = document.createElement("a");
       rra.setAttribute("href","http://www.rr.com");
       var rrimg = document.createElement("img");
       rrimg.setAttribute("src","http://cdn.channel.aol.com/ch_global/rr_hdr_l.gif");
       rrimg.setAttribute("alt","Road Runner");
       rra.appendChild(rrimg);
       rr.appendChild(rra);
       b.insertBefore(rr,b.firstChild);
   }
  
   function so_applyStyleString(obj,str) {
       if(document.all && !window.opera) {
           obj.style.setAttribute("cssText",str);
       } else {
           obj.setAttribute("style",str);
       }
   }
}

function goTab2(daform,chartform){
	if(!validateSym(daform.sym.value)){
		alert("There are characters in the symbol that are not allowed.");
		return;
	}
	var dist=daform.tabs.options[daform.tabs.selectedIndex].value;
	var sym=makeSym(daform.sym.value).toLowerCase();
	var pid=daform.pid.value;
	var exch=daform.exch.value.toLowerCase();
	var dur="";
	var symbs="";
	var compidx1="";
	var compidx2="";
	var compidx3="";
	var url="";
	if((dist=="charts")&&(chartform!=null)&&(chartform.dr.value)){
		dur=chartform.dr.value;
		symbs=chartform.symbs.value;
		if((chartform.compidx1!=null)&&(chartform.compidx1.checked==true))
			compidx1=chartform.compidx1.value;
		if((chartform.compidx2!=null)&&(chartform.compidx2.checked==true))
			compidx2=chartform.compidx2.value;
		if((chartform.compidx3!=null)&&(chartform.compidx3.checked==true))
			compidx3=chartform.compidx3.value;
	}
	else{
		dur=daform.dr.value;
		symbs=daform.symbs.value;
		compidx1=daform.compidx1.value;
		compidx2=daform.compidx2.value;
		compidx3=daform.compidx3.value;
	}
	if(dist=="quotesandnews"){
		if((sym!=null)&&(sym.length>0)){
			url="http://finance.aol.com/quotes/"+sym+"/"+exch+"?tabs="+dist;
		}
		else{
			url="http://finance.aol.com/quotes/"+exch+"?tabs="+dist;
		}
	}
	else{
		if((sym!=null)&&(sym.length>0)){
			url="http://finance.aol.com/quotes/"+sym+"/"+exch+"/"+dist+"?tabs="+dist;
		}
		else{
			url="http://finance.aol.com/quotes/"+exch+"/"+dist+"?tabs="+dist;
		}
	}
	if((pid!=null)&&(pid!=""))
		url+="&pid="+pid;
	if((symbs!=null)&&(symbs!=""))
		url+="&symbs="+symbs;
	if((dur!=null)&&(dur!=""))
		url+="&dr="+dur;
	if((compidx1!=null)&&(compidx1!=""))
		url+="&compidx1="+compidx1;
	if((compidx2!=null)&&(compidx2!=""))
		url+="&compidx2="+compidx2;
	if((compidx3!=null)&&(compidx3!=""))
		url+="&compidx3="+compidx3;
	if((dist=="charts")&&(chartform!=null)){
		if(chartform.ag.value)
			url+="&ag="+chartform.ag.value;
		if(chartform.index.value)
			url+="&index="+chartform.index.value;
		if(chartform.te.value)
			url+="&te="+chartform.te.value;
		if(chartform.se.value)
			url+="&se="+chartform.se.value;
		if(chartform.vl.checked==true)
			url+="&vl="+chartform.vl.value;
		if(chartform.ss.checked==true)
			url+="&ss="+chartform.ss.value;
		if(chartform.dv.checked==true)
			url+="&dv="+chartform.dv.value;
		if(chartform.hs.checked==true)
			url+="&hs="+chartform.hs.value;
		if(chartform.vs.checked==true)
			url+="&vs="+chartform.vs.value;
		if(chartform.state.value)
			url+="&state="+chartform.state.value;
		if(chartform.settings.value)
			url+="&settings="+chartform.settings.value;
		if(chartform.vl1.value)
			url+="&vl1="+chartform.vl1.value;
		if(chartform.ss1.value)
			url+="&ss1="+chartform.ss1.value;
		if(chartform.dv1.value)
			url+="&dv1="+chartform.dv1.value;
		if(chartform.hs1.value)
			url+="&hs1="+chartform.hs1.value;
		if(chartform.vs1.value)
			url+="&vs1="+chartform.vs1.value;
		if(chartform.scs.value)
			url+="&scs="+chartform.scs.value;
		if(chartform.daysb4.value)
			url+="&daysb4="+chartform.daysb4.value;
		if(chartform.fromdate.value)
			url+="&fromdate="+chartform.fromdate.value;
		if(chartform.todate.value)
			url+="&todate="+chartform.todate.value;
		if(chartform.freq.value)
			url+="&freq="+chartform.freq.value;
		if(chartform.timeframe.value)
			url+="&timeframe="+chartform.timeframe.value;
	}
	window.location=url;
}

function srchSub(ref){
  var frm=p_o("search");
  var queryval = frm.sym.value.trim();
  queryval = queryval.replace( /\+/, " ");
  newurl = ref.href + queryval;
  window.location = newurl;
  return false;
}

/****
Project: light xmlhttp library
Author : Amit Rai
Version : 1
****/


function xL(url,requestType,isAsync,requestData){

    var _url="";
    var _requestType="";
    var _isAsync=true;
    var _initialized=false;
    var _xmlHttpObject=false;
    var _valueStr="";
    var _requestData=new Object();
    var _debugMode=false;
    var _responseHandler=function(obj){};
    var _errMsg = "";
        
    var debugMsg = function(msg)
    {
        if(_debugMode)
        {
            alert(msg);
        }
    }
    
    var trim = function(str)
    {
           return str.replace(/^\s*|\s*$/g,"");
    }
    
    var createRequestValueString = function ()
    {
        var str=new String();
        var aObject = _requestData;
        
        for(var key in aObject)
        str=str+"&"+key+"="+aObject[key];
        
        if(_requestType=="GET")
        str="?"+str;

        return encodeURI(str);
    }
            
    var createXmlHttpObject = function ()
    {
        
        if(window.XMLHttpRequest && !(window.ActiveXObject)) 
        {// FF , mozilla and safari 
            try 
            {
                req = new XMLHttpRequest();
            
            } 
            catch(e) 
            {
                req = false;
            }
        } 
        else if(window.ActiveXObject) 
        {// IE Windows ActiveX version
               try 
            {
                req = new ActiveXObject("Msxml2.XMLHTTP");
              } 
            catch(e) 
            {
                try 
                {
                      req = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch(e) 
                {
                      req = false;
                }
            }
        }
        return req;
    }
    
    var init = function(url,requestType,isAsync,requestData)
    {
        
        if(url.length>11 && requestType.length>2)
        {
            _url=encodeURI(url);
            _requestType=requestType.toUpperCase();
            _initialized=true;
            _isAsync=isAsync;
            _xmlHttpObject = createXmlHttpObject();
            _requestData = requestData;
            _valueStr = createRequestValueString();
        } 
        else
        {
            debugMsg("Initialization data is not correct!");
        }
        
    }
    
    init(url,requestType,isAsync,requestData);
    
    var sendGetRequest = function()
    {
            if(_xmlHttpObject)
        {    
            _xmlHttpObject.onreadystatechange = function(){_responseHandler(_xmlHttpObject)};
            try
            {
                _xmlHttpObject.open(_requestType, _url+_valueStr, _isAsync);
                _xmlHttpObject.send(null);
            }
            catch(e)
            {
                _errMsg = e;
            }
        }
        return _errMsg;
    }
    
    var sendPostRequest = function()
    {
        if(_xmlHttpObject)
        {    
            _xmlHttpObject.onreadystatechange = function(){_responseHandler(_xmlHttpObject)};
            try
            {
                _xmlHttpObject.open(_requestType, _url, _isAsync);
                _xmlHttpObject.send(_valueStr);
            }
            catch(e)
            {
                _errMsg = e;
            }
        }
        return _errMsg;
    }
    
    var sendHeadRequest = function()
    {
        if(_xmlHttpObject)
        {
            _xmlHttpObject.onreadystatechange = function(){_responseHandler(_xmlHttpObject)};
        try
        {    
            _xmlHttpObject.open(_requestType, _url, _isAsync);
            _xmlHttpObject.send(null);
        }
        catch(e)
        {
            _errMsg = e;
        }
        }
        return _errMsg;
    }

    var alertAll = function()
    {
        if(_debugMode)
        {
            alert("_url = "+ _url + "\n _requestType= " + _requestType + "\n _isAsync= " + _isAsync);
            alert("_initialized " + _initialized + "\n _xmlHttpObject " +_xmlHttpObject + "\n _valueStr " +_valueStr);
        }
    }
    
    alertAll();
    
    return {
        
        abortRequest : function()
        {
            if(_xmlHttpObject.readyState!=4)
            {
                _xmlHttpObject.onreadystatechange = function (){};
                _xmlHttpObject.abort();
            }
        },
        
        getXmlHttpObject : function() {
            return createXmlHttpObject();
        },
        
        init : function(url,requestType,isAsync,requestData) {
            init(url,requestType,isAsync,requestData);
        },
        
        sendRequest : function() 
        {
            switch (_requestType)
            {
                case "GET":
                    sendGetRequest();
                    break;
                case "POST":
                    sendPostRequest();
                    break;
                case "HEAD":
                    sendHeadRequest();
                    break;
                default:
                    debugMsg(_requestType + " : request type not found");
            }
                        
            return _errMsg;
        },
        
        setResponseHandler : function(functionObj)
        {
            if((typeof functionObj)=="function"){
                _responseHandler = functionObj;
            }
        },
        
        setDebugMode : function(debug)
        {
            if(typeof(debug)=="boolean"){
                _debugMode=debug;    
            }
        }
            
    };//end return
} //end Xlib

/*Start:  JS code for the News Photogallery*/
//global news photogallery object loaded with default values,
//needs to be overridden on per module instance basis
    
var pgGlbObject = function() {
    this.pgTotalImages = 0;
    this.pgGalleryId = 0;
    this.glbPgTimer = 0;
    this.glbCurrentImg = 1;
    this.navAction = '';
    this.omnitureURL = 'omni_track';
    this.xmlUrl = 'common/photogallery/response.xml?&id=3&index=2&feedtype=news&navAction=next';
    this.feedType = 'news';
    this.magicNumber = 0;
    this.adContinue = 'See More Pictures';
    this.adCaption = 'ADVERTISEMENT';
    this.isAd = 0;
    this.gallerySize = '';
}

function appInit(modId){
    var debugMode = false;
    mI = window[modId];
    var queryParam = new Object();
    var requestParameters = new String();
    var today = new Date();
    
    if(mI.isAd == 0) {
       updateTallyNumber(modId);
    }
    
    queryParam['id'] = mI.pgGalleryId;
    queryParam['index'] = mI.glbCurrentImg;
    queryParam['feedtype'] = mI.feedType;
    queryParam['navAction'] = mI.navAction;
    queryParam['magicnumber'] = mI.magicNumber;
    queryParam['ts'] = today.getSeconds();
    queryParam['isAd'] = mI.isAd;
    queryParam['gallerySize'] = mI.gallerySize;
    url = mI.xmlUrl;

    reqType='GET';

    if(debugMode) {
        alert('id = '+mI.pgGalleryId + ' index= ' + mI.glbCurrentImg + ' feedtype= '+mI.feedType+' navAction= '+mI.navAction+' isAd= '+mI.isAd+' gallerySize= '+mI.gallerySize);
    }
    var objLap = new xL(url,reqType,true,queryParam);
                
    var serverErrorHandler = function(statusCode,statusMsg)
    {
        if(debugMode) {
            alert("Error Code : " + statusCode + " Message : " + statusMsg);
        }
    }
    
    var responseHandler = function(req) 
    {
        if(mI.glbPgTimer==0)
        {
            var timeOutErr = function() 
            {
                clearTimeout(mI.glbPgTimer);
                objLap.abortRequest();
            }
            mI.glbPgTimer = setTimeout(timeOutErr,5000);
        }
        // only if req shows "loaded"
        if (req.readyState == 4)
        {
            if (req.status == 200) 
            {
                resXML = req.responseXML;
                resTxt = req.responseText;
                uaStr = navigator.userAgent.toLowerCase();
               // Firefox has issue reading the xml returned from server
               if(uaStr.indexOf('firefox') != -1) {
                   if (document.implementation.createDocument && typeof(window.DOMParser) != "undefined") {
                       var parser = new DOMParser();
                       resXML = parser.parseFromString(resTxt, "text/xml");
                   }
               } 
                updateGallery(resXML,modId);
            } else {
                if(debugMode) {
                    alert("Error : "+req.getAllResponseHeaders());
                }
            }
        }
        //end main if else
    }       
    
    objLap.setResponseHandler(responseHandler);
    
    err=objLap.sendRequest();
    
    if(err.length>0 && debugMode==true)
    {
        alert(err);
    }
}

function updateGallery(resXML,modId) {
    var debugMode = false;
    var i = 0;
    var mod = "_" + modId;
    var mI = window[modId];
    var root = document.getElementById('newsmaker_'+modId);
 
    //only if the proper data is returned 
    if(resXML.getElementsByTagName("img")[0]) {
        document.getElementById('ad'+mod).style.display='none';

        //set the required values from xml fragment
        var isAd = getNodeValue(resXML.getElementsByTagName("isAd")[0]);
        if (isAd != "1") {
            var pgCredit = getNodeValue(resXML.getElementsByTagName("pgcredits")[0]);
            var photoCaption = getNodeValue(resXML.getElementsByTagName("photocaption")[0]);
            var imgSrc = resXML.getElementsByTagName("img")[0].getAttribute('src');
            var imgAlt = resXML.getElementsByTagName("img")[0].getAttribute('alt');

            if(debugMode) {
                alert('isAd='+isAd+'pgCredit='+pgCredit+'photoCaption='+photoCaption+'imgSrc='+imgSrc);
            }

            //update the dom information
            document.getElementById('pg_ImgMain'+ mod).style.display="block";
            document.getElementById('pg_ImgMain'+ mod).src = imgSrc;
            document.getElementById('pg_ImgMain'+ mod).alt = imgAlt;
            document.getElementById('pg_credits' + mod).innerHTML = pgCredit;
            document.getElementById('center_pic_cont' + mod).innerHTML = photoCaption;
            
            if(mI.navAction == 'next') {
                document.getElementById('newsmakerTally' + mod).innerHTML = mI.glbCurrentImg + " of " + mI.pgTotalImages;
                sendOmnitureData(resXML,modId);
            }

            if(mI.navAction == 'prev') {
                 sendOmnitureData(resXML,modId);
                 document.getElementById('newsmakerTally' + mod).innerHTML = mI.glbCurrentImg + " of " + mI.pgTotalImages;
            }

            //ad refresh on image change
            try {
                ch_refresher.refresh_ads();
            } catch(e) {}
        }
    }// end main if

   // if the isAd parameter in response xml is 1 
    if(getNodeValue(resXML.getElementsByTagName("isAd")[0])==1) {
        try { 
            document.getElementById('pg_ImgMain'+ mod).style.display="none";
            document.getElementById('pg_credits' + mod).innerHTML = mI.adCaption.toUpperCase();
            document.getElementById('newsmakerTally' + mod).innerHTML = mI.adContinue;
            document.getElementById('center_pic_cont' + mod).innerHTML = "";
            var adCont = document.getElementById('ad'+mod);
            
            if(!document.getElementById('ifr'+mod)) {
                var ifr = document.createElement('iframe');
                ifr.setAttribute('id','ifr'+mod);
                ifr.style.height='250px';
                ifr.style.widht='300px';
                ifr.style.overflow='hidden';
                ifr.frameBorder='0';
                if(ifr.scrolling){
                   ifr.scrolling='no';
                }
            } else{
              ifr = document.getElementById('ifr'+mod);
            }
            var adURL = mI.adURL + mI.magicNumber;
            ifr.src = adURL;
            adCont.appendChild(ifr);
            adCont.style.display='block';
        } catch(e) {
          if(debugMode)
             alert(e);
        }
        
    }

    //set the isAd value in module object, this is needed to prevent the ad fromo looping
    mI.isAd = getNodeValue(resXML.getElementsByTagName("isAd")[0]);
}// end updateGallery

function updateTallyNumber(modId) {
    var mI = window[modId];
    if(mI.navAction == 'next') {
    
        if(mI.glbCurrentImg < mI.pgTotalImages) {
            ++mI.glbCurrentImg;
            mI.navAction = 'next';
        } else {
            mI.glbCurrentImg=1;
            mI.navAction = 'next';
        }
    
    } 

    if(mI.navAction == 'prev') {

        if(mI.glbCurrentImg > 1) {
             --mI.glbCurrentImg;
            mI.navAction = 'prev';
        }
        else 
        {
            mI.glbCurrentImg=mI.pgTotalImages;
            mI.navAction = 'prev';
        }

    }
} // end updateTallyNumber

function getNodeValue(node) {
    var val = "";

    if (node != undefined || node != null){ 
        if(node.nodeValue == null || node.nodeValue == undefined){
            try {
                val = node.firstChild.nodeValue;
        } catch (e){}
      }
  }

    return val;
}

function sendOmnitureData(resXML,modId) {
    var mI = window[modId];
    var omniUrl = mI.omnitureURL;
    var reqType= "GET";
    var qp = new Object();
    str = "?";
    qp['id'] = mI.pgGalleryId;
    qp['index'] = mI.glbCurrentImg;
    qp['feedtype'] = mI.feedType;
    qp['navAction'] = mI.navAction;
    qp['debug'] = 0;
    
    if(document.getElementById('pgOmniIframe'+modId)) {
        ifr = document.getElementById('pgOmniIframe'+modId);
    } else {
        ifr = document.createElement('iframe');
        ifr.setAttribute('id','pgOmniIframe'+modId);
        ifr.width=0;
        ifr.height = 0;
        ifr.border = 0;
        ifr.style.visibility = 'hidden';
        document.body.appendChild(ifr);
    }

    for(var key in qp)
        str=str+"&"+key+"="+qp[key];
    
    omniUrl = omniUrl + str;
    ifr.src = omniUrl;
}

function nextImg(modId) {
    mI = window[modId];
    mI.navAction = 'next';
    appInit(modId);
    return false;
}

function prevImg(modId) {
    mI = window[modId];
    mI.navAction = 'prev';
    appInit(modId);
    return false;
}
/*End:  JS code for the News Photogallery*/

/*new modules 2007 July ****/
function mnc_myportfolio_sub(obj) {
    ourElement ="mnc_myportfolio_sub" +elemNum ; 
    openIMG = "openSesame" +elemNum ;
    moduleString ='';

    /* if the the div clicked is the same as the one before AND was not closed before, do not open div again */
    if (previousElemNum == elemNum && previousElemNum != -1){
        previousElemNum = -1;
        return false;
    }
    //try looping thru symlist results from ajax call
    try{
        moduleString +='<div class="seesub"><p class="seesubhead">Portfolio Holdings</p></div><table class="marketData" border="0" cellpadding="0" cellspacing="0">';
    moduleString +='<thead><tr class="header"><th class="th_symbol">Symbol</th><th class="th_last">Last</th><th class="th_change" colspan="3">Change</th><th>&nbsp;</th><th>&nbsp;</th></tr></thead><tbody>'

        for(var i=0;i<obj.ResultSet.symslist.length;i++){
	    var stockDirection = "";

	    if(obj.ResultSet.symslist[i].c.indexOf("+") != -1)
	        var stockDirection = "positive"; 
	    else if(obj.ResultSet.symslist[i].c.indexOf("-") != -1)
	        var stockDirection = "negative";

            moduleString +='<tbody><tr class="' + stockDirection + '"><td class="wl_Symbol"><a  title="' + obj.ResultSet.symslist[i].n + '" href="' + obj.ResultSet.symslist[i].lu + '">' + obj.ResultSet.symslist[i].s + '</a></td>';
            moduleString +='<td class="last">' + obj.ResultSet.symslist[i].p + '</td>';
            moduleString +='<td  class="amountIncr">' + obj.ResultSet.symslist[i].c.replace('+','&nbsp;&nbsp;') + '</td>';
            moduleString +='<td class="moneyarrow">&nbsp;</td>';

            if (obj.ResultSet.symslist[i].pc.indexOf('N/A') < 0)
	        moduleString +='<td class="percentIncr">' + obj.ResultSet.symslist[i].pc.replace('+','').replace('-','') + '%</td>';
            else
	        moduleString +='<td class="percentIncr">' + obj.ResultSet.symslist[i].pc + '</td>';

            moduleString +='<td class="wl_chart" title="See Chart for ' + obj.ResultSet.symslist[i].s + '"><a href="' + obj.ResultSet.symslist[i].lu + '/charts">&nbsp;&nbsp;&nbsp;&nbsp;</a></td>';
            moduleString +='<td class="wl_headlines" title="See Latest Headlines for ' + obj.ResultSet.symslist[i].s + '"><a href="' + obj.ResultSet.symslist[i].lu.replace("/quotes/","/headlines/") + '">&nbsp;&nbsp;&nbsp;&nbsp;</a></td></tr>';


        }
    moduleString +='</tbody></table>';
    headlines ='';
    headlinesLoop = ''; 
    headlines = '<div class="seesub2"><p class="seesubhead">Top Headlines</p>';

    //try looping thru news results from ajax call
    try{
        for(var i=0;i<obj.ResultSet.newspress.length && i<newsMAX;i++){
            headlinesLoop +='<div class="headlines"><span class="headsymbol">' + obj.ResultSet.newspress[i].s + '&nbsp;&nbsp;-&nbsp;&nbsp;';
            headlinesLoop +='<a href="' + obj.ResultSet.newspress[i].u + '" >' + obj.ResultSet.newspress[i].h.substr(0,35);
            if(obj.ResultSet.newspress[i].h.length > 35) 
                headlinesLoop += '...';
	    if(obj.ResultSet.newspress[i].d.indexOf("AM") > -1 || obj.ResultSet.newspress[i].d.indexOf("PM") > -1)
                headlinesLoop +='</a><br /><span class="headlinedate"><b>' + obj.ResultSet.newspress[i].d + '&nbsp;</b></span>';
	    else
		headlinesLoop +='</a><br /><span class="headlinedate">' + obj.ResultSet.newspress[i].d + '&nbsp;</span>';
            headlinesLoop +='<span class="headlinesource">|&nbsp;' + obj.ResultSet.newspress[i].i + '</span>';
            headlinesLoop +='</div>';
        }
        headlinesLoop +='<div class="pfeditview"><a class="pfview" href="' + document.getElementById("viewUrl" + elemNum).innerHTML + '">More Headlines</a></div>';
    }catch(err){
       headlinesLoop ='<div class="headlines">No news for these symbols at this time.</div>'; 
    }
    headlines += headlinesLoop +'<div class="pfeditview"><a class="pfedit" href="' + document.getElementById("viewUrl" + elemNum).innerHTML.replace("view","edit") + '">Edit Portfolio</a><a class="pfview" href="' + document.getElementById("viewUrl" + elemNum).innerHTML + '">View Porfolio</a></div></div>';

    headlines += '<div class="hidesum"><a href="javascript:void(0);" title="Hide Portfolio" onclick="javascript:closePortDiv();elemNum=-1;" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hide</a></div>';

    moduleString += headlines;
    //alert(moduleString)
    //portfolio
    document.getElementById(ourElement).innerHTML = moduleString;
    document.getElementById(ourElement).style.display = 'block';
    //flips expand image and changes row background
    document.getElementById("portRow" +elemNum).setAttribute("class", "activePortRow");
    document.getElementById("portRow" +elemNum).setAttribute("className", "activePortRow");
    document.getElementById("openSesame" +elemNum).title = "Hide Portfolio";

    //visible portfolio is now given a border and background
    document.getElementById(ourElement).style.borderBottom = '1px solid #DEDDE2';
    document.getElementById("mnc_myportfolio_sub" +elemNum).style.background = '#F7F7F7';
    document.getElementById("portSubRow" +elemNum).style.background = '#F7F7F7';

    previousElemNum = elemNum;
    }catch(err){
        //alert(err);
    }
}

//default function to use to make json calls
function ensureUploadScriptIsLoaded(jsonCall) {
    var head = document.getElementsByTagName("body")[0];
    script = document.createElement('script');
    script.id = 'uploadScript';
    script.type = 'text/javascript';
    script.src = jsonCall;
    head.appendChild(script);
}

//function to close individual portfolios
function closePortDiv(){
    if (elemNum > 0) {
        document.getElementById("portRow" +elemNum).setAttribute("class", "inactivePortRow");
        document.getElementById("portRow" +elemNum).setAttribute("className", "inactivePortRow");
        document.getElementById("mnc_myportfolio_sub" +elemNum).style.display = 'none';
        document.getElementById("portSubRow" +elemNum).style.background = 'none';
        document.getElementById("portRow" +elemNum).style.fontWeight = 'normal';
        document.getElementById("openSesame" +elemNum).title = "Show Portfolio";
    }
    elemNum = -1;
}

//function to get cookie
function getCookie(NameOfCookie){
    if (document.cookie.length > 0) {              
        begin = document.cookie.indexOf(NameOfCookie+"=");       
        if (begin != -1) {           
            begin += NameOfCookie.length+1;       
            end = document.cookie.indexOf(";", begin);
            if (end == -1) end = document.cookie.length;
                return unescape(document.cookie.substring(begin, end));
        } 
    }
    return null;
}

//function to set cookie
function setCookie(NameOfCookie, value, expiredays) {
    var ExpireDate = new Date ();
    ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

    document.cookie = NameOfCookie + "=" + escape(value) + 
    ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie) {
    if (getCookie(NameOfCookie)) {
        document.cookie = NameOfCookie + "=" +
        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

//function to display watchlist contents
function mnc_watchlist(obj) {   
    var addportfolioStr;
    document.getElementById("mnc_portfolios").style.display = "none";
    document.getElementById("mnc_recentquotes").style.display = "none";
    document.getElementById("mnc_watchlist").style.display = "block";
    document.getElementById("watchNav").setAttribute("class", "activeTab");
    document.getElementById("portNav").setAttribute("class", "");
    document.getElementById("recentNav").setAttribute("class", "");
    document.getElementById("watchNav").setAttribute("className", "activeTab");
    document.getElementById("portNav").setAttribute("className", "");
    document.getElementById("recentNav").setAttribute("className", "");

    moduleString ='';
    moduleString ='<div class="smybolPut"  id="smybolPut"><form action="javascript:addWatchList();">';
    moduleString +='<input class="addwatchlist" id="addwatchlist" type="text" onClick="if(userAdding==0)this.value=\'\';userAdding=1;" value="Enter symbol(s) separated by commas" name="sym" maxlength="80" alt="Enter a symbol here" tabindex="0">';
moduleString +='<a class="aolBtn watchlist_button" href="javascript:addWatchList();" title="Add Symbol(s)" type="submit">Add</a></form></div>';
    moduleString +='<div class="symbolErr"  id="symbolErr">' + defSymErr + '</div>';

    //if user has no cookie is set, or cookie has no symbols, display default message
    if(!AOL_StockQuotesWatchList || AOL_StockQuotesWatchList=="" || AOL_StockQuotesWatchList.replace(",","").length==0){
moduleString +='<center><br /><a href="http://finance.aol.com/usw/portfolios/myportfolios"><b>Track Your Stocks Here!</b></a><br />Find out why more people track their stocks on<br />AOL Money and Finance than anywhere else.<br /><br /></center>'

    }else{
        moduleString +='<table class="marketData" border="0" cellpadding="0" cellspacing="0"><thead>';
moduleString +='<tr class="header"><th class="th_symbol">Symbol</th><th>&nbsp;</th><th class="th_last">Last</th><th colspan="3" class="th_change">Change</th><th>&nbsp;</th></tr>'
            //looping thru results from json call  
  	    for(var i=0;i<obj.ResultSet.symslist.length;i++){
                //this stores the direction of increase/decrease of stocks
        	var stockDirection = "";

        	if(obj.ResultSet.symslist[i].c.indexOf("+") != -1)
	    	    var stockDirection = "positive"; 
        	else if(obj.ResultSet.symslist[i].c.indexOf("-") != -1)
	    	    var stockDirection = "negative";
 
        	    moduleString +='<tr class="' + stockDirection + '"><td class="wl_Symbol"><a title="' + obj.ResultSet.symslist[i].s + ': ' + obj.ResultSet.symslist[i].n + ' Quote, News & Summary" href="' + obj.ResultSet.symslist[i].lu + '">' + obj.ResultSet.symslist[i].s.substring(0,5);
      	           if(obj.ResultSet.symslist[i].s.length > 5)
		        moduleString +='...';
    	                moduleString +='</a></td><td><a class="wl_delete" href="" onClick="javascript:delFromList(\'' + obj.ResultSet.symslist[i].s + '\');return false;" title="Remove ' + obj.ResultSet.symslist[i].s + ' from Watchlist">&nbsp;&nbsp;</a></td>';
    	                moduleString +='<td class="last">' + obj.ResultSet.symslist[i].p + '</td>';
    	                moduleString +='<td class="amountIncr">' + obj.ResultSet.symslist[i].c.replace('+','&nbsp;') + '</td>';
    	                moduleString +='<td class="moneyarrow">&nbsp;</td>';
    	                moduleString +='<td class="percentIncr">' + obj.ResultSet.symslist[i].pc.replace('+','').replace('-','') + '%</td>';
    	                moduleString +='<td><a class="wl_headlines" title="' + obj.ResultSet.symslist[i].s + ': ' + obj.ResultSet.symslist[i].n + ' News & Analysis" href="' + obj.ResultSet.symslist[i].lu.replace('/quotes/','/news/') + '?more=news">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td></tr>';
	
    	           }
                   //portion of cookie to use to add new portfolio 
                   addportfolioStr = AOL_StockQuotesWatchList.substring(1,AOL_StockQuotesWatchList.length - 1);

    	           moduleString +='<tr><td colspan="3" class="clearall"><a class="aolBtn watchlist_button" href="javascript:delAllList();" title="Clear All"/>Clear All</a></div></td><td colspan="4" class="wl_right"><a href="http://finance.aol.com/usw/portfolios/advancedCreate?symbols=' + addportfolioStr.replace(/,/g,'&exchange=NYS&symbols=') + '&exchange=NYS">Save as New Portfolio</a></td></tr></table>';
           
            }
            //display watchlist
	    document.getElementById('mnc_watchlist').innerHTML = moduleString;

        //if a bad symbol was added while this function was adding symbols, display message
        if(goodSymbol==0)
            document.getElementById("symbolErr").innerHTML =symbolErr;

        //max has been set to 100 symbols otherwise error message displays
        if(maxReached==1)
            document.getElementById("symbolErr").innerHTML ="<span class=\"errDiv\">You can only have " + watchlistMAX + " symbols in  your Watchlist.  Please remove some to add more.</span>"; 
}

function showPortfolio(){
    document.getElementById("mnc_watchlist").style.display = "none";
    document.getElementById("mnc_recentquotes").style.display = "none";
    document.getElementById("mnc_portfolios").style.display = "block";
    document.getElementById("portNav").setAttribute("class", "activeTab");
    document.getElementById("watchNav").setAttribute("class", "");
    document.getElementById("recentNav").setAttribute("class", "");
    document.getElementById("portNav").setAttribute("className", "activeTab");
    document.getElementById("watchNav").setAttribute("className", "");
    document.getElementById("recentNav").setAttribute("className", "");
}

//ajax call for one symbol to validate get and pass on to errorcheck 
function validateSymbol(ourSymbol){
   var head = document.getElementsByTagName("body")[0];
   script = document.createElement('script');
   script.id = 'uploadScript';
   script.type = 'text/javascript';
   script.src = 'http://portal.pf.aol.com/jsonqpus/ws?service=symslist&exchange=USA&symbols=' + ourSymbol + '&callback=errorCheck';
   head.appendChild(script);
}

//watchlist symbol is added
function errorCheck( obj ){
    
    try{
 	flagVar = obj.ResultSet.symslist[0].pc.length;
	var sym = obj.ResultSet.symslist[0].s;
        if ( sym && AOL_StockQuotesWatchList.indexOf("," + sym + ",") == -1 ) {
	   if(AOL_StockQuotesWatchList.split(",").length > watchlistMAX + 1 || maxReached == 1){
		document.getElementById("symbolErr").innerHTML= "You can only have " + watchlistMAX + " symbols in your Watchlist.  Please remove some to add more.";
	        maxReached = 1; 
	   }else if(sym.length > 0){
               if (!AOL_StockQuotesWatchList){
                   setCookie("AOL_StockQuotesWatchList", "," + sym + ",", 90) ;
               }else{
                   AOL_StockQuotesWatchList = sortString("," + sym + AOL_StockQuotesWatchList);
                   setCookie("AOL_StockQuotesWatchList", AOL_StockQuotesWatchList, 90);
               }

               AOL_StockQuotesWatchList = getCookie("AOL_StockQuotesWatchList");

               ensureUploadScriptIsLoaded('http://portal.pf.aol.com/jsonqpus/ws?service=symslist&exchange=USA&symbols=' + AOL_StockQuotesWatchList +'&callback=mnc_watchlist');
               document.getElementById('addwatchlist').value = addText;
               userAdding=0;//indicates user is no longer in the process of adding
	       }
        }
    }catch(err){
 	goodSymbol = 0;document.getElementById("symbolErr").innerHTML =symbolErr; 
    }
	
}

//add new watchlist symbols
function addWatchList(){
   //start addition clean 
    if(errFlag==1){
        document.getElementById("symbolErr").innerHTML =defSymErr;
        errFlag=0;
    }
    goodSymbol = 1;
    var additions = document.getElementById('addwatchlist').value.replace(/ /g,',').toLowerCase();
    var ourArray=additions.split(",");
    for (i=0; i<ourArray.length; i++){
        validateSymbol(ourArray[i]);
    }
    if ( goodSymbol == 0){
        errFlag=1; goodSymbol = 1;
    }
}

//delete symbol by symbol
function delFromList( sym ){
   //remove error shown if any 
   document.getElementById("symbolErr").innerHTML =defSymErr;
   sym= sym.toUpperCase();
   goodSymbol=1;
   errFlag=0;
   if( AOL_StockQuotesWatchList.indexOf("," + sym + ",") > -1){

        setCookie("AOL_StockQuotesWatchList", AOL_StockQuotesWatchList.replace("," + sym + ",",","), 90);
    }
    AOL_StockQuotesWatchList = getCookie("AOL_StockQuotesWatchList");
    //if comma is left delete cookie
    if(AOL_StockQuotesWatchList==",")AOL_StockQuotesWatchList="";
    ensureUploadScriptIsLoaded('http://portal.pf.aol.com/jsonqpus/ws?service=symslist&exchange=USA&symbols=' + AOL_StockQuotesWatchList +'&callback=mnc_watchlist');
    if(AOL_StockQuotesWatchList==",")delCookie("AOL_StockQuotesWatchList");
    document.getElementById('addwatchlist').value = addText;
    maxReached = 0;
    userAdding = 0;
}
//delete all symbols
function delAllList(){

    //remove error shown if any
    document.getElementById("symbolErr").innerHTML =defSymErr;
    errFlag=0;
    maxReached = 0;
    userAdding = 0;
    maxReached = 0;
    goodSymbol=1;
    delCookie("AOL_StockQuotesWatchList");
    AOL_StockQuotesWatchList="";
    ensureUploadScriptIsLoaded('http://portal.pf.aol.com/jsonmfus/ws?service=symslist&exchange=USA&symbols=' + AOL_StockQuotesWatchList +'&callback=mnc_watchlist');
}

var mostactivesURL = "http://portal.pf.aol.com/jsonmfus/ws?service=mostactives,&exchange=";

function show_marketmovers(xchnge){

        ensureUploadScriptIsLoaded(mostactivesURL + xchnge + '&mosttype=0,3,4&&mostmax=' + symbolMax[0] + '&callback=mnc_marketmovers');
}

function mnc_marketmovers(obj) {
    marketmoversString = "";
    //most actives
    subSection++;
    mostActiveObj = obj.ResultSet.mostactives[0].mostactive0;
    marketmoversString +='<h3>' + catTitle[subSection-1]  + '</h3>';
    marketmoversString +='<table class="marketData" border="0" cellpadding="0" cellspacing="0">';
    marketmoversString +='<thead><tr class="header"><th class="th_symbol">Symbol</th><th class="th_last">Last</th><th colspan="3" class="th_change">Change</th><th class="th_volume">Volume</th></tr></thead><tbody>';

    for(var i=0;i<mostActiveObj.length;i++){
        var stockDirection = "";
        if(mostActiveObj[i].c.indexOf("+") != -1)
            var stockDirection = "positive"; 
        else if(mostActiveObj[i].c.indexOf("-") != -1)
            var stockDirection = "negative";

        marketmoversString +='<tr class="' + stockDirection + '">';
        marketmoversString +='<td class="wl_Symbol"><a title="' + mostActiveObj[i].s + ': ' + mostActiveObj[i].n + ' Quote, News & Summary" href="' + mostActiveObj[i].lu + '">'  

        if(mostActiveObj[i].s.length>5)
            marketmoversString +=mostActiveObj[i].s.substr(0,4) + '...</a></td>';
	else
	    marketmoversString +=mostActiveObj[i].s + '</a></td>';

        marketmoversString +='<td class="last">' + mostActiveObj[i].p + '</td>';
        marketmoversString +='<td class="amountIncr">' + mostActiveObj[i].c.replace('+','&nbsp;') + '</td>';
        marketmoversString +='<td class="moneyarrow">&nbsp;</td>';
        marketmoversString +='<td class="percentIncr">' + mostActiveObj[i].pc.replace('+','').replace('-','') + '%</td>';
        marketmoversString +='<td class="mv_volume">' + mostActiveObj[i].v + '</td></tr>';	

    }
    marketmoversString +='</tbody></table><div class="footerLink"><a href="' + catLinksLnk[subSection-1]  + '">' + catLinksLbl[subSection-1]  + '</a></div>';
    
    //biggest gainers
    subSection++;
    mostActiveObj = obj.ResultSet.mostactives[1].mostactive3;
    marketmoversString +='<h3>' + catTitle[subSection-1]  + '</h3>';
    marketmoversString +='<table class="marketData" border="0" cellpadding="0" cellspacing="0">';
    marketmoversString +='<thead><tr class="header"><th class="th_symbol">Symbol</th><th class="th_last">Last</th><th colspan="3" class="th_change">Change</th><th class="th_volume">Volume</th></tr></thead><tbody>';

    for(var i=0;i<mostActiveObj.length;i++){
        var stockDirection = "";
        if(mostActiveObj[i].c.indexOf("+") != -1)
            var stockDirection = "positive"; 
        else if(mostActiveObj[i].c.indexOf("-") != -1)
            var stockDirection = "negative";

        marketmoversString +='<tr class="' + stockDirection + '">';
        marketmoversString +='<td class="wl_Symbol"><a title="' + mostActiveObj[i].s + ': ' + mostActiveObj[i].n + ' Quote, News & Summary" href="' + mostActiveObj[i].lu + '">'  

        if(mostActiveObj[i].s.length>5)
            marketmoversString +=mostActiveObj[i].s.substr(0,4) + '...</a></td>';
	else
	    marketmoversString +=mostActiveObj[i].s + '</a></td>';

        marketmoversString +='<td class="last">' + mostActiveObj[i].p + '</td>';
        marketmoversString +='<td class="amountIncr">' + mostActiveObj[i].c.replace('+','&nbsp;') + '</td>';
        marketmoversString +='<td class="moneyarrow">&nbsp;</td>';
        marketmoversString +='<td class="percentIncr">' + mostActiveObj[i].pc.replace('+','').replace('-','') + '%</td>';
        marketmoversString +='<td class="mv_volume">' + mostActiveObj[i].v + '</td></tr>';	

    }
    marketmoversString +='</tbody></table><div class="footerLink"><a href="' + catLinksLnk[subSection-1]  + '">' + catLinksLbl[subSection-1]  + '</a></div>';
    
    //biggest losers
    subSection++;
    mostActiveObj = obj.ResultSet.mostactives[2].mostactive4;  
     marketmoversString +='<h3>' + catTitle[subSection-1]  + '</h3>';
    marketmoversString +='<table class="marketData" border="0" cellpadding="0" cellspacing="0">';
    marketmoversString +='<thead><tr class="header"><th class="th_symbol">Symbol</th><th class="th_last">Last</th><th colspan="3" class="th_change">Change</th><th class="th_volume">Volume</th></tr></thead><tbody>';

    for(var i=0;i<mostActiveObj.length;i++){
        var stockDirection = "";
        if(mostActiveObj[i].c.indexOf("+") != -1)
            var stockDirection = "positive"; 
        else if(mostActiveObj[i].c.indexOf("-") != -1)
            var stockDirection = "negative";

        marketmoversString +='<tr class="' + stockDirection + '">';
        marketmoversString +='<td class="wl_Symbol"><a title="' + mostActiveObj[i].s + ': ' + mostActiveObj[i].n + ' Quote, News & Summary" href="' + mostActiveObj[i].lu + '">'  

        if(mostActiveObj[i].s.length>5)
            marketmoversString +=mostActiveObj[i].s.substr(0,4) + '...</a></td>';
	else
	    marketmoversString +=mostActiveObj[i].s + '</a></td>';

        marketmoversString +='<td class="last">' + mostActiveObj[i].p + '</td>';
        marketmoversString +='<td class="amountIncr">' + mostActiveObj[i].c.replace('+','&nbsp;') + '</td>';
        marketmoversString +='<td class="moneyarrow">&nbsp;</td>';
        marketmoversString +='<td class="percentIncr">' + mostActiveObj[i].pc.replace('+','').replace('-','') + '%</td>';
        marketmoversString +='<td class="mv_volume">' + mostActiveObj[i].v + '</td></tr>';	

    }
    marketmoversString +='</tbody></table><div class="footerLink"><a href="' + catLinksLnk[subSection-1]  + '">' + catLinksLbl[subSection-1]  + '</a></div>';
   
    document.getElementById("mnc_marketmovers_sub").innerHTML = marketmoversString;

    //pass in tab as selected, resets all and sets active tab
    reset_tabs("mkMovertab", 3,marketmoveTB);
    subSection = 0;
}

function reset_tabs(idString, num, setLoc){
   for(i=1; i<num+1; i++){ 
      document.getElementById(idString+i).setAttribute("class", "inActiveTab");
      document.getElementById(idString+i).setAttribute("className", "inActiveTab");
   } 
   document.getElementById(idString+setLoc).setAttribute("class", "activeTab");
   document.getElementById(idString+setLoc).setAttribute("className", "activeTab");

}

//adrefreshes
function adRefresh() {
    if (refreshAD>0) {
        var adSpots = '0';
        try {
        if (pgAdSpots != null && pgAdSpots != 'undefined' && pgAdSpots != '') {
                adSpots = pgAdSpots;
        }
        } catch(e) {
                adSpots = '0';
        }
        try {
	  top.ch_refresher.refresh_ads();
        } catch(e) { }
    }
        return true;
}

var arrMarketData = new Array();

//Market News
function buildArray(obj) {

	var arrayString;
	var lastItem = 4;
	var totalItems = obj.ResultSet.symslist.length;

	var mktAcronym, curPrice, todayDelta, pctDelta,stockDirection, thisUrl;

	// empty the array for fresh data to be pushed into from JSON call.
	arrMarketData = new Array(); 

	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	// + Let's populate the 'multidimensional' array with     +
	// + data culled from the JSON call.                      +
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	for (i = 0;i < totalItems; i++) {

	    mktAcronym = obj.ResultSet.symslist[i].s;
	    curPrice = obj.ResultSet.symslist[i].p;
	    todayDelta = obj.ResultSet.symslist[i].c;
	    pctDelta = obj.ResultSet.symslist[i].pc.replace('+','');
            if(obj.ResultSet.symslist[i].c.indexOf("+") != -1)
	        stockDirection = "U"; 
            else if(obj.ResultSet.symslist[i].c.indexOf("-") != -1)
	    	stockDirection = "D";
	    thisUrl = obj.ResultSet.symslist[i].lu;
            mktXch = obj.ResultSet.symslist[i].x;

	    arrMarketData.push([mktAcronym, curPrice, todayDelta, pctDelta, stockDirection, thisUrl, mktXch]);

	}


}

function buildArrayStay(obj) {

        buildArray(obj);

        displaySymbolData(last);
        select_tabs(first);

        paginationData = tabCount + " of " + arrMarketData.length;
        document.getElementById("carouselPagination").innerHTML = paginationData;
        paintButtons();
} // end buildArrayNext


function buildArrayNext(obj) {

	buildArray(obj);
	if(tabCount < arrMarketData.length) {
	    paginationData = ++tabCount + " of " + arrMarketData.length;
	    document.getElementById("carouselPagination").innerHTML = paginationData;

	    if(first%4==0) {
		 first=1;last=tabCount+2;
		 displaySymbolData(last);
		 select_tabs(1);
	    } else if(tabCount < arrMarketData.length+1){
			
		 first++;//alert("last: "+last);
		 displaySymbolData(last);
		 select_tabs(first);

            }
		
	   paintButtons();
        }


} // end buildArrayNext

function buildArrayPrevious(obj) {
	buildArray(obj);
	if(tabCount > 1) {
	    paginationData = --tabCount + " of " + arrMarketData.length;
	    document.getElementById("carouselPagination").innerHTML = paginationData;
	
	    if (first > 1) {

		reset_carousel_tabs('carousel-tab-',4,--first);

	    } else {
		last=tabCount-1;

		displaySymbolData(last);
		select_tabs(4);first=4;
	    }

    	    paintButtons();
	}

} // end buildArrayPrevious
			
function paintButtons(){

    if(!(tabCount < arrMarketData.length)){
	document.getElementById("next-button").setAttribute("class", "carousel-Btn-disabled");
	document.getElementById("next-button").setAttribute("className", "carousel-Btn-disabled");
    }else{
	document.getElementById("next-button").setAttribute("class", "carousel-Btn");
	document.getElementById("next-button").setAttribute("className", "carousel-Btn");
    }

    if(tabCount == 1){
	document.getElementById("previous-button").setAttribute("class", "carousel-Btn-disabled");
	document.getElementById("previous-button").setAttribute("className", "carousel-Btn-disabled");
    }else{
	document.getElementById("previous-button").setAttribute("class", "carousel-Btn");
	document.getElementById("previous-button").setAttribute("className", "carousel-Btn");
    }
    var s_265=s_gi(clickTrack); 
    s_265.linkTrackVars='prop23'; 
    s_265.linkTrackEvents='None'; 
    s_265.prop23 = s_265.pageName + ' Market News Symbol: ' + arrMarketData[tabCount - 1][0];
    s_265.tl(true,'o', s_265.pageName + ' Market News Tab: ' + tabCount); 
}

var last = 3;
var first = 1;
var arrMarketData = [];
var myDiv, myDiv2;
var selTabInit;
var tabCount = 1;
var paginationData;
var currentDirection = "";
var clickTrack = "aolpf";

function callTab(direction){
    currentDirection = direction;
    if(direction=="next")
 	ensureUploadScriptIsLoaded('http://portal.pf.aol.com/jsonmfus/ws?service=symslist&exchange=USA&symbols=' + marketNewsStocks + '&callback=buildArrayNext');
    else if(direction=="previous")
   	ensureUploadScriptIsLoaded('http://portal.pf.aol.com/jsonmfus/ws?service=symslist&exchange=USA&symbols=' + marketNewsStocks + '&callback=buildArrayPrevious');
    else
    	ensureUploadScriptIsLoaded('http://portal.pf.aol.com/jsonmfus/ws?service=symslist&exchange=USA&symbols=' + marketNewsStocks + '&callback=buildArrayStay');
 
} 


function displaySymbolData(last){
    if(last-3<arrMarketData.length)document.getElementById("carousel-tab-1").innerHTML = stockLabelsArr[last - 3]+'<div class="tab-data">' + arrMarketData[last - 3][1] + '<p class="' + arrMarketData[last - 3][4] + '"><span class="amountIncr">'+arrMarketData[last-3][2]+'</span><span class="moneyarrow"> </span><span class="percentIncr">'+arrMarketData[last - 3][3]+'%</span></p></div>'; else document.getElementById("carousel-tab-1").innerHTML="";
    if(last-2<arrMarketData.length)document.getElementById("carousel-tab-2").innerHTML = stockLabelsArr[last - 2]+'<div class="tab-data">' + arrMarketData[last - 2][1] + '<p class="' + arrMarketData[last - 2][4] + '"><span class="amountIncr">'+arrMarketData[last - 2][2]+'</span><span class="moneyarrow"> </span><span class="percentIncr">'+arrMarketData[last - 2][3]+'%</span></p></div>'; else document.getElementById("carousel-tab-2").innerHTML="";
    if(last-1<arrMarketData.length)document.getElementById("carousel-tab-3").innerHTML =  stockLabelsArr[last - 1]+'<div class="tab-data">' + arrMarketData[last - 1][1] + '<p class="' + arrMarketData[last - 1][4] + '"><span class="amountIncr">'+arrMarketData[last - 1][2]+'</span><span class="moneyarrow"> </span><span class="percentIncr">'+arrMarketData[last - 1][3]+'%</span></p></div>'; else document.getElementById("carousel-tab-3").innerHTML="";
    if(last<arrMarketData.length) 
	document.getElementById("carousel-tab-4").innerHTML = stockLabelsArr[last]+'<div class="tab-data">' + arrMarketData[last][1] + '<p class="' + arrMarketData[last][4] + '"><span class="amountIncr">'+arrMarketData[last][2]+'</span><span class="moneyarrow"> </span><span class="percentIncr">'+arrMarketData[last][3]+'%</span></p></div>'; else document.getElementById("carousel-tab-4").innerHTML="";

			
}

function createChartLinks(){
    var currentIndex = tabCount-1;var chartLinks;
    chartLinks='<ul class="chart-date-selector" id="chartLinks"><li><span class="chart-view">' + chartDay + '</span></li>';
    
    var chartTimeStr = chartStringsArr[currentIndex];
    chartTimeStr = trimAll(chartTimeStr);

    /* convert the string to an array */
    chartTimeStrArray = chartTimeStr.split(",");
    //for non bonds
    if(chartTimeStrArray[0] != "" && arrMarketData[currentIndex][0].charAt(0) != "("){
        for(i=0;i<chartTimeStrArray.length;i++){
            timeLabelArray = chartTimeStrArray[i].split(":");
            timeStr = timeLabelArray[0];
            labelStr= timeLabelArray[1]; 
            chartLinks+='<li><a href="'+ arrMarketData[currentIndex][5] +'/charts?dr=' + timeLabelArray[0] + '" class="chart-view" onclick ="s_objectID=s_265.pageName + \' Market News Chart: ' + timeLabelArray[1] + '\';">' + timeLabelArray[1] + '</a></li>';
        } 
    }
 
    chartLinks+='</ul><a href="'+ arrMarketData[currentIndex][5] +'/charts?dr=999" class="chart-view" onclick ="s_objectID=s_265.pageName + \' Market News Chart: View More Charts\';">View More Charts</a>';
    chartLinks+='<a href="'+ arrMarketData[currentIndex][5] +'/charts?dr=999" onclick ="s_objectID=s_265.pageName + \' Market News Chart: Main Chart Clicked\';"><img src="http://quote-web.aol.com/?s='+ arrMarketData[currentIndex][0] +'&e='+ arrMarketData[currentIndex][6] +'&dur=999&type=mountain&hgl=1&vgl=1&vol=0&splits=0&div=0&w=432&h=242&scheme=platinum&gran=d" width="432" height="242" alt="Market News" border="0" /></a>';

    document.getElementById("selected-tab-area").innerHTML = chartLinks;
}

function select_tabs(tabnum){
    reset_carousel_tabs("carousel-tab-", 4, tabnum);
}

function setPagination( tabCount){
    if(tabCount < arrMarketData.length) {
	paginationData = ++tabCount + " of " + arrMarketData.length;
          document.getElementById("carouselPagination").innerHTML = paginationData;
    }
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + reset_carousel_tabs function                                  +
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//pass in tab as selected, resets all and sets active tab
function reset_carousel_tabs(idString, num, setLoc){
	for(i=1; i<num+1; i++){
		document.getElementById(idString+i).setAttribute("class", "inActiveTab");
		document.getElementById(idString+i).setAttribute("className", "inActiveTab");
	}

	document.getElementById(idString+setLoc).setAttribute("class", "activeTab");
	document.getElementById(idString+setLoc).setAttribute("className", "activeTab");
        createChartLinks();
} // end reset_tabs function


// Start: News Article - User Comments JS 
// rating
var xmlHttpRating;

function getRating(objectURI, category, type, score, appId) {
    var procName = "dms.trri.addRatingAndGet"
    var parameters = objectURI + ',' + category + ',' + type  + ',' + score + ',' + appId;

     if (window.ActiveXObject) {
        xmlHttpRating = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttpRating = new XMLHttpRequest();
    }
   
    xmlHttpRating.onreadystatechange = handleStateChange;
   
    var ourl = document.URL;

    //url="http://sports.channel.office.aol.com/httprequest.adp"
    var ind = ourl.indexOf('aol.com/');
    var url = ourl.substring(0, ind+8);
    url += 'httprequest.adp';

    url = url + "?_pn=" + procName;
    if (parameters!="")
    {
          url = url + "&_pa=" + parameters;
    }

    url += '&date=' + new Date().getTime();

    //alert(url);
    xmlHttpRating.open("GET", url, true);
    xmlHttpRating.setRequestHeader("Accept", "text/xml");
    xmlHttpRating.send(null);
}
   
function handleStateChange() {
    if(xmlHttpRating.readyState == 4) {
        if(xmlHttpRating.status == 200) {
            if(xmlHttpRating.responseText.length) {
                var result = xmlHttpRating.responseText.substring(1, xmlHttpRating.responseText.length - 1 );
                var results = result.split(" ");
                document.getElementById('label').innerHTML = "Thanks";
                document.getElementById('thumbsup').innerHTML = '<img src="http://www.aolcdn.com/ch_news/news-icon-thumbup" title="Thumbs Up" border="0" class="images" />' + results[0] + ' %';
                document.getElementById('thumbsdown').innerHTML = '<img src="http://www.aolcdn.com/ch_news/news-icon-thumbdown" title="Thumbs Up" border="0" class="images" />' + results[1] + ' %';
                document.getElementById('total').innerHTML = results[2] + ' VOTES';
                mouseoutup();
                mouseoutdown();
            }
        }
    }
}


// comment

var xmlHttpComment;

function displayComments(start) {
    var uri = document.getElementById("cmmt_uri").value;
    var category = document.getElementById("cmmt_category").value;
    var assetType = document.getElementById("cmmt_assetType").value;
    var appID = document.getElementById("cmmt_appID").value;
    var numCmmt = document.getElementById("cmmt_numCmmt").value;
    var AddBtnLbl = document.getElementById("cmmt_AddBtnLbl").value;
    var CanBtnLbl = document.getElementById("cmmt_CanBtnLbl").value;
    var reportThis = document.getElementById("cmmt_reportThis").value;
    var thisurl = document.getElementById("cmmt_thisurl").value;

    var procName = "dms.trri.displayReviews"
    var del=',';
    var parameters = uri;
    parameters += del + category;
    parameters += del + assetType;
    parameters += del + appID;
    parameters += del + start;
    parameters += del + numCmmt;
    parameters += del + AddBtnLbl;
    parameters += del + CanBtnLbl;
    parameters += del + reportThis;
    parameters += del + thisurl;

    if (window.ActiveXObject) {
        xmlHttpComment = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttpComment = new XMLHttpRequest();
    }
   
    xmlHttpComment.onreadystatechange = readyForComments;
   
    var ourl = document.URL;

    var ind = ourl.indexOf('aol.com/');
    var url = ourl.substring(0, ind+8);
    url += 'httprequest.adp';

    url = url + "?_pn=" + procName;
    if (parameters!="")
    {
          url = url + "&_pa=" + parameters;
    }

    url += '&date=' + new Date().getTime();

    //alert(url);
    xmlHttpComment.open("GET", url, true);
    xmlHttpComment.setRequestHeader("Accept", "text/xml");
    xmlHttpComment.send(null);
}
   
function readyForComments() {
    if(xmlHttpComment.readyState == 4) {
        if(xmlHttpComment.status == 200) {
            document.getElementById('cmmntBox').innerHTML = xmlHttpComment.responseText;
        }
    }
}


function submitComments()
{
	var sn = loginId;
	submitCommentsWithSN(sn);
}

var xmlHttpAddComment;
function submitCommentsWithSN(sn)
{
    var comment = document.getElementById("addCommentHere").value;
	if(comment == null || comment.length < 1 || comment == 'Type your own comment here')
		return;

    var uri = document.getElementById("cmmt_uri").value;
    var category = document.getElementById("cmmt_category").value;
    var assetType = document.getElementById("cmmt_assetType").value;
    var appID = document.getElementById("cmmt_appID").value;

    procName = "dms.trri.addReview";

    var del='|';
    parameters = uri;
    parameters += del + sn;
    parameters += del + comment;
    parameters += del + category;
    parameters += del + assetType;
    parameters += del + appID;

    if (window.ActiveXObject) {
        xmlHttpAddComment = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttpAddComment = new XMLHttpRequest();
    }
    
    xmlHttpAddComment.onreadystatechange = afterAddComments;
    
    var ourl = document.URL;

    var ind = ourl.indexOf('aol.com/');
    var url = ourl.substring(0, ind+8);
    url += 'httprequest.adp';

    data = "_pn=" + procName;
    data += "&_pa=" + parameters;
    data += "&_del=" + del;

    xmlHttpAddComment.open("POST",url,true);
    xmlHttpAddComment.setRequestHeader("Accept", "text/xml");
    xmlHttpAddComment.send(data);
} 

function afterAddComments() 
{ 
     if(xmlHttpAddComment.readyState == 4) {
        if(xmlHttpAddComment.status == 200) { 
            var status = xmlHttpAddComment.responseText;
		    if (status == '1') {
                displayComments(0);
            } else {   
                document.getElementById('ucMsg').innerHTML = "Your comment could not be successfully saved at this time. Please try again later."
            }
        }
    } 
}

//Enforce maxlength attribute of usercomments textarea.
function checkMaxLength(obj) {
	var maxLength = obj.getAttribute('maxlength');
	var currentLength = obj.value.length;

	if (currentLength > maxLength)
		obj.value=obj.value.substring(0,maxLength)

	var counter = getEl(obj.getAttribute('counter'));
	counter.firstChild.nodeValue = currentLength + '/' + maxLength;
	// not innerHTML
}

// Login Functions
function AsnsSignIn() {
 	pSNS = getEl("snsMiniUI");
	pSNS.innerHTML = "";
	pSNS.innerHTML = _sns_var_;
	pSNS.style.display = 'block';
}

function getEl( id ){ 
    return document.getElementById( id ); 
}

function showToolTip(oCaller, ttID){
	document.getElementById(ttID).style.display = "block";
}

function hideToolTip(oCaller, ttID){
	document.getElementById(ttID).style.display = "none";
}
// End: News Article - User Comments JS

// Start:  SHARE THIS WIDGET JS

var sharePopFlag = true;                             //variable for onclick popup
  
function showShareThisPop(topDivId, botDivId)        //function to call the popup onclick
{
    if (sharePopFlag)
    {
        document.getElementById('shareLeftIDBB').style.borderBottom = "1px solid #000";
        document.getElementById(botDivId).style.display = "block";
        document.getElementById(topDivId).className = "share_right_on";
    }
    else 
    {
        document.getElementById('shareLeftIDBB').style.borderBottom = "none";
        document.getElementById(botDivId).style.display = "none";
        document.getElementById(topDivId).className = "share_right";
    }
    sharePopFlag = !sharePopFlag;
}

function shareOperation(iOperation, strUrl, strTitle)
{
    var staf_obj = new staf_SE();
    staf_obj.setLang("en-US");
    if (strUrl != "")
    {
        staf_obj.setURL(strUrl);
    }
    if (strTitle != "")
    {
        staf_obj.setTitle(strTitle);        
    }
    if (iOperation == 1) // IM This
    {
        staf_obj.sendIM();
    }
    else
    {
        staf_obj.sendEmail();
    }
}

function mouseoverup()
{
    document.getElementById("thumbsup").className="thumbsup_on";
}

function mouseoutup()
{
    document.getElementById("thumbsup").className="thumbsup";
} 

function mouseoverdown()
{
    document.getElementById("thumbsdown").className="thumbsdown_on";
}

function mouseoutdown()
{
    document.getElementById("thumbsdown").className="thumbsdown";
}

// End: SHARE THIS WIDGET JS

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + function sortString                                      +
// + A generic function to sort comma delimeted strings       +
// + through conversion to array and then back to string      +
// + after sorting.                                           +
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function sortString(string) {

    string = trimAll(string);

    var strSortString;
    var arrSortStringArray;

    /* convert the string to an array */
    arrSortStringArray = string.split(",");
    
    /* sort the array */
    arrSortStringArray.sort();

    /* convert the sorted array back into a string */
    strSortString = arrSortStringArray.join(",");
    strSortString = "," + strSortString  + ",";

    /* return the string so we can use it. */
    return strSortString;

}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function delRecentQuotes(){

    Delete_Cookie("AOL_QUOTE_HISTORY_LIST","/",".aol.com");
    strRecentQuotes = "";
    ensureUploadScriptIsLoaded(recentqURL + strRecentQuotes + '&callback=mnc_recentquotes');
}

// +++++++++++++++ start code related to Recent Quotes tab ++++++++++++++++

function mnc_recentquotes(obj) {

    // Max number of Recent Quote symbols. 
    var rqMax = 20;

    ourElement ="mnc_recentquotes";

    document.getElementById("mnc_portfolios").style.display = "none";
    document.getElementById("mnc_watchlist").style.display = "none";
    document.getElementById(ourElement).style.display = "block";

    document.getElementById("recentNav").setAttribute("class", "activeTab");
    document.getElementById("watchNav").setAttribute("class", "");
    document.getElementById("portNav").setAttribute("class", "");
    document.getElementById("recentNav").setAttribute("className", "activeTab");
    document.getElementById("watchNav").setAttribute("className", "");
    document.getElementById("portNav").setAttribute("className", "");

    moduleString ='';
   
    //try looping thru symlist results from ajax call
    try{

        // check ResultSet for exception returned data 
        var exCount = 0;
        for(var rqEx = 0;rqEx<obj.ResultSet.symslist.length;rqEx++) {
            if(obj.ResultSet.symslist[rqEx].e){
               exCount++;
            }
        }

        if (strRecentQuotes=="" || exCount>0) {

	    // if the backend string is empty, display a default message.
	    moduleString +='<center><br /><b>Track your most recent quotes here!</b><br />Enter a symbol above or <a href="javascript:prntPack(\'http://finance.aol.com/quotes/lookup?from=quote_lookup&pop=y&exch=USA\',703,326);">look up a symbol</a>.<br /><br /></center>'

	} else {
 	    moduleString +='<table class="marketData" border="0" cellpadding="0" cellspacing="0">';
    	    moduleString +='<thead><tr class="header"><th class="th_symbol">Symbol</th><th class="th_last">Last</th><th class="th_change" colspan="3">Change</th><th>&nbsp;</th><th>&nbsp;</th></tr></thead><tbody>'

            for(var i = 0;i < rqMax && i < obj.ResultSet.symslist.length;i++){

                var stockDirection = '';

                if(obj.ResultSet.symslist[i].c.indexOf("+") != -1)
	            var stockDirection = "positive";

	        else if(obj.ResultSet.symslist[i].c.indexOf("-") != -1)
	            var stockDirection = "negative";

            	moduleString +='<tbody><tr class="' + stockDirection + '"><td class="wl_Symbol"><a  title="' + obj.ResultSet.symslist[i].n + '" href="' + obj.ResultSet.symslist[i].lu + '">';
            	moduleString += obj.ResultSet.symslist[i].s.substring(0,5);

		if(obj.ResultSet.symslist[i].s.length > 5)

		    moduleString +='...';
            	    moduleString +='</a></td>';
            	    moduleString +='<td class="last">' + obj.ResultSet.symslist[i].p + '</td>';
            	    moduleString +='<td  class="amountIncr">' + obj.ResultSet.symslist[i].c.replace('+','&nbsp;&nbsp;') + '</td>';
            	    moduleString +='<td class="moneyarrow">&nbsp;</td>';


            	    if (obj.ResultSet.symslist[i].pc.indexOf('N/A') < 0)

	                moduleString +='<td class="percentIncr">' + obj.ResultSet.symslist[i].pc.replace('+','').replace('-','') + '%</td>';
            	    else
	        	moduleString +='<td class="percentIncr">' + obj.ResultSet.symslist[i].pc + '</td>';

            		moduleString +='<td class="wl_chart" title="See Chart for ' + obj.ResultSet.symslist[i].s + '"><a href="' + obj.ResultSet.symslist[i].lu + '/charts">&nbsp;&nbsp;&nbsp;&nbsp;</a></td>';
            		moduleString +='<td class="wl_headlines" title="See Latest Headlines for ' + obj.ResultSet.symslist[i].s + '"><a href="' + obj.ResultSet.symslist[i].lu.replace("/quotes/","/headlines/") + '">&nbsp;&nbsp;&nbsp;&nbsp;</a></td></tr>';

        	    }
                        addportfolioRQ = strRecentQuotes.substring(1,strRecentQuotes.length);

                        moduleString +='<tr><td colspan="2" class="clearall"><a class="aolBtn watchlist_button" href="javascript:delRecentQuotes();" title="ClearAll"/>Clear All</a></td><td colspan="5" class="wl_right">';
                        moduleString += '<a href="http://finance.aol.com/usw/portfolios/advancedCreate?symbols=' + addportfolioRQ.replace(/,/g,'&exchange=NYS&symbols=') + '&exchange=NYS"">Save as new Portfolio</a></td></tr>';

                    moduleString +='</tbody></table>';
	}

    		    document.getElementById(ourElement).innerHTML = moduleString;


    }catch(err){
        //alert(err);
    }


}
// +++++++++++++++ end code related to Recent Quotes tab ++++++++++++++++

// this function trims leading and trailing commas.
function trimAll(sString) {

    while (sString.substring(0,1) == ',') {
        sString = sString.substring(1, sString.length);
    }

    while (sString.substring(sString.length-1, sString.length) == ',') {
        sString = sString.substring(0,sString.length-1);
    }

    return sString;
}

