<!--
/*var arrHost = window.location.host.split ( '.' );
var domain = arrHost[arrHost.length - 2] + '.' + arrHost[arrHost.length - 1];
if ( document.domain != domain )
{
	document.domain = domain;
}*/

function $ ( objId )
{
	return document.getElementById ( objId );
}

// 保存 Cookie
function setCookie ( name, value, domain, expiresTime )
{
	expires = new Date();
	expires.setTime(expires.getTime() + (1000 * 86400 * 365));
	value = String(value).replace(/@/g,"#");
	if (expiresTime != null)
	{
	    document.cookie = name + "=" + escape(value) + "; path=/; domain=" + domain;  
	}
	else
	{
		//document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/; domain=" + domain;  
		document.cookie = name + "=" + escape(value) + "; path=/; domain=" + domain;  
	}
}

// 獲取 Cookie
function getCookie ( 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)
		{
			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;
}

// 清除 Cookie
function delCookie ( name )
{
	var expireNow = new Date();
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/; domain=cmwebgame.com";
}

// 獲取 URL 变量
function getURLVar ( queryVar, url )
{
	var url = url == null ? window.location.href : url;
	var re = new RegExp ( ".*[\?|&]" + queryVar + "=([^&#]+).*", "g" );
	if ( url.match ( re ) )
	{
		var queryVal = url.replace ( re, "$1" );
		return queryVal;
	}
	return '';
}

// 獲取遊戲域名
function getGameHost ()
{
	var host = window.location.host
	return ( 's1.' + host );
}

// 獲取當前域名
function getURLHost ( url )
{
	if ( url == null )
	{
		return window.location.host;
	}

	var re = new RegExp ( "([^\/]*)\/\/([^\/]*)\/.*", "g" );
	if ( url.match ( re ) )
	{
		var urlHost = url.replace ( re, "$1//$2" );
		return urlHost;
	}
	return '';
}

function setSelectOptions ( the_form, the_select, do_check )
{
    var selectObject = document.forms[the_form].elements[the_select];
    var selectCount  = selectObject.length;

    for (var i = 0; i < selectCount; i++) {
        selectObject.options[i].selected = do_check;
    }
    return true;
}

function setChecked ( val, obj, name )
{
	len = obj.elements.length;
	var i=0;
	for( i=0 ; i<len ; i ++ )
	{
		if ( obj.elements[i].name == name )
		{
			obj.elements[i].checked = val;
		}
	}
}

// 在指定對象显示信息
function showMessage ( msg, objName )
{
	var obj;
	if ( typeof (objName) == 'string' )
	{
		obj = document.getElementById ( objName );
	}
	else
	{
		obj = objName;
	}

	process.finish ();

	if ( obj )
	{
		obj.innerHTML = msg;
		if ( obj.className.indexOf ( 'dialog_box' ) >= 0 )
		{
			obj.style.zIndex = gzIndex;
			if ( msg.indexOf ( 'dialog.close' ) < 0 )
			{
				appendCloseButton ( obj );
			}
		}
		try { obj.scrollTop = 0; } catch (e) {}
	}
	else
	{
		showDialogBox ( msg, objName );
	}

	// 解析 Script
	execScript ( msg );
}

// 添加關閉按钮
function appendCloseButton ( obj, closeScript )
{
	var closeButton = document.createElement ( 'div' );
	closeButton.className = 'dialog_box_close';
	closeButton.onclick = function () {
		if ( closeScript != null ) eval ( closeScript );
		dialog.close(this);
	}
	closeButton.onmouseover = function () { this.style.marginTop = '1px'; }
	closeButton.onmouseout = function () { this.style.marginTop = '0px'; }
	obj.appendChild ( closeButton );
}

// 解析 Script
function execScript ( msg )
{
	var _re = /<script[^>]*>([^\x00]+)$/i
	var _msgs = msg.split ( "<\/script>" );
	for ( var _i in _msgs )
	{
		var _strScript;
		if ( _strScript = _msgs[_i].match ( _re ) )
		{
			var _strEval = _strScript[1].replace ( /<!--/, '' );
			try
			{
				eval ( _strEval );
			}
			catch (e) {}
		}
	}
}

// 移除對話框
function removeDialogBox ( objName )
{
	if ( objName == null )
	{
		objName = 'dialog_box' + mask.maskIndex;
	}
	mask.hide ();
	removeItems ( objName );
	gzIndex --;
}

// 移除物件
function removeItems ( objName )
{
	var obj;
	objs = getObjects ( objName );
	for ( var i in objs )
	{
		try
		{
			obj = objs[i];
			obj.parentNode.removeChild ( obj );
		}
		catch (e) {}
	}
}

