/**
 * Oeffnet Popup-Fenster fuer Games
 *
 * @param Integer game_id Die Game-ID
 * @return 
 */
function popGameWindow(game_id)
{
  var windowWidth       = "990";
  var windowHeight      = "685";
  var enableToolbar     = "no";
  var enableLocationbar = "no";
  var enableDirectories = "no";
  var enableStatusbar   = "no";
  var enableMenubar     = "no";
  var enableScrollbars  = "no";
  var isResizable       = "yes";
  var leftPosition      = "0";
  var topPosition       = "0";

  /* Position bestimmen (Center) */

  var pageSize = getPageSize();

  if (pageSize[2] > 0)
  {
    leftPosition = Math.floor((pageSize[2] - windowWidth) / 2);
  }

  if (pageSize[3] > 0)
  {
    topPosition = Math.floor((pageSize[3] - windowHeight) / 2);
  }

  var features = 
    "toolbar=" + enableToolbar + 
    ",location=" + enableLocationbar + 
    ",directories=" + enableDirectories + 
    ",status=" + enableStatusbar + 
    ",menubar=" + enableMenubar + 
    ",resizable=" + isResizable + 
    ",scrollbars=" + enableScrollbars + 
    ",width=" + windowWidth + 
    ",height=" + windowHeight + 
    ",top=" + topPosition + 
    ",left=" + leftPosition + 
    ",screenX=" + leftPosition + 
    ",screenY=" + topPosition;

  return popWindow("/games/start/" + game_id, "gameWindow", features);
}

/**
 * Oeffnet Popup-Fenster fuer Game (ohne Konsole)
 *
 * @return 
 */
function popFreegameWindow(game)
{
  var windowWidth       = "980";
  var windowHeight      = "600";
  var enableToolbar     = "no";
  var enableLocationbar = "no";
  var enableDirectories = "no";
  var enableStatusbar   = "no";
  var enableMenubar     = "no";
  var enableScrollbars  = "no";
  var isResizable       = "yes";
  var leftPosition      = "0";
  var topPosition       = "0";

  /* Position bestimmen (Center) */

  var pageSize = getPageSize();

  if (pageSize[2] > 0) {
    leftPosition = Math.floor((pageSize[2] - windowWidth) / 2);
  }

  if (pageSize[3] > 0) {
    topPosition = Math.floor((pageSize[3] - windowHeight) / 2);
  }

  var features = 
    "toolbar=" + enableToolbar + 
    ",location=" + enableLocationbar + 
    ",directories=" + enableDirectories + 
    ",status=" + enableStatusbar + 
    ",menubar=" + enableMenubar + 
    ",resizable=" + isResizable + 
    ",scrollbars=" + enableScrollbars + 
    ",width=" + windowWidth + 
    ",height=" + windowHeight + 
    ",top=" + topPosition + 
    ",left=" + leftPosition + 
    ",screenX=" + leftPosition + 
    ",screenY=" + topPosition;

  return popWindow("/freegames/start/" + game, "freegameWindow", features);
}

/**
 * Oeffnet Popup-Fenster fuer Game (ohne Konsole, TOI)
 *
 * @return 
 */
function popTFreegameWindow(game)
{
  var windowWidth       = "800";
  var windowHeight      = "600";
  var enableToolbar     = "no";
  var enableLocationbar = "no";
  var enableDirectories = "no";
  var enableStatusbar   = "no";
  var enableMenubar     = "no";
  var enableScrollbars  = "no";
  var isResizable       = "yes";
  var leftPosition      = "0";
  var topPosition       = "0";

  /* Position bestimmen (Center) */

  var pageSize = getPageSize();

  if (pageSize[2] > 0) {
    leftPosition = Math.floor((pageSize[2] - windowWidth) / 2);
  }

  if (pageSize[3] > 0) {
    topPosition = Math.floor((pageSize[3] - windowHeight) / 2);
  }

  var features = 
    "toolbar=" + enableToolbar + 
    ",location=" + enableLocationbar + 
    ",directories=" + enableDirectories + 
    ",status=" + enableStatusbar + 
    ",menubar=" + enableMenubar + 
    ",resizable=" + isResizable + 
    ",scrollbars=" + enableScrollbars + 
    ",width=" + windowWidth + 
    ",height=" + windowHeight + 
    ",top=" + topPosition + 
    ",left=" + leftPosition + 
    ",screenX=" + leftPosition + 
    ",screenY=" + topPosition;

  return popWindow("/freegames/tstart/" + game, "freegameWindow", features);
}

