$(document).ready(function(){
		  $('#frmforgotpass').submit(function() {	   			
				   var options = {
				   target:        '#status', 
				   beforeSubmit:  forgotRequest,
				   success:       forgotResponse,        
				   url:           'admin/controller/forgotpass_controller.php', 
				   type:          'post',
				   timeout:       3000
				   };		   
		   			$('#status').fadeIn();
	   				$("#status").html("<b> Checking details.Please wait...</b>");		   
					$(this).ajaxSubmit(options);
					return false;
		    });
});


function forgotResponse(responseText, statusText)
{
    $('#status').fadeIn();
	if(responseText == 1)
	{
		 $("#status").html("<b>New password is sent to your email address.You can now login with that password.</b>");
		 setTimeout(function(){ $('#status').fadeOut('slow'); }, 2000);
		 window.location='index.php';//return true;
	}
	else if(responseText == 2)
	{
		$("#status").html("<b>Username not found,please register.</b>");
		setTimeout(function(){ $('#status').fadeOut('slow'); }, 1000);
	}
	else if(responseText == 3)
	{
		$("#status").html("<b>Username and associated email address does not match</b>");
		setTimeout(function(){ $('#status').fadeOut('slow'); }, 1000);
	}
	else
	{
		$("#status").html("<b>Error in retrieving data</b>");
		setTimeout(function(){ $('#status').fadeOut('slow'); }, 1000);
	}
	return false;	
}

function forgotRequest(accountData, registerForm, options)
{
	if (!CheckNull($("#txtbusr").val()))
	{
		$('#status').fadeIn();	
		$("#status").html("<b> Please enter Username</b>");				
		$("#txtbusr")[0].style.border='2px solid red';
		flg=false;
		return false;				
	} 
	else
	{
		flg=true;
		$("#txtbusr")[0].style.border='1px solid #FFFFFF';
	}
	
	
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	$('#txtbemail').each(function() { 
		if(!filter.test(this.value))
		{
			$('#status').fadeIn();		   
			$("#status").html("<b> Please enter valid Email Address ...</b>");				
			this.style.border='2px solid red';
			flg=false;
			return false;				
		}
		else
		{ 
			flg=true;
			this.style.border='1px solid #FFFFFF';
		}
	});
	
	
	return flg;
}

