var myGame;
var myService;
var myLoc;



function start_WO() {

  document.getElementById("whoson_title").innerHTML="Who's On?";
  document.getElementById("whoson_detail_title").innerHTML="User Details";
  
  ajax("imon.php?junk="+randomString(), "request=2", set_checkbox);
  
}

function check_checkbox() {
  if (document.getElementById('im_on').checked) {
    lock_settings();
    myGame = document.getElementById("whoson_game").value;
    myService = document.getElementById("whoson_service").value;
    myLoc = document.getElementById("whoson_loc").value;
    
    // I am on and want to play something.
    ajax("imon.php?junk="+randomString(),"location="+myLoc+"&game="+myGame+"&method="+myService+"&request=1",nothing);
  } else {
    unlock_settings();
    ajax("imon.php?junk="+randomString(),"request=3",nothing);
  }
}

function set_checkbox(value) {
  split_value = value.split("|");
  if (split_value[0]=="1") {
    document.getElementById('im_on').checked = true;
    document.getElementById("game_"+split_value[1]).selected = true;
    document.getElementById("service_"+split_value[2]).selected = true;
    document.getElementById("whoson_loc").value = split_value[3];
    lock_settings();
  }
  else document.getElementById('im_on').checked = false;
  
  check_status();
}

function nothing(nothing_text) {
  
}

function check_status() {
  obj = document.getElementById('im_on');
  if (obj.checked) {
  
    myGame = document.getElementById("whoson_game").value;
    myService = document.getElementById("whoson_service").value;
    myLoc = document.getElementById("whoson_loc").value;
    
    // I am on and want to play something.
    ajax("imon.php?junk="+randomString(),"location="+myLoc+"&game="+myGame+"&method="+myService+"&request=1",nothing);

  }

  document.getElementById("whoson_content").style.border="1px solid #FF0000";

  ajax("ajax_whoson.php?junk="+randomString(), null, set_content);

}

function set_content(content) {
  document.getElementById("whoson_content").innerHTML = content;
  document.getElementById("whoson_content").style.border="1px solid #FFFFFF";
  window.setTimeout("check_status()", 2000);
}

function lock_settings() {
  myGame = document.getElementById("whoson_game").value;
  myService = document.getElementById("whoson_service").value;

  document.getElementById("whoson_game").disabled = true;
  document.getElementById("whoson_service").disabled = true;
  document.getElementById("whoson_loc").disabled = true;
}

function unlock_settings() {
  document.getElementById("whoson_service").disabled = false;
  document.getElementById("whoson_game").disabled = false;
  document.getElementById("whoson_loc").disabled = false;
}

function set_details(details, profile_link) {
  clear_details();
  document.getElementById("whoson_details").innerHTML = details+"<br /><a href='"+profile_link+"'>Profile</a>";
}

function clear_details() {
  document.getElementById("whoson_details").innerHTML = "";
}

