
var saveFav = GetXmlHttpObject(); // Get the XMLHttpObject

function saveGame(gameID) 
{
    // URL of the PHP and a rand value to make sure response isnt' cached
    var url = "/addFaveGame.php?gameID=" + gameID + "&rand="+Math.random(); 
    saveFav.onreadystatechange = handleGameSaved;
		saveFav.open("GET", url, true); 
		saveFav.send(null);
			
} 

function handleGameSaved() 
{
  // If we're not done processing, go back and do it again
	if (saveFav.readyState != 4)
  {
      return;
  } 
    
    // Grab the link element
  	var addFav = document.getElementById("addFave");
		if (saveFav.status == 200) {
    addFav.innerHTML = "";
    // Set the response to the ahref (for now) to let the user know what happened.
    addFav.innerHTML += saveFav.responseText;
    }
    else
    {
        addFav.innerHTML = "There was an error.";
    }
		
}

function GetXmlHttpObject()
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    return xmlHttp;
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      // IE 6+
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      return xmlHttp;
      }
    catch (e)
      {
      try
        {
        // IE 5.5
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        return xmlHttp;
        }
      catch (e)
        {
        // Browser doesn't support AJAX!
        return null;
        }
      }
    }
  }