// Creates and returns a request object.
function ajax(type, url, params, success, error, complete) {
	$.ajax({
		type: type,
		url: url,
		cache: false,
		data: params,
		success: success,
		error: error,
		complete: complete
	});
}

// Cleans up the AJAX response text
function cleanUp(response) {
	return unescape(response);
}

function buttonize(elem, icon) {
	$(elem).button({
		icons: {
			primary: "ui-icon-" + icon
		}
	});
	$(elem).click(function() {
		$(elem).removeClass("ui-state-active");
	});
}

function icon_buttonize(elem, icon) {
	$(elem).button({
		text: false,
		icons: {
			primary: "ui-icon-" + icon
		}
	});
	$(elem).click(function() {
		$(elem).removeClass("ui-state-active");
	});
}

function calendarize(elem, close) {
	$(elem).datepicker({
		dateFormat: 'yy-mm-dd',
		showOn: 'button',
		buttonImage: '/jquery_css/images/calendar.gif',
		buttonImageOnly: true,
		autoSize: true,
		showAnim: 'fadeIn',
		changeMonth: true,
		changeYear: true,
		onClose: close
	});

	$(elem).css({marginRight: "3px"});
}

// Override the default alert function with a custom one
// that makes use of the jQuery UI Dialog library.
/*window.alert = function(msg) {

	$("<div id='alertBox'></div>").html("<p>" + msg + "</p>").dialog({
		title: "Alert",
		buttons: {
			"OK": function() {
				$(this).dialog("close");
			}
		},
		close: function() {
			$(this).remove();
		}
	});

}*/

