cghub.ajaxResponse = function (response, statusText) {
	if (typeof response == 'object') {
		cghub.parseJsonResponse(response);
	} else if (response.isJSON()) {
		cghub.parseJsonResponse(JSON.parse(response));
	} else {
		//pass
	}
};

cghub.parseJsonResponse = function (json) {
	if (typeof json.execute != 'undefined' && cghub.allowedToExecute.in_array(json.execute)) {
		if (typeof json.params != 'undefined') {
			var params = json.params;
		} else {
			var params = [];
		}

		cghub.execute('cghub.executeMethods.'+json.execute, params);
	}
	/*if (typeof json.flash != 'undefined') {
		cghub.flash(json.flash);
	}*/
	if (typeof json.invalidate != 'undefined') {
		cghub.invalidateFields(json.invalidate);
	}
	if (typeof json.redirect != 'undefined') {
		cghub.redirect(json.redirect);
	}
};

cghub.execute = function(methodName, params) {
	if (typeof params[0] == 'undefined') { //not an array
		params = [params];
	}

	method = eval(methodName);
	
//	params.foreach(function(key, value){
//		params[key] = 'JSON.parse(\''+JSON.stringify(value)+'\')';
//	});
//	var evalString = method+'('+params.join(',')+')';

	if ($.browser.msie) {
		setTimeout(function(){
			method.apply(this, params);
		}, 100);
	} else {
		method.apply(this, params);
	}
};

cghub.redirect = function (url) {
	document.location.href = url;
};

cghub.refreshPage = function(noCache) {
	document.location.reload(noCache);
};
