var QuickLoginForm = {
	width:0,
	height:0,
	id:null,
	url:null,
	msg:null,
	show: function(obj)
		{
			var o;
			if (typeof(obj) == "object")
			{
				o = obj;
			}
			else
			{
				try {
					if (typeof(window.event.srcElement) == "object")
					 	o = window.event.srcElement;
					if (typeof(obj.target) == "object")
					{
						o = obj.target;
					}
				} catch (e) {
					
				}
			}
			this.width = 219;
			this.height = 124;
			var body = lib.getBody();
			var w = parseInt(this.getWidth());
			var h = parseInt(body.offsetHeight) + parseInt(body.scrollTop);
			var x = parseInt(lib.x(o));
			var y = parseInt(lib.y(o));
			var _x = 0;
			var _y = 0;
			var _ow = parseInt(this.width/2);
			var _oh = parseInt(this.height/2);
			if (x - _ow < 0)
			{
				_x = 0;
			}
			else if (x + _ow >= w)
			{
				_x = w - this.width - 10;
			}
			else
			{
				_x = x - _ow + lib.intval(o.offsetWidth)/2;
			}
			
			if (h - y < this.height)
			{
				_y = h - this.height - 20;
			}
			else
			{
				_y = y + 20;
			}

			var div = lib.element(this.id);
			if (div == null)
			{
				var div = document.createElement("div");
				div.id = this.id
				document.body.appendChild(div);
			}
			div.style.cssText = "background:#fff;filter:alpha(opacity=90);-moz-opacity:0.90;opacity:0.90;z-index:100;margin:0px;padding:0px;width:" + (this.width + 2) + "px;height:" + (this.height +2) + "px;position:absolute;left:" + _x + "px" + ";top:" + _y + "px";
			div.innerHTML = "<iframe width=" + (this.width + 2) + " height=" + (this.height + 2) + " src=" + this.url + "?msg=" +escape(this.msg) + "&id=" + this.id + " scrolling=no frameborder=0></iframe>";
		},
	
	remove: function()
	{
		var div = lib.element(this.id);
		if (div != null)
		{
			document.body.removeChild(div);
		}
	},
	
	close: function(id)
	{
		if (!id) {
			id = lib.getParameter("id");
			window.parent.document.body.removeChild(window.parent.document.getElementById(id));
		} else {
			if (document.getElementById(id)) {
				document.body.removeChild(document.getElementById(id));	
			}
		}		
		return false;
	},
	
	send: function(user, pass, auto_login)
	{
		var _user = user.value.trim();
		var _pass = pass.value.trim();
		var _login = (auto_login.checked)?1:0;
		if (_user == "" || _user == "请输入用户名或手机号")
		{
			alert("请输入您的用户名");
			user.value = "";
			user.focus();
			return false;
		}
		if (_pass == "")
		{
			alert("请输入您的登录密码");
			pass.value = "";
			pass.focus();
			return false;
		}	

		var req = new Request(
						function ()
						{
							if (req.xmlhttp.readyState == 4) {
								var rs = req.xmlhttp.responseText;
							
								//100: 登录成功 101: 用户不存在 102: 用户密码错误  103:手机登录
								if (rs == "100")
								{
									QuickLoginForm.close();
								}
								else if (rs == "101")
								{
									alert("您的用户名或手机号输入错误");
									user.focus();
								}
								else if (rs == "102") {
									alert("您的密码输入错误");
									pass.focus();
								}
								else if (rs.toString().indexOf("103") > -1) {
									alert("一分钟完成资料填充，成为正式会员，赢取丰厚大奖！");
									window.top.location = "http://passport.wangyou.com/register.php?" + rs.toString();
								}
								else {
									alert(rs);
								}
							}
						}
					);
		req.get("index.php?q=login&user=" + lib.urlencode(_user) + "&pass=" + _pass + "&auto_login=" + _login);
		return false;
	},
	
	check: function()
	{
		if (cookie.get("wangyoulogin") != null && cookie.get("wangyoulogin").length == 32)
		{
			return true;
		}
		return false;
	},
	
	logout: function() 
	{
		cookie.set("wangyoulogin", null, 0, "/");
		return true;
	},
	
	getWidth: function()
	{
	  	if (window.innerWidth)
   			return window.innerWidth;
		if (document.body&&document.body.clientWidth)
   			return document.body.clientWidth;
  		if (document.documentElement&&document.documentElement.clientWidth)
   			return document.documentElement.clientWidth;
  		
	}
}