
var oAjax=new ajax_sender();var xmlHttp=oAjax.createXmlHttpRequestObject();var pcResponseVarname='ajax_response_object';var ajax_response_object=null;var plDebugRun=true;function xmlHttp_handle_ServerResponse()
{if(xmlHttp.readyState==4)
{if(xmlHttp.status==200)
{oAjax.responseText=xmlHttp.responseText;oAjax.responseXML=xmlHttp.responseXML;xmlHttp_Make_ResponseObj();oAjax.anim_hide();if(plDebugRun)oAjax.responser();else
{try{oAjax.responser();}
catch(e){alert(oAjax.msg_ResponseProcessError);return false;}}}
else
{oAjax.anim_hide();alert(oAjax.msg_GrantError+xmlHttp.status+"\n"+xmlHttp.statusText);return false;}}
return true;}
function ajax_sender()
{this.xmlHTTP=null;this.method='POST';this.responser=null;this.responseText='';this.responseXML='';this.responseObj={};this.XmlHttpVersions=new Array("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");this.msg_CantMakeXmlHTTP='Ошибка создания объекта XMLHttpRequest!\nЗапросы к серверу невозможны.';this.msg_UseOpera='\nПопробуйте включить в своем браузере JavaScript или смените свой браузер на более новый (например Opera 9 - www.opera.com)';this.msg_CantConnect='Загрузить данные невозможно, т.к. отсутствует возможность связаться с сервером\n';this.msg_GrantError="Ошибка при доступе к серверу:\n";this.msg_ResponseProcessError='Ошибка при обработке ответа сервера';this.anim_shell='upmeter_shell';this.anim_text='Идет загрузка. Подождите...';this.anim_w=240;this.anim_h=120;var oTarget=null;this.start=function(tcUrl,tfFunction,taFields,tlAnim)
{if(xmlHttp.readyState==4||xmlHttp.readyState==0)
{var lcPOSTFields='';if((taFields.constructor==String)&&(!document.getElementById(taFields)))lcPOSTFields=taFields;else lcPOSTFields=this.makePost(taFields);try
{this.responser=tfFunction;xmlHttp.open(this.method,tcUrl,true);xmlHttp.onreadystatechange=xmlHttp_handle_ServerResponse;xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xmlHttp.send(lcPOSTFields);if(tlAnim)this.anim_show();}
catch(e){alert(this.msg_CantConnect+'\n'+e.toString());}}}
this.update=function(tcUrl,toTarget,taFields,tlAnim)
{if(xmlHttp.readyState==4||xmlHttp.readyState==0)
{var lcPOSTFields='';if((taFields.constructor==String)&&(!id(taFields)))lcPOSTFields=taFields;else lcPOSTFields=this.makePost(taFields);try
{oTarget=(toTarget.constructor==String)?id(toTarget):toTarget;this.responser=_ajaqsUpdate;xmlHttp.open(this.method,tcUrl,true);xmlHttp.onreadystatechange=xmlHttp_handle_ServerResponse;xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xmlHttp.send(lcPOSTFields);if(tlAnim)this.anim_show();}
catch(e){alert(this.msg_CantConnect+'\n'+e.toString());}}}
function _ajaqsUpdate()
{if(this.responseObj&&this.responseObj.result!='Ok')
{alert(this.responseObj.error);return true;}
if(this.responseText!='')oTarget.innerHTML=this.responseText;return true;}
this.formComplete=function(toIFrame)
{this.anim_hide();var loDoc=toIFrame.contentDocument;if(!loDoc&&toIFrame.contentWindow)loDoc=toIFrame.contentWindow.document;if(!loDoc)loDoc=window.frames[toIFrame.id].document;if(!loDoc)return null;if(loDoc.location=="about:blank")return null;if(loDoc.XMLDocument)loDoc=loDoc.XMLDocument;this.responseText=loDoc.body.innerHTML;try{eval(this.responseText);}
catch(e)
{ajax_response_object=null;try{console.log(this.responseText);}catch(e){}}
this.responseObj=ajax_response_object;if(this.responseObj)
{for(var i in this.responseObj)this.responseObj[i]=win2unicode(unescape(this.responseObj[i]));}
return true;}
this.createXmlHttpRequestObject=function()
{var xmlHttp=null;try{xmlHttp=new XMLHttpRequest();}
catch(e)
{for(var i=0;i<this.XmlHttpVersions.length&&!xmlHttp;i++)
{try{xmlHttp=new ActiveXObject(this.XmlHttpVersions[i]);}
catch(e){};}}
if(!xmlHttp)
{alert(this.msg_CantMakeXmlHTTP+this.msg_UseOpera);this.xmlHTTP=false;}
else this.xmlHTTP=xmlHttp;return this.xmlHTTP;}
this.makePost=function(taFields)
{var laFields=null;var laSend=new Array();var lcType=typeof(taFields);var lcVal='';if(taFields.constructor==Array)
{for(var i=0;i<taFields.length;i++)
{var lcName=taFields[i];var loObj=id(lcName);if(!loObj)
{alert('Элемент с ID '+lcName+' не существует');laSend[i]=lcName+'=';}
else laSend[i]=_get_element(loObj);}}
if(taFields.constructor==String)
{var loObj=id(taFields);if(loObj.tagName=='FORM')
{var loElements=loObj.elements;for(var i=0;i<loElements.length;i++)
{laSend[i]=_get_element(loElements[i]);}}
else
{var loObj=id(taFields);laSend[0]=_get_element(loObj);}}
return laSend.join('&');}
function _get_element(toObj)
{var lcRet='';var lcName=toObj.id||toObj.name;if(toObj.tagName=='INPUT'&&toObj.type=='checkbox')var lcVal=((toObj.checked)?"1":"0");else var lcVal=_escape1251(toObj.value);return lcName+'='+lcVal;}
function _escape1251(str)
{if(!str||str=='')return'';var trans=new Array();for(var i=0x410;i<=0x44F;i++)trans[i]=i-0x350;trans[0x401]=0xA8;trans[0x451]=0xB8;trans[0x490]=0xA5;trans[0x491]=0xB4;trans[0x404]=0xAA;trans[0x454]=0xBA;trans[0x406]=0xB2;trans[0x456]=0xB3;trans[0x407]=0xAF;trans[0x457]=0xBF;var ret=[];for(var i=0;i<str.length;i++)
{var n=str.charCodeAt(i);if(typeof trans[n]!='undefined')n=trans[n];if(n<=0xFF)ret.push(n);}
return escape(String.fromCharCode.apply(null,ret));}
this.anim_show=function()
{var loUpmeter=id(this.anim_shell);if(!loUpmeter)
{loUpmeter=dce('div');loUpmeter.id=this.anim_shell;var loUpText=dce('p');loUpText.innerHTML=this.anim_text;loUpmeter.appendChild(loUpText);dbac(loUpmeter);var loUpmeter=id(this.anim_shell);}
try{var lnTop=calcPWindowY(this.anim_h);}
catch(e){var lnTop=200;}
try{var lnLeft=calcPWindowX(this.anim_w);}
catch(e){var lnLeft=200;}
loUpmeter.style.left=lnLeft+'px';loUpmeter.style.top=lnTop+'px';loUpmeter.style.width=this.anim_w+'px';loUpmeter.style.height=this.anim_h+'px';loUpmeter.style.display='block';loUpmeter.style.zIndex=300;loUpmeter.onclick=function(){hide(loUpmeter);};}
this.anim_hide=function()
{hide(this.anim_shell);}
this.alert=function()
{if(this.responseObj)alert('responseObj \n'+getProps(this.responseObj));else alert(this.responseText);}}
function xmlHttp_Make_ResponseObj()
{if(oAjax.responseText.search(pcResponseVarname)>0)
{if(plDebugRun)
{eval(oAjax.responseText);oAjax.responseObj=(ajax_response_object)?ajax_response_object:null;}
else
{try
{eval(oAjax.responseText);oAjax.responseObj=ajax_response_object;}
catch(e){ajax_response_object=null;}}
if(oAjax.responseObj)
{for(var i in oAjax.responseObj)oAjax.responseObj[i]=win2unicode(unescape(oAjax.responseObj[i]));}}
else oAjax.responseObj=ajax_response_object=null;return oAjax.responseObj;}
function handle_FormResponse(toIFrame)
{oAjax.anim_hide();var loDoc=toIFrame.contentDocument;if(!loDoc&&toIFrame.contentWindow)loDoc=toIFrame.contentWindow.document;if(!loDoc)loDoc=window.frames[toIFrame.id].document;if(!loDoc)return null;if(loDoc.location=="about:blank")return null;if(loDoc.XMLDocument)loDoc=loDoc.XMLDocument;oAjax.responseText=loDoc.body.innerHTML;xmlHttp_Make_ResponseObj();return true;}
