/**
 * @author developer
 */

 // wait for the document to 
 // get ready then we begin to process
 $(document).ready(function(){
 	
	$('#submitform').click(DoLogin);
 });
 
 // perform the login for the user
 // using the entered credentials
 function DoLogin()
 {
 	$('.account-msg').remove();
	
	$('#submitform').val('Signing In....');
	
 	$.post('./util_scripts/ajax_main.php', {usrname:$('#username').val(), password:$('#password').val(), opr:'sign_in'}, function(result){
		
		if(result.IsSuccess)
		{
			document.location = result.redirection;
			$('#submitform').val('loading...');
		}
		else
		{
			$('#submitform').val('Sign In');
			
			switch(result.reason)
			{
				case 'EXPIRED':
					$('<p class="account-msg account-expire">Dear valued subscriber, your subscriptions has expired since '+result.expired_on+'. Please renew your subscription to continue accessing the daily paper</p>').insertBefore('#frm_paper_login');
				break;
				
				case 'INCORRECT_CREDENTIALS':
					$('<p class="account-msg" id="login_fail_msg">Incorrect username or password, please make sure that caps lock is not on.. and try again.</p>').insertBefore('#frm_paper_login');
				break;
			}	
		}
		
	}, 'json');
	
	return false;
 }
 
 // perform the sign out
 function DoSignOut()
 {
 	
 }
 
 
 