// GAMES functions

var regbuy = "http://www.regnow.com/softsell/nph-softsell.cgi?";
var regaff = "http://www.regnow.com/softsell/visitor.cgi?affiliate=19083&action=site&";
var winfeat = 'toolbar=yes,status=yes,scrollbars=yes,resizable=yes,width=760,height=600';

function browser_mac() { return (navigator.appVersion.indexOf("Macintosh") != -1); }
function safari_mac() { return (navigator.appVersion.indexOf("Safari") != -1); }

function macError() {
  if (browser_mac()) {
    alert("We're sorry.  This game is not available for Macintosh.");
    return false;
  }
  else { return true; }
}


/**
 * Play a web game iframe
 *
 * @argument gameID - real game uid
 * @argument width - width of the iframe, made larger for the width of the window
 * @argument height - height of the iframe, made larger for the height of the window
 */
function webPlay(gameID, width, height) {
	if (gDisableLogin != true) {
		// If we dont have email on file prompt for it before download
	  if (!isValidMember()) {
			window.location = "/members/get_email";
			return false;
		}
	}

  if (width == null || width == 0) {
    width = 800;
  }
  if (height == null || height == 0) {
    height = 700;
  }
  // Put parameter string together...
  var pars = "width=" + width + "&height=" + height;
  // Make the width&height of the window larger than the iframe
  width = width + 100;
  height = height + 40;

  if (screen.width > 800) {
    features = 'status=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height;
  } else {
    features = 'status=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height;
  }
  theURL = "/games/show_web_game/"+ gameID +"?"+ pars;

  // count this as a download
  countDownload(gameID, "web");

  window.open(theURL, 'WebGame', features);
}

/**
 * Standard download method. Opens a new window to gamehouse & fires off ajax request to
 * increment the download counter of the game downloaded.
 */
function openDownloadWindow(theUrl, gameID, platform) {
	if (gDisableLogin != true) {
		// If we dont have email on file prompt for it before download
	  if (!isValidMember()) {
	    showPopWin("/members/get_email?referer="+theUrl, 600, 350);
			return false;
		}
	}

  // alert(theURL);
  window.open(theUrl, "downloadWindow", "top=300,left=300,height=350,width=640,status=no,toolbar=no,menubar=no,location=no");
  // increment download counter
  countDownload(gameID, platform);
}


/**
 * Counts a game as downloaded
 */
function countDownload(gameID, platform, callback) {
  var pars = "gameID="+ gameID +"&platform="+ platform;
  if (callback == null) {
    var ajax = new Ajax.Request(
      '/games/increment_download/',
      {method: 'get', parameters: pars}
    );
  } else {
    var ajax = new Ajax.Request(
      '/games/increment_download/',
      {method: 'get', parameters: pars, onComplete: callback}
    );
  }
}

/**
 * Counts download then fires off the real game download afterwards.
 */
function dld(gameID) {
  //alert(validMember);
  if (gDisableLogin != true) {
	  // If we dont have email on file prompt for it before download
	  if (!isValidMember()) {
			window.location = "/members/get_email";
			return false;
		} else {
			countDownload(gameID, "real", dldGame);
		}
	} else {
		countDownload(gameID, "real", dldGame);
	}
}

function dldCount(gameID) {
   if (gameID != 0) {
     //alert('counting game');
     countDownload(gameID, "real");
   } else {
     //alert('already counted');      
   }
}

/**
 * Done as a callback when incrementing the download counter is done
 */
function dldGame(originalRequest) {
	// Game ID is passed back from the server...
	gameID = originalRequest.responseText;	
	if (browser_mac()) {
		alert(gMacMSG);
		return;
	}
	// Make sure to set the TPS for skunk
	initGameScript("skunk_");
	window.location = getDownloadUrl(gameID);
}

// Alerts mac users they can't download/buy real arcade games.
function buyReal(gameUID, isItV1) {
  if (browser_mac()) {
    alert(gMacMSG);
  } else {
     if (isItV1 == 0) {
       window.location = "/games/buy_now/"+gameUID+"?os=realv1";
     } else {
       window.location = "/games/buy_now/"+gameUID+"?os=real";
     }
  }
  return false;
}

/**
 * Standard real screenshot browser
 */
function oss(url,parameters) {
  var parameters = "scrollbars=auto,left=20,top=20,width=600,height=550,noresize";
	var theWin = window.open('http://switchboard.real.com/arcade/feeds.html?action=screen_shots&tps=skunk_&gameid=' + url,'racshots',parameters);
}

/**
 * Custom screenshot browser
 */
function oss2(url, width, height) {
  if (width == null) { width = 600; }
  if (height == null) { height = 550; }
  var parameters = "scrollbars=auto,left=20,top=20,width="+width+",height="+height+",noresize";
	var theWin = window.open(url,'racshots',parameters);
  
}