﻿function isLoginindex(){
	
	var xmlhttp;
	 try{
		xmlhttp=new XMLHttpRequest();
		}
	catch(e){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4){
			if (xmlhttp.status==200){
				var data=xmlhttp.responseText;			
				if(data!=""){
					if(data == "-1")
					{
						document.getElementById("nologin").style.display = "block"
						document.getElementById("inlogin").style.display = "none"
					}
					else
					{
						document.getElementById("nologin").style.display = "none"
						document.getElementById("inlogin").style.display = "block"
						document.getElementById("loginu").innerHTML = data;
					}
				}
			}
		}
	}
	xmlhttp.open("get", "islogin.aspx?rnd="+Math.round(Math.random()*10000), true);
	xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlhttp.send(null);
}

function loginindex(){
	var username = document.getElementById("txt_loginuser").value;
	var pwd = document.getElementById("txt_loginpwd").value;
	if (username == "")
	{
		alert("请输入用户名");
		return;
	}
	if(pwd == "")
	{
		alert("请输入密码");
		return;
	}
	var xmlhttp;
	 try{
		xmlhttp=new XMLHttpRequest();
		}
	catch(e){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4){
			if (xmlhttp.status==200){
				var data=xmlhttp.responseText;			
				if(data!=""){
					if(data == "登录成功")
					{
						document.getElementById("nologin").style.display = "none"
						document.getElementById("inlogin").style.display = "block"
						isLoginindex();
					}
					else
					{
						alert(data);
					}
				}
			}
		}
	}
	xmlhttp.open("get", "login.aspx?username=" + encodeURI(username) + "&pwd=" + encodeURI(pwd) + "&rnd="+Math.round(Math.random()*10000), true);
	xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlhttp.send(null);
}

function loginsubmitindex(oevent) 
        {        
          if(oevent.keyCode==13)
          {
              oevent.returnValue = false;              
		      loginindex();
              return false; 
          }
        }  
		
var isIe=(document.all)?true:false;

function closepwdWindow() 
{ 
 if(document.getElementById('back')!=null) 
 { 
 document.getElementById('back').parentNode.removeChild(document.getElementById('back')); 
 } 
 if(document.getElementById('pwdWindow')!=null) 
 { 
 document.getElementById('pwdWindow').parentNode.removeChild(document.getElementById('pwdWindow')); 
 } 
} 

