//*****************************
//  Author Wang Luyi
//  Need jquery-1.3.2.min.js
//  Need verify.js
//  Version 1.0
//*****************************

jQuery(function(){

	/*字符串操作*/String.prototype.Trim = function(){ return this.replace(/(^\s*)|(\s*$)/g, ""); }
	/*添加隐藏控件*/f=jQuery("#loginForm");lm=jQuery("<input type='hidden' id='loginMethod' name='loginMethod'></input>").appendTo(f).val(12);
	/*用户名格式确认*/setNameType=function(){n=jQuery("#logiName").val();lm.val(isEmail(n)?11:(isMobile(n)?14:12)); }
	/*按钮控制*/b=jQuery("#loginButton"); switchButton=function(t){b.attr("enabled",(t?1:0));}; 
	jQuery("#loginPassword").bind("keypress",function(e){var code = (e.keyCode ? e.keyCode : e.which); if(code==13) jQuery("#loginForm").submit(); });
	jQuery("#loginEnter").bind("keypress",function(e){var code = (e.keyCode ? e.keyCode : e.which); if(code==13) jQuery("#loginForm").submit(); })
	
	/*登录名验证*/
	validateLoginName=function(logiName,it){ it.find(".r_img").hide(); if(logiName.Trim()==""){it.find(".r_img").show();return false;} return true; }
	jQuery("#logiName").bind("blur",function(){ validateLoginName(jQuery(this).val(),jQuery(this).parent().parent());});
	
	/*密码验证*/
	validateLoginPassword=function(password,it){ it.find(".r_img").hide(); if(password==""){it.find(".r_img").show();return false;} return true; }
	jQuery("#loginPassword").bind("blur",function(){ validateLoginPassword(jQuery(this).val(),jQuery(this).parent().parent());});
	
	/*登陆Ajax验证*/
	validateLogin=function(){p={"loginMethod":jQuery("#loginMethod").val(),"logiName":jQuery("#logiName").val().Trim(),"password":jQuery("#loginPassword").val()}; jQuery.ajaxSetup({async:false}); v=false; jQuery.get("../login/dologinValidation.action?timestamp="+new Date().getTime(),p,function(d){if(d!="") {jQuery("#errorTip").show();} else v=true; }); return v};

	/*Form提交绑定*/
	jQuery("#loginForm").submit(function(){ if(b.attr("enabled")!="1") return false; if(validateLoginForm()){ jQuery("#logiName").val(jQuery("#logiName").val().Trim()); jQuery("#errorTip").hide(); switchButton(false); setNameType(); v=validateLogin(); switchButton(!v); return v; } ; return false; });
	
	validateLoginForm=function(){
		var v=true;
		v=validateLoginName(jQuery("#logiName").val(),jQuery("#logiName").parent().parent()) && v;
		v=validateLoginPassword(jQuery("#loginPassword").val(),jQuery("#loginPassword").parent().parent()) && v;
		return v;
	}
	//b.attr("enabled","1").bind("click",function(){ if(jQuery(this).attr("enabled")=="1"){ jQuery(this).attr("enabled","0"); if (validateLoginForm()) jQuery("#loginForm").submit(); else jQuery(this).attr("enabled","1"); }});
	b.attr("enabled",1).bind("click",function(){jQuery("#loginForm").submit();pageTracker._trackEvent('Login','Login','Mamabb');});
	
});
