function addQuotesToPortfolio(baseUrl, dist)
{
	var symbolList = getQuoteSelectionList(",");
	
	if(symbolList.length > 0)
	{
		var qs = new Querystring();
		var addUrl = baseUrl + '?symbs=' + symbolList + 
			'&siteid=' + qs.get('siteid', '') + '&dist=' + dist;
		window.open(addUrl, 'new', 'toolbars=no,scrollbars=yes,resizable=yes,height=375,width=700');			
	}
	else
	{
		alert ("Please select one or more symbols first.");
	}
}

function updateRelatedNewsContent(jsonFormat, relatedNewsContainer, newsText, header, subHeader, moreTitle)
{
	try
	{
		var headlines = eval('(' + jsonFormat + ')');

		if(headlines != null && headlines.Headlines != null &&
			headlines.Headlines.length > 0)
		{
			var currentQS = (new Querystring(new Array('guid'), new Array('dist=RNPullDown'))).toString();

			relatedNewsContainer.innerHTML = "";

			var addedHeadlines = 0;
			// TODO - Jason - 12/16/2005 - I wonder if there's a way you can parse the 
			// current page URL to get the story ID, rather than having story.aspx
			// register a hidden field.
			var currentStoryID = document.forms[0].currentStoryID.value;			
			
            for(var i = 0; i < headlines.Headlines.length; i++)
			{
				var headline = headlines.Headlines[i];

				if(headline.ID != currentStoryID &&
					addedHeadlines < 3)
				{
				    var contentLink = document.createElement("A");
				    contentLink.innerHTML = headline.Content;
				    if ((header == "Bankrate") && (headline.ExternalLink != "") && (headline.ExternalLink != null))
				    {
				        contentLink.href = headline.ExternalLink;
				    }
				    else
				    {
					    contentLink.href = headline.InternalLink +
						    (currentQS.length > 0 ? "&" + currentQS : "");
					}
					
					contentLink.className = "RRHeadline";

					relatedNewsContainer.appendChild(contentLink);
					var linkBreak = document.createElement("BR");
					relatedNewsContainer.appendChild(linkBreak);

					var linkBreak2 = document.createElement("BR");
					relatedNewsContainer.appendChild(linkBreak2);	
					addedHeadlines++;															
				}								
			}		

			if(addedHeadlines > 0)
			{
				var bullet = document.createElement("img");

				bullet.alt = "bullet";
				bullet.src = "http://i.mktw.net/images/bullet_dark_sage_5x10.gif";
				bullet.className = "bullet";
				relatedNewsContainer.appendChild(bullet);

				var moreNewsLink = document.createElement("A");				
				if (header == "Bankrate")
				{
				    moreNewsLink.innerHTML = "More news from Bankrate.com";
				    moreNewsLink.href = "http://www.bankrate.com/cbsmw";
				}
				else
				{
	                moreNewsLink.innerHTML = "More news related to " + moreTitle;
				    moreNewsLink.href = getMoreNewsHref(header, subHeader, headlines.LinkBase);
				}
				moreNewsLink.className = "RRHeadline";
				relatedNewsContainer.appendChild(moreNewsLink);
				var moreNewsBreak = document.createElement("BR");
				relatedNewsContainer.appendChild(moreNewsBreak);
			}
			else
			{							
				relatedNewsContainer.innerHTML = "";
				relatedNewsContainer.innerHTML = "Related News for " + newsText + " is currently not available.";													
			}
		}
		else
		{
			relatedNewsContainer.innerHTML = "";
			relatedNewsContainer.innerHTML = "Related News for " + newsText + " is currently not available.";						
		}
	}
	catch(exception) 
	{ 
		relatedNewsContainer.innerHTML = "";
		relatedNewsContainer.innerHTML = "Related News for " + newsText + " is currently not available.";
	}
	}	


function getRelatedNewsContent(relatedNewsContainer, newsText, header, subHeader, moreTitle)
{
	var request = getRequest();
	
	try
	{
		request.open("GET", "/news/story/RelatedNewsBridge.aspx?header=" + header + 
			"&subHeader=" + escape(subHeader), true);		
		request.onreadystatechange = function() {
			if (request.readyState == 4) 
			{
				var response = request.responseText;

				if(response != null)
				{
				    updateRelatedNewsContent(response, relatedNewsContainer, newsText, header, subHeader, moreTitle);
				}
			}
		}

		request.send(null);	
	}
	catch(sendException) 
	{ 
		relatedNewsContainer.innerHTML = "";
		relatedNewsContainer.innerHTML = "Related News for " + newsText + " is currently not available.";
	}
}

