(function ($) {
$.askService = function(options) {
	var self = this;
	this.options = $.extend({
		url: service_url,
		type: '',
		method: '',
		async: false,
		onComplete: false
	}, options);
	if (this.options.authcode == undefined) {
		this.options.authcode = function () {
			return SR_Authcode[self.options.type][self.options.method];
		}
	}
	this.error = false;
	if (this.options.onComplete == false) {
		this.onComplete = function(inp) {
			self.reply = inp;
		};
	} else {
		this.onComplete = this.options.onComplete;
	}
	this.reply = '';
	jQuery.ajax({
		async: self.options.async,
		contentType: 'application/json',
		type: 'POST',
		processData: false,
		dataType: 'json',
		url: self.options.url,
		cache: false,
		data: JSON.stringify({
			type: self.options.type,
			method: self.options.method,
			data: self.options.data,
			authcode: self.options.authcode()
		}),
		error: function(req,stat,err){
			self.error = true;
			self.error_message = stat;
			self.error_request = req;
		},
		success: self.onComplete
	});
	if (this.error) {
		this.reply = {
			error: {message: self.error_message}
		}
	}
	return this.reply;
};
})(jQuery);