// Newtimer.js version 1.0 // james wright // These four functions will take the time till expiration + 1s (expireat) and at that time send a request to jpartner // That request will not reset the expiration for the session. // Because of the specialized request, Jpartner will response with one of two choices // Logged in users will get an XML response back that indicates the new time of expiration. // At that point, the js will effectively start over with the new expiration time. // Logged out users will be a standard response back. At that point the JS will clear the screen, // inform the user they've been logged out, and then reload the window on their confirmation. // Also included is the standardized function parseXML which will search a DQ for the text value of a given node. var req; var testrequest; var sess; function startclock(expireat) { sess = expireat; window.setTimeout('reqSender();', expireat); } function reqSender(){ var url = "/?&Action=viewSimplejsttimer"; var myAjax = new Ajax.Request(url, {method:'post',onComplete:testrequest}); } function testrequest(transport){ if (204 == transport.status){ // logged out. var xxy = window.location.href; clear(); alert('You have been logged out. The window will now refresh.'); document.location.href = xxy; } else{ var s = transport.responseText; var time; var node = 'jsttimertime'; if (s.indexOf(node) != -1){ time = parseXML(s, node); window.setTimeout('reqSender();', time); } else { var xxz = window.location.href; clear(); alert('You have been logged out. The window will now refresh.'); document.location.href = xxz; } } } function parseXML(input,nodename){ var length = nodename.length + 2; var start = input.indexOf("<"+ nodename+">") + length; var stop = input.indexOf(""); var out = input.substring(start, stop); return out; } function clear(){ var _s=top; var _d=_s.document; _d.open(); _d.write(""); _d.close(); }