function isNotOldIE(){return((getIEVersionNumber()>5.1)||(getIEVersionNumber()==true));}
encode=function(par)
{return((getIEVersionNumber()>5.01)||(getIEVersionNumber()==true))?encodeURIComponent(par):par;}
function getRandom(){var min_=1;var max_=10000;max_++;var range=max_-min_;var n=Math.floor(Math.random()*range)+min_;return n;}
function getElemText(node){return node.text||node.textContent||(function(node){var txt='';if(node==null){return txt;}
var childrens=node.childNodes;var i=0;while(i<childrens.length){var child=childrens.item(i);switch(child.nodeType){case 5:txt+=arguments.callee(child);break;case 4:txt+=child.nodeValue;break;break;}
i++;}
return txt;}(node))||node.nodeValue;}
function getRequest(){var req_=null;if(typeof window.XMLHttpRequest!="undefined")
req_=new XMLHttpRequest();else
if(typeof ActiveXObject!="undefined"){try{req_=new ActiveXObject("Microsoft.XMLHTTP");}
catch(error1){if(req_===null)
try{req_=new ActiveXObject("Msxml.XMLHTTP");}
catch(error2){req_=null;}}}
return req_;}
function ajax(url,params,method,onComplete,onLoading,onError){this.url=url;this.params=params;this.method=(method)?method:'POST';this.req=getRequest();if(!this.req){this.error=true;return;}
this.onReadyFunc=false;this.onComplete=(onComplete)?onComplete:function(){};this.onLoading=(onLoading)?onLoading:function(){};this.onError=(onError)?onError:function(){this.error=true;alert('Не удалось соединиться с сервером. Попробуйте отправить сообщение позже');restore();};this.sendRequest();}
ajax.prototype.sendRequest=function(url,params,method){this.req=null;this.req=getRequest();if(this.req){var aj=this;this.req.onreadystatechange=function(){if(isNotOldIE())
aj.onReadyFunction.call(aj);else
aj.onReadyFunction();}
var headers={'X-Requested-With':'XMLHttpRequest','Content-Type':'application/x-www-form-urlencoded','Accept':'text/javascript, text/html, application/xml, text/xml, */*'};this.req.open(this.method,this.url,true);for(var name in headers)
this.req.setRequestHeader(name,headers[name]);var pars=this.encodeData(this.params);this.req.send(pars);}
return false;}
ajax.prototype.setOnReadyFunction=function(onReady){this.onReadyFunc=onReady;}
ajax.prototype.onReadyFunction=function(){var aj=this;var ready=aj.req.readyState;if(ready==1){if(aj.onLoading&&typeof aj.onLoading=="function")
aj.onLoading();}
if(ready==4){if(aj.req.status=="200"){if(aj.onComplete&&typeof aj.onComplete=="function"){if(isNotOldIE())
aj.onComplete.call(aj,aj.req);else
aj.onComplete();}
else
if(aj.onComplete&&typeof aj.onComplete=="string")
getElement(aj.onComplete).innerHTML=aj.getResponseText();else
if(aj.onComplete&&typeof aj.onComplete=="object"){var elemNodeName=aj.onComplete.nodeName.toLowerCase();if(elemNodeName=="input"||elemNodeName=="select"||elemNodeName=="option"||elemNodeName=="textarea"){aj.onComplete.value=aj.getResponseText();}else{aj.onComplete.innerHTML=aj.getResponseText();}}}
else
if(aj.onError&&typeof aj.onError=="function")
if(isNotOldIE())
aj.onError.call(aj);else
aj.onError();}}
ajax.prototype.encodeData=function(params,format){out='';if(typeof params=='Object'){for(name in params){out+=name+'='+encode(params[name])+'&';}}
else
if(params)
out+=params.toString();out+="error=er&callback=cb&";out+='rand='+getRandom()+'&js=1&';if(format)
out+='format='+format;return out;}
ajax.prototype.getResponseType=function(){try{var type=this.req.getResponseHeader('Content-Type');if(type.indexOf(';')==-1)
return type;else
return type.substr(0,type.indexOf(';'));}catch(error){return null;}}
ajax.prototype.isResponseText=function(){var type=this.getResponseType();if((type=='plain/text')||(type=='text/html'))
return true;return false;}
ajax.prototype.isResponseXML=function(){var type=this.getResponseType();if((type=='application/xml')||(type=='text/xml'))
return true;return false;}
ajax.prototype.isResponseJSON=function(){var type=this.getResponseType();if((type=='text/javascript')||(type=='application/json'))
return true;return false;}
ajax.prototype.isJSON=function(str){str=str.replace(/\\./g,'@').replace(/"[^"\\\n\r]*"/g,'');return(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);}
ajax.prototype.evalJSON=function(json){try{if(this.isJSON(json))
return eval('('+json+')');}
catch(e){return null;}}
ajax.prototype.getResponseText=function(){if(this.req.responseText)
return this.req.responseText;return false;}
ajax.prototype.getResponseXML=function(){if(this._responseXML)
return this._responseXML;if(this.req.responseXML){this._responseXML=this.req.responseXML;return this._responseXML;}
return false;}
ajax.prototype.getJSONObject=function(){if(this._jsonObj)
return this._jsonObj;if(this.isResponseJSON()){var json=this.getResponseText();this._jsonObj=this.evalJSON(json);if(this._jsonObj)
return this._jsonObj;}
return null;};ajax.prototype.getXMLObject=function(){if(this.isResponseXML()){var xml=this.getResponseXML();return xml;}
return null;};ajax.prototype.getXMLValue=function(tagName){var res='';var xml=this.getXMLObject();if(xml==null)
return;var els=xml.getElementsByTagName(tagName);if(els.item(0)){var elz=els.item(0).childNodes;for(i=0;i<elz.length;i++){res+=getElemText(elz[i]);}}
return res;}