var ResponseHandler = Class.create();
ResponseHandler.prototype = {

	response: null,
	error: null,
	success: null,
	status: null,

	initialize: function(success, error) {
		this.success = success;
		this.error = error;	
		log(this.error);
	},
	
	handle: function(results) {
		this.status = results[0];
		if (this.status == 'ERROR') {
			this.response = this.error;
			log("error");
			this.displayErrors(results);
		} else if (this.status == 'SUCCESS') {
			Element.hide(this.error);
			this.response = this.success;
			log("success");
			this.displaySuccess(results);
		}
		log(this.response);
	},
	
	
	displayErrors: function(responses) {
		var responseContent = '<ul>';
		for (var i=1;i<responses.length;i++)  {
			responseContent+='<li>' + responses[i].errorMessage + '</li>';
		}
		responseContent+='</ul>';
		$(this.response).innerHTML = responseContent;
		new Effect.BlindDown(this.response);
	},
	
	displaySuccess: function(responses) {
		if (responses.length > 2) {
			displayErrors(responses);
		} else {
			$(this.response).innerHTML = responses[1].errorMessage;
			new Effect.BlindDown(this.response);
		}
	},
	
	isSuccessful: function() {
		return this.status == 'SUCCESS';
	}
}
