function trim(str)
{
	return str.replace(/(^\s*)|(\s*$)/g,"");
}
function getCookie(name){
	var datas = document.cookie.split(";");
	for( var i = 0 ; i < datas.length ; i++ )
	{
		var values = trim(datas[i]).split("=",2);
		if( values[0] == name )
			return values[1];
	}
	return null;
}
function removeCookie(name,path,domain)
{
    var strCookie=name+"=";
    if(!path) path="/";
    strCookie+="; path="+path;
    if(domain) {
        strCookie+="; domain="+domain;
    }
    strCookie+="; expires=Thu,1 Jan 1970 00:00:01 UTC";
    if(getCookie(name)){
        document.cookie=strCookie;
    }
}
function getUserLoginURL(){
	var channelurl
	if( top != this && document.referrer != null )
	{
		channelurl = document.referrer;
	}
	else
	{
		channelurl = location.href;
	}
	channelurl = channelurl.replace(/&/g,"|");
	channelurl = channelurl.replace(/"/g,"%22");
	channelurl = channelurl.replace(/'/g,"%27");
	return channelurl;
}
function mbr_init(info) 
{
	var obj = document.getElementById("header.member");
	if( obj )
		obj.innerHTML = mbr_link(info);
	else
		document.write(mbr_link(info));
	setTimeout(this,1000);
}
function mbr_init(info)
{
	_mbr_init(info);
	//if( document.getElementById("header.member") )
	{
		setInterval("_mbr_init('"+info+"')",10000);
	}
}
function _mbr_init(info) 
{
	var obj = document.getElementById("header.member");
	if( obj )
	{
		obj.innerHTML = mbr_link(info);
	}
	else
	{
		document.write(mbr_link(info));
	}
}
function mbr_link(info){
	if( getCookie("otpw")==null ||getCookie("otpw")=="" )
	{
		return '<a href="'+rootpath+'/login/login.jsp?channelurl='+getUserLoginURL()+'" target="_top">'+info+'登入</a>';
	}else{
		return '<a href="'+rootpath+'/login/logout.jsp?channelurl='+getUserLoginURL()+'" target="_top">'+info+'登出</a>';
	}	
}

function getusername()
{
	var value = getCookie("MemberInformation");
	if( value != null )
	{
		value = decodeURI(value);
		return value;
	}
	return null;
}
function mbr_nameArea1(){
	_mbr_nameArea1();
	//if( document.getElementById("header.member.shwonamearea") )
	{
		setInterval("_mbr_nameArea1()",10000);
	}
}
function _mbr_nameArea1(){
	var content='',info = null;
	try
	{
		info = getusername();
	}
	catch(e)
	{
		info = getCookie("DoubleCheckUid");
	}
	if( info == null )
	{
	}
	/*else if( info.length > 10)
	{
		content+='<span title="Hi! '+info+'">Hi! '+info.substring(0,10)+'...</span>';
	}*/
	else
	{
		content+='Hi! '+info;
	}
	var obj = document.getElementById("header.member.shwonamearea");
	if( obj )
		obj.innerHTML = content;
	else
		document.write(content);
}
function mbr_showArea(type){
	if( type == 1 )
	{
		_mbr_showArea1();
		//if( document.getElementById("header.member.shwoarea") )
		{
			setInterval("_mbr_showArea1()",10000);
		}
	}
	else
	{
		_mbr_showArea();
		//if( document.getElementById("header.member.shwoarea") )
		{
			setInterval("_mbr_showArea()",10000);
		}
	}
}
function _mbr_showArea1(){
	var content ='';
	if( getCookie("otpw")==null ||getCookie("otpw")=="" ){
		content +='<a href="'+rootpath+'/login/login.jsp?channelurl='+getUserLoginURL()+'" target="_top">登入</a>';
	}else{
		content +='<a href="'+rootpath+'/login/logout.jsp?channelurl='+getUserLoginURL()+'" target="_top">登出</a>';
	}
	var obj = document.getElementById("header.member.shwoarea");
	if( obj )
		obj.innerHTML = content;
	else
		document.write(content);
}
function _mbr_showArea(type){
	var content ='';
	if( getCookie("otpw")==null ||getCookie("otpw")=="" ){
		content +='<a href="'+rootpath+'/login/login.jsp?channelurl='+getUserLoginURL()+'" target="_top">登入</a>';
	}else{
		content +='<a href="'+rootpath+'/login/logout.jsp?channelurl='+getUserLoginURL()+'" target="_top">登出</a>';
	}
	var obj = document.getElementById("header.member.shwoarea");
	if( obj )
		obj.innerHTML = content;
	else
		document.write(content);
}