/**
 * @author mpoisson
 * @version 1.0
 * 
 * Class used to specify service parameters
 */

function Service(name, url, sid) {
	this.name = name;
	this.url = url;
	this.sid = sid;
	this.cacheable = false;
	this.callBackObject = null;
	this.callBackFunction = null;
	this.result = new ServiceResult();
	this.method = 'POST';
	this.paramCount = 0;
	this.keyArray = [];
	this.valueArray = [];
}

Service.prototype.getName = function() {
	return this.name;
};

Service.prototype.setName = function(name) {
	this.name = name;
};

Service.prototype.isCacheable = function() {
	return this.cacheable;
};

Service.prototype.setCacheable = function(value) {
	this.cacheable = value;
};

Service.prototype.getSID = function() {
	return this.sid;
};

Service.prototype.getURL = function() {
	return this.url;
};

Service.prototype.throwOnServiceComplete = function() {
	if (this.callBackObject == null) {
		eval(this.callBackFunction)(this);
	} else {
		this.callBackObject[this.callBackFunction](this);	
	}
};

Service.prototype.setOnServiceComplete = function(object, method) {
	this.callBackObject = object;
	this.callBackFunction = method;
};

Service.prototype.getMethod = function() {
	return this.method;
};

Service.prototype.setMethod = function(method) {
	this.method = method;
};

Service.prototype.getParamCount= function () {
	return this.paramCount;
};

Service.prototype.getResult = function() {
	return this.result;
};

Service.prototype.setResult = function(result) {
	this.result = result;
};

Service.prototype.addParameter = function(key, value) {
	this.keyArray[this.getParamCount()] = key;
	this.valueArray[this.getParamCount()] = value;
	this.paramCount++;
};

Service.prototype.getKey = function(index) {
	return this.keyArray[index];
};

Service.prototype.getParameterByKey = function(key) {
	var value = "";
	for (i=0; i< this.keyArray.length; i++) {
		if (this.keyArray[i] == key) {
			value = this.valueArray[i];
		}
	}
	return value;
};

Service.prototype.getParameterByIndex = function(index) {
	var value = "";
	value = this.valueArray[index];
	return value;
};


Service.prototype.buildCacheKey = function() {
	var key = this.getName();
	
	for (i=0; i < this.getParamCount(); i++) {
		key += '_' + this.getParameterByIndex(i);
	}
	return key;	
};