
Ajax = function()
{
	/**
	 * Send request to server
	 *
	 * @param JSON A JSON string with post parameters
	 * @return void
	 */
	function sendPost(post, cbComplete, cbError)
	{
		var request = {
						type : 'POST',
						url : 'Backend.ashx',
						contentType : 'application/x-www-form-urlencoded; charset=UTF-8',
						cache : false,
						dataType : 'text',
						error : cbError,
						complete : cbComplete,
						data : post
					}
					
		$.ajax(request)
	}
	
	/**
	 * Extract custom status data from http headers
	 *
	 * @param XmlHttpRequest The response object
	 * @param string The prefix of the header (prefix-status-code, prefix-status-message)
	 * @returns A Status with data taken from the http headers
	 */
	function getStatus(http, prefix)
	{
		var s = new Ajax.Status(0, '')
		
		if (prefix == null || prefix == undefined)
			prefix = 'gko'
		
		s.code = http.getResponseHeader(prefix+'-status-code')
		s.message = decodeURI(http.getResponseHeader(prefix+'-status-message'))
		s.body = http.responseText
		
		return s
	}
	
	return {
		"sendPost" : sendPost,
		"getStatus" : getStatus
	}
}();


/**
 * Holds simple http header status data
 */
Ajax.Status = function(inCode, inMsg)
{
	this.code = inCode
	this.message = inMsg
	this.body = ''
}