function updateCommentaryContent(jsonFormat, relatedNewsContainer, newsText, header, subHeader)
{
	try
	{
		var contentAdded = false;

		var commentators = eval('(' + jsonFormat + ')');
		if(commentators != null && commentators.Commentators != null &&
			commentators.Commentators.length > 0)
		{
			relatedNewsContainer.innerHTML = "";
			var currentQS = (new Querystring(new Array('guid'))).toString();

			// TODO - Jason - 12/16/2005 - I wonder if there's a way you can parse the 
			// current page URL to get the story ID, rather than having story.aspx
			// register a hidden field.
			var currentStoryID = document.forms[0].currentStoryID.value;
			for(var i = 0; i < commentators.Commentators.length; i++)
			{
				var commentator = commentators.Commentators[i];

				if(commentator.Headlines != null && commentator.Headlines.length > 0)
				{
					var headline = null;

					for(var j = 0; j < commentator.Headlines.length; j++)
					{
						if(commentator.Headlines[j].ID != currentStoryID)
						{
							headline = commentator.Headlines[j];
							break;									
						}
					}

					if(headline != null)
					{
						contentAdded = true;
						var commentatorLink = document.createElement("A");
						commentatorLink.innerHTML = commentator.Author.toUpperCase();
						commentatorLink.href = commentators.LinkBase + "search/?Property=column" +
							(currentQS.length > 0 ? "&" + currentQS : "") + "&value=" + escape(commentator.ColumnName);
						commentatorLink.className = "RRHeadline";
						relatedNewsContainer.appendChild(commentatorLink);

						var commentatorDaySpan = document.createElement("SPAN");
						commentatorDaySpan.innerHTML = "&nbsp;(" + 
							commentator.Day.toUpperCase() + ")";
						relatedNewsContainer.appendChild(commentatorDaySpan);							

						var br = document.createElement("BR");
						relatedNewsContainer.appendChild(br);								

						var contentLink = document.createElement("A");
						contentLink.innerHTML = headline.Content;
						contentLink.href = headline.InternalLink +
							(currentQS.length > 0 ? "&" + currentQS : "");
						contentLink.className = "RRHeadline";

						relatedNewsContainer.appendChild(contentLink);
						relatedNewsContainer.appendChild(br.cloneNode(false));								
						relatedNewsContainer.appendChild(br.cloneNode(false));								
					}
				}
			}						
		}
		else
		{
			relatedNewsContainer.innerHTML = "";
			relatedNewsContainer.innerHTML = "Related News for " + newsText + " is currently not available.";						
		}		

		if(contentAdded == true)
		{
			var bullet = document.createElement("img");

			bullet.alt = "bullet";
			bullet.src = "http://i.mktw.net/images/bullet_dark_sage_5x10.gif";
			bullet.className = "bullet";
			relatedNewsContainer.appendChild(bullet);

			var moreNewsLink = document.createElement("A");
			moreNewsLink.innerHTML = "More news related to " + subHeader;
			moreNewsLink.href = getMoreNewsHref(header, subHeader, commentators.LinkBase);
			moreNewsLink.className = "RRHeadline";
			relatedNewsContainer.appendChild(moreNewsLink);						
		}
		else
		{
			relatedNewsContainer.innerHTML = "";
			relatedNewsContainer.innerHTML = "Related News for " + newsText + " is currently not available.";											
		}		
	}
	catch(exception) 
	{ 
		relatedNewsContainer.innerHTML = "";
		relatedNewsContainer.innerHTML = "Related News for " + newsText + " is currently not available.";
	}
}

function getCommentaryScreenContent(relatedNewsContainer, newsText, header, subHeader)
{
	var request = getRequest();
	
	try
	{
		request.open("GET", "/news/story/CommentatorsBridge.aspx", true);		
		request.onreadystatechange = function() {
			if (request.readyState == 4) 
			{
				var response = request.responseText;

				if(response != null)
				{
					updateCommentaryContent(response, relatedNewsContainer, newsText, header, subHeader);
				}
				else
				{
					relatedNewsContainer.innerHTML = "";
					relatedNewsContainer.innerHTML = "Related News for " + newsText + " is currently not available.";						
				}		
			}
		}

		request.send(null);	
	}
	catch(sendException) 
	{ 
		relatedNewsContainer.innerHTML = "";
		relatedNewsContainer.innerHTML = "Related News for " + newsText + " is currently not available.";
	}
}

function changeRelatedNews(newsList)
{    
	if((newsList != null) && (newsList.selectedIndex >= 0))
	{
		var relatedNewsContainer = document.getElementById("RelatedNewsInformation");
		var newsText = newsList.options[newsList.selectedIndex].text;
		var newsValues = newsList.options[newsList.selectedIndex].value.split("|");
		var header = newsValues[0];
		var subHeader = newsValues[1];
		var moreTitle = newsValues[2];
		
		if(header == "Commentary" && subHeader == "News &amp; Commentary")
		{
			getCommentaryScreenContent(relatedNewsContainer, newsText, header, subHeader);
		}
		else
		{
			getRelatedNewsContent(relatedNewsContainer, newsText, header, subHeader, moreTitle);
		}
	}
}

