// adsAreDisabled is set by http://login.gamespy.com/ads/jscheck.aspx 
var new_adsAreDisabled = adsAreDisabled;

function doesCookieExist(label) { // simply returns the appropriate cookie information
 var labelLen = label.length;
 var cLen = document.cookie.length;
 var new_cLen = 0;
 var i = 0;
 while (i < cLen) {
	var j = i + labelLen;
	if (document.cookie.substring(i,i+3) == "ATA") { // we don't want the ATABeacon cookie
		i += 4;
	}
	if (document.cookie.substring(i,j) == label) {
		var cEnd = document.cookie.indexOf(";",j);
		if (cEnd == -1) {
			cEnd = document.cookie.length;
		}
	new_cLen = unescape(document.cookie.substring(j,cEnd)).length;
	}
 i++;
 } // end while
 if (new_cLen > 0) { 
 	return true; 
 } else { 
	return false; 
 }
} // end function

if ( doesCookieExist('76hgd762hlk') && doesCookieExist('plprof') ) {
new_adsAreDisabled = true;
}

// onclick linktracker that uses ata
function gspy_trackclick(aid) {
	var now      = new Date();
	var random   = now.getTime();
	var ref 	 = "&r=" + escape(document.location);
		ref      = ref.split('/').join('%2F');
		ref      = ref.split('.').join('%2E');
		ref      = ref.split('%').join('$');		
	var origin = document.location.toString().substring(7); /* convert location to string, trim http:// */
		origin = origin.substring(0,origin.indexOf('/')); /* pull subdomain only */
		aid = aid + "-" + origin;
	var lnk      = "&p=http://www.ignlinktrack.com/" + aid;
		lnk      = lnk.split('/').join('%2F');
		lnk      = lnk.split('.').join('%2E');
		lnk      = lnk.split('%').join('$');
        i = new Image();
        i.src  = "http://atax.gamespy.com/network=gamespy&size=1x1" + lnk + ref + "&name=ATAtracker?"+ random + "\" height=\"1\" width=\"1\" style=\"position: absolute; visibility: hidden";
}

// allows a search with radio buttons. this function is GameSpy specific, other network includes have diff site values
function multiSiteSearchSubmit(form) {
	qry = urlEncode(form.query.value);
	if (qry=="") { alert('Please type in your search query.'); return; } // check for empty strings 
	redir = "";
	if (form.domain[0].checked) { // assumes global WebSearch is listed first
		redir = "http://search.gamespy.com/web?query= " + qry;
	} else if (form.domain[1].checked) { // assumes site search is second
		redir = "http://search.gamespy.com/products?query=" + qry;
	}
	gotoval = redir;
	if (gotoval != "") { document.location=gotoval; }
	return;
}

// allows section controllers to check parameters passed in URL strings 
function checkParam(param,value) {
p = new String(document.location);
p = p.substring( p.indexOf('?')+1 , p.length );
var compareField = new String(param);
if (p.indexOf(compareField) > -1) { 
	var compareValue = new String(value);
	pArray = p.split("&");
	k = pArray.length;
	for (i= 0 ; i < k; i++) {
		keyVal = pArray[i].split('=');
		if (keyVal.length != 2) { 
			continue; 
		}
		if (keyVal[0] == compareField && keyVal[1] == compareValue) { 
			return true; 
		}
	}
 }
return false;
}

// checks to see if the parameter matches the current locale or if a setLocale parameter was passed in the url
function  checkLocale(LOCALE){
		urlLocale = getLocale();
		paramLocale = LOCALE;		
	if (urlLocale == paramLocale){ return true; }
	if (checkParam('setLocale',paramLocale)){ return true; }
return false;
}

//gets the locale by using a regular expression to grab whatever is between the first '//' and the first '.' in the url
function getLocale(){
  p = new String(document.location);
  regx = /\/\/(\w.*?)\./;
  result = p.match(regx);
	if ( result != null ) { return result[1]; }
}
