var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");
$(document).ajaxSend(function(e, xhr, options) {
	if(token && header){
		xhr.setRequestHeader(header, token);
	}
});

$(document).ajaxError( function(event, xhr, settings, thrownError){
	if(thrownError == 'abort'){  
    }else if(xhr.responseJSON){
		Lobibox.notify("error", {
			msg: xhr.responseJSON.message
		});
	}else{
		if(xhr.status!=0){
			Lobibox.notify("error", {
				msg: thrownError
			});
		}
	}
});

$('.navigation-menu li.has-submenu a[href="#"]').on('click', function (e) {
	e.preventDefault();
});

Lobibox.notify.DEFAULTS = $.extend({}, Lobibox.notify.DEFAULTS, {
	size: 'mini',
	rounded: true,
	position: "center top",
	soundPath: contextPath+'/libs/lobibox/sounds/',
	iconSource: 'fontAwesome',
	icons: {
		fontAwesome: {
	        success: 'far fa-check-circle',
	        error: 'far fa-times-circle',
	        warning: 'far fa-exclamation-circle',
	        info: 'far fa-info-circle'
	    }
	}
});

var Alert = {
	hide : function ($div){
		$div.hide();
		$div.html('');
	},
	danger : function ($div, $message){
		$div.show();
		var html = '<div class="alert alert-danger alert-dismissible fade show" role="alert">'
			  +$message
			  +'<button type="button" class="close" data-dismiss="alert" aria-label="Close">'
			  +'<span aria-hidden="true">&times;</span>'
			  +'</button>'
			  +'</div>';
		$div.html(html);
	},
	success : function ($div, $message){
		$div.show();
		var html = '<div class="alert alert-success alert-dismissible fade show" role="alert">'
			  +$message
			  +'<button type="button" class="close" data-dismiss="alert" aria-label="Close">'
			  +'<span aria-hidden="true">&times;</span>'
			  +'</button>'
			  +'</div>';
		$div.html(html);
	},
	info : function ($div, $message){
		$div.show();
		var html = '<div class="alert alert-info alert-dismissible fade show" role="alert">'
			  +$message
			  +'<button type="button" class="close" data-dismiss="alert" aria-label="Close">'
			  +'<span aria-hidden="true">&times;</span>'
			  +'</button>'
			  +'</div>';
		$div.html(html);
	}
}