function changeRelatedNewsWithJson(jsonFormat, newsText, value)
{
    var relatedNewsContainer = document.getElementById("RelatedNewsInformation");
	var newsValues = value.split("|");
	var header = newsValues[0];
	var subHeader = newsValues[1];
	var moreTitle = newsValues[2];
	updateRelatedNewsContent(jsonFormat, relatedNewsContainer, newsText, header, subHeader, moreTitle);
}

function changeCommentaryWithJson(jsonFormat, newsText, value)
{
	var relatedNewsContainer = document.getElementById("RelatedNewsInformation");
	var newsValues = value.split("|");
	var header = newsValues[0];
	var subHeader = newsValues[1];
	updateCommentaryContent(jsonFormat, relatedNewsContainer, newsText, header, subHeader);
}

function getMoreNewsHref(header, subHeader, linkBase)
{
	var headerType = "";
	var docType = "806";
	
	if(header == "Company")
	{
		headerType = "symb";
	}
	else if(header == "Industry")
	{
		headerType = "mktw-industry";
	}
	else if(header == "Keyword")
	{
		headerType = "word";
	}
	else if(header == "Column")
	{
		headerType = "column";
		docType = "2005";
		subHeader = subHeader.split(":")[0];
	}
	else if(header == "Topic")
	{
		headerType = "mktw-issue";
	}
	else if(header == "Region")
	{
		headerType = "mktw-location";
	}
	else if(header == "Commentary" || header == "PF")
	{
		headerType = "subchannel-code";
		docType = "2005";
		subHeader = "2048";
	}

	return linkBase + "search/?Property=" + headerType + 
		"&value=" + escape(subHeader) + "&docType=" + docType + "&dist=RNMoreNews";
}

function getGetAlertsHref(header, subHeader, linkBase)
{
	var selectedType = 0;
	
	if(header == "Company")
	{
		selectedType = 2;
	}
	else if(header == "Industry")
	{
		selectedType = 7;
	}
	else if(header == "Keyword")
	{
		selectedType = 5;
	}
	else if(header == "Column")
	{
		selectedType = 3;
	}
	
	return linkBase + "tools/alerts/createalert.asp?alertsymbol=" + escape(subHeader) + 
		(selectedType > 0 ? "&selectedType=" + selectedType : "") + "&dist=RNGetAlerts";
}

function createAlertsForQuotes(baseUrl, dist)
{
	var symbolList = getQuoteSelectionList(" ");
	
	if(symbolList.length > 0)
	{
		var qs = new Querystring();
		var createUrl = baseUrl + '?selectedType=2&alertsymbol=' + symbolList + 
			'&siteid=' + qs.get('siteid', '') + '&dist=' + dist;	
		window.location = createUrl;
	}
	else
	{
		alert ("Please select one or more symbols first.");
	}
}

function getQuoteSelectionList(delimiter)
{
	var quoteList = new Array();
	var index = 0;
	
	for(i = 0; i < quoteSelections.length; i++)
	{
		var quoteSelection = document.getElementById(quoteSelections[i]);
		
		if(quoteSelection.checked == true)
		{
			quoteList[index] = quoteSelection.value;
			index++;
		}
	}

	return escape(quoteList.join(delimiter).replace( /^\s+/g,'').replace(/\s+$/g,''));
}

function changeAd(adUrl, adPlacementId, reset)
{
	var container = document.getElementById(adPlacementId);
	var currentContainer = container.innerHTML;
	
	var request = getRequest();
		
	try
	{
		request.open("GET", adUrl, true);		
		request.onreadystatechange = function() {
			if (request.readyState == 4) 
			{
				var responseAd = request.responseText;

				if(responseAd != null && responseAd.length > 0)
				{
					container.innerHTML = responseAd;			
				}
			
				setTimeout("changeAd(\"" + adUrl + "\",\"" + adPlacementId + "\", " + reset + ")", reset);			
			}
		}

		request.send();	
	}
	catch(sendException) 
	{ 
		setTimeout("changeAd(\"" + adUrl + "\",\"" + adPlacementId + "\", " + reset + ")", reset);			
	}
}

function getRequest()
{
	var xmlHttp = false;
	
	try 
	{
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (msxml2Exception) 
	{
		try 
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (microsoftException) 
		{
			xmlHttp = false;
		}
	}
	
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		xmlHttp = new XMLHttpRequest();
	}
	
	return xmlHttp; 
}

