if(top.location.href != document.location) top.location.href = document.location;

//href
function j(dest,qstr)
{
  var loc = '';
  if (dest != '') loc += '/cg/agg.dll?p=agg&sql=' + dest;
  else loc += '/cg/agg.dll?p=agg';
  if (qstr) loc += qstr;
  document.location = loc;
}

//onclick
function z(dest,qstr)
{
  var loc = '';
  if (dest != '' && qstr == '') loc += '/game.php?id=' + dest;
  if (qstr) loc += '/' + qstr + '.php?id=' + dest;
  if (dest == '' && qstr == '') loc += '/index.php';
document.location = loc;
}

//barnes
function b(upc,btype)
{
  bloc = 'http://service.bfast.com/bfast/click?bfmid=2181&sourceid=4014022' + btype + '&bfpid=' + upc + '&bfmtype=music'
  window.open(bloc);
}

//video detective
function mv(vid)
{
  window.open(vid,'Player','width=750,height=394');
}

//flash
function tokenFlashPass() {
  if ('tokenAvailable' in window) {
	window.document.flashspinner.SetVariable("token", tokenAvailable);
  }
}
function fl(dest)
{
  var loc = '';
  if (location.search.indexOf('usrmgr') != -1) loc = 'http://www.allgame.com/';
  if (dest && 'tokenAvailable' in window) loc += '/cg/agg.dll?p=agg&token=' + tokenAvailable + '&sql=' + dest;
  else loc += '/cg/agg.dll?p=agg';
  document.location = loc;
}
function flbl(dest)
{
  var loc = '';
  if (location.search.indexOf('usrmgr') != -1) loc = 'http://www.allgame.com/';
  if (dest && 'tokenAvailable' in window) loc += '/cg/agg.dll?p=agg&token=' + tokenAvailable + '&sql=' + dest;
  else loc += '/cg/agg.dll?p=agg';
  window.open(loc);
}

//Cookie Function to save preivous search setting
function GetByID(Name) 
{
	return document.getElementById(Name);
}

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function saveSearch()
{
	var SimDB = GetByID("search_opt").value;
	var CookieStart = "SimParam|"  + SimDB;
	
	// create an instance of the Date object
	var now = new Date();
	// fix the bug in Navigator 2.0, Macintosh
	fixDate(now);
	/*
	cookie expires in one year (actually, 365 days)
	365 days in a year
	24 hours in a day
	60 minutes in an hour
	60 seconds in a minute
	1000 milliseconds in a second
	*/
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

	ValidSimpleSearchData = false;
	
	if (GetByID("search_txt").value == "")
	{
		alert("Invalid Search Query: Search criteria cannot be blank");
	}
	else
	{
		//alert(SimDB);
		setCookie("SimDB", SimDB, now , "/cg/", "allgame.com");
		setCookie("SimDB", SimDB, now , "/", "allgame.com");
		ValidSimpleSearchData = true;
	}	
	
	return ValidSimpleSearchData
}

function toggleSearch()
{
	var SimDB = getCookie("SimDB");
	//alert(SimDB)	
	if (SimDB != undefined)
	{
		GetByID("search_opt").value = SimDB;
	}

	
}

function initMenu() {
	var oMenuItems = document.getElementById("header_menu").getElementsByTagName("a");
	for (var i=0;i<oMenuItems.length;i++) {
		var oItem = oMenuItems[i];
		oItem.style.backgroundImage='url(img/menu_bar/'+oItem.id+'.gif)';
		oItem.onmouseover = function () {this.style.backgroundPosition='top center';}
		oItem.onmouseout = function () {this.style.backgroundPosition='0px -100px';}

		if (navigator.userAgent.indexOf("Opera")>=0) {
			if (oItem.id.indexOf("sub_menu")>=0) {
				oItem.onmouseover = function () {this.style.backgroundPosition='center -5px';}
			} else {
				oItem.onmouseover = function () {this.style.backgroundPosition='top center';}
			}
		}

		if (navigator.userAgent.indexOf("Safari")>=0) {
			oItem.style.backgroundImage=''
			oItem.style.backgroundPosition='0px 0px'
			oItem.onmouseover = function () {this.style.backgroundImage='url(img/menu_bar/'+this.id+'.gif)'}
			oItem.onmouseout = function () {this.style.backgroundImage=''}
		}
	}
}

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
}
