function PortalHandler(xmlnamespace, url)
{
	this._xmlnamespace = xmlnamespace;
	this._url = url;
};
PortalHandler.prototype.requestLogin = function(id, password, onValid, onLeave, onInvalidId, onInvaliedPassword, onError) 
{
	if(!xmlHttpRequest.isfunction(onValid, "onValid") 
		|| !xmlHttpRequest.isfunction(onLeave, "onLeave") 
		|| !xmlHttpRequest.isfunction(onInvalidId, "onInvalidId") 
		|| !xmlHttpRequest.isfunction(onInvaliedPassword, "onInvaliedPassword") 
		|| !xmlHttpRequest.isfunction(onError, "onError"))
	{
		return;
	}
	this._onValid = onValid;
	this._onLeave = onLeave;
	this._onInvalidId = onInvalidId
	this._onInvaliedPassword = onInvaliedPassword;
	this._onError = onError;
	this._userId = id;
	var paramNames = ["userId", "password"];
	var paramValues = [id, password];
	
	var soapMessage = xmlHttpRequest.createSoap(this._xmlnamespace, "SetLogin", paramNames, paramValues);
	this.responseLoad = this.responseLogin;
	xmlHttpRequest.send(this, this._url, this._xmlnamespace + "/SetLogin", soapMessage);
};
PortalHandler.prototype.requestLogout = function(onComplete) 
{
	var soapMessage = xmlHttpRequest.createSoap(this._xmlnamespace, "SetLogout");
	this.responseLoad = (onComplete == null) ? this.responseLogout : onComplete;
	xmlHttpRequest.send(this, this._url, this._xmlnamespace + "/SetLogout", soapMessage);
};
PortalHandler.prototype.responseLogin = function() 
{
	var response = this.responseText;
	if (response == 'undefined') 
	{
		alert("Sign in service, an error has occurred.\nIn a few minutes, please try again.");
		this._onError.call(this, this._userId);
		return;
	}
	var res = xmlHttpRequest.createDocument(response);	
	
  var temp = (this.GetQueryString("returnUrl") == "") ? this.urlEncode(top.location.href) : this.GetQueryString("returnUrl");	
  
	switch (xmlHttpRequest.getNode(res, 'Flag')) 
	{
	  case "0":
				var status = xmlHttpRequest.getNode(res, 'Agree');
				var loginUser = this.getLoginUser(res, this._userId, status);
				if(loginUser != null)
				{
					this._onValid.call(this, loginUser, temp);
					if(status != 'Y')
					    top.window.location.href = "http://www.t3fun.com/MemberShip/Verification_01.aspx";
				}
			break;
	  case "1": this._onLeave.call(); break;
	  case "2": this._onInvalidId.call(); break;
	  case "3": top.window.location.href = "http://www.t3fun.com/MemberShip/Login.aspx?returnUrl=" + temp; break;
	  case "5": top.window.location.href = "http://www.t3fun.com/MemberShip/Verification_01.aspx"; break; //No Login
	  default : this._onError.call(this, this._userId); break;
	}		
};
PortalHandler.prototype.responseLogout = function() 
{
	var response = this.responseText;
	if (response != 'undefined') 
	    location.href='/';
};
PortalHandler.prototype.getLoginUser = function(res, userId, status) 
{
	alert("please override getLoginUser function");
	return null;
};
PortalHandler.prototype.loginChangeUrl = function(status) 
{
	return (status == 0 || status == -1 || status == 1) ? false : true;
};
PortalHandler.prototype.urlEncode = function(plaintext) 
{
	var SAFECHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()";
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") 
	    {
		    encoded += "%20";
		} 
		else if (SAFECHARS.indexOf(ch) != -1) 
		{
		    encoded += ch;
		} 
		else 
		{
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				// encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}
	return encoded;
};
PortalHandler.prototype.GetQueryString = function(url) 
{
	m_url = location.search;
	m_url = m_url.slice(1);
	var v_result = {};

	v_querys = m_url.split("&");

	for(var i=0; i<v_querys.length; i++)	{
		v_query = v_querys[i].split("=");
		v_result[v_query[0]] = v_query[1];
	}

	if(v_result[url] != null)	{
		return v_result[url];
	}else{
		return false;
	}
};