var ajax={xmlhttp:null,buffer:new Array(),active_request:"",csrf_token:"",addRequest:function(b,f,c,d,a,e){ajax_state=ajax.getReadyState();if(ajax_state==false||ajax_state=="COMPLETE"){ajax.send(b,f,c,d,a,e)}else{ajax.buffer.unshift(new Array(b,f,c,d,a,e))}},trySendRequest:function(a){if(a!=null&&a=="COMPLETE"){request=ajax.buffer.pop();if(request!=null&&request.length>0){ajax.send(request[0],request[1],request[2],request[3],request[4],request[5])}}},send:function(b,i,d,g,a,h){try{this.xmlhttp=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")}catch(f){alert("Chyba v soubor ajax.js - Nepodarilo se vytvorit objekt xmlhttp request!");return false}if(b.indexOf("csrf_token")==-1&&this.csrf_token.length>0){if(b.indexOf("?")==-1){b+="?csrf_token="+this.csrf_token}else{b+="&csrf_token="+this.csrf_token}}if(i.toLowerCase()=="post"&&d.indexOf("csrf_token")==-1&&this.csrf_token.length>0){if(d.length>0){d+="&csrf_token="+this.csrf_token}else{d+="csrf_token="+this.csrf_token}}this.xmlhttp.open(i,b,true);this.xmlhttp.onreadystatechange=function(){if(ajax!=null){var e=ajax.getReadyState();if(a!=null){if(h!=null){a(ajax.getReadyState(e),h)}else{a(ajax.getReadyState(e))}}ajax.trySendRequest(e)}};if(g!=null){for(var c in g){this.xmlhttp.setRequestHeader(c,g[c])}}else{this.xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");if(d!=null){this.xmlhttp.setRequestHeader("Content-Length",d.length)}this.xmlhttp.setRequestHeader("Connection","close")}this.active_request=b;this.xmlhttp.send(d);return true},getReadyState:function(a){if(ajax.xmlhttp==null){return false}if(a!="number"){switch(ajax.xmlhttp.readyState){case 0:return"NOT_INITIALIZED";case 1:return"INITIALIZED";case 2:return"SENT";case 3:return"IN_PROCESS";case 4:return"COMPLETE";default:return"UNDEFINED"}}else{return(ajax.xmlhttp.readyState)}},getStatusCode:function(){if(ajax.xmlhttp==null){return false}return ajax.xmlhttp.status},getStatusText:function(){if(ajax.xmlhttp==null){return false}return ajax.xmlhttp.statusText},getResponse:function(a){if(this.xmlhttp==null){return false}if(a=="xml"){return this.xmlhttp.responseXML}else{return this.xmlhttp.responseText}},setToken:function(a){this.csrf_token=a},displayProgress:function(i){var h,g;if(window.pageYoffset){h=window.pageXoffset;g=window.pageYoffset}else{if(document.documentElement&&document.documentElement.scrollTop){h=document.documentElement.scrollLeft;g=document.documentElement.scrollTop}else{if(document.body){h=document.body.scrollLeft;g=document.body.scrollTop}}}var e,d;if(window.innerHeight){e=window.innerWidth;d=window.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){e=document.documentElement.clientWidth;d=document.documentElement.clientHeight}else{if(document.body){e=document.body.clientWidth;d=document.body.clientHeight}}}var b=300;var c=50;var a=h+(e-b)/2;var f=g+(d-c)/2;container=document.createElement("div");container.style.position="fixed";container.style.top="0";container.style.left="0";container.style.zIndex="90";container.style.width="100%";container.style.height=g+d+"px";container.style.backgroundColor="#000";container.style.filter="alpha(opacity=60)";container.style.MozOpacity=" 0.6";container.style.opacity="0.6";loading=document.createElement("div");loading.style.position="absolute";loading.style.width=b+"px";loading.style.height=c+"px";loading.style.top=f+"px";loading.style.left=a+"px";loading.style.textAlign="center";loading.style.zIndex="100";loading.style.color="#fff";loading.style.fontWeight="bold";loading.innerHTML='<img src="/js/loading.gif" alt="loading..." />';if(i!=null&&i.length>0){loading.innerHTML+='<br /><span id="ajaxText">'+i+"</span>"}container.appendChild(loading);if(document.getElementsByTagName("body").item(0)!=null){document.getElementsByTagName("body").item(0).appendChild(container)}},changeProgressText:function(a){if(document.getElementById("ajaxText")!=null&&a!=null&&a.length>0){document.getElementById("ajaxText").innerHTML=a}},hideProgress:function(){if(document.getElementsByTagName("body").item(0)!=null){document.getElementsByTagName("body").item(0).removeChild(container)}}};
