/* The contents of this file are protected by copyright law. * All rights are retained. * A non-exclusive license is hereby granted to use the file * in connection with the website http://www.covariable.com/ * Copyright 2006 Woodley Packard and Steven Stanek */ /* Uses a junk variable to make certain that GETs are unique. That is, after a change is made * a get request may return a different value from a call before the modification was made. You do * not want the browser to return an old cached version of the get after the modification. */ var junk=Math.floor(Math.random()*100000000); function xmlh() { try { return new XMLHttpRequest(); } catch(e) { var XMLHTTP_IDS = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP']; for(var i in XMLHTTP_IDS) { try { return new ActiveXObject(XMLHTTP_IDS[i]); } catch(e) {} } alert("unable to create xmlhttprequest"); return null; } } function urlencode(string) { string = string.replace(new RegExp("%", "g"), "%25"); string = string.replace(new RegExp("#", "g"), "%23"); string = string.replace(new RegExp("\\+", "g"), "%2B"); string = string.replace(new RegExp("&", "g"), "%26"); string = string.replace(new RegExp("=", "g"), "%3D"); string = string.replace(new RegExp("/", "g"), "%2F"); string = string.replace(new RegExp(" ", "g"), "+"); return string; } function urldecode(string) { string = string.replace(new RegExp("\\+", "g"), " "); string = string.replace(new RegExp("%23", "g"), "#"); string = string.replace(new RegExp("%2B", "g"), "+"); string = string.replace(new RegExp("%26", "g"), "&"); string = string.replace(new RegExp("%3D", "g"), "="); string = string.replace(new RegExp("%2F", "g"), "/"); string = string.replace(new RegExp("%25", "g"), "%"); string = string.replace(new RegExp("%20", "g"), " "); return string; } var dontbothermeagain = 0; function ajaxPost(target, type, data) { var req = xmlh(); req.open('POST', target, false); req.setRequestHeader("Content-type", type); req.send(data); if(req.status == 200) { if(req.responseText == "200 Session Expired") { if(!dontbothermeagain)alert("Your session has expired. Please log in again."); dontbothermeagain=1; throw("session expired"); } return req.responseText; } else alert(req.status + ": " + req.statusText); return null; } function ajaxGet(target) { var req = xmlh(); if(target.search("\\?") != -1) req.open('GET', target+"&junk="+junk, false); else req.open('GET', target+"?junk="+junk, false); req.send(""); if(req.status == 200) { if(req.responseText == "200 Session Expired\n" || req.responseText == "200 Session Expired") { if(!dontbothermeagain)alert("Your session has expired. Please log in again."); dontbothermeagain=1; throw("session expired"); } return req.responseText; } else alert(target + "\n" + req.status + ": " + req.statusText); return null; }