// JavaScript Document
var pwd=getCookie('pwd');
var uname=getCookie('uname');
if(document.getElementById("user_login")){
    if(uname){
    document.getElementById("user_login").value=uname; 
    }
    else{
       document.getElementById("user_login").value='';  
    }
}
if(document.getElementById("user_pass")){
    if(pwd){
    document.getElementById("user_pass").value=pwd;
    }
    else{
      document.getElementById("user_pass").value='';  
    }
}

function valLogin()
{
    var val1 = document.getElementById("user_login").value
    var val2 = document.getElementById("user_pass").value;
    
    if(document.getElementById("user_login").value=="")
    {
        alert("Please enter Username");
        document.getElementById("user_login").focus();        
        return false;
    }

    if(document.getElementById("user_pass").value=="")
    {
        alert("Please enter Password");
        document.getElementById("user_pass").focus();        
        return false;
    }

   process_login();
   return false;
}
function process_login(){
    
    $.post('/process-user-login.php',$("#user-login-form").serialize(), function(data) {
        $.trim(data);
        if(data=='S'){
            location.href='http://www.thesba.com/access-center.php';
        }
        else{
            $('#msgLogin').show();
            return false;
        }

});

   
}
function isValidEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  
   if(reg.test(email) == false) {
     
      return false;
   }
   else{
       return true;
   }
}

function valForgotAccount()
{
    var val3 = document.getElementById("emailAA").value;
	
    if(document.getElementById("emailAA").value=="")
    {
        alert("Please enter Email");
        document.getElementById("emailAA").focus();        
        return false;
    }
    
	if(!isValidEmail(val3))
	{
        alert("Please enter valid Email");
        document.getElementById("emailAA").focus();        
        return false;
    }

    process_forgot_account();
	
	return false;
}

function process_forgot_account(){
    //alert($("#account-form").serialize())
    $.post('/process_forgot_account.php',$("#forgot-form").serialize(), function(data) {
        $.trim(data);
       //alert(data)
        //alert(data.res)
        if(data.indexOf('Success')!=-1){
			 document.getElementById("emailAA").value = "";
             $('#msgForgotAccount').show();
             $('#account-table').hide();
             $('#forgot-table').hide();			 
             $('#login-table').show();
           //  return false;
        }
        else{
            $('#msgForgotError').show();
            return false;
        }

});
  
}

function valAccount()
{
    var val1 = document.getElementById("firstname").value
    var val2 = document.getElementById("lastname").value;
    var val3 = document.getElementById("emailA").value;
    
    if(document.getElementById("firstname").value=="")
    {
        alert("Please enter First Name");
        document.getElementById("firstname").focus();        
        return false;
    }

    if(document.getElementById("lastname").value=="")
    {
        alert("Please enter Last Name");
        document.getElementById("lastname").focus();        
        return false;
    }
     if(document.getElementById("emailA").value=="")
    {
        alert("Please enter Email");
        document.getElementById("emailA").focus();        
        return false;
    }
    if(!isValidEmail(val3)){
        alert("Please enter valid Email");
        document.getElementById("emailA").focus();        
        return false;
    }

   process_create_account();
  return false;
}
function process_create_account(){
    //alert($("#account-form").serialize())
    $.post('/process_create_account.php',$("#account-form").serialize(), function(data) {
        $.trim(data);
       //alert(data)
        //alert(data.res)
        if(data.indexOf('Success')!=-1){
             $('#msgAccount').show();
             $('#account-table').hide();
             $('#forgot-table').hide();			 
             $('#login-table').show();
           //  return false;
        }
        else{
            $('#msgAccountError').show();
            return false;
        }

});

   
}

function create_account(){
	$('#account-table').show();
	$('#login-table').hide();
	$('#forgot-table').hide();
}

function forgot_account(){
	$('#forgot-table').show();
	$('#account-table').hide();
	$('#login-table').hide();
}

function create_account_cancell(){
	$('#forgot-table').hide();
	$('#account-table').hide();
	$('#login-table').show();
}
