var wwwUrl = "http://www.16888.com";
var login_result_tb;
function login(){
		var username = $("#username").val();
		username = encodeURI(username);
		var password = $("#password").val();
		if(username==""||password==""){
			$("#alert").html("<em>请输入密码和账号</em>");
		}else{
			$.getScript(wwwUrl+"/ajax/login2.php?act=login&username="+username+"&password="+password,function(){
				if(login_result_tb!=0&&login_result_tb){
					login_result_tb = '<a href="http://bbs.16888.com">车主社区&gt;&gt;</a>'+login_result_tb;
					$("#login_div").html(login_result_tb);	
				}else{
					$("#alert").html("<em>密码或账号错误，请重新输入</em>");
				}
			});
		}
	}
function logout(){
		$.getScript(wwwUrl+"/ajax/login2.php?act=logout",function(){$("#login_div").html(login_result_tb);});
	}
function getCookie_login(c_name){
		if (document.cookie.length>0){	
			c_start=document.cookie.indexOf(c_name + "=")
			if (c_start!=-1){ 
				c_start=c_start + c_name.length+1 ;
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
			} 
		}
	return ""
	}
$(function(){
	//登陆区域
	
	$.getScript(wwwUrl+"/ajax/login2.php",function(){
		
		if(login_result_tb!=0&&login_result_tb){
			login_result_tb = '<a href="http://bbs.16888.com">车主社区&gt;&gt;</a>'+login_result_tb;
			$("#login_div").html(login_result_tb);
		}else{
			
			//var username = getCookie_login('username_last_login');
			if (username_last_login!=null && username_last_login!=""){
				$("#username").val(username_last_login);
			}
		}
	});
	$("#password").bind("keyup", function(event){
		if (event.keyCode=="13"){
			login();
		}
	});
});
