
	var rpcClient = Class.create(rpcBase, {
		initialize:function($super, URI, apiKey){
			$super(URI, apiKey);
			this.instID = 'rpcClient_' + parseInt(Math.random()*1000000);
		},
		
		execute : function(callBack){
			this.responseDOM = '';
			if (!callBack) callback = function(){}; // assign anonymous function if no callback is passed
			this.callBack = callBack;
			var xmlReq = "<requests>" + this.getRequestXML() + "</requests>";
			var qs = 'fromJSONProxy=true&objID='+this.instID+'&APIKEY=' +this.apiKey+'&req=' + encodeURIComponent(xmlReq) + '&rand=' + parseInt(Math.random()*1000000);
			var reqURI = this.URI + "?" + qs
			if (this.debug && window.console){
				console.log(reqURI)
			} 
			
            if (!$(this.instID)){
	            var script = new Element('script', {
	                src: reqURI,
	                type: 'text/javascript',
	                id :"script_" + this.instID
	            });
	            $$('head')[0].appendChild(script);
            }else{
            	$(this.instID).src = reqURI; 
            }
            // start monitoring
            this.monitorOutput();			
		},

		
		monitorOutput : function(){
//			console.log(this.instID);
			try{
				this.req = eval(this.instID);
				if (!(this.req instanceof Object)) {
					this.timeout = setTimeout(this.monitorOutput.bind(this), 50);
					return;
				}
				this.handleResults(this.req);
				if (this.debug) console.log(this.req);
				setTimeout(this.close.bind(this), 750);
				return;
			}catch(e){
				if (e.message.indexOf('undefined')  == -1 && e.message.indexOf(this.instID) == -1){
					if (this.debug) {
						console.log(e);
					}
					return;		
				}
				this.timeout = setTimeout(this.monitorOutput.bind(this), 50);			
			}
		},
		
		close: function(){
			if (!this.debug) $E("script_" + this.instID).remove();
		},
		
		handleResults : function(req){
			var xmlStr = req.output;
			try {
				//Internet Explorer
				xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async="false";
				xmlDoc.loadXML(xmlStr);
			}catch(e){
				parser=new DOMParser();
				xmlDoc=parser.parseFromString(xmlStr,"text/xml");
			}			
			this.responseDOM = xmlDoc
			this.callBack(this.responseDOM, this);
		}
		
	})
