var http = GetHTTPObject(); // We create the HTTP Object            

function GetPageName()
{
  return location.href.substring(location.href.lastIndexOf('/')+1, location.href.length);
}

function GetPagePath()
{
  return location.href.substring(0, location.href.lastIndexOf('/')+1);
}

function RestoreFrameset(RequestedPage)
{
  if (RequestedPage == "")
    RequestedPage = "contest.html";

  if (parent.location.href == self.location.href) 
  {
    if (window.location.href.replace)
      window.location.replace('index.php?Page='+RequestedPage);
    else
      // causes problems with back button, but works
      window.location.href = 'index.php?Page='+RequestedPage;
  }
}

function GetHTTPObject() 
{//retrieves a browser compliant XMLHTTPRequest object
  var xmlhttp;
/*@cc_on
          @if (@_jscript_version >= 5)
          try 
          { 
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
          } 
          catch (e) 
          {
            try 
            {
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (E) 
            {
              xmlhttp = false;
            }
         }
         @else
         xmlhttp = false;
          @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
  {
    try 
    {
      xmlhttp = new XMLHttpRequest();
    } 
    catch (e) 
    {
      xmlhttp = false;
    }
  }
  if (!xmlhttp)
    alert("XMLHTTPRequests are not supported by this browser!");
  return xmlhttp;
}

function FillElementFromXMLXSL(XML, XSL, TargetId, Parameters)
{//fills the specified Target-element with the output generated by transforming the XML using the XSL (any specified parameters are set on the XSL before transforming)
  //var RetrieveStart;
  //var RetrieveTime;
  //var TransformStart;
  //var TransformTime;
  if(document.implementation && document.implementation.createDocument)
  {// Mozilla
    var XSLTProc = new XSLTProcessor();
    var XMLObject;
    var XSLObject;
    var GeneratedHTML;
    var Target;
    
//RetrieveStart = (new Date()).getTime();
    
    if (typeof(XML) == "string")
    {//XML is a filename
      var HTTPRequest = new XMLHttpRequest();
      HTTPRequest.open("GET", XML, false);
      HTTPRequest.send(null);
      XMLObject = HTTPRequest.responseXML;
    }
    else
    {//XML is an object
      XMLObject = XML;
    }
    
    if (typeof(XSL) == "string")
    {//XSL is a filename
      var HTTPRequest = new XMLHttpRequest();
      HTTPRequest.open("GET", XSL, false);
      HTTPRequest.send(null);
      XSLObject = HTTPRequest.responseXML;      
    }
    else
    {//XSL is an object
      XSLObject = XSL;
    }
    
//RetrieveTime = ((new Date()).getTime() - RetrieveStart);
    
    XSLTProc.importStylesheet(XSLObject);

    //add the specified Parameters to the XSLTProcessor
    if (Parameters)
    {
      for (i=0;i<Parameters.length;i++)
      {
        //alert(Parameters[i].Name +":"+Parameters[i].Value);
        XSLTProc.setParameter(null, Parameters[i].Name, Parameters[i].Value);
      }
    }
    
    Target = document.getElementById(TargetId);
    if (Target)
    {
      //empty the node
      while (Target.firstChild)
      {
        Target.removeChild(Target.firstChild);
      }
      
      //transform the XML using the XSL and add the result to the specified document-node
//TransformStart = (new Date()).getTime();
      GeneratedHTML = XSLTProc.transformToFragment(XMLObject, document);
//TransformTime = ((new Date()).getTime() - TransformStart);
      Target.appendChild(GeneratedHTML);
    }
  }
  else if(window.ActiveXObject)
  {//Internet Explorer
    var XMLObject;
    var XSLObject;
    var XSLProcessor;
    var XSLTemplate = new ActiveXObject("Msxml2.XSLTemplate");
    var i;
    var Target;
//RetrieveStart = (new Date()).getTime();
    if (typeof(XML) == "string")
    {//XML is a filename
      var XMLObject = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
      XMLObject.async = false;
      XMLObject.load(XML);
    }
    else
    {//XML is an object
      XMLObject = XML;
    }

    if (typeof(XSL) == "string")
    {//XSL is a filename
      XSLObject = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
      XSLObject.async = false;
      XSLObject.load(XSL);
    }
    else
    {//XSL is an object
      XSLObject = XSL;
    }
//RetrieveTime = ((new Date()).getTime() - RetrieveStart);
    //add the specified Parameters to the XSLTProcessor
    XSLTemplate.stylesheet = XSLObject;
    XSLProcessor = XSLTemplate.createProcessor();

    if (Parameters)
    {
      for (i = 0; i < Parameters.length; i++)
      {
        //alert(Parameters[i].Name +":"+Parameters[i].Value);
        XSLProcessor.addParameter(Parameters[i].Name, Parameters[i].Value);
      }
    }

    //transform the XML using the XSL and add the result to the specified document-node
    XSLProcessor.input = XMLObject;
//TransformStart = (new Date()).getTime();
    XSLProcessor.transform();    
//TransformTime = ((new Date()).getTime() - TransformStart);
    Target = document.getElementById(TargetId);
    Target.innerHTML = XSLProcessor.output;
  }
  else
  {//some other browser
    document.write("Unsupported Browser.<br/>Please use Internet Explorer or Firefox.");
  }
  
//window.status = "Retrieve: "+RetrieveTime+"s\nTransform:"+TransformTime;
}

function SetElementContents(ElementID, NewContents)
{//sets the contents of the document-element with the specified id (if it exists) to the supplied contents
  var Target = document.getElementById(ElementID);
  if (!Target)
    return false;
    
  if(document.implementation && document.implementation.createDocument && typeof(NewContents)!='string')
  {// Mozilla object
    //empty the node
    while (Target.firstChild)
    {
      Target.removeChild(Target.firstChild);
    }
      
    Target.appendChild(NewContents);
  }
  else
  {//Internet Explorer & mozilla string
    Target.innerHTML = NewContents;
  }
    
  return true;
}

function FillElementFromPHPXSL(TargetElementId, PHPPage, XSLFile, PHPParamString, XSLParameters)
{//fills the specified element using the XML obtained from a asynchroneous request to the PHPPage, transformed using the XSL (any specified parameters are set on the XSL before transforming)
  if (!PHPParamString)
    PHPParamString = '';
  
  http.open("POST", PHPPage, false);
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", PHPParamString.length);
  http.setRequestHeader("Connection", "close");
  http.send(PHPParamString);

  var Response = http.responseXML;
  //alert(http.responseText);
  if (VerifyResponse(TargetElementId))
  {
    FillElementFromXMLXSL(Response, XSLFile, TargetElementId, XSLParameters);
  }
}

function VerifyResponse(OutputElementId)
{//verifies the servers response. Extract the responseXML BEFORE calling this function, as this functions clears all http-states
  var RootElement;
  var Result;
  var Errors;
  var Messages;
  var ResponseString = "";  
  var Response = http.responseXML;
  
  //alert(http.responseText);
  
  if (http.status == 200) 
  {  
    if (http.getResponseHeader("content-type") == "text/html")
    {
      SetElementContents(OutputElementId, http.responseText);
      http.abort();
      return false;
    }
    if (Response.parseError)
    {
      if (Response.parseError.errorCode != 0)
      {
        SetElementContents(OutputElementId, "ErrorCode: "+Response.parseError.errorCode+"<br/>Reason: "+Response.parseError.reason+"<br/>Response: "+http.responseText);
        http.abort();
        return false;
      }
    }
    
    RootElement = Response.getElementsByTagName('response').item(0);   // read the first element with a dom's method
    if (!RootElement)
    {
      http.abort();
      return false;
    }
   
    Result = RootElement.getElementsByTagName('result')[0].firstChild.data;
    if (Result != "OK")
    {
      Messages = RootElement.getElementsByTagName('message');
      for (i = 0; i < Messages.length; i++)
      {
        ResponseString += Messages[i].childNodes[0].nodeValue;
        ResponseString += "<br/>";
      }
      
      if (ResponseString == "")
      {//no messages in response --> return the errors
        Errors = RootElement.getElementsByTagName('error');
        for (i = 0; i < Errors.length; i++)
        {
          ResponseString += Errors[i].childNodes[0].nodeValue;
          ResponseString += "<br/>";
        }
        
        if (ResponseString == "")
          ResponseString = http.responseText;//"Invalid ServerResponse";
      }
        
      SetElementContents(OutputElementId, ResponseString);
      
      http.abort();
      return false;
    }
  }
  else
  {
    SetElementContents(OutputElementId, http.responseText);
    http.abort();
    return false;
  }

  http.abort();
  return true;
}

function Login(Username, Password, ResponseId)
{
  //alert("LoginData: "+ Username +", "+ Password);
  if (Username == '' || Password == '')
  {
    SetElementContents(ResponseId, "U heeft niet alle velden ingevuld!");
    return false;  
  }
  
  var params = ""
  params += "Mail=" + Username;
  params += "&";
  params += "Password=" + Password;
  
  //uss an anonymous function that calls the OnLoginStatusChanged()-function. This is the only way  for passing arguments on a status-change.
  http.onreadystatechange = function() {OnLoginStatusChanged(Username, Password, ResponseId);};
  http.open("POST", "login.php", true);
  
  //Send the proper header infomation along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  
  http.send(params);
}

function OnLoginStatusChanged(Username, Password, ResponseId)
{
  if (http.readyState == 1)
  {
    SetElementContents(ResponseId, "Een moment geduld AUB. <br\>Uw gegevens worden gecontroleerd.");
  }
  else if (http.readyState == 4)
  {
    var Response = http.responseXML;
    if (VerifyResponse(ResponseId))
    {
      parent.Menu.location = "studentmenu.php";
    }
  }
}

function Logout()
{
  var params = "DS=-1";
  
  http.open("POST", "logout.php", false);
  
  //Send the proper header infomation along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  
  http.send(params);
  
  top.document.location = "index.php";
}

function FillDrivingSchoolSelection(SelectionControl, ActiveOnly, CityName)
{
  var params = "City="+CityName;
  params += "&ActiveOnly="+ActiveOnly;
  
  http.open("POST", "getdrivingschools.php", false);
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");  
  http.send(params);

  var Response = http.responseXML;
  if (VerifyResponse())
  {
    //clear node
    while (SelectionControl.firstChild)
    {
      SelectionControl.removeChild(SelectionControl.firstChild);
    }
    
    SelectionControl.options[SelectionControl.options.length] = new Option('', '-1');

    var DrivingSchoolsArray = Response.getElementsByTagName('drivingschool');
    for (i = 0; i < DrivingSchoolsArray.length; i++)
    {
      var OptionText = DrivingSchoolsArray[i].getElementsByTagName('name')[0].childNodes[0].nodeValue
      if (DrivingSchoolsArray[i].getElementsByTagName('city')[0].childNodes.length)
      {
        var City = DrivingSchoolsArray[i].getElementsByTagName('city')[0].childNodes[0].nodeValue;
        OptionText = OptionText + '  (' + City + ')';
      }
      
      var OptionValue = DrivingSchoolsArray[i].getElementsByTagName('id')[0].childNodes[0].nodeValue;
      
      SelectionControl.options[SelectionControl.options.length] = new Option(OptionText, OptionValue);
    }
  }
}

function ChangePassword(Username, OldPassword, NewPassword, RetypedNewPassword, ResponseId)
{
  if (NewPassword != RetypedNewPassword && NewPassword != '')
  {
    SetElementContents(ResponseId, "Uw hebt niet twee keer hetzelfde nieuwe paswoord ingevuld!");
    return false;
  }

  if (NewPassword.length < 6)
  {
    SetElementContents(ResponseId, "Uw paswoord moet uit minimaal 6 karakters bestaan!");
    return false;
  }
  
  if (Username == '' || OldPassword == '' || NewPassword == '' || RetypedNewPassword == '')
  {
    SetElementContents(ResponseId, "U heeft niet alle velden ingevuld!");
    return false;  
  }
  var params = "";

  params += "Mail=" + Username;
  params += "&";
  params += "OldPassword=" + OldPassword;
  params += "&";
  params += "NewPassword=" + NewPassword;
  
  //use an anonymous function that calls the OnChangePasswordStatusChanged()-function. This is the only way  for passing arguments on a status-change.
  http.onreadystatechange = function() {OnChangePasswordStatusChanged(Username, NewPassword, ResponseId);};   
  http.open("POST", "changepassword.php", true);

  //Send the proper header infomation along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  
  http.send(params);
}

function OnChangePasswordStatusChanged(Username, Password, ResponseId)
{
  if (http.readyState == 4)
  {
    var Response = http.responseXML;  
    if (VerifyResponse(ResponseId)) 
    {
      SetElementContents(ResponseId, "Het paswoord is gewijzigd.");
      //Logout();
    }
  }
}


function ChangeNickname(StudentID, NewNickname, ResponseId, CurrentNicknameId)
{
  var params = "";

  params += "StudentID=" + StudentID;
  params += "&";
  params += "Nickname=" + NewNickname;
  
  //use an anonymous function that calls the OnChangePasswordStatusChanged()-function. This is the only way  for passing arguments on a status-change.
  http.onreadystatechange = function() {OnChangeNicknameStatusChanged(NewNickname, ResponseId, CurrentNicknameId);};
  http.open("POST", "changenickname.php", true);

  //Send the proper header infomation along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  
  http.send(params);  
}

function OnChangeNicknameStatusChanged(NewNickname, ResponseId, CurrentNicknameId)
{
  if (http.readyState == 1)
  {
    SetElementContents(ResponseId, "Een moment geduld AUB...");
  }
  else if (http.readyState == 4)
  {
    if (VerifyResponse(ResponseId))
    {
      if (NewNickname == "")
      {
        SetElementContents(ResponseId, "Uw nickname is verwijderd uit de database.");
        document.getElementById(CurrentNicknameId).value = "";
      }
      else
      {
        SetElementContents(ResponseId, "Uw nickname is veranderd in '" + NewNickname + "'");
        document.getElementById(CurrentNicknameId).value = NewNickname;
      }
    }
  }
}

function ChangeNicknameUsage(StudentID, ResponseId, UseNicknameId, DontUseNicknameId)
{
  var params = "";

  params += "StudentID=" + StudentID;
  
  if (document.getElementById(UseNicknameId).checked)
    NewUseNickname = 1;
  else
    NewUseNickname = 0;

  params += "&";
  params += "UseNickname="+NewUseNickname;    
    
  //use an anonymous function that calls the OnChangePasswordStatusChanged()-function. This is the only way  for passing arguments on a status-change.
  http.onreadystatechange = function() {OnChangeNicknameUsageStatusChanged(NewUseNickname, ResponseId, UseNicknameId, DontUseNicknameId);};
  http.open("POST", "changenicknameusage.php", true);

  //Send the proper header infomation along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  
  http.send(params);  
}

function OnChangeNicknameUsageStatusChanged(NewUseNickname, ResponseId, UseNicknameId, DontUseNicknameId)
{
  if (http.readyState == 1)
  {
    SetElementContents(ResponseId, "Een moment geduld AUB...");
  }
  else if (http.readyState == 4)
  {
    if (VerifyResponse(ResponseId))
    {
      //set the appropriate value of the radio-group.
      if (NewUseNickname)
      {
        document.getElementById(DontUseNicknameId).checked = false;
        document.getElementById(UseNicknameId).checked = true;
        SetElementContents(ResponseId, "Vanaf nu wordt uw nickname gebruikt in de ranglijst.");
      }
      else
      {
        document.getElementById(DontUseNicknameId).checked = true;
        document.getElementById(UseNicknameId).checked = false;
        SetElementContents(ResponseId, "Vanaf nu wordt uw echte naam gebruikt op de ranglijst.");
      }
    }
  }
}
function ChangePermission(StudentID, NewHighscoreMember, ResponseId, PermissionId)
{
  var params = "";
  
  params += "StudentID=" + StudentID;
  params += "&";
  params += "HighscoreMember=" + NewHighscoreMember;
  
  //use an anonymous function that calls the OnChangePasswordStatusChanged()-function. This is the only way  for passing arguments on a status-change.
  http.onreadystatechange = function() {OnChangePermissionStatusChanged(NewHighscoreMember, ResponseId, PermissionId);};
  http.open("POST", "changepermissions.php", true);

  //Send the proper header infomation along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  
  http.send(params);
}

function OnChangePermissionStatusChanged(NewHighscoreMember, ResponseId, PermissionId)
{
  if (http.readyState == 1)
  {
    SetElementContents(ResponseId, "Een moment geduld AUB...");
  }
  else if (http.readyState == 4)
  {
    if (VerifyResponse(ResponseId))
    {
      if (NewHighscoreMember)
      {
        SetElementContents(ResponseId, "Uw resultaat is voortaan zichtbaar in de ranglijst.");
        document.getElementById(PermissionId).checked = true;
      }
      else
      {
        SetElementContents(ResponseId, "Uw resultaat is voortaan niet meer zichtbaar in de ranglijst.");
        document.getElementById(PermissionId).checked = false;
      }
    }
  }
}
function FillDrivingSchoolTable(TargetName)
{
  return FillElementFromPHPXSL(TargetName, "getdrivingschools.php", "drivingschooltable.xsl");
}

function ResetPassword(EMail, ResponseElementId)
{
  if (EMail == '')
  {
    SetElementContents(ResponseElementId, "Het email-adres is niet ingevuld!");
    return false;
  }
  
  var params = "";
  params += "Mail=" + EMail;
    
  //use an anonymous function that calls the OnResetPasswordStatusChanged()-function. This is the only way  for passing arguments on a status-change.
  http.onreadystatechange = function() {OnResetPasswordStatusChanged(ResponseElementId);};   
  http.open("POST", "resetpassword.php", true);

  //Send the proper header infomation along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  
  http.send(params);
}

function DrivingSchoolSelected(DrivingSchoolId, AlternativePage)
{
  if (DrivingSchoolId == -1)
  {//load default header
    parent.Content.location = "./"+AlternativePage;
    ResetLogo();
  }
  else
  {//retrieve drivingschool info and set the page contents.
    var params = "DSID="+DrivingSchoolId;
    http.open("POST", "drivingschool.php", false);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");  
    http.send(params);

    var Response = http.responseXML;
    if (VerifyResponse())
    {
      var DrivingSchoolsArray = Response.getElementsByTagName('drivingschool');
      var Name = DrivingSchoolsArray[0].getElementsByTagName('name')[0].childNodes[0].nodeValue;
      var Path = DrivingSchoolsArray[0].getElementsByTagName('path')[0].childNodes[0].nodeValue;
      var Url = DrivingSchoolsArray[0].getElementsByTagName('url')[0].childNodes[0].nodeValue;
      
      //parent.Content.location = "dscontest.php?DSID="+DrivingSchoolId;
      parent.Menu.location = "dsmenu.php?DSID="+DrivingSchoolId;
      parent.Content.location = Url;
      
      parent.Header.document.getElementById("HeaderText").innerHTML = Name;
      parent.Header.document.getElementById("HeaderText").setAttribute("class", "HeaderDS");
      parent.Header.document.getElementById("HeaderText").className = "HeaderDS";      
      SetLogo(parent.Header.document.getElementById("Logo"), "http://www.drivemaster.nl/"+Path+"logo.jpg", Name);
    }   
  }
}

function ResetLogo()
{
  var HeaderTextElement = parent.Header.document.getElementById("HeaderText");
  if (HeaderTextElement)
  {
    HeaderTextElement.innerHTML = "<img id='RSTLogo' src='./resources/images/RijstijltestLogo.png' alt='Rijstijl Test'/>";  
    HeaderTextElement.setAttribute("class", "HeaderRST");
    HeaderTextElement.className = "HeaderRST";
  }
  SetLogo(parent.Header.document.getElementById("Logo"), "./resources/images/gdlogo.jpg", "Green Dino");
}

function SetLogo(ImageElement, ImageLocation, DSName)
{
  if (!ImageElement)
    return;
    
  //alert("IE:"+ImageElement+" IL:"+ImageLocation+" Name:"+DSName);
  //alert("SetLogo");
  var max_width = 200;
  var max_height = 100;
  var max_aspect = max_width/max_height;

  ImageElement.src = ImageLocation;
  ImageElement.alt = DSName;
  //ImageElement.onLoad = AdjustImage(ImageElement);
  
/*  
  Logo = new Image();
  Logo.onLoad = alert(Logo.width);
  Logo.src = ImageLocation; 
  var LogoAspect = Logo.width/Logo.height;
  
  alert("else: LH:" + Logo.height + " LW:" + Logo.width + " LA:"+LogoAspect);

  ImageElement.removeAttribute("height");  
  ImageElement.removeAttribute("width");
  
  alert(Logo.complete);
  
  //if ((Logo.width > max_width && Logo.height <= max_height) || (LogoAspect >= max_aspect))
  if ((Logo.width > max_width && Logo.height <= max_height) || (LogoAspect >= max_aspect))
  {
    ImageElement.setAttribute("width", max_width);
    //ImageElement.setAttribute("height", max_width/LogoAspect);
    alert("width");
  }
  else if ((Logo.height > max_height && Logo.width <= max_width) || (LogoAspect <= max_aspect))
  {
    ImageElement.setAttribute("height", max_height);
    alert("height");
    //ImageElement.setAttribute("width", max_height*LogoAspect);    
  }
  else
  {
    alert("else: LH:" + Logo.height + " LW:" + Logo.width + " LA:"+LogoAspect);
  }
  */
  //alert("SetLogo Done");  
}

