String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); }
Array.prototype.contains = function(x) { for (var i = 0; i < this.length; i++) { if (this[i] == x) return true; } return false; } 
Array.prototype.shuffle = function() { var result = this.concat(); for (var i = 0; i < result.length; i++) { var j = i; while (j == i) { j = Math.floor(Math.random() * result.length); } var contents = result[i]; result[i] = result[j]; result[j] = contents; } return result; };

// --------------------------------------------------------
function GetQueryStringValue(name)
{
   var value = "";
   var location = window.location.toString();	    
   if( location.indexOf(name+"=") > -1 )
   {
      value = location.substring(location.indexOf(name+"=")+name.length+1);
   }
   return ( value.indexOf("&") > -1 ? decodeURI(value.substring(0,value.indexOf("&"))) : decodeURI(value));
}

// --------------------------------------------------------
function GetQueryString()
{

   var value = "";
   var location = window.location.toString();	    
   if( location.indexOf("?") > -1 )
   {
      value = location.substring(location.indexOf("?")+1);
   }
   return ( decodeURI(value));
}

// --------------------------------------------------------
function SetCookie( name, value, expDays, path, domain, secure ) 
{
    // set expiration
    var expDate = new Date();
    expDate.setTime( expDate.getTime() + (expDays * 1000 * 60 * 60 * 24) );

    document.cookie = name + "=" + value +
        ( ( expDays > 0 ) ? ";expires=" + expDate.toGMTString() : "" ) + 
        ( ( path ) ? ";path=" + path : "" ) + 
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );        
}

// --------------------------------------------------------
function DeleteCookie( name, path, domain ) 
{
    document.cookie = name + "=" +
          ( ( path ) ? ";path=" + path : "") +
          ( ( domain ) ? ";domain=" + domain : "" ) +
          ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// --------------------------------------------------------
function GetCookie(name) 
{ 
    var arg = name + "="; 
    var alen = arg.length; 
    var clen = document.cookie.length; 
    var i = 0; 
    while (i < clen) 
    { 
        var j = i + alen; 
        if (document.cookie.substring(i, j) == arg) 
        {
           var eCookieIx = document.cookie.indexOf (";", j); 
           if (eCookieIx == -1) { eCookieIx = document.cookie.length; }
           return unescape(document.cookie.substring(j, eCookieIx));
        }
        i = document.cookie.indexOf(" ", i) + 1; 
        if (i == 0) break; 
    } 
    return null;
}

// --------------------------------------------------------
function GetCookieVal(cookie,name) 
{ 
    var value = "";
    var sValIx = cookie.indexOf(name+"=");
    if( sValIx >= 0 )
    {
       eValIx = cookie.indexOf("&",sValIx+name.length+1);
       if( eValIx == -1 ) { eValIx = cookie.length; }
       value = cookie.substring(sValIx+name.length+1,eValIx);
    }
    
    return value;
}

// --------------------------------------------------
function GetWinSize()
{
   var sizeOfX = 0, sizeOfY = 0;
   if( typeof( window.innerWidth ) == 'number' ) 
   {
      // Firefox compliant
      sizeOfX = window.innerWidth;
      sizeOfY = window.innerHeight;
   } 
   else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
   {
      // IE 6+ in 'standards compliant mode'
      sizeOfX = document.documentElement.clientWidth;
      sizeOfY = document.documentElement.clientHeight;
   } 
   else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
   {
      // IE 6 compatible
      sizeOfX = document.body.clientWidth;
      sizeOfY = document.body.clientHeight;
   }

   return [ sizeOfX, sizeOfY ];
}

// --------------------------------------------------
function ShowFullScreenMode()
{
	 var winLoc = window.location.toString();
	 winLoc += (winLoc.indexOf("?") > - 1 ? "&" : "?") + "fullscreen=1";
	 var FreeGamesToPLayFullScreenWin = window.open(winLoc,"FreeGamesToPLayFullScreenWin","fullscreen=yes, toolbar=no, scrollbars=yes, resizable=yes, status=no, directories=no, copyhistory=no, location=no, menubar=no");
	 FreeGamesToPLayFullScreenWin.focus();
}

// --------------------------------------------------
function TestFullScreenMode(title)
{
	 var winLoc = window.location.toString();
 	 winLoc = "http://shockwavegames.us/game/" + title.substring(0,1).toLowerCase() + "/" + title.toLowerCase() + "/";
	 winLoc += (winLoc.indexOf("?") > - 1 ? "&" : "?") + "fullscreen=1";
	 var FreeGamesToPLayFullScreenWin = window.open(winLoc,"FreeGamesToPLayFullScreenWin","fullscreen=yes, toolbar=no, scrollbars=yes, resizable=yes, status=no, directories=no, copyhistory=no, location=no, menubar=no");
	 FreeGamesToPLayFullScreenWin.focus();
}

// --------------------------------------------------
function WinCloseGameFrame(p)
{
	if( parent == p )
	{
		return;
	}

	var winLoc = window.location.toString();	
	var slashIx = winLoc.indexOf("/",8)+1;
	if( winLoc.indexOf("localhost") > - 1 )
	{
		slashIx = winLoc.indexOf("/",slashIx)+1;
	}
	winLoc = winLoc.substring(0,slashIx);
	if( typeof(document.gameFrame) != "undefined" )
	{
		document.gameFrame.location.replace(winLoc + "fullscreenMsgWin.php?id="+gameId);
	}
	else
	{
		document.getElementById('gameFrame').contentWindow.location.replace(winLoc + "fullscreenMsgWin.php?id="+gameId);
	}
}

//var winMouseX=0,winMouseY=0;
//document.onmousemove = getMouseXY;
// --------------------------------------------------
function getMouseXY(e) 
{
	if (window.event) 
	{
		 // grab the x-y pos.s if browser is IE
		winMouseX = window.event.clientX;
		winMouseY = window.event.clientY;
	}
	else 
	{ 
		// grab the x-y pos.s if browser is NS
		winMouseX = e.pageX;
		winMouseY = e.pageY;
	}
} 
// --------------------------------------------------
function ShowGameDetails(src)
{
   var lImgFile = src.substring(0,src.indexOf(".")-1) + "l.jpg";
	 document.getElementById("DynamicThumbDiv").innerHTML = '<img src="' + lImgFile + '">';
	 document.getElementById("DynamicThumbDiv").style.top = winMouseY+5;
	 document.getElementById("DynamicThumbDiv").style.left = winMouseX+5;	 
}

// --------------------------------------------------
function HideGameDetails()
{
	 document.getElementById("DynamicThumbDiv").style.top = -1000;
	 document.getElementById("DynamicThumbDiv").style.left = -1000;	 
}

// --------------------------------------------------
function RedirectGame(url)
{
	 window.location = url;
}

// --------------------------------------------------
function ShowGameTitle(thumbType,id)
{
	if( document.getElementById(thumbType+'Thumb'+id).offsetHeight > 0 )
	{
		document.getElementById(thumbType+'Thumb'+id).style.top = "-" + (document.getElementById(thumbType+'Thumb'+id).offsetHeight+1) + "px";	
	}
	else
	{
		setTimeout("ShowGameTitle('"+thumbType+"',"+id+");",300);
	}
}