// 显示提示窗口
var gzIndex = 999;
function showDialogBox ( msg, objId, noClose )
{
	var objClass = 'dialog_box';
	
	if ( objId == null )
	{
		objId = objClass + mask.maskIndex;
	}

	var msgBox = document.getElementById ( objId );
	if ( msgBox )
	{
		msgBox.parentNode.removeChild ( msgBox );
		mask.hide ();
	}
	if ( msg != '' ) mask.show ();
	msgBox = document.createElement ( 'div' );
	msgBox.id = objId;
	msgBox.className = objClass;
	var objBody = document.getElementsByTagName('body').item(0);
	objBody.appendChild ( msgBox );
	msgBox.style.zIndex = gzIndex ++;

	msgBox.innerHTML = msg;

	if ( noClose == null ) noClose = false;
	if ( !noClose && msg.indexOf ( 'dialog.close' ) < 0 )
	{
		appendCloseButton ( msgBox );
	}

	centerDiv ( msgBox );
}

// 字數限制函數
function lengthLimit ( obj, Limit, objShow, objAlert )
{
	var Len = obj.value.length;
	if ( Len > Limit )
	{
		obj.value = obj.value.substring ( 0, Limit );
		Len = Limit;
		showMessage ( String.sprintf ( "字數超出限制, 最多 %d 字!", Limit ), objAlert );
	}
	if ( objShow = document.getElementById ( objShow ) )
	{
		objShow.innerHTML = Len;
	}	
}

// 列表搜索
function clientSearch ( value, obj )
{
	if ( value != '' )
	{
		for ( var i = obj.selectedIndex + 1; i < obj.options.length; i ++ )
		{
			if ( obj.options[i].text.indexOf ( value, 0 ) >= 0 )
			{
				obj.selectedIndex = i;
				return true;
			}		
		}
	}
	obj.selectedIndex = 0;
}

// 列表項目移動
function moveOptions ( objFrom, objTo, errMsg, moveList )
{
	moveList = moveList != null ? moveList : '';
	moveList = ',' + moveList + ',';
	if ( objFrom.selectedIndex == -1 && errMsg != null )
	{
		alert ( errMsg );
	}
	for ( var i = 0; i < objFrom.options.length; i ++ )
	{
		if ( moveList.match ( ',-1,' ) || moveList.match ( ',' + objFrom.options[i].value + ',' ) || objFrom.options[i].selected )
		{
			objTo.options.add ( new Option ( objFrom.options[i].text, objFrom.options[i].value ) );
			objFrom.options[i--] = null;
		}
	}
}

// 設置状态栏
function setStatus ( w, id )
{
	window.status = w;
	return true;
}
function clearStatus ()
{
	window.status = '';
}

// 显示物件
function showItem ( obj, posX, posY )
{
	if ( typeof (obj) == 'string' )
	{
		obj = document.getElementById ( obj );
	}
	try
	{
		obj.style.display = '';
		if ( posX != null ) obj.style.left = posX + 'px';
		if ( posY != null ) obj.style.top = posY + 'px';
		obj.focus ();
	}
	catch (e)
	{
	}
}

// 隐藏物件
function hideItem ( obj )
{
	if ( typeof (obj) == 'string' )
	{
		obj = document.getElementById ( obj );
	}
	try
	{
		obj.style.display = 'none';
	}
	catch (e)
	{
	}	
}

// 交替显示/隐藏物件
function itemShowHide ( obj )
{
	if ( typeof ( obj ) == 'string' )
	{
		obj = document.getElementById ( obj );
	}
	try
	{
		if ( obj.style.display != '' )
		{
			showItem ( obj );
		}
		else
		{
			hideItem ( obj );			
		}
	}
	catch (e)
	{
	}
}

// 獲取错误信息
function getError ( string )
{
	var errorFlag = '<ERROR>';
	if ( string.substring ( 0, errorFlag.length ) == errorFlag )
	{
		return string.substring ( errorFlag.length, string.length );
	}
	else
	{
		return false;
	}
}

// 根据标签獲取物件
function getTag ( obj, tagName, index )
{
	if ( typeof ( obj ) == 'string' )
	{
		obj = document.getElementById ( obj );
	}
	var tags = obj.getElementsByTagName ( tagName );
	if ( index != null )
	{
		return tags[index];
	}
	else
	{
		return tags;
	}
}

// Ajax 通用回调函數
function ajaxCallback ( ret, obj )
{
	var errorMsg = getError ( ret );
	if ( errorMsg )
	{
		if ( !window.onErrorMsg )
		{
			window.onErrorMsg = true;
			showMessage ( errorMsg );
		}
	}
	else if ( ret != '' )
	{
		showMessage ( ret, obj );
	}
}

