setCookie = function ( name, value, domain, noExpire )
{
	
	var expires = new Date();
	expires.setTime(expires.getTime() + (1000 * 86400 * 365));
	var stringExpires = expires.toGMTString ();
	
	
	value = String(value).replace(/@/g,"#");
	
	var cookieObj = name + "=" + escape(value) + "; path=/";
	//var cookieObj = name + "=" + escape(value) + "; expires=" + stringExpires +  "; path=/";
	if(domain != null && domain){
		cookieObj += ";domain=" + domain;
	}
	document.cookie = cookieObj;
//	alert(document.cookie);
};

getCookie = function(name) {
	cookie_name = name + "=";
	cookie_length = document.cookie.length;
	cookie_begin = 0;

	while (cookie_begin < cookie_length) {
		value_begin = cookie_begin + cookie_name.length;
		if (document.cookie.substring(cookie_begin, value_begin) == cookie_name) {
//			alert(document.cookie);
			var value_end = document.cookie.indexOf(";", value_begin);
			if (value_end == -1) {
				value_end = cookie_length;
			}
			var v = unescape(document.cookie.substring(value_begin, value_end));
			//alert(v);
			v = String(v).replace(/#/g,"@");
			//alert(v);
			return v;
		}
		cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1;
		if (cookie_begin == 0) {
			break;
		}
	}
	return null;
};

function postFormforpassportTop(){

	var inputbox = document.getElementById('top_username');

	if( inputbox.value == '' ){

		alert('請輸入用戶名');

		return false;

	}
	else
	{
		//if(!/^\w{1,20}$/.test(inputbox.value))
		//{
		//	alert("帳號包含非法字元");
		//	return false;
		//}
	}

	var inputbox = document.getElementById('top_password');

	if( inputbox.value == '' ){

		alert('請輸入密碼');

		return false;

	}

	delCookie('passportCmwebgameCookie');

	var frm = document.getElementById('formPassportTopLogin');

	frm.submit();

};

delCookie = function(name) {
	var expireNow = new Date();
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT"
			+ "; path=/; domain=cmwebgame.com";
};

showTopHtml = function() {
	var html = '';
	html += '<style>';
	html += '.header { background:url(../images/9wee_topbg.gif) repeat-x; width:100%; height:100px;}';
	html += '.header_box { width:1000px; margin:0 auto;}';
	html += '.header_left { float:left; width:450px; height:78px; background:url(../images/9wee_topbgt.gif) no-repeat right;}';
	html += '.header_logo { float:left; width:195px; padding-top:16px;}';
	html += '.header_about { float:left; color:#676363; height:28px; line-height:22px; background:url(../images/9wee_www.gif) no-repeat left bottom; padding-top:27px;}';
	html += '.header_right { float:left; width:550px; line-height:22px;}';
	html += '.header_right a { padding:0 4px;}';
	html += '.header_bottom { float:left; width:1000px; line-height:28px;}';
	html += '.header_bottom a { padding:0 4px;}';
	html += '.header_url { width:544px; color:#858484; padding:8px 0; text-align:right; padding-right:6px;}';
	html += '.header_position {float:left;padding-left:50px; width:400px; color:#181818;}';
	html += '.header_login {float:right;padding-right:50px; width:500px; color:#181818;}';
	html += '.header_login li { float:left; padding-left:4px;}';
	html += '.header_input {border:1px solid #E8E3E9;  background:url(../images/9wee_in_bg.gif) repeat-x top; padding:2px;}';
	html += '.nav { float:left;width:550px; height:78px; padding-top:12px; background:url() repeat-x top;}';
	html += '.nav_box { width:550px; margin:0 auto;}';
	html += '.nav_box li { float:right;}';
	html += '.nav_box a{ display:block; width:70px; height:63px; text-decoration:none; text-align:center; font-weight:bold; font-size:14px; line-height:35px;}';
	html += '.nav_on a:link,.nav_on a:visited{color:#4d4b4b; background:url(../images/9wee_nav_c.gif) no-repeat bottom center;}';
	html += '.nav_on a:hover,.nav_on a:active{color:#920000; text-decoration:none;}';
	html += '.nav_off a:link,.nav_off a:visited{color:#FFF; background:url(../images/9wee_nav_a.gif) no-repeat left 1px; }';
	html += '.nav_off a:hover,.nav_off a:active{color:#FFF; background:url(../images/9wee_nav_d.gif) no-repeat left top; text-decoration:none;}';
	html += '.nav_off a:link,.nav_off a:visited{color:#FFF; background:url(../images/9wee_nav_a.gif) no-repeat left 1px; }';
	html += '.nav_off a:hover,.nav_off a:active{color:#FFF; background:url(../images/9wee_nav_d.gif) no-repeat left top; text-decoration:none;}';
	html += '.nav_on1 a:link, .nav_on1 a:visited {color:#4d4b4b;background-image: url(../images/top1_2.gif);background-repeat: no-repeat;background-position: center bottom;}';
	html += '.nav_on1 a:hover, .nav_on1 a:active {color:#920000;text-decoration:none;background-image: url(../images/top1_1.gif) no-repeat left 1px;}';
	html += '.nav_off1 a:link, .nav_off1 a:visited {color:#FFF;background:url(../images/top1_1.gif) no-repeat left 1px;}';
	html += '.nav_off1 a:hover, .nav_off1 a:active {color:#FFF;background:url(../images/top1_2.gif) no-repeat left top;text-decoration:none;}';
	html += '.nav_on2 a:link, .nav_on2 a:visited {color:#4d4b4b;background-image: url(../images/top2_2.gif);background-repeat: no-repeat;background-position: center bottom;}';
	html += '.nav_on2 a:hover, .nav_on2 a:active {color:#920000;text-decoration:none;}';
	html += '.nav_off2 a:link, .nav_off2 a:visited {color:#FFF;background:url(../images/top2_1.gif) no-repeat left 1px;}';
	html += '.nav_off2 a:hover, .nav_off2 a:active {color:#FFF;background:url(../images/top2_2.gif) no-repeat left top;text-decoration:none;}';
	html += '.nav_on3 a:link, .nav_on3 a:visited {color:#4d4b4b;background-image: url(../images/top3_2.gif);background-repeat: no-repeat;background-position: center bottom;}';
	html += '.nav_on3 a:hover, .nav_on3 a:active {color:#920000;text-decoration:none;}';
	html += '.nav_off3 a:link, .nav_off3 a:visited {color:#FFF;background:url(../images/top3_1.gif) no-repeat left 1px;}';
	html += '.nav_off3 a:hover, .nav_off3 a:active {color:#FFF;background:url(../images/top3_2.gif) no-repeat left top;text-decoration:none;}';
	html += '.nav_on4 a:link, .nav_on4 a:visited {color:#4d4b4b;background-image: url(../images/top4_2.gif);background-repeat: no-repeat;background-position: center bottom;}';
	html += '.nav_on4 a:hover, .nav_on4 a:active {color:#920000;text-decoration:none;}';
	html += '.nav_off4 a:link, .nav_off4 a:visited {color:#FFF;background:url(../images/top4_1.gif) no-repeat left 1px;}';
	html += '.nav_off4 a:hover, .nav_off4 a:active {color:#FFF;background:url(../images/top4_2.gif) no-repeat left top;text-decoration:none;}';
	html += '.nav_on5 a:link, .nav_on5 a:visited {color:#4d4b4b;background-image: url(../images/top5_2.gif);background-repeat: no-repeat;background-position: center bottom;}';
	html += '.nav_on5 a:hover, .nav_on5 a:active {color:#920000;text-decoration:none;}';
	html += '.nav_off5 a:link, .nav_off5 a:visited {color:#FFF;background:url(../images/top5_1.gif) no-repeat left 1px;}';
	html += '.nav_off5 a:hover, .nav_off5 a:active {color:#FFF;background:url(../images/top5_2.gif) no-repeat left top;text-decoration:none;}';
	html += '.nav_on6 a:link, .nav_on6 a:visited {color:#4d4b4b;background-image: url(../images/top6_2.gif);background-repeat: no-repeat;background-position: center bottom;}';
	html += '.nav_on6 a:hover, .nav_on6 a:active {color:#920000;text-decoration:none;}';
	html += '.nav_off6 a:link, .nav_off6 a:visited {color:#FFF;background:url(../images/top6_1.gif) no-repeat left 1px;}';
	html += '.nav_off6 a:hover, .nav_off6 a:active {color:#FFF;background:url(../images/top6_2.gif) no-repeat left top;text-decoration:none;}';
	html += '.nav_on7 a:link, .nav_on7 a:visited {color:#4d4b4b;background-image: url(../images/top7_2.gif);background-repeat: no-repeat;background-position: center bottom;}';
	html += '.nav_on7 a:hover, .nav_on7 a:active {color:#920000;text-decoration:none;}';
	html += '.nav_off7 a:link, .nav_off7 a:visited {color:#FFF;background:url(../images/top7_1.gif) no-repeat left 1px;}';
	html += '.nav_off7 a:hover, .nav_off7 a:active {color:#FFF;background:url(../images/top7_2.gif) no-repeat left top;text-decoration:none;}';
	html += '.nav_on8 a:link, .nav_on8 a:visited {color:#4d4b4b;background-image: url(../images/top8_2.gif);background-repeat: no-repeat;background-position: center bottom;}';
	html += '.nav_on8 a:hover, .nav_on8 a:active {color:#920000;text-decoration:none;}';
	html += '.nav_off8 a:link, .nav_off8 a:visited {color:#FFF;background:url(../images/top8_1.gif) no-repeat left 1px;}';
	html += '.nav_off8 a:hover, .nav_off8 a:active {color:#FFF;background:url(../images/top8_2.gif) no-repeat left top;text-decoration:none;}';
	html += '.nav_on9 a:link, .nav_on9 a:visited {color:#4d4b4b;background-image: url(../images/top9_2.gif);background-repeat: no-repeat;background-position: center bottom;}';
	html += '.nav_on9 a:hover, .nav_on9 a:active {color:#920000;text-decoration:none;}';
	html += '.nav_off9 a:link, .nav_off9 a:visited {color:#FFF;background:url(../images/top9_1.gif) no-repeat left 1px;}';
	html += '.nav_off9 a:hover, .nav_off9 a:active {color:#FFF;background:url(../images/top9_2.gif) no-repeat left top;text-decoration:none;}';
	html += '</style>';

	html += '	<div class="header">' ;
	html += '		<div class="header_box">' ;
	html += '			<div class="header_left">' ;
	html += '				<div class="header_logo"><a href="#"><img src="../images/logo02.gif" border="0" alt="育駿科技首頁" /></a></div>' ;
	html += '				<div class="header_about">玩網頁遊戲 交知心朋友</div>' ;
	html += '			</div>' ;
	html += '	<div class="nav">' ;
	html += '		<div class="nav_box">' ;
	html += '			<ul id="top_9wee_navi">' ;
	html += '				<li class="nav_off9" id="top_9wee_navi_8"><a href="http://bms.cmwebgame.com" target="_self" alt="客服中心">&nbsp;</a></li>' ;
	html += '				<li class="nav_off8" id="top_9wee_navi_7"><a href="http://forum.cmwebgame.com" target="_self" alt="火爆論壇">&nbsp;</a></li>' ;
	//html += '				<li class="nav_off7" id="top_9wee_navi_6"><a href="#" target="_self"></a></li>' ;
	html += '				<li class="nav_off6" id="top_9wee_navi_5"><a href="#" target="_self" alt="公會聯盟">&nbsp;</a></li>' ;
	html += '				<li class="nav_off5" id="top_9wee_navi_4"><a href="../member/index" alt="用戶中心">&nbsp;</a></li>' ;
	html += '				<li class="nav_off4" id="top_9wee_navi_3"><a href="../order/order_index" alt="儲值專區">&nbsp;</a></li>' ;
	//html += '				<li class="nav_off3" id="top_9wee_navi_2"><a href="#"></a></li>' ;
	html += '				<li class="nav_off2" id="top_9wee_navi_1"><a href="/" alt="遊戲中心">&nbsp;</a></li>' ;
	html += '				<li class="nav_off1" id="top_9wee_navi_0"><a href="http://www.cmwebgame.com" alt="網站首頁">&nbsp;</a></li>' ;
	html += '			</ul>' ;
	html += '		</div>' ;
	html += '	</div>' ;
	html += '			<div class="header_bottom">' ;
//	html += '				<div class="header_url shi_a"><span style="color:#ff7c00">旗下網站：</span> <a href="http://sg.cmwebgame.com" target="_self">武林三國</a></div>' ;
	html += '				<div class="header_position" id="your_position">' ;
	html += '				您的位置：育駿科技首頁 >> ' ;
	html += '				</div>' ;
	html += '				<div class="header_login" id="login_form">' ;
	html += '					用戶資料載入，請稍候...' ;
	html += '				</div>' ;
	html += '			</div>' ;
	html += '		</div>' ;
	html += '	</div>' ;
//	html += '	<div class="nav">';
//	html += '		<div class="nav_box">';
//	html += '			<ul id="top_9wee_navi">';
//	html += '				<li class="nav_off" id="top_9wee_navi_0"><a href="/">網站首頁</a></li>';
//	html += '				<li class="nav_off" id="top_9wee_navi_7"><a href="#">遊戲中心</a></li>';
//	html += '				<li class="nav_off" id="top_9wee_navi_1"><a href="../member/index">用戶中心</a></li>';
//	html += '				<li class="nav_off" id="top_9wee_navi_2"><a href="../order/order_index">儲值專區</a></li>';
//	html += '				<li class="nav_off" id="top_9wee_navi_3"><a href="#" target="_self">客服中心</a></li>';
//	html += '				<li class="nav_off" id="top_9wee_navi_4"><a href="#" target="_self">推廣聯盟</a></li>';
//	html += '				<li class="nav_off" id="top_9wee_navi_5"><a href="#" target="_self">聯合運營</a></li>';
//	html += '				<li class="nav_off" id="top_9wee_navi_6"><a href="http://forum.cmwebgame.com">遊戲論壇</a></li>';
//	html += '			</ul>';
//	html += '		</div>';
//	html += '	</div>';
	document.write(html);

	if (typeof (topNaviIndex) == 'undefined')
		topNaviIndex = 0;
	topNaviIndex = parseInt(topNaviIndex);
	if ( !isNaN ( topNaviIndex ) )
	{
		// var naviMenus = document.getElementById( 'top_9wee_navi' ).getElementsByTagName ( 'li' );
		// naviMenus[topNaviIndex].className = 'nav_on';
		var navObj = document.getElementById ( 'top_9wee_navi_' + topNaviIndex );
		var temp = topNaviIndex +1;
		if ( navObj ) navObj.className = 'nav_on' + temp;
		if(temp==1){
			document.getElementById('your_position').innerHTML = '您的位置：育駿科技首頁 >> 網站首頁';
		}else if(temp==2){
			document.getElementById('your_position').innerHTML = '您的位置：育駿科技首頁 >> 游戲中心';
		}else if(temp==4){
		    document.getElementById('your_position').innerHTML = '您的位置：育駿科技首頁 >> 儲值專區';
	    }else if(temp==5){
	        document.getElementById('your_position').innerHTML = '您的位置：育駿科技首頁 >> 用戶中心';
        }else if(temp==6){
	        document.getElementById('your_position').innerHTML = '您的位置：育駿科技首頁 >> 公會聯盟';
        }else if(temp==8){
	        document.getElementById('your_position').innerHTML = '您的位置：育駿科技首頁 >> 火爆論壇';
        }else if(temp==9){
	        document.getElementById('your_position').innerHTML = '您的位置：育駿科技首頁 >> 客服中心';
	    }	
	}
}

initLoginForm = function(token) {
	eval('var ret = ' + token + ';');
	var html = '';
	html += '<span style="float: right; margin-right: 5px">';

	if (ret && ret.loginFlag) {
		//if (typeof (passportLogoutUrl) != 'string') {
			passportLogoutUrl = '../j_spring_security_logout';
		//}

		html += '歡迎您，<span style="color:#ff6600">' + ret.nickname + '</span>   ';
		html += '<a href="profile" target="_self">填寫資料</a>|';
		html += '<a href="profile?step=2" target="_self">修改郵箱</a>|';
		html += '<a href="profile?step=3" target="_self">修改密碼</a>|';
		html += '<a href="profile?step=4" target="_self" style="color:red">密碼保護</a>|';
		html += '<a href="../j_spring_security_logout" onclick="this.href = \'' + passportLogoutUrl + '\'; delCookie(\'passportCmwebgameCookie\')">退出帳號</a>';
	} else {
		html += '<form action="/j_spring_security_check" method="post" name="formPassportTopLogin" id="formPassportTopLogin" onsubmit="postFormforpassportTop();return false;">';
		html += '	<ul>';
		html += '		<li>育駿帳號：</li>';
		html += '		<li><input type="text" class="header_input" name="j_username" id="top_username" value="" style="width:100px; height:14px;" /></li>';
		html += '		<li>密碼：</li>';
		html += '		<li><input type="password" class="header_input" name="j_password" id="top_password" value="" style="width:100px; height:14px;" /></li>';
		html += '		<li class="c"><input name="" type="image" src="../images/9wee_login.gif"></li>';
		html += '		<li><a href="../register.jsp" target="_self">註冊帳號</a>|<a href="../getpassword.jsp" target="_self">找回密碼</a></li>';
		html += '	</ul>';
		html += '</form>';
	}
	html += '</span>';

	document.getElementById('login_form').innerHTML = html;
	setCookie('passportCmwebgameCookie', token, 'cmwebgame.com');
};

showTopHtml();
var passportCmwebgameCookie = getCookie('passportCmwebgameCookie');
//alert(passportCmwebgameCookie);
if (passportCmwebgameCookie) {
	initLoginForm(passportCmwebgameCookie);
} else {
	document
			.write('<script type="text/javascript" src="showJsUser?callback=initLoginForm"><' + '/script>');
	//initLoginForm(passportUserToken);
}