// first makes sure client is cookieable, then does the ActiveCatalogue login
// need to update the greeting line in the masthead based on whether we're logged in or not


function doesIt() {
 var acceptsCookies = false;
 // first see if we've already done this
 if (document.cookie.indexOf('acceptsCookies=yes') != -1) {
  acceptsCookies = false;	// client really accepts cookies, but we don't want to do the login again
 }
 else {	// either we haven't done this yet, or the client doesn't accept cookies
  document.cookie = 'acceptsCookies=yes; path=/restek'; // Try to set a cookie.
  if (document.cookie.indexOf('acceptsCookies=yes') != -1) {
   acceptsCookies = true;	// client accepts, and this is our first shot at logging them in
  }
 }
 if (acceptsCookies) {
  loginAjax();
 }

 // check to see if there's a globally unique identifier
 // getElementById for the spans (toggle, regis)
 // update spans according to responsetext

 if (document.cookie.indexOf('restekGUID') == -1) {
   var mytoggle = document.getElementById("toggle");
   mytoggle.innerHTML = "<a href=\"javascript:loginscreen(\'/restek/templates/restek34a4/loginscreen.asp\');\">Log In</a>";
 }
 else {
//  var greetme = document.getElementById("greeting");
  var mytoggle = document.getElementById("toggle");
  var philbin = document.getElementById("regis");

//  greetme.innerHTML = userinfo[1];
  mytoggle.innerHTML = "<a href=\"javascript:logoutscreen();\">Log Out</a>";
  philbin.innerHTML = "Your Account";
 }
}

function loginAjax() {
  getXHttp();
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
// do stuff
     userinfo = xmlHttp.responseText.split('=');
  var greetme = document.getElementById("greeting");
  greetme.innerHTML = userinfo[1];
  //alert(xmlHttp.responseText);
      }
    }
  xmlHttp.open("GET","/restek/templates/restek34a4/bespoke/bespokecode/checklogin_flat.asp",true);
  xmlHttp.send(null);
}
