$(function(){

	loadDatepicker();
	
	$('.loginForm').submit(function(){
		
		var form = $(this).serialize();
		var formBody = $(this);
		var classError = '.errorUser';
		
		$('.loading-body').removeClass('hidden');
		
		$.post(URL+'index/login',form)
		.done(function(returnData){
			
			$('.alert-content').html(returnData);
			
			if(returnData == 'Invalid Login')
			{
				openAlert(classError);
				setTimeout(closeAlert,3000);
				$('.loading-body').addClass('hidden');
			}
			else
			{
				location.reload();
			}
		})
		return false;
	})
	
	
	$('#sidebar li a').click(function(){
		$('.cssload-holder').removeClass('hidden');
	})
	closeAlertBtn();
})
function openAlert(classError)
{
	$('.alert-notification'+classError).css('opacity',1);
	$('.alert-notification'+classError).css('right','300px');
}
function closeAlert()
{
	$('.alert-notification').css('opacity',0);
	$('.alert-notification').css('right','0px');
}

function closeAlertBtn()
{
	$('.close-alert').click(function(){
		$(this).closest('.alert-notification').css('opacity',0);
		$(this).closest('.alert-notification').css('right','0px');
	})
}
function loadDatepicker()
{
	$('.datepicker').datepicker({
			format: "yyyy-mm-dd"
	});  
}