/*
 * @require jade.js
 */
jade.Ajax=function(a,b,c,d){this.url=a;if(b)this.method=b;if(c)this.user=c;if(d)this.password=d};
jade.Ajax.prototype.url="";jade.Ajax.prototype.method="POST";jade.Ajax.prototype.user=null;jade.Ajax.prototype.password=null;jade.Ajax.getRequestor=function(){if(window.XMLHttpRequest)return new XMLHttpRequest;if(window.ActiveXObject)return new ActiveXObject("Microsoft.XMLHTTP");throw Error("Unable to initialize Ajax requestor");};
jade.Ajax.getResponse=function(a){var b;return(b=a.getResponseHeader("Content-Type"))&&b.toLowerCase().indexOf("xml")!=-1?a.responseXML:a.responseText};
jade.Ajax.prototype.send=function(a,b,c){var d;d=jade.Ajax.getRequestor();d.open(this.method,this.url,!0,this.user,this.password);b&&new jade.AjaxResponse(d,b,c);(!a||!a.getElementById)&&d.setRequestHeader("Content-type","text/plain");d.send(a);jade.sessionTimeout&&jade.sessionTimeout.reset()};
jade.Ajax.send=function(a,b,c,d){var e;e=new jade.Ajax(a,b?"POST":"GET");e.send(b,c,d)};
jade.Ajax.prototype.request=function(a){var b;b=jade.Ajax.getRequestor();b.open(this.method,this.url,!1,this.user,this.password);(!a||!a.getElementById)&&b.setRequestHeader("Content-type","text/plain");b.send(a);if(b.status!=200)throw Error("HTTP request failed: "+b.status+" "+b.statusText);jade.sessionTimeout&&jade.sessionTimeout.reset();return jade.Ajax.getResponse(b)};
jade.Ajax.request=function(a,b){var c;c=new jade.Ajax(a,b?"POST":"GET");return c.request(b)};
jade.AjaxResponse=function(a,b,c){var d;this.requestor=a;this.onResponse=b;if(c)this.onResponseScope=c;d=jade.AjaxResponse.nextInstance++;jade.AjaxResponse.instances[d]=this;a.onreadystatechange=function(){jade.AjaxResponse.handleReadyStateChange(d)}};
jade.AjaxResponse.prototype.requestor=null;jade.AjaxResponse.prototype.onResponse=null;jade.AjaxResponse.prototype.onResponseScope=window;jade.AjaxResponse.nextInstance=1;jade.AjaxResponse.instances=[];jade.AjaxResponse.prototype.handleReadyStateChange=function(a){this.requestor.readyState==4&&(this.onResponse.call(this.onResponseScope,jade.Ajax.getResponse(this.requestor),this.requestor),jade.AjaxResponse.instances[a]=null)};
jade.AjaxResponse.handleReadyStateChange=function(a){jade.AjaxResponse.instances[a].handleReadyStateChange(a)};
