//******************************* XML request **********************************


   function XML_Load(url, method, req_params, ret_method, uparams) {
	this.XMLo=null;
    this.url = url;
    this.method = method;
    this.ret_method=ret_method; //XML or TEXT
    this.uparams = uparams;
    this.req_params=req_params;

     if (window.XMLHttpRequest) {  
         try { this.XMLo = new XMLHttpRequest(); }
         catch (e) { this.XMLo=null; }
     } else if (window.ActiveXObject) {    
                try { this.XMLo = new ActiveXObject("Microsoft.XMLHTTP"); }
                catch (e) { this.XMLo=null; }
            } else this.XMLo=null;

    if (this.XMLo!=null) { 
       //Wait while XML object initialized
       while (this.XMLo.readyState != 4 && this.XMLo.readyState != 0) {}
    }
   }

   XML_Load.prototype.IsReady=function() {   
    if (this.XMLo==null) return false;
    return true;
   }

   XML_Load.prototype.Load=function() {   
    if (this.method == "POST") {
        this.XMLo.open("POST", this.url, true);
        this.XMLo.setRequestHeader("Content-Type",
        "application/x-www-form-urlencoded; charset=UTF-8");
    } else if (this.method == "GET") {
               this.XMLo.open("GET", this.url+'?'+this.req_params, true);
           }

    var eobj=this;

    this.XMLo.onreadystatechange = function () {
     var eclass=eobj;
     var eXMLo=eclass.XMLo;

     if (eXMLo.readyState == 4) {
         if (eXMLo.status == 200) {
//     alert(eXMLo.responseText); //For Debugging only
             eclass.OnReady("",eclass.uparams,((eclass.ret_method=="XML") ? eXMLo.responseXML.documentElement : eXMLo.responseText));
			 delete eXMLo;
             delete eclass;
         } else {
//                 alert(eXMLo.responseText); //For Debugging only
                 eclass.OnReady("There was a problem retrieving the XML data:\n" + eXMLo.statusText,eclass.uparams,((eclass.ret_method=="XML") ? eXMLo.responseXML.documentElement : eXMLo.responseText));
                 delete eXMLo;
                 delete eclass;
         }
     }
    }

    if (this.method == 'POST') this.XMLo.send(this.req_params);
        else if (this.method == 'GET') this.XMLo.send(null);

   }


  // Когда нужно задержать выполнение скрипта до получения ответа от сервера
   XML_Load.prototype.Load_=function() {   
    if (this.method == "POST") {
        this.XMLo.open("POST", this.url, false);
        this.XMLo.setRequestHeader("Content-Type",
        "application/x-www-form-urlencoded; charset=UTF-8");
    } else if (this.method == "GET") {
               this.XMLo.open("GET", this.url+'?'+this.req_params, true);
           }

    var eobj=this;

    this.XMLo.onreadystatechange = function () {
     var eclass=eobj;
     var eXMLo=eclass.XMLo;

     if (eXMLo.readyState == 4) {
         if (eXMLo.status == 200) {
 //         alert(eXMLo.responseText); //For Debugging only
             eclass.OnReady("",eclass.uparams,((eclass.ret_method=="XML") ? eXMLo.responseXML.documentElement : eXMLo.responseText));
			 delete eXMLo;
             delete eclass;
         } else {
//                 alert(eXMLo.responseText); //For Debugging only
                 eclass.OnReady("There was a problem retrieving the XML data:\n" + eXMLo.statusText,eclass.uparams,((eclass.ret_method=="XML") ? eXMLo.responseXML.documentElement : eXMLo.responseText));
                 delete eXMLo;
                 delete eclass;
         }
     }
    }

    if (this.method == 'POST') this.XMLo.send(this.req_params);
        else if (this.method == 'GET') this.XMLo.send(null);

   }















   //User defined function
   XML_Load.prototype.OnReady=function(uparams,ldata) {   
 
   }

// Example of call:
// var xl=new XML_Load("http://somthing.com","GET",null,"someparameters");
// if (xl.IsReady()) {
//     xl.OnReady=function(uparams,ldata) {
//      alert(uparams); //display "someparameters"
//      alert(ladata);  //display page from somthing.com
//     }
//     xl.Load();
// }