/**
 * Oeffnet Popup-Fenster fuer ChallengeGame
 *
 * @return 
 */
function popChallengeGameWindow(game)
{
  var windowWidth       = "810";
  var windowHeight      = "685";
  var enableToolbar     = "no";
  var enableLocationbar = "no";
  var enableDirectories = "no";
  var enableStatusbar   = "no";
  var enableMenubar     = "no";
  var enableScrollbars  = "no";
  var isResizable       = "yes";
  var leftPosition      = "0";
  var topPosition       = "0";

  /* Position bestimmen (Center) */

  var pageSize = getPageSize();

  if (pageSize[2] > 0) {
    leftPosition = Math.floor((pageSize[2] - windowWidth) / 2);
  }

  if (pageSize[3] > 0) {
    topPosition = Math.floor((pageSize[3] - windowHeight) / 2);
  }

  var features = 
    "toolbar=" + enableToolbar + 
    ",location=" + enableLocationbar + 
    ",directories=" + enableDirectories + 
    ",status=" + enableStatusbar + 
    ",menubar=" + enableMenubar + 
    ",resizable=" + isResizable + 
    ",scrollbars=" + enableScrollbars + 
    ",width=" + windowWidth + 
    ",height=" + windowHeight + 
    ",top=" + topPosition + 
    ",left=" + leftPosition + 
    ",screenX=" + leftPosition + 
    ",screenY=" + topPosition;

  return popWindow("/challenge_games/enter/" + game, "challengeGameWindow", features);
}

/**
 * Oeffnet Popup-Fenster fuer Fusakas
 *
 * @return 
 */
function popFusakasWindow()
{
  var windowWidth       = "990";
  var windowHeight      = "685";
  var enableToolbar     = "no";
  var enableLocationbar = "no";
  var enableDirectories = "no";
  var enableStatusbar   = "no";
  var enableMenubar     = "no";
  var enableScrollbars  = "no";
  var isResizable       = "no";
  var leftPosition      = "0";
  var topPosition       = "0";

  /* Position bestimmen (Center) */

  var pageSize = getPageSize();

  if (pageSize[2] > 0) {
    leftPosition = Math.floor((pageSize[2] - windowWidth) / 2);
  }

  if (pageSize[3] > 0) {
    topPosition = Math.floor((pageSize[3] - windowHeight) / 2);
  }

  var features = 
    "toolbar=" + enableToolbar + 
    ",location=" + enableLocationbar + 
    ",directories=" + enableDirectories + 
    ",status=" + enableStatusbar + 
    ",menubar=" + enableMenubar + 
    ",resizable=" + isResizable + 
    ",scrollbars=" + enableScrollbars + 
    ",width=" + windowWidth + 
    ",height=" + windowHeight + 
    ",top=" + topPosition + 
    ",left=" + leftPosition + 
    ",screenX=" + leftPosition + 
    ",screenY=" + topPosition;

  return popWindow("/fusakas/start", "fusakasWindow", features);
}

/**
 * Oeffnet Popup-Fenster fuer AGB und Widerruf
 *
 * @return Object Window
 */
function popAgbWindow(content)
{
  var windowWidth       = "750";
  var windowHeight      = "600";
  var enableToolbar     = "no";
  var enableLocationbar = "no";
  var enableDirectories = "no";
  var enableStatusbar   = "no";
  var enableMenubar     = "no";
  var enableScrollbars  = "yes";
  var isResizable       = "yes";
  var leftPosition      = "0";
  var topPosition       = "0";

  /* Position bestimmen (Center) */

  var pageSize = getPageSize();

  if (pageSize[2] > 0) {
    leftPosition = Math.floor((pageSize[2] - windowWidth) / 2);
  }

  if (pageSize[3] > 0) {
    topPosition = Math.floor((pageSize[3] - windowHeight) / 2);
  }

  var features = 
    "toolbar=" + enableToolbar + 
    ",location=" + enableLocationbar + 
    ",directories=" + enableDirectories + 
    ",status=" + enableStatusbar + 
    ",menubar=" + enableMenubar + 
    ",resizable=" + isResizable + 
    ",scrollbars=" + enableScrollbars + 
    ",width=" + windowWidth + 
    ",height=" + windowHeight + 
    ",top=" + topPosition + 
    ",left=" + leftPosition + 
    ",screenX=" + leftPosition + 
    ",screenY=" + topPosition;

  return popWindow("/pages/popup_" + content, "agbWindow", features);
}

