﻿var xmlHttp = GetXmlHttpObject()

function clickd(page){
		var php = "serverProxy.php?page="+page;
    xmlHttp.open("GET", php, true);  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = updateContent;
    // make the server request
    xmlHttp.send(null);
}

function updateContent(){
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
	    document.getElementById("content").innerHTML = xmlHttp.responseText;                                      
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

function GetXmlHttpObject()
{
	  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}