var popupLogin = function () {
	var objs = document.getElementsByTagName("object");
	if (!$.browser.msie) {
		objs = document.getElementsByTagName("embed");
	}
	
	for(i = 0;i < objs.length; i ++) {
		if(objs[i].style.visibility != 'hidden') {
			objs[i].setAttribute("oldvisibility", objs[i].style.visibility);
			objs[i].style.visibility = 'hidden';
		}
	}
	
	var clientWidth = document.body.clientWidth;
	var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
	var pmwidth = 300;
	var pmheight = 200;
	if(!$('#loginLayer').length) {
		div = "<div id='loginLayer' style='width:";
		div +=  pmwidth + "px;height:" + pmheight + "px;left:" + ((window.screen.width - pmwidth) / 2) + "px;position:absolute;z-index:999; background:#fff url(http://skin.cnal.com/img/wintitle.gif) repeat-x 0 0; border:1px solid #CCCCCC;'></div>"
		div +=  "<div style='display: block; position: absolute; background-color: #f9f9f9; z-index: 99; left: 0px; top: 0px;right: 0px; height: " + document.body.clientHeight + "px;' id='loginOverLayer'></div><div id='loginLayerRun'></div>";
		$("body").append(div);
		$('#loginOverLayer').css('opacity', '0.5');
		var from = encodeURIComponent(window.location.href);
		$('#loginLayer').html('<div id="loginTitleBar" style="padding:5px 10px 0 0;height: 19px;background:url(http://skin.cnal.com/img/logo.png) no-repeat 10px 0; text-align:right;border-bottom:1px solid #CCCCCC;"><img id="LoginClose" src="http://skin.cnal.com/img/winclose.gif" /></div><h3 style="margin:5px;height:30px;line-height:30px;text-align:center;">登&nbsp;&nbsp;录</h2><div style="line-height:30px;text-align:center;"><label for="loginLayerName">用户名：</label><input maxlength="15" type="text" id="loginLayerName" /></div><div style="line-height:30px;text-align:center;"><label for="loginLayerPWD">密&nbsp;&nbsp;码：</label><input type="password" id="loginLayerPWD" /></div><div style="line-height:30px;text-align:center;"><input style="width:71px;line-height:19px;background:url(http://skin.cnal.com/img/on.gif) repeat-x 0 0;border:1px solid #83BBD9;font-size:14px;font-weight:bold;color:#3898CB;" type="button" id="loginLayerSubmit" value="登 录" /></div><div style="line-height:40px;text-align:center;font-size:12px;"><a target="_blank" href="http://member.cnal.com/find.php?from=' + from + '">忘记密码</a>&nbsp;&nbsp;<a target="_blank" href="http://member.cnal.com/reg.php?from=' + from + '">注册用户</a></div>');
		$('#LoginClose').click(function () {
			for(i = 0;i < objs.length; i ++) {
				if(objs[i].attributes['oldvisibility']) {
					objs[i].style.visibility = objs[i].attributes['oldvisibility'].nodeValue;
					objs[i].removeAttribute('oldvisibility');
				}
			}
			$('#loginLayer').css('display', 'none');
			$('#loginOverLayer').css('display', 'none');
		});
		$('#loginLayerPWD').keypress(function (e){
			if (e.which == 13) {
				$('#loginLayerSubmit').click();
			}
		});
		$('#loginLayerSubmit').click(function () {
			var username = encodeURIComponent($.trim($('#loginLayerName').val()));
			var password = encodeURIComponent($.trim($('#loginLayerPWD').val()));
			if (username == '') {
				alert('请输入您的用户名！');
				$('#loginLayerName').focus();
				return false;
			}
			if (password == '') {
				alert('请输入您的密码！');
				$('#loginLayerPWD').focus();
				return false;
			}
			$.post("/service/?m=login&a=popup", {'username' : username, 'password' : password}, function(data){
				$('#loginLayerRun').html(data);
			});
			return false;
		});
		$('#loginTitleBar').mousedown(function (e) {
			
		});
	}
	$('#loginLayer').css('display', '');
	$('#loginOverLayer').css('display', '');
	$('#loginLayer').css('top', ((clientHeight - pmheight) / 2 + scrollTop) + 'px');
}

