if(typeof($try)=="undefined"){$try=function(){for(var i=0,l=arguments.length;i<l;i++){try{return arguments[i]();}catch(e){}}return null;};}if(typeof($empty)=="undefined"){$empty=function(){};}if(typeof($exec)=="undefined"){var $exec=function(text){if(!text)return text;if(window.execScript){window.execScript(text);}else{var script=document.createElement('script');script.setAttribute('type','text/javascript');script.text=text;headTag=document.getElementsByTagName("HEAD")[0];headTag.appendChild(script);}return text;};}if(typeof($type)=="undefined"){$type=function(obj){if(obj==undefined)return false;if(obj.nodeName){switch(obj.nodeType){case 1:return'element';case 3:return(/\S/).test(obj.nodeValue)?'textnode':'whitespace';}}else if(typeof obj.length=='number'){if(obj.callee)return'arguments';else if(obj.item)return'collection';}return typeof obj;}}if(typeof(Function.prototype.bind)=="undefined"){Function.prototype.bind=function(obj){var fn=this;return function(){var args=[this];for(var i=0,ix=arguments.length;i<ix;i++){args.push(arguments[i]);}return fn.apply(obj,args);};};}if(typeof(String.prototype.stripScripts)=="undefined"){String.prototype.stripScripts=function(option){var scripts='';var text=this.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi,function(){scripts+=arguments[1]+'\n';return'';});if(option===true)$exec(scripts);else if($type(option)=='function')option(scripts,text);return text;}}if(typeof(String.prototype.contains)=="undefined"){String.prototype.contains=function(string,separator){return(separator)?(separator+this+separator).indexOf(separator+string+separator)>-1:this.indexOf(string)>-1;}}var sendchk;Libero.Request=Class.create();Libero.Request.prototype={options:{url:'',data:'',headers:{'X-Requested-With':'XMLHttpRequest','Accept':'text/javascript, text/html, application/xml, text/xml, */*'},async:true,method:'post',link:'',isSuccess:null,urlEncoded:true,encoding:'utf-8',evalResponse:true,requestType:'',update:false,evalScripts:true,secure:true},initialize:function(options){this._setoptions(options);this.xhr=this._detect();this.options.isSuccess=this.options.isSuccess||this.isSuccess;this.headers=this._setheader(this.options.headers);var rtype=this.options.requestType.toLowerCase();if(rtype=='json'){this.headers=this._setheader(this.headers,'Accept','application/json');this.headers=this._setheader(this.headers,'X-Request','JSON');}},onStateChange:function(){if(this.xhr.readyState!=4||!this.running)return;this.complete(this.xhr.getAllResponseHeaders());this.running=false;this.status=0;$try(function(){this.status=this.xhr.status;}.bind(this));if(this.options.isSuccess.call(this,this.status)){this.response={text:this.xhr.responseText,xml:this.xhr.responseXML};this.success(this.response.text,this.response.xml);}else{this.response={text:null,xml:null};this.failure(this.xhr.getAllResponseHeaders());}this.xhr.onreadystatechange=$empty;},isSuccess:function(){return((this.status>=200)&&(this.status<300));},success:function(text,xml){var rtype=this.options.requestType.toLowerCase();var response={};if(rtype=='html'){var options=this.options,response=this.response;response.html=text.stripScripts(function(script){response.javascript=script;});response.tree=null;var temp=this._processHTML(response.html);if(temp){response.tree=temp.childNodes;response.elements=temp.getElementsByTagName('*');}var upElement=$(this.options.update);if(upElement){this.sethtml(upElement,'');this.sethtml(upElement,response.html);}if(options.evalScripts)$exec(response.javascript);this.onSuccess(response.tree,response.elements,response.html,response.javascript);}else if(rtype=='json'){json=this._jsondecode(text,this.options.secure);response.text=text;this.onSuccess(json,response.text);}else{response.text=this._processScripts(text);response.xml=xml;this.onSuccess(response.text,xml);}},onSuccess:function(){},request:function(){this.onRequest();},onRequest:function(){},complete:function(){this.onComplete(arguments);},onComplete:function(){},failure:function(){this.onFailure();},onFailure:function(){},send:function(options){var vrReturn=this;if(typeof(GlobalchkLoginUrl)!='undefined'){newimg=document.createElement('img');var rand=parseInt(777*Math.random(0,1));newimg.src=GlobalchkLoginUrl+'?ajax=1&rnd='+rand;newimg.onload=function(){if(!this._check(arguments.callee,options))return this;this.running=true;var dataform='';if(options){dataform=this._serializeformdata(options);}var data=this.options.data,url=this.options.url,method=this.options.method;data=this._toQueryString(data);if(dataform){data+='&'+dataform;}if(this.options.urlEncoded&&method=='post'){var encoding=(this.options.encoding)?'; charset='+this.options.encoding:'';this.headers=this._setheader(this.headers,'Content-type','application/x-www-form-urlencoded'+encoding);}if(data&&method=='get'){url=url+(url.contains('?')?'&':'?')+data;data=null;}this.xhr.open(method.toUpperCase(),url,this.options.async);this.xhr.onreadystatechange=this.onStateChange.bind(this);for(var key in this.headers){try{this.xhr.setRequestHeader(key,this.headers[key]);}catch(e){}}this.request();this.xhr.send(data);if(!this.options.async)this.onStateChange.bind(this);return this;}.bind(this);newimg.onerror=function(){this.failure();vrReturn=false;}.bind(this);return vrReturn;}else{if(!this._check(arguments.callee,options))return this;this.running=true;var dataform='';if(options){dataform=this._serializeformdata(options);}var data=this.options.data,url=this.options.url,method=this.options.method;data=this._toQueryString(data);if(dataform){data+='&'+dataform;}if(this.options.urlEncoded&&method=='post'){var encoding=(this.options.encoding)?'; charset='+this.options.encoding:'';this.headers=this._setheader(this.headers,'Content-type','application/x-www-form-urlencoded'+encoding);}if(data&&method=='get'){url=url+(url.contains('?')?'&':'?')+data;data=null;}this.xhr.open(method.toUpperCase(),url,this.options.async);this.xhr.onreadystatechange=this.onStateChange.bind(this);for(var key in this.headers){try{this.xhr.setRequestHeader(key,this.headers[key]);}catch(e){}}this.request();this.xhr.send(data);if(!this.options.async)this.onStateChange.bind(this);return this;}},cancel:function(){if(!this.running)return this;this.running=false;this.xhr.abort();this.xhr.onreadystatechange=$empty;this.xhr=this._detect();return this;},sethtml:function(element,html){element.innerHTML=html;},_getHeader:function(name){return $try(function(){return this.xhr.getResponseHeader(name);}.bind(this));},_processScripts:function(text){if(this.options.evalResponse||(/(ecma|java)script/).test(this._getHeader('Content-type')))return $exec(text);return text.stripScripts(this.options.evalScripts);},_processHTML:function(text){var match=text.match(/<body[^>]*>([\s\S]*?)<\/body>/i);text=(match)?match[1]:text;var match=text.match(/<(\?)(.*)\1>/);if(match){text=text.replace(match[0],'');}var container=document.createElement('div');return $try(function(){var root='<root>'+text+'</root>',doc;if(document.implementation.createDocument){var parser=new DOMParser();doc=parser.parseFromString(root,"text/xml");}else if(window.ActiveXObject){doc=new ActiveXObject("Microsoft.XMLDOM");doc.async=false;doc.loadXML(root);}root=doc.getElementsByTagName('root')[0];if(root){return root;}else{this.sethtml(container,text);return container;}})||this.sethtml(container,text);},_check:function(caller){if(!this.running)return true;if(this.options.link=='cancel'){this.cancel();return true;}return false;},_serializeformdata:function(f){var g=function(n){return f.getElementsByTagName(n);};var nv=function(e,tf){if(e.multiple){var rs=[];var tot=0;for(var i=0;i<e.options.length;i++){if(e.options[i].selected){rs[tot]=e.name+'['+tot+']='+encodeURIComponent(e.options[i].value);++tot;}}return(rs.join('&'))}else if(e.type=='checkbox'){field=tf[e.name];var rs=[];var tot=0;if(field.length){for(j=0;j<field.length;j++){if(field[j].checked){rs[tot]=field[j].name+'['+tot+']='+encodeURIComponent(field[j].value);++tot;}}return(rs.join('&'));}else{if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return'';}}else{if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return'';}};var tf=f;var i=this._collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked){return nv(i,tf);}});var s=this._collect(g('select'),nv);var t=this._collect(g('textarea'),nv);return i.concat(s).concat(t).join('&');},_collect:function(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v);}return n;},_jsondecode:function(string,secure){if($type(string)!='string'||!string.length)return null;if(secure){if(!(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(string.replace(/\\./g,'@').replace(/"[^"\\\n\r]*"/g,'')))return null;}return eval('('+string+')');},_setheader:function(object,add,value){var vr=[];for(var key in object){vr[key]=object[key];}if(typeof((add))!="undefined"&&typeof((value))!="undefined"){vr[add]=value;}return vr;},_toQueryString:function(base){var queryString=[];for(var key in base){value=base[key];var result;switch(typeof(value)){case'function':break;case'object':result=this._toQueryString(value);break;default:result=key+'='+encodeURIComponent(value);}if(value!=undefined)queryString.push(result);}return queryString.join('&');},_setoptions:function(options){if(typeof(options)=='object'){var result={};for(var i in this.options){if(typeof(options[i])!='undefined'){result[i]=options[i];}else{result[i]=this.options[i];}}}else{result=this.options;}this.options=result;},_detect:function(){var xmlhttp=null;try{xmlhttp=new XMLHttpRequest();}catch(e){try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}}return xmlhttp;}}