function changepwdtable()
{
	if (document.getElementById("Table_02").style.display == "none")
	{
		document.getElementById("Table_01").style.display = "none";
		document.getElementById("Table_02").style.display = "block";
	}
	
}
function showgetpwd()
{
	closepwdWindow();
	var bWidth=parseInt(document.documentElement.scrollWidth); 
 	if (document.body.scrollHeight>document.documentElement.scrollHeight)
	{
		var bHeight=parseInt(document.body.scrollHeight); 
	}
	else
	{
		var bHeight=parseInt(document.documentElement.scrollHeight); 
	}
	var back=document.createElement("div"); 
	back.id="back"; 
	var styleStr="top:0px;left:0px;position:absolute;background:#000000;width:"+bWidth+"px;height:" + bHeight + "px;z-index:98;"; 
	styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;"; 
	back.style.cssText=styleStr; 
	document.body.appendChild(back); 
	var mesW=document.createElement("div"); 
	mesW.id="pwdWindow"; 
 	mesW.className="pwdWindow"; 

	var divhtml = " <table id=\"Table_01\" width=\"383\" height=\"229\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
	divhtml += "<tr>";
	divhtml += "	<td colspan=\"3\">";
	divhtml += "		<img src=\"images/forgetpass_01.jpg\" width=\"383\" height=\"46\" alt=\"\" border=\"0\" usemap=\"#Map\"></td>";
	divhtml += "</tr>";
	divhtml += "<tr>";
	divhtml += "	<td  background=\"images/forgetpass_02.jpg\" height=\"119\" colspan=\"3\"><table width=\"100%\" height=\"119\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	divhtml += "	  <tr>";
	divhtml += "	    <td width=\"12%\">&nbsp;</td>";
	divhtml += "	    <td width=\"74%\">请填写您的Email</td>";
	divhtml += "	    <td width=\"14%\">&nbsp;</td>";
	divhtml += "      </tr>";
	divhtml += "	  <tr>";
	divhtml += "	    <td>&nbsp;</td>";
	divhtml += "	    <td> <input type=\"text\" name=\"getpwdmail\" id=\"getpwdmail\"></td>";
	divhtml += "	    <td>&nbsp;</td>";
	divhtml += "      </tr>";
	divhtml += "	  <tr>";
	divhtml += "	    <td>&nbsp;</td>";
	divhtml += "	    <td>登录Email查看账号信息</td>";
	divhtml += "	    <td>&nbsp;</td>";
	divhtml += "     </tr>";
	divhtml += "   </table></td>";
	divhtml += "</tr>";
	divhtml += "<tr>";
	divhtml += "	<td rowspan=\"2\">";
	divhtml += "		<img src=\"images/forgetpass_03.jpg\" width=\"267\" height=\"64\" alt=\"\"></td>";
	divhtml += "	<td>";
	divhtml += "		<a href=\"javascript:getPwdBack()\"><img src=\"images/forgetpass_04.jpg\" width=\"99\" height=\"46\" alt=\"\" border=\"0\" ></a></td>";
	divhtml += "	<td>";
	divhtml += "		<img src=\"images/forgetpass_05.jpg\" width=\"17\" height=\"46\" alt=\"\"></td>";
	divhtml += "</tr>";
	divhtml += "<tr>";
	divhtml += "	<td colspan=\"2\">";
	divhtml += "		<img src=\"images/forgetpass_06.jpg\" width=\"116\" height=\"18\" alt=\"\"></td>";
	divhtml += "</tr>";
	divhtml += "</table>";
	
	divhtml += "<table id=\"Table_02\" width=\"383\" height=\"229\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"display:none;\">";
  	divhtml += "<tr>";
    divhtml += "<td colspan=\"3\"><img src=\"images/forgetpass_01.jpg\" alt=\"\" width=\"383\" height=\"46\" border=\"0\" usemap=\"#Map\"></td>";
  	divhtml += "</tr>";
  	divhtml += "<tr>";
    divhtml += "<td  background=\"images/forgetpass_02.jpg\" height=\"119\" colspan=\"3\"><table width=\"100%\" height=\"119\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    divhtml += "  <tr>";
    divhtml += "    <td width=\"12%\">&nbsp;</td>";
    divhtml += "    <td width=\"74%\">已发送至以下邮箱</td>";
    divhtml += "    <td width=\"14%\">&nbsp;</td>";
    divhtml += "  </tr>";
    divhtml += "  <tr>";
    divhtml += "    <td>&nbsp;</td>";
    divhtml += "    <td><label id=\"msgemail\">abc@abc.com</label></td>";
    divhtml += "    <td>&nbsp;</td>";
    divhtml += "  </tr>";
    divhtml += "  <tr>";
    divhtml += "    <td>&nbsp;</td>";
    divhtml += "    <td>&nbsp;</td>";
    divhtml += "    <td>&nbsp;</td>";
    divhtml += "  </tr>";
    divhtml += "</table></td>";
  	divhtml += "</tr>";
  	divhtml += "<tr>";
    divhtml += "<td rowspan=\"2\"><img src=\"images/forgetpass_03.jpg\" width=\"267\" height=\"64\" alt=\"\"></td>";
    divhtml += "<td><a href=\"javascript:closepwdWindow()\"><img src=\"images/forgetpass_close_bu.jpg\" width=\"99\" height=\"46\" alt=\"\" border=\"0\"></a></td>";
    divhtml += "<td><img src=\"images/forgetpass_05.jpg\" width=\"17\" height=\"46\" alt=\"\"></td>";
 	divhtml += " </tr>";
  	divhtml += "<tr>";
    divhtml += "<td colspan=\"2\"><img src=\"images/forgetpass_06.jpg\" width=\"116\" height=\"18\" alt=\"\"></td>";
  	divhtml += "</tr>";
	divhtml += "</table>";
	
	divhtml += "<map name=\"Map\"><area shape=\"rect\" coords=\"330,2,381,43\" href=\"javascript:closepwdWindow();\"></map>";

	mesW.innerHTML = divhtml;
	styleStr="position:absolute; width:383px; height:229px; left:50%; top:95%; margin-left:-196px;margin-top:-115px;z-index:99;";
 	mesW.style.cssText=styleStr; 
	//document.getElementById("city").style.display = "none";
    //document.getElementById("counter").style.display = "none";
	document.body.appendChild(mesW);
	
}

function getPwdBack()
{
	var Email = document.getElementById("getpwdmail").value;
	if (Email == "")
	{
		alert("请输入电子邮件地址");
		return;
	}
	else
	{
		var len = Email.length;
		var pos1 = Email.indexOf("@");
		var pos2 = Email.indexOf(".");
		if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))  
		{
			alert("请输入正确的电子邮件地址");
			return;
		}
		var xmlhttp;
		 try{
			xmlhttp=new XMLHttpRequest();
			}
		catch(e){
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4){
				if (xmlhttp.status==200){
					var data=xmlhttp.responseText;			
					if(data!=""){
						if(data == "0")
						{
							document.getElementById("msgemail").innerText = Email;							
						}
						else
						{
							document.getElementById("msgemail").innerText = "电子邮箱不存在";
						}
						changepwdtable();
					}
				}
			}
		}
		xmlhttp.open("get", "getPassword.aspx?email=" + encodeURI(Email) + "&rnd="+Math.round(Math.random()*10000), true);
		xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		xmlhttp.send(null);		
	}	
}
