GPassport = function(){

    /*********** Property ************/
    // GPassport success url (Redirect to this url after login success)
    this.SuccessUrl = "";
    // GPassport channel id (daraoke, gmember, ikeyclub)
    this.Channel = "";
    this.LoginText = "Logout";
    this.NotLoginText = "Login";
    this.UserId = "";
    this.CallName = "";
	this.Serviceid
    this.Email = "";
    this.Style = "";
    this.LoginUrl = "http://gpassport.gmember.com/SignIn.aspx";
    this.LogoutUrl = "http://gpassport.gmember.com/SignOut.aspx";
    /************* END ***************/
    
    
    /*********** Method ************/
    this.getLoginCookie = function(name){
        var start = document.cookie.indexOf( name + "=" );
        var len = start + name.length + 1;
        if ((!start) && (name != document.cookie.substring(0, name.length)))
            return "";
        if (start == -1) return "";
        var end = document.cookie.indexOf(";", len);
        if (end == -1) end = document.cookie.length;
        var cookie = document.cookie.substring(len, end);
        if (cookie == null)
            cookie = "";
        return unescape(cookie);
    }
    this.isLogin = function(){
        var userId = this.getLoginCookie("uid");
        var email = this.getLoginCookie("em");
        var gsk = this.getLoginCookie("gsk");
		var si = this.getLoginCookie("si");
		var cn = this.getLoginCookie("cn");
        if (userId != "" && email != "" && gsk != "") // Online
	        return true;
        else // Offline
	        return false;
    }
    this.render = function(){
        var link;
        
        if (this.isLogin()){

			link = '<a href="{0}" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image4\',\'\',\'http://daraoke.gmember.com/images/btn_logout2.gif\',1)"><img src="http://daraoke.gmember.com/images/btn_logout1.gif" name="Image4" width="104" height="30" border="0" id="Image4" /></a>'
           	//link = '<a href="{0}" style="{1}">{2}</a>';
            link = link.replace("{0}", this.LogoutUrl);
            
            link = link.replace("{1}", this.Style);
            link = link.replace("{2}", this.LoginText);
        }
        else{
       		// link = '<a href="{0}" style="{1}">{2}</a>&nbsp;&nbsp; |<a href="http://gpassport.gmember.com/Register.aspx">Register</a>';
			//link = '<a href="{0}" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image24\',\'\',\'images/but_login2.jpg\',1)"><img src="images/but_login1.jpg" name="Image24" width="56" height="21" border="0" id="Image24" onClick="MM_showHideLayers(\'Login\',\'\',\'show\')" /></a>'
			link = '<a href="{0}" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image219\',\'\',\'http://daraoke.gmember.com/images/btn_login2.gif\',1)"><img src="http://daraoke.gmember.com/images/btn_login1.gif" name="Image219" width="104" height="30" border="0" id="Image219" /></a>'
            link = link.replace("{0}", this.LoginUrl);
     
            link = link.replace("{1}", this.Style);
            link = link.replace("{2}", this.NotLoginText);
        }
        document.write(link);
    }
    /************* END ***************/
}

GPassport.Utility = function(){
    this.UTF8Encode = function(text){
        text = text.replace(/\r\n/g,"\n");
        var utftext = "";
        for (var n = 0; n < text.length; n++){
            var c = text.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
        }
        return utftext;
    }
    this.UTF8Decode = function (text){
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < text.length ){
			c = text.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = text.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = text.charCodeAt(i+1);
				c3 = text.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
    this.UrlEncode = function(url){
	    var encoded = escape(this.UTF8Encode(url));
	    return encoded;
    }
}

p = new GPassport();
p.render();