// 固定 Div
function stayDiv ( obj, top, left )
{
	if ( typeof ( obj ) == 'string' )
	{
		obj = document.getElementById ( obj );
	}
	top = top != null ? top : 0;
	left = left != null ? left : 0;
	obj.style.top = top + document.documentElement.scrollTop + 'px';
	obj.style.left = left + document.documentElement.scrollLeft + 'px';
	setTimeout ( "stayDiv('" + obj.id + "'," + top + "," + left + ")", 100 );
}


// Div 居中
function centerDiv ( obj )
{
	if ( typeof ( obj ) == 'string' )
	{
		obj = document.getElementById ( obj );
	}
	if ( obj )
	{
		obj.style.top = '50%';
		obj.style.left = '50%';
		try
		{
			obj.style.marginLeft = ( 0 - obj.scrollWidth / 2 + document.documentElement.scrollLeft ) + 'px';
			obj.style.marginTop = ( 0 - obj.scrollHeight / 2 + document.documentElement.scrollTop ) + 'px';
		}
		catch (e)
		{
		}
		setTimeout ( "centerDiv('" + obj.id + "')", 100 );
	}
}

// 設置背景色
function setBg ( obj, color )
{
	if ( typeof ( obj ) == 'string' )
	{
		obj = document.getElementById ( obj );
	}
	try
	{
		obj.style.backgroundColor = color;
	}
	catch (e)
	{
	}
}

