// Spinner show/hide methods ~ Andrea Mannocci
var spinnerOpts = {
	lines: 15,
	length: 16,
	width: 5,
	radius: 25,
	color: '#eeeeee',
	className: 'spinner',
	top: '40%'
};
			
var spinnerTarget = document.getElementById('spinnerdiv');
			
var spinner;
		
function showSpinner() {
	spinner = new Spinner(spinnerOpts).spin(spinnerTarget);
	spinnerTarget.style.visibility = 'visible';
}
		
function hideSpinner()  {
	spinnerTarget.style.visibility = 'hidden';
	spinner.stop();
}
	
function call_http_get($http, url, onSuccess) {
	showSpinner();
				
	$http.get(url).then(function successCallback(res) {
		hideSpinner();
		onSuccess(res);
	}, function errorCallback(res) {
		hideSpinner();
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
	});
}
			
function call_http_delete($http, url, onSuccess) {
	showSpinner();
		
	$http.delete(url).then(function successCallback(res) {
		hideSpinner();
		onSuccess(res);
	}, function errorCallback(res) {
		hideSpinner();
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
	});
}
			
function json_http_post($http, url, obj, onSuccess) {
	showSpinner();
	$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
	$http.post(url, obj).then(function successCallback(res) {
		hideSpinner();
		onSuccess(res);
	}, function errorCallback(res) {
		hideSpinner();
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
	});
}
			
function params_http_post($http, url, params, onSuccess) {
	showSpinner();
	$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
	$http.post(url, params).then(function successCallback(res) {
		hideSpinner();
		onSuccess(res);
	}, function errorCallback(res) {
		hideSpinner();
		alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
	});
}
