﻿/*
<div class="member03a">用户:<input type="text" size="10" class="input" />
密码:<input name="text" type="text" size="10" class="input" /></div>
<div class="member03b"><img src="http://images.hhwww.net/zjypw/button_dl.gif" /></div>
*/
var Contents ="<form name='login' id='login' method='post' onsubmit='postvalue(this)' >";
Contents += "<div id='unlogin' class=\"member03\">";
Contents += "<div class=\"member03a\">用户:<input name='UserName' type=\"text\" size=\"10\" class=\"input\" />";
Contents += "密码:<input type='password' name='PassWord' size=\"10\" class=\"input\" /></div>";
Contents += "<div class=\"member03b\"><input style='border:0px;background:url(http://images.hhwww.net/zjypw/button_dl.gif); height:20px; width:54px;' type='submit' value='' /></div>";
Contents += "</div>";
Contents += "<div id='logined' class=\"member03\">";
Contents += "<div class=\"member03a\">";
Contents += "欢迎您：“{UserName}” &nbsp;&nbsp;";
Contents += "<a href='http://www.hhwww.net/signOut.aspx'>安全退出</a>&nbsp;";
Contents += "<a href='http://www.hhwww.net/UserCenter'>用户中心</a>";
Contents += "</div>";
Contents += "</div>";
Contents += "</form>";

function clearValue(obj){ obj.value ='' ; }
function postvalue(form){ 
    form.action ='http://www.hhwww.net/scripts/LoginHandler.aspx';    
    var tar ='test' ;
    form.target = tar;
    window.open ('', tar, 'height=500, width=1000 toolbar=yes,menubar=yes,scrollbars=yes, resizable=yes,location=yes, status=yes'); 
    window.location = window.location.href; 
}
function ShowLogined()					                    
{					 			                            
    var LoginedDiv = document.getElementById("logined");	
    var UnLoginedDiv = document.getElementById("unlogin");	
    if(IsLogined)						                    
    {							                            
        LoginedDiv.style.display = "block";			    
        UnLoginedDiv.style.display = "none";		        
    }else							                        
    {							                            
        LoginedDiv.style.display = "none";                
        UnLoginedDiv.style.display = "block";		        
    }							                            
}								                            
    var IntervalTime = 200;                 
    var MaxTry = 40;                        
    var TryCount = 0;                       
    var IsLogined = false;                  
    var IntervalID = -1;                    
	function TryReadCookie()                
	{								        
	    TryCount++;							
	    if(TryCount<MaxTry)                 
	    {								    
            GetUserCookie();					
            if(IsLogined)						        
            {							                
                window.clearInterval(IntervalID);		
                ShowLogined();	    
            }							                    
	    }								                    
	    else							                    
	    {								                    
		    window.clearInterval(IntervalID);			    
	    }								                
	}								                    
	function GetUserCookie()					        
	{								                    
	    var Psp=getCookie("Psp");	            
	    if(Psp!="" && Psp !=null)					        
	    {                                    
		    IsLogined = true;
		    var obj = document.getElementById("logined");
		    obj.innerHTML = obj.innerHTML.replace("{UserName}" ,GetUserName(Psp));
	    }                                               
	}								                    
	if(!IsLogined)							            
	{								                    
		IntervalID = window.setInterval(TryReadCookie,IntervalTime);
	}

function PostRequestData(URL,data)
{ 
    try{
            var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	        xmlhttp.Open("POST",URL, false); 
	        xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=utf-8"); 
	        xmlhttp.SetRequestHeader ("SOAPAction","http://tempuri.org/DecryptUserName"); 
	        try { 
		        xmlhttp.Send(data); 
		        var result = xmlhttp.status;
	        } 
	        catch(ex) { 
		        return("0" + ex.description + "|" + ex.number); 
	        } 
	        if(result==200) { 
		        return(xmlhttp.responseText); 
	        }
	        xmlhttp = null; 
	}catch (e)
	{
	  return null; 
	}
} 

function getCookie(name)
{
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	 if(arr != null) return unescape(arr[2]); return null;
}

function GetUserName(value){ 
	var url = 'http://www.hhwww.net/Psp.asmx'; 
	var data ; 
	var r; 
	data = '<?xml version="1.0" encoding="utf-8"?>'; 
	data = data + '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">'; 
	data = data + '<soap12:Body>'; 
	data = data + '<DecryptUserName  xmlns="http://tempuri.org/">'; 
	data = data + '<str>'+value+'</str>'; 
	data = data + '</DecryptUserName>'; 
	data = data + '</soap12:Body>'; 
	data = data + '</soap12:Envelope>'; 
	r=PostRequestData(url,data); 
	return GetUserNameByXml(r);
} 

function GetUserNameByXml(xmlstr)
{
	var regExp=/<DecryptUserNameResult>(\w*)<\/DecryptUserNameResult>/;
		regExp.exec(xmlstr);
		var UserName=RegExp.$1;
		return UserName;
}
document.write(Contents);
GetUserCookie(); 
ShowLogined(); 
