iwms.logVcode=function(disp){
	$("#phVcode").css("display",disp?"":"none");
}

iwms.logBanIp=function(){
	iwms.logVcode(false);
	$("#loginForm button").attr("disabled","disabled");
	$("#logMsg").html("登陆失败过多，稍后再试");
}

// 登陆提交,f 表单,adm 是否管理登录
iwms.logChk=function(f,adm){
//		var f=o.form;
	if (f.memberName.value=="" || f.memberName.style.color=="#999"){
		alert("请填写会员名");
		f.memberName.focus();
		return false;
	}
	if (f.memberPass.value==""){
		alert("请填写密码");
		f.memberPass.focus();
		return false;
	}
	if(adm==undefined)adm=false;
	
	iwms.ajSrc=$(f).find("button").get(0);
	$.post("ajax.aspx",{cmd:adm?"loginAdm":"login",username:iwms.ajEncode(f.memberName.value),password:f.memberPass.value,vcode:f.vcode.value},
		function(r){
			switch(r.result){
				case 1 :
					$("#logMsg").html("登录成功");
					if(adm){
						r.user.keep=iwms.user.keep;
						iwms.cookie("iwmsAdmin","y",0.15);
					}else{
						r.user.keep=f.keepLogin.checked?1:0;
					}
					iwms.logVcode(false);
					iwms.logSave(r.user);
					if(adm){
						top.location.href="admin_main.aspx";
					}else{
						setTimeout("iwms.logReload()",1500);
					}
					return;
				case 2 :
					$("#logMsg").html("用户名或密码错误");
					$(f.memberPass).val("").focus();
					break;
				case 3 :
					$("#logMsg").html("会员已到期");
					break;
				case 4 :
					$("#logMsg").html("验证码错误");
					$(f.vcode).val("").focus();
					break;
			}
			iwms.logVcode(r.dispVcode);
			if (r.banIp){
				iwms.logBanIp();
			}
		},"json"
	);
	
	return false;
};

$(function(){
	var f=$("#loginForm").get(0);
	if (iwms.user.name.length>0){
		$(f.memberName).val(iwms.user.name);
		$(f.memberPass).focus();
	}else{
		$(f.memberName).focus();
	}
	$(f.vcode).focus(function(){
		var o=$("#vimg");
		if(o.length==0){
			o=$("<img id='vimg' src='admin_verifyimg.aspx?' style='position:absolute;border:1px solid #999'/>").appendTo("#loginForm");
		}else{
			o.show();
			o.attr("src","admin_verifyimg.aspx?"+parseInt(Math.random()*1000));
		}
		var p=$(this).offset();
		p=iwms.elePos(this);
		o.css({left:p.x+p.w+1,top:p.y});
	}).blur(function(){
		$("#vimg").hide();
	});
	
});