
//////////////////////////////////////////////////////////////////////////////
//
// Source file for FrontEnd/Std/Std.js
// Main client script file for MSNBC.com
// Incorporates former std.js, nmjs07.js, buttons.js, and video-tease.js
//
// Script code should live in this file rather than inline on pages to
// minimize download size of pages after initial visit (PLT2 vs PLT1).
// Eventual goal is for there to be no script inline on pages other than
// calls to functions in this file.
//
// To make changes to /js/std.js:
//
// 1. Integrate bin-sources/Std/Std.js, bin-sources/Std/JSquishStdJs.bat, and
//    FrontEnd/js/std.js to your project folder and check in.
// 2. Check out both bin-sources/Std/Std.js and FrontEnd/js/std.js from your
//    project folder.
// 3. Make your changes in this file (bin-sources/Std/Std.js).
// 4. Run JSquishStdJs.bat from the bin-sources/Std folder to compress this
//    file and generate FrontEnd/js/std.js.
// 5. When your changes are complete and verified, check in in both
//    bin-sources/Std/Std.js and FrontEnd/js/std.js to your project folder.
// 6. When your project is ready for integration to the private/wb tree,
//    integrate both bin-sources/Std/Std.js and FrontEnd/js/std.js. You
//    should not have needed to modify bin-sources/Std/JSquishStdJs.bat,
//    so you should not have any changes to that file that need integration.
//
// Note that if you're having trouble debugging in the compressed version of
// the file, you can copy the uncompressed version to FrontEnd/js/std.js to
// make it easier. Be sure to re-compress afterward; the uncompressed
// version should never be checked in as FrontEnd/js/std.js.
//
// Questions? Ask PeterDur.
//


// Include this comment in output. You can modify bin-sources/Std/Std.js.
// This comment is a reminder not to edit/modify FrontEnd/js/std.js directly.
//#out /* Copyright (C) 2001-2005 MSNBC - Do not modify */


// Comment template for STD.JS - intended for eventual automated harvest
// of documentation. Summary should be a 1-2 line description of what the
// function does. Remarks should include from where this function is
// called (only from std.js, from particular XSLs, etc.) and any additional
// details.
/// <summary>
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
/// </remarks>


//////////////////////////////////////////////////////////////////////////////
//
// Original STD.JS
//

/// <summary>
/// declare domain name list
/// </summary>
var siteDomainList = {"MSNBC":"www.msnbc.msn.com", 
					  "NBCSPORTS":"nbcsports.msnbc.com",
					  "Today":"today.msnbc.msn.com",
					  "CNBC":"www.cnbc.com"};
if(pd_me==null){pd_me=new Object();pd_me.site="MSNBC";}
//Expand and Collaspse colorbox

function collapseColorBox(o)
{
	var cboxtbl=getObj(o.getAttribute("id").replace("img",""));
	if (cboxtbl!=null)
	{
		cboxtbl.style.display=((cboxtbl.style.display=="none")?"block":"none");
	}
	var exco=new Array("Expand", "Collapse");
	o.src=((o.src.indexOf(exco[0])>0)?o.src.replace(exco[0],exco[1]):o.src.replace(exco[1],exco[0]) );
	pd_onc( ((o.src.indexOf(exco[0])>0)?exco[0]:exco[1])+" Colorbox", '',o.getAttribute("id").replace("cbimg_",""),'0',((o.src.indexOf(exco[0])>0)?exco[0]:exco[1])+" Colorbox",window.location.href);
}

//
// Marquee
//


/// <summary>
/// Writes a marquee item into the specified div.
/// </summary>
/// <param name="sDivId">Name of the marquee div to update</param>
/// <remarks>
/// Call inserted by _renderMarquee in BNMarquee.xsl; also called by mq_timer
/// in this file.
/// </remarks>

function mq_write(sDivId)
{
	var oS = new UberSniff();
	mq = mq_a[sDivId];
	
	var oMqd = document.getElementById(sDivId);
	oMqd.innerHTML = mq.mq_as[mq.Current];
	
	if (mq.items > 1)
	{
		mq_timer(mq.Time, sDivId);
		mq.Current++;
		if (mq.Current > mq.items)
			mq.Current = 1;
	}
}

/// <summary>
/// Restarts the timer for the marquee animation.
/// </summary>
/// <param name="n">Interval for the animation</param>
/// <remarks>
/// Calls written for mouse events in _renderMarquee and
/// BNGetHeadlinesDownlevel in BNMarquee.xsl; also called from mq_write
/// and mq_move
/// </remarks>
function mq_timer(n, sDiv)
{
	if (mq_a[sDiv].Timer)
	{
		clearTimeout(mq_a[sDiv].Timer);
	}
	mq_a[sDiv].Timer=0;
	if (n > 0)
	{
		mq_a[sDiv].Timer = setTimeout("mq_write('"+ sDiv +"')", n);
	}
}


//
// Print This - Email This - Blog This - IM This
//


/// <summary>
/// Pops up printer-friendly child window for "Print This"
/// </summary>
/// <remarks>
/// Call written by the doThis template in storyBody.xsl.
/// The ID of the current story is passed as an ignored parameter to this
/// function; that makes the print link appear visited only if you've printed
/// the particular story.
/// TODO: Can we simplify RE code below with pd_me properties?
/// </remarks>
function printThis()
{
	var x, s = location.href;
	if ((x=s.indexOf('#')) >= 0)
	{
	    s = s.substr(0,x);
	}
	if (s.indexOf('?') >= 0)
	{
		s += '&print=1&displaymode=1098';
	}
	else
	{
		if (s.charAt(s.length-1) != '/')
		{
			s += '/';
		}
		s += 'print/1/displaymode/1098/';
	}
	var rdid = /[\?|&|\/]did[=|\/](\d*)/;
	var mdid = s.match(rdid);
	if (mdid != null && mdid[1] != '')
	{
		var rid = /[\?|&|\/]id[=|\/](\d*)/;
		var mid = s.match(rid);
		if (mid != null && mid[1] != '')
		{
			s = s.replace(mid[1], mdid[1])
		}
	}
	var o = new UberSniff();
	if (o.webtv)
	{
		location.href = s;
	}
	else
	{
		OCW(s, 'print', 'width=640,height=480,scrollbars=1,resizable=1');
	}
}


