
//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use

$(document).ready(function()
{
	$("#login_form").submit(function() {
		//remove all the class add the messagebox classes and start fading
		document.getElementById('centeritem2').style.display = "block";
		$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("../ajax/member_ajaxlogin.php",{ userid:$('#loginid').val(),password:$('#password').val(),rand:Math.random() } ,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() { 
						//document.location='secure.php';
						var sPath = window.location.pathname;
						var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
						if ((sPage == "member_logout.php") || (sPage == "member_login.php") || (sPage == "member_register.php") || (sPage == "member_wrong.php")){
							document.location='../movies/movies.php';
						} 
						else {
							window.location.reload();
						}
			  	$(this).fadeTo(900,0,function() {
			  	});
			  });
			});
		  }
		  else {
		  	$("#msgbox").fadeTo(200,0.1,function() { 
			  	$(this).removeClass().html('Invalid UserID/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_form").trigger('submit');
	});
});
