
var allcookies = document.cookie;
var cookie_minutes = 20;

  if (allcookies != "") {
    var ct = allcookies.indexOf("aceuser=");
    var ut = allcookies.indexOf("userid=");
    var dt = allcookies.indexOf("DEBUG_MODE=on");
    if (ct >= 0) {

      //
      // Figure out what domain to set to cookie for
      //
      var v_domain = document.domain;
      v_index = v_domain.indexOf(".dev");
      if (v_index < 0) {
         v_index = v_domain.indexOf(".unit");
         if (v_index < 0) {
           v_index = v_domain.indexOf(".test");
           if (v_index < 0) {
             v_index = v_domain.indexOf(".");
           }
         }
      }
      if (v_index > 0) {
         v_domain = v_domain.substr(v_index);
      }

      //
      // Do not expire this ace if there is no uid
      // Let the regular signin expire the ace
      //

      //
      // Figure out who the ace is
      //
      var v_aceuser = allcookies.substr(ct);
      v_index = v_aceuser.indexOf(";")
      if (v_index > 0) {
        v_aceuser = v_aceuser.substr(0,v_index);
      }
      v_aceuser = v_aceuser.substr(v_aceuser.indexOf("=") + 1);
  
      //
      // Figure out when to expire the cookie
      //
      var expireTime = new Date();
      var now = expireTime.valueOf();
      now = now + cookie_minutes * 60 * 1000;
      expireTime.setTime(now);
      var expireStr = expireTime.toUTCString();
  
      //
      //
      // Now set the cookie
      //
      document.cookie = "aceuser=" + v_aceuser
                      + "; expires=" + expireStr
                      + "; path=/; domain=" + v_domain + ";";

    }
  }

