// remote scripting library // (c) copyright 2005 modernmethod, inc var sajax_debug_mode=false; var sajax_request_type="POST"; var sajax_target_id=""; var sajax_failure_redirect=""; function sajax_debug(text){ if (sajax_debug_mode) alert(text); } function sajax_init_object(){ sajax_debug("sajax_init_object() called..") var A; var msxmlhttp=new Array( 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'); for (var i=0; i < msxmlhttp.length;="" i++){="" try="" {="" a="new" activexobject(msxmlhttp[i]);="" }="" catch="" (e){="" a="null;" }="" }="" if(!a="" &&="" typeof="" xmlhttprequest="" !="undefined" )="" a="new" xmlhttprequest();="" if="" (!a)="" sajax_debug("could="" not="" create="" connection="" object.");="" return="" a;="" }="" var="" sajax_requests="new" array();="" function="" sajax_cancel(){="" for="" (var="" i="0;" i="">< sajax_requests.length;="" i++)="" sajax_requests[i].abort();="" }="" function="" sajax_do_call(func_name,="" args){="" var="" i,="" x,="" n;="" var="" uri;="" var="" post_data;="" var="" target_id;="" sajax_debug("in="" sajax_do_call().."="" +="" sajax_request_type="" +="" "/"="" +="" sajax_target_id);="" target_id="sajax_target_id;" if="" (typeof(sajax_request_type)="="undefined"" ||="" sajax_request_type="="")" sajax_request_type="GET" ;="" uri="ajaxinit.php" ;="" if="" (sajax_request_type="="GET"){" if="" (uri.indexof("?")="=-1)" uri="" +="?rs=" +="" escape(func_name);="" else="" uri="" +="&rs=" +="" escape(func_name);="" uri="" +="&rst=" +="" escape(sajax_target_id);="" uri="" +="&rsrnd=" +="" new="" date().gettime();="" for="" (i="0;" i="">< args.length-1;="" i++)="" uri="" +="&rsargs[]=" +="" escape(args[i]);="" post_data="null;" }="" else="" if="" (sajax_request_type="="POST"){" post_data="rs=" +="" escape(func_name);="" post_data="" +="&rst=" +="" escape(sajax_target_id);="" post_data="" +="&rsrnd=" +="" new="" date().gettime();="" for="" (i="0;" i="">< args.length-1; i++) post_data=post_data + "&rsargs[]=" + escape(args[i]); } else { alert("illegal request type: " + sajax_request_type); } x=sajax_init_object(); if (x==null){ if (sajax_failure_redirect != ""){ location.href=sajax_failure_redirect; return false; } else { sajax_debug("null sajax object for user agent:\n" + navigator.useragent); return false; } } else { x.open(sajax_request_type, unescape(uri), true); //x.open(sajax_request_type, uri, true); // window.open(uri); sajax_requests[sajax_requests.length]=x; if (sajax_request_type=="post"){ x.setrequestheader("method", "post " + uri + " http/1.1"); x.setrequestheader("content-type", "application/x-www-form-urlencoded"); } x.onreadystatechange=function(){ if (x.readystate != 4) return; sajax_debug("received " + x.responsetext); var status; var data; var txt=x.responsetext.replace(/^\s*|\s*$/g,""); status=txt.charat(0); data=http://www.aromahadek.ru/js/txt.substring(2); if (status==""){ // let's just assume this is a pre-response bailout and let it slide for now } else if (status=="-") alert("error: " + data); else { if (target_id != "") document.getelementbyid(target_id).innerhtml=eval(data); else { try { var callback; var extra_data=false; if (typeof args[args.length-1]=="object"){ callback=args[args.length-1].callback; extra_data=args[args.length-1].extra_data; } else { callback=args[args.length-1]; } callback(eval(data), extra_data); } catch (e){ sajax_debug("caught error " + e + ": could not eval " + data ); } } } } } sajax_debug(func_name + " uri=" + uri + "/post=" + post_data); x.send(post_data); sajax_debug(func_name + " waiting.."); delete x; return true; } // wrapper for addtobasket function x_addtobasket(){ sajax_do_call("addtobasket", x_addtobasket.arguments); } // wrapper for addtobasket2 function x_addtobasket2(){ sajax_do_call("addtobasket2", x_addtobasket2.arguments); } // wrapper for delfrombasket2 function x_delfrombasket2(){ sajax_do_call("delfrombasket2", x_delfrombasket2.arguments); } // wrapper for ajaxtestphp function x_ajaxtestphp(){ sajax_do_call("ajaxtestphp", x_ajaxtestphp.arguments); } args.length-1;="" i++)="" post_data="post_data" +="" "&rsargs[]=" + escape(args[i]); } else { alert(" illegal="" request="" type:="" "="" +="" sajax_request_type);="" }="" x="sajax_init_object();" if="" (x="=null){" if="" (sajax_failure_redirect="" !="" ){="" location.href="sajax_failure_redirect;" return="" false;="" }="" else="" {="" sajax_debug("null="" sajax="" object="" for="" user="" agent:\n"="" +="" navigator.useragent);="" return="" false;="" }="" }="" else="" {="" x.open(sajax_request_type,="" unescape(uri),="" true);="" x.open(sajax_request_type,="" uri,="" true);="" window.open(uri);="" sajax_requests[sajax_requests.length]="x;" if="" (sajax_request_type="="POST"){" x.setrequestheader("method",="" "post="" "="" +="" uri="" +="" "="" http/1.1");="" x.setrequestheader("content-type",="" "application/x-www-form-urlencoded");="" }="" x.onreadystatechange="function(){" if="" (x.readystate="" !="4)" return;="" sajax_debug("received="" "="" +="" x.responsetext);="" var="" status;="" var="" data;="" var="" txt="x.responseText.replace(/^\s*|\s*$/g,"");" status="txt.charAt(0);" data="http://www.aromahadek.ru/js/txt.substring(2);" if="" (status="=""){" let's="" just="" assume="" this="" is="" a="" pre-response="" bailout="" and="" let="" it="" slide="" for="" now="" }="" else="" if="" (status="="-")" alert("error:="" "="" +="" data);="" else="" {="" if="" (target_id="" !="" )="" document.getelementbyid(target_id).innerhtml="eval(data);" else="" {="" try="" {="" var="" callback;="" var="" extra_data="false;" if="" (typeof="" args[args.length-1]="="object"){" callback="args[args.length-1].callback;" extra_data="args[args.length-1].extra_data;" }="" else="" {="" callback="args[args.length-1];" }="" callback(eval(data),="" extra_data);="" }="" catch="" (e){="" sajax_debug("caught="" error="" "="" +="" e="" +="" ":="" could="" not="" eval="" "="" +="" data="" );="" }="" }="" }="" }="" }="" sajax_debug(func_name="" +="" "="" uri=" + uri + " ost=" + post_data); x.send(post_data); sajax_debug(func_name + " waiting..");="" delete="" x;="" return="" true;="" }="" wrapper="" for="" addtobasket="" function="" x_addtobasket(){="" sajax_do_call("addtobasket",="" x_addtobasket.arguments);="" }="" wrapper="" for="" addtobasket2="" function="" x_addtobasket2(){="" sajax_do_call("addtobasket2",="" x_addtobasket2.arguments);="" }="" wrapper="" for="" delfrombasket2="" function="" x_delfrombasket2(){="" sajax_do_call("delfrombasket2",="" x_delfrombasket2.arguments);="" }="" wrapper="" for="" ajaxtestphp="" function="" x_ajaxtestphp(){="" sajax_do_call("ajaxtestphp",="" x_ajaxtestphp.arguments);="" }="">