statusMessageController.Form = new Class({
	Extends: statusMessageController,

	events: {},

	initialize: function(element, form, events){
		this.parent(element);
		this.form = $(form);

		if($type(events) == "object"){
			this.events = events;
			}

		this.registerEvent();
		},

	setEvent: function(){
		this.form.set("send", {
			onComplete: function(response){
				this.response(response);
				}.bind(this)
			});
		},

	registerEvent: function(){
		this.form.addEvent("submit", function(event){
			event.stop();
			
			this.setEvent();
			this.send();
			}.bind(this));
		},

	send: function(){
		this.form.send();
		},

	response: function(response){
		var match = /^<!-- (I|S|W|E)#([0-9]+) -->(.*)$/.exec(response);

		console.log(match);

		if(match){
			switch(match[1]){
				case "I":
					if($type(this.events.onInformation) == "function"){
						this.events.onInformation = this.events.onInformation.bind(this, [match[1], match[2], match[3]]);
						this.events.onInformation();
						}
					else{
						this.information(match[3]);
						}
					break;

				case "S":
					if($type(this.events.onSuccess) == "function"){
						this.events.onSuccess = this.events.onSuccess.bind(this, [match[1], match[2], match[3]]);
						this.events.onSuccess();
						}
					else{
						this.success(match[3]);
						}
					break;

				case "W":
					if($type(this.events.onWarning) == "function"){
						this.events.onWarning = this.events.onWarning.bind(this, [match[1], match[2], match[3]]);
						this.events.onWarning();
						}
					else{
						this.warning(match[3]);
						}
					break;

				case "E":
					if($type(this.events.onError) == "function"){
						this.events.onError = this.events.onError.bind(this, [match[1], match[2], match[3]]);
						this.events.onError();
						}
					else{
						this.error(match[3]);
						}
					break;
				}
			}
		else{
			this.error("Es ist ein Fehler beim Request aufgetreten.");
			}
		}
	});

statusMessageController.Form.JSON = new Class({
	Extends: statusMessageController.Form,

	events: {},

	initialize: function(element, form, events){
		this.parent(element, form, events);
		},

	response: function(response){
		var response = JSON.decode(response);

		if($type(response) == "object"){
			switch(response.type){
				case "I":
					if($type(this.events.onInformation) == "function"){
						this.events.onInformation = this.events.onInformation.bind(this, response);
						this.events.onInformation();
						}
					else{
						if($type(response.message) == "array"){
							this.information(response.message.join("<br/>"));
							}
						else{
							this.information(response.message);
							}
						}
					break;

				case "S":
					if($type(this.events.onSuccess) == "function"){
						this.events.onSuccess = this.events.onSuccess.bind(this, response);
						this.events.onSuccess();
						}
					else{
						if($type(response.message) == "array"){
							this.success(response.message.join("<br/>"));
							}
						else{
							this.success(response.message);
							}
						}
					break;

				case "W":
					if($type(this.events.onWarning) == "function"){
						this.events.onWarning = this.events.onWarning.bind(this, response);
						this.events.onWarning();
						}
					else{
						if($type(response.message) == "array"){
							this.warning(response.message.join("<br/>"));
							}
						else{
							this.warning(response.message);
							}
						}
					break;

				case "E":
					if($type(this.events.onError) == "function"){
						this.events.onError = this.events.onError.bind(this, response);
						this.events.onError();
						}
					else{
						if($type(response.message) == "array"){
							this.error(response.message.join("<br/>"));
							}
						else{
							this.error(response.message);
							}

						this.scrollable.toElement(this.element);
						}
					break;
				}
			}
		}
	});