var XHR=new Class({options:{method:"post",async:true,onRequest:Class.empty,onSuccess:Class.empty,onFailure:Class.empty,urlEncoded:true,encoding:"utf-8",autoCancel:false,headers:{}},setTransport:function(){
this.transport=(window.XMLHttpRequest)?new XMLHttpRequest():(window.ie?new ActiveXObject("Microsoft.XMLHTTP"):false);
return this;
},initialize:function(_2b6){
this.setTransport().setOptions(_2b6);
this.options.isSuccess=this.options.isSuccess||this.isSuccess;
this.headers={};
if(this.options.urlEncoded&&this.options.method=="post"){
var _2b7=(this.options.encoding)?"; charset="+this.options.encoding:"";
this.setHeader("Content-type","application/x-www-form-urlencoded"+_2b7);
}
if(this.options.initialize){
this.options.initialize.call(this);
}
},onStateChange:function(){
if(this.transport.readyState!=4||!this.running){
return;
}
this.running=false;
var _2b8=0;
try{
_2b8=this.transport.status;
}
catch(e){
}
if(this.options.isSuccess.call(this,_2b8)){
this.onSuccess();
}else{
this.onFailure();
}
this.transport.onreadystatechange=Class.empty;
},isSuccess:function(_2b9){
return ((_2b9>=200)&&(_2b9<300));
},onSuccess:function(){
this.response={"text":this.transport.responseText,"xml":this.transport.responseXML};
this.fireEvent("onSuccess",[this.response.text,this.response.xml]);
this.callChain();
},onFailure:function(){
this.fireEvent("onFailure",this.transport);
},setHeader:function(name,_2bb){
this.headers[name]=_2bb;
return this;
},send:function(url,data){
if(this.options.autoCancel){
this.cancel();
}else{
if(this.running){
return this;
}
}
this.running=true;
if(data&&this.options.method=="get"){
url=url+(url.contains("?")?"&":"?")+data;
data=null;
}
this.transport.open(this.options.method.toUpperCase(),url,this.options.async);
this.transport.onreadystatechange=this.onStateChange.bind(this);
if((this.options.method=="post")&&this.transport.overrideMimeType){
this.setHeader("Connection","close");
}
$extend(this.headers,this.options.headers);
for(var type in this.headers){
try{
this.transport.setRequestHeader(type,this.headers[type]);
}
catch(e){
}
}
this.fireEvent("onRequest");
this.transport.send($pick(data,null));
return this;
},cancel:function(){
if(!this.running){
return this;
}
this.running=false;
this.transport.abort();
this.transport.onreadystatechange=Class.empty;
this.setTransport();
this.fireEvent("onCancel");
return this;
}});
XHR.implement(new Chain,new Events,new Options);
var Ajax=XHR.extend({options:{data:null,update:null,onComplete:Class.empty,evalScripts:false,evalResponse:false},initialize:function(url,_2c0){
this.addEvent("onSuccess",this.onComplete);
this.setOptions(_2c0);
this.options.data=this.options.data||this.options.postBody;
if(!["post","get"].contains(this.options.method)){
this._method="_method="+this.options.method;
this.options.method="post";
}
this.parent();
this.setHeader("X-Requested-With","XMLHttpRequest");
this.setHeader("Accept","text/javascript, text/html, application/xml, text/xml, */*");
this.url=url;
},onComplete:function(){
if(this.options.update){
$(this.options.update).empty().setHTML(this.response.text);
}
if(this.options.evalScripts||this.options.evalResponse){
this.evalScripts();
}
this.fireEvent("onComplete",[this.response.text,this.response.xml],20);
},request:function(data){
data=data||this.options.data;
switch($type(data)){
case "element":
data=$(data).toQueryString();
break;
case "object":
data=Object.toQueryString(data);
}
if(this._method){
data=(data)?[this._method,data].join("&"):this._method;
}
return this.send(this.url,data);
},evalScripts:function(){
var _2c2,scripts;
if(this.options.evalResponse||(/(ecma|java)script/).test(this.getHeader("Content-type"))){
scripts=this.response.text;
}else{
scripts=[];
var _2c3=/<script[^>]*>([\s\S]*?)<\/script>/gi;
while((_2c2=_2c3.exec(this.response.text))){
scripts.push(_2c2[1]);
}
scripts=scripts.join("\n");
}
if(scripts){
(window.execScript)?window.execScript(scripts):window.setTimeout(scripts,0);
}
},getHeader:function(name){
try{
return this.transport.getResponseHeader(name);
}
catch(e){
}
return null;
}});
Object.toQueryString=function(_2c5){
var _2c6=[];
for(var _2c7 in _2c5){
_2c6.push(encodeURIComponent(_2c7)+"="+encodeURIComponent(_2c5[_2c7]));
}
return _2c6.join("&");
};
Element.extend({send:function(_2c8){
return new Ajax(this.getProperty("action"),$merge({data:this.toQueryString()},_2c8,{method:"post"})).request();
}});
var Cookie=new Abstract({options:{domain:false,path:false,duration:false,secure:false},set:function(key,_2ca,_2cb){
_2cb=$merge(this.options,_2cb);
_2ca=encodeURIComponent(_2ca);
if(_2cb.domain){
_2ca+="; domain="+_2cb.domain;
}
if(_2cb.path){
_2ca+="; path="+_2cb.path;
}
if(_2cb.duration){
var date=new Date();
date.setTime(date.getTime()+_2cb.duration*24*60*60*1000);
_2ca+="; expires="+date.toGMTString();
}
if(_2cb.secure){
_2ca+="; secure";
}
document.cookie=key+"="+_2ca;
return $extend(_2cb,{"key":key,"value":_2ca});
},get:function(key){
var _2ce=document.cookie.match("(?:^|;)\\s*"+key.escapeRegExp()+"=([^;]*)");
return _2ce?decodeURIComponent(_2ce[1]):false;
},remove:function(_2cf,_2d0){
if($type(_2cf)=="object"){
this.set(_2cf.key,"",$merge(_2cf,{duration:-1}));
}else{
this.set(_2cf,"",$merge(_2d0,{duration:-1}));
}
}});
var Json={toString:function(obj){
switch($type(obj)){
case "string":
return "\""+obj.replace(/(["\\])/g,"\\$1")+"\"";
case "array":
return "["+obj.map(Json.toString).join(",")+"]";
case "object":
var _2d2=[];
for(var _2d3 in obj){
_2d2.push(Json.toString(_2d3)+":"+Json.toString(obj[_2d3]));
}
return "{"+_2d2.join(",")+"}";
case "number":
if(isFinite(obj)){
break;
}
case false:
return "null";
}
return String(obj);
},evaluate:function(str,_2d5){
return (($type(str)!="string")||(_2d5&&!str.test(/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/)))?null:eval("("+str+")");
}};
Json.Remote=XHR.extend({initialize:function(url,_2d7){
this.url=url;
this.addEvent("onSuccess",this.onComplete);
this.parent(_2d7);
this.setHeader("X-Request","JSON");
},send:function(obj){
return this.parent(this.url,"json="+Json.toString(obj));
},onComplete:function(){
this.fireEvent("onComplete",[Json.evaluate(this.response.text,this.options.secure)]);
}});
var Asset=new Abstract({javascript:function(_2d9,_2da){
_2da=$merge({"onload":Class.empty},_2da);
var _2db=new Element("script",{"src":_2d9}).addEvents({"load":_2da.onload,"readystatechange":function(){
if(this.readyState=="complete"){
this.fireEvent("load");
}
}});
delete _2da.onload;
return _2db.setProperties(_2da).inject(document.head);
},css:function(_2dc,_2dd){
return new Element("link",$merge({"rel":"stylesheet","media":"screen","type":"text/css","href":_2dc},_2dd)).inject(document.head);
},image:function(_2de,_2df){
_2df=$merge({"onload":Class.empty,"onabort":Class.empty,"onerror":Class.empty},_2df);
var _2e0=new Image();
_2e0.src=_2de;
var _2e1=new Element("img",{"src":_2de});
["load","abort","error"].each(function(type){
var _2e3=_2df["on"+type];
delete _2df["on"+type];
_2e1.addEvent(type,function(){
this.removeEvent(type,arguments.callee);
_2e3.call(this);
});
});
if(_2e0.width&&_2e0.height){
_2e1.fireEvent("load",_2e1,1);
}
return _2e1.setProperties(_2df);
},images:function(_2e4,_2e5){
_2e5=$merge({onComplete:Class.empty,onProgress:Class.empty},_2e5);
if(!_2e4.push){
_2e4=[_2e4];
}
var _2e6=[];
var _2e7=0;
_2e4.each(function(_2e8){
var img=new Asset.image(_2e8,{"onload":function(){
_2e5.onProgress.call(this,_2e7);
_2e7++;
if(_2e7==_2e4.length){
_2e5.onComplete();
}
}});
_2e6.push(img);
});
return new Elements(_2e6);
}});
