// 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');

try
{
	getURLByFormat = cnbc_getURLByFormat;	
}
catch (e){}

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;
	}	

	//Ensure Windows Media Object is completely stopped
	if(!cnbc_video_isIE) 
	{	
		var WMPDiv = document.getElementById('WMPObject');
		if(WMPDiv!=null)
		{
			WMPDiv.innerHTML = "";
		}
	}	
	
	saved_cnbc_video_setURL(id,url, image, tmptitle, exclusive,date,time, tmpdescription, tmpcategory, premium,play);	
}

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_getURLByFormat(url)
{
    var formatURL = "";
    
    if(url!=null)
    {
        var globalvideoformat = cnbc_globalvideoformat.replace("&format=","");       
        
        var formats = url.split(';');
        for(var i=0; i<formats.length; ++i)
        {        
            if(isWMVFormat())
            {
                formatURL = formats[i];
                break;
            }
            else if(formats[i].indexOf(globalvideoformat)!= -1)
            {
                var tokens = formats[i].split("\|");
                
                if(tokens.length>=2)
                {
                    formatURL = tokens[1];
                }
                break;
            }             
        }
     }   
        
    var inx = formatURL.indexOf('&reporting');

if(inx!= -1)
{
   return formatURL.substring(0,inx);
}
else
{
    return formatURL;
}

}


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, prop31, prop37, prop36,prop19)
{		
	s_account	=account;
	s_prop8 	=prop8;
	s_prop9 	=prop9;
	s_prop10	=prop10;
	
	s.prop8		=prop8;
	s.prop9		=prop9;
	s.prop10	=prop10;
	s.prop31	=prop31;
	s.prop37	=prop37;
	s.prop36	=prop36;
	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;    
    s.prop19	=prop19;   
    s_parsedQueryString = false

    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)
{		
	var wmvFormat = true;
	
	try
	{ 
		wmvFormat = isWMVFormat();
	}
	catch(e){/*Ignore*/} 

	if(wmvFormat)
	{
		if(dartPlayer==null)
		{
			dartPlayer = new CNBCDartPlayer("Player0", DARTReady);
		}
		
		window.setTimeout("cnbc_videoAdStarted()",4000);
	}		
	
	var parsedTitle = null;
	var parsedDate  = null;
	var parsedTime  = null;
	var parsedVidID	= null;
	var parsedShow	= null;
	var prop3 		= "";

	//Extract Video ID from Page....
	var curVidID= document.getElementById('videoid');
	if(curVidID!=null)
	{
		parsedVidID	= curVidID.innerHTML;		
	    prop3		= "Right Rail";
	}
	else
	{
		var omnicontentID= document.getElementById('omnicontentID');
		if(omnicontentID!=null)
		{
			parsedVidID=omnicontentID.innerHTML;
		}				
	}
	
	//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= "Right Rail";
	}
	else
	{
		var omnicontentTitle= document.getElementById('omnicontentTitle');

		if(omnicontentTitle!=null)
		{
			if(cnbc_sectionName=='')
				{
					cnbc_docid	= parent.cnbc_docid;
					prop3		= "Embedded";
				}
				else
				{
					prop3= "Permalink";
				}
						
			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= "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);			
		}	
	}
	
	var curShow= document.getElementById('showid');
	if(curShow!=null)
	{	
		parsedShow	= curShow.innerHTML;	
		parsedShow	= parsedShow.toUpperCase();	
	}
	else
	{
		var omnicontentShow= document.getElementById('omnicontentShow');
		if(omnicontentShow!=null)
		{
			parsedShow=omnicontentShow.innerHTML;
			parsedShow=parsedShow.toUpperCase();
		}				
	}
	
	if(parsedTitle!=null)
	{
		window.setTimeout('cnbc_trackOmniture("nbcuglobal, nbcucnbcd, nbcucnbcbu", "cnbc", "cnbc.com", "Video Player","Vid Clip|Video Player|'+parsedVidID+'|'+escape(parsedTitle.substr(0,65))+
						  '","", "free: cnbc.com", "", "","'+cnbc_docid+'","'+prop3+'","'+parsedVidID+
						  '","", "", "", "event6,event20", "", "", "","", "", "", "","'+parsedTime+'","Video Player","Vid Clip","'+parsedVidID+'","'+parsedShow+'")', 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;
	}
	
	function cnbc_getDartShowParam()
	{
		var parsedShow = null;
		
		var curShow= document.getElementById('showid');
		if(curShow!=null)
		{	
			parsedShow	= curShow.innerHTML;		
		}
		else
		{
			var omnicontentShow= document.getElementById('omnicontentShow');
			if(omnicontentShow!=null)
			{
				parsedShow=omnicontentShow.innerHTML;
			}				
		}
		
		if(parsedShow!=null)
		{		
			parsedShow = parsedShow.replace(/$/gi, '' );
			parsedShow = parsedShow.replace(/&/gi, '' );
			parsedShow = parsedShow.replace(/%/gi, '' );
			parsedShow = parsedShow.replace(/'/gi, '' );
			parsedShow = parsedShow.replace(/"/gi, '' );
			parsedShow = parsedShow.replace(/\./gi, '' );
			parsedShow = parsedShow.replace(/,/gi, '' );
			parsedShow = parsedShow.replace(/>/gi, '' );
			parsedShow = parsedShow.replace(/</gi, '' );
			parsedShow = parsedShow.replace(/\\/gi, '' );
			parsedShow = parsedShow.replace(/\//gi, '' );
			parsedShow = parsedShow.replace(/;/gi, '' );
			parsedShow = parsedShow.replace(/:/gi, '' );
			parsedShow = parsedShow.replace(/=/gi, '' );
			parsedShow = parsedShow.replace(/@/gi, '' );
			parsedShow = parsedShow.replace(/;/gi, '' );
			parsedShow = parsedShow.replace(/\+/gi, '' );
			parsedShow = parsedShow.replace(/;/gi, '' );
			parsedShow = parsedShow.replace(/\|/gi, '' );
			parsedShow = parsedShow.replace(/\[/gi, '' );
			parsedShow = parsedShow.replace(/\]/gi, '' );
			parsedShow = parsedShow.replace(/\(/gi, '' );
			parsedShow = parsedShow.replace(/\)/gi, '' );
			parsedShow = parsedShow.replace(/\^/gi, '' );
			parsedShow = parsedShow.replace(/\~/gi, '' );
			parsedShow = parsedShow.replace(/\!/gi, '' );
			parsedShow = parsedShow.replace(/\?/gi, '' );
			parsedShow = parsedShow.replace(/\-/gi, '' );
			parsedShow = parsedShow.replace(/ /gi, '' );
			parsedShow = parsedShow.replace(/_/gi, '' );
			
			return parsedShow.toLowerCase().substring(0,28);
		}
		
		return null;		
	}
	
	function cnbc_getDartVideoParam()
	{
		var parsedVidID= null;
		
		//Extract Video ID from Page....
		var curVidID= document.getElementById('videoid');
		if(curVidID!=null)
		{
			parsedVidID	= curVidID.innerHTML;			    
		}
		else
		{
			var omnicontentID= document.getElementById('omnicontentID');
			if(omnicontentID!=null)
			{
				parsedVidID=omnicontentID.innerHTML;
			}				
		}
		
		return parsedVidID;
	}

    function cnbc_resetFlashPlayer(thumbnail, url)
	{
		window.setTimeout("cnbc_processResetFlashPlayer('"+thumbnail+"','"+url+"')",0);		 	
	}
	
	function cnbc_processResetFlashPlayer(thumbnail, url)
	{
		if(!isWMVFormat())
		{
			var cnbc_flv_releaseURL =escape(url);
	        var cnbc_flv_thumbnailURL=escape(thumbnail);
	         	      
	        var SWFObject = document.getElementById('SWFObject');
	        
	        if(SWFObject!=null)
	        {
	        	//Ensure current player width/height is extracted from current FLASH PLAYER
	        	//already loaded on the page.
	        	var width 	= 350;
	        	var height 	= 300;
		        var flvPlayer = document.getElementById(cnbc_flvPlayer_Id);
		        if(flvPlayer!=null)
		        {
		        	width 	= flvPlayer.width;
		        	height 	= flvPlayer.height;		        	 
		        }
		        
	            SWFObject.innerHTML = AC_FL_GetContent(	  'codebase','http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0', 
	                                                   	  'width', width,
	                                                      'height', height,
		                                                  'src',cnbc_FlashPlayer,
		                                                  'quality', 'high', 
		                                                  'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
		                                                  'align', 'left',
		                                                  'wmode', 'transparent',
		                                                  'id','flashPlayer',
		                                                  'bgcolor', '#ffffff',
		                                                  'salign','tl', 
		                                                  'name', cnbc_flvPlayer_Id,
		                                                  'allowScriptAccess', 'always',
		                                                  'movie',cnbc_FlashPlayer,
		                                                  'FlashVars','thumbnail='+cnbc_flv_thumbnailURL+'&preloadMovie='+cnbc_FlashLoaderURL+'&releaseUrl='+cnbc_flv_releaseURL+'&autoStart=false' );
	        }
	 	}
	}