$(function(){
	$('#loginform').keypress(function (e) {
		 if(e.keyCode==13)login();
	});
});
function login(){
	var form=document.getElementById('loginform');
	var uv = form.username.value, pv = form.password.value;
	if(uv.isEmpty()){
		alert("用户名不能为空");
		form.username.focus();
	}else if(!uv.isMatch(/^[a-z]\w{4,15}$/i)){
		alert("用户名不合法，必须以字母开头5-16字节，允许字母数字下划线");
		form.username.focus();
	}else if(pv.isEmpty()){
		alert("密码不能为空");
		form.password.focus();
	}else if(!pv.isMatch(/^[\x00-\xff]{6,16}$/)){
		alert("密码不合法，必须为6-16个字节");
		form.password.focus();
	}else{
		var url = form.ssoserver.value+"!checkByJson.zte?username="+uv+"&password="+pv+"&jsoncallback=?";
		$.getJSON(url,
			function(data){
				var r=$.trim(data.info);
				if(r=="success") {
					form.submit();
				}else if(r=="username_not_valid"||r=="username_incorrect"){
					alert("用户名不正确！");
				}else if(r=="password_not_valid"||r=="password_incorrect"){
					alert("密码不正确！");
				}else if(r=="username_not_exist"){
					alert("用户名不存在！");
				}else if(r=="restrict_login"){
					alert("用户名已经被管理员限制登录！");
				}else{
					alert("系统出错，请联系管理员！");
				}
		});
	}
}
/**
 * 将产品加入暂存架
 * 未登录:other...;成功:success;已存在:existError
 */
function appendMytemp(pid){
	$.get("customer/appendMytemp.action?pid="+pid,function(r){
		if(r=="success"){
			alert("已成功加入暂存架!");
		}else if(r=="existError"){
			alert("对不起,您已经收藏过此产品!");
		}else{
			window.location.href=r;
		}
	});
}

function forgetPassword(){
	$.getCss('res/css/jquery.popup.css');
	$.getScript('res/js/jquery.popup.js',function(){
    	$(document.body).popup($.extend({
    		buttons:{},
	    	iframe: true,
	    	type: 9,
	    	title:'忘记密码？',
	    	url:'http://passport.ztemc.com/popupForgetPassword.jsp',
	    	width: 400,
	    	height: 240
    	}));
	});
}