// JavaScript Document


/**


 * @copyright	Copyright (C) Lab Imagination. All rights reserved.


 * @license  Lab Imagination, see LICENSE.php


 * Lab Imagination! is not free web application. This version may not have been modified pursuant


 * to the Lab Imagination License, and as not distributed it is not included or


 * is not derivative of works licensed under the Lab Imagination License.


 * See COPYRIGHT.php for copyright notices and details.


*/


$(document).ready(function()


{


	$("#login_form").submit(function()


	


	{


		//remove all the class add the messagebox classes and start fading


		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn(1000);


		//check the username exists or not from ajax


		$.post("userlogin.php",{ loginID:$('#username').val(),password:$('#password').val()} ,function(data)


        {


	     //alert(data);


		  if(data=='yes') //if correct login detail


		  {


		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox


			{ 


			  //add message and change the class of the box and start fading


			  $(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,


              function()


			  { 


			  	 //redirect to secure page


				 document.location='index.php?dashboard';


			  });


			  


			});


		  }


		  else 


		  {


			$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox


			{ 


			


			  //add message and change the class of the box and start fading


			  $(this).html('Invalid username or password').addClass('messageboxerror').fadeTo(900,1);


			});		


          }


				


        });


 		return false; //not to post the  form physically


	});


	//now call the ajax also focus move from 


	$("#password").blur(function()


	{


		$("#Login").trigger('submit');


	});


});





/*-----------------------Forgot Password?------------------------------------*/


   


$(document).ready(function(){


$("#forgotForm").submit(function(){





var str = $("#forgotForm").serialize();


   $.ajax({


   type: "POST",


   url: "sendPassword.php",


   data: str,


   success: function(msg){  


   


$("#note_forgot").ajaxComplete(function(event, request, settings)


{





if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form


{


result = '<div class="notification_ok">Password is sent successfully. Thank you!</div>';


$("#fields_forgot").show();


}


else


{


result = msg;


}





$(this).html(result);





});





}





 });





return false;





});





});