AjaxUtils = {
	dataType: "json",
	jsonpCallbackKey: "jsonpCallback",
	requestMethod: "POST",
		
	/**
	 * @param source url
	 * @param parameters 
	 * @param handler complete event handler, gets revieved data passed as the only parameter
	 * @param handlerContext
	 * @param queue if supplied, uses this queue object instead of directly dispatching the XHR call
	 */
	loadJSON: function (source, parameters, handler, handlerContext, queue) {
		var params = {
			cache: false,
			context: handlerContext ? handlerContext : window,
			data: parameters,
			dataType: AjaxUtils.dataType,
			jsonp: AjaxUtils.jsonpCallbackKey,
			error: AjaxUtils.handleError,
			success: function (data, textStatus, xhr) {
				if (!data || !data.type) {
					AjaxUtils.handleError(xhr, textStatus, null);
					return;
				}
				
				if (data.type == "Exception") {
					AjaxUtils.handleError(xhr, data.message, data);
					return;
				}
				
				handler.call(handlerContext, data);
			},
			type: AjaxUtils.requestMethod,
			url: source	
		};
	
		if (queue) {
			queue.add(params);
		} else {
			jQuery.ajax(params);
		}
	},
	
	/**
	 * default error handler for XHR calls
	 */
	handleError: function (xhr, errorMessage, errorThrown) {
		if (errorMessage == "success") {
			return;
		}
		alert("ajax request failed: " + errorMessage + (errorThrown ? ("\n\n" + errorThrown) : ""));
	}
};