function newToggleSection(disabledSectionNames, disabledTabNames, enabledSection, enabledTab)
{
	for(de = 0; de < disabledSectionNames.length; de++)
	{
		var disabledSection = document.getElementById(disabledSectionNames[de]);
		if (disabledSection && disabledSection.style)
		{
		    disabledSection.style.display = 'none';
		}
	}

	for(dl = 0; dl < disabledTabNames.length; dl++)
	{
		var disabledTab = document.getElementById(disabledTabNames[dl]);
		var disabledTabLeftImg = document.getElementById(disabledTabNames[dl]+'Left');
		var disabledTabRightImg = document.getElementById(disabledTabNames[dl]+'Right');
		if (disabledTab && disabledTab.style)
		{
		    disabledTab.className = "RRTab Off";
		    disabledTabRightImg.className = "ImgTab OffRight";
		    disabledTabLeftImg.className = "ImgTab OffLeft";
		}
	}
	
	var enabledSection = document.getElementById(enabledSection);
	if (enabledSection && enabledSection.style)
	{
	    enabledSection.style.display = 'block';
	}
	
	var enabledTabLeftImg = document.getElementById(enabledTab+'Left');
	var enabledTabRightImg = document.getElementById(enabledTab+'Right');
	var enabledTab = document.getElementById(enabledTab);	
	if (enabledTab && enabledTab.style)
	{
	    enabledTab.className = "RRTab On";
	    enabledTabRightImg.className = "ImgTab OnRight";
	    enabledTabLeftImg.className = "ImgTab OnLeft";
	}
	
	return false;
}

function toggleSection(disabledSectionNames, disabledLinkNames, enabledSection, enabledLink)
{
	for(de = 0; de < disabledSectionNames.length; de++)
	{
		var disabledSection = document.getElementById(disabledSectionNames[de]);
		if (disabledSection && disabledSection.style)
		{
		    disabledSection.style.display = 'none';
		}
	}

	for(dl = 0; dl < disabledLinkNames.length; dl++)
	{
		var disabledLink = document.getElementById(disabledLinkNames[dl]);
		if (disabledLink && disabledLink.style)
		{
		    disabledLink.style.textDecoration = 'underline';
		    disabledLink.style.color = "";
		}
	}
	
	var enabledSection = document.getElementById(enabledSection);
	if (enabledSection && enabledSection.style)
	{
	    enabledSection.style.display = 'block';
	}
	
	var enabledLink = document.getElementById(enabledLink);
	if (enabledLink && enabledLink.style)
	{
	    enabledLink.style.textDecoration = 'none';
	    enabledLink.style.color = "#000000";
	}
	
	return false;
}

function addToPortfolio (thePage, siteid)
{
   AddPortfolio = window.open(thePage,'new', 'toolbars=no,scrollbars=yes,resizable=yes,height=375,width=700');
}

function openDelicious()
{
	window.open('http://del.icio.us/post?v=4&partner=mkw&noui&jump=close&url='+encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title),'delicious','toolbar=0,width=700,height=400');
    return false;
}

function openDigg(title, bodytext)
{

    window.open('http://www.digg.com/submit?phase=2&url=' + encodeURIComponent(location.href) + '&title=' + title + '&bodytext=' + bodytext + '&topic=business_finance', 'digg','toolbar=no, scrollbars=yes,resizable=yes');
    return false;
    
}


function storySetImage(imageId, imageUrl)
{
    var image = document.getElementById(imageId);
    if (image)
    {
        image.src = imageUrl;
    }
}


function storyAddClass(elementId, className)
{
    var element = document.getElementById(elementId);
    if (element)
    {
        YAHOO.util.Dom.addClass(element, className);
    }
}


function storyRemoveClass(elementId, className)
{
    var element = document.getElementById(elementId);
    if (element)
    {
        YAHOO.util.Dom.removeClass(element, className);
    }
}


var currentStoryImagePanel = null;

