var caution = false
var now = new Date()
fixDate(now)
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000)

var account = getCookie("last_account")
if( !account )
     account=""

var user_id = getCookie("last_user")
if( !user_id )
     user_id = ""


function window_onload() {
   init();
   document.all.able.requestFocus();
}

function window_onswitch() {
   document.all.able.requestFocus();
}

function init()
{
    document.all.able.restore_last_account_and_user( account, user_id );
}

function window_onunload() {
   finalize();
}


function finalize() {
   account=document.all.able.get_last_account();
   setCookie("last_account", account, now)
   user_id=document.all.able.get_last_user();
   setCookie("last_user", user_id, now)
}


function setCookie(name, value, expires, path, domain, secure) {
      var curCookie = name + "=" + escape(value) +
         ((expires) ? "; expires=" + expires.toGMTString() : "") +
         ((path) ? "; path=" + path : "") +
         ((domain) ? "; domain=" + domain : "") +
         ((secure) ? "; secure" : "")
      if (!caution || (name + "=" + escape(value)).length <= 4000)
         document.cookie = curCookie
      else
         if (confirm("Cookie exceeds 4KB and will be cut!"))
            document.cookie = curCookie
}

function getCookie(name) {
      var prefix = name + "="
      var cookieStartIndex = document.cookie.indexOf(prefix)
      if (cookieStartIndex == -1)
         return null
      var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex +
         prefix.length)
      if (cookieEndIndex == -1)
         cookieEndIndex = document.cookie.length
      return unescape(document.cookie.substring(cookieStartIndex +
         prefix.length,
   cookieEndIndex))
}

function fixDate(date) {
      var base = new Date(0)
      var skew = base.getTime()
      if (skew > 0)
         date.setTime(date.getTime() - skew)
}

function writeAppletTagStart() {
   document.write('<applet code="com.ProgrammingConcepts.Able.Able.class"');
   document.write('        width="975"');
   document.write('        scriptable="true"');
   document.write('        name="able"');
   document.write('        id="able"');
   document.write('        archive="ABLE.jar"');
   document.write('        height="555"');
   document.write('        mayscript>');
}

function writeAppletTagEnd() {
   document.write('</applet>');
}
