//快速函数
function g(sid){
	return document.getElementById(sid);
}

//用户接口
function changebtn(bs){
	if(bs==1){
		g('submitbtn').disabled=true;
	}else{
		g('submitbtn').disabled=false;
	}
}

//初始表单的检查
function initlogin(value, lb){
	if(lb==0){
		if (value==''){
			g('username').style.background='';
		}
	}
	if(lb==1){
		if (value==''){
			g('password').style.background='';
		}
	}
}
function editlogin(value, lb){
	if(lb==0){
		if(value==''){
			g('username').style.background='url(/images/username.gif) no-repeat left center';
		}
	}
	if(lb==1){
		if(value==''){
			g('password').style.background='url(/images/password.gif) no-repeat left center';
		}
	}
}

//登录检查
function sess(val) {	
	var tt=typeof val;
	if (tt=="string"){
		alert (wrong[val]);
		return;
	}
	
	defaulthtml=gethtmlbody(val['user'],val['img'],val['sess'],val['mess'],"default");
	if(val['sess']!=0){						
		htmlbody=gethtmlbody(val['user'],val['img'],val['sess'],val['mess'],"login");						
		if(val['club']!=0){							
			g('space_login').innerHTML= htmlbody;
		}else{
			joinselect(wrong["UE107"],htmlbody,defaulthtml);
		}
	}else{							
		g('space_login').innerHTML= defaulthtml;
		if (val['user']!=0)
		{
			g('username').style.background='';
			g('username').value=val['user'];
		}
	}		
}

//登录
function userlogin(){
	var user=encodeURIComponent(g("username").value);
	var pass=g("password").value;
	var icookie=0;
	if(g("remember_me").checked==true){
		icookie=1;
	}
	
	if(user==""){
		alert(wrong["UE108"]);
		return;
	}
	if(pass==""){
		alert(wrong["PE107"]);
		return;
	}

	//alert(user);
	sajax_request_type='POST';
	x_login(user, pass, icookie, sess);
}

//注销
function logout(){
	sajax_request_type='GET';
	x_logout(sess);
}

//社区选择
function joinselect(msg,htmlbody,defaulthtml){
	
	if (confirm(msg)) {
	   x_joinclub(sess);;
    }else {       
	   x_logout(logout);;
    }
	
}

//默认动作
x_sess(sess); 
