function JSQueryRequest(queryName, params){
	this.queryName = queryName;
	this.params = params;
	this.req = null;
}

JSQueryRequest.prototype.execute = function(){
	var paramObject = {
		queryname: this.queryName,
		'params[]': this.params
	};

	var options = {
		method: 'get',
		parameters: paramObject,
		onComplete: this.processResults.bind(this)
	};

	this.req = new Ajax.Request('/jsquery.php', options);
};

JSQueryRequest.prototype.processResults = function(){
	var xmldoc = this.req.transport.responseXML;
	var text = this.req.transport.responseText;
	if (!xmldoc){
		this.onError('Invalid response returned for query: '+this.queryName, xmldoc, text);
	}
	else {
		if (xmldoc.documentElement.getAttribute('code') == 'error'){
			var errorMessage = xmldoc.documentElement.getElementsByTagName('error')[0].firstChild.nodeValue;
			this.onError(errorMessage, xmldoc, text);
		}
		else {
			this.onSuccess(xmldoc, text);
		}
	}
};

JSQueryRequest.prototype.onError = function(errorMessage, xmldoc, responseText){
	if (!confirm('Error:\n'+errorMessage+'\n\nPress Cancel to see debug info')){
		alert('XML Document object: \n'+xmldoc);
		alert('Response Text: \n'+responseText);
	}
};

JSQueryRequest.prototype.onSuccess = function(xmldoc, text){
	//alert(xmldoc);
};

