$(document).ready(function() {
	loginmodal()
	
	$("#frmsignin").validate({
			rules: {
				username: "required",
				password: "required"
			}	
		})
		$("#signin_submit").click(function() {
		// validate and process form here		
			//alert('oks lang');
			var dataString = $("#frmsignin").serialize();
			  $.ajax({
				type: "POST",
				url: "inc/process_login.php",
				data: dataString,
				//Do not cache the page
				cache: false,
				
				success: function(data) {
					//alert(data);
					if (data.indexOf("yes") == -1) {  
						//$( "#result" ).empty().append("Invalid account! Please try again!");
						//alert('Invalid account! Please try again!');
						$("#msgbox").fadeTo(200,5,function()  //start fading the messagebox   
						{    //add message and change the class of the box and start fading    
							$(this).html('Invalid account! Please try again...').addClass('messageboxlogin').fadeTo(2000,1); 
							$("#msgbox").fadeOut('slow');  
						});				
					}  
					else
					{
						window.location.replace("index.php");
					}
									
				}  
				
			  });
			  
		});
});

function loginmodal()
{
	$('#access .login').click(function (e) {
		$('#login').modal();
		return false;
	});	
}
