var game_win;

function activate(id) {
  menuItem = document.getElementById('mnu' + id);
  if(menuItem && menuItem.className != "menu_active") {
     menuItem.className = 'menu_hover';
  }
}

function deactivate(id) {
  menuItem = document.getElementById('mnu' + id);
  if(menuItem && menuItem.className != "menu_active") {
     menuItem.className = 'menu_inactive';
  }
}

function clearInput(el) {
  if (el && el.value == el.defaultValue) {
    el.value = '';
  }
}

function resetInput(el) {
  if (el && el.value == '') {
    el.value = el.defaultValue;
  }
}

function launchGame(lobby, ads){
  if(game_win != null && !game_win.closed) {
    game_win.focus();
    return;
  }
  
  var width = 770;
  var height = (ads) ? 580 : 550;

  url = "/launch.php?lobby=" + lobby;
  game_win = window.open(url, "game", "resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,status=yes,width="+width+",height="+height+",left=20,top=20");
  game_win.location.href=url;
  game_win.focus();
}

function launchSoloGame(game, width, height){
  if(game_win != null && !game_win.closed) {
    game_win.focus();
    return;
  }

  url = "/solo/launch.php?game=" + game;
  game_win = window.open(url, "game", "resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,status=yes,width=" + width + ",height=" + height + ",left=20,top=20");
  game_win.location.href=url;
  game_win.focus();
}

/**
 * Collects some statistical info about the users
 */
function collectInfo() {
  var ie = navigator.userAgent.indexOf('MSIE') != -1;
  var info;
  
  // browser info
  info = escape(navigator.userAgent);
  
  // timezone info
  info += ' ' + new Date().getTimezoneOffset();
  
  // plugins installed
  if(ie) {
    info += ' missing';
  } else {
    info += ' '
    for(var i=0; i<navigator.plugins.length; i++) {
      if(i>0) {
        info += ',';
      }
      info += escape(navigator.plugins[i].name);
    }    
  }
  
  // java installed
  info += ' ' + navigator.javaEnabled();
  
  // webstart enabled
  jws = (navigator && navigator.mimeTypes && navigator.mimeTypes.length && typeof(navigator.mimeTypes['application/x-java-jnlp-file']));
  if(jws == 0 && ie) {
    jws = false;
  } else {
    jws = jws != 'undefined';
  }
  info += ' ' + jws;
  
  // screen info
  info += ' ' + screen.width + 'x' + screen.height + 'x' + screen.colorDepth;
  return info;
}