// html 特殊字符
function htmlchars ( string )
{
	string = string.replace ( /\"/g, '&quot;' );
	string = string.replace ( /\'/g, '&#039;' );

	return string;
}

// 格式化輸出
function sprintf ()
{
	if ( sprintf.arguments.length < 2 )
	{
		return;
	}
	var data = sprintf.arguments[ 0 ];
	for( var k=1; k<sprintf.arguments.length; ++k )
	{
		switch( typeof( sprintf.arguments[ k ] ) )
		{
			case 'string':
			data = data.replace( /%s/, sprintf.arguments[ k ] );
			break;
			case 'number':
			data = data.replace( /%d/, sprintf.arguments[ k ] );
			break;
			case 'boolean':
			data = data.replace( /%b/, sprintf.arguments[ k ] ? 'true' : 'false' );
			break;
			default:
			break;
		}
	}
	return( data );
}

 if ( !String.sprintf ) String.sprintf = sprintf;

// 图层定位
function moveDivHere ( obj, loadingMsg )
{
	try
	{
		if ( obj != null )
		{
			if ( loadingMsg != null ) obj.innerHTML = loadingMsg;

			// 獲取當前鼠标坐标
			var posX = clsMouseCoords.x + 5;
			var posY = clsMouseCoords.y + 5;
			obj.style.left = posX + 'px';
			obj.style.top = posY + 'px';
		}
	}
	catch (e)
	{
	}
}

// 复制URL地址
function setCopy (_sTxt)
{
	if ( navigator.userAgent.toLowerCase().indexOf ( 'ie' ) > -1 )
	{
		clipboardData.setData ( 'Text', _sTxt );
		alert ( '網址“' + _sTxt + '”\n已經複製\n您可以使用Ctrl+V貼到需要的地方' );
	}
	else
	{
		prompt ( '請複製網站地址:', _sTxt ); 
	}
}

// 設為首頁
function setHomePage ( url )
{
	var obj = getSrcElement ();

	if ( document.all )
	{
		obj.style.behavior='url(#default#homepage)';
		obj.setHomePage ( url );
	}
	else
	{
		if ( window.netscape )
		{
			try
			{  
				netscape.security.PrivilegeManager.enablePrivilege ( "UniversalXPConnect" );
			}
			catch (e)  
			{  
				alert ( "您的瀏覽器不支援自動設置首頁，請自行手動設置。");
			}
		}

		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
		prefs.setCharPref ( 'browser.startup.homepage', url );
	}
}

// 加入收藏
function addBookmark ( site, url )
{
	if ( document.all )
	{
		window.external.addFavorite(url,site);
	}
	else if ( window.sidebar )
	{
		window.sidebar.addPanel ( site, url, "" )
	}
	else if ( navigator.userAgent.toLowerCase().indexOf ( 'opera' ) > -1 )
	{
		alert ( '請使用 Ctrl+T 將本頁加入收藏夾' );
	}
	else
	{
		alert ( '請使用 Ctrl+D 將本頁加入收藏夾' );
	}
}

// 语言包支持
function lang ()
{
	var strInput = langPackage[lang.arguments[0]];
	var strParams = '';

	for( var k=1; k < lang.arguments.length; ++k )
	{
		switch( typeof( lang.arguments[ k ] ) )
		{
			case 'string':
				strParams += ", '" + lang.arguments[ k ] + "'";
			break;
			case 'number':
				strParams += ", " + lang.arguments[ k ] + "";
			break;
		}
	}
	if ( strParams != '' )
	{
		strEval = "strOutput = String.sprintf ( strInput" + strParams + " );";
		eval ( strEval );
	}
	else
	{
		strOutput = strInput;
	}	
	return ( strOutput );
}

// 獲取鼠标坐标
function mouseCoords ()
{
	this.x = 0;
	this.y = 0;

	this.getMouseCoords = function ( ev )
	{
		try
		{
			ev = ev || window.event;
			if ( ev.pageX || ev.pageY )
			{
				this.x = ev.pageX;
				this.y = ev.pageY;
			}
			else
			{
				this.x = ev.clientX + document.documentElement.scrollLeft - document.documentElement.clientLeft;
				this.y = ev.clientY + document.documentElement.scrollTop  - document.documentElement.clientTop;
			}
		}
		catch (e)
		{
		}
	}
}

var clsMouseCoords = new mouseCoords ();
document.onmousemove = function ( ev )
{
	clsMouseCoords.getMouseCoords ( ev );
}

// 生成递归列表
function listRecursion ( DataArray, Template, Iconexpand, IconContract )
{
	this.DataArray = DataArray; // 數据數组
	this.Template = Template; // 内容模板
	this.Iconexpand = Iconexpand; // 展開按钮
	this.IconContract = IconContract; // 收缩按钮

	this.List = function ( Parent )
	{
		var ret = '';
		for ( var i = 0; i < this.DataArray.length; i ++ )
		{
			if ( this.DataArray[i][2] == Parent )
			{
				var Sub = this.List ( this.DataArray[i][0] );
				var Content = this.Template;
				re = /%SUB%/g
				if ( !Sub )
				{
					var Icon = this.IconContract;
					Content = Content.replace ( re, '' );
				}
				else
				{
					var Icon = this.Iconexpand;
					Content = Content.replace ( re, Sub );
				}

				re = /%ICON%/g
				Content = Content.replace ( re, Icon );
				re = /%KEY%/g
				Content = Content.replace ( re, i );
				re = /%0%/g
				Content = Content.replace ( re, this.DataArray[i][0] );
				re = /%1%/g
				Content = Content.replace ( re, this.DataArray[i][1] );
				re = /%2%/g
				Content = Content.replace ( re, this.DataArray[i][2] );
				re = /%3%/g
				Content = Content.replace ( re, this.DataArray[i][3] );
				re = /%4%/g
				Content = Content.replace ( re, this.DataArray[i][4] );
				re = /%5%/g
				Content = Content.replace ( re, this.DataArray[i][5] );
				ret += Content
			}
		}
		return ( ret );
	}

	this.expand = function ( Img, Sub, Flag )
	{
		var Img = document.getElementById ( Img );
		var Sub = document.getElementById ( Sub );

		if ( Sub.innerHTML != '' )
		{
			if ( ( Flag == null || Flag == false ) && Img.flag )
			{
				Img.src = "/common/images/icon-expand.gif";
				Img.flag = 0;
				hideItem ( Sub );
			}
			else if ( ( Flag == null || Flag == true ) && !Img.flag )
			{
				Img.src = "/common/images/icon-contract.gif";
				Img.flag = 1;
				showItem ( Sub );
			}
		}
	}
	
	this.expandAll = function ( ImgPrefix, SubPrefix, Flag )
	{
		var i = 0;
		var Img;
		while ( Img = document.getElementById ( ImgPrefix + i ) )
		{
			var Sub = document.getElementById ( SubPrefix + i );
			this.expand ( ImgPrefix + i, SubPrefix + i, Flag );
			i ++;
		}
	}
}

// 更改所有名稱為 objName 的物件的 innerHTML
function setValue ( objName, value )
{
	try
	{
		objs = getObjects ( objName );
		for ( var i in objs )
		{
			objs[i].innerHTML =value;
		}
	}
	catch (e){}
}

// 獲取物件
function getObjects ( objName )
{
	var objs = new Array ();

	if ( idObjs = document.getElementById ( objName ) )
	{
		objs.push ( idObjs );
	}

	if ( document.all ) // IE
	{
		var objTypes = new Array ( 'table', 'tr', 'td', 'div', 'li', 'span', 'a' );
		for ( var tagType in objTypes )
		{
			var typeObjs = document.getElementsByTagName ( objTypes[tagType] );
			for ( var i in typeObjs )
			{
				if ( typeObjs[i].name == objName )
				{
					objs.push ( typeObjs[i] );
				}
			}
		}
	}
	else // 其他瀏覽器
	{
		nameObjs = document.getElementsByName ( objName );
		for ( var i in nameObjs )
		{
			objs.push ( nameObjs[i] );
		}
	}

	return objs;
}

// 獲得焦點
function setFocus ( objName )
{
	var obj;

	var objs = document.getElementsByName ( objName );
	if ( objs.length > 0 )
	{
		obj = objs.item(0);
	}
	else
	{
		obj = document.getElementById ( objName );
	}
	if ( obj )
	{
		obj.focus ();
	}
}

// 高亮物件
function highlight ( obj, highlightClass )
{
	if ( typeof ( obj ) == 'string' )
	{
		obj = document.getElementById ( obj );
	}
	if ( highlightClass == null )
	{
		highlightClass = 'highlight';
	}
	try 
	{
		for ( var i in obj.parentNode.childNodes )
		{
			if ( obj.parentNode.childNodes[i].className != null )
			{
				var re = new RegExp ( "[ ]*" + highlightClass );
				obj.parentNode.childNodes[i].className = obj.parentNode.childNodes[i].className.replace ( re, '' );
			}
		}
		obj.className += ' ' + highlightClass;
	}
	catch ( e ) {}
}

// 载入物件
function objLoader ()
{
	this.timeStamp = null;
	this.loadedJs = '';
	this.loadedCss = '';

	// 载入指定頁面到指定物件
	/*
		loadUrl : 载入頁面的 URL
		targetObj : 目标容器物件 ID
		queryString : 附加送出变量
		loadJs : 附加 Js 文件
		loadingMsg : 载入中提示文字
	*/
	this.get = function ( loadUrl, targetObj, queryString, loadingMsg, callbackFunc, loadJs )
	{
		this.load ( 'GET', loadUrl, targetObj, queryString, loadingMsg, callbackFunc, loadJs );
	}

	this.post = function ( loadUrl, targetObj, queryString, loadingMsg, callbackFunc, loadJs )
	{
		this.refreshCache ();
		this.load ( 'POST', loadUrl, targetObj, queryString, loadingMsg, callbackFunc, loadJs );
	}

	this.load = function ( method, loadUrl, targetObj, queryString, loadingMsg, callbackFunc, loadJs )
	{
		if ( !loadUrl ) return;
		var obj;
		if ( typeof ( targetObj ) == 'string' )
		{
			obj = document.getElementById ( targetObj );
		}
		else
		{
			obj = targetObj;
		}
		if ( obj )
		{
			if ( loadingMsg != null ) obj.innerHTML = loadingMsg;
		}
		if ( callbackFunc == null )
		{
			callbackFunc = ajaxCallback;
		}

		this.getTimeStamp ();
		loadUrl += loadUrl.indexOf ( '?' ) == -1 ? '?' : '&';
		loadUrl += 'timeStamp' + this.timeStamp + '=' + this.timeStamp;

		if ( queryString == null ) queryString = '';
		var clsAjax = new Ajax ( loadUrl, queryString, callbackFunc, targetObj );

		if ( loadJs != null )
		{
			this.loadJs ( loadJs );
		}
		if ( method.toLowerCase () == 'post' )
		{
			clsAjax.post ();
		}
		else
		{
			clsAjax.get ();
		}
	}

	// 载入 Js
	this.loadJs = function ()
	{
		if ( !document.getElementById )
		{
			return;
		}
		for ( var i=0; i < arguments.length; i++ )
		{
			var file = arguments[i];
			var fileref = '';
			if ( this.loadedJs.indexOf ( file ) == -1 )
			{
				fileref = document.createElement ( 'script' );
				fileref.setAttribute ( 'type', 'text/javascript' );
				fileref.setAttribute ( 'src', file );
			}
			if ( fileref != '' )
			{
				document.getElementsByTagName('head').item(0).appendChild ( fileref );
				this.loadedJs += file + ' ';
			}
			return fileref;
		}
	}
	
	// 载入 Css
	this.loadCss = function ()
	{
		if ( !document.getElementById )
		{
			return;
		}
		for ( var i=0; i < arguments.length; i++ )
		{
			var file = arguments[i];
			var fileref = '';
			if ( this.loadedCss.indexOf ( file ) == -1 )
			{
				fileref=document.createElement ( 'link' );
				fileref.setAttribute ( 'rel', 'stylesheet' );
				fileref.setAttribute ( 'type', 'text/css' );
				fileref.setAttribute ( 'href', file );
			}
			if ( fileref != '' )
			{
				document.getElementsByTagName('head').item(0).appendChild ( fileref );
				this.loadedCss += file + ' ';
			}
		}
	}
	
	// 設置時间戳, 用於控制頁面缓存
	this.refreshCache = function ()
	{
		this.timeStamp = this.makeTimeStamp ();
	}


    // 生成時间戳
	this.makeTimeStamp = function ()
	{
		var dateTime = new Date ();
		var timeStamp = dateTime.getTime ();
		if ( typeof ( timeStamp ) == 'undefined' || timeStamp == null )
		{
			timeStamp = Math.floor ( Math.random () * 10000 * 10000 );
		}
		setCookie ( 'timeStamp', timeStamp );
		return timeStamp;
	}
	
	// 獲取缓存時间戳
	this.getTimeStamp = function ()
	{
		this.timeStamp = getCookie ( 'timeStamp' );
		if ( typeof ( this.timeStamp ) == 'undefined' || this.timeStamp == null ) this.timeStamp = this.makeTimeStamp ();
		return this.timeStamp;
	}
}

var loader = new objLoader ();
loader.refreshCache ();

// 遮罩
var noMask = false;
function clsMask ()
{
	this.maskId = 'mask';
	this.maskIndex = 0;
	this.lastHTMLStyle = null;

	this.show = function ()
	{
		if ( noMask ) return false;
		this.maskIndex ++;
		var maskName = this.maskId + this.maskIndex;
		var mask = document.getElementById ( maskName );
		if ( mask )
		{
			mask.parentNode.removeChild ( mask );
		}
		var objBody = document.getElementsByTagName('body').item(0);

		mask = document.createElement ( 'div' );
		mask.id = maskName;
		mask.className = this.maskId;
		mask.style.width = screen.width + 'px';
		mask.style.height = screen.height + 'px';
		mask.style.zIndex = gzIndex ++;

		var maskFrame = document.createElement ( 'iframe' );
		maskFrame.id = maskName + '_frame';
		maskFrame.className = this.maskId;
		maskFrame.style.width = screen.width + 'px';
		maskFrame.style.height = screen.height + 'px';
		maskFrame.style.zIndex = gzIndex ++;

		objBody.appendChild ( maskFrame );
		objBody.appendChild ( mask );

		var objHTML = document.getElementsByTagName('html').item(0);
		if ( this.lastHTMLStyle == null ) this.lastHTMLStyle = objHTML.style.overflow;
		objHTML.style.overflow = 'hidden';
	}

	this.hide = function ()
	{
		if ( noMask ) return false;
		var maskFrame = document.getElementById ( this.maskId + this.maskIndex + '_frame' );
		if ( maskFrame )
		{
			try
			{
				maskFrame.parentNode.removeChild ( maskFrame );
			}
			catch ( e )
			{
			}
		}
		var mask = document.getElementById ( this.maskId + this.maskIndex );
		if ( mask )
		{
			var objHTML = document.getElementsByTagName('html').item(0);
			mask.parentNode.removeChild ( mask );
			this.maskIndex --;
			gzIndex --;
			if ( this.maskIndex == 0 )
			{
				objHTML.style.overflow = this.lastHTMLStyle;
			}
		}
	}
}
var mask = new clsMask ();

var objHTML = document.getElementsByTagName('html').item(0);

// 處理過程提示框
function clsProcess ( dialogName ) 
{
	this.processing = false;
	this.dialogName = dialogName;
	this.chkTimeOut = null;
	this.timeOutSeconds = 15; // 超時秒數
	this.showMask = false;

	if ( this.dialogName == null ) this.dialogName = 'processing_box';

	// 正在處理
	this.start = function ( procMsg )
	{
		if ( !this.processing )
		{
			if ( procMsg == null ) procMsg = '正在處理，請稍候...';
			showDialogBox ( '<table class="box" style="width:300px;height:60px;"><tr><td align="center"><table align="center"><tr><td align="left" class="message"><img alt="" align="absmiddle" src="http://static.9way.cn/football/icons/icon-loading.gif" />&nbsp;&nbsp;' + procMsg + '</td></tr></table></td></tr><table>', this.dialogName, true );
			setFocus ( this.dialogName );
			this.processing = true;
			this.chkTimeOut = setTimeout ( "process.timeOut()", this.timeOutSeconds * 1000 );
		}
	}

	// 處理完成
	this.finish = function ()
	{
		if ( this.processing )
		{
			objContentBody = document.getElementById ( 'body' );
			// objContentBody.scrollTop = 0;
			removeDialogBox ( this.dialogName );
			this.processing = false;			
			clearTimeout ( this.chkTimeOut );
		}
	}

	this.timeOut = function ()
	{
		this.finish ();
		show_alert ( '<center>網路連結超時，請重試！</center>' );
	}
}
var process = new clsProcess ();

// 數值操作类
function clsNumber ( clsName, funcCallback, callbackParams )
{
	this.clsName = clsName;
	this.adding = 0;
	this.interval = null;
	this.callback = funcCallback != null ? funcCallback : null; // 回调函數
	this.callbackParams = callbackParams != null ? callbackParams : null; // 回调函數参數

	this.value = 0;
	this.minValue = 0;
	this.maxValue = -1;

	this.check = function ( obj )
	{
		if ( typeof ( obj ) == 'string' )
		{
			obj = document.getElementById ( obj );
		}
		objValue = Math.round ( obj.value );
		if ( isNaN ( objValue ) || objValue < this.minValue )
		{
			obj.value = this.minValue;
		}
		else if ( this.maxValue >= 0 && objValue > this.maxValue )
		{
			obj.value = this.maxValue;
		}
		this.value = obj.value;
		if ( this.callback != null )
		{
			this.callback ( this.callbackParams );
		}
	}

	this.add = function ( objId, quantity, minValue, maxValue )
	{
		if ( minValue == null ) minValue = this.minValue;
		if ( maxValue == null ) maxValue = this.maxValue;

		obj = document.getElementById ( objId );
		obj.value = Math.round ( obj.value ) + quantity;
		if ( this.adding > 5 )
		{
			obj.value = Math.round ( obj.value / 10 ) * 10;
		}
		if ( this.minValue >= 0 && obj.value <= this.minValue && quantity < 0 )
		{
			obj.value = minValue;
		}
		else if ( maxValue >= 0 && obj.value >= maxValue && quantity > 0 )
		{
			obj.value = maxValue;
		}
		this.value = obj.value;
		this.check ( obj );
	}

	this.startAdd = function ( objId, quantity, minValue, maxValue )
	{
		if ( minValue == null ) minValue = this.minValue;
		if ( maxValue == null ) maxValue = this.maxValue;

		if ( this.adding == 0 )
		{
			this.adding = true;
			this.doAdd ( objId, quantity, minValue, maxValue );
		}
	}

	this.doAdd = function ( objId, quantity, minValue, maxValue )
	{
		if ( this.adding > 0 )
		{
			this.adding ++;

			var addQuantity = Math.max ( 1, Math.floor ( this.adding / 5 ) * 10 ) * quantity;

			this.add ( objId, addQuantity, minValue, maxValue );
			this.interval = setTimeout ( this.clsName + ".doAdd('" + objId + "'," + quantity + "," + minValue + "," + maxValue + ")", 100 );
		}
		else
		{
			clearTimeout ( this.interval );
		}
	}

	this.finishAdd = function ()
	{
		this.adding = 0;
	}
}

var number = new clsNumber ( 'number' );

// 载入完成後调用函數
function callAfterLoaded ( callback, script )
{
	if ( document.all ) // IE 支持
	{
		script.onreadystatechange = function ()
		{
			if ( script.readyState == 'loaded' || script.readyState == 'complete' )
			{
				callback();
			}
		}
	}
	else // Firefox 支持
	{
		script.onload = callback;
	}
}

// 按 td 的 c 属性對查看表格
function table_view_by ( objList, c )
{
	if ( typeof ( objList ) == 'string' )
	{
		objList = document.getElementById ( objList );
	}
	if ( !objList )
	{
		return false;
	}
	var objSubs = objList.getElementsByTagName ( 'td' );
	for ( var i in objSubs )
	{
		try
		{
			var itemCate = objSubs[i].getAttribute ( 'c' );
			if ( itemCate == c )
			{
				objSubs[i].style.display = '';
			}
			else if ( itemCate != null )
			{
				objSubs[i].style.display = 'none';
			}
		}
		catch (e) {}
	}
}

// 随機數
function get_rand ( min, max )
{
	var range = max - min;
	var rand = Math.random();
	return ( min + Math.round ( rand * range ) );
}

// 预载入图片
function pre_load_image ( imgArr )
{
	var preLoads = new Array ();
	for ( var i = 0; i < imgArr.length; i ++ )
	{
		preLoads[i] = new Image ();
		preLoads[i].src = imgArr[i];
	}
}

// 判定數组中是否存在
function in_array ( value, array )
{
	for ( var i in array )
	{
		if ( array[i] == value )
		{
			return true;
		}
	}
	return false;
}

// 显示图片或 Flash
function show_object ( filename, width, height )
{
	var parts = filename.split ( '.' );
	var fileType = parts.pop ();
	var html;

	switch ( fileType )
	{
		case 'swf':
		{
			html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + width + '" height="' + height + '"><param name="movie" value="' + filename + '" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="' + filename + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" width="' + width + '" height="' + height + '"></embed></object>';
			break;
		}
		default :
		{
			html = '<img alt="" src="' + filename + '" />';
		}
	}

	return html;
}

// 限制文本框字數
function maxLength ( obj, length, showAlert )
{
	if ( obj.value.length > length )
	{
		obj.value = obj.value.substring ( 0, length );
		if ( showAlert != null )
		{
			show_alert ( '<center>很抱歉，您最多只能輸入 ' + length + ' 個字符</center>' );
		}
		return false;
	}
}

// 查找 Event 對象
function searchEvent ()
{
	var func = searchEvent.caller;
	while ( func != null )
	{
		var firstArg = func.arguments[0];
		if ( firstArg )
		{
			if ( firstArg.constructor == MouseEvent || firstArg.constructor == Event ) return firstArg;
		}
		func = func.caller;
	}
	return null;
}

function getSrcElement ()
{
	var evt;
	try
	{
		evt = searchEvent ();
		var srcElem = evt.target;
	}
	catch (e)
	{
		evt = window.event;
		var srcElem = evt.srcElement;
	}
	return srcElem;
}

//edit by joe.xu at 2008-5-27
//function showTab ( key )
//{   
//	for ( i = 1; i < 5; i ++ )
//	{
//		var articleLi = document.getElementById ( "li" + i );
//		var articleList = document.getElementById ( "list" + i );
//		var articleMore = document.getElementById ( "moreover" );
//		if ( key == i )
//		{   
//			articleLi.className = "title1";
//			articleList.style.display = "";			
//		}
//		else
//		{
//		    articleLi.className = "title1";
//			articleList.style.display = "none";	
//		}
//	}
//}

//add by joe.xu at 2008-5-27 for LoginBox
function func50zqLoginGame ( form )
{
	if ( form.username.value == '' )
	{
		alert ( '請填寫您的帳號帳號！' );
		setFocus ( "username" );
		return false;
	}
	if ( form.password.value == '' )
	{
		alert ( '請填寫您的登入密碼！' );
		setFocus ( "password" );
		return false;
	}
	
	delCookie('passportTokenCookie');
}


init_login_form = function ( token )
{
	eval ( 'var ret = ' + token + ';' );
	if ( ret && ret.loginFlag )
	{
		//var html = ret.nickname + ' [ <a href="https://passport.9way.cn/logout" onclick="delCookie(\'passportTokenCookie\')">退出</a> ]';
		// 以上内容换成需要显示的 html，注意點退出鏈接時須清除 cookie : 'passportTokenCookie'
		var html = '<ul><li style="padding-left:30px;">' + ret.nickname + '，您好！<br />歡迎回到武林足球經理II<br /></li><li><a href="javascript:;" onclick="select_server();"><img alt="" src="http://static1.zq2.cljoy.com/football/login/login_server.gif" /></a>&nbsp;&nbsp;<a href="https://passport.9way.cn/logout" onclick="delCookie(\'passportTokenCookie\')"><img alt="" src="http://static1.zq2.cljoy.com/football/login/login_out.gif" /></a></li></ul>';
		document.getElementById('div50zqLogin').innerHTML = html;
	}
	else
	{
		//var html = '<form action="https://passport.9way.cn/login" method="post" onsubmit="delCookie(\'passportTokenCookie\')">帳號：<input type="text" name="username" /><br />帳　號：<input type="password" name="password" /><br /><input type="submit" value="登入" /></form>';
		// 以上内容换成需要显示的 html，注意送出登入表單時須清除 cookie : 'passportTokenCookie'
		var html = '<form method="post" id="formPassportLogin" action="https://passport.9way.cn/login" onsubmit="return func50zqLoginGame(this)"><ul><li>帳號：<input name="username" type="text" class="input_txt" /></li><li>密　碼：<input name="password" type="password" class="input_txt" /></li><li style="padding-top:10px;"><input type="hidden" name="_REFERER" value="http://zq2.cljoy.com" /><input name="" type="image" src="http://www.9way.cn/templets/default/zq2_new/images/denglu.gif" border="0" />&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" onclick="this.href=\'https://passport.9way.cn/register?from=http://zq2.cljoy.com\';"  target="_blank" title="立即註冊属於您的球队"><img src="http://www.9way.cn/templets/default/zq2_new/images/zhuce.gif" /></a></li><li style="padding-left:10px;"><a href="https://passport.9way.cn/getpsw" target="_blank">找回密碼</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#">協議說明</a></li></ul></form>';

		document.getElementById('div50zqLogin').innerHTML = html;
	}
	setCookie ( 'passportCmwebgameCookie', token, 'cmwebgame.com' );
}

select_server = function()
{
	document.getElementById('id_select_server').style.display = '';
}


function show_reg(bb, consigneeCode)
{
	var code = "";
	if(consigneeCode == null || consigneeCode === ""){
		code = "cmwebgame";
	}else{
	    code = 	consigneeCode;
	}
	if(bb)
	{
		document.getElementById("win_reg").style.display="";
		document.getElementById("cover_reg").style.width=document.getElementById("sb").scrollWidth+"px"; 
		document.getElementById("cover_reg").style.height=document.getElementById("sb").scrollWidth+"px"; 
		document.getElementById("cover_reg").style.display=""; 
		bb=true;
	    var q;
		q = getURLVar('q')?getURLVar('q'):getCookie("cookie_q");
		var obj = document.getElementById('iframe_select_server_reg');
		if ( obj ) obj.src = "http://passport.cmwebgame.com/reg_open.jsp?consigneeCode=" + code + "&rand=" + new Date().getTime()+"&q="+q;		
	
	}
	else
	{
	   document.getElementById("win_reg").style.display="none";
	   document.getElementById("cover_reg").style.display="none"; 
	   bb=false;
     }
}


