
/**
*
*  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);
}

/*
 * Cookie functions -- taken from:
 * http://www.quirksmode.org/js/cookies.html
 */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/*
 * Cookie functions -- modified from:
 * http://www.quirksmode.org/js/cookies.html
 */
function createShortTermCookie(name,value,minutes) {
	if (minutes) {
		var date = new Date();
		date.setTime(date.getTime()+(minutes*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/*
 * Returns the value of the named cookie, or null if no such cookie
 * exists.
 */
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/*
 * Deletes the specified cookie.
 */
function eraseCookie(name) {
	createCookie(name,"",-1);
}

/*
 * 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 = readCookie("blvdSessionId");
	if (blvdSessionId == null) blvdSessionId = '';
	
	//	Generate the dynamic javascript tag
	var scriptTag = document.createElement("script");
	scriptTag.src =
		"http://www.blvdstatus.com/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;
}