function RegisterNamespaces(){
for(var i=0;i<arguments.length;i++){
var p=arguments[i].split("."),w=window;
for(var j=0;j<p.length;j++){
if(!w[p[j]]){
w[p[j]]={};
}
w=w[p[j]];
}
}
}
RegisterNamespaces("Inpl.Network");
if(!window.XMLHttpRequest&&window.ActiveXObject){
window.XMLHttpRequest=function(){
var r,x=["MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
for(var a in x){
try{
r=new ActiveXObject(x[a]);
return r;
}
catch(e){
}
return null;
}
};
}
Inpl.Network=new function(){
var _8=this;
var _9=new Queue();
this.XML=1;
this.JSON=2;
this.TEXT=3;
this.JS=4;
this.CSS=5;
var _a="Inpl_Progress";
this.DEFAULT_TIMEOUT=5000;
var _b=null;
this.onShowProgress=showProgress;
this.onHideProgress=hideProgress;
var _c=null;
var _d="Wczytuję...";
var cn="Inpl.Network.";
this.createRequest=function(_f,url,_11,_12,_13){
var r=null;
if(_8.BrowserIsCompatible()){
r=new Request(_f,url,_11,_12,_13);
}
return r;
};
this.get=function(_15){
if(_15.params){
_15.url+=(-1==_15.url.indexOf("?")?"?":"&")+getParams(_15.params);
}
var r=_8.createRequest(_15.type?_15.type:_8.TEXT,_15.url,null,_15.tag||null,_15.headers||null);
r.Execute(_15.onSuccess||null,_15.timeout?_15.timeout:_8.DEFAULT_TIMEOUT,_15.onError||null,_15.onTimeout||null);
return r;
};
this.post=function(_17){
var r=_8.createRequest(_17.type?_17.type:_8.TEXT,_17.url,_17.params||null,_17.tag||null,_17.headers||null);
r.Execute(_17.onSuccess||null,_17.timeout?_17.timeout:_8.DEFAULT_TIMEOUT,_17.onError||null,_17.onTimeout||null);
return r;
};
this.loadCss=function(_19){
if(typeof _19=="string"){
_19={"url":_19};
}
_19.type=_8.CSS;
return _8.get(_19);
};
this.loadJs=function(_1a){
if(typeof _1a=="string"){
_1a={"url":_1a};
}
_1a.type=_8.JS;
return _8.get(_1a);
};
this.download=function(obj,_1c){
if(_1c.tag){
_1c.tag.__downloadToObject=obj;
}else{
_1c.tag={"__downloadToObject":obj};
}
if(_1c.onSuccess){
_1c.tag.__onSuccess=_1c.onSuccess;
}
_1c.onSuccess=new Function("el, context",cn+"doneDownload(el, context)");
return _8.get(_1c);
};
this.doneDownload=function(el,_1e){
if(typeof _1e.__downloadToObject=="object"){
_1e.__downloadToObject.innerHTML=el;
}else{
$(_1e.__downloadToObject).innerHTML=el;
}
_1e.__downloadToObject=null;
if(_1e.__onSuccess){
run=_1e.__onSuccess;
_1e.__onSuccess=null;
run(el,_1e);
}
};
this.setMaxParallelRequest=function(max){
_9.setMaxParallelRequest(max);
};
function getParams(p){
var r="";
for(var i in p){
r+=(r?"&":"")+urlEncode(i)+"="+urlEncode(p[i]);
}
return r;
}
this.BrowserIsCompatible=function(){
return (window.XMLHttpRequest?true:false);
};
this.setProgressText=function(_23){
_d=_23;
};
function createProgress(){
if($(_a)){
return $(_a);
}else{
_b=document.createElement("DIV");
_b.id=_a;
_b.style.position="fixed";
_b.style.top="0px";
_b.style.right="0px";
var dPp=document.createElement("p");
dPp.innerHTML=_d;
_b.appendChild(dPp);
if(document.all&&!window.opera){
_b.style.position="absolute";
}
document.body.appendChild(_b);
}
return _b;
}
this.updateProgressPosition=function(){
if(_b){
$(_a).style.top=document.body.scrollTop+"px";
$(_a).style.left=(document.body.clientWidth-$(_a).offsetWidth)+"px";
}
};
function showProgress(){
if(!_c){
_c=setTimeout(realShowProgress,200);
if(document.all&&!window.opera){
window.attachEvent("onresize",_8.updateProgressPosition);
window.attachEvent("onscroll",_8.updateProgressPosition);
}
}
}
function hideProgress(){
clearShowProgress();
if(_b){
_b.style.display="none";
if(document.all&&!window.opera){
window.detachEvent("onresize",_8.updateProgressPosition);
window.detachEvent("onscroll",_8.updateProgressPosition);
}
}
}
function realShowProgress(){
createProgress();
_b.style.display="block";
}
function clearShowProgress(){
if(_c){
clearTimeout(_c);
}
_c=null;
}
function Request(_25,url,_27,_28,_29){
var _2a=false;
if(_25!=_8.JS&&_25!=_8.CSS){
url+=(-1==url.indexOf("?")?"?":"&")+"inpl_network_request=true";
}
var _2b={"type":_25,"url":url,"onSuccess":null,"context":_28,"postString":null,"headers":_29,"timeout":null};
if(typeof _27=="object"){
_2b.postString=getParams(_27);
}else{
_2b.postString=_27;
}
this.Execute=function(_2c,_2d,_2e,_2f){
_2b.onSuccess=_2c;
if(_2e){
_2b.onError=_2e;
}
if(_2f){
_2b.onTimeout=_2f;
}
if(_2d){
_2b.timeout=_2d;
}else{
_2b.timeout=_8.DEFAULT_TIMEOUT;
}
if(!_2a){
_9.Add(_2b);
}
_2a=true;
};
this.IsExecuting=function(){
return _2a;
};
this.Abort=function(){
_9.Remove(_2b);
_2a=false;
};
}
function Queue(){
var _30=this;
var _31=[];
var _32=0;
var _33=2;
this.setMaxParallelRequest=function(max){
_33=max;
};
this.Add=function(_35){
_31.push(_35);
_30.Continue();
};
this.Remove=function(_36){
for(var i in _31){
if(_31[i]===_36){
_31.splice(parseInt(i),1);
break;
}
}
};
this.AbortAll=function(){
_31=[];
};
this.Continue=function(){
if(_32<_33){
if(_31.length){
_8.onShowProgress();
var o=_31.shift();
_32++;
switch(o.type){
case _8.XML:
case _8.TEXT:
case _8.JSON:
o.executing=FetchText(o);
break;
case _8.JS:
o.executing=FetchJs(o);
break;
case _8.CSS:
o.executing=FetchCss(o);
break;
default:
_32--;
}
}else{
_8.onHideProgress();
}
}
};
function FetchText(o){
var xml=new XMLHttpRequest();
if(o.timeout){
o.timer=setTimeout(TimedOut,o.timeout);
}
var i=0;
xml.onreadystatechange=doCallback;
if(o.postString){
xml.open("POST",o.url,true);
xml.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xml.setRequestHeader("X-Requested-With","XMLHttpRequest");
}else{
xml.open("GET",o.url,true);
xml.setRequestHeader("X-Requested-With","XMLHttpRequest");
}
if(o.headers){
for(var h in o.headers){
xml.setRequestHeader(h,o.headers[h]);
}
}
xml.send(o.postString);
function doCallback(){
if(4==xml.readyState){
xml.onreadystatechange=function(){
};
if(o.timer){
clearTimeout(o.timer);
}
var r=null;
switch(o.type){
case _8.XML:
if(xml.responseXML){
r=xml.responseXML;
}
break;
case _8.TEXT:
if(xml.responseText){
r=xml.responseText;
}
break;
case _8.JSON:
if(xml.responseText){
r=new Function("return "+xml.responseText)();
}
break;
}
Finished(r,o);
xml=o=null;
}
}
function TimedOut(){
xml.onreadystatechange=function(){
};
xml.abort();
xml=null;
Finished(null,o);
o=null;
}
return xml;
}
function FetchCss(o){
var css=document.createElement("LINK");
css.onload=doCallback;
css.onerror=doError;
css.setAttribute("rel","stylesheet");
css.setAttribute("type","text/css");
css.setAttribute("href",o.url);
document.getElementsByTagName("HEAD")[0].appendChild(css);
if(o.timeout){
o.timer=setTimeout(TimedOut,o.timeout);
}
var i=0;
function doCallback(){
if(o.timer){
clearTimeout(o.timer);
}
Finished(true,o);
css=o=null;
}
function doError(){
if(o.timer){
clearTimeout(o.timer);
}
Finished(null,o);
css=o=null;
}
function TimedOut(){
Finished(null,o);
o=null;
}
return css;
}
function FetchJs(o){
var js=document.createElement("SCRIPT");
js.onload=doCallback;
js.onerror=doError;
js.setAttribute("type","text/javascript");
js.setAttribute("src",o.url);
document.body.appendChild(js);
if(o.timeout){
o.timer=setTimeout(TimedOut,o.timeout);
}
var i=0;
function doCallback(){
if(o.timer){
clearTimeout(o.timer);
}
Finished(true,o);
js=o=null;
}
function doError(){
if(o.timer){
clearTimeout(o.timer);
}
Finished(null,o);
js=o=null;
}
function TimedOut(){
Finished(null,o);
o=null;
}
return js;
}
function Finished(el,obj){
_32--;
if(obj.onTimeout&&null==el){
obj.onTimeout(obj.context);
}else{
if(obj.onError&&null==el){
obj.onError(obj.context);
}else{
if(obj.onSuccess){
obj.onSuccess(el,obj.context);
}
}
}
obj=obj.onSuccess=obj.onError=obj.onTimeout=obj.context=obj.executing=el=null;
setTimeout(_30.Continue,1);
}
}
function urlEncode(s){
r=""+s;
r=r.replace(/\%/g,"%25");
r=r.replace(/\n/g,"%0A");
r=r.replace(/\s/g,"%20");
r=r.replace(/\#/g,"%23");
r=r.replace(/\&/g,"%26");
r=r.replace(/\+/g,"%2B");
r=r.replace(/\?/g,"%3F");
r=r.replace(/\"/g,"%22");
r=r.replace(/\'/g,"%27");
r=r.replace(/:/g,"%3A");
r=r.replace(/\//g,"%2F");
r=r.replace(/</g,"%3C");
r=r.replace(/>/g,"%3E");
r=r.replace(/\\/g,"%5C");
return r;
}
function $(n){
return document.getElementById(n);
}
this.assign=function(_48,_49){
if(typeof _48=="string"){
_48=$(_48);
}
if(_49){
_48.__params=_49;
}
if(_48.onsubmit){
_48.__onsubmit=_48.onsubmit;
}
_48.onsubmit=new Function("return "+cn+"send(this)");
};
this.send=function(_4a,_4b){
var r=true;
if(typeof _4a=="string"){
_4a=$(_4a);
}
if(!_4b&&_4a.__params){
_4b=_4a.__params;
}
var i,k,e={};
if(!_4b.url){
_4b.url=_4a.action;
}
if(!_4b.params){
_4b.params={};
}
for(i=0;i<_4a.elements.length;i++){
e=_4a.elements[i];
if(e.disabled){
continue;
}
switch(e.type){
case "text":
case "password":
case "hidden":
case "textarea":
_4b.params[e.name]=e.value;
break;
case "select-one":
if(e.selectedIndex>=0){
_4b.params[e.name]=e.options[e.selectedIndex].value;
}
break;
case "select-multiple":
for(k=0;k<e.options.length;k++){
if(e.options[k].selected){
if(!_4b.params[e.name]){
_4b.params[e.name]=[];
}
_4b.params[e.name][_4b.params[e.name].length]=e.options[k].value;
}
}
break;
case "checkbox":
if(e.checked){
if(!_4b.params[e.name]){
_4b.params[e.name]=[];
}
_4b.params[e.name][_4b.params[e.name].length]=e.value;
}
break;
case "radio":
if(e.checked){
_4b.params[e.name]=e.value;
}
break;
}
}
if(_4a.__onsubmit){
r=_4a.__onsubmit();
}
if(r){
if("post"==_4a.method){
_8.post(_4b);
}else{
_8.get(_4b);
}
}
return false;
};
};

