  function XML_RPC_Client(url)
  {
  	this.url=url;
  	this.http_request=false;
  	
  	this.request="";
  	this.value=null;
  	this.failedCode=null;
  	
  	this.failed=false;

    this.data=null;
    this.callbackFunction;
    
   
    
    this.httpRequests=[];
    
  	
		this.createXmlHttpRequestObject=function()
		{
  		var xmlHttp=null;
  		try
  		{
    		xmlHttp = new XMLHttpRequest();
  		}
  		catch(e)
  		{
    		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    		"MSXML2.XMLHTTP.5.0",
                                    		"MSXML2.XMLHTTP.4.0",
                                    		"MSXML2.XMLHTTP.3.0",
                                    		"MSXML2.XMLHTTP",
                                    		"Microsoft.XMLHTTP");
    		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    		{
      		try 
      		{ 
        		xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      		} 
      		catch (e) {}
    		}
  		}
    	return xmlHttp;
		}		
    
    this.setData=function(data,callback)
    {
      this.data=data;
      this.callbackFunction=callback;
    }

  	this.call=function(method,id)
  	{
  		this.failedCode = null;
  		this.failed    = false;
  	
			this.httpRequests[id] = this.createXmlHttpRequestObject();
		
			if (!this.httpRequests[id])
			{
				throw "XMLHttpRequest not supported.";
				return false;
			}
			var JSON_call_object={"method":method,"querySearch":this.data,"id":id};


      var callbackFunction=this.callbackFunction;
      
      var httpRequestLocal=this.httpRequests[id];
      this.httpRequests[id].onreadystatechange=function()
      {
       
 switch (httpRequestLocal.readyState)
        {
          case 1: 
		  	try
			{
	                     httpRequestLocal.setRequestHeader("Content-Type", "text/xml");
                              httpRequestLocal.setRequestHeader("Accept-Charset","UTF-8")


                              httpRequestLocal.send(JSON_call_object.toJSONString());	
			}
			catch(e)
			{
				break;
			}


            //document.getElementById("log_test").value+="Request: /n"+JSON_call_object.toJSONString()+"/n/n";

          break;
          case 4:

        	  if ( httpRequestLocal.status == 200 ) {
		           try {

	                 
//document.getElementById("log_test").value+="Response: /n"+httpRequestLocal.responseText+"/n/n";

		             var serverResponse = httpRequestLocal.responseText.parseJSON();
		           }catch (e){
		             serverResponse = {'response':null,'error':e,'id':id};
		           }
		           callbackFunction(serverResponse);
            }
          break;
        }
      };
      
			this.httpRequests[id].open('POST',url,true);

    }  
    
    this.killRequest=function(id)
    {
      this.httpRequests[id].onreadystatechange=function(){};
    }
  }


