$(function(){
	$('a[rel*=facebox]').facebox();
	
	$("#login_form").submit(function()

	{

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

		//check the username exists or not from ajax
		var username = $("#txtUsername").val();
		var password = $("#txtPass").val();
		var rndnum = Math.random(); //Spoof the Cache
		

		$.post("../../processors/login.php",{ username:username, password:password ,rand:rndnum } ,function(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='../userpanel/index.php';

			  });

			  

			});

		  }

		  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('Login Failed...').addClass('messageboxerror').fadeTo(900,1);

			});		

          }

				

        });

 		return false; //not to post the  form physically

	});

	//now call the ajax also focus move from 

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

	{

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

	});
	
	$('a#forgotpass').facebox({
        	loadingImage : '../../css/facebox/loading.gif',
        	closeImage   : '../../css/facebox/closelabel.gif'
    });	
	$('#frmforgotpass').livequery("submit", function(){
		var emailAddress = $('#txtEmail').val();
		$.facebox(function(){
			$.post("../../processors/forgotpass.php", {emailAddress:emailAddress}, function(data){
				$.facebox(data);
			});
		});
		return false;
	});



});