function AdjustImage(ImageElement)
{
  //alert(ImageElement.width);
}

function StudentSelected()
{
  var params = "Dummy=Fake";

  http.open("POST", "getactivestudent.php", false);
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");  
  http.send(params);

  var Response = http.responseXML;
  if (VerifyResponse())
  {
    parent.Menu.location = "studentmenu.php";
  
  /*
    var StudentName = Response.getElementsByTagName('name')[0].firstChild;
    if (StudentName)
    {
      parent.Header.document.getElementById("HeaderText").innerHTML = StudentName.data;
      parent.Header.document.getElementById("HeaderText").setAttribute("class", "HeaderStudent");
      parent.Header.document.getElementById("HeaderText").className = "HeaderStudent";
      SetLogo(parent.Header.document.getElementById("Logo"), "./resources/images/studentlogo.jpg", "");
    }
    */
  }
}


function SetStatus(StatusElementId)
{
  http.open("GET", "getactivestudent.php", false);
  http.send(null);
  
  var Response = http.responseXML;
  if (VerifyResponse())
  {
    var Username = Response.getElementsByTagName('username')[0].firstChild;
    if (Username)
    {
      var Contents = "<input class='button' type='button' value='Logout' onclick='javascript:Logout()'></input>";
      Contents += "<br/>";
      //Contents += "<input class='button' type='button' value='Mijn Pagina' onclick='document.location=\"studentmenu.php\"'></input>";
      Contents += "<input class='button' type='button' value='Mijn Pagina' onclick='javascript:StudentSelected();'></input>";
      SetElementContents(StatusElementId, Contents);
      return true;
    }
  }

  var onClick = 'parent.frames.Content.location="login.php"';
  
  SetElementContents(StatusElementId, "<input class='button' type='button' value='Login' onclick="+onClick+"></input>");
}

function ParameterPair(Name, Value)
{
  this.Name = Name;
  this.Value = Value;
}

function ExtractParametersFromURL(WindowLocation)
{
  var URL = new String(WindowLocation);
  var StartIndex = URL.indexOf('?', 0);
  var MidIndex = URL.indexOf('=', StartIndex);
  var EndIndex = URL.indexOf('&', StartIndex);
  var Parameters = new Array();  
  
  if (StartIndex != -1)
    while (MidIndex != -1)
    {
      if (EndIndex == -1)
        EndIndex = URL.length;
        
      var Name = URL.slice(StartIndex + 1, MidIndex);
      var Value = URL.slice(MidIndex + 1, EndIndex);      
      
      var Parameter = new ParameterPair(Name, Value);      
      Parameters.push(Parameter);
      
      StartIndex = EndIndex;
      MidIndex = URL.indexOf('=', StartIndex+1);
      EndIndex = URL.indexOf('&', StartIndex+1);
      //alert(StartIndex +":"+MidIndex+":"+EndIndex);
    }
  URL=null;//destroy String
  
  return Parameters;
}
