Ext.ns('core');

core.ajax = new function() {
	this.request = function(successFunction, params) {
		var url = null;
		
		if(params.get == null) params.get = ''; 
		
		if(params.url == null) {
			url = 'ajax.php' + params.get;
		} else {
			url = params.url + params.get;
		}
		
		Ext.Ajax.request({
				url: url,
  				success: function(response) {
  					response = Ext.util.JSON.decode(response.responseText);
					
					if(response != null) {
  						eval(successFunction)(response);
  					} else {
  						core.ajax.responseInvalid();
  					}
  				},
  				failure: core.ajax.failure,
  				headers: {
  					'content-type': 'text/html;'
  				},
  				params: params,
  				form: params.form
		});
	};
	
	this.responseInvalid = function(response) {
		alert("Die Anfrage konnte nicht ordnungsgemäß verarbeitet werden");
	};
	
	this.requestException = function() {
		alert("Die Anfrage konnte nicht gesendet werden");
	};
	
	this.requestInvalid = function() {
		alert("Die Anfrage konnte nicht gesendet werden");
	};
	
	this.failure = function() {
		alert("Die Anfrage ist fehlgeschlagen");
	};
	
	this.beforeRequest = function() {
//		admin.showLoading();
	};
	
	this.requestComplete = function() {
//		admin.hideLoading();
	};
};