﻿jQuery.extend({

	authAwareAjax: function(url, data, callback, method, type) {
		if(method == null) method = "GET";
		
		return jQuery.ajax({
			url: url,
			type: method,
			data: data,
			dataType: type,
			success: callback,
			error: function(xhr, status, err) {
				if(xhr.getResponseHeader("X-Authentication-Required") == "true") {
					location.href = "/Users/SignIn?returnUrl=" + escape(location.pathname + location.search);
				}
			}
		});
	},
	
	postJSONX: function(url, data, callback) {
		return jQuery.authAwareAjax(url, data, callback, "POST", "json");
	}
});