
/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
*	[CB] Compressed by YUI Compressor
**/
var Url={encode:function(A){return escape(this._utf8_encode(A))},decode:function(A){return this._utf8_decode(unescape(A))},_utf8_encode:function(B){B=B.replace(/\r\n/g,"\n");var A="";for(var D=0;D<B.length;D++){var C=B.charCodeAt(D);if(C<128){A+=String.fromCharCode(C)}else{if((C>127)&&(C<2048)){A+=String.fromCharCode((C>>6)|192);A+=String.fromCharCode((C&63)|128)}else{A+=String.fromCharCode((C>>12)|224);A+=String.fromCharCode(((C>>6)&63)|128);A+=String.fromCharCode((C&63)|128)}}}return A},_utf8_decode:function(A){var B="";var C=0;var D=c1=c2=0;while(C<A.length){D=A.charCodeAt(C);if(D<128){B+=String.fromCharCode(D);C++}else{if((D>191)&&(D<224)){c2=A.charCodeAt(C+1);B+=String.fromCharCode(((D&31)<<6)|(c2&63));C+=2}else{c2=A.charCodeAt(C+1);c3=A.charCodeAt(C+2);B+=String.fromCharCode(((D&15)<<12)|((c2&63)<<6)|(c3&63));C+=3}}}return B}};

/*
 *	Digg friendly URLEncode function -- taken from:
 *	http://cass-hacks.com/articles/code/js_url_encode_decode/
 *	[CB] Modified to use %20 instead of + for spaces
 * 	[CB] Replaced by webtoolkit's URL encoder
 */
function URLEncode (clearString) {
  return Url.encode(clearString);
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires )
	{
		//expires = expires * 1000 * 60 * 60 * 24;
		expires = expires * 60 * 1000;
    }
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function 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

	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;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

/*
 * Utility function to test if another object is actually a function.
 */
function isFunction(object) {
	return (object && typeof(object) == 'function');
}

/*
 * The afterLoad function, which is responsible for triggering the
 * dynamic JavaScript pull.
 */
function afterLoad() {
	//	We call all the existing onload functions _first_,
	//	in the hope that if they modify the document we
	//	will catch the changes.
	if (isFunction(chain_onload)) {
		chain_onload();
	}
	
	//	Check and see if we have a BLVD session cookie,
	//	if so, maintain that session value. If not, a session
	//	value will be generated by the PHP script.
    var blvdSessionId = Get_Cookie('blvdS');
    if(blvdSessionId) {
    	Set_Cookie('blvdS', blvdSessionId, 30,'/');
    } else {
        blvdSessionId = 's4b70fc9159ec55.27278761';
        Set_Cookie('blvdS', blvdSessionId, 30,'/');
    }    
	
	//	Generate the dynamic javascript tag
	var scriptTag = document.createElement("script");
	scriptTag.src =
		"http://www.blvdstatus.com/app/js/dynamicJS.php" +
		"?blvdSessionId=" + blvdSessionId + 
		"&referrer=" + URLEncode(document.referrer) +
		"&title=" + URLEncode(document.title) +
		"&screenWidth=" + screen.width +
		"&screenHeight=" + screen.height +
		"&screenDepth=" + screen.colorDepth +
		"&ait=false" +
		"&tid="
	;
	
	var bodyNode = document.getElementsByTagName("body")[0];
	bodyNode.appendChild(scriptTag);
}

/*
 * Chain the BLVD afterLoad function into the OnLoad event handler.
 * We store the current OnLoad handler first so we can call it
 * from our own function.
 */

if (isFunction(window.addEventListener)) {
	window.addEventListener('load', afterLoad, false);
} else if (isFunction(window.attachEvent)) {
	window.attachEvent('load', afterLoad);
} else {
	var chain_onload = window.onload;
	window.onload = afterLoad;
}