﻿
function GetObject(id){ return document.getElementById(id); }
  
function UiTree(url)
{  
       if(GetObject("popshow")!=null)
       {
        document.body.removeChild(GetObject("popshow")); 
       }
       
       
       
      var PopBody="<div id='denlublock'>";
      PopBody=PopBody+"<div><input type='submit' name='button' id='close' value='关闭  ' onclick='divClose()' /></div>";
      PopBody=PopBody+"<div class='txzout'><img src='http://www.life5000.com/images/dl_04.gif' alt='登录通行证' width='94' height='31' /></div>";
      PopBody=PopBody+"<ul class='dlout_input'>";
      PopBody=PopBody+"<li>用户名&nbsp;&nbsp;<input id='UIuserName' type='text' size='25' style='width:200px'/><input id='urlkey' type='hidden' /></li>";
      PopBody=PopBody+"<li>密&nbsp;&nbsp;码&nbsp;&nbsp;<input id='UIpassWord' type='password' size='25' style='width:200px'/></li>";
      PopBody=PopBody+"<li>验证码&nbsp;&nbsp;<input id='UIverify' type='text' size='8' />";
      PopBody=PopBody+" <img id='UIcheng' src='http://www.life5000.com/VerifyCode.aspx?' align='absmiddle' alt='' /> &nbsp;<a href='javascript:UIchanne();'>&nbsp;换一张</a></li>";
      PopBody=PopBody+"</ul>";
      PopBody=PopBody+"<div class='dlout_menu'><input name='' type='button' class='input' value='登  录' onclick=UILogin('"+url+"') /><a href='http://www.life5000.com/reg.aspx' target='_blank'>新用户注册</a></div>";
      PopBody=PopBody+"<div class='clearz'></div>";
      PopBody=PopBody+"</div>";
       
       
       
//       
//	      var PopBody="<div id='K6Login'>";
//	      PopBody=PopBody+"<div class='tit'><img src='/images/K6LoginLogo.jpg' alt='' /><img id='K6LoginClose' onclick=divClose(); src='/images/K6LoginClose.jpg' alt='关闭' /></div>";
//	      PopBody=PopBody+"<div class='form'><label>用户名：<input id='UIuserName' type='text' size='25' style='width:160px'/> </label><input id='urlkey' type='hidden' /></div>";
//	      PopBody=PopBody+"<div class='form'><label>密　码：<input id='UIpassWord' type='password' size='25' style='width:160px'/> </label></div>";
//	      PopBody=PopBody+"<div class='form'><label>验证码：<input id='UIverify' type='text' size='8' /> <img id='UIcheng' src='VerifyCode.aspx?' alt='' /><a style='color:#4185DA;' href='javascript:UIchanne();'>换一张</a></label></div>";
//	      PopBody=PopBody+"<div class='form' style='text-align:center'><label><input type='image' onclick=UILogin('"+url+"'); style='border:none;' src='/images/K6LoginPost.jpg' alt='' /><a href='javascript:loginAndReg(1,1)' style='color:#D63E0F;text-decoration:none;'>注册成为新用户</a></label></div>";
//	      PopBody=PopBody+"</div>";


	    
	    var pop=document.createElement("div");
	    pop.id='popshow';
	    pop.innerHTML=PopBody;
        document.body.insertBefore(pop,null);
	    GetObject("urlkey").value=url;
	    GetObject("UIuserName").focus();
}

function divClose(){  document.body.removeChild(GetObject("popshow")); }

  document.onkeydown=function(event){
        e = event ? event :(window.event ? window.event : null); 
        if(e.keyCode==13){  
       var element=e.srcElement || e.target;
  
       if(element.id=="UIuserName")
      {
       document.getElementById("UIpassWord").focus();   return false;
      }
      else if(element.id=="UIpassWord")
      {
       document.getElementById("UIverify").focus();   return false;
      }else if(element.id=="UIverify")
      { 
         UILogin(document.getElementById("urlkey").value);  return false;
      }else if(element.id=="content")
      { 
        //发表评论文本域换行
      }else 
      {
       return false;
      }
        }
    }
  function UIchanne()
 {
    objimgVerify=document.getElementById("UIcheng");
    objimgVerify.src="http://www.life5000.com/VerifyCode.aspx?date="+new Date;
 }
 
 function UIUser(url)
 {
 
      var user=GetCookie("UserInfo");
	  if(user==null)
	  {
	      window.location.href=decodeURIComponent(url);
		//UiTree(url);
	  }
	  else
	  {	      
             window.location.href=decodeURIComponent(url);
	  }   
 }
 
  function UILogin(url)   
   { 
    var Username=document.getElementById("UIuserName").value; //用户名
    var Password=document.getElementById("UIpassWord").value; //密码  
    var vCode=document.getElementById("UIverify").value; //验证码  
   
        if(Username.length==0||Password.length==0)    
         {
             alert("请输入用户名或密码！");  
             document.getElementById("UIuserName").focus(); 
             document.getElementById("UIpassWord").value="";
         }
         else
         {
             if(vCode.length==0) 
             { 
                 alert("请输入验证码！");      
                 document.getElementById("UIverify").focus();
             }else
             { 
                 
                 //验证用户名和密码是否正确	 
                 var data='Time='+Date()+'&Username=' + escape(Username) + '&Password=' + escape(Password) + '&vCode=' +escape(vCode);
                 var msg=new ajax().connect("http://www.life5000.com/DivLogin.aspx","get",data);

                 if(msg==1){  alert("验证码错误！"); }
                 else if(msg==2){ alert("用户名或密码错误,请检查！");}
                 else if(msg==3) {alert("此用户名已被禁用,请与管理员联系！");}
		         else{ 
		         
		               SetCookie("UserInfo",escape(msg)+'|'+escape(Username));
		               
		               if(url!="")
		                   {window.location.href=decodeURIComponent(url);}
                       else 
                           {window.location.reload(); }
                     }             
             }
          }        
   }
   
   
   function loginAndReg(login,Url)
   {
    if(login==0)//登录
    {
     window.location.href="/reg.aspx?login=0&&Url="+encodeURIComponent(Url);
    }else//注册
    {
    window.location.href="/reg.aspx?login=1";
    }
   
   }