QuickLogin= RequestBase.extend({
  initialize: function() {
  	this.parent();
  },
  bindFunc:function(func){
	this.afterLoginFunc=func;
  },
  show:function(){
	  if(!this.htmlElement)
		  this._createUI();
	  $("loginInfo").innerHTML="";
	  $("loginInfo").style.display="none";
	  this.htmlElement.style.display="block";
	  $("q_username").focus();
	  this.rePosition();
  },
  hide:function(){
	  this.htmlElement.style.display="none";
  },
  _createUI:function(){
	//html='<div id="quickLogin">
    html='<div class="titleBar">';
    html+='<div>';
    html+='<span title="关闭" class="r" id="quick_login_close"> </span>';
    html+='<span  class="title" style="display: block;">登录一起爱宝宝</span>';
	html+='</div>';
    html+='</div>';

    html+='<div class="content">';
    html+='<div id="loginInfo"></div>';
	html+='<div class="case">'; 
    html+='<div style="" id="notice_bar" class="mgntxt">请输入一起爱宝宝用户名和密码登录</div>';
	html+='<div class="input">';
	html+='<label for="text0">用户名：</label>';
	html+='<input type="text" id="q_username" name="userName" tabindex="110"/>';
	html+='</div>'; 
	html+='<div class="input">';
	html+='<label for="text1">密　码：</label>';
	html+='<input type="password" id="q_password" name="userPassword" tabindex="111"/>'; 
	html+='</div>';
	   
	html+='<div class="btnbar">';
	html+='<input type="checkbox" id="q_can_remember_me" name="q_can_remember_me" tabindex="112"/>';
	html+='<label for="q_can_remember_me">自动登录</label>'; 
	html+='<input type="button" id="qLoginButt" value="登录一起爱宝宝" tabindex="113"/>';
	html+='</div>';         

    html+='</div>';
    html+='</div>';
	html+='</div>';	
	var div=document.createElement('div');
	div.id="quickLogin";
	div.innerHTML=html;
	document.body.appendChild(div);
	this.htmlElement=div;
	this.bindEvent();

  },
  bindEvent:function(){
	$("quick_login_close").onclick=this.hide.bindAsEventListener(this);
	$("qLoginButt").onclick=this.login.bindAsEventListener(this);

  },
  login:function(){

     //检查用户是否输入了用户名、密码
       this.username=$('q_username').value;
       if(!this.username){
         alert("请输入用户名！");
         return false;
       }
       this.password=$('q_password').value;
       if(!this.password){
         alert("请输入密码！");
         return false;
       }

       if($('q_can_remember_me'))
	       this.rememberMe = $('q_can_remember_me').checked;
	   else
	   		this.rememberMe=0;
	  
       this.showInfo("正在验证");
       this._post('bloghome.validate.validateUserLogin',this.onLogin.bind(this),{username:this.username,password: this.password,rememberMe:this.rememberMe});


  },
  onLogin:function(xmlhttp){
       if (xmlhttp.status != 200) {
            return;
        }

        var elements = xmlhttp.responseXML.getElementsByTagName("rsp");
        if (elements == null || elements.length != 1) {
            return;
        }
        var rsp = elements[0];
        var stat = rsp.getAttribute("stat");
        if (stat == "ok") {
          //$('loginForm').submit();
          //得到rsp的子节点，是一个数组，只有一个元素
          var node = rsp.childNodes;
          var validateResult = node[0].getAttribute("result");
          var referer = node[0].getAttribute("referer");
          //根据服务器端返回的值，做出不同的提示，如果用户输入信息那么直接跳转到用户登录后的首页
          switch(validateResult){
              case "ok":
				  if(this.afterLoginFunc){
					  this.hide();
					  var userName=node[0].getAttribute("userName");
					  var userId=node[0].getAttribute("userId");
					  var params={userName:userName,userId:userId};
					  this.afterLoginFunc(params);

			      }else
					window.location.reload();
                  break;
              case "noUser":
                  var content="对不起，用户名不存在，请重新输入";
                  this.showInfo(content);
                  return false;
                  break;
              case "passwordError":
                  var content="对不起，密码不正确，请重新输入";
                  this.showInfo(content);
                  return false;
                  break;
              case "disable":
                  var content="对不起，此用户已经被禁止使用";
                  this.showInfo(content);
                  return false;
                  break;
              case "tooManyTimesToLogin":
                  var content="对不起，您已经3次尝试登录本站失败，请间隔15分钟后再次尝试。";
                  this.showInfo(content);
                  return false;
                  break;
              case "many":
                  var content="对不起，系统存在重名用户，无法确认您的身份，请到<a href='http://www.172baby.com' target='_blank'>这儿</a>重新登陆。";
                  this.showInfo(content);
                  return false;
                  break;
          }
        }
     },
     showInfo:function(info){
		 $("loginInfo").style.display="block";
		 $("loginInfo").innerHTML=info;
	 },
	 rePosition:function(e){
        if (this.htmlElement)
        {
             this.deltaX =  window.pageXOffset
                || document.documentElement.scrollLeft
                || document.body.scrollLeft
                || 0;
			this.deltaY =  window.pageYOffset
                || document.documentElement.scrollTop
                || document.body.scrollTop
                || 0;
            var y= 120;
            //this.htmlElement.style.left = x + "px";
            this.htmlElement.style.top = this.deltaY+163 + "px";
           
        }
    }
});