////////////////////////////////////////////////////////////////////////////////
//									      //
//  This functions loads the data to the page from other php-pages with Ajax  //
//  loadpage(onPage)							      //
//  getPage()								      //
//  printPage()								      //
//  printPage()								      //
//  CreateXmlHttpObject()						      //
//									      //
////////////////////////////////////////////////////////////////////////////////
//
//  We want the page to work with out javascript. When we load the page we only load one of the five pages
//  If the user browser supports JavaScript we will us Ajax to load the other 4 pages.
//  We do also change the menu so it calls up on the menu functions in menu.js instead of sending the user directly
//  to the php-page

var xmlHttp = null;

// This variables contains information about what page to load or is all ready loaded
var getPageNR = 0;
var onPageNR = 0;

// This is the main function
function loadpage(onPage)
{
  // First we check so the browser suports Ajax
  xmlHttp = CreateXmlHttpObject();
  if (xmlHttp == null)
  {
    alert ("Your browser is out of date\nPlease download a newer version for this site to work properly\n\nWe recommend www.getfirefox.com.");
    return;
  } 
  
  // If it does, we will change the menulinks to call up on move_start() instead of sending the user to an other page
  for(var j_link = 0; j_link < allIDs.length; j_link++)
  {
    if(allIDs[j_link] != onPage)
    {
      document.getElementById(allIDs[j_link]+"_link").href = "javascript: move_start(\""+allIDs[j_link]+"\");";
    }
  }
  
  document.getElementById("previous").href = "javascript: next(\"previous\", 1);";
  document.getElementById("next").href = "javascript: next(\"next\", 1);";
  
  // Now we start to load the pages
  onPageNR = onPage;
  getPage("whatspr", "whatspr");
}

// This function loads a page and gets the information from it.
function getPage()
{
  if(getPageNR == onPageNR)
  {
    getPageNR++;
  }
  if(getPageNR < urls.length)
  {
    xmlHttp = CreateXmlHttpObject();
    xmlHttp.onreadystatechange=printPage;
    xmlHttp.open("GET",urls[getPageNR],true);
    xmlHttp.send(null);
  }
}

// When the page is loaded this function will print the information and call getPage() ones more.
function printPage()
{
  if (xmlHttp.readyState==4)
  {
    document.getElementById(allIDs[getPageNR]).innerHTML=xmlHttp.responseText;
    getPageNR++;
    getPage();
  }
}

// Here is a basic function to create a HttpObject
function CreateXmlHttpObject()
{
  var xmlHttp = null;
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer
    try
    {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}