/// <summary>
/// Launches mail client to send a link to a page.
/// </summary>
/// <remarks>
/// TODO: CALLER: Insert caller information.
/// Named emThis rather than emailThis because of poptext_codeV2.js.
/// The ID of the current story is passed as an ignored parameter to this
/// function; that makes the print link appear visited only if you've printed
/// the particular story.
/// </remarks>
function emThis()
{
	var emailSubject;
    var linkUrl;
    if (pd_me.snm == 'Today')
    {
        emailSubject = 'TODAY';
        linkUrl = 'today.msnbc.msn.com';
    }
    else if (pd_me.nw)
    {
        emailSubject = 'Newsweek.com%20on%20MSNBC';
        linkUrl = location.host;
    }
    else
    {
		// Change MSNBC.com to msnbc.com - Bug 6943
		switch(pd_me.site)
		{
			case "NBCSPORTS":
				emailSubject = 'nbcsports.com';
				break;
				
			default:
				emailSubject = 'msnbc.com';
				break;
		}
        linkUrl = location.host;
    }
	trackit();
	// Add rH, rD variables to make the code more clear
	// Use replace() to solve the problem with & and # character in email subject and content - Bug 6563
	// Replace all '&' with '%26' and '#' with '%23'
	var rH = encodeURI(pd_noul(pd_me.h)).replace(/&/g, '%26').replace(/#/g, '%23');
	var rD = encodeURI(pd_noul(pd_me.d)).replace(/&/g, '%26').replace(/#/g, '%23');	
	var et = 'mailto:?subject=' +
		emailSubject +
		// Remove 'Article' in email subject - Bug 6943
		/* '%20Article:%20'  */	
		':%20' + rH +
		'&body=' + rH +
		'%0D%0A' + rD +
		'%0D%0Ahttp://' +
		linkUrl + '/id/' + pd_me.id + pd_me.su + '/from/ET/';
	if (pd_me.ep != '')
		et += '%0D%0A_____________________________%0D%0A' + pd_me.ep;

	location.href = et;
}

/// <summary>
/// Launches mail client to send a link to a page. for related photo track email event
/// </summary>
/// <param name="id">Photo ID</param>
/// <param name="emsub">mail subject set by related photo</param>
/// <param name="embody">mail content set by related photo</param>
/// <remarks>
/// </remarks>

function emThis2(id, emsub, embody, address)
{
	trackit(id);
	var et = 'mailto:';
	if(address)
		et += address;
	et += '?subject=' + emsub + '&body=' + embody;
	location.href = et;
}


/// <summary>
/// Checks to see if Blog This links should be shown.
/// </summary>
/// <remarks>
/// TODO: CALLER: Insert caller information.
/// The Blog This link is normally hidden, and is only shown for browsers
/// for which this functionality is supported.
/// </remarks>
function blogCheck()
{
	// Show Blog This for MSIE on Windows only
	// TODO: Use UberSniff here? Create global UberSniff object in pd_top?
	if ((navigator.userAgent.indexOf("MSIE") > 0) &&
		(navigator.userAgent.indexOf("Win") > 0))
	{
		document.all.blogThis.style.display = "";
	}
}


/// <summary>
/// Starts an MSN Spaces blog entry about this page.
/// </summary>
/// <param name="u">URL to pass to blog entry</param>
/// <remarks>
/// TODO: CALLER: Insert caller information.
/// </remarks>
function blogThis(u)
{
	// Normalize the URL
	if (u.charAt(0) == "/")
	{
		u = "http://" + window.location.host + u
	}
	else
	{
		u = window.location.href
	}

	// Get selected text
	var sel = document.selection.createRange();
	sel.expand("word");

	// Create popup window to compose blog entry
	window.open("http://spaces.msn.com/BlogIt.aspx?Title="
		+ escape(document.title) + "&SourceURL=" + escape(u) +
		"&description=" + escape(sel.text));
}


/// <summary>
/// Launches MSN Messenger to IM this story.
/// </summary>
/// <param name="docId">Document ID of the calling story</param>
/// <remarks>
/// Called from doThis template in storyBody.xsl.
/// </remarks>
function IMThis(docId)
{
	this.gid=function(i)
	{
		return document.getElementById(i);
	};
	try
	{
		obj=new ActiveXObject("MSNMessenger.P4QuickLaunch");
	}
	catch(e)
	{
		obj=null;
	};
	if(obj!=null)
	{
		obj.LaunchApp("10331036","");
		SetCookie('MSGRSTORYID',docId);
	}
	else
	{
		if (!gid("noMSNImDiv"))
		{
			noMSNImDiv=document.createElement("div");
			noMSNImDiv.setAttribute("id","noMSNImDiv");
			contentContainer=document.createElement("div");
			noMSNImDiv.appendChild(contentContainer);
		}
		else
		{
			gid("noMSNImDiv").style.display="block";
		};
		noMSNImDiv.className="floatBox";
		contentContainer.className="floatBoxContent";
		contentContainer.innerHTML="<div class='floatBoxHead'><span onmouseover='document.body.style.cursor=\"pointer\"' onmouseout='document.body.style.cursor=\"auto\"' onclick='document.getElementById(\"noMSNImDiv\").style.display=\"none\"'>[x]</a></div>Sorry, your configuration doesn't support this feature.<br>The minimum requirements are MSN Messenger 6.0 or higher and Internet Explorer 5.5 or higher.<br><a href='http://get.live.com/messenger/overview' style='color:black;text-decoration:underline'  target='msnwin'>Download Windows Live Messenger now</a>.<br><br>";
		dt=gid("doThis");
		it=gid("imThis"); 
		if(it==dt.childNodes[dt.childNodes.length-1])
		{
			dt.appendChild(noMSNImDiv);
		}
		else
		{
			dt.insertBefore(noMSNImDiv,it.nextSibling);
		}
	}
}


//
// Sidebar
//


/// <summary>
/// Sets timeout and hooks resize event to call msnSideBar2 to show/hide
/// D column sidebar depending on window size.
/// </summary>
/// <param name="bNFirst">Never passed</param>
/// <remarks>
/// Call written by DColumnStory and DColumnFront in DColumn.xsl.
/// TODO: Remove bnFirst.
/// </remarks>
function msnSideBar(bNFirst)
{
	var oS = new UberSniff();
	if (oS.ie || oS.nn >= 5)
	{
		if (!bNFirst)
		{
			if (oS.ie >= 5 && !oS.mac)
			{
				window.attachEvent("onresize", msnSideBar);
			}
			else
			{
				window.onresize = msnSideBar;
			}
		}
		setTimeout("msnSideBar2()", 100);
	}
}


/// <summary>
/// Shows/hides D column sidebar
/// </summary>
/// <remarks>
/// INTERNAL: called from event and timeout set up by msnSideBar.
/// TODO: Remove SiteCal support.
/// TODO: Outer browser check not needed as function is only called when
/// this condition is true since msnSideBar checks it.
/// </remarks>
function msnSideBar2()
{
	var oS = new UberSniff();
	if (oS.ie || oS.nn >= 5)
	{
		var oSBar = document.getElementById("DCol");
		if (oSBar)
		{
			var bWid =
				(((oS.ie) ? document.body.clientWidth : self.innerWidth) > 935);
			if (bWid)
			{
				var oSC = document.getElementById("siteCal");
				if ((oSC != null) && (oSC.src == "about:blank"))
					oSC.src = oSC.getAttribute("hideSrc");
			}
			if (oS.nn >= 5 && bWid && oSBar.style.display == "none")
			{
				oSBar.style.display = "block";
				oSBar.style.display = "none";
			}
			oSBar.style.display = bWid ? "block" : "none";
		}
	}
}


//
// Launching Video, Audio, and Slideshows
//

/// <summary>
/// Launches Next Gen video player.
/// </summary>
/// <param name="vDocId">doc id off the video tease to open</param>
/// <param name="sGuid">guid for emergency switch back to msn</param>
/// <param name="sFlavor">optional, specify a particular flavor of player to launch</param>

function vPlayer(vDocId,sGuid,sFlavor){
	var bEmergency=false;
	var sHost="http://" + siteDomainList[pd_me.site];

	if (!siteDomainList[pd_me.site]){
		sHost="http://www.msnbc.msn.com";	
	}
	var sDefaultFlavor="21134540";
	if (sHost.toLowerCase().indexOf("nbcsports.msnbc.com")>-1||(location.host.toLowerCase().indexOf("nbcsports.msnbc.com")>-1)){
		sDefaultFlavor="22825103";
		sHost="http://nbcsports.msnbc.com";
	}
	if (!sFlavor){			
		sFlavor=sDefaultFlavor;
	}
	var vUrl=sHost+"/id/"+sFlavor+"/vp/"+vDocId+"#"+vDocId;




	if (!bEmergency){
		var oUser=new UberSniff();
		var sLoc=",location=1";
		if (oUser.ie>6){
			sLoc=",location=0";
		}
		var w = window.open(vUrl,"MSNBCvplayer","width=1000,height=600,status=1,scrollbars=0,resizable=0,toolbar=0,menubar=0,titlebar=0,directories=0"+sLoc);
		if (w.focus){
			w.focus();
		}
	}
	else{
		msnvDwd('00',sGuid, 'us','', 'm5', 'msnbc', '', '', '');	
	}
}

/// <summary>
/// Launches video player.
/// </summary>
/// <param name="gPV">?</param>
/// <param name="sGuid">GUID of video to open</param>
/// <param name="bDck">If true, open in main browser window (no popup)</param>
/// <param name="sMenu">Not currently used</param>
/// <param name="sSubM">Not currently used</param>
/// <param name="sURL">URL to open in browser below video player</param>
/// <param name="sPL">Playlist parameters</param>
/// <param name="bRP">Not currently used</param>
/// <param name="bStatic">Not currently used</param>
/// <param name="sList">?</param>
/// <remarks>
/// Call written by hyperlink.xsl.
/// Legacy function, it calls msnvDwd instead now.
/// </remarks>
function oMvsLink(gPV, sGuid, bDck, sMenu, sSubM,
	sURL, sPL, bRP, bStatic, sList)
{
	/*
	var sLink = "http://video.msn.com/v/us/msnbc.htm";
	if (sPL)
	{
		sGuid = sGuid + "," + sPL;
	}
	sLink += "?f=" + gPV + "&g=" + sGuid + "&t=m5";
	if (sList)
	{
		sLink += "&p=" + escape(sList);
	}
	if (!bDck)
	{
		var ovp = window.open(sLink, "ovp",
			"width=788,height=598,status=1,scrollbars=yes,resizable=yes");
		if (sURL)
		{
			location.href = sURL;
		}
	}
	else
	{
		location.href = sLink;
	}
	*/
	msnvDwd(gPV, sGuid, 'us', sList, 'm5', 'msnbc', '', '', '');
}

/// <summary>
/// Bug 4658 fix, handler for vidoe player launch button.
/// Process linkTrackHandler function and stop event bubble
/// </summary>
/// <param name="e"></param>
/// <remarks>
/// </remarks>
function msnvBut(e)
{
    if (e)
    {
        linkTrackHandler(e);

        //stop the event bubble up
        if (e.target) 
        {
            e.stopPropagation(); //dom/firefox
        }
        else if (e.srcElement) 
        {
            e.cancelBubble = true;//ie
        }
    }
}

/// <summary>
/// Launches video player. (new)
/// </summary>
/// <param name="pid">Partner Id, 00 by default</param>
/// <param name="guid">GUID of video to open</param>
/// <param name="mkt">Market value</param>
/// <param name="pl">Playlist parameters</param>
/// <param name="t">Video Taxonomy</param>
/// <param name="idp">Page name</param>
/// <param name="fg">?</param>
/// <param name="did">Video Id</param>
/// <param name="tit">Video Title</param>
/// <remarks>
/// This function comes from http://video.msn.com/js/vp.js
/// Call written by hyperlink.xsl.
/// </remarks>
function msnvDwd(pid,guid,mkt,pl,t,idp,fg,did,tit) {
	if(mkt=='' || mkt==undefined) {mkt="us";}
	if(t=='' || t==undefined) {t="m5";}
	if(!pl) {pl='';}
	if(!t) {t='';}
	if(!fg) {fg='';}
	var vurl = msnvVU(mkt);
	var page = "v.htm";
	var rf = document.URL;
	if(idp != null && idp != undefined && idp.length > 0)
	{
		page = idp + ".htm";
	}
	var w = window.open(vurl + "/v/"+mkt+"/" + page + "?f="+pid+"&g="+guid+"&p="+escape(pl)+"&t="+t+"&rf="+rf+"&fg="+fg+"&brand=msnbc","msnVDWd","width=1020,height=750,status=1,scrollbars=1,resizable=1");

	if (did != '' && did != undefined && pd_me)
	{
		s_pageName = "Video" + 
			'|' + pd_nou(pd_me.s.substring(0,10)) +
			'|' + pd_nou(pd_me.ss.substring(0,10)) +
			'|' + pd_nou(tit);
		s_prop15 = pd_me.id;
		s_prop16 = "Video";
		s_prop35 = did;
		
		s_gs(s_account);
	}
}

/// <summary>
/// Get video url
/// </summary>
/// <param name="mkt">Market value</param>
/// <remarks>
/// This function comes from http://video.msn.com/js/vp.js
/// INTERNAL: call by msnvDwd
/// </remarks>
function msnvVU(mkt)
{
	var vurl = "http://video.msn.com";
	if(mkt != null && mkt != undefined && mkt.length > 0)
	{
		switch(mkt.toLowerCase())
		{
			case "es-us":
				vurl = "http://latino.video.msn.com";
				break;
			case "ja-jp":
				vurl = "http://jp.video.msn.com";
				break;
			case "en-ca":
				vurl = "http://video.sympatico.msn.com";
				break;
			case "fr-ca":
				vurl = "http://video.fr.sympatico.msn.com";
				break;
			case "en-au":
				vurl = "http://ninemsn.video.msn.com";
				break;
			case "en-gb":
				vurl = "http://video.uk.msn.com";
				break;
			case "en-ap":
				vurl = "http://video.ap.org";
				break;
			case "us":
				vurl = "http://video.msn.com";
				break;
			case "fr-fr":
				vurl = "http://video.fr.msn.com";
				break;
			default:
				vurl = "http://video.msn.com";
				break;
		}
	}
	return vurl;
}

/// <summary>
/// Launches audio player.
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
/// Call written by hyperlink.xsl.
/// TODO: Remove backward compatible code at some point?
/// </remarks>
function m_OpenMPV3(sType, sAsx)
{
	var sUA = navigator.userAgent.toLowerCase();
	if (sUA.indexOf("webtv") > -1)
	{
		alert("Sorry, your browser does not support MSNBC video.");
	}
	else
	{
		if ((sType.toLowerCase() == "a"))
		{
			location.href = "http://www.msnbc.com/news/asx/audio/28/" +
				sAsx + ".asx";
		}
		else
		{
			alert("The video you are looking for is no longer available.");
		}
	}
}


/// <summary>
/// Opens a legacy slideshow.
/// </summary>
/// <param name="sPath">Path to slideshow</param>
/// <param name="sName">Not currently used</param>
/// <param name="b6x4">600x480 supported</param>
/// <param name="b8x6">800x600 supported</param>
/// <param name="b10x7">1024x768 supported</param>
/// <remarks>
/// Caller unknown.
/// TODO: Is this obsolete?
/// </remarks>
function OpenSS(sPath, sName, b6x4, b8x6, b10x7)
{
	var sQry = (sPath.indexOf("?") >= 0) ? "&" : "?";
	oUser = new UberSniff();
	if (self.name=='')
	{
		self.name = "cover";
	}
	nW = oUser.screenWidth;
	sOptions = "resizeable=yes,top=0,left=0,screenx=0,screeny=0,width=";
	sOptions += (nW>=1024 && b10x7) ? "935,height=700" :
		((nW >= 800 && b8x6) ? "675,height=520" : "510,height=430");
	if ((nW < 800 && !b6x4) || (oUser.mac > 0 && nW <= 700))
	{
		location.href = sPath + sQry + "fmt=&res=inline";
		return;
	}
	else
	{
		sPath += (sQry + "res=" + ((nW >= 1024 && b10x7) ? "10x7" :
			((nW >= 800 && b8x6) ? "8x6" : "6x4")));
		var sQry = "&";
		var xwinopen = window.open(sPath + sQry + "fmt=child",
			"slideshowhi", sOptions);
		if (oUser.nn > 3 || oUser.ie > 3)
		{
			xwinopen.focus();
		}
	}
}


/// <summary>
/// Opens a Workbench slideshow.
/// </summary>
/// <param name="nId">ID of slideshow tease document</param>
/// <param name="nSize"></param>
/// <param name="sFrame">Specific slide to go to (optional)</param>
/// <param name="sVar1">Optional extra variable</param>
/// <param name="sVar2">Optional extra variable</param>
/// <remarks>
/// TODO: CALLER: Insert caller information.
/// TODO: Use UberSniff throughout here.
/// </remarks>
function SSOpen(nId, nSize, sFrame, sVar1, sVar2)
{
	if (!nId)
		return;
	if (!nSize || nSize == '')
		nSize = 0;
	oUser = new UberSniff();
	var nW = oUser.screenWidth;
	var sOptions = "resizable=no,top=0,left=0,screenx=0,screeny=0";
		
	var sHref;
	if (nId.indexOf('workarea') != -1)
	{
	    sHref = "/id/" + nId + "/displaymode/1107/";
	}else{
	    sHref = "http://" + siteDomainList[pd_me.site] + "/id/" + nId + "/displaymode/1107/";
	}
		
	if (sFrame && sFrame != '')
		sHref += "framenumber/" + sFrame + "/";
	if (sVar1 && sVar1 != '')
		sHref += "var1/" + sVar1 + "/";
	if (sVar2 && sVar2 != '')
		sHref += "var2/" + sVar2 + "/";
	var bNew = true;
	if (((nSize == 0) || (nSize == 2)) && nW >= 935)
	{
		sOptions += ",width=935,height=685";
		sHref += "s/2/";
	}
	else if (((nSize == 0) || (nSize == 1)) && nW >= 780)
	{
		sOptions += ",width=780,height=519";
		sHref += "s/1/";
	}
	else
	{
		bNew=false;
	}
	gEnabled = (new tryCatch(
		"if (gEnabled!=undefined) return gEnabled; else return false;",
		"return false;")).trycatch();
	if (gEnabled)
	{
		// TODO: Refactor to share with glinkClick?
		var ua = window.navigator.userAgent;
		if (ua.indexOf('Win') != -1)
		{
			var ie = ua.indexOf('MSIE');
			if (ie != -1)
			{
				if (!(parseFloat(ua.slice(ie + 5)) < 5))
				{
					if (liveEnv)
					{
						destUrl = "http://" + siteDomainList[pd_me.site];
					}
					else
					{
						destUrl = location.protocol + "//" + location.host;
					}
					var evSrc = window.document.activeElement;
					var cmNode = evSrc;
					while (cmNode != null)
					{
						if (cmNode.tagName == "SPAN")
						{
							if (cmNode.getAttribute("subCM") != null)
								subCM = cmNode.getAttribute("subCM") + subCM;
							if (cmNode.getAttribute("CM") != null)
								break;
						}
						cmNode = cmNode.parentElement;
					}
					var ceNode = evSrc;
					while (ceNode != null)
					{
						if (ceNode.getAttribute("CE") != null)
							break;
						ceNode = ceNode.parentElement;
					}
					if (cmNode != null && ceNode != null)
					{
						var highlight = "SLIDE SHOW", path = sHref, surl = "";
						switch (evSrc.tagName)
						{
						case "A":
							highlight = evSrc.innerText;
							break;
						case "IMG":
							var aTag = evSrc;
							while (aTag != null)
							{
								if (aTag.tagName == "A")
								{
									break;
								}
								aTag = aTag.parentElement;
							}
							highlight = evSrc.alt;
							break;
						}
						if (pd_me.id != '3053415')
							surl = 'id/' + pd_me.id + '/';
						if (highlight.length > 0)
							highlight = "&HL=" +
								escape(highlight.substring(0, 60));
						sHref = defaultG + destUrl + "/" + path +
							"&&PS=" + pd_me.ps +
							"&SU=" + escape(destUrl + '/' + surl)+highlight +
							"&CM=" + escape(cmNode.getAttribute("CM")+subCM) +
							"&CE=" + escape(ceNode.getAttribute("CE"));
					}
				}
			}
		}
	}
	if (!bNew)
	{
		var xwinopen = window.open(sHref, "slideshow");
	}
	else
	{
		var	xwinopen = window.open(sHref, "slideshow", sOptions);
		if (oUser.nn > 3 || oUser.ie > 3)
		{
			xwinopen.focus();
		}
	}
	//s_gs(s_account);
}


/// <summary>
/// Creates try-catch wrapper in a JS object to avoid syntax errors in
/// downlevel browsers.
/// </summary>
/// <param name="sTry">Code to execute that might cause an error</param>
/// <param name="sCatch">Code to execute if an error occurs</param>
/// <returns>JS object with try-catch helper methods.</returns>
/// <remarks>
/// TODO: CALLER: Insert caller information.
/// </remarks>
function tryCatch(sTry, sCatch)
{
	this.trycatch =
		new Function("try{" + sTry + "}catch(e){" + sCatch + "}");
	this.trycatchV =
		new Function("s1", "try{" + sTry + "}catch(e){" + sCatch + "}");
}


/// <summary>
/// Consolidates browser sniffing code in one JS object.
/// </summary>
/// <param name="sUndefined">Not passed, used to check for undefined</param>
/// <returns>JS object with browser sniffing properties.</returns>
/// <remarks>
/// TODO: CALLER: Insert caller information.
/// </remarks>
function UberSniff(sUndefined)
{
	var ua = navigator.userAgent.toLowerCase();

	// Identify specific browser versions
	this.webtv = (ua.indexOf("webtv") > -1);
	this.ie = (parseFloat(ua.slice(ua.indexOf("msie") + 5)));
	this.nn = (this.ie) ? (-1) :
		(parseFloat(ua.slice(ua.indexOf("mozilla/") + 8)));
	this.mac = (ua.indexOf("mac") > -1);
	this.firefox = (ua.indexOf("firefox") > -1);
	this.safari = (ua.indexOf("safari") > -1);

	// Flash version
	// TODO: Why use navigator.MSNBCFlashVer?
	if (navigator.MSNBCFlashVer == sUndefined)
	{
		if (this.nn <= 0 && this.ie < 5)
		{
			// TODO: Why do we say 6 here?
			navigator.MSNBCFlashVer = 6;
		}
		else
		{
			if (!this.mac && this.ie > 4)
			{
				var oTestVersion = new tryCatch(
					"oWMPlayer=new ActiveXObject('ShockwaveFlash.ShockwaveFlash.'+s1);return s1;",
					"return 0;");
				navigator.MSNBCFlashVer = -1;
				for (var nCheckVersion = 9; nCheckVersion > 2; --nCheckVersion)
				{
					if (oTestVersion.trycatchV(nCheckVersion))
					{
						navigator.MSNBCFlashVer = nCheckVersion;
						break;
					}
				}
			}
			else
			{
				if (navigator.plugins['Shockwave Flash'])
				{
					navigator.MSNBCFlashVer = (parseInt(navigator.
						plugins['Shockwave Flash'].description.substr(16)));
				}
				else
				{
					navigator.MSNBCFlashVer =- 1;
				}
			}
		}
	}
	this.flash=navigator.MSNBCFlashVer;

	// Media Player version
	// TODO: Is the MSNBCMPlayer boolean or a number?
	if (navigator.MSNBCMPlayer == sUndefined)
	{
		if ((this.nn <= 0 && this.ie < 5) || this.mac)
		{
			navigator.MSNBCMPlayer = true;
		}
		else
		{
			if (!this.mac && this.ie > 4)
			{
				var oTestVersion = new tryCatch(
					"oWMPlayer=new ActiveXObject('WMPlayer.OCX');return oWMPlayer.versionInfo;",
					"return 0;");
				if (oTestVersion.trycatch())
				{
					// TODO: Remove duplicate call to trycatch?
					navigator.MSNBCMPlayer = oTestVersion.trycatch();
				}
				else
				{
					for (itest = 0; itest < 9; ++itest)
					{
						oTestVersion = new tryCatch(
							"oWMPlayer=new ActiveXObject('MediaPlayer.MediaPlayer.'+itest);return 1;",
							"return 0;");
						navigator.MSNBCMPlayer = (oTestVersion.trycatch());
						if (navigator.MSNBCMPlayer)
						{
							// TODO: Break rather than bump iterator?
							itest=100;
						}
					}
				}
			}
			else
			{
				// TODO: Do we need !! below?
				navigator.MSNBCMPlayer = !!(navigator.mimeTypes &&
					navigator.mimeTypes["video/x-ms-wm"] &&
					navigator.mimeTypes["video/x-ms-wm"].enabledPlugin);
			}
		}
	}
	this.mplayer=navigator.MSNBCMPlayer;

	// Screen resolution
	this.screenHeight = screen.height;
	this.screenWidth = screen.width;
	this.colorDepth = (this.nn >= 4) ? screen.pixelDepth : screen.colorDepth;
}


//
// Image rollover code
// Author - Brenden West. Updated 8-22-01
//


// TODO: INLINE: Move into pd_top? Want to avoid inline code as it will get
// reset on extra script src of this file.
//#newline
if (!window.sSelectedImg)
{
	var sSelectedImg = new Array();
}


/// <summary>
/// Handles button image state changes
/// </summary>
/// <param name="sImage">Image</param>
/// <param name="nState">0=out, 1=over, 2=selected, 3=both</param>
/// <remarks>
/// TODO: CALLER: Insert caller information.
/// TODO: Review need to support legacy use?
/// TODO: Simplify?
/// </remarks>
function SwapImage(sImage, nState)
{
	if (document.images)
	{
		if (parseInt(sImage) >= 0)
		{
			// convert old method
			sImage = "MenuImg" + sImage;
		}
		var oImage=document.images[sImage];
		if (oImage)
		{
			var sMenu = (sImage.indexOf("_img") > 0) ?
				sImage.substring(0,sImage.indexOf("_img")) : "x";
			if (!sSelectedImg[sMenu])
			{
				sSelectedImg[sMenu]="";
			}
			var oSelImg = sSelectedImg[sMenu];
			if (oSelImg != oImage)
			{
				var sNewState = "_" + nState + ".";
				if (nState == 0)
				{
					sNewState = ".";
				}
				else if (nState == 3)
				{
					sNewState = "_1.";
				}
				var sSrc = oImage.src;
				var sSrc1 = sSrc.substring(0, sSrc.lastIndexOf(".") + 1);
				var sSrc2 = sSrc.substring(sSrc.lastIndexOf(".") + 1);
				if (sSrc1.indexOf("_1.") > 0)
				{
					oImage.src = sSrc1.replace(/_1\.$/,sNewState) + sSrc2;
				}
				else if (sSrc != oSelImg.src)
				{
					oImage.src = sSrc1.replace(/\.$/,sNewState) + sSrc2;
				}
				if (nState > 1)
				{
					if (oSelImg)
					{
						oSelImg.src = oSelImg.src.replace("_1.", ".");
						oSelImg.src = oSelImg.src.replace("_2.", ".");
					}
					sSelectedImg[sMenu] = oImage;
				}
			}
		}
	}
}


/// <summary>
/// Fail over to default src for missing nav states.
/// </summary>
/// <param name="oImage">Image we need a fallback for</param>
/// <remarks>
/// TODO: CALLER: Insert caller information.
/// Not called from Std.js - is this still used?
/// </remarks>
function navImgFailover(oImage)
{
	if (oImage.src.indexOf("_1.") > -1)
	{
		SwapImage(oImage.name, 0);
	}
	else if (oImage.src.indexOf("_2.") > -1)
	{
		SwapImage(oImage.name.substring(0, oImage.name.indexOf("_img")) + "_img99", 2);
		SwapImage(oImage.name,3);
	}
}


//
// Child windows
//


/// <summary>
/// Launches a popup window with specifed content and options.
/// </summary>
/// <param name="sPath">URL to launch</param>
/// <param name="sName">Reuse name for popup window</param>
/// <param name="sOptions">Popup window options</param>
/// <remarks>
/// TODO: CALLER: Insert caller information.
/// Called from lots of random code.
/// TODO: Do we still need to set self.name?
/// TODO: Can we just use OCW name for this?
/// </remarks>
function OpenChildWindow(sPath, sName, sOptions)
{
	var oUser = new UberSniff();
	if (self.name == '')
	{
		self.name = "cover";
	}

	// TODO: Remove this code to do pre-WB slideshows?
	if ((sPath.indexOf("/c/") >= 0 &&
		sPath.toLowerCase().indexOf("ssmain") >= 0))
	{
		var sQry = (sPath.indexOf("?") >= 0) ? "&" : "?";
		var nW = oUser.screenWidth;
		sOptions = "resizeable=yes,top=0,left=0,screenx=0,screeny=0,width=";
		sOptions += (nW>=1024) ? "935,height=700" : "675,height=520";
		if (nW < 800)
		{
			location.href = sPath.replace(/fmt=child/i,"fmt=") +
				sQry + "res=inline";
			return;
		}
		else
		{
			sPath += sQry + "res=" + ((nW >= 1024) ? "10x7" : "8x6");
		}
	}

	// Open the window and set focus to it
	var x = window.open(sPath, sName, sOptions);
	if (oUser.nn > 3 || oUser.ie > 3)
	{
		x.focus();
	}
}


/// <summary>
/// Launches a popup window with specifed content and options.
/// </summary>
/// <param name="sPath">URL to launch</param>
/// <param name="sName">Reuse name for popup window</param>
/// <param name="sOptions">Popup window options</param>
/// <remarks>
/// TODO: CALLER: Insert caller information.
/// Called from lots of random code.
/// TODO: Do we still need to set self.name?
/// TODO: Can we just set OCW = OpenChildWindow?
/// </remarks>
function OCW(sPath, sName, sOptions)
{
	OpenChildWindow(sPath, sName, sOptions);
}


//
// Flash
//


/// <summary>
/// Renders a Flash object appropriately for the user's browser.
/// </summary>
/// <param name="oFl">JS object with properties describing Flash app</param>
/// <returns>HTML to write to page for Flash object</returns>
/// <remarks>
/// Call written by components\Flash.xsl.
/// TODO: Are there other callers from CDATA etc?
/// TODO: Need to document JS object properties, here or in Flash.xsl.
/// TODO: Instrumentation appears to no longer be used. Remove?
/// </remarks>
function writeFlashComponent2(oFl)
{
	// Create new UberSniff object if necessary
	if (!window.oSniff)
		oSniff = new UberSniff();

	// Set instrumentation properties
	// TODO: Properties are set but no longer used. Remove?
	if (oFl.instrumented)
	{
		oFl.instrumentInit();
		oFl.instrument.flashVer = oSniff.flash;
		oFl.instrument.browser = ((oSniff.ie > 0) * 1) +
			((oSniff.nn > 0) * 2) +
			((oSniff.ie < 1 && oSniff.nn < 1) * 3);
		oFl.instrument.browserVer = ((oSniff.ie > 0) * oSniff.ie) +
			((oSniff.nn > 0) * oSniff.nn);
	}

	// Set up default links to Flash download
	var sReturn;
	var noFlashLink1 = "";
	var noFlashLink2 = "<br clear=all><a href=\"http://www.macromedia.com/go/getflashplayer\"><img src=\"http://msnbcmedia.msn.com/i/msnbc/Components/Art/SITEWIDE/no_flash.gif\" border=\"0\"></a>";
	if (oFl.downloadLink == "top" || oFl.downloadLink == "")
	{
		noFlashLink1 = "<a href=\"http://www.macromedia.com/go/getflashplayer\" target=\"_new\">";
		noFlashLink2 = "</a>";
	}
	else if (oFl.downloadLink == "crop")
	{
		if (!oSniff.flash)
		{
			oFl.height = oFl.height - 25;
		}
	}

	// Determine what to write out if Flash is not supported
	// TODO: Refactor to combine the if/else cases? The 1/default cases?
	if (oFl.altImgWB3)
	{
		switch (oFl.defaultType)
		{
		case 1:
			noFlashLink1 = "<a href=" + oFl.url + ">";
			sReturn = "<table width=100% height=100%><tr><td align=center>" +
				noFlashLink1 + oFl.altImgWB3 + noFlashLink2 +
				"</td></tr></table>";
			break;

		case 2:
			sReturn = oFl.altImgWB3;
			break;

		case 3:
			sReturn = oFl.htm;
			break;

		default:
			sReturn = "<table width=100% height=100%><tr><td align=center>" +
				noFlashLink1 + oFl.altImgWB3 + noFlashLink2 +
				"</td></tr></table>";
		}
	}
	else
	{
		switch (oFl.defaultType)
		{
		case 1:
			noFlashLink1 = "<a href=" + oFl.url + ">";
			sReturn = "<table width=100% height=100%><tr><td align=center>" +
				noFlashLink1 + "<img src=" + oFl.altImg +
				" width=210 height=25 border=0>" + noFlashLink2 +
				"</td></tr></table>";
			break;

		case 2:
			sReturn = "<img border=0 src=" + oFl.altImg + " usemap=#" +
				oFl.ID + ">" + oFl.imageMap;
			break;

		case 3:
			sReturn = oFl.htm;
			break;

		default:
			sReturn = "<table width=100% height=100%><tr><td align=center>" +
				noFlashLink1 + "<IMG SRC=" + oFl.altImg +
				" WIDTH=210 HEIGHT=25 BORDER=0>" + noFlashLink2 +
				"</td></tr></table>";
		}
	}

	// Do we have a sufficient version of Flash for this application?
	if (oSniff.flash >= oFl.flashVer)
	{
		// Wrap flashvars to allow for empty values
		// TODO: Can't we set default of this to empty in flashObj2 below?
		var flashvars = "";
		if (oFl.flashVars)
		{
			flashvars = oFl.flashVars;
		}

		// Select separator for additional parameters on Flash app name
		// TODO: Just add the additional parameters here?
		var sSep = (oFl.flashFile.indexOf("?") > -1) ? "&" : "?";

		var seamlessTabbing='true';if(oFl.hasOwnProperty('seamlessTabbing') && oFl.seamlessTabbing.toLowerCase()=='false') seamlessTabbing='false';
		
		// Write out correct code for browser
		if (oSniff.mac || oSniff.nn >= 4 || oSniff.webtv)
		{
			// Use EMBED tag on Mac, Netscape/Firefox, and WebTV
			sReturn = "<a name=\"anc_" + oFl.ID + "\"><EMBED SRC=\"" +
				oFl.flashFile + sSep + "domain=" + document.domain + "&" +
				flashvars + "\" swLiveConnect=TRUE WIDTH=" + oFl.width +
				" HEIGHT=" + oFl.height +
				" ALIGN=top PLAY=" + oFl.play +
				" LOOP=" + oFl.loop +
				" BGCOLOR=" + oFl.bgcolor +
				" QUALITY=" + oFl.quality +
				" SCALE=" + oFl.scale +
				" SALIGN=" + oFl.salign +
				" MAYSCRIPT NAME=" + oFl.ID +
				" id=" + oFl.ID +
				" MENU=" + oFl.menu +
				" DEVICEFONT=" + oFl.deviceFont +
				" WMODE=" + oFl.mode +
				" ALLOWFULLSCREEN="+oFl.fullScreen+
				" SEAMLESSTABBING="+seamlessTabbing+
				" ALLOWSCRIPTACCESS=always TYPE=application/x-shockwave-flash PLUGINSPAGE=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash></EMBED></a>";
		}
		else if (oSniff.ie >= 4)
		{
			// Use OBJECT tag on Internet Explorer
			// TODO: Remove newlines from below
			sReturn = "<a name=\"anc_" + oFl.ID +
				"\"><OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://active.macromedia.com/flash2/cabs/swflash.cab#version=" +
				oFl.cabVersion + "\" ID=\"" + oFl.ID + "\" WIDTH=\"" +
				oFl.width + "\" HEIGHT=\"" + oFl.height + "\">\n";
			sReturn += "<PARAM NAME=movie VALUE=\"" + oFl.flashFile + sSep +
				"domain=" + document.domain + "&" + flashvars + "\">\n";
			sReturn += "<PARAM NAME=play VALUE=\"" + oFl.play + "\">\n";
			sReturn += "<PARAM NAME=loop VALUE=\"" + oFl.loop + "\">\n";
			sReturn += "<PARAM NAME=quality VALUE=\"" + oFl.quality + "\">\n";
			sReturn += "<PARAM NAME=scale VALUE=\"" + oFl.scale + "\">\n";
			sReturn += "<PARAM NAME=salign VALUE=\"" + oFl.salign + "\">\n";
			sReturn += "<PARAM NAME=menu VALUE=\"" + oFl.menu + "\">\n";
			sReturn += "<PARAM NAME=devicefont VALUE=\"" + oFl.deviceFont +
				"\">\n";
			sReturn += "<PARAM NAME=bgcolor VALUE=\"" + oFl.bgcolor + "\">\n";
			sReturn += "<PARAM NAME=wmode VALUE=\"" + oFl.mode + "\">\n";
			sReturn += "<PARAM NAME=allowScriptAccess VALUE=\"always\">\n";
			sReturn += "<PARAM NAME=allowFullScreen VALUE=\""+oFl.fullScreen+"\">\n";
			sReturn += "<PARAM NAME=seamlessTabbing VALUE=\""+seamlessTabbing+"\">\n";
			sReturn += "</OBJECT></a>\n";

			// Prevent News Menu flyouts from hiding this Flash app if
			// parameters permit this.
			// TODO: Can we just set this property on OBJECT tag in HTML?
			if ((oFl.mode.toLowerCase != "window") && (oSniff.ie >= 5))
			{
				sReturn += "<SCR" +
					"IPT LANGUAGE=JAVASCRIPT>document.getElementById('" +
					oFl.ID + "').nm_bOk=true;</SCR" + "IPT>";
			}
		}
	}
	return sReturn;
}


/// <summary>
/// Creates an JS object for Flash applications with default values.
/// </summary>
/// <returns>JS object for Flash application</returns>
/// <remarks>
/// Call written by components\Flash.xsl.
/// TODO: Can we reduce download size by counting on these defaults?
/// TODO: Are some of these parameters no longer used?
/// TODO: Instrumentation appears to no longer be used. Remove?
/// </remarks>
function flashObj2()
{
	this.flashFile = "filename.swf";
	this.altImg =
		"http://msnbcmedia.msn.com/i/msnbc/Components/Art/SITEWIDE/no_flash.gif";
	this.imageMap = "";
	this.defaultType = "";
	this.url = "";
	this.htm = "";
	this.height = "400";
	this.width = "520";
	this.ID = "dw";
	this.downloadLink = "top";
	this.webTV = "true";
	this.play = "true";
	this.loop = "false";
	this.quality = "best";
	this.scale = "noborder";
	this.salign = "LT";
	this.menu = "false";
	this.deviceFont = "false";
	this.mode = "opaque";
	this.cabVersion = "4,0,0,0";
	this.flashVer = 4;
	this.notCompatImg =
		"http://www.msnbc.com/images/msnbc/flash_default.gif";
	this.instrumented = false;
	this.instrumentInit =
		new Function("sMainSection", "sRefferer",
			"this.instrument=new instrumentObj(sMainSection,sRefferer,'0fa')");
	this.debug = true;
	this.fullScreen=false;
	this.seamlessTabbing='true';
	this.render = new Function("return writeFlashComponent2(this)");
	this.write = function() {
		document.write(this.render());
	};
	this.innerWrite= function(destination){
		var e=document.createElement("div");
		e.innerHTML=this.render();
		if (destination.firstChild){
			destination.replaceChild(e,destination.firstChild);
		}
		else{
			destination.appendChild(e);
		}
							
	};
}


/// <summary>
/// Creates a encapsulating Flash instrumentation parameters.
/// </summary>
/// <param name="sMain">Main section ID, never passed?</param>
/// <param name="sRef">Referrer, never passed?</param>
/// <param name="sPrefix">Parameter prefix, always 0fa?</param>
/// <returns>JS object encapsulating parameters</returns>
/// <remarks>
/// TODO: Instrumentation appears to no longer be used. Remove?
/// </remarks>
function instrumentObj(sMain, sRef, sPrefix)
{
	this.prefix = sPrefix;
	this.mainSection = sMain;
	this.referrer = sRef;
	this.flashVer = "0";
	this.browser = "0";
	this.browserVer = "0";
	this.os = "0";

	// TODO: Is instrumentObj.render used?
	this.render = new Function(
		"return this.prefix+'='+this.mainSection+this.referrer+this.flashVer+this.browser+this.browserVer+this.os");
}


/// <summary>
/// Obsolete function to show leave behind ads.
/// </summary>
/// <remarks>
/// TODO: No callers found. Remove?
/// </remarks>
function showLeaveBehindAd()
{
}


//
// Cookies
//


/// <summary>
/// Parses a value associated with the given key out of cookie.
/// </summary>
/// <param name="ck">Key for value to be read from cookie</param>
/// <returns>Value associated with key in cookie</returns>
/// <remarks>
/// INTERNAL: Called only from several functions in Std.js.
/// TODO: Rename for consistency?
/// TODO: May return wrong value if one key is a suffix of an earlier key.
/// </remarks>
function readCookie(ck)
{
	var anyCookies = document.cookie;
	var pos = anyCookies.toUpperCase().indexOf(ck.toUpperCase() + "=");
	var value = "";
	if (pos != -1)
	{
		var start = pos + ck.length + 1;
		var end = anyCookies.indexOf(";", start);
		if (end == -1)
		{
			end = anyCookies.length;
		}
		value = anyCookies.substring(start, end);
		value = unescape(value);
	}
	return value;
}

// TODO: INLINE: Move into pd_top?
//#newline
if (document.cookie.indexOf("TZM=") == -1)
{
	// TODO: Is parseInt necessary here? Why 0-x rather than -x?
	SetCookie("TZM", parseInt(0 - (new Date().getTimezoneOffset())));
}


/// <summary>
/// Adds a key-value pair to the cookie, with path and domain handled
/// correctly for the live site, and expiration in the distant future.
/// </summary>
/// <param name="sName">Key name for new item in cookie</param>
/// <param name="sValue">Value name for new item in cookie</param>
/// <param name="expDate">expire date for the cookie</param>
/// <remarks>
/// INTERNAL: Called only from several functions in Std.js.
/// TODO: Might we want to allow an optional expiry parameter?
/// </remarks>
function SetCookie(sName, sValue, expDate)
{
	var sExpires;
	if (expDate == "session"){
		sExpires = "";
	} else {
		sExpires = ";expires=" + (expDate ? expDate : new Date(2021, 10, 4).toGMTString());
	}
	document.cookie = sName + "=" + escape(sValue) + sExpires + ";path=/" + 
		((location.host.toLowerCase().indexOf("msnbc.msn.com")>=0) ? 
			";domain=msnbc.msn.com" : "");
}


// TODO: Do we still need this aliasing?
// TODO: Move to below flashObj2.
//#newline
flashObj = flashObj2;


//
// Email address validation
//


/// <summary>
/// Validates a list of email addresses.
/// </summary>
/// <param name="sEml">Email addresses to validate</param>
/// <returns>true if valid, false if invalid</returns>
/// <remarks>
/// TODO: CALLER: Not called from XSL or JS; used elsewhere? Is this
/// leftover from old Email This code?
/// </remarks>
function validateEmail(sEml)
{
	var bOK;

	// Remove trailing semicolon and spaces
	if (sEml.charAt(sEml.length - 1) == ";")
	{
		sEml = sEml.substr(0, sEml.length - 1);
	}
	sEml = sEml.replace(/\s/g, "");

	// Split into individual addresses; more than 5 is too many
	var aEml = sEml.split(";");
	if (aEml.length > 5)
	{
		return false;
	}

	// Validate each address
	// TODO: Don't need bOK; return false if 2 returns false else return true
	for (var i = 0;i < aEml.length; i++)
	{
		bOK = validateEmail2(aEml[i]);
		if (!bOK)
		{
			break;
		}
	}
	return bOK;
}


/// <summary>
/// Validates a single email address.
/// </summary>
/// <param name="strValue">Address to validate</param>
/// <returns>true if valid, false if invalid</returns>
/// <remarks>
/// INTERNAL: Called only from validateEmail.
/// </remarks>
function validateEmail2(strValue)
{
	var objRegExp = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9]{1,}[a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i;
	return objRegExp.test(strValue);
}


//
// G links
//


/// <summary>
/// Generates a G image reference when a link is clicked.
/// </summary>
/// <remarks>
/// Call hooked to onClick events by GLink.xsl.
/// </remarks>
function glinkClick()
{
	// Don't do anything if G links are turned off
	if (!gEnabled)
		return true;

	// Only do G linking on Windows IE 5+
	// TODO: Use uberSniff here?
	var ua = window.navigator.userAgent;
	if (ua.indexOf('Win') == -1)
		return true;
	var ie = ua.indexOf('MSIE');
	if (ie == -1)
		return true;
	if (parseFloat(ua.slice(ie + 5)) < 5)
		return true;

	// Force live G environment for pages hosted in Outlook
	if (location.protocol == "outlook:")
	{
		liveEnv = true;
		defaultG = liveG;
	}

	// Force preferred domain for live environment links
	if (liveEnv)
	{
		destUrl = "http://" + siteDomainList[pd_me.site];
	}
	else
	{
		destUrl = location.protocol + "//" + location.host;
	}

	// Capture source of click
	var evSrc = window.event.srcElement;

	// Find content module
	// TODO: Declare subCM?
	var cmNode = evSrc;
	while (cmNode != null)
	{
		if (cmNode.tagName == "SPAN")
		{
			if (cmNode.getAttribute("subCM") != null)
				subCM = cmNode.getAttribute("subCM") + subCM;
			if (cmNode.getAttribute("CM") != null)
				break;
		}
		cmNode = cmNode.parentElement;
	}

	// Find content element
	// TODO: Refactor to share with CM search above?
	var ceNode=evSrc;
	while (ceNode != null)
	{
		if (ceNode.getAttribute("CE") != null)
			break;
		ceNode = ceNode.parentElement;
	}

	// Do we have a CM and CE to pss to G?
	if (cmNode != null && ceNode != null)
	{
		// Get properties from source link
		// TODO: Refactor common code?
		var highlight = "", path = null, surl = "";
		switch (evSrc.tagName)
		{
		case "A":
			highlight = evSrc.innerText;
			path = evSrc.pathname + evSrc.search;
			if (evSrc.hash.length > 0)
				return true;
			break;

		case "AREA":
			path = evSrc.pathname + evSrc.search;
			if (evSrc.hash.length > 0)
				return true;
			break;

		case "IMG":
			var aTag = evSrc;
			while (aTag != null)
			{
				if (aTag.tagName == "A")
					break;
				aTag = aTag.parentElement;
			}
			if (aTag != null)
			{
				path = aTag.pathname + aTag.search;
				if (aTag.hash.length > 0)
					return true;
			}
			highlight = evSrc.alt;
			break;
		}

		// If don't have destination, work up to find one
		if (path == null)
		{
			var evNode = evSrc;
			while (evNode != null)
			{
				if (evNode.pathname != undefined)
				{
					path = evNode.pathname + evNode.search;
					break;
				}
				evNode = evNode.parentElement;
			}
		}
		if (path == null)
			return true;

		// Assemble parameters into G image reference
		if (pd_me.id != '3053415')
			surl = 'id/' + pd_me.id + '/';
		if (highlight.length > 0)
			highlight = "&HL=" + escape(highlight.substring(0, 60));
		defaultG = defaultG.replace("com/", "com/_");
		durl = defaultG + destUrl + "/" + path +
			"&&PS=" + pd_me.ps +
			"&SU=" + escape(destUrl + '/' + surl) + highlight +
			"&CM=" + escape(cmNode.getAttribute("CM") + subCM) +
			"&CE=" + escape(ceNode.getAttribute("CE"));
		var g_img = new Image();
		g_img.src = durl;
	}
	return true;
}


//
// Styles
//


/// <summary>
/// Writes a stylesheet reference if the stylesheet has not already been
/// referenced on the page.
/// </summary>
/// <param name="id">Document ID of style document</param>
/// <remarks>
/// Call written by boxstyle.xsl.
/// </remarks>
function getCSS(id)
{
	if (cssList[id] != true)
	{
		document.write(
			'<link rel="stylesheet" type="text/css" href="/default.ashx/id/' +
			id + '/">');
		cssList[id] = true;
	}
}


//
// IPN (Recommended Stories) history
//


/// <summary>
/// Adds the current page to the user's IPN history.
/// </summary>
/// <param name="docid">Document ID of current page</param>
/// <param name="docid">Section navigation ID of current page</param>
/// <remarks>
/// INTERNAL: Called from pd_top.
/// </remarks>
function add_history(docid, snid)
{
	if (docid.length > 0 && snid.length > 0)
	{
		// Get the old cookie
		var h1 = readCookie("H1");
		if (h1.length > 0)
		{
			// Respect user's choice not to track history
			if (h1 == 'X')
				return;

			// If item is already in history, remove it
			var pos = h1.indexOf(snid + "x" + docid);
			if (pos != -1)
				h1 = search_delete_history(snid + "x" + docid);

			// If there are more than 32 items in list, drop last two
			h1Set = h1.split("x");
			if (h1Set.length >= 32)
			{
				var secondLastDelim = h1.lastIndexOf("x",
					h1.lastIndexOf("x") - 1);
				h1 = h1.substr(0, secondLastDelim);
			}
			h1 = snid + "x" + docid + "x" + h1;
		}
		else
			h1 = snid + "x" + docid;

		// Update cookie value
		SetCookie("H1", h1);
	}
}


/// <summary>
/// Removes an entry from the user's IPN history.
/// </summary>
/// <param name="snid_docid">SN id + 'x' + document id</param>
/// <returns>New value of H1 cookie</returns>
/// <remarks>
/// Called from add_history here and from delete_history in
/// CDATA on Why page.
/// As currently coded, assumes snid_docid pair is in history.
/// </remarks>
function search_delete_history(snid_docid)
{
	var h1 = readCookie("H1");
	if (h1)
	{
		if (h1 == 'X')
			return;
		var pos = h1.indexOf(snid_docid);
		if (pos == 0)
		{
			h1 = h1.substr(snid_docid.length + 1);
		}
		else if (pos + snid_docid.length == h1.length)
		{
			h1 = h1.substr(0, pos - 1);
		}
		else
		{
			h1 = h1.substr(0, pos) + h1.substr(pos + snid_docid.length + 1);
		}
	}
	SetCookie("H1", h1);
	return h1;
}

/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function moveByline() {
    if (!document.all) {
        var elByline = document.getElementById("byLine");
        //bug 5117 fix, add element checks
        if (elByline){
            var byLineContent = elByline.innerHTML;
            if (byLineContent.length > 0) {
                var elStoryHead = document.getElementById("storyHead");
                
                //bug 5117 fix, add element checks
                if(elStoryHead){
                    var storyHeadContent = elStoryHead.innerHTML;
                    elStoryHead.innerHTML = "";
                    elByline.innerHTML = "";
                    var elFinalPos = document.getElementById("finalPos");
                    byLineContent = byLineContent.replace("padding: 5px 15px 0pt 0pt;", "padding: 15px 15px 0pt 0pt;");
                    
                    //bug 5117 fix, add element checks
                    if (elFinalPos){
                        elFinalPos.innerHTML = storyHeadContent + byLineContent;
                    }
                }
            }
        }
    }
}

/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function addFavorite(sUrl,sTitle){ if (!sUrl || sUrl == '') { sUrl = location.href; } if (!sTitle || sTitle == '') { sTitle = document.title; } if (document.all) { window.external.AddFavorite(sUrl,sTitle);} else {window.alert( 'Please click OK then press Ctrl+D to create a bookmark' );}}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function checkRecAdded(id){var recStr=readCookie("PERSONALRECIPE");obj=document.getElementById("addtoboxbtn"+id);if(recStr.indexOf(""+id)!=-1){if(obj)obj.innerHTML="This recipe has been added to your recipe box";}if(navigator.userAgent.indexOf("Opera")>-1)obj.style.paddingLeft="3px";}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function addToRecipeBox(id){var recStr=readCookie("PERSONALRECIPE");var recList=recStr.split("|");if(recList.length==200){alert("Sorry, your personal recipe box is already full.(maximum 200 recipes)");return;}id=""+id;if(recStr.indexOf(id)==-1){if(recStr!="")recStr+="|";recStr+=id;SetCookie("PERSONALRECIPE",recStr);document.location.reload(true);}}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function gotoRecipeBox(){SetCookie("RECIPEPAGE","");SetCookie("DELMARK","");document.location.href = "/id/8921460/";}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function printRecipe(id,mode){var s;s="/id/"+id+"/displaymode/1174/pm/"+mode+"/";var o=new UberSniff();if(o.webtv){location.href=s;}else{OCW(s,'print','width=800,height=600,menubar=1,scrollbars=1,resizable=1');}}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function printfull(id){printRecipe(id,0);}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function print4x6(id){printRecipe(id,1);}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function print3x5(id){printRecipe(id,2);}


//
// Page Data
//


// Page Data globals
//#newline
var pd_me,			// Collects properties of this page
cssList = new Array(),			// List of CSS stylesheets already rendered
curDoc,				// DEPRECATED: Id of the current document (use pd_me.id)
PSTaxonomy,			// DEPRECATED: Taxonomy value for Newsweek (use pd_me.ps)
s_pageName,			// Omniture: Page name as shown in SiteCatalyst
s_pageType,			// Omniture: errorPage if 404, else unused
s_channel,			// Omniture: Section name
s_campaign,			// Omniture: Not used
s_zip,				// Omniture: User's zip, from P2 cookie
s_account,			// Omniture: Site account, msnbcom in production
s_visitorSampling,	// Omniture: Sampling rate, usually 100
s_prop1,			// Omniture: Not used (was headline)
s_prop2,			// Omniture: Not used (was deck)
s_prop3,			// Omniture: Byline
s_prop4,			// Omniture: Section name
s_prop4_orig,		// Omniture: Used for link tracking
s_prop5,			// Omniture: Subsection name
s_prop5_orig,		// Omniture: Used for link tracking

s_prop6,			// Omniture: Subsubsection name
s_prop6_orig,		// Omniture: Used for link tracking

s_prop7,			// Omniture: Layout (template name, handheld, etc.)
s_prop8,			// Omniture: Is user personalized (Y/N)
s_prop9,			// Omniture: User's zip, from P2 cookie
s_prop10,			// Omniture: Connection speed (from MSN Video)
s_prop11,			// Omniture: Stock choices, from P1 cookie
s_prop12,			// Omniture: Weather choices, from P1 cookie
s_prop13,			// Omniture: Local News choice, from P1 cookie / from Stid(Station id) cookie for NBC sports
s_prop14,			// Omniture: Sports choices, from P1 cookie
s_prop15,			// Omniture: Document ID (Phase 2)
s_prop16,			// Omniture: DocType, or external page type (Phase 2)
s_prop16_orig,      // Omniture: Used for link tracking
s_prop17,			// Omniture: Search terms (Phase 2)
s_prop18,			// Omniture: Hour updated (Phase 2)
s_prop19,			// Omniture: Local affiliate of page (Phase 2)
s_prop20,			// Omniture: Tracking of From (Phase 2)
s_prop21,			// Omniture: Tracking of From RS (Phase 2)
s_prop22,			// Omniture: Tracking of From RL (Phase 2)
s_prop23,			// Omniture: Tracking of From RSS (Phase 2)
s_prop24,			// Omniture: Tracking of From ET (Phase 2)
s_prop26,			// Omniture: Tracking of the "Name" field of the Source document
s_prop27,			// Omniture: Tracking of link location (autobox, databox, tabbox)
s_prop28,			// Omniture: Tracking of "dst" in the query string
s_prop30,			// Omniture: Tracking Domain Consolidation (Phase 2)
s_prop31,			// Omniture: Tracking of "ocid" in the query string
s_prop33,			// Omniture: Tracking of From Radio (Phase 2)
s_prop35,			// Omniture: Partner Wrapper Name
s_prop39,			// Omniture: Flyout user setting
s_prop41,			// Omniture: Tracking "AVERAGE RATING | NUMBER OF RATINGS"
s_eVar1,			// Omniture: Tracking of From (Phase 2)
s_eVar2,			// Omniture: Tracking of From RS (Phase 2)
s_eVar3,			// Omniture: Tracking of From RL (Phase 2)
s_eVar4,			// Omniture: Tracking of From RSS (Phase 2)
s_eVar5,			// Omniture: Tracking of From ET (Phase 2)
s_eVar39;			// Omniture: Tracking of From MSN Referrer


/// Called at the top of each page to initialize page data and other
/// constructs for client-side JavaScript code.
/// </summary>
/// <param name="dt">DocType, or external page type</param>
/// <param name="dv">Device name (html40, msntv, handheld)</param>
/// <param name="id">Document ID</param>
/// <param name="h">Headline</param>
/// <param name="d">Description (aka Abstract)</param>
/// <param name="s">Section</param>
/// <param name="ss">Subsection</param>
/// <param name="sss">Subsubsection</param>
/// <param name="pn">Page number, if available</param>
/// <param name="pc">Page count, if appropriate</param>
/// <param name="t">Last update time, as 'hh:mm, dd/mm/yy' in ET (24h)</param>
/// <param name="b">Byline, without 'By ' prefix</param>
/// <param name="l">Layout name</param>
/// <param name="af">Affiliate name, on local pages</param>
/// <param name="ep">Email promo text for Email This</param>
/// <param name="sn">ID of Section Navigation</param>
/// <param name="ps">PS Taxonomy value</param>
/// <param name="pw">Partner wrapper Name (for NFN)</param>
/// <param name="nd">News menu default setting</param>
/// <param name="adp">Adpackage Object</param>
/// <param name="sid">Site Name, as "MSNBC", "Today", etc.</param>
/// <param name="sc">the "Name" field of the Source document</param>
/// <remarks>
/// The call to this function is usually inserted by BodyTop in
/// SectionDescription.xsl. May also be called from non-Workbench pages.
/// Unused values can be passed as '' or undefined if a placeholder is needed.
/// TODO: Create UberSniff object here?
/// </remarks>
function pd_top(dt, dv, id, h, d, s, ss, sss, 
	pn, pc, t, b, l, af, ep, sn, ps, pw, nd,tvc,adp,snm,olt,sc,ssss,sssss,sitename)
{
	// Set up pd_me with values passed in, pd_me may be instanted and filled at other places, so don't remove the if(pd_me==null), by v-starli@microsoft.com 2007/2/13
	if(pd_me==null) pd_me = new Object;		
	pd_me.dt = dt;
	pd_me.dv = pd_str(dv);
	pd_me.id = curDoc = pd_str(id);
	pd_me.h = pd_str(h);
	pd_me.d = pd_str(d);
	pd_me.s = pd_str(s);
	pd_me.ss = pd_str(ss);
	pd_me.sss = pd_str(sss);
	if(ssss!=null) pd_me.ssss = pd_str(ssss);else pd_me.ssss='';
	if(sssss!=null) pd_me.sssss = pd_str(sssss);else pd_me.sssss='';
	if(sitename!=null) pd_me.site = sitename;else pd_me.site='';
	pd_me.pn = pd_str(pn);
	pd_me.pc = pd_str(pc);
	pd_me.t = pd_str(t);
	pd_me.b = pd_str(b);
	pd_me.l = pd_str(l);
	pd_me.af = pd_str(af);
	pd_me.ep = pd_str(ep);
	pd_me.sn = pd_str(sn);
	pd_me.ps = PSTaxonomy = pd_str(ps);
	pd_me.pw = pd_str(pw);
	pd_me.nd = pd_str(nd);
	pd_me.tvc = tvc;
	pd_me.snm = pd_str(snm);
	pd_me.olt = (olt == 'true');
	pd_me.sc = pd_str(sc);
	
	//adpackage and encapsulated dap call
	
	if(null != adp)
	{
	    pd_me.adp=adp;	
	    pd_me.adp.dap=function(adpS){var adpO=adp[adpS];if(adpO&&adpO.AdGroup&&(typeof(dap)=="function")){dap("&amp;PG="+adpO.AdGroup+"&amp;AP="+adpO.AdSizeCode,adpO.Width,adpO.Height);return true;}return false;};
	}
	
	// Get values from personalization cookies
	var p1r = readCookie('P1');
	var p2r = readCookie('P2');
	pd_me.p1 = (p1r + '|||||||||||').split('|');
	pd_me.zip = ((p2r.length > 8) && (p2r.substring(0, 4) == 'pi6='))
		? p2r.substring(4, 9) : '';

	// Derived: nw true for Newsweek pages
	pd_me.nw = location.href.indexOf('/site/newsweek') > 0;

	// Derived: su is site suffix
	pd_me.su = (pd_me.nw) ? '/site/newsweek' : '';

	// Derived: isF true for Front pages
	pd_me.isF = (pd_me.dt == 'Front');

	// Derived: isS true for Story/Tools/Handbuilt pages
	pd_me.isS = ((dt == 'Story') || (dt == 'ToolsHandbuilt'));

	// Forward: isRp is true for Related Photos pages
	pd_me.isRp = false;

	// Other page initialization for html40 device
	if (dv == 'html40')
	{
		// Initialize list of tabs for Most Popular boxes
		pop_tabBoxes = new Array();

		// Add OnLoad hook for next story box
		pd_me.onlNext = window.onload;
		window.onload = pd_onl;
	}

	// Add stories to IPN / Recommended Stories history
	if (pd_me.isS)
		add_history(pd_me.id, pd_me.sn);
		
	// Specify a default Omniture account so we can detect when there's no tracking
	s_account = '';

	if(location.href.indexOf('from=rss') > -1)  SetCookie("FROMRSS","true");

	//Check for MSN Referrer, and set cookie.
	var ref = document.referrer;
	if(ref.indexOf('msn.com') > -1){
		if(ref.indexOf('msnbc') < 0){
			SetCookie("FROMMSN","true","session");                              
			//document.cookie = "FROMMSN=true";
		}
	}
	
	// add document onclick event to capture omniture data
	if (pd_me.olt)
	{
        if (document.addEventListener)    //Firefox model
            document.addEventListener('click', linkTrackHandler, false);
        else if (document.attachEvent)    //IE model
            document.attachEvent('onclick', linkTrackHandler);
    }

	if(snm == "MSNBC")
		BrowserDetect.init();
		
	//nbs sports site, used for ad load record
	if(pd_me.ss=='' && pd_me.dt=='Cover') 
	{pd_me.nss="nbcsports_home";pd_me.nssect="home";pd_me.nssub="home";}
	else if(pd_me.ss=='')
	{pd_me.nss="nbcsports";pd_me.nssect="";pd_me.nssub="";}
	else
	{
		pd_me.nss="nbcsports_"+pd_me.ss;pd_me.nssect=pd_me.ss;pd_me.nssub=pd_me.sss;
		if(pd_me.sss!='') pd_me.nss=pd_me.nss+"_"+pd_me.sss;
		if(pd_me.ssss!='') pd_me.nss=pd_me.nss+"_"+pd_me.ssss;
		if(pd_me.sssss!='') pd_me.nss=pd_me.nss+"_"+pd_me.sssss;	
		if(pd_me.sss=='' && pd_me.isF) {pd_me.nssub="home";pd_me.nss=pd_me.nss+"_home";}
	}
	pd_me.nsa=readCookie('STID');//nbc sports station id
	pd_me.nsl=(pd_me.nsa==''?'N':'Y');//nbc sports localized
}	


/// <summary>
/// Called at the top of Related Photos pages to set up parameters for
/// Omniture.
/// </summary>
/// <param name="rsId">Document ID from related story</param>
/// <param name="rsH">Headline from related story</param>
/// <param name="rsS">Section from related story</param>
/// <param name="rsSs">Subsection from related story</param>
/// <param name="rpId">Document ID from related photo</param>
/// <param name="phn">Photo number</param>
/// <param name="phc">Photo count</param>
/// <remarks>
/// The pd_top function must be called before this function.
/// The call to this function is inserted by BodyTop in
/// SectionDescription.xsl when a Related Photos component exists.
/// </remarks>
function pd_rp(rsId, rsH, rsS, rsSs, rpId, phn, phc)
{
	// Extend pd_me with values passed in
	pd_me.rsId = rsId;
	pd_me.rsH = rsH;
	pd_me.rsS = rsS;
	pd_me.rsSs = rsSs;
	pd_me.rpId = rpId;
	pd_me.phn = phn;
	pd_me.phc = phc;

	// Set related photos flag
	pd_me.isRp = true;
}


/// <summary>
/// Called at the top of each page to set up parameters for Omniture.
/// </summary>
/// <param name="a">Account, usually 'msnbcdev' or 'msnbcom'</param>
/// <param name="s">Sampling rate, usually 100</param>
/// <remarks>
/// The pd_top function must be called before this function.
/// The call to this function is usually inserted by BodyTop in
/// SectionDescription.xsl. May also be called from non-Workbench pages.
/// </remarks>
function pd_om(a, s)
{
	// Set up base Omniture values
	s_account = a;
	s_visitorSampling = s;
	s_pageName = '';
	s_campaign = '';
	s_zip = pd_me.zip;

	// Set up basic properties
	s_prop3 = pd_nou(pd_me.b);
	s_prop4 = pd_nou(pd_me.s);
	s_prop4_orig = pd_nou(pd_me.s);
	s_prop5 = pd_nou(pd_me.ss);
	s_prop5_orig = pd_nou(pd_me.ss);
	s_prop6 = pd_nou(pd_me.sss);
	s_prop6_orig = pd_nou(pd_me.sss);
	s_prop7 = pd_me.l;
	
	//CNBC Omniture Settings
	if (s_account == "CNBCOmnitureAccount")
	{
		s_prop8 = "cnbc";
		s_prop9 = "cnbc.com";
		s_prop10 = pd_nou((pd_me.dt == 'Cagle') ? pd_me.dt : pd_me.s); //For Cagle, we want channel to be doctype ('Cagle') instead of section name
		s_channel = "free:CNBC.com";
	}
	else
	{
		s_prop8 = (pd_me.p1[0] != '') ? 'Y' : 'N';
		s_prop9 = pd_me.zip;
		s_prop10 = readCookie('CP');
		s_channel = pd_nou((pd_me.dt == 'Cagle') ? pd_me.dt : pd_me.s); //For Cagle, we want channel to be doctype ('Cagle') instead of section name
	}
	
	s_prop11 = pd_me.p1[6];
	s_prop12 = pd_me.p1[2];
	s_prop13 = pd_me.p1[5];
	s_prop14 = pd_me.p1[11];
	s_prop15 = pd_me.id;
	s_prop16 = pd_me.dt;
	s_prop16_orig = pd_me.dt;
	s_prop19 = pd_me.af;
	s_prop26 = pd_me.sc;
	var tOREF = readCookie("OREF");
	if(pd_me.h != 'Page not found') {s_prop30 = tOREF;}
	document.cookie="OREF="+tOREF+";path=/;expires="+new Date(1900, 1, 1).toGMTString();
	s_prop27 = readCookie('lt');
	s_prop28=pd_bet(location.href, 'dst=', '&', 'true');
	s_prop31=pd_bet(location.href, 'ocid=', '&', 'true');
	s_prop35 = pd_me.pw;
	s_prop46 = pd_me.tvc;
	
	if(pd_me.site == "NBCSPORTS")
	{
		s_prop13 = readCookie('STID');
		s_prop8 = (s_prop13 != '') ? 'Y' : 'N';
	}
	
    // clear cookie
    var date = new Date();
    date.setTime(date.getTime() - 120000);
    SetCookie('lt', '', date.toGMTString());
	
	
	// Get flyout user setting
	var nm = readCookie("NM");
	if (nm.length == 0)
	{
		s_prop39 = pd_me.nd == '1' ? "ON" : "OFF";
	}
	else
	{
	    switch (nm)
	    {
	        case '1':
	            s_prop39 = 'ON';
	            break;
	        case '0':
	            s_prop39 = 'OFF';
	            break;
	        case '1|0':
	            s_prop39 = 'ON|OFF';
	            break;
	        case '0|1':
	            s_prop39 = 'OFF|ON';
	            break;
	        default:
	            break;
	    }
	}
	
	// Populate evar39 if FROMMSN = true in the cookie
	var msnRefer = readCookie("FROMMSN");
	if (msnRefer == "true"){
		s_eVar39 = "msn referrer";
	}

	// Get search terms from referrer
	var ref = document.referrer, st = '';
	if ((ref.indexOf('http://search.msn.com/') == 0) &&
		(ref.indexOf('id=3053419') > 0))
	{
		if (ref.indexOf('search=MSNBC') > 0)
		{
			st = 'MSNMSNBC|' + pd_une(pd_bet(ref, '&q=', '+site%3A'));
		}
		else
		{
			st = 'MSN|' + pd_une(pd_bet(ref, '&q=', '&'));
		}
	}
	else if (ref.indexOf(location.host +
		'/Apps/Search/ArchiveResults.aspx?id=3053419') > 0)
	{
		st = 'MSNBC|' + pd_bet(ref, '&qt=', '');
	}
	else if(ref.indexOf(location.host +
		'/?search') > 0)
	{
		st = 'MSNBC|' + pd_bet(ref, '&q=', '');
		st = (st.indexOf('&') > 0) ? st.substring(0, st.indexOf('&')) : '';
	}
	if (st != '')
		s_prop17 = pd_nou(st);

	// Get hour property from updated time
	if (pd_me.t.length > 2)
		s_prop18 = pd_me.t.substring(0,2);

	// Get from properties/events from query string
	var f1 = pd_bet(location.href, '/from/', '/');
	if (f1 != '')
	{
		var f2 = pd_me.id + '|from|' + f1.replace('.', '|');

		s_prop20 = f2;
		s_eVar1 = f2;

		switch (f1.split('.')[0])
		{
		case 'RS':
			// Recommended stories (IPN)
			s_prop21 = f2;
			//s_eVar2 = f2;
			break;

		case 'RL':
			// Related stories (Relevance)
			s_prop22 = f2;
			//s_eVar3 = f2;
			break;

		case 'RSS':
			// RSS
			s_prop23 = f2;
			//s_eVar4 = f2;
			break;

		case 'ET':
			// Email This
			s_prop24 = f2;
			//s_eVar5 = f2;
			break;
			
		case 'radio':
			// RSS
			s_prop33 = f2;
			//s_eVar4 = f2;
			break;
		}
	}

	// Adjust doc type to page type for Omniture purposes
	var pt = pd_me.dt;
	if (pd_me.isRp)
		pt = (pd_me.l == 'Photo-L') ? pd_me.l : 'Photo-R';

	// Implement doctype-specific business rules for pageName, etc.
	switch(pt)
	{
	case 'Error':
		// Error (404) page tracking
		s_pageType = "errorPage";
		break;

	case 'Photo-R':
	case 'Photo-L':
		// Related Photos
		s_pageName =
			pt +
			'|' + pd_nou(pd_me.rsS.substring(0,10)) +
			'|' + pd_nou(pd_me.rsSs.substring(0,10)) +
			'|' + pd_me.rsId +
			'|' + pd_nou(pd_me.rsH.substring(0,50));
			s_prop16=pt;
			s_prop35=pd_me.phn + '|' + pd_me.phc;
		break;
	// Recipe doc page
	case 'Recipe':	
		s_pageName = pd_nou(pd_me.s.substring(0,10)) +
			'|' + pd_nou(pd_me.ss.substring(0,10)) +
			'|' + pd_me.id +
			'|' + 'Recipe ' + pd_nou(pd_me.h.substring(0,50));;
		break;
	case 'Slideshow':	
		if (parseInt(pd_me.pn) > 0)
			pn = 'p' + pd_me.pn;
		s_pageName =
			pd_me.dt +
			'|' + pd_nou(pd_me.s.substring(0,10)) +
			'|' + pd_nou(pd_me.ss.substring(0,10)) +
			'|' + pd_me.id +
			((pd_me.id == '8903108' )? ('|' + pd_une(pd_bet(location.href, 'qt=', '&', 'true')).replace(/\|/g, ' ')): '') +
			'|' + pd_nou(pd_me.h.substring(0,50));
			s_prop35=pn + '|' + pd_me.pc;
		break;
	case 'Fun':
	     s_channel = 'Fun';
	     var sPage = '';
	     var FunP = new RegExp("sFile=(\\D*)(\\d*)");
	     var nset = {"ftr":"Trivia","fcx":"Crossword","uj":"Jigsaw","sudoc":"Sudoku","co":"Checkout","nt":"Nile Tiles","ps":"Poker Solitaire"};
	     var result = FunP.exec(location.href);
	     if (result !=null)
	     {
	        s_prop15 = result[1] + result[2];
	        if (nset[result[1]] != null)
	        {s_prop5 = nset[result[1]];
	         sPage = ((s_prop5 != 'Crossword')?(s_prop5):'DailyCrossword');}
	        else 
	        {s_prop5 = 'Comics';sPage = 'Entertainment ' + s_prop15;}	                  
	     }
	     else {s_prop15 = ''; sPage = 'Comics,Sudoku,Puzzle front';}
	      s_prop35 = s_prop15 +'|'+ sPage;
	      s_pageName = pd_me.dt + '|' + s_prop4 + '|' + s_prop5;      
	     break;
	case 'SportsTools':
	    s_channel = 'SportsTools';
	    s_prop4 = 'Sports';
	    s_prop5 = 'Scores/Sched';
	    var url = location.href;
	    var SptRet = /([^/]*)\.(?:asp\?|html|asp)(?:frames=\w*)?/i.exec(url);
	    if(SptRet != null)
	    {
	    var sport = /[&|?]sport=(\w*)/i.exec(url);
	    var cat = /&cat=(\w*)/i.exec(url);
	    var team = /&team=(\w*)/i.exec(url);
	    var player = /&player=(\w*)/i.exec(url);
	    var rank = /&rank=(\w*)/i.exec(url);
	    var format = /&format=(\w*)/i.exec(url);
	    s_prop35 = SptRet[1] + '|'+ ((sport == null)?'':sport[1]) + '|'+ ((cat == null)?'':cat[1]) + '|'+ ((team == null)?'':team[1]) +'|' + ((player == null)?'':player[1]) + '|'+ ((rank == null)?'':rank[1]) + ((format == null)?'':format[1]);
	    }
	    s_pageName = pd_me.dt + '|' + s_prop4 + '|' + s_prop5;
	     break;    
	default:
		// Story, Tools/Handbuilt, Front, and Cagle tracking
		var pn = '';
		if (parseInt(pd_me.pn) > 0)
			pn = 'p' + pd_me.pn;
		else
			if (pd_me.dt == 'Cagle') pn = pd_me.pn; //For Cagle, set pn to page name if page name couldn't be parsed as int.

		s_pageName =
			((pd_me.dt == 'ToolsHandbuilt') ? 'HandTool' : pd_me.dt) +
			'|' + pd_nou(pd_me.s.substring(0,10)) +
			'|' + pd_nou(pd_me.ss.substring(0,10)) +
			'|' + pd_me.id +
			((pd_me.id == '8903108' )? ('|' + pd_une(pd_bet(location.href, 'qt=', '&', 'true')).replace(/\|/g, ' ')): '') +
			'|' + pd_nou(pd_me.h.substring(0,50)) +
			'|' + pn;
		break;
	}
	// Check if weird case (all underscores or start with 5 underscores) happens
	var reg = /\|((.*_____.*)|(_+))\|/;
	if(reg.test(s_pageName))
		s_pageName = pt + "|Other";
}

/// <summary>
/// Consolidated window.onload method for all of Std.js
/// </summary>
/// <remarks>
/// INTERNAL: event hooked by pd_top.
/// Currently only called for html40 device.
/// There were three different onload functions across Std.js which
/// were hooked and chained differently; this caused PS 5244 on
/// consolidation because of the evil of multiple Std.js references
/// from a single page.
/// </remarks>
function pd_onl()
{
	// Former nxtStoryLoad

	// Firefox float issue workaround for byline components
	if (pd_me.isS)
		moveByline();

	// Former /id/7181974

	// Show tabs in any Most Popular boxes
	pop_ShowTabs();

    //Check both boxes available
    boxMove("bba","bb1","bb2");
    boxMove("bbb","bb3","bb4");
	// Former nmjs07.js
	if (nm_nIE)
		nm_done();

	// Chain to previous event handler
	if (pd_me.onlNext != null)
		pd_me.onlNext();		
	
	//hide frames with no ads in it, and change the sponsor ad title if there is any, by v-starli@microsoft.com 2007/2/15
	HideAdFramesAndChangeTitles();
	
    renderTimestampIcon();
}
/// <summary>
/// Function to show tow button boxes if all data available
/// </summary>
/// <param name="p">the id of parent DIV of box</param>
/// <param name="c1">the id of left box DIV</param>
/// <param name="c2">the id of right box DIV</param>
function boxMove(p,c1,c2)
{
    var b1=document.getElementById(c1);
    var b2=document.getElementById(c2);
    if(b1!=null & b2!=null)
    {   
        var re=/<table/i;           
        if(b1.innerHTML.search(re)!=-1 && b2.innerHTML.search(re)!=-1) 
        {
            document.getElementById(p).style.display="inline";
         }
     }
 }   

/// <summary>
/// Helper function that returns the part of string s after string a and
/// before string b.
/// </summary>
/// <param name="s">String to look in</param>
/// <param name="a">String that precedes our target</param>
/// <param name="b">String that follows our target</param>
/// <returns>String in s between a and b</returns>
/// <remarks>
/// INTERNAL: called only from within Std.js.
/// </remarks>
function pd_bet(s,b,a,r)
{
	var i = s.indexOf(b);
	if (i < 0)
		return '';
	s = s.substring(i + b.length, s.length);
	if (a == '')
		return s;
	i = s.indexOf(a);
	if(r == 'true')
	{
		return (i > 0) ? s.substring(0,i) : s;
	}
	else
	{
		return (i > 0) ? s.substring(0, i) : '';
	}
}

/// <summary>
/// Helper function that converts its argument into a string, handling
/// undefined values.
/// </summary>
/// <param name="o">Object to convert</param>
/// <returns>Value of object as a string, or '' if undefined</returns>
/// <remarks>
/// INTERNAL: called only from within Std.js.
/// </remarks>
function pd_str(o)
{
	return (typeof(o) == 'undefined') ? '' : '' + o;
}


/// <summary>
/// Helper function that unescapes strings from URLs
/// </summary>
/// <param name="s">String to unescape</param>
/// <returns>String unescaped for normal use</returns>
/// <remarks>
/// INTERNAL: called only from within Std.js.
/// </remarks>
function pd_une(s)
{
	return unescape(s.replace(/\+/g,' '));
}


/// <summary>
/// Helper function that escapes strings
/// </summary>
/// <param name="s">String to escape</param>
/// <returns>String escaped for URL use</returns>
/// <remarks>
/// INTERNAL: called only from within Std.js.
/// </remarks>
function pd_esc(s)
{
	return escape(pd_nou(s));
}


/// <summary>
/// light version of pd_nou, won't strip character with accent 
/// </summary>
/// <param name="s">String to fix up</param>
/// <returns>String fixed up with no Unicode characters</returns>
/// <remarks>
/// INTERNAL: called only from within Std.js.
/// </remarks>
function pd_noul(s)
{
	return s.replace(/\u2013/g,'-').replace(/\u2014/g,'-').replace(/\u2018/g,'\'').replace(/\u2019/g,'\'').replace(/\u201C/g,'"').replace(/\u201D/g,'"');
}

/// <summary>
/// Helper function that removes Unicode chars from strings
/// </summary>
/// <param name="s">String to fix up</param>
/// <returns>String fixed up with no Unicode characters</returns>
/// <remarks>
/// INTERNAL: called only from within Std.js.
/// </remarks>
function pd_nou(s)
{
	return pd_noul(s).replace(/[^\x20-\x7F]/g,'_');
}


/// <summary>
/// Hyperlink tracking function
/// </summary>
/// <param name="area">Area that Link is located in</param>
/// <param name="module">Colorbox or Image that link is in.</param>
/// <param name="linkType">e for exit, o for custom, d for download (not used)</param>
/// <param name="linkPos">Position of Link in link list, and total # of links (i.e. 1|5)</param>
/// <param name="textVal">value of text, if image then it will be the alt text</param>
/// <param name="obj">Link being click on</param>
/// <returns>submits the link values to omniture</returns>
/// <remarks></remarks>
function pd_onc(area, module, linkType, linkPos, textVal, obj){
	// Only do click tracking if Omniture code exists on this page
	if (typeof(s_account) != "undefined" && s_account != '')
	{	
	s_prop48 = area;
	s_prop49 = s_channel;
	s_prop50 = module;
	s_linkType = linkType;
	s_linkName = area+'|'+s_channel+'|'+module+'|'+linkPos+'|'+textVal;
	s_lnk = s_co(obj);
	if (area == 'Related Stories')
	{
		s_prop20 = pd_me.id+ '|from|RL|' +linkPos;
		s_prop22 = s_prop20;		
	}
	if (area == 'Recommended Stories')
	{
		s_prop20 = pd_me.id+ '|from|RS|' +linkPos;
		s_prop21 = s_prop20;		
	}
	s_gs(s_account);
}
}

//////////////////////////////////////////////////////////////////////////////
//
// Original /id/7181974
//


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function updHead(){logoImg();newRadioBtns();}


/// <summary>
///
/// </summary>
/// <param name="bg"></param>
/// <returns></returns>
/// <remarks>
/// Modified and added parameter bg for forward/backward compatibility with siteframe architecture. 
/// Parameter bg has a value of "d" to get the right image (light image on dark background) from msn.  
/// Previous image did not require a parameter. 
/// </remarks>
function logoImg(bg)
{
    if (bg==null)
    {
        //supports old version of msn header
        document.write("<img id=\"logo\" vspace=\"5\" width=\"66\" height=\"34\" src=\"http://sc.msn.com/global/c/lgpos/"+getPartnerId()+"_pos.gif\" alt=\"go to  MSN.com\" title=\"go to MSN.com\"/>");
    }else{
        //supports new version of msn header
        document.write("<img id=\"logo\" vspace=\"5\" width=\"118\" height=\"35\" src=\"http://stc.msn.com/br/gbl/lg/1/" + bg + "/"+getPartnerId()+".gif\" alt=\"go to  MSN.com\" title=\"go to MSN.com\"/>");    
    }
}

/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function getPartnerId(){var s=document.cookie + ";";var i=s.indexOf("mh=");var p="msft";if(i>=0)p=s.substring(i+3,s.indexOf(";",i));if(null==p)p="msft";return p.substring(0,4);}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function newRadioBtns(){var el=document.getElementById("search");if (el!=null) el=el.lastChild;if (el!=null){for(var i=0; i < el.childNodes.length; i++) {var ch = el.childNodes[i];if (ch.type=='radio') ch.onclick= chngBtn;}}}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function chngBtn()
{
	var el1 = document.getElementById("q");
	var el2 = document.getElementById("search");
	var el3;
	if (el2!=null)
	{
		el3 = el2["FORM"];
		if (el3!=null)
		{
			if (el1!=null)
			{
				switch (this.value)
				{
					case "Web":
						el1.name = "q";
						el2.action = "http://g.msn.com/0nwenus0/AE/16?SU=http://" + siteDomainList[pd_me.site];
						el3.value="AE";
						break;
					default :
						el1.name = "q";
						el2.action = "http://g.msn.com/0nwenus0/AE/16?SU=http://" + siteDomainList[pd_me.site];
						el3.value=pd_me.site;
				}
			}
		}
	}
}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function doSearch()
{
	var el = document.getElementById("search");
	if (el!=null)
		el=el.lastChild;
	if (el!=null)
	{
		for(var i=0; i < el.childNodes.length; i++)
		{
			var ch = el.childNodes[i];
			if (ch.type=='radio')
				if (ch.value == "MSNBC")
					if (ch.checked)
						pop_getEl("q").value += " site:" + siteDomainList[pd_me.site];
		}
	}
}

//
// Most Popular
//


//#newline
var pop_tabBoxes,	// List of Most Popular boxes which need DHTML tabs
	pop_el,			// Temporary var to hold affected tab across timeout
	pop_shadow = "url(http://msnbcmedia.msn.com/i/msnbc/Test-Dev/sowmith/shadow.png)",
	pop_clear = "url(/images/cleardot.gif)",
	pop_filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://msnbcmedia.msn.com/i/msnbc/Test-Dev/sowmith/shadow.png', sizingMethod='scale')";


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function pop_setupTab(o){var t=pop_getEl(o.id); if (t.evented!=null) return;t.evented = "true";if (pop_getEl(o.id + "_img") != null)return;if (document.all){t.style.backgroundImage = pop_clear;t.style.filter=pop_filter;}else{t.style.backgroundImage = pop_shadow;}if (document.all) t.style.cursor="hand";else t.style.cursor="pointer";pop_addClickEvent(t);return true;}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function pop_coords(o){var v={"x":0,"y":0};while(o){v.x+=o.offsetLeft;v.y+=o.offsetTop;o=o.offsetParent}return v}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function pop_getEl(o){return document.getElementById(o);}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function pop_displayTab(o, u){var i=1;el=pop_getEl(o + "_tab" + i);while (el!=null){if (pop_setupTab(el)) pop_addClickEvent(el);if (document.all) el.style.cursor="hand"; else el.style.cursor="pointer"; if (i==u){el.style.fontWeight = 'bold';pop_getEl(el.id + "_bt").style.display = "none";pop_getEl(el.id).style.backgroundImage = "none";if (document.all) pop_getEl(el.id).style.filter ="";pop_getEl(el.id + "_c").style.display = "";var cu=pop_getEl(el.id + "_cu");if (cu!=null) cu.style.display = "";}else{el.style.fontWeight = '';pop_getEl(el.id + "_bt").style.display = "";pop_getEl(el.id).style.backgroundImage = pop_shadow;var ua = window.navigator.userAgent;var msie = ua.indexOf("MSIE");if (msie>0){if (parseInt (ua.substring (msie+5, ua.indexOf (".", msie ))) >= 6) pop_getEl(el.id).style.backgroundImage = pop_clear; else pop_getEl(el.id).style.backgroundImage = pop_shadow;pop_getEl(el.id).style.filter=pop_filter;}else{pop_getEl(el.id).style.backgroundImage = pop_shadow;}pop_getEl(el.id + "_c").style.display = "none";var cu=pop_getEl(el.id + "_cu");if (cu!=null) cu.style.display = "none";}el = pop_getEl(o + "_tab" + (++i));}}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function pop_addClickEvent(o){var ev = "click";if (o.addEventListener){ o.addEventListener(ev, pop_tabClick, false);}else if (o.attachEvent){o.attachEvent("on"+ev, pop_tabClick)}}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function pop_tabClick(o){var newo;if (o.target) newo=o.target;else newo=window.event.srcElement;if (newo.tagName==undefined) newo = newo.parentElement;if(newo.tagName=="TD");newo = newo.firstChild;o=newo;var re1 = /(.*_tab\d*)/g;var re2 = /.*_tab(\d+)/g;var re3 = /(.*)_tab/g;var tabid = o.id.match(re1);var b = re2.exec(tabid);var c=0;while (b==null){b=re2.exec(tabid);c++;if (c==100) return;}c=0;var a = re3.exec(tabid);while (a==null){a = re3.exec(tabid);c++;if (c==100) return;}pop_displayTab(a[1], b[1]);pop_el=pop_getEl(a[1] + "_tab" + b[1]);setTimeout("pop_rerender()",10);}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function pop_rerender(){pop_getEl(pop_el.id + "_c").style.height = 1000;pop_getEl(pop_el.id + "_c").style.height = "auto";}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function pop_pushTabBox(o){pop_tabBoxes.push(o);}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function pop_ShowTabs()
{
    if(pop_tabBoxes != null && pop_tabBoxes != undefined)
    {
        for (var o in pop_tabBoxes)
        {
            pop_displayTab(pop_tabBoxes[o], 1);
        }
    }
}


/// <summary>
///
/// </summary>
/// <param name="id">document id, use pd_me.id if it is null</param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function trackit(id){var i=new Image(); var did=id; if(did == null) did=pd_me.id; i.src='/trackit.aspx?id='+did+'&eventType=100';}


//////////////////////////////////////////////////////////////////////////////
//
// Original BUTTONS.JS
//


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function findObj(n,d){var p,i,x; if(!d) d=document;if((p=n.indexOf("?"))>0&&parent.frames.length){d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}if(!(x=d[n])&&d.all) x=d.all[n];for(i=0;!x&&i<d.forms.length;i++){x=d.forms[i][n];}for(i=0;!x&&d.layers&&i<d.layers.length;i++){x=MM_findObj(n,d.layers[i].document);}if(!x && d.getElementById){x=d.getElementById(n);}return x;}


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function swapImage(id,src){var x;if(!id){return;}if((x=findObj(id))==null){return;}x.src = src;}


//////////////////////////////////////////////////////////////////////////////
//
// Next Story - originally in NextStory.xsl
//


/// <summary>
///
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function nextStory(sStoryArray){
	if(sStoryArray.charAt(sStoryArray.length-1)=="|"){
		sStoryArray=sStoryArray.substr(0,sStoryArray.length-1);
	}
	var aStoryArray=sStoryArray.split("|");
	if(pd_me != null && pd_me != undefined)
	{
	if(pd_me.id!=''&&sStoryArray.indexOf(pd_me.id)>-1){
		for(i=0;i<aStoryArray.length;i++){
			var aCurStory=aStoryArray[i].split("^");
			if(aCurStory[0].indexOf("\/" + pd_me.id + "\/") > -1){
				var storyHref=aCurStory[0];
				var storyHL=aCurStory[1];
				curDom=document.getElementById("nxtStry"+(i+1));
				curDomIH=curDom.innerHTML;
				curDom.className='nxtStryArrow';
				if(i < aStoryArray.length-1){
					var nxtStory=aStoryArray[i+1].split("^");
					var nxtStoryHref=nxtStory[0];
					var nxtStoryHL=nxtStory[1];
					document.getElementById("nextText").innerHTML=nxtStoryHL;
					var nxtButton=document.getElementById("StoryNextButton");
					var hrRegEx = /href="([\w,\/]+)"/;
					if (hrRegEx.test(nxtButton.innerHTML)){
						tmpHref = nxtButton.innerHTML.match(hrRegEx);
						nxtButton.innerHTML=nxtButton.innerHTML.replace(tmpHref[1], nxtStoryHref);
					}
				}
			}

		}
	}
}
}


//////////////////////////////////////////////////////////////////////////////
//
// News Menu - originally in NMJS07.TPL.JS
//


// Width of scrollbars on Netscape 6
//#const
var dxNetScrFudge=14;
// #const
var dyNetScrFudge=15;

// Overlap of menus
//#const
var dxMenuOverlap=2;
//#const
var dyBorder=1;

// Timeout lengths
//#const
var cmsecDismiss=600;
//#const
var cmsecNew=250;

//
// Exposed Functions
//
var nmDataURL = {"MSNBC":["http://msnbcmedia.msn.com/i/nm/nm.js","http://www.msnbc.msn.com/id/3027113/displaymode/1038/"],
				 "NBCSPORTS":["http://msnbcmedia.msn.com/i/nm/sm.js","http://nbcsports.msnbc.com/id/3032112/displaymode/1038/"]};
/// <summary>
/// Sets up News Menu resources
/// </summary>
/// <param name="sBas">Base URL for links</param>
/// <param name="sOTyp">News menu Output Type</param>
/// <remarks>
/// modified by Tiff Fehr 12/18/07 to include changes previously in CDATA ID 21588166, allowing newsmenu flyouts for all Gecko browsers.
/// original override and corrections by Colin Hicks.
/// </remarks>
function nm_init(sBas, sOTyp) {
	
	// Moved var inits here, away from definitions, since std.js can be requested multiple times
	// TODO: Can we remove/reduce this duplication?
	nm_bDis = 0,nm_nIE = 0,nm_nNN = 0,nm_aDlo = new Array,nm_cDlo = 0,nm_iDlo = 0,nm_raw = new Array,nm_as = new Array,nm_exp = new Array,nm_nD = 0,nm_tDis = 0,nm_tNew = 0,nm_nNew = 0,nm_aDef = 0,nm_sSuf = '',nm_bFla = false;
    
	// Remember base URL
	nm_sBas = sBas;
	
	// Figure out browser version
    var sUa = window.navigator.userAgent,icIE = sUa.indexOf('MSIE'),icNN = sUa.indexOf('Gecko');
    if (icIE != -1) 
		nm_nIE = parseFloat(sUa.slice(icIE + 5));
    else if (icNN != -1) 
		nm_nNN = 6;
    nm_bWin = sUa.indexOf('Win') != -1;
    nm_sCoo = ';' + document.cookie + ';';
    
	// Does this browser support the DHTML News Menu?
	nm_bNM = ((nm_bWin && nm_nIE >= 5) || (nm_nNN >= 6));
    
	// Does the flyout menu supported by this browser and outtype?
	nm_bFM = ((nm_bWin && nm_nIE >= 5.5) || icNN || (sUa.indexOf('KHTML') != -1)) && (sOTyp != 'static');
    
	// Do we have a menu?
	if (nm_bNM) 
	{
        // Hook up events on buttons
		a = document.getElementsByName("nmb");
        for (var i = 0; i < a.length; i++) 
        {
	    if(a[i].className == 'nmIK' || a[i].className == 'nmIKD')
	    {
	        a[i].nwAds = true;
	    }
	    a[i].onmouseover = nm_bi;
            a[i].onmouseout = nm_bo;
            a[i].onclick = nm_bc;
            a[i].firstChild.onclick = nm_bc;
        }
    }
    if (nm_bFM) 
	{
        // Emit script for data
		// default url is set for dynamic
		var dataUrl = nmDataURL[pd_me.site][1];
        switch (nm_fSet) {
            case "off":
            	break;
            case "dynamic":
	            nm_data('nm_nm', dataUrl);
	            nm_local();
	            break;
            case "useropt":
	            //sets static url and fall into dynamic_useropt case
			    dataUrl = nmDataURL[pd_me.site][0];
            case "dynamic_useropt":
	            var nm = readCookie('NM');
	            if (nm.length > 0) 
				{
	                if (nm == "1|0") SetCookie('NM', '0');
	                else if (nm == "0|1") SetCookie('NM', 1);
	            }
	            if (nm_opt(nm_tDef)) 
				{
	                nm_data('nm_nm', dataUrl);
	                nm_local();
	            }
	            break;
            default:
	            nm_data('nm_nm', nmDataURL[pd_me.site][0]);
	            nm_local();
	            break;
        }
    }
}


/// <summary>
/// Sets up deferred load of News Menu data feed
/// </summary>
/// <param name="sId">ID to use for script element</param>
/// <param name="sU">URL to script data</param>
/// <remarks>
///
/// </remarks>
function nm_data(sId,sU)
{
	// Create a reference to the specified data file
	if(nm_nIE)
	{
		// For Internet Explorer, Remember the information and create the empty script tag
		nm_aDlo[nm_cDlo++]=sId;
		nm_aDlo[nm_cDlo++]=sU;
		document.write('<sc'+'ript language="javascript" charset="utf-8" id="'+sId+'"></scr'+'ipt>');
	}
	else
	{
		// For Netscape, we can't defer the script, so we'll take the hit now
		document.write('<scrip'+'t language="javascript" charset="utf-8" id="'+sId+'" src="'+sU+'"></s'+'cript>');
	}
}


/// <summary>
/// Adds data for local affiliate to build
/// </summary>
/// <remarks>
///
/// </remarks>
function nm_local()
{
	var s=nm_sCoo;
	var i=s.indexOf('; P1=');
	if(i<0)
		return;
	s=s.slice(i+5);
	s=s.slice(0,s.indexOf('; '));
	if(s.length>3&&s.slice(0,3)=='01%')
		s=unescape(s);
	var a=s.split('|');
	if(a.length<6)
		return;
	if(a[5]=='')
		return;
	//todo: the databox url should be passed as a parameter
	// this url could be resolved by rendering if a proper display
	// mode is created. No need to to this in a databox.
	// This 'fix' makes the assumption that the databox server
	// will be under /databox/.
	var dbBas = nm_sBas.replace("/id", "/databox");
	//var dbBas = "http://databox.msnbc.msn.com/";
	var u=dbBas+"data.aspx?dbid=3228674&s=|||||"+a[5];
	nm_data('nm_nml',u);
}


/// <summary>
/// Says that previous load of page/data is done, move to next data file
/// </summary>
/// <remarks>
///
/// </remarks>
function nm_done()
{
    //if(nm_exp == null) nm_exp = new Array;
	if(nm_raw)
	{
		// Load newsmenu data
		for(var i = 0; i < nm_raw.length; i+=2)
		{
			if(nm_as[nm_raw[i]] != null)
			{
				nm_exp[nm_raw[i]] = nm_raw[i];				
				if(nm_as[nm_raw[i]].length < nm_raw[i+1].length)
				    nm_as[nm_raw[i]] = nm_raw[i+1];
			}
			else
				nm_as[nm_raw[i]] = nm_raw[i+1];
		}
		nm_raw = null;
		
		// Assign arrows for flyout menu when script is loaded
		var a = document.getElementsByName("nmb");
		for(var i = 0; i < a.length; i++)
		{
			var sn = a[i].getAttribute('nm_sn');
			if (typeof(nm_as[sn]) != "undefined" && nm_as[sn] != "")
			{
				a[i].className = a[i].className.replace("I", "A") + " " + a[i].className;
			}
		}
		
		// Show flyout toggle button
		if (nm_fSet == "useropt" || nm_fSet == "dynamic_useropt") nm_st();
	}
	
	if(nm_iDlo<nm_cDlo)
	{
		// Get the script tag and set its source
		var o=document.getElementById(nm_aDlo[nm_iDlo++]);
		o.src=nm_aDlo[nm_iDlo++];
	}
	
	// Event chain in window.onload event
	if (nm_eNext != null) nm_eNext();
}


//
// Internal Functions
//


//
// News Menu globals
//
//#newline
var nm_bNM,			// Is DHTML News Menu supported by this browser at all?
	nm_bFM,			// Is Flyout menu opened?
	nm_bDis,		// Set to true to disable popups
	nm_nIE,			// IE Browser version
	nm_nNN,			// Netscape browser version
	nm_bWin,		// Is this a Windows machine?
	nm_aDlo,		// Data for script tag deferred loads
	nm_cDlo,		// Count into above when adding
	nm_iDlo,		// Index into above when reading
	nm_raw,			// Raw data of news menu
	nm_as,			// Array of data for each section
	nm_nD,			// Current menu depth
	nm_sBas,		// Base URL for links
	nm_tDis,		// Dismiss timer
	nm_tNew,		// New popup protection timer
	nm_nNew,		// True if in new popup protection time
	nm_aDef,		// Collected deferred arguments
	nm_sSuf,		// Site suffix string to add to URLs
	nm_bFla,		// All Flash objects are opaque?
	nm_eNext,		// Host of event chain for newsmenu in Script source page
	nm_fSet,		// The value of setting newsMenu flyouts
	nm_tDef,		// The default value for toggle display
	nwAdOps,		// The newsweek Ads rendering HTML
	nm_Enter;


/// <summary>
/// News Menu Button mouse Click
/// </summary>
/// <param name="o">Object clicked</param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function nm_bc(o)
{
	//Process news menu click event through
	//Omniture handler
	if(o)
	{
	    Omni.LinkTrack.OnclickHandler(o); //dom
	}
	else
	{
	    Omni.LinkTrack.OnclickHandler(window.event); //ie
	}
	
	// Get initiating button
	if(o)
	{
		// Ignore right button clicks in Netscape
		if(o.which==3)
			return true;
		o=o.target;
	}
	else
		o=window.event.srcElement;

	// Force to our object
	o=nm_ne(o,'onclick');
	if(nm_sx(o.className)!='H')
		o.className+='H';

	// Handle the click
	var sU;
	if(o.firstChild.tagName=='A')
		sU=o.firstChild.getAttribute('href');
	else
		sU=o.getAttribute('href');

	if(sU!='')
	{
		// Navigate to the Url
		return nm_mc(nm_su(sU));
	}
}

/// <summary>
/// News Menu Button mouse In (over)
/// </summary>
/// <param name="o">Object clicked</param>
/// <remarks>
/// modified by Tiff Fehr 12/18/07 to include changes previously in CDATA ID 22119282, adding delay to news menu flyout behavior.
/// original override and corrections by Ben Tesch.
/// </remarks>
function nm_bi(o) {
    
	// Get initiating button
	if (o)
        o = o.target;
    else
        o = window.event.srcElement;
    
	// Force to our object
	o = nm_ne(o, 'onmouseover');
	
	//newsmenu delay
	NMfunc = function(){
   		nm_mi(o, '*' + o.getAttribute('nm_sn'), o.getAttribute('nm_suf'), 0, o.getAttribute('CM_sf'));
	};
	
	// Launch menu
	nm_Enter = window.setTimeout('NMfunc()',500);
}


/// <summary>
/// News Menu Button mouse Out
/// </summary>
/// <param name="o">Object clicked</param>
/// <remarks>
/// modified by Tiff Fehr 12/18/07 to include changes previously in CDATA ID 22119282, adding delay to news menu flyout behavior.
/// original override and corrections by Ben Tesch.
/// </remarks>
function nm_bo(o) {

	//newsmenu delay
	if (nm_Enter) 
	{
		window.clearTimeout(nm_Enter);
        nm_Enter = 0;
    }
    
	// Get initiating button
	if (o) 
	{
        o2 = o.relatedTarget;
        o = o.target;
    } 
	else 
	{
        o = window.event.srcElement;
        o2 = window.event.toElement;
    }
    
	// Force to our object; ignore if internal
	o = nm_ne(o, 'onmouseout');
    o2 = nm_ne(o2, 'onmouseout');
    if (o == o2)
        return;
    
	// Turn off active color
	nm_mo(o);
}


/// <summary>
/// News Menu Menu Click
/// </summary>
/// <param name="sU">Already-normalized URL</param>
/// <returns>false</returns>
/// <remarks>
///
/// </remarks>
function nm_mc(sU)
{
	// Dismiss menus
	nm_mx(0,0);

	// Cancel event bubbling before we go
	if(nm_nIE>0)
		window.event.cancelBubble=true;

	// Execute javascript if it's a JS link
	if(sU.slice(0,11)=='javascript:')
	{
		eval(sU.slice(11));
		return false;
	}

	sU=nm_g(sU);

	// Open a new window if the shift key is down
	if((nm_nIE>=5)&&(window.event.shiftKey))
	{
		document.selection.empty();
		window.open(sU);
		return false;
	}

	// Navigate there in the top frame
	location.href=sU;
	return false;
}


/// <summary>
/// GLink version of URL
/// </summary>
/// <param name="sU">Original URL</param>
/// <returns>URL for GLink</returns>
/// <remarks>
///
/// </remarks>
function nm_g(sU)
{
	if (window.navigator.userAgent.indexOf('MSIE') == -1) return sU;
	var gCheck=new Function("try{if (gEnabled) return true; else return false;}catch(e){return false;}");
	if (!gCheck()) return sU;
	var gNode=window.event.srcElement;
	var CM, CE=null;
	while(gNode!=null)
	{
		if(gNode.id=="nmb")
		{
			CM=gNode.getAttribute("CM")+gNode.getAttribute("CM_sf");
			CE=gNode.getAttribute("nm_sn");
			break;
		}
		else if(gNode.getAttribute("CM")!=null)
		{
			if(sU.indexOf("http:")!=-1)
				return sU;
			CM=gNode.getAttribute("CM");
			CE=gNode.getAttribute("CE");
			if(liveEnv){sU="http://" + siteDomainList[pd_me.site] +sU;}else{sU=location.protocol+"//"+location.host+sU};
			break;
		}
		gNode=gNode.parentElement;
	}

	if(CE!=null)
	{
		defaultG=defaultG.replace("com/", "com/_");
		var g_img=new Image();
		g_img.src=defaultG+sU+"&&PS="+pd_me.ps+"&SU=http%3A//" + siteDomainList[pd_me.site] + "/newsmenu/&CM="+escape(CM)+"&CE="+escape(CE);
	}
	return sU;
}


/// <summary>
/// News Menu Menu mouse In
/// </summary>
/// <param name="o">Object instantiating menu</param>
/// <param name="sU">URL / Section ID associated with object</param>
/// <param name="sS">Suffix associated with object</param>
/// <param name="nD">Depth of object</param>
/// <remarks>
/// modified by Tiff Fehr 12/18/07 to include changes previously in CDATA ID 21588166, allowing a top-aligned news menu and flyout changes for that space.
/// original override and corrections by Colin Hicks.
/// SiteDev added omniture tracking 12/18/07.
/// </remarks>
function nm_mi(o, sU, sS, nD, gS) {
    if (nm_tDis) {
        window.clearTimeout(nm_tDis);
        nm_tDis = 0;

    }
    if (nm_nNew) {
        if (nD < nm_nD) {
            nm_aDef = new Array(o, sU, sS, nD, gS);
            return;

        } else {
            window.clearTimeout(nm_tNew);
            nm_tNew = 0;
            nm_nNew = 0;

        }

    }
    var b = (sU.charAt(0) == '*') && (!nm_bDis);
    nm_mx(nD, b);
    if (b) {
        var body = document.body,
        dxCli,
        dyCli,
        dxOff,
        dyOff,
        sId = sU.slice(1);
        if (dxCli = body.clientWidth) {
            dyCli = body.clientHeight;
            dxOff = body.scrollLeft;
            dyOff = body.scrollTop;

        } else {
            dxCli = window.innerWidth - 14;
            dyCli = window.innerHeight - dyNetScrFudge;
            dxOff = window.pageXOffset;
            dyOff = window.pageYOffset;

        }
        var oX = new nm_xy(o, body),
        xPar = oX.x,
        yPar = oX.y,
        dxPar = oX.dx,
        dyPar = oX.dy;
        dxOff -= oX.xP;
        dyOff -= oX.yP;
        if ((nm_as[sId]) && ((nD > 0) || (dxCli > 2 * dxPar) && (dyCli > 4 * dyPar))) {
            var sas = nm_as[sId];
            if (nD == 0) {
                if (sas.charAt(0) != '*') sas = '+|Latest headlines|' + sas;
                sas = sas.replace(/\*/, '+|Topics|*');
                var nmC = (sas.indexOf('|Topics|') == -1) ? 1: 2;
                nm_sSuf = sS;

            } else {
                sas = sas.replace(/\*.*/, '');

            }
            var as = sas.split('|'),
            cs = as.length - 1,
            sS,
            s = new Array,
            sV,
            sW,
            sT;
            nD = nD + 1;
            nm_nD = nD;

            //init omniture link track values
            var omni_nm_pn = Omni.NewsMenu.ProjectName;
            var omni_nm_ct = '';
            var omni_nm_cn = '';

            s.push('<div id="newsSUB"><div id="nm_d' + nD + '" class="nmF nmC' + nmC + '"><div class="subbox"><ul id="nm_t' + nD + '" class="nmTF c1">');
            var ceCnt = 0,
            CM = "",
            temp;
            for (var is = 0; is < cs; is += 2) {
                sT = as[is + 1];
                if (sT.indexOf("#") == (sT.length - 1)) sT = sT.replace("#", " Front Page");
                sV = sW = nm_link(as[is], sT);
                var arrowflavor = '';
                var sn = '';

                //get the parent omniture link track data ct value
                var omni_parent_ct = o.getAttribute('ct');
                var omni_parent_cn = o.getAttribute('cn') || ''; //default value statement

				if (sW.charAt(0) == '*') {
					temp = sV.slice(1);
					if(nm_exp[temp] != null)
						continue;
                    temp = nm_as[temp].split('|');
                    if (sT == "") sT = temp[1].substr(0, temp[1].length - 1);
                    sV = nm_link(temp[0]);
                    sS = arrowflavor = 'F';
                    sn = sW.substring(1);
                    if (typeof(nm_as[sn]) == "undefined" || nm_as[sn] == "") arrowflavor = "E";
                    if (CM != 'F') ceCnt = 0;
                    CM = 'F';

                    //Omniture news menu link track, assign first subsection flyout ct value and cn value
                    //ct == component type
                    if (omni_parent_ct && omni_parent_ct == Omni.NewsMenu.Top) {
                        omni_nm_ct = Omni.NewsMenu.FirstFront;
                        omni_nm_cn = sT.substr(0, 30);
                        //cn is subsection name, limited to first 30 characters

                    }

                }
                else if (sW.charAt(0) != '+') //headline
                {
                    //Omniture new menu link track, determine parent ct value and assign headline ct value and cn value
                    if (omni_parent_ct)
                    {
                        if (omni_parent_ct == Omni.NewsMenu.Top)
                        {
                            omni_nm_ct = Omni.NewsMenu.FirstHeadline;
                            omni_nm_cn = omni_parent_cn;

                        }
                        else if (omni_parent_ct == Omni.NewsMenu.ExpandFront)
                        {
                            omni_nm_ct = Omni.NewsMenu.ExpandHeadline;
                            omni_nm_cn = omni_parent_cn;

                        }
                        else if (omni_parent_ct == Omni.NewsMenu.FirstFront)
                        {
                            omni_nm_ct = Omni.NewsMenu.SecondHeadline;
                            omni_nm_cn = omni_parent_cn;

                        }

                    }

                    sS = arrowflavor = 'E';
                    if (CM != 'S') ceCnt = 0;
                    CM = 'S';

                }
                sV = nm_su(sV);
                if (sW.charAt(0) == '+') {
                    if (sT == "Latest headlines") s.push('<li class="nmIR" onmouseout="nm_mo(this)" onmouseover="nm_mi(this,\'' + nm_se(sW) + '\',null,' + nD + ',\'' + gS + '\')">' + sT + '</li>');
                    else s.push('</ul><ul id="nm_t' + nD + '" class="nmTF c2"><li class="nmIR" onmouseout="nm_mo(this)" onmouseover="nm_mi(this,\'' + nm_se(sW) + '\',null,' + nD + ',\'' + gS + '\')">' + sT + '</li>');

                } else {
                    s.push('<li CM="NewsMenuL' + (nD + 1) + CM + gS + '" CE="' + sId + '-' + (++ceCnt) + '" class="nmI' + arrowflavor + ' nmLink" onclick="Omni.LinkTrack.OnclickHandler(event);nm_mc(\'' + nm_se(sV) + '\')" onmouseout="nm_mo(this)" onmouseover="nm_mi(this,\'' + nm_se(sW) + '\',null,' + nD + ',\'' + gS + '\')" pn="' + omni_nm_pn + '" ct="' + omni_nm_ct + '" cn="' + omni_nm_cn + '"><a href="' + sV + '" CM="NewsMenuL' + (nD + 1) + CM + gS + '" CE="' + sId + '-' + (ceCnt) + '" class="nmL' + sS + '" onclick="return false;">' + sT + '</a></li>');

                }

            }
            s.push('</ul></div></div></div>');
            var oC = document.getElementById('nm_c' + nD);
            oC.innerHTML = s.join("");
            var oT = document.getElementById('nm_t' + nD),
            dx = oT.offsetWidth,
            dy = oT.offsetHeight;
            var x = xPar,
            y = yPar;
            if (o.nm_bDrp) {
                y += dyPar;
                if (x + dx > dxOff + dxCli) x = (dxOff + dxCli) - dx; //j-chicks

            } else if (o.parentNode.parentNode.className.indexOf('horiz-menu') != -1) {
                y = y + o.offsetHeight + 6;
                dx = oT.parentNode.offsetWidth;
                if (x + dx > dxOff + dxCli) {
                    if (xPar - dx > dxOff) x = xPar + o.offsetWidth - dx;
                    else x = (dxOff + dxCli) - dx;

                }
                if (x < dxOff) x = dxOff; //end j-chicks

            } else {
                var dxOverlap = (nD == 1) ? 0: 2;
                x += dxPar - dxOverlap;
                x += 6;
                y += 1;
                if (nD > 1) y -= 1;
                if (x + dx > dxOff + dxCli) {
                    if (xPar - dx > dxOff) x = xPar + dxOverlap - dx;
                    else x = (dxOff + dxCli) - dx;

                }
                if (x < dxOff) x = dxOff;
                if (y + dy > dyOff + dyCli) {
                    y = (dyOff + dyCli) - dy;
                }
                if (y < dyOff) y = dyOff;

            }

            var oD = document.getElementById('nm_d' + nD);
            oD.style.pixelWidth = oD.style.width = dx;
            oD.style.pixelHeight = oD.style.height = oD.offsetHeight;
            oD.style.pixelLeft = oD.style.left = x;
            oD.style.pixelTop = oD.style.top = y;
            oD.style.zIndex = 100000000;
            nm_os(nD, dx, dy, x, y);
            if (!nm_bFla) nm_of();
            nm_nNew = 1;

        }

    }
    if (nm_sx(o.className) != 'H') {
        o.className += 'H';
        if (o.firstChild.nodeType == 1) o.firstChild.className += 'H';
    }
}

function nm_link(link, vname)
{
	if(link.charAt(1) == "(")
	{
		var param = nm_se(link.substr(2)).replace(/`/g, "','");
		
		switch(link.charAt(0))
		{
			case "v":
                                param = "vPlayer('" + param;
				break;
			case "a":
				param = "m_OpenMPV3('" + param;
				break;
			case "s":
				param = "SSOpen('" + param;
				break;
			case "o":
				param = "OCW('" + param.replace("^", "','_blank','");
				break;
			default:
				return link;
		}
		return "javascript:" + param  + "')"; 
	}
	else if(link.charAt(1) == ":")
	{
		var legacyLink = ["www.msnbc.com/modules/counters/scoreboard.asp?sport=", "boards.live.com/MSNBCboards/board.aspx?BoardID=", "covers.msnbc.com/data/", "www.scoreboard.msnbc.com/msnbc/", "www.msnbc.com/"];
		return "http://" + legacyLink[link.charAt(0)-"0"] + link.substr(2);
	}
	else
		return link;
}
/// <summary>
/// News Menu Get shim IFRAME for menu DIV
/// </summary>
/// <param name="nD">The depth of Menu DIV</param>
/// <returns>Shim for the Menu DIV</returns>
/// <remarks>
/// INTERNAL: called only from within Std.js, by nm_os and nm_mx
/// </remarks>
function nm_gs(nD)
{
	// Get the shim according to the id of menu
	return document.getElementById("nm_shim" + nD);
}

/// <summary>
/// News Menu Open the shim IFRAME
/// </summary>
/// <param name="nD">Menu DIV depth</param>
/// <param name="dx">shim width</param>
/// <param name="dy">shim height</param>
/// <param name="x">shim left</param>
/// <param name="x">shim top</param>
/// <remarks>
/// INTERNAL: called only from within Std.js, by nm_mi
/// </remarks>
function nm_os(nD, dx, dy, x, y)
{
	// Get the shim
	var shim = nm_gs(nD);

	// If there is no shim for the menu DIV then create a new one
	if (!shim)
	{
		var shim = document.createElement("iframe");

		// Set the initial property for shim
		shim.scrolling = "no";
		shim.frameBorder = "0";
		shim.style.position = "absolute";

		// Set the name, id of the shim according to menu DIV
		shim.name = shim.id = "nm_shim" + nD;

		// Set the zIndex of shim a little bit less than the menu DIV
		if (nm_nIE) shim.style.zIndex = 99999999;

		// Firefox doesn't support shim which has zIndex that greater than 1000
		else shim.style.zIndex = 999;

		// Add the shim to document body
		window.document.body.appendChild(shim);
	}

	// Set the position and shape of the shim
	shim.style.width = dx;
	shim.style.height = dy;
	shim.style.left = x;
	shim.style.top = y;
	
	// Make the shim visible
	shim.style.display = "inline";
}

/// <summary>
/// News Menu Deal with flash objects in the page
/// </summary>
/// <remarks>
/// INTERNAL: called only from within Std.js, by nm_mi
/// </remarks>
function nm_of()
{
	// Only when EMBED object is supported for the client browser
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])
	{
		// get all EMBED objects in the page
		var embeds = document.getElementsByTagName("embed");

		var spnFlash, embed1;
		var sFlash = "";

		// Loop in the EMBED objects
		for (i=0; i<embeds.length; i++)
		{
			embed1 = embeds[i];

			// If the EMBED object is already opaque then skip it
			if (embed1.getAttribute("wmode") == "opaque") continue;

			// Add a container SPAN for the embed object, move the EMBED object into this container
			spnFlash = document.createElement("span");
			embed1.parentNode.insertBefore(spnFlash, embed1);
			embed1.parentNode.removeChild(embed1);
			spnFlash.appendChild(embed1);

			// change the innerHTML of its container
			var sFlash = spnFlash.innerHTML.replace("embed ", "embed wmode='opaque'");
			spnFlash.innerHTML = sFlash;
		}
	}

	// Set the global variable to be true to make sure the function is called only once
	nm_bFla = true;
}

/// <summary>
/// News Menu Menu mouse Out
/// </summary>
/// <param name="o">Object moved from</param>
/// <remarks>
/// INTERNAL: called only from within Std.js, by nm_bo and nm_mi
/// modified by Tiff Fehr 12/18/07 to include changes previously in CDATA ID 22119282, adding delay to news menu flyout behavior.
/// original override and corrections by Ben Tesch.
/// </remarks>
function nm_mo(o) {
    //newsmenu delay
	if (nm_Enter) 
	{
        window.clearTimeout(nm_Enter);
        nm_Enter = 0;
    }
    
	// Check if we opened a menu
	if ((nm_nNew == 1) && (nm_nD)) 
	{
        // Just opened the menu, so set the new menu protection timeout
		nm_nNew = 2;
        nm_tNew = window.setTimeout('nm_mt();', 250);
        
		// Remember to turn off highlight later
		document.getElementById('nm_c' + nm_nD).nm_aOff = new Array(o);
    } 
	else 
	{
        // Turn off the highlight style for this item
		if (nm_sx(o.className) == 'H') {
            o.className = o.className.slice(0, -1);
            if (o.firstChild.className) {
                o.firstChild.className = o.firstChild.className.slice(0, -1);
            }
        }
    }
    
	// Clear deferred arguments
	nm_aDef = 0;
    
	// Set dismiss timer
	nm_tDis = window.setTimeout('nm_mx(0,0)', 500);
}

/// <summary>
/// News Menu Menu Timeout
/// </summary>
/// <returns></returns>
/// <remarks>
/// INTERNAL: called only from within Std.js, by nm_bo
/// </remarks>
function nm_mt()
{
	// Clear new menu flag
	nm_nNew=0;

	// Is there a deferred call?
	if(nm_aDef!=0)
		nm_mi(nm_aDef[0],nm_aDef[1],nm_aDef[2],nm_aDef[3],nm_aDef[4]);
}


/// <summary>
/// News Menu Menu eXit
/// </summary>
/// <param name="nD">Desired depth of menus on return (not counting new menus)</param>
/// <param name="b">Will a new menu be popped up after we return?</param>
/// <remarks>
/// INTERNAL: called only from within Std.js, by nm_mc, nm_mo and nm_mi
/// </remarks>
function nm_mx(nD,b)
{
	// Turn off highlight for topmost menu closed
	var aOff=document.getElementById('nm_c'+(nD+1)).nm_aOff;
	if(aOff)
	{
		if(nm_sx(aOff[0].className)=='H')
		{
			aOff[0].className=aOff[0].className.slice(0,-1);
			aOff[0].firstChild.className=aOff[0].firstChild.className.slice(0,-1);
		}
	}

	// Empty deeper div containers
	for(var iD=nD+1;iD<=nm_nD;iD++)
	{
	    // Close shim IFRAME
        var shim = nm_gs(iD);
        if (shim) shim.style.display = "none";
        
		// Move out the Newsweek Ad
		if (iD == 1 && nwAdOps && nwAdOps.parentNode)
		{
			nwAdOps.parentNode.removeChild(nwAdOps);
		}
		
		var oC=document.getElementById('nm_c'+iD);
		oC.nm_aOff=0;
		oC.innerHTML='';
	}

	// Remember new depth
	nm_nD=nD;
}


/// <summary>
/// News Menu Normalize Event
/// </summary>
/// <param name="o">Original object</param>
/// <param name="e">Event name</param>
/// <returns>Listening object</returns>
/// <remarks>
/// INTERNAL: called only from within Std.js, by nm_bc, nm_bo and nm_bi
/// </remarks>
function nm_ne(o,e)
{
	while(true)
	{
		if((o==null)||(typeof(o)=='undefined'))
			return null;
		if((o[e]!=null)&&(typeof(o[e])!='undefined'))
			return o;
		o=o.parentNode;
	}
}


/// <summary>
/// News Menu find XY of object on page
/// </summary>
/// <param name="o">Object we're looking at</param>
/// <param name="oR">Root object to be relative to</param>
/// <remarks>
/// INTERNAL: called only from within Std.js, by nm_mi
/// </remarks>
function nm_xy(o,oR)
{
	var oP=o,x=0,y=0,dx=o.offsetWidth,dy=o.offsetHeight;

	// Initialize location of parent
	this.xP=0;
	this.yP=0;

	// Figure out where object is
	while(true)
	{
		// If the parent is floated, we want to position
		// relative to them, so stop walking upward.
		// NMJS07: Now that we've moved the nm_cX DIVs to be
		// children of body, we don't want this any more
		// if (nm_nIE)
		// {
		// 	if (oP.currentStyle.styleFloat!="none")
		// 	{
		// 		// Pass up location of parent
		// 		this.xP=oP.offsetLeft;
		// 		this.yP=oP.offsetTop;
		// 		break;
		// 	}
		// }

		// Get our offset from parent
		x+=oP.offsetLeft;
		y+=oP.offsetTop;

		// Are we where we want to stop?
		if(oP==oR)				// need for N6 top level
			break;

		// Iterate to next parent
		oP=oP.offsetParent;
		if(oP==null)			// need for N6 sub level
			break;
	}

	// Return position as properties on object
	this.x=x;
	this.y=y;
	this.dx=dx;
	this.dy=dy;
}


/// <summary>
/// News Menu String of Url normalized and decorated
/// </summary>
/// <param name="sU">URL to normalize</param>
/// <returns>normalized URL</returns>
/// <remarks>
/// INTERNAL: called only from within Std.js, by nm_bc and nm_mi
/// </remarks>
function nm_su(sU)
{
	// If URL is not absolute, examine further
	if((sU.slice(0,5)!='http:')&&(sU.slice(0,11)!='javascript:'))
	{
		// If there are no slashes, append one (for /id/xxx/)
		if(sU.indexOf('/')==-1)
		{
			if(nm_sSuf!='')
			{
			    if(nm_sSuf.slice(0,5) == 'http:')
			    {
			        sU = nm_sSuf + sU + '/';
			        return sU;
			    }
			    else
			    {
				sU+=nm_sSuf;
				}
			}
			sU=sU+'/';
		}

		// If URL is relative, prepend path
		if(sU.charAt(0)!='/')
			sU=nm_sBas+sU;
		else if(nm_sBas.slice(0,6)=='http:/')
			sU=nm_sBas.slice(0,nm_sBas.indexOf('/',7))+sU;
	}

	// Give back the normalized URL
	return sU;
}


/// <summary>
/// News Menu String Escape
/// </summary>
/// <param name="s">string to escape</param>
/// <returns>escaped string</returns>
/// <remarks>
/// INTERNAL: called only from within Std.js, by nm_mi
/// </remarks>
function nm_se(s)
{
	return s.replace(/\'/g, '\\\'').replace(/\\\\\'/g, '\\\\\\\'');
}


/// <summary>
/// News Menu String suffiX
/// </summary>
/// <param name="s">URL to get last character of</param>
/// <returns>the last character of the URL</returns>
/// <remarks>
/// INTERNAL: called only from within Std.js
/// </remarks>
function nm_sx(s)
{
	return s.charAt(s.length-1);
}

/// <summary>
/// News Menu flyout enabled or not
/// </summary>
/// <returns>true - opened, false - closed</returns>
/// <remarks>
///
/// </remarks>
function nm_opt()
{
    var nm = readCookie("NM");
    if (nm.length == 0)
        return nm_tDef == "1";

    return nm == "1";
}

/// <summary>
/// Change News Menu flyout user setting
/// </summary>
/// <remarks>
///
/// </remarks>
function nm_flyouts()
{
    SetCookie("NM", nm_opt(nm_tDef) ? "1|0" : "0|1");
}

/// <summary>
/// News Menu Show the content of toggle button
/// </summary>
/// <remarks>
///
/// </remarks>
function nm_st()
{
    if (nm_bFM)
    {
        // Set the toggle text
        var sEn = nm_opt(nm_tDef)?"Disable Fly-out":"Enable Fly-out";        
		var togglebutton = document.getElementById("togglebutton");
		if (togglebutton)
		{
			togglebutton.href = "javascript:nm_flyouts();location.reload();";
			togglebutton.innerHTML = sEn;
		}
		
		// Display the toggle button
		var togglerow = document.getElementById("flyouttogglerow");
		if (togglerow)
		{
			togglerow.style.display = nm_nNN ? "table-row" : "block";
		}
    }
}

// call script in container if exists
if(typeof(nm_onscriptload)=='function')
	nm_onscriptload();


/// <summary>
/// RAD function to call MSN ad service
/// </summary>
///
/// <param name="nHeight"></param>
/// <param name="nWidth"></param>
/// <param name="sAdStr"></param>
///
/// <returns>Javascript Ad Code</returns>
///
/// <remarks></remarks>
function ad_dap(nHeight, nWidth, sAdStr)
{
    if (window['dap'])
    {
        dap(sAdStr, nWidth, nHeight);
    }
}


/// <summary>
/// RAD function to call MSN ad service
/// </summary>
///
/// <param name="nHeight"></param>
/// <param name="nWidth"></param>
/// <param name="sAdStr"></param>
///
/// <returns>Javascript Ad Code</returns>
///
/// <remarks></remarks>
function ad_dap(nHeight, nWidth, sAdStr)
{
    if (window['dap'])
    {
        dap(sAdStr, nWidth, nHeight);
    }
}

/// <summary>
/// placead* function to call Newsweek ad service
/// </summary>
///
/// <param name="sAdStr"></param>
/// <returns>Javascript Ad Code</returns>
///
/// <remarks></remarks>
function ad_nw(sAdStr)
{
    if (window['placeAd'])
    {
        placeAd(sAdStr,'newsweek.'+window.section_name);
    }
}

//
// Use css and input to replace image button
//
/// <summary>
/// swap button appearance when mouseover and mouseout
/// </summary>
/// <param name="obj">input object, usually use this</param>
/// <param name="index">0 for normal, 1 for mouseover</param>
/// <returns></returns>
/// <remarks>
/// </remarks>
function swapbtn(obj,index)
{
	switch(index)
	{
		case 0:
			obj.className=obj.className.replace("mboxi", "mbox");
			break;

		case 1:
			obj.className=obj.className.replace("mbox", "mboxi");
			break;
	}
}

//
// To get User Rating data before omniture code, put component at begining and move it to right place later
//
/// <summary>
/// Find the rating code and insert it into rating bar
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
/// </remarks>
/*function moveURCode()
{
	var code = document.getElementById("URholder");
	var place = document.getElementById("URplace");
	if(code != null && place != null)
	{
		place.appendChild(code);
		code.style.display = "";
	}
	WriteRatings();
}
*/
// IMAX moveDiv interval ID
var oInt;

/// <summary>
/// Move the IMAX bottom panel down gradually
/// </summary>
/// <param name="nHeight">bottom panel height</param>
/// <param name="sObj">bottom panel id</param>
/// <returns></returns>
/// <remarks>
/// </remarks>
function moveDiv(nHeight,sObj)
{
	var oObj = document.getElementById(sObj);
	//sets interval and default pos
	if (oInt == null) oInt = setInterval("moveDiv("+nHeight+",'"+sObj+"')",1);
	//moves object specified height, then clears interval
	if (oObj.offsetTop >= nHeight + imax_top) {
		if (oSniff.ie > -1 && oSniff.mac == true) oObj.style.posTop = nHeight + imax_top;
		else oObj.style.top = nHeight + imax_top;
		clearInterval(oInt);
	} else {
		if (oSniff.ie > -1 && oSniff.mac == true) oObj.style.posTop += 20;
		else oObj.style.top = oObj.offsetTop + 20;
	}
}

// IMAX Mainart top position on the page
var imax_top;

/// <summary>
/// Get IMAX Mainart top position used by moveDiv function
/// </summary>
/// <remarks>
/// </remarks>
function imaxTop()
{
	imax_top = document.getElementById('imax_ct').offsetTop;
}

/// <summary>
/// Set the top position of whole 'below-fold' div for moveDiv
/// </summary>
/// <param name="sPos">bottom panel start position</param>
/// <returns></returns>
/// <remarks>
/// </remarks>
function imaxStartPos(sPos)
{
	document.getElementById('below-fold').style.top = sPos + imax_top;
}

/// <summary>
/// Fix compatible bugs in firefox and opera for "More From" box
/// </summary>
/// <remarks>
/// </remarks>
function imaxFixNext()
{
	var nxt;
	for(var i = 1; i < 11; i++)
	{
		nxt = document.getElementById('nxtStry' + i);
		if(nxt!=null)
			nxt.style.height='';
	}
	var ntxt = document.getElementById('nextText');
	if(ntxt) ntxt.className='textMedBlackBold p16';
}

/// <summary>
/// Site Search - when you press enter on the button.ascx input box - redirects to the next search
/// </summary>
/// <remarks>
/// </remarks>
function sr_NewFormAction()
{
	if(((event.which)&&(event.which==13))||((event.keyCode)&&(event.keyCode==13)))
	{
		var port;
		if(location.port!="")
		{
			port=":"+location.port;
		}
		else
		{
			port="";
		}
		var searchString=document.getElementById("searchButton_txtSearch").value;
		document.getElementById("q").value=searchString;
		document.getElementById("SearchForm").action="http://"+location.hostname+port+"/?search=MSNBC&q="+searchString+"&submit=Search&FORM=AE&os=0&gs=1&p=1&id="+document.getElementById("defaultId").value+"";
		document.location=document.getElementById("SearchForm").action;
	}
}
/// <summary>
/// Site Search
///  </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function sr_ChngBtn()
{
	var el1=document.getElementById("q");
	var el2=document.getElementById("search");
	var el3;
	var el4=document.getElementById("os");
	var el5=document.getElementById("gs");
	var el6=document.getElementById("p");
	var el7 =document.getElementById("adunitid");
	var el8 =document.getElementById("propertyid");
					
	if(el2!=null)
	{
		el3=el2["FORM"];
		if(el3!=null)
		{
			if(el1!=null)
			{
				switch(this.value)
				{
					case"Web":
						el1.name="q";
						el2.action="http://g.msn.com/0nwenus0/AE/16?SU=http://" + siteDomainList[pd_me.site];
						el3.value="AE";
						el7.value="939";
						el8.value="3501";
						break;
					default:
						el1.name="q";
						el2.action="http://" + siteDomainList[pd_me.site];
						el3.value=pd_me.site;
						el4.name="os";
						el5.name="gs";
						el6.name="p";
						el7.value="";
						el8.value="";
						
				}
			}
		}
	}
}

/// <summary>
/// Site Search
/// </summary>
/// <param name=""></param>
/// <returns></returns>
/// <remarks>
///
/// </remarks>
function sr_DoSearch()
{
	var el=document.getElementById("search");
	if(el!=null)
	{
	    var elbackup = el;
		el=el.lastChild;
		if(el!=null)
			for(var i=0;i<el.childNodes.length;i++)
			{
				var ch=el.childNodes[i];
				if(ch.type=='radio')
					if(ch.value=="MSNBC")
					{
					    if(ch.checked)
						{
							pop_getEl("q").value+="";
    					    elbackup.target = "_self";
    					}
    					else
					        elbackup.target = "_blank";
					    return;
					}
			}
	}
}

function sr_NewRadioBtns(){
var el=document.getElementById("search");

if (el!=null) el=el.lastChild;
if (el!=null)
    {for(var i=0; i < el.childNodes.length; i++) 
        {var ch = el.childNodes[i];
            if (ch.name=='search') ch.onclick=sr_ChngBtn;
        }
     }
 }
 
function sr_UpdHead(bg){logoImg(bg);sr_NewRadioBtns();}
function sr_MSNTVSearch(){var port;if(location.port!=""){port=":"+location.port;}else{port="";}var el1=document.getElementById("q");var el2=document.getElementById("search");var el3;var el4=document.getElementById("os");var el5=document.getElementById("gs");var el6=document.getElementById("p");var el7=document.getElementById("device");if(el2!=null){el3=el2["FORM"];if(el3!=null){if(el1!=null){for(counter=0;counter<el2.searchRad.length;counter++){if(el2.searchRad[counter].type=="radio" && el2.searchRad[counter].checked==true){if(el2.searchRad[counter].value=="Web"){el1.name="q";el2.action="http://g.msn.com/0nwenus0/AE/16?SU=http://" + siteDomainList[pd_me.site] + "/";el3.value="AE";}else{el1.name="q";el2.action="http://"+location.hostname+port+"/";el3.value=pd_me.site;el4.name="os";el5.name="gs";el6.name="p";el7.name="device";}}}}}}}

function toggleMSNMore()
{
    //var MSNMoreBtn = document.getElementById('msnMore');
    //MSNMoreBtn.className=(MSNMoreBtn.className=='ButtonOpen')?'ButtonClosed':'ButtonOpen';   
    var msnMoreBlock = document.getElementById('msnMore');    
    msnMoreBlock.className=(msnMoreBlock.className=='blockOpen')?'blockClosed':'blockOpen';
        
}

function DateTime() {
	var ma = ["Jan","Feb","March","April","May","June","July","Aug","Sept","Oct","Nov","Dec"];
	var wa = ["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"];
	var za = ["ET","CT","MT","PT","AKT","HT","HT"];

	this.D2S = function(d,f) {
		var r = "updated ";
		if(f) {
			var c = new Date();
			var m = parseInt(((c-d)/1000)/60);
			if(m==0) {
				return r + "less than 1 minute ago";
			}
			else if(m < 180 && m > 0) {
				return r + M2S(m);
			}
		}
		return r + "<span class=\"time\">" + GetT(d) + " " + this.GetTZ(d) + ",</span> <span class=\"date\">" + GetD(d) + "</span>";
	};

	var M2S = function(m) {
		var r = "";
		if(m>59) {
			var h = parseInt(m/60);
			m = m-(h*60);
			r = h + " hour" + ((h>1)?"s":"") + ((m>0)?", ":"");
		}
		return r+= ((m>0) ? (m + " minute"+((m>1)?"s":"")) : "") + " ago";
	};

	var T2M = function(t) {
		return parseInt((t - 621355968000000000)/10000);
	};

	this.T2D = function(t) {
		return new Date(T2M(t));
	};

	var GetT = function(d) {
		var h = d.getHours();
		var m = d.getMinutes();
		return ((h<13) ? ((h==0) ? 12 : h) : (h-12)) + ":" + ((m<10) ? "0"+m:m) + " " + ((h<12) ? "a.m.":"p.m.");
	};

	var GetD = function(d) {
		var m = wa[d.getDay()]+"., "+ma[d.getMonth()]+". "+d.getDate()+", "+d.getFullYear();
		return m;
	};

	this.GetTZ = function(d) {
		var o = d.getTimezoneOffset()/60;
		var st = (d.toString().lastIndexOf("ST")>-1||d.toString().lastIndexOf("Standard Time")>-1)?5:4;
		return (o <=10 && o >=st) ? za[o-st]:false;
	};
}

/// <summary>
/// Set MSNBC your homepage 
/// </summary>
/// <remarks>
/// Homepage
/// </remarks>
function setHome(action, objlink){
 var _ieshp=document.getElementById("ieshp");
 var sp="http://"+window.location.host+"/";
 _ieshp.style.behavior='url(#default#homepage)';
  var oS = new UberSniff();  
  if (action)
  {
        pd_onc('Make MSNBC Your Homepage', '', 'o', '0', 'Make MSNBC Your Homepage', objlink);
	if (oS.ie) {
		_ieshp.setHomePage(sp);
		var spnHome=document.getElementById('spnHome');
  	        var anHome=document.getElementById('anHome');
  	        if (!oS.ie ||!(_ieshp.isHomePage(sp)||_ieshp.isHomePage(sp+"/")) ){
		        spnHome.style.display="none";	
		        anHome.style.display = "inline";
		}
		else {	 
		        anHome.style.display = "none";
		        spnHome.style.display="inline";
  	        }
	        window.event.returnValue = false;
		}
  }	
	var spnHome=document.getElementById('spnHome');
  	var anHome=document.getElementById('anHome');
  	if (!oS.ie ||!(_ieshp.isHomePage(sp)||_ieshp.isHomePage(sp+"/")) ){
		spnHome.style.display="none";	
		anHome.style.display = "inline";
  	}
  	else {
		anHome.style.display = "none";
		spnHome.style.display="inline";
  	}  
}

/// RSS Buttons for Next Links box 
var MSNBC = {
	RSS: {	
		showBtns:function(id,u,site){
		    var moreOnNote = "More RSS feeds from MSNBC.com";
		    var moreOnId = "5216556";
			if (site == "21683474") {moreOnNote = "More RSS feeds from NBCSports.com"; moreOnId = "22507087";}			
				u = 'http://' + siteDomainList[pd_me.site] + '/id/' + id + '/device/rss/rss.xml';
				document.write(MSNBC.RSS.MyMSNBtn(u) + MSNBC.RSS.liveBtn(u) + MSNBC.RSS.yahooBtn(u) + MSNBC.RSS.bloglinesBtn(u) +  MSNBC.RSS.xmlBtn(u));
				document.write('<div><span class="bulletRedSmall">&#8226; </span><span class="headlineList2"><a class="linkBlack" href="http://' + siteDomainList[pd_me.site] + '/id/' + moreOnId + '">' + moreOnNote + '</a></span></div>');						
		},
		
		liveBtn:function(u){
			return '<a href="http://www.live.com/?add=' + u + '" target="_blank"><img border="0" src="http://msnbcmedia.msn.com/i/msnbc/Components/ColorBoxes/Styles/ColorBoxImages_GlobalOnlyPlease/wl.gif" height="17" width="106" class="rssButton"/></a>';
		},
		
		yahooBtn:function(u){
			return '<a href="http://add.my.yahoo.com/rss?url=' + u + '" target="_blank"><img src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif" width="91"; height="17" alt="Add to My Yahoo!" class="rssButton"/></a>';
		},
		
		bloglinesBtn:function(u){
			return '<a href="http://www.bloglines.com/sub/' + u + '" target="_blank"><img src="http://static.bloglines.com/images/sub_modern11.gif" alt="Subscribe with Bloglines" width="76" height="17" class="rssButton"/></a>';
		},
		
		MyMSNBtn:function(u){
			return '<a href="http://my.msn.com/addtomymsn.armx?id=rss&ut=' + u + '" target="_blank"><img src="http://msnbcmedia.msn.com/i/msnbc/Components/ColorBoxes/Styles/ColorBoxImages_GlobalOnlyPlease/rss_MyMSN.gif" width="71" height="14" alt="Add to MyMSN" class="rssButton"/></a>';
		},
		
		xmlBtn:function(u){
			return '<a href="' + u + '" target="_blank"><img src="http://msnbcmedia.msn.com/i/msnbc/Components/ColorBoxes/Styles/ColorBoxImages_GlobalOnlyPlease/xmlIcon.gif" height="14" width="36" class="rssButton"/></a>';
		},
		
		newsgatorBtn:function(u){
			return '<a href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=' + u + '" title=" Newsweek RSS Feed " target="_blank"><img src="http://www.newsgator.com/images/ngsub1.gif" alt="Subscribe in NewsGator Online" width="91" height="17" class="rssButton"/></a>';
		},
		
		myNewsweekBtn:function(u){
			return '<a href="http://my.newsweek.com/ngwhitelabel/Sites/AddSubscription.aspx?orgStr=nwk&xmlUrl=' + u + '&returnPage=/NGWhiteLabel/Sites/nwk/reader.aspx" target="_blank"><img src="http://msnbcmedia.msn.com/i/msnbc/Sections/Newsweek/NWProjects/NWNewsgator/components/i/nw_mynw_chicklet.gif" width="96" height="17" class="rssButton"/></a>';
		}		
	}
};

///<summary>
///Check if user has seen survey in two weeks, and select survey randomly if more than one
///</summary>
/// <remarks>
/// </remarks>
function checkSurvey()
{
	if(surveyList.length == 0)
		return;

	var url = location.href;
	if(url.indexOf("/print/") > -1 || url.indexOf("&print=") > -1 ||
		url.indexOf("displaymode/1168") > -1 || url.indexOf("displaymode=1168") > -1)
		return;

	var bSeen = readCookie("SURVEY");
	if(bSeen != "")
		return;
	
	var sIndex = Math.round(Math.random() * 100) % surveyList.length;
	var rate = surveyList[sIndex].rate * surveyList.length;
	if(rate > 100)
		rate = 100;
	
	if((Math.random() * 100) < rate)
	{
		s_prop16 = "Survey";
		s_pageName = "Survey|" + pd_nou(pd_me.s.substring(0,10)) + '|' + pd_nou(pd_me.ss.substring(0,10)) +	'|' + pd_me.id + '|' +
			surveyList[sIndex].name + "|" + pd_me.dt;
		var d = new Date();
		d.setDate(d.getDate() + 14);
		SetCookie("SURVEY", "1", d.toGMTString());
		saveOmniture();
		location.href = "/id/" + surveyList[sIndex].page + "/from" + escape(location.pathname);
	}
}

///<summary>
/// Save omniture code to cookie, which can be called in survey invitation page
///</summary>
/// <remarks>
/// </remarks>
function saveOmniture()
{
	var str = "s_pageName`'" + s_pageName.replace(/'/g, "\\\'");
	if(s_pageType) str += "';s_pageType`'" + s_pageType;
	if(s_channel) str += "';s_channel`'" + s_channel.replace(/'/g, "\\\'");
	if(s_campaign) str += "';s_campaign`'" + s_campaign;
	if(s_zip) str += "';s_zip`'" + s_zip;
	if(s_account) str += "';s_account`'" + s_account;
	if(s_visitorSampling) str += "';s_visitorSampling`'" + s_visitorSampling;
		
	for(var i = 1; i <= 24; i++)
	{
		var temp = eval("s_prop" + i);
		if(temp)
			str += "';s_prop" + i + "`'" + temp;
	}
	if(s_prop35) str += "';s_prop35`'" + s_prop35;
	if(s_prop39) str += "';s_prop39`'" + s_prop39;
	if(s_prop41) str += "';s_prop41`'" + s_prop41;
	str += "';";
	SetCookie("OMNICODE", str);
}

///<summary>
/// Load omniture code
///</summary>
/// <remarks>
/// </remarks>
function loadOmniture()
{
    if(s_account==null || s_account==undefined)
    {
        s_account="msnbcom"
    }
	var code = readCookie("OMNICODE");
	if(code == "")
	{
		closeSurvey();
		return;
	}
	code = code.replace(/`/g, "=");
	eval(code);
	SetCookie("OMNICODE", "");
}
///<summary>
/// Close the invitation page and go back to original page, updated by v-starli@microsoft.com, 2007-10-18
///</summary>
/// <remarks>
/// </remarks>
function closeSurvey()
{
	if(document.all)
	{
		history.go(-1);
		return;
	}
	var url = location.href;
	var index = location.href.indexOf("from/");
	if(index > -1)
	{
		location.href = "http://" + location.host + unescape(url.substr(index + 4));
	}
}

///when user click yes on the survey invitation page, by v-starli@microsoft.com, 2007-10-18
function clickYes(CustomURL)
{
	if(CustomURL!=null) SurveyURL=CustomURL;
	window.open(SurveyURL,"_blank");
	closeSurvey();
}

function pd_rr(ct, ii, it, ai, key, hc, usrR, totalU)
{
	if(!pd_me) return;
	pd_me.ct = ct;
	pd_me.ii = ii;
	pd_me.it = it;
	pd_me.ai = ai;
	pd_me.key = key;
	pd_me.hc = hc;
	pd_me.rated = false;
	pd_me.usrRating = usrR;
	pd_me.totalUsers = totalU;
	s_prop41=usrR+"|"+totalU;
}

function WriteRatings()
{
	var rating = document.getElementById("URplace");
	if(!rating) return;
	
	var value = docRated(pd_me.key, rating);
	if(value != -1)
	{
		rating.style.cursor = "auto";
		pd_me.rated = true;
	}
	
	if(!pd_me.rated)
	{
		if(document.all)
			rating.onmouseleave = rateout;
		else
			rating.onmouseout = rateout;
	}
		
	for(var i = 0; i < 10; i++)
	{
		var item = document.createElement("div");

		if(!pd_me.rated)
		{
			item.onmouseover = rateover;
			item.onclick = ratethis;
		}
		rating.appendChild(item);

		var image = document.createElement("img");
		image.id = "star" + i;
		image.ii = i;
		image.src = "/Images/msnrrua/star.gif";
		if(!pd_me.rated)
			image.alt = "Rate it " + (i + 1) / 2;
		
		item.appendChild(image);
		if(i % 2 == 1)
			item.style.marginRight = "1px";
	}
	if(pd_me.rated)
		setStar(value, 1);
	else
		setStar(pd_me.usrRating * 2 - 1, 0);

	var div = document.getElementById("userRatingTotal");
	if (div)
	{
		div.innerHTML = "<nobr>Current rating: <b>" + pd_me.usrRating + "</b> by <b>" + pd_me.totalUsers +"</b> users</nobr>";
		div.style.display = "";
	}
}

function docRated(key, parent)
{
	if(parent == null) parent = document.body;
	var usrrat = document.getElementById("usrrat");
	if(!usrrat)
	{
		usrrat = document.createElement("input");
		usrrat.type = "hidden";
		usrrat.id = "usrrat";
		if(document.all)
			usrrat.style.behavior = "url(#default#userData)";
		parent.appendChild(usrrat);
	}

	var value = -1;
	var dc = document.cookie;
	var pos = dc.indexOf(key + "=");
	if(pos != -1)
	{
		var pos2 = dc.indexOf(";", pos);
		if (pos2 == -1)	pos2 = dc.length;
		value = parseInt(dc.substring(pos + key.length + 1, pos2));
	}
	return value;
}

function rateover(evt)
{
	if(pd_me.rated) return;

	var image, id;

	if(evt == null) evt = window.event;
	var obj = evt.srcElement ? evt.srcElement : evt.target;
	id = obj.ii;
	
	setStar(id, 1);
}

function setStar(id, set)
{
	var alt = "You rated this item " + (id + 1) / 2;
	for(var i = 0; i < 10; i++)
	{
		image = document.getElementById("star" + i);
		if(i < id)
			image.style.left = -24 * set - 6 * (i % 2);
		else if(i == id)
			image.style.left = -24 * set - 12 + 6 * (i % 2);
		else
			image.style.left = -48 - 6 * (i % 2);
		
		if(pd_me.rated)
			image.alt = alt;
	}
}

function rateout()
{
	if(pd_me.rated) return;
	setStar(pd_me.usrRating * 2 - 1, 0);
}

function ratethis(evt)
{
	if(pd_me.rated || (typeof(rrList) == 'undefined')) return;
	
	if(evt == null) evt = window.event;
	var obj = evt.srcElement ? evt.srcElement : evt.target;
	var id = obj.ii;

	var rating = document.getElementById("URplace");
	rating.style.cursor = "auto";
	pd_me.rated = true;
	setStar(id, 1);

	rateDoc(pd_me, rrList[id], id, rating);
}

function rateDoc(pdm, rateHash, score, parent)
{
	if(parent == null) parent = document.body;
	
	var usrKey = pdm.key.replace(/\s/g, '_');
	var attr, usr = 0;
	
	var usrrat = document.getElementById("usrrat");

	if(usrrat.expires == '')
	{
		try
		{
			usrrat.load(pdm.ct);
			attr = usrrat.getAttribute('r' + pdm.hc);
			if (attr)
				usr = attr.indexOf(' ' + usrKey + ' ') + 1;
			else
				attr = '';
		}
		catch(e)
		{ }
	}

	var img = document.getElementById("usrimg");
	if(!img)
	{
		img = document.createElement("img");
		img.id = "usrimg";
		img.width = "1";
		img.height = "1";
		img.style.position = "absolute";
		parent.appendChild(img);
	}
	
	img.src = "/rate.ashx?ct=" + pdm.ct + "&ii=" + pdm.ii + "&it=" + pdm.it + "&ai=" + pdm.ai + "&r=" + rateHash + "&c=" + score + "&u=" + usr;
	
	if(usrrat.expires == '' && usr < 1)
	{
		try
		{
			usrrat.setAttribute('r' + pdm.hc, attr + ' ' + usrKey + ' ');
			usrrat.save(pdm.ct);
		}
		catch(e)
		{ }
	}
}

function getObj(id) {return document.getElementById(id);}

function createEl(name) {return document.createElement(name);}

//indicate whether it's a RSS user, by v-starli@microsoft.com 2007/2/14	
function IsRSSUser()
{
    if(pd_me==null) pd_me = new Object;	
    if(!(pd_me.hasOwnProperty('IsRSSUser'))) 
    {
        if(location.href.indexOf('from=rss') > -1)  SetCookie("FROMRSS","true");	
        pd_me.IsRSSUser=(readCookie("FROMRSS")=="true");    		    
        pd_me.AdsToHide="";        
    }
    return pd_me.IsRSSUser;
}

//add an ad to be hidden, by v-starli@microsoft.com 2007/2/13
function AddAdToHide(AdFieldName)
{
    if(pd_me==null) pd_me = new Object;	
    if(pd_me.hasOwnProperty('AdsToHide')) pd_me.AdsToHide=pd_me.AdsToHide+" "+AdFieldName;
    else pd_me.AdsToHide=AdFieldName;
}

//hide the frames of ads when there is nothing of the inner part of the ad;change the sponsor ad title if there is any, by v-starli@microsoft.com 2007/2/15
function HideAdFramesAndChangeTitles()
{
    //hide frames
    if(pd_me==null) return;
    if(pd_me.hasOwnProperty('AdsToHide'))
    {
        var ads=pd_me.AdsToHide.split(' ');
        for(var i=0;i<ads.length;i++)
        {
            HideAdFrame(ads[i]);
        }
    }
    
    //there are 10 brokerbutton ads in the frame of id='AdBrokerButtons_F', when all the ads inside the frame are hidden, hide the frame
    var F=getObj('AdBrokerButtons_F');
    if(F!=null)
    {
        var Has=false;
        for(var j=1;j<=10;j++)
        {
            var adframe=getObj('AdBrokerButton'+j+'_F1');
            if(adframe!=null && adframe.style.display!='none') {Has=true;break;}
        } 
        if(!Has) F.style.display='none';
    }
}

//whether there is no DColumn brokenbutton ads, by v-starli@microsoft.com 2007/3/20
function bNoDBrokenButton()
{
    var b=true;var adframe;
    for(var j=1;j<=4;j++)
    {
        adframe=getObj('DColBrokerButton'+j+'_F1');
        if(adframe!=null && adframe.style.display!='none') {b=false;break;}
    }
    return b;
}

//hide the frame of an ad, by v-starli@microsoft.com 2007/3/5
function HideAdFrame(AdName)
{
    if(pd_me!=null && pd_me.hasOwnProperty('AdsToHide') && pd_me.AdsToHide.indexOf(AdName) > -1)
    {
        for(var j=1;j<=10;j++)
        {
            var adframe=getObj(AdName+"_F"+j);
            if(adframe) adframe.style.display='none';
            else break;
        }
        if(AdName=='AdSponsor')
        {
            //when both sponsor ad and breadclumb are empty, hide the frame of them if there is any
            var F=getObj('AdSponsor_F');
            if(F!=null && getObj('BreadCrumb_F').innerHTML.length<10) F.style.display='none';
        }
    }
}

//change the title if there is any, by v-starli@microsoft.com 2007/3/5
function ChangeSponsorAdTitle()
{
    if(pd_me!=null)  
    {
        var AdTitle;
        if(pd_me.hasOwnProperty('SAdTitle')) {AdTitle=getObj('SAdTitle');if(AdTitle) AdTitle.innerHTML=pd_me.SAdTitle;}
        if(pd_me.hasOwnProperty('STSAdTitle')) {AdTitle=getObj('STSAdTitle');if(AdTitle) AdTitle.innerHTML=pd_me.STSAdTitle;}	
    }

}


/// <summary>
/// Called for RSS Video Partner Headline Boxes
/// </summary>
/// <param name="sDateTime">Preformatted Date String</param>
/// <param name="s">Sampling rate, usually 100</param>
/// <remarks>
/// This function is used to reorder the pre-formated date that comes in from local affiliates
/// </remarks>
function CB_Aff_DateTime(sDateTime){
	try{
		var aDTRaw = sDateTime.split(",");
		var aDateTime = aDTRaw[1].split(" ");
		var aTime = aDateTime[4].split(":");
		var sTime;

		if(aTime[0]>12){
			sTime = aTime[0]-12 + ":" + aTime[1] +  " p.m.";
		}else{
			sTime = aTime[0] + ":" + aTime[1] +  " a.m.";
		}
		//remove starting 0 from a.m. time.
		if(sTime.charAt(0)=="0"){sTime = sTime.substr(1);}
		
		if(!(sTime.indexOf("NaN")>-1) && !(aDateTime[2].indexOf("NaN")>-1) && !(aDateTime[1].indexOf("NaN")>-1)){
			document.write(sTime + ", " + aDateTime[2] + ". " + aDateTime[1]);
		}
	}
	catch(err){
		document.write(sDateTime);
	}

}

//a js function follow the d-column brokenbutton ads, by v-starli@microsoft.com 2007/3/20
function D_msnSideBar()
{
    for(var i=1;i<=4;i++){var AdName="DColBrokerButton"+i;HideAdFrame(AdName);}
    if(!(bNoDBrokenButton())) msnSideBar();
}

function buildIPredictTable()
{
	var root = getObj("iPredictTbl");
	var oTBody = root.tBodies[0];
	if(!oTBody)
	{
		oTBody = createEl("tbody");
		root.appendChild(oTBody);
	}
	var ipIdList = iPredIDs.split(",");
	var id, row, lcell, rcell, cell, value, div, link;
	
	while(oTBody.hasChildNodes())
	{
		oTBody.deleteRow(0);
	}
	
	for(var i = 0; i < ipIdList.length; i++)
	{
		id = ipIdList[i];
		
		row = oTBody.insertRow(-1);
			
		lcell = createEl("td");
		if(iPredList[id])
			value = iPredList[id][1];
		else
			value = 0;
		lcell.value = value.toString();
		if(value > 0)
		{
			lcell.innerHTML = "+" + value;
			lcell.className = "avgp cGreen";
		}
		else if(value == 0)
		{
			lcell.innerHTML = "Toss Up";
			lcell.className = "avgt c666";
		}
		else
		{
			lcell.innerHTML = "" + value;
			lcell.className = "avgn cRed";
		}
		row.appendChild(lcell);

		cell = createEl("td");
		row.appendChild(cell);
		div = createEl("div");
		div.className = "iptopic";
		cell.appendChild(div);
		link = createEl("a");
		link.href = "/id/" + pd_me.id + "/vid/" + id;
		link.innerHTML = link.title = cell.value = ipData[i].replace("<", "&lt;").replace(">", "&gt;");
		div.appendChild(link);

		cell = createEl("td");
		if(id == curIPredID)
			cell.id = id;
		ipUserVote(cell, userPredicts[id]);
		row.appendChild(cell);

		cell = createEl("td");
		if(iPredList[id])
			value = Math.round((iPredList[id][1] - iPredList[id][7]) * 10) / 10;
		else
			value = 0;
		cell.value = value.toString();
		if(value == 0)
		{
			cell.innerHTML = "-";
			cell.className = "c666";
		}
		else if(value > 0)
		{
			cell.innerHTML = "+" + value;
			cell.className = "cGreen";
		}
		else
		{
			cell.innerHTML = "" + value;
			cell.className = "cRed";
		}
		cell.className += " aC";
		row.appendChild(cell);

		rcell = createEl("td");
		rcell.className = "c666 aR";
		if(iPredList[id])
			count = iPredList[id][5];
		else
			count = 0;
		rcell.value = count.toString();
		value = count.toLocaleString();
		if(document.all)
			rcell.innerHTML = value.substr(0, value.length - 3);
		else
			rcell.innerHTML = value;
		row.appendChild(rcell);

		if(curIPredID == parseInt(id))
		{
			row.className = "ipcur";
			lcell.className += " ipcurl";
			rcell.className += " ipcurr";
			document.title = link.title + " - " + document.title;
		}
	}
	ipsort(0);
}

function ipsort(iCol)
{
	var oTable = getObj("iPredictTbl");
	var ipSortType;
	
	switch(iCol)
	{
		case 0:
		case 3:
			ipSortType = "float";
			break;
		case 2:
		case 4:
			ipSortType = "int";
			break;
		default:
			ipSortType = "string";
	}
	ipTblUpdate(oTable, iCol);
	sortTable(oTable, iCol, ipSortType);
}

function ipTblUpdate(oTable, iCol)
{
	var oTHead = oTable.tHead.rows[0];
	var th, row;
	
	if(oTable.sortCol != undefined && oTable.sortCol != iCol)
	{
		th = oTHead.cells[iCol];
		th.childNodes[0].className = th.childNodes[0].className.replace("iphead", "ipheadhl");
		th.childNodes[1].firstChild.className = "iparrow";
		th = oTHead.cells[oTable.sortCol];
		th.childNodes[0].className = th.childNodes[0].className.replace("ipheadhl", "iphead");
		th.childNodes[1].firstChild.className = "";
	}
}

function sortTable(oTable, iCol, sortType)
{
	var oTBody = oTable.tBodies[0];
	var colDataRows = oTBody.rows;

	var aTRs = new Array;

	for (var i=0; i < colDataRows.length; i++)
	{
		aTRs[i] = colDataRows[i];
	}

	if (oTable.sortCol == iCol)
	{
		aTRs.reverse();
	}
	else
	{
		aTRs.sort(function (oTR1, oTR2)
		{
			var vValue1, vValue2;
			var ret, order = -1;
			
			if (sortType == "string")
				order = 1;
		
			if (oTR1.cells[iCol].value)
			{
				vValue1 = convert(oTR1.cells[iCol].value, sortType);
				vValue2 = convert(oTR2.cells[iCol].value, sortType);
			}
			else
			{
				vValue1 = convert(oTR1.cells[iCol].firstChild.nodeValue, sortType);
				vValue2 = convert(oTR2.cells[iCol].firstChild.nodeValue, sortType);
			}
		
			if (vValue1 < vValue2)
				ret =  -1;
			else if (vValue1 > vValue2)
				ret = 1;
			else
				ret = 0;
				
			return ret * order;
		});
	}

	var oFragment = document.createDocumentFragment();
	for (var i=0; i < aTRs.length; i++)
	{
		oFragment.appendChild(aTRs[i]);
	}

	oTBody.appendChild(oFragment);
	oTable.sortCol = iCol;
}

function convert(sValue, sortType)
{
	switch(sortType)
	{
		case "int":
			return parseInt(sValue);
		case "float":
			return parseFloat(sValue);
		case "date":
			return Date.parse(sValue);
		default:
			return sValue.toString();
	}
}

function fillUserVotes(votes)
{
	var data = votes.split(",");
	for(var i = 0; i < data.length; i+=2)
	{
		userPredicts[data[i]] = data[i+1];
	}
	
	setTimeout(buildIPredictTable, 10);
}

function loadIPredict(param)
{
	switch(param)
	{
		case "IDs": return curIPredID + "," + location.host + "," + pd_me.id + ";" + iPredIDs;
		case "Data": return curIPredTitle + "~" + curIPredCredits + "~" + curIPred.join("~");
		case "Story": if(typeof(iPredStory) == "undefined") return "";
/*			var dt = new DateTime();
			for(var i = 1; i < iPredStory.length; i+=4)
			{
				var d = dt.T2D(iPredStory[i]);
				iPredStory[i] = dt.GetD(d);
			}*/
			return iPredStory.join("~");
			
	}
}

function ipUserVote(cell, score)
{
	cell.value = score;
	cell.innerHTML = "&nbsp;";
	switch(score)
	{
		case "-2":
			cell.className = "ipvul";
			break;
		
		case "-1":
			cell.className = "ipul";
			break;

		case "0":
			cell.className = "";
			cell.innerHTML = "Toss Up";
			break;
			
		case "1":
			cell.className = "ipl";
			break;
		
		case "2":
			cell.className = "ipvl";
			break;
		
		case "":
			cell.value = "-3";
			break;
	}
	cell.className += " aC c666";
}

function updateUserVote(score)
{
	var cell = getObj(curIPredID);
	ipUserVote(cell, score.toString());
}

var tabObj;

function tabboxInit(id, disPin, defTxt, asgTxt)
{
	var tabbox = getObj("tbx-" + id);
	var ul = tabbox.firstChild;
	var tabs = ul.childNodes[2].childNodes;
	var sheets = tabbox.childNodes;
	
	var def, tabName;
	
	if(!tabObj) tabObj = new Object;
	tabObj.disPin = disPin;
	tabObj.defTxt = defTxt;
	tabObj.asgTxt = asgTxt;
	
	for(var i = 0; i < tabs.length; i++)
	{
		tabs[i].firstChild.onclick = switchTab;
		if(tabs[i].getAttribute("def") == "1")
			def = i;
	}
	
	if(disPin)
	{
		tabs[def].className += " current";
		showTabSheet(sheets, def+1);
		return;
	}
	
	var pins = ul.childNodes[1].childNodes;
	pins[0].firstChild.onclick = pins[1].firstChild.onclick = pinTab;
	pins[0].firstChild.innerHTML = defTxt;
	pins[1].className = "btn pinned";
	pins[1].title = "pinned";
	
	tabName = readCookie(id);

	if(tabName == "") tabName = tabs[def].firstChild.innerHTML;

	for(var i = 0; i < tabs.length; i++)
	{
		if(tabName == tabs[i].firstChild.innerHTML)
		{
			def = i;
			tabs[i].def = "1";
		}
		else
		{
			tabs[i].def = "0";
		}
	}
	
	tabs[def].className += " current";
	showTabSheet(sheets, def+1);
}

function showTabSheet(sheets, sheet)
{
	for(var i = 1; i < sheets.length; i++)
	{
		if(i == sheet)
		{
			sheets[i].className = sheets[i].className.replace(" hide", "");
		}
		else if(sheets[i].className.indexOf(" hide") < 0)
		{
			sheets[i].className += " hide";
		}
	}
}

function switchTab(evt)
{
	var tab, sheet, pin;

	if(window.event)
		evt = window.event;
	
	tab = evt.srcElement || evt.target;
	tab = tab.parentNode;
	
	var tabs = tab.parentNode.childNodes;
	var sheets = tab.parentNode.parentNode.parentNode.childNodes;
	var pins = tab.parentNode.parentNode.childNodes[1].childNodes;
	
	for(var i = 0; i < tabs.length; i++)
	{
		if(tabs[i] == tab)
		{
			if(tab.className.indexOf("current") == -1)
				tab.className += " current";
			sheet = i;
		}
		else
		{
			tabs[i].className = tabs[i].className.replace(" current", "");
		}
	}
	
	if(!tabObj.disPin)
	{
		pins[1].className = (tab.def == "1" ? "btn pinned" : "btn");
		pins[1].title = (tab.def == "1" ? "pinned" : "unpinned");
		pins[0].firstChild.innerHTML = (tab.def == "1" ? tabObj.defTxt : tabObj.asgTxt);
	}
	showTabSheet(sheets, sheet+1);
	
	evt.returnValue = false;
	if(s_account && typeof(s_gs) != 'undefined')
		s_gs(s_account);
	
	return false;
}

function pinTab(evt)
{
	var pin, tabboxid, tab, tabs, parent;

	if(window.event)
		evt = window.event;
	
	pin = evt.srcElement || evt.target;
	pin = pin.parentNode;
	parent = pin.parentNode;
	pin = parent.childNodes[1];
	if(pin.className.indexOf("pinned") == -1)
	{
		pin.className = "btn pinned";
		parent.firstChild.firstChild.innerHTML = tabObj.defTxt;
		tab = parent.parentNode;
		tabboxid = tab.parentNode.id;
		tabs = tab.childNodes[2].childNodes;
		
		for(var i = 0; i < tabs.length; i++)
		{
			if(tabs[i].className.indexOf("current") != -1)
			{
				SetCookie(tabboxid, tabs[i].firstChild.innerHTML);
				tabs[i].def = "1";
			}
			else
				tabs[i].def = "0";
		}
	}

	evt.returnValue = false;
	return false;
}

function linkTrackHandler(e)
{
    var target;
    var targetNodename;
    var doLinkTrack = false;
    
    if (!e) var e = window.event;
    if (e.target) target = e.target; // mozilla
    else if (e.srcElement) target = e.srcElement; // ie
    
    if (target)
    {
        var bVideo = false;
        switch (target.nodeName.toUpperCase())
        {
            case "A":
                doLinkTrack = true;
                if (target.getAttribute('href').indexOf('msnvDwd(') != -1) {bVideo = true;}
                break;
            case "TD"://newsmenu button cells
                if(target.firstChild)
                {
                    target = target.firstChild;
                }
                if(target.nodeName.toUpperCase()=='A')
                {
                    doLinkTrack = true;
                    if (target.getAttribute('href').indexOf('msnvDwd(') != -1) {bVideo = true;}
                }
                break;
            case "AREA":
                doLinkTrack = true;
                if (target.getAttribute('href').indexOf('msnvDwd(') != -1) {bVideo = true;}
                break;
            case "IMG":
                if (target.parentNode && target.parentNode.nodeName.toUpperCase() == "A")
                {
                    doLinkTrack = true;
                    if (target.parentNode.getAttribute('href').indexOf('msnvDwd(') != -1) {bVideo = true;}
                }
                break;           
            case "INPUT":
                if (target.getAttribute('type') && target.getAttribute('type').toUpperCase() == "BUTTON")
                {
                    doLinkTrack = true;
                    if (target.getAttribute('onclick').toString().indexOf('msnvDwd(') != -1) {bVideo = true;}
                }
                break;
            default:
                doLinkTrack = false;
        }
    }
    if (doLinkTrack)
    {
        var ltData = getLinkTrackData(target);       
        if (ltData)
        {               
            bVideo? s_prop27 = ltData:SetCookie('lt',ltData);           
        }
    }
}

function getLinkTrackData(target)
{
    var ct, cn, pn = null, node = target.parentNode;
    
    // wipe any previous omniture cookie
    var date = new Date();
    date.setTime(date.getTime() - 120000);
    SetCookie('lt', '', date.toGMTString());
    
    // crawl up dom until 'control type' property is found
    while (node)
    {
        if (node.getAttribute && node.getAttribute('ct'))
        {
            if (ct && !pn)
            {
                // we already got component type from
                // a previous node, but project name
                // is still empty. in this case set
                // the project name to this newfound
                // component type
                pn = node.getAttribute('ct');
                break;
            }
            else if (!ct) // we're finding a node for the first time
            {
                ct = node.getAttribute('ct');
                cn = node.getAttribute('cn').substring(0,30);
                pn = node.getAttribute('pn');
                if (pn)
                {
                    pn = pn.substring(0,15);
                    break;
                }
            }
        }
        node = node.parentNode;
    }
    if (ct) return Omni.LinkTrack.GetDoctype() + '|' + Omni.LinkTrack.GetSection() + '|' + pn + '|' + ct + '|' + cn;
}

/// Omniture link tracking

//Set up namespace for Omniture objects
var Omni = {};

//namespace for Omniture news menu, init properties
Omni.NewsMenu = {};
Omni.NewsMenu.ProjectName = '';
Omni.NewsMenu.Top = '';
Omni.NewsMenu.FirstHeadline = '';
Omni.NewsMenu.FirstFront = '';
Omni.NewsMenu.SecondHeadline = '';
Omni.NewsMenu.ExpandFront = '';
Omni.NewsMenu.ExpandHeadline = '';

//namespace for link track objects
Omni.LinkTrack = {};

/// <summary>
/// Omniture link track onclick handler for news menu flyout links
/// Process linkTrackHandler function and stop event bubble
/// </summary>
/// <param name="e"></param>
/// <remarks>
/// </remarks>
Omni.LinkTrack.OnclickHandler = function (e){
    if (e)
    {
        linkTrackHandler(e);

        //stop the event bubble up
        if (e.target) 
        {
            e.stopPropagation(); //dom/firefox
        }
        else if (e.srcElement) 
        {
            e.cancelBubble = true;//ie
        }
    }
};


///// <summary>
/// LinkTrack.GetDoctype method, returns doc type string
/// </summary>
Omni.LinkTrack.GetDoctype = function (){
    if(s_prop16_orig){
        return s_prop16_orig.substring(0,15);
    }
    return '';
};

///// <summary>
/// LinkTrack.GetSection method, returns section string
/// Determines whether link is from section, sub-section, or sub-sub-section.
/// </summary>
Omni.LinkTrack.GetSection = function (){
    
    ///trims the section to 15 characters 
    function TrimSection(str){
        if (str)
        {
            return str.substr(0,15);
        }
        return '';
    }
    
    ///Determine section type
    if (s_prop6_orig)
    {
        return TrimSection(s_prop6_orig);
    } 
    else if (s_prop5_orig)
    {
        return TrimSection(s_prop5_orig);
    } 
    else
    {
        return TrimSection(s_prop4_orig);
    }
};

function getTimestampTitle(currencyDate)
{
	var time = Math.floor((new Date().getTime() - new Date(parseInt((currencyDate - 621355968000000000)/10000)).getTime())/(60*1000));
	var alt = 'Updated';
	if(time>0)
	{
		alt += ' ';
		var d=Math.floor(time/1440);
		var h=Math.floor(time%1440/60);
		var m=Math.floor(time%60);
		if(d==1)
		{
			alt += d + ' day';
		}
		else if(d > 1)
		{
			alt += d + ' days';
		}					
		if(h==1)
		{
			if(d > 0)
			{
				alt += ', ';
			}
		    
			alt += h + ' hour';
		}
		else if(h > 1)
		{
			if(d > 0)
			{
				alt += ', ';
			}
			   
			alt += h + ' hours';
		}					
		if(m==0)
		{
			if(d==0 && h==0)
			{
				alt += 'less than 1 minute ago';
			}
			else
			{
				alt += ' ago';
			}
		}
		else if(m==1)
		{
			if(d > 0 || h > 0)
			{
				alt += ', ';
			}
			   
			alt += m + ' minute ago';
		}
		else
		{
			if(d > 0 || h > 0)
			{
				alt += ', '
			}
			    
			alt += m + ' minutes ago';
		}
	}
	return alt;
}

function renderTimestampIcon()
{
	var icon_U=document.getElementsByName("icon_U");
	for(var i=0;i<icon_U.length;i++)
	{
		icon_U[i].title=getTimestampTitle(icon_U[i].getAttribute('ic_cd'));
	}
}
/// <summary>
/// Truncates Headline
/// </summary>
/// <param name="headline">The headline to be truncated</param>
/// <param name="lngth">The length at which to truncate the headline</param>
/// <param name="cutWord">Whether to cut out a truncated word, or not</param>
/// <remarks>
/// created by j-bhitt. 9/18/07
/// </remarks>
function headTrunc(headline, lngth, cutWord){
	if(headline.length>lngth){
		chrAfter = headline.charCodeAt(lngth);
		headline = headline.substring(0, lngth);
		if(cutWord == true&&chrAfter!=32){
			headline = headline.replace(/\w+$/, '');
		}
		if(!cutWord == true&&chrAfter!=32){
			headline = headline + "..."
		}else{
			headline = headline + " ..."
		}
	}
	document.write(headline);
}
/// <summary>
/// MSN Button zindex
/// </summary>
/// <remarks>
/// created by Tony Pation in Workbench ID 21701339 11/08/07; moved to std.js by Tiff fehr 12/19/07.
/// </remarks>
function toggleMSNMore(){
	var msnMoreBlock=document.getElementById('msnMore');
	var header=document.getElementById('header');
	if(msnMoreBlock.className=='blockOpen'){header.style.zIndex=1; msnMoreBlock.className ='blockClosed';}
	else{header.style.zIndex=200000; msnMoreBlock.className ='blockOpen';}
}

function ssMove(evt)
{
	if(window.event)
		evt = window.event;
	var btn = ss = (evt.srcElement || evt.target).parentNode;
	evt.returnValue = false;
	var dir, sParent, sNext;
	
	if(btn.className == "btn up")
		dir = 0;
	else if(btn.className == "btn down")
		dir = 1;
	else
		return false;
	
	while(ss.className.indexOf("sum") == -1)
	{
		ss = ss.parentNode;
	}
	
	sParent = ss.parentNode;
	
	sNext = ss;
	do
	{
		sNext = (dir == 0 ? sNext.previousSibling : sNext.nextSibling);
	}
	while(sNext != null && sNext.className.indexOf("sum") == -1);
	
	if(sNext == null)
		return false;
	
	var tc = ss.className;
	ss.className = sNext.className;
	sNext.className = tc;
	
	var temp = document.createElement("div");
	sParent.replaceChild(temp, sNext);
	sParent.replaceChild(sNext, ss);
	sParent.replaceChild(ss, temp);
	
	temp = null;
	ssSave(sParent);
	btn.innerHTML = btn.innerHTML;
	
	return false;
}

function ssSize(evt)
{
	if(window.event)
		evt = window.event;
	var ss = evt.srcElement || evt.target, n = ss.getAttribute("s");

	evt.returnValue = false;
	ss = ss.parentNode;
	if(ss.className != "")
		return false;
		
	var sParent = ss.parentNode.childNodes;

	for(var i = 1; i < sParent.length-1; i++)
		sParent[i].className = "";
	ss.className = "btn current";
	
	while(ss.className.indexOf("sum") == -1)
	{
		ss = ss.parentNode;
	}

	ssShow(ss, n-1);
	ssSave(ss.parentNode);
	return false;
}

function ssShow(ss, n, bfirst)
{
	var sizeclass = ["", "sum-min", "sum-med", "sum-max"];
	ss.childNodes[1].className = "ssBody " + sizeclass[n];

	var grid, style = ss.childNodes[1].style;
	ss.s = n;
	if(n == 0)
	{
		style.visibility = "hidden";
		style.height = "1px";
		style.overflow = "hidden";
	}
	else
	{
		grid = getGridInSS(ss);
		style.visibility = "visible";
		style.overflow = "visible";
		switchSize(grid, n);
	}
	if(bfirst) ss.style.display = "block";
	if(n != 0)
	{
		resetSSize(grid);
		style.height = "auto";
	}
}

function ssSave(ssWrap)
{
	if(typeof(pd_me) == "undefined")
		return;
	var key = "SS" + pd_me.id, list = Array();

	ssWrap = ssWrap.childNodes;
	for(var i = 0; i < ssWrap.length; i++)
	{
		if(ssWrap[i].className.indexOf("sum") != -1)
		{
			list.push(String.fromCharCode(ssWrap[i].i >> 6) + String.fromCharCode(((ssWrap[i].i % 64) << 2) + ssWrap[i].s));
		}
	}

	SetCookie(key, list.join(""));
}

function ssInit(ids, size, adp)
{
	var sList = Array(), temp = Array(), ss, setting = typeof(pd_me) != "undefined" ? readCookie("SS" + pd_me.id) : "";
	
	ids = ids.split(",");
	size = size.split("");
	
	if(setting != "")
	{
		var c;

		for(var i = setting.length-1; i >=0; i-=2)
		{
			ss = new Object();
			c = setting.charCodeAt(i);
			ss.id = (setting.charCodeAt(i-1) << 6) + (c >> 2);
			ss.size = c % 4;

			sList.push(ss);
			temp["" + ss.id] = ss.size;
		}
	}

	for(var i = ids.length - 1; i >= 0; i--)
	{
		if(temp[ids[i]] == null)
		{
			ss = new Object();
			ss.id = ids[i];
			ss.size = size[i] - '0';
			sList.push(ss);
		}
	}

	var slice, ssHead, mBtn, sBtn, ads = getObj("AdBanner_F1"), n, k=0, ssWrap = getObj("ssWrap"), len = sList.length, cid, sParent;

	for(var i = 0; i < len; i++)
	{
		slice = sList.pop();

		if(i == adp)
		{
			if(ads != null && ssWrap != ads.parentNode)
			{
				ads.parentNode.removeChild(ads);
				ssWrap.appendChild(ads);
			}
		}
		ss = getObj('ss_' + slice.id);
		if(!ss) continue;

		sParent = ss.parentNode;
		ss.i = slice.id;
		ss.s = slice.size;

		if(k == 0)
			ss.className += " pos1";
		else
			ss.className += " pos" + ((k-1)%9+2);
		k++;
		if(i == len-1)
			ss.className += " last";
		
		sParent.removeChild(ss);
		if(i < adp && ads != null && ssWrap == ads.parentNode)
			ssWrap.insertBefore(ss, ads);
		else
			ssWrap.appendChild(ss);
			
		ssHead = ss.firstChild.childNodes;
		mBtn = ssHead[1].childNodes;
		mBtn[1].onclick = mBtn[2].onclick = ssMove;
		
		sBtn = ssHead[2].childNodes;
		if(sBtn.length > 2)
		{
			var bs, j, set = false;
			for(j = 1; j < sBtn.length-1; j++)
			{
				bs = parseInt(sBtn[j].firstChild.getAttribute("s"))-1;
				if(bs == slice.size)
				{
					sBtn[j].className = "btn current";
					ss.s = bs;
					set = true;
				}
				sBtn[j].onclick = ssSize;
			}
			if(!set)
			{
				sBtn[j-1].className = "btn current";
				ss.s = bs;
			}
		}

		ssShow(ss, ss.s, true);
	}
}

function getGridInSS(ss)
{
	var grid = null, grids = ss.childNodes[1].childNodes;
	for(var i = 0; i < grids.length; i++)
		if(grids[i].className.indexOf("grid") != -1)
		{
			grid = grids[i];
			break;
		}
	return grid;
}

function switchSize(grid, cn)
{
	if(grid == null) return;
	var divs = grid.getElementsByTagName("DIV");
	var sc = ["min", "med", "max"], show;
	for(var i = 0; i < divs.length; i++)
	{
		if(divs[i].className.indexOf(" m") != -1)
		{
			if(divs[i].className.indexOf(sc[cn-1]) != -1)
				show = "block";
			else
				show = "none";
			divs[i].style.display = show;
		}
	}
}

function resetSSize(grid)
{
	if(grid == null) return;
	var contents = grid.childNodes, maxH = 0, oh, ot, rowH = Array(), list = Array();
	for(var i = 0; i < contents.length; i++)
		if(contents[i].style.display != "none")
			list[list.length] = contents[i];

	for(i = 0; i < list.length; i++)
	{
		list[i].style.height = "auto";
		ot = list[i].offsetTop;
		oh = list[i].offsetHeight;
		if(rowH[ot] == null || rowH[ot] < oh)
			rowH[ot] = oh;
		if(maxH < ot + oh)
			maxH = ot + oh;
	}
	
	for(i = 0; i < list.length; i++)
		list[i].style.height = rowH[list[i].offsetTop] + "px";

	grid.style.height = maxH;
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "unknown browser";
		this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "unknown version";
		this.OS = this.searchString(this.dataOS) || "unknown OS";
		document.getElementsByTagName("body")[0].className = BrowserDetect.OS + " " + BrowserDetect.browser + " " + BrowserDetect.browser + "-" + Math.floor(BrowserDetect.version) + " " + BrowserDetect.OS + "-" + BrowserDetect.browser;
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "IE",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Win"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

//grid resizing variables:
var gridList;
var gridTimerInterval;
var gridTimerId;

//adds grid to list of grids that need their height checked
function addGrid(gridName)
{
  if(gridList == null) gridList=new Array();
  gridList[gridName] = gridName;
}

//iterates over the list of grids and checks their height
function checkGrids()
{
  var grid;
  for(grid in gridList)
  {
    setGridHeight(grid);
  }
}

//checks all of the child DIV tags in the grid for the tallest one and sets the grid's height to match
function setGridHeight(gridName)
{
  var grid = document.getElementById(gridName);
  if(grid != null)
  {
    var nHeight = 0;
    var nTemp = 0;
    
    var childElements = grid.childNodes;
    for(var c = 0; c < childElements.length; c++)
    {
    if(childElements[c].id)
    {
      nTemp = 0;
      if(childElements[c].style)
      {
          childElements[c].style.height = "auto";
      }//if(childElements[c].style)
      
      try
      {
   //Get tallest grid cell
   nTemp = childElements[c].offsetHeight;
      }
      catch(err)
      {
        nTemp = 0;
      }
      
      if(nTemp > nHeight)
      {
        nHeight = nTemp;
      }
    }//if(childElements[c].id)
    }//for(var c = 0; c < childElements.length; c++)

    if(nHeight > 0)
    {
      for(var c = 0; c < childElements.length; c++)
      {
        if(childElements[c].id && childElements[c].style)
        {
          childElements[c].style.height = nHeight + "px";
        }//if(childElements[c].id && childElements[c].style)
      }//for(var c = 0; c < childElements.length; c++)
      
      grid.style.height = nHeight + "px";
    }//if(nHeight > 0)
  }//if grid
}

function startGridTimer()
{
  gridList = new Array();
  gridTimerInterval = 100;
  gridTimerId = setTimeout("checkGrids();", gridTimerInterval);
}

function clearGridTimer()
{
    if(gridTimerId != 0)
    {
      clearTimeout(gridTimerId);
      gridTimerId = 0;      
    }
    checkGrids();    
}

String.format = function( str )
{
    //decrement to move to the second argument in the array
    var tokenCount = arguments.length - 2;
    //iterate through the tokens and replace their placeholders from the original text in order
    for( var token = 0; token <= tokenCount; token++ )
    { str = str.replace( new RegExp( "\\{" + token + "\\}", "gi" ),arguments[ token + 1 ] );}
    return str;
};
