﻿var logdivstring,regdivstring;
var globaluid=0;
var globaluname="";

function EmailCheck(v)
{
	if (v.match(/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,4}$/))
		return true;
	else
		return false;
}

function UserNameCheck(v)
{
	if (checkStrLen(v)<4 || checkStrLen(v)>15)
		return false;
	else
		return true;
}

function PasswordCheck(v)
{
	if (checkStrLen(v)<6 || checkStrLen(v)>16)
		return false;
	else
		return true;
}

function readCookie(name){
	var cookieValue = "";
	var s_search = name + "=";
	if(document.cookie.length > 0){
		offset = document.cookie.indexOf(s_search);
		if (offset != -1){
			offset += s_search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}

function writeCookie(name, value, hours){
  var expire = "";
  if(hours != null)  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire ;
}


var logdivstring2="<div class=\"logcon\"><div class=\"close\" onclick=\"closeBotmLayer()\"><img border=\"0\" src=\"images/close.gif\" /></div><div class=\"title\">登录</div><div class=\"logname\"><ul><li class=\"txt\">电子邮箱</li><li><input type=\"text\" name=\"email\" id=\"email\" /></li></ul></div><div class=\"logpwd\"><ul><li class=\"txt\">登录密码</li><li><input type=\"password\" name=\"loginpwd\" id=\"loginpwd\" /></li><li class=\"getpwd\"><span onclick='getpwdfun2()'>忘记密码</span></li></ul></div><div class=\"logcook\"><ul><li>登录有效期</li><li class=\"selcook\"><input type=\"radio\" value=\"365\" name=\"dlyxq\" id=\"dlyxq\"  />1年&nbsp;<input type=\"radio\"  name=\"dlyxq\" id=\"dlyxq\" value=\"30\" checked=\"checked\"/>1月&nbsp;<input type=\"radio\"  name=\"dlyxq\" id=\"dlyxq\" value=\"1\" />1天&nbsp;<input type=\"radio\"  name=\"dlyxq\" id=\"dlyxq\" value=\"0\" />无</li></ul></div><div class=\"but\" onClick=\"divlogin2()\">登 录</div><div class=\"bottom\"><div class=\"wblog\" onclick=\"sinawblog()\"></div><div class=\"rlink\"><span  class=\"hand\"  onclick=\"freereg2()\">免费注册</span></div></div></div>";
var regdivstring2="<div class=\"regcon\"><div class=\"close\" onclick=\"closeBotmLayer()\"><img border=\"0\"  src=\"images/close.gif\" /></div><div class=\"title\">注册</div><div class=\"regdiv\"><ul><li class=\"txt\">注册邮箱</li><li><input type=\"text\" name=\"regemail\" id=\"regemail\" class=\"inputtxt\" maxlength=\"100\"  onblur=\"NowCheck2(1)\">&nbsp;<span id=\"emailright\"></span><span id=\"emailerr\"></span></li></ul></div><div class=\"regdiv\"><ul><li class=\"txt\">设置密码</li><li><input type=\"password\" name=\"regloginpwd\" id=\"regloginpwd\" class=\"inputtxt\" maxlength=\"25\" ></li></ul></div><div class=\"regdiv\"><ul><li class=\"txt\">确认密码</li><li><input type=\"password\" name=\"regloginpwd2\" id=\"regloginpwd2\" class=\"inputtxt\" maxlength=\"25\"></li></ul></div><div class=\"but\" onClick=\"divregister2()\">注 册</div><div class=\"bottom\"><div class=\"wblog\" onclick=\"sinawblog()\"></div><div class=\"rlink\"><span  class=\"hand\"  onclick=\"gologin2()\">直接登录</span></div></div></div>";

var getpwdstring2="<div class=\"logcon\"><div class=\"close\" onclick=\"closeBotmLayer()\"><img border=\"0\" src=\"images/close.gif\" /></div><div class=\"title\">找回密码</div><div class=\"getpwdin\"><ul><li class=\"txt\">注册邮箱</li><li><input type=\"text\" name=\"getemail\" id=\"getemail\" /></li></ul></div><div class=\"but2\" onClick=\"getpwdsend()\">发送密码至邮箱</div><div class=\"bottom\"><div class=\"rlink\"><span class=\"hand\" onclick=\"freereg2()\">注册</span>&nbsp;&nbsp;|&nbsp;&nbsp;<span onclick=\"gologin2()\">登录</span></span></div></div>";

var yonghumingalert="<div class='alertlayer'><div class='close'><div class='txt'>提示</div><div class='img'><img border='0' onclick='closeLayer()' src='images/close.gif' /></div></div><div class='con'><ul><li class='img'><img src='images/alert-no.gif' /></li><li class='txt'><p>请先到<a href='myconfig.asp'>我的设置</a>中激活主页</p></li></ul></div></div>";
var globallogtype=0; //0底部检查　1顶部登录　2点击商城
var globalgourl="";
var xmlHttp2;
try
{
	xmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
	try
	{
		xmlHttp2= new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlHttp2 = new XMLHttpRequest();
		}
		catch(e) {}
	}
}



function openBotmLayer(showc)
	 {
		var arrayPageSize   = getPageSize2();//调用getPageSize()函数
		var arrayPageScroll = getPageScroll2();//调用getPageScroll()函数
		document.getElementById("botmurlcheckdiv").innerHTML=showc;
		document.getElementById("botmurlcheckdiv").style.position = "absolute";		
		document.getElementById("botmurlcheckdiv").style.zIndex = 99;
		
		document.getElementById("botmurlcheckbackdiv").style.position = "absolute";
		document.getElementById("botmurlcheckbackdiv").style.width = "100%";
		document.getElementById("botmurlcheckbackdiv").style.height = (arrayPageSize[1] + 35 + 'px');
		document.getElementById("botmurlcheckbackdiv").style.zIndex = 98;
		document.getElementById("botmurlcheckbackdiv").style.top = 0;
		document.getElementById("botmurlcheckbackdiv").style.left = 0;
		document.getElementById("botmurlcheckbackdiv").style.filter = "alpha(opacity=50)";
		document.getElementById("botmurlcheckbackdiv").style.opacity = 0.5;
		document.getElementById("botmurlcheckbackdiv").style.background = "#CCCCCC";
		document.getElementById("botmurlcheckbackdiv").style.display = "";
		document.getElementById("botmurlcheckdiv").style.display = "";
		
		document.getElementById("botmurlcheckdiv").style.top = arrayPageScroll[1] + (arrayPageSize[3] - document.getElementById("botmurlcheckdiv").offsetHeight) / 2-50 + 'px';
		document.getElementById("botmurlcheckdiv").style.left = (arrayPageSize[0] - document.getElementById("botmurlcheckdiv").offsetWidth) / 2 -30 + 'px';
	}
	
     //获取滚动条的高度
     function getPageScroll2()
	 {
      var yScroll;
      if (self.pageYOffset)
	  {
       yScroll = self.pageYOffset;
      }
	  else if (document.documentElement && document.documentElement.scrollTop)
	  {
       yScroll = document.documentElement.scrollTop;
      }
	   else if (document.body)
	  {
       yScroll = document.body.scrollTop;
      }

      arrayPageScroll = new Array('',yScroll);
      return arrayPageScroll;
     }

     //获取页面实际大小

     function getPageSize2()
	 {
      var xScroll,yScroll;
      if (window.innerHeight && window.scrollMaxY)
	  {
       xScroll = document.body.scrollWidth;
       yScroll = window.innerHeight + window.scrollMaxY;
      }
	  else if (document.body.scrollHeight > document.body.offsetHeight)
	  {
       xScroll = document.body.scrollWidth;
       yScroll = document.body.scrollHeight;
      }
	  else
	  {
       xScroll = document.body.offsetWidth;
       yScroll = document.body.offsetHeight;
      }

      var windowWidth,windowHeight;
      //var pageHeight,pageWidth;
      if (self.innerHeight)
	  {
       windowWidth = self.innerWidth;
       windowHeight = self.innerHeight;
      }
	  else if (document.documentElement && document.documentElement.clientHeight)
	  {
       windowWidth = document.documentElement.clientWidth;
       windowHeight = document.documentElement.clientHeight;
      }
	  else if (document.body)
	  {
       windowWidth = document.body.clientWidth;
       windowHeight = document.body.clientHeight;
      }

      var pageWidth,pageHeight;
      if(yScroll < windowHeight)
	  {
       pageHeight = windowHeight;
      }
	  else
	  {
       pageHeight = yScroll;
      }
      if(xScroll < windowWidth)
	  {
       pageWidth = windowWidth;
      }
	  else
	  {
	   pageWidth = xScroll;
      }
      arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
      return arrayPageSize;
     }

     //关闭弹出层
     function closeBotmLayer()
	 {
      document.getElementById("botmurlcheckbackdiv").style.display = "none";
      document.getElementById("botmurlcheckdiv").style.display = "none";
	  document.getElementById("botmurlcheckdiv").innerHTML="";
	  globallogtype=0;
	  globalgourl="";
      return false;
     }
	 
	function getDivCon2()
	{
		if (xmlHttp2.readyState == 4) {
			var response = xmlHttp2.responseText;
			try{			
					
			 if (response.indexOf("headshowname")>0)
			 {
				document.getElementById("botmurlcheckdiv").innerHTML=response;
				
				if (globalgourl!="")
				{					
				
					location.href=globalgourl;					
					return false;
				}				
				
				globaluid=document.getElementById("e_id").value;
				globaluname=document.getElementById("e_name").value;
				if (globallogtype==0)
				botmurlcheck();
				if (globallogtype==2)
				{				
				gowebpage();
				}
				showHeadContent();
				
				closeBotmLayer();
				
			 }
			 else
			 {
				document.getElementById("botmurlcheckdiv").innerHTML=response;
			 }
			}catch(exception){}
		}	
	}


	function divlogin2()
	{
	try
	{		
		if (document.getElementById("email").value=="")
		{
			alert("请输入电子邮箱名!");
			document.getElementById("email").focus();
			return false;
		}
		
		if (document.getElementById("loginpwd").value=="")
		{
			alert("请输入登录密码!");
			document.getElementById("loginpwd").focus();
			return false;
		}
		if (EmailCheck(document.getElementById("email").value)==false)
		{
			alert("邮箱格式不正确！");
			document.getElementById("email").focus();
			return false;
		}
		
		var url = "divdaren.asp?naction=log&ltype=1&email=" +encodeURI(escape(document.getElementById("email").value))+"&loginpwd="+encodeURI(escape(document.getElementById("loginpwd").value))+"&dlyxq="+document.getElementById("dlyxq").value;
		//window.open(url);
		//return false;
		xmlHttp2.open("GET", url, true);
		xmlHttp2.onreadystatechange = getDivCon2;
		xmlHttp2.send(null);	
		
	}
	catch(exception){}
	}



	function divregister2()
	{
	try
	{
		if (document.getElementById("regemail").value=="")
			{
				alert("请输入电子邮箱名!");
				document.getElementById("regemail").focus();
				return false;
			}		
			
			if (document.getElementById("regloginpwd").value=="")
			{
				alert("请输入登录密码!");
				document.getElementById("regloginpwd").focus();
				return false;
			}
			if (document.getElementById("regloginpwd2").value=="")
			{
				alert("请输入确认密码!");
				document.getElementById("regloginpwd2").focus();
				return false;
			}
			if (document.getElementById("regloginpwd2").value!=document.getElementById("regloginpwd").value)
			{
				alert("二密码不一致!");
				document.getElementById("regloginpwd2").focus();
				return false;
			}
			
			if (document.getElementById("emailright").innerHTML=="")
			{
				alert("电子邮箱格式不正确或者已经注册过!");
				document.getElementById("regemail").focus();
				return false;
			}
			
		
		
		var url = "divdaren.asp?naction=reg&ltype=1&regemail=" +encodeURI(escape(document.getElementById("regemail").value))+"&regloginpwd="+encodeURI(escape(document.getElementById("regloginpwd").value));
		
		xmlHttp2.open("GET", url, true);
		xmlHttp2.onreadystatechange = getDivCon2;
		xmlHttp2.send(null);	
		
	}
	catch(exception){}
	}



	function NowCheck2(type)
	{
		if (type==1)
		{
			if (document.getElementById("regemail").value=="")
				return false;
			if (EmailCheck(document.getElementById("regemail").value)==false)
			{
				alert("请输入有效的Email！");
				document.getElementById("regemail").focus();
				return false;
			}
			
		}
		
		if (type==2)
		{
			if (document.getElementById("regusername").value=="")
				return false;
			if (UserNameCheck(document.getElementById("regusername").value)==false)
			{
				alert("请输入有效的用户名！");
				document.getElementById("regusername").focus();
				return false;
			}
		}
		
		if (type==3)
		{
			if (document.getElementById("mobile").value=="")
				return false;
			if (MobileCheck(document.getElementById("mobile").value)==false)
			{
				alert("请输入有效的手机号！");
				document.getElementById("mobile").focus();
				return false;
			}
		}
		var url = "checkuser.asp?checktype="+type+"&email="+encodeURI(escape(document.getElementById("regemail").value));
		xmlHttp2.open("GET", url, true);
		xmlHttp2.onreadystatechange = showCon2;
		xmlHttp2.send(null);	
	}
	
	function showCon2()
	{
		if (xmlHttp2.readyState == 4) {
		var response = xmlHttp2.responseText;
		try{			
			if (response==1)
			{
				document.getElementById("emailright").innerHTML="<img src='images/alert-suc.gif' />";
				document.getElementById("emailerr").innerHTML="";
			}
			if (response==2)
			{
				document.getElementById("emailright").innerHTML="";
				document.getElementById("emailerr").innerHTML="<img src='images/alert-err.gif' /><font color='red'>该邮箱已经注册过！</font><br/>";
			}
			if (response==3)
			{
				document.getElementById("usernameright").innerHTML="<img src='images/alert-suc.gif' />";
				document.getElementById("usernameerr").innerHTML="";
			}
			if (response==4)
			{
				document.getElementById("usernameright").innerHTML="";
				document.getElementById("usernameerr").innerHTML="<img src='images/alert-err.gif' /><font color='red'>该用户名已经存在！</font><br/>";
			}
			if (response==5)
			{
				document.getElementById("mobileright").innerHTML="<img src='images/alert-suc.gif' />";
				document.getElementById("mobileerr").innerHTML="";
			}
			if (response==6)
			{
				document.getElementById("mobileright").innerHTML="";
				document.getElementById("mobileerr").innerHTML="<img src='images/alert-err.gif' /><font color='red'>该手机号已经存在！</font><br/>";
			}
		}catch(exception){}
	}	
	}

function freereg2()
{
	document.getElementById("botmurlcheckdiv").innerHTML=regdivstring2;
}

function gologin2()
{
	document.getElementById("botmurlcheckdiv").innerHTML=logdivstring2;
}

function globallog(gourl)
{
	
	globallogtype=1;
	globalgourl=gourl;
	openBotmLayer(logdivstring2);
}

function globalreg()
{
	globallogtype=1;
	openBotmLayer(regdivstring2);
	
}

function showHeadContent()
{
	document.getElementById("globalheaddiv").innerHTML="<span>" + document.getElementById("headshowname").value + "！</span> | <a href=\"logout.asp\">退出</a>";
	
}



function getpwdfun2()
{
	globallogtype=6;
	openBotmLayer(getpwdstring2);
}

function getpwdsend()
{
	if (document.getElementById("getemail").value=="")
	{
		alert("请输入电子邮箱名!");
		document.getElementById("getemail").focus();
		return false;
	}
	
	if (EmailCheck(document.getElementById("getemail").value)==false)
	{
		alert("邮箱格式不正确！");
		document.getElementById("getemail").focus();
		return false;
	}
		
	var url = "getpwd.asp?email=" +encodeURI(escape(document.getElementById("getemail").value));
	xmlHttp2.open("GET", url, true);
	xmlHttp2.onreadystatechange = getPwdCon;
	xmlHttp2.send(null);	
}

function getPwdCon()
{
	if (xmlHttp2.readyState == 4) {
		var response = xmlHttp2.responseText;
		try{			
			if (globallogtype==6)
			{
			document.getElementById("botmurlcheckdiv").innerHTML=response;
			setTimeout(closeBotmLayer,2000);
			}
			else
			{
			document.getElementById("logdiv").innerHTML=response;
			setTimeout(closeLayer,2000);
			}
			
			//globallog();
		}catch(exception){}
	}	
}

function sinawblog()
{
	location.href="sinawblog.asp";
}
