
var xchangediv;
var xmlhttp;

function changeBodyID(newID)
{
  document.getElementsByTagName('body')[0].id = newID;
  return;
}

function changeTitle(newID)
{
  switch (newID)
  {
    case "index": document.title = "Buy Neopoints from Buy Neopoints.com, and spend Neopoints like a king!";
                   break;
 
    case "buy-neopoints": document.title = "Buy Neopoints from Buy Neopoints.com, and spend Neopoints like a king! Buy Neopoints!";
                     break;
 
    case "buy-accounts": document.title = "Buy Neopoints from Buy Neopoints.com, and spend Neopoints like a king! Buy Accounts!";
                     break;
 
    case "about-us": document.title = "Buy Neopoints from Buy Neopoints.com, and spend Neopoints like a king! About Us!";
                       break;
 
    case "contact-us": document.title = "Buy Neopoints from Buy Neopoints.com, and spend Neopoints like a king! Contact Us!";
                    break;
 
    default: document.title = "Buy Neopoints from Buy Neopoints.com, and spend Neopoints like a king";
  }
  return;
}

function changePage(page)
{
  if(xchangediv == null)
  {
    xchangediv = document.getElementById('xchange');
  }
  xchangediv.innerHTML = "";
  xchangediv.innerHTML =
  "<h1>Loading Page...</h1><img id=\"loader\" src=\"./img/ajax-loader.gif\" />";
  
  match = /\/([a-z-_]*)\.php/i.exec(page);
  
  changeBodyID(match[1]);
  changeTitle(match[1]);

  xmlhttp = getRequestObject();
  
  if(xmlhttp != null)
  {
    xmlhttp.onreadystatechange=function()
    {
      if(xmlhttp.readyState==4)
      {
        xchangediv.innerHTML = xmlhttp.responseText;
      }
    }
    xmlhttp.open("GET","./content/" + match[1] + ".html",true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
    xmlhttp.send(null);
  }
  
  return;
}

function getRequestObject()
{
if (window.XMLHttpRequest)
  {
  return new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  xchangediv.innerHTML =
  "<h1>Ajax Error</h1><p>Your browser doesn't support Ajax.</p>";
  return null;
  }
}