function openLargeImage(caption, smallImageId, bigImageUrl, imageWidth, imageHeight, imagePath)
{
    var panelId = "ipan_" + smallImageId;
    var closeImgId = "ipan_" + smallImageId + "_cimg";
    var closeTextId = "ipan_" + smallImageId + "_ctext";
    var config = new Object;

    config.close = false;
    config.visible = true;
    config.draggable = false;
    config.monitorresize = false;
    config.constraintoviewport = true;
    config.context = [smallImageId, "bl", "bl"];
    config.modal = true;
    config.iframe = true;
    config.zIndex = 100200;
    config.underlay = "none";
    //config.effect = { effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5 };

    var myPanel = new YAHOO.widget.Panel(panelId, config);

    var body = "";
    body += "<table cellspacing='0' cellpadding='0'><tbody>";
    body +=   "<tr>";
    body +=     "<td class='pimagePan_ulhc pimagePan_empty'>&nbsp;</td>";
    body +=     "<td class='pimagePan_top pimagePan_empty' style='width: " + imageWidth + "px'>&nbsp;</td>";
    body +=     "<td class='pimagePan_urhc pimagePan_empty'>&nbsp;</td>";
    body +=   "</tr>";

    body +=   "<tr>";
    body +=     "<td class='pimagePan_left'></td>";
    body +=     "<td class='pimagePan_content'>";
    body +=       "<div class='pimagePan_title'>";
    body +=         "<div class='FloatRight clickableItem' onclick='return closeLargeImage();'>";
    body +=           "<img id='" + closeImgId + "'";
    body +=             " onmouseover='storySetImage(\"" + closeImgId + "\", \"http://www.marketwatch.com/mw3/portfolio/close-rollover.gif\");'";
    body +=             " onmouseout='storySetImage(\"" + closeImgId + "\", \"http://www.marketwatch.com/mw3/portfolio/close.gif\");'";
    body +=             " src='http://www.marketwatch.com/mw3/portfolio/close.gif'/>";
    body +=         "</div>";
    body +=         "<div id='" + closeTextId + "' class='FloatRight clickableItem' onclick='return closeLargeImage();'";
    body +=             " onmouseover='storyAddClass(\"" + closeTextId + "\", \"pimagePan_title_highlight\");'";
    body +=             " onmouseout='storyRemoveClass(\"" + closeTextId + "\", \"pimagePan_title_highlight\");'>";
    body +=           "<span>Close&nbsp;</span>";
    body +=         "</div>";
    body +=         "<div class='clearall'></div>";
    body +=       "</div>";
    body +=       "<div><img class='clickableItem' src='" + bigImageUrl + "' width='" + imageWidth + "' height='" + imageHeight + "' onclick='return closeLargeImage();'/></div>";
    body +=       "<div class='pimagePan_caption'><span>" + unescape(caption) + "</span></div>";
    body +=     "</td>";
    body +=     "<td class='pimagePan_right'></td>";
    body +=   "</tr>";

    body +=   "<tr>";
    body +=     "<td class='pimagePan_llhc pimagePan_empty'>&nbsp;</td>";
    body +=     "<td class='pimagePan_bottom pimagePan_empty' style='width: " + imageWidth + "px'>&nbsp;</td>";
    body +=     "<td class='pimagePan_lrhc pimagePan_empty'>&nbsp;</td>";
    body +=   "</tr>";
    body += "</tbody></table>";

    body += "<script type=\"text/javascript\" language=\"JavaScript\" src=\"http://www.marketwatch.com/include/js/s_code.js\"></script>";
    body += "<script type=\"text/javascript\" language=\"JavaScript\">";
    body += "if (typeof s != \"undefined\") {";
    body += "s.pageName = \"/news/story/imageclick.aspx\";";
    body += "var s_code=s.t();if(s_code)document.write(s_code) }//--></script>";
    body += "<script type=\"text/javascript\" language=\"JavaScript\"><!--";
    body += "if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')";
    body += "//--></script>";

    myPanel.setBody(body);

    myPanel.render(document.body);
    myPanel.show();
    
    currentStoryImagePanel = myPanel;

    return false;
}


function closeLargeImage()
{
    if (currentStoryImagePanel != null)
    {
        currentStoryImagePanel.hide();
        currentStoryImagePanel = null;
    }
    
    return false;
}


