
_xssAjaxResponse=[];
var ScriptTransport=Class.create({
initialize:function(id){
this.readyState=0;
this.requestId=id;
},
open:function(method,url,asynchronous){
_xssAjaxResponse[this.requestId]={};
this.readyState=1;
this.respondToReadyState(1);
this.onreadystatechange();
this.url=url;
this.userAgent=navigator.userAgent.toLowerCase();
},
send:function(body){
this.readyState=2;
this.onreadystatechange();
this.getScriptXS(this.url);
},
callback:function(){
if(_xssAjaxResponse['unknown']){this.requestId='unknown';}
try{this.responseText=typeof _xssAjaxResponse[this.requestId].response==='string'?_xssAjaxResponse[this.requestId].response:'';}catch(e){this.responseText='';}
try{this.responseJSON=typeof _xssAjaxResponse[this.requestId].response==='object'?_xssAjaxResponse[this.requestId].response:null;}catch(e){this.responseJSON=null;}
try{this.responseXml=(new DOMParser()).parseFromString(_xssAjaxResponse[this.requestId].response,'text/xml');}catch(e){this.responseXml=null;}
try{this.status=parseInt(_xssAjaxResponse[this.requestId].status,10);}catch(e){this.status=404;}
try{this.statusText=this.getStatusText(_xssAjaxResponse[this.requestId].status);}catch(e){this.statusText='Not Found';}
this.readyState=4;
this.onreadystatechange();
delete _xssAjaxResponse[this.requestId];
try{$(this.requestId).remove();}catch(e){}
},
getScriptXS:function(){
var arg={'url':arguments[0]};
this.node=document.createElement('script');
this.node.type='text/javascript';
this.node.id=this.requestId;
this.node.src=arg.url;
var ua=navigator.userAgent.toLowerCase();
if(ua.indexOf('msie')>-1){
this.boundCallback=function(obj){return function(){if(this.readyState==='complete'||this.readyState==='loaded'){return obj.callback.call(obj);}};}
this.node.onreadystatechange=this.boundCallback(this);
}else if(ua.indexOf('webkit')>-1||ua.indexOf('opera')>-1){
this.timepassed=0;
this.checkTimer=setInterval(function(){
this.timepassed=this.timepassed+100;
if(typeof eval(_xssAjaxResponse[this.requestId].status)!=='undefined'&&eval(_xssAjaxResponse[this.requestId].status)!==null){
this.callback();
clearInterval(this.checkTimer);
}
if(this.timepassed>20000){clearInterval(this.checkTimer);}
}.bind(this),100);
}else{
this.node.onload=this.callback.bind(this);
}
this.readyState=3;
this.onreadystatechange();
document.getElementsByTagName('head')[0].appendChild(this.node);
},
setRequestHeader:function(){},
onreadystatechange:function(){},
respondToReadyState:function(){},
getResponseHeader:function(){return false;}
});
Ajax.Request.prototype=Object.extend(Ajax.Request.prototype,{
initialize:function(url,options){
this.options={
method:'post',
asynchronous:true,
contentType:'application/x-www-form-urlencoded',
encoding:'UTF-8',
parameters:'',
evalJSON:true,
evalJS:true
};
Object.extend(this.options,options||{});
this.options.method=this.options.method.toLowerCase();
if(Object.isString(this.options.parameters)){
this.options.parameters=this.options.parameters.toQueryParams();
}else if(Object.isHash(this.options.parameters)){
this.options.parameters=this.options.parameters.toObject();
}
var chars='0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ';
this.requestId='';
for(var i=0;i<20;i++){var r=Math.floor(Math.random()*chars.length);this.requestId+=chars.substring(r,r+1);}
var re=/^(?:\w+:\/\/)([-A-Za-z0-9.]+).*/i;
this.options.crossSite=(re.test(url)&&document.domain.toLowerCase()!==url.replace(re,'$1').toLowerCase());
this.transport=(!this.options.crossSite)?Ajax.getTransport():new ScriptTransport(this.requestId);
this.options.asynchronous=(!this.options.crossSite)?this.options.asynchronous:false;
if(this.options.crossSite){this.options.evalJSON='force';this.options.method='get';}
if(this.transport.respondToReadyState){this.transport.respondToReadyState=this.respondToReadyState.bind(this);}
if(this.options.crossSite){url+=/\?[\w\-]+\=/.test(url)?'&':'?';url+='xss=true&xssrequestid='+this.requestId;}
this.request(url);
}
});