
function AjaxReq()
{
	var XMLHttpRequestObject = 0;
	var Method = "POST";
	var Url    = "";
	var Param  = "";
    var lol = "11";
    var error= 0;
    var ParamArr = new Array();
    var CallBackFunct;
    this.GerResponseText = function ()
    {
    	return XMLHttpRequestObject.responseText;
    }
    this.GerResponseXML = function ()
    {
    	return XMLHttpRequestObject.responseXML;
    }
	this.CreateReqObj = function()
	{


 				 if(window.XMLHttpRequest)
                {
                		XMLHttpRequestObject = new XMLHttpRequest();
                		XMLHttpRequestObject.overrideMimeType('text/xml');

                }
                else
                {
				    try
				    {
				    	 XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP.6.0");

				    	 return;
				    }
				    catch(e)
				    {
					    try
					    {
					    	 XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP.3.0");

					    	 return;
					    }
				    	catch(e)
				    	{

					   	 	try
					    	{
					    	 	XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP");

					    	 	return;
					    	}
					    	catch(e)
					    	{


							    try
							    {
							    	XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");

							    	return;
							    }
							    catch(e) {
							    	XMLHttpRequestObject = 0;
							    }
							    throw new Error("This111 browser does not support XMLHttpRequest.");
							}
						}
					}
				}


	}

	this.CreateReqObj();
	///////////////////////////////////////////
	/////////////

	this.processReqChange = function()
	{

		  try
		  {

		    if (XMLHttpRequestObject.readyState == 4)
		    {

		        if (XMLHttpRequestObject.status == 200)
		        {


		            CallBackFunct( );
		        }
		        else
		        {
		            error =1;
		            CallBackFunct();
		        }
		    }
		    else
		    {

		    }

		  }
		  catch( e )
		  {

               error =1
		      // alert('Caught Exception: ' + e.description);
		      // В связи с багом XMLHttpRequest в Firefox приходится отлавливать ошибку
		      // Bugzilla Bug 238559 XMLHttpRequest needs a way to report networking errors
		      // https://bugzilla.mozilla.org/show_bug.cgi?id=238559
		  }
	}

	/////////////////////////////
	/////////////////////////////
	this.SetMethod = function(m)
	{
		this. Method = m;
	}
    ///////////////////////////////
	this.SetUrl = function(u)
	{
		this. Url = u;
	}
   ///////////////////////////////////
	this.Request = function()
	{
			XMLHttpRequestObject.open( Method  , this. Url, 1 );

			XMLHttpRequestObject.onreadystatechange = this.processReqChange;

            Param = "";
            for(var key in ParamArr)
            {
            	Param    = Param + encodeURI( key ) + "=" + encodeURI( ParamArr[ key ] ) + "&";
            }
            //alert(Param);


			if(this. Method == "GET")
			{
				 XMLHttpRequestObject.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
				 http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				 XMLHttpRequestObject.send(null);
			}
			if(this. Method == "POST")
			{
				 XMLHttpRequestObject.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
				 XMLHttpRequestObject.send(Param);
			}

	}
     ////////////////////////////////
	this. ClearParam = function()
	{
		Param    = "";
		ParamArr = [];
	}
	//////////////////////////////////
	this. SetParam = function ( name, value)
	{
		ParamArr[name] = value;
	}
	////////////////////////////////
	this.SetCallBackFunction = function(nf)
	{

	    CallBackFunct = nf;
	}

}



//var MainAjax = new AjaxReq();

function addEvent(elm, evType, fn, useCapture) {
        if (elm.addEventListener) {
                elm.addEventListener(evType, fn, useCapture);
        return true;
        }
        else if (elm.attachEvent) {
                var r = elm.attachEvent('on' + evType, fn);
                return r;
        }
        else {
                elm['on' + evType] = fn;
        }
}

function elem(name, attrs, style, text) {
    var e = document.createElement(name);
    if (attrs) {
        for (key in attrs) {
            if (key == 'class') {
                e.className = attrs[key];
            } else if (key == 'id') {
                e.id = attrs[key];
            } else {
                e.setAttribute(key, attrs[key]);
            }
        }
    }
    if (style) {
        for (key in style) {
            e.style[key] = style[key];
        }
    }
    if (text) {
        e.appendChild(document.createTextNode(text));
    }
    return e;
}


function XML_listNodes(startNode)
{
    var list = new Array();
    var node = startNode;
    while(node)
    {
        list.push(node);
        node = nextNode(node);
    }
    return list;
}
function getAttributes(node)
{
  var ret = new Object();
  if(node.attributes)
  for(var i=0; i<node.attributes.length; i++)
  {
    var attr = node.attributes[i];
    ret[attr.name] = attr.value;
  }
  return ret;
}