function openLargeChart(bigChartUrl, smallChartId, caption)
{
    var panelId = "cpan_" + smallChartId;
    var closeImgId = "cpan_" + smallChartId + "_cimg";
    var closeTextId = "cpan_" + smallChartId + "_ctext";
    var config = new Object;

    config.close = false;
    config.visible = true;
    config.draggable = false;
    config.monitorresize = false;
    config.constraintoviewport = true;
    config.context = [smallChartId, "bl", "bl"];
    config.modal = true;
    config.iframe = true;
    config.zIndex = 100200;
    config.underlay = "none";
    config.effect = { effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5 };

    var myPanel = new YAHOO.widget.Panel(panelId, config);

    var body = "";
    body += "<table cellspacing='0' cellpadding='0'><tbody>";
    body +=   "<tr>";
    body +=     "<td class='pimagePan_ulhc pimagePan_empty'>&nbsp;</td>";
    body +=     "<td class='pimagePan_top pimagePan_empty' style='width: 550px'>&nbsp;</td>";
    body +=     "<td class='pimagePan_urhc pimagePan_empty'>&nbsp;</td>";
    body +=   "</tr>";

    body +=   "<tr>";
    body +=     "<td class='pimagePan_left'></td>";
    body +=     "<td class='pimagePan_content'>";
    body +=       "<div class='pimagePan_title'>";
    body +=         "<div class='FloatRight clickableItem' onclick='return closeLargeImage();'>";
    body +=           "<img id='" + closeImgId + "'";
    body +=             " onmouseover='storySetImage(\"" + closeImgId + "\", \"http://www.marketwatch.com/mw3/portfolio/close-rollover.gif\");'";
    body +=             " onmouseout='storySetImage(\"" + closeImgId + "\", \"http://www.marketwatch.com/mw3/portfolio/close.gif\");'";
    body +=             " src='http://www.marketwatch.com/mw3/portfolio/close.gif'/>";
    body +=         "</div>";
    body +=         "<div id='" + closeTextId + "' class='FloatRight clickableItem' onclick='return closeLargeImage();'";
    body +=             " onmouseover='storyAddClass(\"" + closeTextId + "\", \"pimagePan_title_highlight\");'";
    body +=             " onmouseout='storyRemoveClass(\"" + closeTextId + "\", \"pimagePan_title_highlight\");'>";
    body +=           "<span>Close&nbsp;</span>";
    body +=         "</div>";
    body +=         "<div class='clearall'></div>";
    body +=       "</div>";
    body +=       "<div><img class='clickableItem' src='" + bigChartUrl + "' width='550' height='386' onclick='return closeLargeImage();'/></div>";
    body +=       "<div class='pimagePan_caption'><span>" + unescape(caption) + "</span></div>";
    body +=     "</td>";
    body +=     "<td class='pimagePan_right'></td>";
    body +=   "</tr>";

    body +=   "<tr>";
    body +=     "<td class='pimagePan_llhc pimagePan_empty'>&nbsp;</td>";
    body +=     "<td class='pimagePan_bottom pimagePan_empty' style='width: 550px'>&nbsp;</td>";
    body +=     "<td class='pimagePan_lrhc pimagePan_empty'>&nbsp;</td>";
    body +=   "</tr>";
    body += "</tbody></table>";

//    body += "<script type=\"text/javascript\" language=\"JavaScript\" src=\"http://www.marketwatch.com/include/js/s_code.js\"></script>";
//    body += "<script type=\"text/javascript\" language=\"JavaScript\">";
//    body += "if (typeof s != \"undefined\") {";
//    body += "s.pageName = \"/news/story/imageclick.aspx\";";
//    body += "var s_code=s.t();if(s_code)document.write(s_code) }//--></script>";
//    body += "<script type=\"text/javascript\" language=\"JavaScript\"><!--";
//    body += "if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')";
//    body += "//--></script>";

    myPanel.setBody(body);

    myPanel.render(document.body);
    myPanel.show();
    
    currentStoryImagePanel = myPanel;

    return false;
}

//Supports doctype 449 and 425
function OpenWin(lochref)
{
    window.open(lochref);
}

var storyPortalLastArrow = "";

// pick up the live quote change and flash the color and change the arrow -- stolen from Quote Page, but NO FLASHING!
function StoryPortalLiveQuotePickup(symbol)
{
    try
    {
        var arrows = document.getElementsByClassName("changearrow");
        var change = symbol.Change();

        if (change > 0)
        {
            if(storyPortalLastArrow != 'up')
            {
                for (i = 0; i < arrows.length; i++) {
                    arrows[i].src = 'http://i.mktw.net/mw3/quotes/arrow-up-lg.gif';
                }
                storyPortalLastArrow = 'up';           
            }
        }
        else if (change < 0)
        {
            if(storyPortalLastArrow != 'dn')
            {
                for (i = 0; i < arrows.length; i++) {
                    arrows[i].src = 'http://i.mktw.net/mw3/quotes/arrow-dn-lg.gif';
                }
                storyPortalLastArrow = 'dn';
            }
        }
        else if (storyPortalLastArrow != 'none')
        {
            for (i = 0; i < arrows.length; i++) {
                arrows[i].src = 'http://i.mktw.net/mw3/1.gif';
            }
            storyPortalLastArrow = 'none';
        }
    }
    catch(ex)
    {
		//document.title = ex;
    }     
}

function StoryPortalLiveQuoteSetup()
{
    try
    {    			
	    var livequotes=false;
		
        if(window.MWLiveQuotes != null)
        {
			// old live quotes
			if(storyPortalSymbol != "")
			{
	            var app = MWLiveQuotes.getApplication();     
	            var symbol = app.BindSymbol(livequoteTicker);
	            var context = new Object();
	            context.onPickup = StoryPortalLiveQuotePickup;
	            symbol.attach(context);
			} 
			livequotes=true;
        }
        
        if(window.LiveQuotesGateway != null)
		{
			if(!livequotes)
			{			
            	var lqg = LiveQuotesGateway.Instance();
				if(livequoteTicker && livequoteTicker != "INDU") 
				{                                                  		
            		if(typeof(window.LiveQuotesExchanges) != "undefined" && window.LiveQuotesExchanges != "")
            		    lqg.BindToHybridQuote(livequoteTicker, StoryPortalLiveQuotePickup, window.LiveQuotesExchanges);
            	    else
            	    {
            	        lqg.BindToQuote(livequoteTicker, StoryPortalLiveQuotePickup);
            	        //lqg.BindToHybridQuote(MKTW.quotepage.Live.livequoteTicker, MKTW.quotepage.Live.silentTestPickup, "NLs,CSK");
            	    }
				}
			}
        }
		
		var upArrow = new Image();
		upArrow.src = "http://i.mktw.net/mw3/quotes/arrow-up-lg.gif";
		var downArrow = new Image();
		downArrow.src = "http://i.mktw.net/mw3/quotes/arrow-dn-lg.gif";
    }
    catch(ex)
    {	
		//document.title = ex;
    }  
}


