var tzo = new Date().getTimezoneOffset();
document.cookie = "clientTimezoneOffset=" + escape(tzo * (-1))+ "; path=/; Domain=gamesradar.com";

/* START: advertisements */
		var ord=Math.random()*10000000000000000;
		var AD_TILE=0;

		/* START: 300x600 ad rss handling */
		function loadRSS(){
			var getRSSText = top.frames["getRSSFrame"].generate_rss_feeds();
		}
		/* END: 300x600 ad rss handling */

		/* START: skin ad handling */
		function swapBgr(getURL)
		{
			document.body.style.backgroundImage=url(getURL);
			document.body.style.backgroundAttachment='fixed';
			document.body.style.backgroundPosition ='top center';
			document.body.style.backgroundRepeat='no-repeat';
		}
		/* END: skin ad handling */

/* END: advertisements */

/* START: cookie handling */

		function Get_Cookie(name){
			var start = document.cookie.indexOf(name + "=");
			var len = start + name.length + 1;

			if((!start) && (name != document.cookie.substring(0, name.length))){
				return null;
			}

			if(start == -1 ) return null;

			var end = document.cookie.indexOf(";", len);
			if ( end == -1 ) end = document.cookie.length;

			return unescape( document.cookie.substring( len, end ) );
		}

		function setSession(name, platform){
			var cookieVal = Get_Cookie(name);

			if(cookieVal == null) cookieVal = "";

			var theCookie = name + "=" + cookieVal + platform.toUpperCase() + "|; path=/; Domain=gamesradar.com";
			//alert(theCookie);
			document.cookie=theCookie;
		}

		function getSession(name, platform){
			//ist settings
			var offset = 0;
			var freq = 2;
			var max = 3;  //otherwise known as cap

			//session determinant processing
			var cookieVal = Get_Cookie(name);
			var doesPlatformExist = false;
			var result = "";
			if(cookieVal != null){
				result = cookieVal.split("|");
				for(var i=0; i < result.length; i++){
					if(result[i].toUpperCase() == platform.toUpperCase()){
						doesPlatformExist = true;
						break;
					}
				}
			}

			//return processing
			if(doesPlatformExist == true){
				return 'true';
			}else{
				setSession(name,platform); //track requested session
				if(offset == 0 && result == ""){
					return false;
				}else{
					if(result.length == offset || ( ((freq*max)+offset) >= result.length+1 && result.length+1 > offset && ((result.length+1-offset)%freq == 0) ) ){
						return 'false';
					}else{
						return 'true';
					}
				}
			}
		}

		function setISTSession(platform){
			setSession("ist", platform);
		}

		function getISTSession(platform){
			return getSession("ist", platform);
		}

/* END: cookie handling */

/* START: video player functions */

		//pop up window
		function openCenteredWindow(URL,params,winName,w,h,winfeatures) {
			var left = 0;
			var top = 0;
			var w = screen.availWidth;
			var h = screen.availHeight;
			var encodedParams = escape(params);
			var newWin = window.open(URL+encodedParams,winName,'width='+w+',height='+h+',left='+left+',top='+top+'toolbar=0,menubar=0,location=0,resizable=0,scrollbars=no,status=no,'+winfeatures);
			newWin.moveTo(left,top)
			newWin.focus();
		}

		// adds a function to the page onload, so we don't overwrite existing onload functions
		function addOnLoad(f) {
		    var currentOnLoad = window.onload;
		    if (typeof window.onload != "function") {
		        window.onload = f;
		    } else {
		        window.onload = function() {
		            currentOnLoad();
		            f();
		        }
		    }
		}

/* END: video player functions */

/* START: page syndication functions */
	//share a page via socialmarker
	function sharePage(text){
		window.location = 'http://www.socialmarker.com/?link='+encodeURIComponent (location.href)+'&title='+encodeURIComponent( document.title)+'&text='+encodeURIComponent(text);
	}
/* END: page syndication functions */

/* START: comment functions */
	//go to top of comments
	function goToComments(){
		document.getElementById("article_comments_content").focus();
	}
	//set focus to submit a comment
	var commentSubmitToggle = false;
	function goToSubmitComment(){
		if(commentSubmitToggle == false){
			document.getElementById("inlineComment").style.display = "block";
			// top.frames["inlineAddCommentFrame"].document.getElementById("comment_body").focus();
			commentSubmitToggle = true;
		}else{
			document.getElementById("inlineComment").style.display = "none";
			// document.getElementById("article_comments_top").focus();
			commentSubmitToggle = false;
		}
	}

/* END: comment functions */

/* START: string functions */
	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function ltrim(stringToTrim) {
		return stringToTrim.replace(/^\s+/,"");
	}
	function rtrim(stringToTrim) {
		return stringToTrim.replace(/\s+$/,"");
	}
/* END: string functions */

function callThickBox(getUrl) {
	var fc = document.getElementById("flashcontent");
	var hf = document.getElementById("hotarmorflash");
	var gr = document.getElementById("grPanorama");
	var cp = document.getElementById("cpPanorama");
	if (fc != null) {
		fc.style.visibility = 'hidden';
	}
	if (hf != null) {
		hf.style.visibility = 'hidden';
	}
	if (gr != null) {
		gr.style.visibility = 'hidden';
	}
	if (cp != null) {
		cp.style.visibility = 'hidden';
	}
	var current_url = window.parent.location.href;
   	var regexp = /screenshots\/(.*)\/pic-/;
	var test_result = regexp.test(current_url);
	if (test_result) {
		window.parent.location.href = "/radarnation/login";
	} else {
		tb_show(null, getUrl, false);
 		setTimeout("thickboxLoginFocus();", 1500);
	}
}

function thickboxLoginFocus() {
	var login = document.getElementById('thickbox_login');
	if (login) {
		login.focus();
	} else {
 		setTimeout("thickboxLoginFocus();", 1000);
	}
}
