
     var Requests = new Array();

     function Request(req, ans) {
          this.req = req;
          this.answer = ans,
          this.state = 0;
     }

     function createXHR() {
          var req;
          try {
               req = new (window.XMLHttpRequest || ActiveXObject)('Msxml2.XMLHTTP');
          } catch (e) {
               throw 'Не могу создать AJAX';
               req = false;
          }
          return req;
     }


	function callserver(command, value, answer, way0)
	{
		$.post("/modules/ajaxagent.php", { command: command, value: value },
			function(data)
			{	ss = way0.split(".");
				way1 = ss[0];
				if (!ss[1]) { way2 = "null"; } else { way2 = ss[1]; }
				if (!ss[2]) { way3 = "null"; } else { way3 = ss[2]; }

				if (way3=="null")
				{	if (way2=="null") { document.getElementById(answer)[way1] = data; }
					else { document.getElementById(answer)[way1][way2] = data; }
				} else { document.getElementById(answer)[way1][way2][way3] = data; }

			}
		);
	}

     function ansRequest() {
          var count = Requests.length;
          for (var i = 0; i < count; i++) {
               if(Requests[i].state == 0) continue;
               req = Requests[i].req;

               answer = Requests[i].answer;
               if (req.readyState == 4) {
                    if (req.status == 200) {
						ans = req.responseText;
						req.abort();
						Requests[i].state = 0;
						Requests[i].req = undefined;

						ss = way.split(".");
						way1 = ss[0];
						if (!ss[1]) { way2 = "null"; } else { way2 = ss[1]; }
						if (!ss[2]) { way3 = "null"; } else { way3 = ss[2]; }

						if (way3=="null")
						{ if (way2=="null") { document.getElementById(answer)[way1] = ans; }
						else { document.getElementById(answer)[way1][way2] = ans; } }
						else { document.getElementById(answer)[way1][way2][way3] = ans; }

                    }
               }
          }
     }

