var Ajax={getTransport:function(){
return Try.these(function(){
return new XMLHttpRequest();
},function(){
return new ActiveXObject("Msxml2.XMLHTTP");
},function(){
return new ActiveXObject("Microsoft.XMLHTTP");
})||false;
},activeRequestCount:0};
Ajax.Responders={responders:[],_each:function(_1){
this.responders._each(_1);
},register:function(_2){
if(!this.include(_2)){
this.responders.push(_2);
}
},unregister:function(_3){
this.responders=this.responders.without(_3);
},dispatch:function(_4,_5,_6,_7){
this.each(function(_8){
if(_8[_4]&&typeof _8[_4]=="function"){
try{
_8[_4].apply(_8,[_5,_6,_7]);
}
catch(e){
}
}
});
}};
Object.extend(Ajax.Responders,Enumerable);
Ajax.Responders.register({onCreate:function(){
Ajax.activeRequestCount++;
},onComplete:function(){
Ajax.activeRequestCount--;
}});
Ajax.Base=function(){
};
Ajax.Base.prototype={setOptions:function(_9){
this.options={method:"post",asynchronous:true,contentType:"application/x-www-form-urlencoded",parameters:""};
Object.extend(this.options,_9||{});
},responseIsSuccess:function(){
return this.transport.status==undefined||this.transport.status==0||(this.transport.status>=200&&this.transport.status<300);
},responseIsFailure:function(){
return !this.responseIsSuccess();
}};
Ajax.Request=Class.create();
Ajax.Request.Events=["Uninitialized","Loading","Loaded","Interactive","Complete"];
Ajax.Request.prototype=Object.extend(new Ajax.Base(),{initialize:function(url,_11){
this.transport=Ajax.getTransport();
this.setOptions(_11);
this.request(url);
},request:function(url){
var _12=this.options.parameters||"";
if(_12.length>0){
_12+="&_=";
}
try{
this.url=url;
if(this.options.method=="get"&&_12.length>0){
this.url+=(this.url.match(/\?/)?"&":"?")+_12;
}
Ajax.Responders.dispatch("onCreate",this,this.transport);
this.transport.open(this.options.method,this.url,this.options.asynchronous);
if(this.options.asynchronous){
this.transport.onreadystatechange=this.onStateChange.bind(this);
setTimeout((function(){
this.respondToReadyState(1);
}).bind(this),10);
}
this.setRequestHeaders();
var _13=this.options.postBody?this.options.postBody:_12;
this.transport.send(this.options.method=="post"?_13:null);
}
catch(e){
this.dispatchException(e);
}
},setRequestHeaders:function(){
var _14=["X-Requested-With","XMLHttpRequest","X-Prototype-Version",Prototype.Version,"Accept","text/javascript, text/html, application/xml, text/xml, */*"];
if(this.options.method=="post"){
_14.push("Content-type",this.options.contentType);
if(this.transport.overrideMimeType){
_14.push("Connection","close");
}
}
if(this.options.requestHeaders){
_14.push.apply(_14,this.options.requestHeaders);
}
for(var i=0;i<_14.length;i+=2){
this.transport.setRequestHeader(_14[i],_14[i+1]);
}
},onStateChange:function(){
var _16=this.transport.readyState;
if(_16!=1){
this.respondToReadyState(this.transport.readyState);
}
},header:function(_17){
try{
return this.transport.getResponseHeader(_17);
}
catch(e){
}
},evalJSON:function(){
try{
return eval("("+this.header("X-JSON")+")");
}
catch(e){
}
},evalResponse:function(){
try{
return eval(this.transport.responseText);
}
catch(e){
this.dispatchException(e);
}
},respondToReadyState:function(_18){
var _19=Ajax.Request.Events[_18];
var _20=this.transport,json=this.evalJSON();
if(_19=="Complete"){
try{
(this.options["on"+this.transport.status]||this.options["on"+(this.responseIsSuccess()?"Success":"Failure")]||Prototype.emptyFunction)(_20,json);
}
catch(e){
this.dispatchException(e);
}
if((this.header("Content-type")||"").match(/^text\/javascript/i)){
this.evalResponse();
}
}
try{
(this.options["on"+_19]||Prototype.emptyFunction)(_20,json);
Ajax.Responders.dispatch("on"+_19,this,_20,json);
}
catch(e){
this.dispatchException(e);
}
if(_19=="Complete"){
this.transport.onreadystatechange=Prototype.emptyFunction;
}
},dispatchException:function(_21){
(this.options.onException||Prototype.emptyFunction)(this,_21);
Ajax.Responders.dispatch("onException",this,_21);
}});
Ajax.Updater=Class.create();
Object.extend(Object.extend(Ajax.Updater.prototype,Ajax.Request.prototype),{initialize:function(_22,url,_23){
this.containers={success:_22.success?$(_22.success):$(_22),failure:_22.failure?$(_22.failure):(_22.success?null:$(_22))};
this.transport=Ajax.getTransport();
this.setOptions(_23);
var _24=this.options.onComplete||Prototype.emptyFunction;
this.options.onComplete=(function(_25,_26){
this.updateContent();
_24(_25,_26);
}).bind(this);
this.request(url);
},updateContent:function(){
var _27=this.responseIsSuccess()?this.containers.success:this.containers.failure;
var _28=this.transport.responseText;
if(!this.options.evalScripts){
_28=_28.stripScripts();
}
if(_27){
if(this.options.insertion){
new this.options.insertion(_27,_28);
}else{
Element.update(_27,_28);
}
}
if(this.responseIsSuccess()){
if(this.onComplete){
setTimeout(this.onComplete.bind(this),10);
}
}
}});
Ajax.PeriodicalUpdater=Class.create();
Ajax.PeriodicalUpdater.prototype=Object.extend(new Ajax.Base(),{initialize:function(_29,url,_30){
this.setOptions(_30);
this.onComplete=this.options.onComplete;
this.frequency=(this.options.frequency||2);
this.decay=(this.options.decay||1);
this.updater={};
this.container=_29;
this.url=url;
this.start();
},start:function(){
this.options.onComplete=this.updateComplete.bind(this);
this.onTimerEvent();
},stop:function(){
this.updater.onComplete=undefined;
clearTimeout(this.timer);
(this.onComplete||Prototype.emptyFunction).apply(this,arguments);
},updateComplete:function(_31){
if(this.options.decay){
this.decay=(_31.responseText==this.lastText?this.decay*this.options.decay:1);
this.lastText=_31.responseText;
}
this.timer=setTimeout(this.onTimerEvent.bind(this),this.decay*this.frequency*1000);
},onTimerEvent:function(){
this.updater=new Ajax.Updater(this.container,this.url,this.options);
}});

