thisURL = this.location.href;

//Get author - utility function used by chartbeat
function Meta() {
	var m = document.getElementsByTagName('META');
	this.meta = {};
	for(var i=0;i<m.length;i++) this.meta[m[i].name] = m[i].content;
}
Meta.prototype.get = function(n) {return this.meta[n];}
meta = new Meta();
		
// Utility functions used by bluekai
var phatcatId = '35415301490';
function isMember() {
        forbes0 = document.cookie.indexOf('forbesmemb=');
        forbes1 = document.cookie.indexOf('forbesmemb_confirm=');
        if (forbes0 != -1 && forbes1 != -1 && findCookie('forbesmemb') != phatcatId)
                return true;
        else 
                return false;
}
function findCookie(NameOfCookie) {  
	if( document.cookie.length > 0 ) { 
		begin = document.cookie.indexOf( NameOfCookie+"=" ); 
		if( begin != -1 ) { 
			begin += NameOfCookie.length + 1; 
			end = document.cookie.indexOf( ";", begin );
			if( end == -1 ) end = document.cookie.length;
			return unescape( document.cookie.substring( begin, end ));
		} 
	}
	return null; 
}

//Start bluekai
function bluekai(){

	var forbesMember = "";
	if(isMember()){
		forbesMember = findCookie('forbesmemb');
	}
	
	//find partner
	var partner = findCookie('s_p_name');
	if(partner == null){
		partner = "";
	}
	document.write('<script type="text/javascript" src="http://tags.bluekai.com/site/3536?ret=js&phint=channel%3D' + displayedChannel + '&phint=section%3D' + displayedSection + '&phint=member%3D' + forbesMember + '&phint=partner%3D' + partner + '"></script>');
}
//End bluekai


//** Start Adx call - used by fast call **/
function Adx_Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	var i = '';

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

//** End Adx call **/

// get canonical url - used by chartbeat and cognitive match
function getCanonicalUrl(){
	
    linkElements = document.getElementsByTagName("link");
    canonicalUrl = "";
    for (i = 0; i < linkElements.length; i++) {
        if((typeof linkElements[i].attributes['rel'] != "undefined") && (linkElements[i].attributes['rel'].nodeValue == "canonical")){
			canonicalUrl = linkElements[i].attributes['href'].nodeValue;
			break;
		}
    }
	return canonicalUrl;

}

function cognitivematch(){
   cmURL = getCanonicalUrl();
   if(cmURL == ""){
		cmURL = thisURL;
   }
   document.write('<img src="http://engine.cmmeglobal.com/evt?sn=forbes&itm=' + encodeURIComponent(cmURL) + '"/>');
}

// fps - forbesproxysignature
	(function(){function f(){var k=document.getElementsByTagName("META");this.meta={};for(var l=0;l<k.length;l++){this.meta[k[l].name]=k[l].content}}f.prototype.get=function(k){return this.meta[k]};meta=new f();if(navigator.appName=="Microsoft Internet Explorer"){document.write('<div id="pzndiv"></div>')}else{var d=document.createElement("div");d.id="pzndiv";document.body.appendChild(d)}var b="?"+a();var j=document.createElement("img");j.width=1;j.height=1;j.src="http://fast.forbes.com/fps/cookie_backup.php"+b;document.getElementById("pzndiv").appendChild(j);if(!Adx_Get_Cookie("google")){var g=document.createElement("img");g.width=1;g.height=1;g.src="http://cm.g.doubleclick.net/pixel?nid=forbes";document.getElementById("pzndiv").appendChild(g)}function a(){var l=window.displayedSection||"";var k="";if(document.referrer&&document.referrer.match(/^(?!http:\/\/(.[^/]+)\.forbes\.com)http(s)?:\/\/(.[^/:]+)/)){k=document.referrer.match(/^http(s)?:\/\/(.[^/:]+)/)[2]}else{if(document.referrer&&"http://www.forbes.com/fdc/welcome_mjx.shtml"==document.referrer&&document.cookie.indexOf("wg_originalReferrer=")!=-1&&window.wg_extdom&&wg_extdom){k=document.cookie.match("wg_originalReferrer=http(s)?://(.[^/:]+)(;|$)")[1]}}return c({op:"user_msg",sh:window.screen&&window.screen.height||"",sw:window.screen&&window.screen.width||"",ch:window.displayedChannel||"",se:l,ti:l==="companytearsheets"&&window.cTicker||"",pt:window.pageType||"",su:h(),re:k,pa:e("partner"),fps:getStandaloneCookie("fps")||"",au:meta.get("author")})}function c(m){var l=[];for(var k in m){if(undefined!==m[k]&&""!==m[k]){l.push(k+"="+escape(m[k]))}}return l.join("&")}function e(k){var n=window.location.search.substring(1).split("&");for(var l=0;l<n.length;l++){var m=n[l].split("=");if(m[0]==k){return m[1]}}return""}function h(){linkElements=document.getElementsByTagName("link");canonicalUrl="";for(i=0;i<linkElements.length;i++){if((typeof linkElements[i].attributes.rel!="undefined")&&(linkElements[i].attributes.rel.nodeValue=="canonical")){canonicalUrl=linkElements[i].attributes.href.nodeValue;return canonicalUrl}}locationUrl=this.location.href.substring(0,this.location.href.indexOf("?"))||this.location.href||"";return locationUrl}})();
	
//if the url contains slide_2.html
if(thisURL.match("slide_2.html")){
	
	//// Chartbeat - 2nd script start, 1st script is in s_code_forbescom.js
	var _sf_async_config={uid:17493,domain:"forbes.com"};
	var chartbeat_section = "";
	if(displayedSection != ""){
		chartbeat_section = "," + displayedSection;
	}
	_sf_async_config.sections = displayedChannel + chartbeat_section;
	var chartbeat_author = meta.get('author');
	if(chartbeat_author == null){
	   chartbeat_author = "";
	}
	_sf_async_config.authors = chartbeat_author;
	
	if(getCanonicalUrl() != ""){
		_sf_async_config.useCanonical = true;
	}
	
	(function(){
		function loadChartbeat() {
			window._sf_endpt=(new Date()).getTime();
			var e = document.createElement('script');
			e.setAttribute('language', 'javascript');
			e.setAttribute('type', 'text/javascript');
			e.setAttribute('src',
			(("https:" == document.location.protocol) ? "https://a248.e.akamai.net/chartbeat.download.akamai.com/102508/" :
			"http://") +
			"static.chartbeat.com/js/chartbeat.js");
			document.body.appendChild(e);
		}
		var oldonload = window.onload;
		window.onload = (typeof window.onload != 'function') ?
		loadChartbeat : function() { oldonload(); loadChartbeat(); };
	})();
	
	// bluekai
	bluekai();
	
	// Krux
	krux();
	
	//cognitivematch
	cognitivematch();
	
}
	

