// TICKER FUNCTIONS //
var isIE = navigator.appName.indexOf("Microsoft") > -1;
var saved_cnbc_video_setURL = null;

var cnbc_MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var cnbc_DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');

function cnbc_LZ(x) {return(x<0||x>9?"":"0")+x}

function cnbc_isDate(val,format) {
	var date=cnbc_getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}

function cnbc_compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=cnbc_getDateFromFormat(date1,dateformat1);
	var d2=cnbc_getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}

function cnbc_formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=cnbc_LZ(M);
	value["MMM"]=cnbc_MONTH_NAMES[M-1];
	value["NNN"]=cnbc_MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=cnbc_LZ(d);
	value["E"]=cnbc_DAY_NAMES[E+7];
	value["EE"]=cnbc_DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=cnbc_LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=cnbc_LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=cnbc_LZ(value["K"]);
	value["kk"]=cnbc_LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=cnbc_LZ(m);
	value["s"]=s;
	value["ss"]=cnbc_LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}
	
function cnbc_isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function cnbc_getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (cnbc_isInteger(token)) { return token; }
		}
	return null;
	}
	
function cnbc_getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=cnbc_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<cnbc_MONTH_NAMES.length; i++) {
				var month_name=cnbc_MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<cnbc_DAY_NAMES.length; i++) {
				var day_name=cnbc_DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=cnbc_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=cnbc_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=cnbc_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=cnbc_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=cnbc_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=cnbc_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=cnbc_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=cnbc_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	
	if (i_val != val.length) { return 0; }
	
	if (month==2) {
		
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { 
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}

function cnbc_parseDate(val) {
	var preferEuro=(arguments.length==2)?arguments[1]:false;
	generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
	monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
	dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
	var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
	var d=null;
	for (var i=0; i<checkList.length; i++) {
		var l=window[checkList[i]];
		for (var j=0; j<l.length; j++) {
			d=cnbc_getDateFromFormat(val,l[j]);
			if (d!=0) { return new Date(d); }
			}
		}
	return null;
	}
	
String.prototype.replaceAll = function(
strTarget, 
strSubString 
){
var strText = this;
var intIndexOfMatch = strText.indexOf( strTarget );
 

while (intIndexOfMatch != -1){

strText = strText.replace( strTarget, strSubString )
 
intIndexOfMatch = strText.indexOf( strTarget );
}
 
return( strText );
}


function cnbcGMTET(cnbcWireDate) {
var formatString = "M/d/y h:mm a";
cnbcWireDate = cnbcWireDate.replaceAll (".","");
var UTCDate = cnbc_getDateFromFormat(cnbcWireDate,formatString);
var ETDate = UTCDate - "14400000";
var finalDateRaw = new Date(ETDate);
var finalDate = cnbc_formatDate(finalDateRaw,formatString);
return( finalDate );
}

function cnbc_ticker_DoFSCommand(command,args)
{
	var fsC;
	fsC = eval(command);
	fsC(args);
}

function cnbc_ticker_drawFlash()
{
	/*var browser		= (isIE) ? 'ie' : 'ff';
	var cuser		= (cnbc_readCookie('CASTOKEN') == null) ? "null" : cnbc_readCookie('CASTOKEN');
	var sessionid	= cnbc_ticker_getCookie('flashTickerSession');


	document.write('	<script language="VBScript">');
	document.write('		sub ticker_FSCommand(ByVal command, ByVal args)');
	document.write('		call cnbc_ticker_DoFSCommand(command,args)');
	document.write('		end sub');
	document.write('	</script>');
	
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="ticker" width="882" height="42" align="middle">\n');
	document.write('	<param name="allowScriptAccess" value="always" />\n');
	document.write('	<param name="swLiveConnect" value="true" />\n');
	document.write('	<param name="movie" value="'+cnbc_tickerDataPath+'/images/ticker.swf" />\n');
	document.write('	<param name="quality" value="high" />\n');
	document.write('	<param name="FlashVars" value="rootpath='+cnbc_tickerRootPath+'&amp;datapath='+cnbc_tickerDataPath+'&amp;qid='+cnbc_tickerQuoteID+'&amp;vid='+cnbc_tickerVideoID+'&amp;gid='+cnbc_tickerGuestID+'&amp;hid='+cnbc_tickerHelpID+'&amp;user='+cuser+'&amp;state=&amp;browser='+browser+'&amp;session='+sessionid+'">\n');
	document.write('	<param name="bgcolor" value="#000066" />\n');
	document.write('	<embed src="'+cnbc_tickerDataPath+'/images/ticker.swf" name="ticker" swLiveConnect=true quality="high" bgcolor="#000066" width="882" height="42" id="ticker" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" FlashVars="rootpath='+cnbc_tickerRootPath+'&amp;datapath='+cnbc_tickerDataPath+'&amp;qid='+cnbc_tickerQuoteID+'&amp;vid='+cnbc_tickerVideoID+'&amp;gid='+cnbc_tickerGuestID+'&amp;hid='+cnbc_tickerHelpID+'&amp;user='+cuser+'&amp;state=&amp;browser='+browser+'&amp;session='+sessionid+'" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
	document.write('</object>\n');		*/
	
	//Initialize CNBC Dependencies...
	cnbc_init_services();
}

function cnbc_init_services()
{	
	/////////////////////////////////////////////////////////////
	//--AD TRACKING
	/////////////////////////////////////////////////////////////
	cnbc_initialize_adtracking();	
	 
 	/////////////////////////////////////////////////////////////
	//--OMNITURE
	////////////////////////////////////////////////////////////
	cnbc_intialize_omniture();
	
	/////////////////////////////////////////////////////////////////
	///--VIDEO RESTRICTION
	////////////////////////////////////////////////////////////////	
	cnbc_initialize_videorestriction();	
}

function cnbc_dart_video_setURL(id,url, image, tmptitle, exclusive,date,time, tmpdescription, tmpcategory, premium, play)
{
	if(dartPlayer!=null)
	{
		delete dartPlayer;
		dartPlayer = null;
	}		
	
	var omnicontentTitle= document.getElementById('omnicontentTitle');
	if(omnicontentTitle!=null)
	{
		omnicontentTitle.innerHTML = unescape(tmptitle);
	}	
	
	var omnicontentDate= document.getElementById('omnicontentDate');
	if(omnicontentDate!=null)
	{
		omnicontentDate.innerHTML = date;
	}	
	
	var omnicontentTime= document.getElementById('omnicontentTime');
	if(omnicontentTime!=null)
	{
		omnicontentTime.innerHTML = time;
	}	
		
	//NOTE:: HACK IMPLEMENTED FOR FIREFOX -- MUST REMOVE FOR BRANCH 200702
	if((navigator.appVersion.indexOf("MSIE") == -1) || (navigator.userAgent.indexOf("Opera") >= 0))
	{
		var WMPDiv 					= document.getElementById('WMPObject');
		var playDiv					= document.getElementById('playVideo');
		var thumbDiv				= document.getElementById('videoThumb');
		var vidCtrlPlay				= document.getElementById('vidCtrlPlay');
		var curVidTitle				= document.getElementById('curVidTitle');	
		var curVidDateTime			= document.getElementById('curVidDateTime');	
		var curVidDescr				= document.getElementById('curVidDescr');	
		var vidCtrlTimer			= document.getElementById('vidCtrlTimer');
		var curVidShare				= document.getElementById('curVidShare');
		var fL_padL_author_info		= document.getElementById('fL_padL_author_info');
		var padL_cnbc_headline_padR = document.getElementById('padL_cnbc_headline_padR');
		var padL_CNBC_Tools			= document.getElementById('padL_CNBC_Tools');
		var fL_padL_CNBC_Tools		= document.getElementById('fL_padL_CNBC_Tools');
		var URLField				= document.getElementById('textfield3');
		var emailButton				= document.getElementById('email_button');	
		var categories				= document.getElementById('categories');
		var compAd                  = document.getElementById('companionAd');
		var title					= unescape(tmptitle);
		var description				= unescape(tmpdescription);
		var category				= unescape(tmpcategory);
		
		if(WMPDiv==null)
		{
			var index = url.indexOf("player/main.do");
			if(index!= -1)
			{
				//Premium URL detected... Redirect to Video Player....			
				var vidPlayer = window.open(cnbc_videoPlusURL+'/'+url.substring(index),"CNBCPlus","toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width=800,height=600");
				if(window.focus)
				{
					vidPlayer.focus();
				}
			}
		}
		else
		{	
			
			WMPDiv.style.display	='none'; 
			
			if(compAd!=null)
		    {
		        compAd.style.display = 'none';
		    }
		    	
			if(thumbDiv!=null)
			{
				thumbDiv.innerHTML		='<img width="100%" src="'+image+'" />';	
			}
			
			if(playDiv!=null)
			{
				playDiv.style.display	='block';
				playDiv.innerHTML		='<a href="#" onclick="javascript:cnbc_video_playURL(\''+url+'\');blur();return false;"><img style="border:0px;" src="/images/cnbc/video/play_video.jpg" /></a>';		
			}
			
			if(vidCtrlPlay!=null)
			{
				vidCtrlPlay.innerHTML	= '<a href="#" onmouseover="javascript:cnbc_video_swapImage(\'playButton\',\'/images/cnbc/video/vid_control_\' + cnbc_video_overState + \'_over.gif\');" '+
										'onmouseout="javascript:cnbc_video_swapImage(\'playButton\',\'/images/cnbc/video/vid_control_\' + cnbc_video_overState + \'.gif\')" ' +
										'onclick="javascript:cnbc_video_togglePlayPause(\''+url+'\');blur();return false;" >' +
										'<img name="playButton" style="border:0px;" src="/images/cnbc/video/vid_control_play.gif" /></a>';	
			}
			
			if(vidCtrlTimer!=null)
			{	
				if(!play)
				{							
					vidCtrlTimer.innerHTML	= '<p>00:00/'+cnbc_video_toDurationString(time)+'</p>';	
				}
			}
			
			if(curVidTitle!=null)
			{
				if(premium=='true')
				{
					curVidTitle.innerHTML= '<p class="curVidTitle">'+title+'<img src="/images/cnbc/video/cnbcplusfeather.png" class="topVidCellExcl" width="39" height="10" style="behavior:url(\'/images/cnbc/pngbehavior.htc\');" /></p>';
				}
				else if(exclusive=='true')
				{
					curVidTitle.innerHTML= '<p class="curVidTitle">'+title+'<img src="/images/cnbc/video/cnbc_exclus.jpg" width="100" height="13" /></p>';
				}
				else
				{			
					curVidTitle.innerHTML= '<p class="curVidTitle">'+title+'</p>';
				}								
			}
			
			if(curVidDateTime!=null)
			{
				curVidDateTime.innerHTML = '<p class="curVidDateTime">'+cnbc_video_toDateString(date)+' ['+cnbc_video_toDurationString(time)+']</p>';
			}
			
			if(curVidDescr!=null)
			{
				if((description!=null) && (description.length>140))
				{
					description  = description.substring(0,140);
					description +="...";
				}
				
				curVidDescr.innerHTML= '<p class="curVidDescr">'+description+'</p>';		
			}		
			
			if(curVidShare!=null)
			{
				curVidShare.innerHTML	=	'<a href="/id/'+cnbc_videoShareDocId+'?video='+id+'" onmouseover="javascript:cnbc_video_swapImage(\'shareVideo\',\'/images/cnbc/video/cur_video_share_over.jpg\')" onmouseout="javascript:cnbc_video_swapImage(\'shareVideo\',\'/images/cnbc/video/cur_video_share.jpg\');">' +
											'<img style="border:0px;" name="shareVideo" src="/images/cnbc/video/cur_video_share.jpg" /></a>';
			}
			
			if(categories!=null)
			{
				categories.innerHTML = category;
			}
		
			if(fL_padL_author_info!=null)
			{
				fL_padL_author_info.innerHTML = 'Last Update: '+cnbc_video_toDateString(date);
			}
						
			
			if(padL_cnbc_headline_padR!=null)
			{	
				padL_cnbc_headline_padR.innerHTML = title;
				
				if(premium=='true')
				{
					padL_cnbc_headline_padR.innerHTML+= '    <img width="39" height="10" style="behavior:url(\'/images/cnbc/pngbehavior.htc\');" src="/images/cnbc/video/cnbcplusfeather.png" />';
				}
				
				try
				{
					var cnbc_breadcrumb = document.getElementById('cnbcbreadcrumb');
					if(cnbc_breadcrumb!=null)
					{						
						if(cnbc_breadcrumb_innerHTML==null)
						{			
							cnbc_breadcrumb_innerHTML = cnbc_breadcrumb.innerHTML;
						}
		
						cnbc_breadcrumb.innerHTML = cnbc_breadcrumb_innerHTML + " " + title;
					}
				}
				catch(e)
				{}
			}
			
			if(padL_CNBC_Tools!=null)
			{
				padL_CNBC_Tools.innerHTML = '<span class="content">'+description+'</span>';
			}						
			
			if(URLField!=null)
			{
				URLField.value= 'http://'+location.host+'/id/'+cnbc_videoShareDocId+'?video='+id;
			}
			
			if(emailButton!=null)
			{
				emailButton.innerHTML = '<a href="#"><img src="/images/cnbc/video/email_video.png" border="0" onclick="cnbc_emailVideoShare('+id+',\''+escape(title)+'\',\''+escape(description)+'\');return false;"/></a><br /><br />';
			}
					
			cnbc_video_playState = "play";
			cnbc_video_overState = "play";		
			
			cnbc_video_isPlaying= false;	
			cnbc_video_setDragPos(0);		

			if(play)
			{
				window.setTimeout("cnbc_video_auto_play()",500);		
			}
		}
	}
	else
	{	
		saved_cnbc_video_setURL(id,url, image, tmptitle, exclusive,date,time, tmpdescription, tmpcategory, premium, play);	
	}	
	//NOTE:: HACK IMPLEMENTED FOR FIREFOX -- MUST REMOVE FOR BRANCH 200702
}

function cnbc_initialize_adtracking()
{
	//Ad Tracking initialization	
	document.write('<div id="cnbcdarttracking">');
	
	if((navigator.appVersion.indexOf("MSIE") == -1) || (navigator.userAgent.indexOf("Opera") >= 0))
	{
		var divName = "Flash_Observer_" + cnbc_docid + "_div";
       	var variableName = "Flash_Observer_" + cnbc_docid;

		document.write('<div id="'+divName+'" style="visibility: hidden; position: absolute; top: 10px; left: 600px;">');
		document.write( '<object id="' + variableName + '" width="1" height="1"  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">' +
						'<param name="movie" value="http://m1.2mdn.net/879366/imp_01_17.swf?uagent=' + navigator.userAgent + '" />' +
						'<param name="allowScriptAccess" value="always" />' + 
					    '<embed id="' + variableName + '" name="' + variableName+'" play="true" src="http://m1.2mdn.net/879366/imp_01_17.swf?uagent=' + navigator.userAgent + 
					    '" AllowScriptAccess="always" quality="high" bgcolor="#ffffff" width="1" height="1"  align="middle" type="application/x-shockwave-flash" /></object>' );		
        document.write('</div>');       
	}
		
    document.write('<script language="JavaScript">');
    
	document.write('document.write(\'<s\'+\'cript src=\"');
	document.write("http://m1.2mdn.net/879366/WMPlayer_01_17.js");
	document.write('"></s\'+\'cript>\');');
	
	document.write('document.write(\'<s\'+\'cript src=\"');
	document.write("http://m1.2mdn.net/879366/EventBin_01_17.js");
	document.write('"></s\'+\'cript>\');');		
	
	document.write('</script>');
	
	document.write('</div>');	
}

function cnbc_initialize_videorestriction()
{
/*	
	var cnbcMD5Path = cnbc_tickerDataPath + "/scripts/md5.js";
	document.write('<script language="JavaScript">');
    
	document.write('document.write(\'<s\'+\'cript src=\"');
	document.write(cnbcMD5Path);
	document.write('"></s\'+\'cript>\');');
	
	document.write('</script>');
*/
}

function cnbc_intialize_omniture()
{	
	if(saved_cnbc_video_setURL==null)
	{
		saved_cnbc_video_setURL = cnbc_video_setURL;
	}
		
	cnbc_video_setURL = cnbc_dart_video_setURL;			
}

function cnbc_trackOmniture(account, prop8, prop9, prop10, pageName, server, channel, pageType, 
						    prop1, prop2, prop3, prop4, campaign, state, zip, events, products, 
						    purchaseID, eVar1, eVar2, eVar3, eVar4, eVar5, prop18)
{		
	s_account	=account;
	s_prop8 	=prop8;
	s_prop9 	=prop9
	s_prop10	=prop10
	
	s.prop8		=prop8;
	s.prop9		=prop9;
	s.prop10	=prop10;
	s.pageName	=unescape(pageName);
    s.server	=unescape(server);
    s.channel	=unescape(channel);
    s.pageType	=unescape(pageType);
    s.prop1		=unescape(prop1);
    s.prop2		=unescape(prop2);
    s.prop3		=unescape(prop3);
	s.prop4		=unescape(prop4);
    s.campaign	=campaign;
    s.state		=state;
	s.zip		=zip;
    s.events	=events;
    s.products	=products;
    s.purchaseID=purchaseID;
    s.eVar1		=eVar1;
    s.eVar2		=eVar2;
    s.eVar3		=eVar3;
    s.eVar4		=eVar4;
    s.eVar5		=eVar5;
    s.prop18	=prop18;    

    var s_code	=s.t();     
	
    var stub 	= document.getElementById('omni');
    
    if(stub!=null)
    {
    	if(s_code) stub.innerHTML += s_code;
		if(navigator.appVersion.indexOf('MSIE')>=0)stub.innerHTML += unescape('%3C')+'\!-'+'-';	
	}
}						    

function cnbc_video_auto_play()
{			
	var playVideo	= document.getElementById('playVideo');
		
	if(playVideo!=null)
	{
		var url = playVideo.innerHTML;
		
		var urlIndex =  url.indexOf('(');
		var parsedURL=  url.substring(urlIndex+2, url.indexOf(')',urlIndex+2)-1);	
		
		parsedURL = parsedURL.replace(/&amp;/gi, '&' );
		cnbc_video_playURL(parsedURL);
	}
}

function cnbc_video_omnitureReporting(url)
{		
	if(dartPlayer==null)
	{
		dartPlayer = new CNBCDartPlayer("Player0", DARTReady);
	}
	
	window.setTimeout("cnbc_videoAdStarted()",2500);		
	
	var parsedTitle = null;
	var parsedDate  = null;
	var parsedTime  = null;
	var prop3 		= "";
	
	//Extract Video Title from Page....
	var curVidTitle	= document.getElementById('curVidTitle');

	if(curVidTitle!=null)
	{
		var title = curVidTitle.innerHTML;
		
		var titleIndex =  title.indexOf('>');
		parsedTitle=  title.substring(titleIndex+1, title.indexOf('<',titleIndex+1));	
	    prop3= "On Demand : Right-rail";
	}
	else
	{
		var omnicontentTitle= document.getElementById('omnicontentTitle');

		if(omnicontentTitle!=null)
		{
			prop3= "On Demand : Embedded - " + cnbc_docid;
			parsedTitle=omnicontentTitle.innerHTML;
		}				
	}
	
	//Extract Video Date from Page....
	var curVidDateTime			= document.getElementById('curVidDateTime');	
	if(curVidDateTime!=null)
	{
		var datetime = 		curVidDateTime.innerHTML;
				
		var dateIndex = datetime.indexOf('>');
		var timeIndex = datetime.indexOf('[', dateIndex + 1 );
		
		parsedDate = datetime.substring(dateIndex+1, timeIndex );
		
		if(parsedDate.indexOf('SCRIPT')==-1 &&
	       parsedDate.indexOf('script')==-1)
		{
			parsedTime = datetime.substring(timeIndex+1, datetime.indexOf(']', timeIndex+1 ));
		}
		else
		{
			dateIndex = datetime.indexOf('/SCRIPT>');
			
			if(dateIndex==-1)
			{
				dateIndex = datetime.indexOf('/script>');
			}
			timeIndex = datetime.indexOf('[', dateIndex + 8 );
			parsedDate = datetime.substring(dateIndex+8, timeIndex );
			parsedTime = datetime.substring(timeIndex+1, datetime.indexOf(']', timeIndex+1 ));
		}
		
	    prop3= "On Demand : Right-rail";
	}
	else
	{
		var omnicontentDate= document.getElementById('omnicontentDate');
		var omnicontentTime= document.getElementById('omnicontentTime');
		
		if(omnicontentDate!=null)
		{
			parsedDate=cnbc_video_toDateString(omnicontentDate.innerHTML);
		}
		
		if(omnicontentTime!=null)
		{
			parsedTime=cnbc_video_toDurationString(omnicontentTime.innerHTML);			
		}	
	}
	
	if(parsedTitle!=null)
	{
		window.setTimeout('cnbc_trackOmniture("nbcuglobal, nbcucnbcd, nbcucnbcbu", "cnbc", "cnbc.com", "Video Player","'+escape(parsedTitle)+
						  '","", "free: cnbc.com", "", "","'+cnbc_docid + ': Video Player'+'","'+prop3+'","'+escape(parsedTitle + ': ' + parsedDate)+
						  '","", "", "", "", "", "", "","", "", "", "","'+parsedTime+'")', 5000 );
	}
}
function checkCNBCVideoRestriction	()
{
	//RESTRICTION TEMPLATE...
	//"keywords=US only|OTHER VALUE;redirect1=https://stage.register.cnbc.com/refreshlogin.jsp?login-view=blogs&service=[url];redirect2=15964816"
	if(cnbc_videorestriction!=null)
	{
		var strVideoRestriction = cnbc_videorestriction.replace(/"/gi, '' );
		var restrictionKeys 	= strVideoRestriction.split(';');

		if(restrictionKeys.length==3)
		{			
			var categories = document.getElementById('categories');
			if(categories!=null)
			{
				
				//--PARSE ALL KEYS...
				var keywords 		=restrictionKeys[0].replace("keywords=", "");
				var loginURL 		=restrictionKeys[1].replace("redirect1=", "");
				var unauthorizedURL =restrictionKeys[2].replace("redirect2=", "");			
						
				//--COMPARE KEYWORDS AGAINST RESTRICTED CATEGORIES
				var keywords 	  = keywords.split("|");
				var strCategories = categories.innerHTML.replace(/&amp;/gi, '&' ).toUpperCase();

				for(var i=0; i<keywords.length; ++i )
				{								
					if((keywords[i].toUpperCase()!='') && (strCategories.indexOf(keywords[i].toUpperCase()) != -1))
					{
						var currentPage = "";
						var parentHREF  = false;
						var URLField	= document.getElementById('textfield3');	
						var WMPDiv 		= document.getElementById('WMPObject');							
						
						//--VERIFY IF CONTENT IS FROM AN IFRAME or SOURCE WINDOW...
						if(cnbc_sectionName=='')
						{
							parentHREF	= true;
							currentPage	= parent.location.href;	
						}
						else
						{
							currentPage = window.location.href;
						}

						//--VERIFY IF CONTENT IS FROM PERMALINK PAGE...
						if(URLField!=null)
						{
							currentPage = URLField.value;											
						}

						//-ENSURE SIGNIFICANT URL PARAMS are removed from SERVICE VARIABLE.
						currentPage = currentPage.replace("?", "/" );
						currentPage = currentPage.replace("&", "/" );
						currentPage = currentPage.replace("=", "/" );												
						loginURL = loginURL.replace('[url]', currentPage );
							
						//--CHECK IF USER IS AUTHENTICATED..																			
						var countryKey = (cnbc_readCookie('SUBSCRIBERINFO2') == null) ? "null" :  
																						cnbc_readCookie('SUBSCRIBERINFO2');						

						if(countryKey == 'null')
						{														
							if(WMPDiv!=null)
							{
								WMPDiv.innerHTML="";
							}
							
							//USER IS NOT AUTHENTICATED...													
							if(parentHREF)
							{
								parent.location = loginURL;
							}
							else
							{								
								window.location = loginURL;
							}

						}				
						else if(countryKey != hex_md5("United States"))
						{
							if(WMPDiv!=null)
							{
								WMPDiv.innerHTML="";
							}
						
							//USER IS NOT FROM U.S. -- RESTRICT CONTENT												
							if(parentHREF)
							{
								parent.location = unauthorizedURL;
							}
							else
							{
								window.location = unauthorizedURL;
							}													
						}																											
					}
				}
			}		
		}		
	}	
}

function cnbc_ticker_popout_drawFlash()
{
	var browser		= (isIE) ? 'ie' : 'ff';
	var cuser		= (cnbc_ticker_getCookie('CASTOKEN') == null) ? "null" : cnbc_ticker_getCookie('CASTOKEN');
	var sessionid	= cnbc_ticker_getCookie('flashTickerSession');

	document.write('	<script language="VBScript">');
	document.write('		sub ticker_FSCommand(ByVal command, ByVal args)');
	document.write('		call cnbc_ticker_DoFSCommand(command,args)');
	document.write('		end sub');
	document.write('	</script>');
	
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="ticker" width="882" height="42" align="middle">\n');
	document.write('	<param name="allowScriptAccess" value="always" />\n');
	document.write('	<param name="swLiveConnect" value="true" />\n');
	document.write('	<param name="movie" value="'+cnbc_tickerDataPath+'/images/ticker.swf" />\n');
	document.write('	<param name="quality" value="high" />\n');
	document.write('	<param name="FlashVars" value="rootpath='+cnbc_tickerRootPath+'&amp;datapath='+cnbc_tickerDataPath+'&amp;qid='+cnbc_tickerQuoteID+'&amp;vid='+cnbc_tickerVideoID+'&amp;gid='+cnbc_tickerGuestID+'&amp;hid='+cnbc_tickerHelpID+'&amp;user='+cuser+'&amp;state=popout&amp;browser='+browser+'&amp;session='+sessionid+'">\n');
	document.write('	<param name="bgcolor" value="#000066" />\n');
	document.write('	<embed src="'+cnbc_tickerDataPath+'/images/ticker.swf" name="ticker" swLiveConnect=true quality="high" bgcolor="#000066" width="882" height="42" id="ticker" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" FlashVars="rootpath='+cnbc_tickerRootPath+'&amp;datapath='+cnbc_tickerDataPath+'&amp;qid='+cnbc_tickerQuoteID+'&amp;vid='+cnbc_tickerVideoID+'&amp;gid='+cnbc_tickerGuestID+'&amp;hid='+cnbc_tickerHelpID+'&amp;user='+cuser+'&amp;state=popout&amp;browser='+browser+'&amp;session='+sessionid+'" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
	document.write('</object>\n');		
}


function cnbc_ticker_getElementPosX(id)
{
	var x;
	var myObj = isIE ? window.document[id] : document.getElementById(id);
	if(isIE)
	{
		x = document.body.scrollLeft;
	} else {
		x = myObj.parentNode.offsetLeft + window.screenX;
	}
	return x;
}

function cnbc_ticker_getElementPosY(id)
{
	var y;
	var myObj = isIE ? window.document[id] : document.getElementById(id);
	if(isIE)
	{
		y = document.body.scrollTop;
	} else {
		y = myObj.offsetTop + myObj.offsetHeight + window.screenY;
	}
	return y;
}

function cnbc_ticker_popOut()
{
	var x,y;
	var id=cnbc_ticker_popOut.arguments[0];
	x = cnbc_ticker_getElementPosX(id);
	y = cnbc_ticker_getElementPosY(id);
	var winName='tickerWin',winParams=("scrollbars=0,toolbars=0,status=0,location=0,resizable=0,menubar=0,width=970,height=42,top="+y+",left="+x),newURL=cnbc_tickerDataPath+"/images/cnbc_ticker.htm?";
	tickerWin = window.open(newURL,winName,winParams);
	if(tickerWin) tickerWin.focus();
}


function cnbc_ticker_popOut_ForTickerAdmin()
{
	var winName='tickerWin',winParams=("scrollbars=0,toolbars=0,status=0,location=0,resizable=0,menubar=0,width=970,height=42"),newURL=cnbc_tickerDataPath+"/images/cnbc_ticker.htm?";
	tickerWin = window.open(newURL,winName,winParams);
	if(tickerWin) tickerWin.focus();
}

function cnbc_ticker_setFlashCookie(value) {
	var c_name = 'flashTickerSession';
	var mydomain = 'cnbc.com';
	var expires = "";
	document.cookie=c_name+ "=" +escape(value)+((expires==null) ? "" : expires+";domain="+mydomain+";path=/" );
}

function cnbc_ticker_getCookie(name) {
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length
				var c_value = unescape(document.cookie.substring(c_start,c_end));
				return c_value;
		}
	}
	return null;
}

function cnbc_ticker_reloadPage() {
	
	window.location.reload();
	
}

function cnbc_combineLists(parent)
	{
		var els = null; var clist = null; var array_holder = '';
		var clist_array = new Array(); var sorted_array = new Array();
		
		els = document.getElementsByTagName("li");
		
		if(els != null) 
		{
			for(i=0; i<els.length; i++) 
			{
				// parent of the lists being combined div->ul->li
				if( els[i].parentNode.parentNode.id == parent) { clist_array[i] = els[i].getAttribute('id'); }	
			}
			//sort id names by numerical
			sorted_array = clist_array.sort(cnbc_reverse);
			
			for (x in sorted_array)
			{	
				for(i=0; i<els.length; i++) 
				{
				
					var org_els = els[i].getAttribute('id');
					//compare sorted id names with original elements id names
					if( sorted_array[x] == org_els ) 
					{
						array_holder += '<li id="'+els[i].getAttribute('id')+'" >'+els[i].childNodes[0].nodeValue+' '+els[i].getAttribute('id')+'</li>';
					}
				}
			}
			//display resulting array elements
			document.getElementById(parent).innerHTML = '<ul>'+array_holder+'</ul>';
			//document.write( '<ul>'+array_holder+'</ul>' );
		}	
	}
	
	function cnbc_reverse (a,b){
		return b - a;
	}
