﻿var Contents="<div id='unlogin'><form name='login' method='post' onsubmit='postvalue(this)' ><div class='title'></div><div class='inputs'><p>  用户名： <input type='text' name='UserName' value='请输入您的用户名' onFocus='clearValue(this)'></p><p>  密　码： <input type='password' name='PassWord'></p></div><div class='loginbt'><input type='submit' title='登录' value='' ></div><div class='mark'><span><a href='http://www.hhwww.net/passport.aspx'>个人注册</a></span> <span><a href='http://www.hhwww.net/userreg.aspx'>企业注册</a></span> <span><a href='http://www.hhwww.net/forgot.aspx'>忘记密码</a></span></div></form></div><div id='logined'><div class='title'></div><div style='margin:5px;'><p> 欢迎您：“{UserName}” &nbsp;&nbsp;<a href='http://www.hhwww.net/signOut.aspx'>安全退出</a></p></div><div class='mark'><span><a href='http://www.hhwww.net/UserCenter'>用户中心</a></span> <span><a href='http://www.hhwww.net/UserCenter/Company/Trade.aspx'>发布供求信息</a></span></div></div>" ;
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");
            //alert('piN0YWbcGowlK1XqzdQPSSAmKIr4jc3Hy+IGqbsx17GI2SAsQMm9mVSPOGlSQeO35YeIiD4J/4WU/dITT9M+Dt//+uqb9Mzh');
            //alert(re.$1);
		    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(); 

