$(function(){

	$("#loginBtn").click(function(){
		var uname = $.trim($("#uname").val());
		var pwd  =	$.trim($("#pwd").val());
		var captcha = $.trim($("#captcha").val());
		if(captcha==''){
			alertify.error("验证码为空！");
			return;
		}
		
		if(uname==''||pwd==''){
			alertify.error("用户名或密码不能为空！");
			return;
		}
		var secpwd=$.md5(pwd);
		var params={    
				uname : uname,    
				pwd : secpwd,
				code:captcha
		};
		$.ajax({
			url:'user/loginSubmit.shtml',
			type:"post",
			data:$.toJSON(params),   
			dataType: "json",
			async:true,
			contentType:"application/json",
			success:function(data){
				if(data.code=='01'){
					var admin=data.content;
					localStorage.hostId = admin.adminId; // 管理员编号
					localStorage.utype = '1'; // 管理员
					localStorage.uname = uname; // 用户名
					localStorage.pwd = secpwd; // 密码
					window.location.href = 'system/index.shtml';
				}else{
					alertify.error(data.msg);
				}
			}
		});
	});
	
	$(".code_change").click(function(){
		changeCode();
	});
	
	$("#captcha_image").click(function(){
		changeCode();
	});
	
	changeCode = function(){
		var rand =  Math.random(); 
		$("#captcha_image").attr("src","captcha/image.shtml?timestamp="+rand);
	};
});