/**
 * Oeffnet Popup-Fenster Revolverheld-Video
 *
 * @return Object Window
 */
function popRevolverheldVideoWindow()
{
  var windowWidth       = "510";
  var windowHeight      = "610";
  var enableToolbar     = "no";
  var enableLocationbar = "no";
  var enableDirectories = "no";
  var enableStatusbar   = "no";
  var enableMenubar     = "no";
  var enableScrollbars  = "no";
  var isResizable       = "yes";
  var leftPosition      = "0";
  var topPosition       = "0";

  /* Position bestimmen (Center) */

  var pageSize = getPageSize();

  if (pageSize[2] > 0) {
    leftPosition = Math.floor((pageSize[2] - windowWidth) / 2);
  }

  if (pageSize[3] > 0) {
    topPosition = Math.floor((pageSize[3] - windowHeight) / 2);
  }

  var features = 
    "toolbar=" + enableToolbar + 
    ",location=" + enableLocationbar + 
    ",directories=" + enableDirectories + 
    ",status=" + enableStatusbar + 
    ",menubar=" + enableMenubar + 
    ",resizable=" + isResizable + 
    ",scrollbars=" + enableScrollbars + 
    ",width=" + windowWidth + 
    ",height=" + windowHeight + 
    ",top=" + topPosition + 
    ",left=" + leftPosition + 
    ",screenX=" + leftPosition + 
    ",screenY=" + topPosition;

  return popWindow("/pages/popup_video_revolverheld", "revolverheldVideoWindow", features);
}

/**
 * Oeffnet Popup-Fenster Revolverheld-Video
 *
 * @return Object Window
 */
function popRevolverheldGameWindow()
{
  var windowWidth       = "800";
  var windowHeight      = "600";
  var enableToolbar     = "no";
  var enableLocationbar = "no";
  var enableDirectories = "no";
  var enableStatusbar   = "no";
  var enableMenubar     = "no";
  var enableScrollbars  = "yes";
  var isResizable       = "yes";
  var leftPosition      = "0";
  var topPosition       = "0";

  /* Position bestimmen (Center) */

  var pageSize = getPageSize();

  if (pageSize[2] > 0) {
    leftPosition = Math.floor((pageSize[2] - windowWidth) / 2);
  }

  if (pageSize[3] > 0) {
    topPosition = Math.floor((pageSize[3] - windowHeight) / 2);
  }

  var features = 
    "toolbar=" + enableToolbar + 
    ",location=" + enableLocationbar + 
    ",directories=" + enableDirectories + 
    ",status=" + enableStatusbar + 
    ",menubar=" + enableMenubar + 
    ",resizable=" + isResizable + 
    ",scrollbars=" + enableScrollbars + 
    ",width=" + windowWidth + 
    ",height=" + windowHeight + 
    ",top=" + topPosition + 
    ",left=" + leftPosition + 
    ",screenX=" + leftPosition + 
    ",screenY=" + topPosition;

  return popWindow("/pages/game_revolverheld2008", "revolverheldGameWindow", features);
}

/**
 * Wrapper fuer javascript:window.open()
 *
 * @param String url Der zu oeffnende URL
 * @param String name Der Name des Fensters
 * @param String features Fenstereigenschaften (siehe auch http://www.javascriptkit.com/jsref/window.shtml)
 * @return Boolean false
 */
function popWindow(url, name, features)
{
  popwindow = window.open(url, name, features);
  popwindow.focus();
  return false;
}

/**
 * Liefert ein Array mit folgenden Angaben:
 * - Seitenbreite und -hoehe
 * - Fensterbreite und -hoehe
 *
 * Core code from - quirksmode.org
 * Edit for Firefox by pHaez
 *
 * @return Array
 */
function getPageSize()
{
  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY) {
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight) { 
    // all but Explorer Mac
    
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else {
    // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;

  if (self.innerHeight) {
    // all except Explorer
    
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) {
    // Explorer 6 Strict Mode
    
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) {
    // other Explorers
    
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }	

  // for small pages with total height less then height of the viewport
  
  if(yScroll < windowHeight) {
    pageHeight = windowHeight;
  } else {
    pageHeight = yScroll;
  }

  // for small pages with total width less then width of the viewport

  if(xScroll < windowWidth) {
    pageWidth = windowWidth;
  } else {
    pageWidth = xScroll;
  }

  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);

  return arrayPageSize;
}
