var Callbacks = {}
Callbacks['default'] = new Class({
	'link': 'chain',
	'onRequestMessage': gettext('sending'),
	'errorMessage':'<span>'+gettext('Unexpected error has occured')+':</span> ',
	'onRequest': function(){
		if (this.options.data.hasClass('clearOnStart')){
			this.options.data.clear();
		}
		this.options.data.notify(this.options.onRequestMessage);
	},
	'onSuccess': function(text){
		try {
			json = JSON.decode(text);
		}
		catch (error) {
			this.options.data.notify(this.options.errorMessage+error,'error');
			return false;
		}
		if (json.status) {
			if (this.options.data.hasClass('redirectOnJsonSuccess')){
				if (json.next){
					window.location = json.next;
				} else {
					location.reload(true);
				}
			} else {
				if (this.options.data.hasClass('clearOnJsonSuccess')){
					this.options.data.clear();
				}
				this.options.data.notify(json.response);
			}
		} else {
			if (this.options.data.hasClass('clearOnSuccess')){
				this.options.data.clear();
			}
			this.options.data.notify(json.response,'error');
		}
	},
	'onFailure': function(xhr){
		this.options.data.notify(this.options.errorMessage+error,'error');
	}
});
Callbacks['marker'] = new Class({
	Extends: Callbacks['default'],
	'onRequestMessage': gettext('adding new marker'),
	'onSuccess': function(text){
		try{
			json = JSON.decode(text);
		}
		catch (error) {
			this.options.data.notify(this.options.errorMessage+error,'error');
			return false;
		}
		if (json.status) {
			alert(json.response);
			map.getMarkers();
		} else {
			this.options.data.notify(json.response,'error');
		}
	}
});
Callbacks['participate'] = new Class({
	Extends: Callbacks['default'],
	'onRequestMessage': null,
	'onSuccess': function(text){
		try{
			json = JSON.decode(text);
		}
		catch (error) {
			return false;
		}
		if (json.status) {
			var participantsText = 'You and <strong>'+(json.response.toInt()-1)+'</strong> people will participate!';
			this.options.data.getElement('#participants').set('html',participantsText);
		}
	}
});

