var submit_ok = ' ';

function login() { 

var user = $("#user").val(); 
var pass = $("#pass").val(); 

if (user == "") { 
    $("#confirm").html("<p style='background:yellow;padding:5px;color:red;'><b>Please Input the User Name!</b></p>"); 
    $("#user").focus(); 
	return false; 
} 
if(pass == "") { 
    $("#confirm").html("<p style='background:yellow;padding:5px;color:red;'><b>Please Input the Password!</b></p>"); 
    $("#pass").focus(); 
    return false; 
} 


$.ajax({ 
    type: "POST", 
    url: "extra/login/login.php", 
    data: "username=" + user + "&passwd=" + pass, 
    beforeSend: function(){ 
    $("#confirm").text("Login......"); 
    }, 
    success: function(msg){ 		
	
   if(msg == "success"){ 
		submit_ok = "success";
	   $("#confirm").html("<p style='background:green;padding:5px;color:yellow;'><b>Successfully! Welcome " + user + " Back!</b></p>"); 
	   $("#login_button").val("Continue Shopping");
	   $("#login_close_pic").hide();
	   $("#user_row").hide();
	   $("#pass_row").hide();
		//$("#login_pic").src("images/top/logout.gif");
    }else { 
		if(msg == "no_username")
		{
       $("#confirm").html("<p style='background:yellow;padding:5px;color:red;'><b>There is no such user !</b></p>");
	   $("#user").focus();
	   $("#user").select(); 
		}
		if(msg == "no_password")
		{
       $("#confirm").html("<p style='background:yellow;padding:5px;color:red;'><b>The password is wrong !</b></p>");
	   $("#pass").focus();
	   $("#pass").select();
		}
    } 
	} 
}); 


}

$(document).ready(function(){ 
    $("#loginform").submit(function(){ 
        login();

		if(submit_ok == "success"){
			return true;
		}else{
			return false;  
		}
    }); 
});