YAHOO.namespace ("rssBalloon");

YAHOO.rssBalloon.TOPRSSLINK = "StoryContent_MidPageNavigation_NewTopRssLink";

YAHOO.rssBalloon.isInitialized = false;
YAHOO.rssBalloon.columnName = null;

YAHOO.rssBalloon.init = function()
{
    YAHOO.rssBalloon.isInitialized = true;

    var RSSCOLUMN = "http://marketwatch.com/rss/columns/?column=";
    var RSSTOPSTORIES = "http://feeds.marketwatch.com/marketwatch/topstories/";
    var RSSDEFAULTTITLE = "Top Stories";
    var IMGLOC = "http://i.mktw.net/mw3/news/rssballoon_images/"

    var ctxY = YAHOO.util.Dom.getY(YAHOO.rssBalloon.TOPRSSLINK);
    var ctxX = YAHOO.util.Dom.getX(YAHOO.rssBalloon.TOPRSSLINK);
    ctxY += 10;
    ctxX -= 340;

    var backgroundConfig = { xy:[ctxX,ctxY], visible:true, width:"370px", iframe:false, zIndex:2};
    var contextConfig = { xy:[ctxX,ctxY], visible:true, width:"370px", iframe:false, zIndex:3};

    YAHOO.rssBalloon.overlayBackground = new YAHOO.widget.Overlay("overlayBackground", backgroundConfig);
    YAHOO.rssBalloon.overlayContext = new YAHOO.widget.Overlay("overlayContext", contextConfig );

    YAHOO.rssBalloon.overlayBackground.setHeader("<div class='overlayBackgroundhd'></div>");
    YAHOO.rssBalloon.overlayBackground.setBody("<div id='overlayrssSpace' class='overlayrssSpace'></div>");
    YAHOO.rssBalloon.overlayBackground.setFooter("<div class='overlayrssFt'></div>");
    YAHOO.rssBalloon.overlayBackground.render(document.body);

    YAHOO.util.Dom.addClass('overlayBackground', 'shown');

    var columnNameElement = document.getElementById(YAHOO.rssBalloon.TOPRSSLINK);
    var rssUrl = "";
    var rssFeedName = "";

    if(YAHOO.rssBalloon.columnName != null)
    {
        rssFeedName = YAHOO.rssBalloon.columnName;
        //most rss readers do not allow spaces; trying this as a work around
        YAHOO.rssBalloon.columnName = YAHOO.rssBalloon.columnName.replace(/ /g, "_");
        rssUrl = RSSCOLUMN + escape(YAHOO.rssBalloon.columnName);
    }
    else
    {
        rssFeedName = RSSDEFAULTTITLE;
        rssUrl = RSSTOPSTORIES;
    }

    //Button Obj Format - href, src, width, height, border, align
    yhooButton = new YAHOO.rssBalloon.button("http://us.rd.yahoo.com/my/atm/MarketWatch/MarketWatch/*http://add.my.yahoo.com/rss?url=" + rssUrl,"yahooRss.gif", 91, 17, 0, "middle");
    aolButton = new YAHOO.rssBalloon.button("http://feeds.my.aol.com/?url=" + rssUrl, "aolRss.gif",63,14,0,"middle");
    gatorButton = new YAHOO.rssBalloon.button("http://www.newsgator.com/ngs/subscriber/subext.aspx?url=" + rssUrl, "gator.gif",91,17,0,"middle");
    rojoButton = new YAHOO.rssBalloon.button("http://www.rojo.com/add-subscription?resource=" + rssUrl, "rojoRss.gif",91,17,0,"middle");
    msnButton = new YAHOO.rssBalloon.button("http://my.msn.com/addtomymsn.armx?id=rss&ut=" + rssUrl, "msnRss.gif",71,14,0,"middle");
    bloglinesButton = new YAHOO.rssBalloon.button("http://www.bloglines.com/sub/" + rssUrl, "bloglinesRss.gif",76,17,0,"middle");
    googleButton = new YAHOO.rssBalloon.button("http://fusion.google.com/add?feedurl=" + rssUrl, "googleRss.gif",104,17,0,"middle");     
    pageflakeButton = new YAHOO.rssBalloon.button("http://www.pageflakes.com/subscribe.aspx?url=" + rssUrl, "pageflakesRss.gif",116,17,0,"middle"); 

    YAHOO.rssBalloon.overlayContext.setHeader("<div class='hdmain'><div id='hdcloselink' class='hdcloselink'></div><div class='hdmaintitle'>Subscribe to " + rssFeedName + "</div></div>");
    YAHOO.rssBalloon.overlayContext.setBody( "<div class='bdsub'>Choose your favorite RSS reader below:</div><div class = 'bdbuttonrow1'><div class='bdbuttonfloat'><div class='bdbutton'><a href=" + yhooButton.href +"><img src=" + IMGLOC + yhooButton.src +" width="+ yhooButton.width +" height="+ yhooButton.height +" border="+ yhooButton.border +" align="+ yhooButton.align +" alt='Add to My Yahoo!'></a></div>" +
                   "<div class='bdbutton'><a href=" + aolButton.href +"><img src=" + IMGLOC + aolButton.src +" width="+ aolButton.width +" height="+ aolButton.height +" border="+ aolButton.border +" align="+ aolButton.align +" alt='Add to My AOL'/></a></div>" +
                   "<div class='bdbutton'><a href=" + gatorButton.href +"><img src=" + IMGLOC + gatorButton.src +" width="+ gatorButton.width +" height="+ gatorButton.height +" border="+ gatorButton.border +" align="+ gatorButton.align +" alt='Subscribe in NewsGator Online'/></a></div></div></div>" + // end button float - end row1
                   "<div class='bdbuttonrow2'><div class='bdbuttonfloat'><div class='bdbutton'><a href=" + rojoButton.href +"><img src=" + IMGLOC + rojoButton.src +" width="+ rojoButton.width +" height="+ rojoButton.height +" border="+ rojoButton.border +" align="+ rojoButton.align +" alt='Subscribe in Rojo'></a></div>" +
                   "<div class='bdbutton'><a href=" + msnButton.href +"><img src=" + IMGLOC + msnButton.src +" width="+ msnButton.width +" height="+ msnButton.height +" border="+ msnButton.border +" align="+ msnButton.align +" alt='Subscribe using MSN'></a></div>" +
                   "<div class='bdbutton'><a href=" + bloglinesButton.href +"><img src=" + IMGLOC + bloglinesButton.src +" width="+ bloglinesButton.width +" height="+ bloglinesButton.height +" border="+ bloglinesButton.border +" align="+ bloglinesButton.align +" alt='Subscribe with Bloglines' /></a></div></div></div>" + //end button float - end row2
                   "<div class = 'bdbuttonrow3'><div class='bdbuttonfloat'><div class='bdbutton'><a href=" + googleButton.href +"><img src=" + IMGLOC + googleButton.src +" width="+ googleButton.width +" height="+ googleButton.height +" border="+ googleButton.border +" alt='Add to Google'></a></div>"  +
                   "<div class='bdbutton'><a href=" + pageflakeButton.href +"><img src=" + IMGLOC + pageflakeButton.src +" width="+ pageflakeButton.width +" height="+ pageflakeButton.height +" border="+ pageflakeButton.border +" align="+ pageflakeButton.align +" alt='Add to Page Flakes'></a></div></div></div>" + //end button float - end row2
                   "<div class='bdendtext'>Paste this link into your favorite RSS desktop reader:</div>" +
                   "<div class='urltext'>" + rssUrl+ "</div>");
                   
    YAHOO.rssBalloon.overlayContext.setFooter("<div class='ftline'></div><div class='ftendtext'>See all the RSS MarketWatch offers:</div><div class='ftlink'><a href='http://marketwatch.com/rss/'>http://marketwatch.com/rss/</a></div>");                                                               
    YAHOO.rssBalloon.overlayContext.render(document.body);

    var closeLink = document.getElementById('hdcloselink');
    YAHOO.util.Event.addListener(closeLink, 'click', YAHOO.rssBalloon.hideBalloon);
};


YAHOO.rssBalloon.setup = function ()
{
    var mainRssLink = document.getElementById(YAHOO.rssBalloon.TOPRSSLINK);
    YAHOO.util.Event.addListener(mainRssLink, 'click', YAHOO.rssBalloon.showBalloon);
};


YAHOO.rssBalloon.button = function (href, src, width, height, border, align)
{
    this.href=href;
    this.src=src;
    this.width=width;
    this.height=height;
    this.border=border;
    this.align = align;
}


YAHOO.rssBalloon.showBalloon = function(e)
{
    if (!YAHOO.rssBalloon.isInitialized)
    {
        YAHOO.rssBalloon.init();
    }
    else
    {
        YAHOO.rssBalloon.overlayBackground.show();
        YAHOO.rssBalloon.overlayContext.show();
    }
    
    YAHOO.util.Event.preventDefault(e);
}


YAHOO.rssBalloon.hideBalloon = function(e)
{
    YAHOO.rssBalloon.overlayContext.hide();
    YAHOO.rssBalloon.overlayBackground.hide();

    YAHOO.util.Event.preventDefault(e); 
}


YAHOO.util.Event.onContentReady('__EVENTVALIDATION', YAHOO.rssBalloon.setup);

