var READY_STATE_COMPLETED = 4
var req = null;
var console = null;
var menuItem = null;


function sendRequest(url, params, HttpMethod)
{
  if (!HttpMethod)
  {
    HttpMethod = "GET";
  }
  
  req = getXMLHttpRequest();
  
  if (req)
  {
    req.onreadystatechange=onReadyState;
    req.open(HttpMethod, url, true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req.send(params);
  }
  
}

function onReadyState()
{
  var ready=req.readyState;
  var data = null;
  
  if(ready == READY_STATE_COMPLETED)
  {
    data = req.responseText;
  }
  else
  {
    data = "<center>loading...</center>";
  }
  
  toConsole(data);
}

function toConsole(data)
{
  if (data == null)
  {
    data = "loading...";
  }
  
  if (console != null)
  {
    console.innerHTML = data;
  }  
}

window.onload=function()
{
  console=document.getElementById('view');
  sendRequest("main.html");
}

function getXMLHttpRequest()
{
  var xRequest = null;
  
  if (window.XMLHttpRequest)
  {
    xRequest = new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {
    xRequest = new ActiveXObject("Microsoft.XMLHTTP");
  }
  
  return xRequest;  
}

function homeOnClick()
{
  sendRequest("main.html");
}

function aboutOnClick()
{
  sendRequest("about.html");
}

function galleryOnClick()
{
  sendRequest("gallery.html");
}

function contactOnClick()
{
  sendRequest("contact.html");
}

function locationOnClick()
{
  sendRequest("location.html");
}

function linksOnClick()
{
  sendRequest("links.html");
}
