
_version=11;
if (navigator.userAgent.indexOf('Mozilla/3') != -1) {
	_version=10;
}

var oas="http://ads.mgnetwork.com/RealMedia/ads/";
var RN = new String (Math.random());
var RNS = RN.substring (2,11);
var sitepage = "boxerjam.com/index.shtml"; 
function DisplayOasAd (position) {
	var oaspage = sitepage + '/1' + RNS + '@' + position;
	if (_version < 11) {
		document.write ('<a href="' + oas + 'click_nx.ads/' + oaspage + '" target="_top"><img src="' + oas + 'adstream_nx.ads/' + oaspage + '" border="0"></a>');
	} else {
		document.write ('<script language="JavaScript1.1" src="' + oas + 'adstream_jx.ads/' + oaspage + '"><\/script>');
	}
}

function popGameHouse(url, w, h) {
	var madURL = url;
	var x, y, winStr;
	x=0; y=0;
 	self.name="opener";
	winStr = "height="+h+",width="+w+",screenX="+x+",left="+x+",screenY="+y+",top="+y+",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0";
	lilBaby = window.open(madURL, "_blank", winStr);
}

function launchPlaytoniumJigsaw(v) {
  // v = vendor id <--- optional, defaults to ""
  if (typeof v == "undefined") { v = ""; }
  w = 640;
  h = 480;
  theURL = "http://playtonium.com/jigsaw/vjs.php?v=" + v;
  winName = "vjigsaw";
  features = "toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes";
  winW = Math.min(w, window.screen.availWidth);
  winH = Math.min(h, window.screen.availHeight);
  sX = parseInt(window.screen.availLeft);
  sY = parseInt(window.screen.availTop);
  lt = ",left=" + sX + ",top=" + sY + ",screenX=" + sX + ",screenY=" + sY + ",";
  features = features + lt + "width=" + winW + ",height=" + winH;
  winRef = window.open(theURL,winName,features);
}

function launchPlaytoniumWordsense(v) {
  // v = vendor id <--- optional, defaults to ""
  if (typeof v == "undefined") { v = ""; }
  w = 600;
  h = 440;
  theURL = "http://playtonium.com/wordsense/vws.php?v=" + v;
  winName = "vws";
  features = "toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes";
  winW = Math.min(w, window.screen.availWidth);
  winH = Math.min(h, window.screen.availHeight);
  sX = parseInt(window.screen.availLeft);
  sY = parseInt(window.screen.availTop);
  lt = ",left=" + sX + ",top=" + sY + ",screenX=" + sX + ",screenY=" + sY + ",";
  features = features + lt + "width=" + winW + ",height=" + winH;
  winRef = window.open(theURL,winName,features);
}

function setGuestCountCookie(count){
	count++;
	var exp = new Date();
	var oneYearFromNow = exp.getTime() + (365 * 24 * 60 * 60 * 1000);
	exp.setTime(oneYearFromNow);
	// guestPlayerCount
	document.cookie = "gsplct=" + count + ";expires=" + exp.toGMTString() + ";path=/;domain=boxerjam.com";
}

function getCookieVal(arg){
        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 endstr = document.cookie.indexOf (";",j);
                        if (endstr == -1){
                                endstr = document.cookie.length;
                        }
                        return (unescape(document.cookie.substring(j, endstr)));
                }
                i = document.cookie.indexOf(" ",i)+1;
                if (i == 0) {
			return(0);
		}
        }
}

function popGame() {
	var startGame = true;
	var playerName = getCookieVal("BJInfo=NAME%3D");
	if ((playerName)&&(playerName.substr(0,5) == "guest")){
	        var GuestPlayCount = getCookieVal("gsplct=");
		setGuestCountCookie(GuestPlayCount);
		if (GuestPlayCount > 6){ // zero based count, so 7 games allowed
			startGame = false;
		}
	}
	if(startGame){
		if (w == "newpage" && h == "newpage"){
			document.location = page;
		}else{
			game = window.open(page,'_blank','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,width=' + w + ',height=' + h);
			timer = setTimeout('detectKiller()', 1000);
			game.opener = self;
			game.focus();
		}
	}else{
		document.location = "/util/login.php?notsi=notsi";
	}
}

function detectKiller() {
  clearTimeout(timer);
  if (!game || game == null || game.closed) {
    alert("The game window failed to open!\nPLEASE CLICK PLAY AGAIN\n\nIf you are using a pop-up window killer,\nplease disable it so you can play our games.");
  } else {
 		game.opener = self;
  }
  window.location = "index.php?dontIncludeAd=true";
  // removing the ads from the game launch page behind the client cause they were eating up all CPU
}

function popPreview() {
  preview = window.open('preview.html','preview','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=380,height=210');
  preview.opener = self;
}

function alertDown() {
  alert("This Game is temporarily down for maintenance.\nFeel free to explore the rest of our site,\nand please try again in a few minutes.");
}

function popScreenShot(picURL,x,y) {
	newWindow=window.open(picURL,'newWin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,scroll=0,resizable=0,width='+x+',height='+y)
	newWindow.document.write('<html><head><title>Screen Shot<\/title><\/head><body bgcolor="#000000" topmargin="0" leftmargin="0"><a href="javascript:window.close()"><img src="'+picURL+'" border="0"><\/a><\/body><\/html>')
	newWindow.focus()
}
