	var ssoWebBasePath = "https://sso.woniu.com/";
	var cookieNameLoginErrMsg = "loginErrorMessage";

	// Remember current URL.
	function rememberMe(){
		referrer = encodeURIComponent(document.location);
		//console.log("Referrer=" + document.location);
		//console.log("Referrer=" + referrer);
		setCookieValue("referrer", referrer);
	}
	
	function adjustContentFrameSize(){
		var contentFrame = document.getElementById("content");
		//newSize = window.frames["content"].document.body.scrollHeight;
		//console.log(contentFrame.body);
		if(contentFrame.contentWindow.document != null && contentFrame.contentWindow.document != undefined){
			newSize = contentFrame.contentWindow.document.body.scrollHeight;
			//console.log(newSize);
			if(newSize < 540){
				newSize = 540;
			}
			contentFrame.height = newSize;
		}
	}


	function retrieveCipherCoordinate(imageId, index, path){
		if(index == 1){
			this.document.getElementById(imageId).src = path + "Cipher.jpg?userSessionKey=cipherCoordinate1&gossip=" + Math.random() + 1;
		}
		if(index == 2){
			this.document.getElementById(imageId).src = path + "Cipher.jpg?userSessionKey=cipherCoordinate2&gossip=" + Math.random() + 2;
		}
		if(index == 3){
			this.document.getElementById(imageId).src = path + "Cipher.jpg?userSessionKey=cipherCoordinate3&gossip=" + Math.random() + 3;
		}
		if(index == 4){
			this.document.getElementById(imageId).src = path + "Cipher.jpg?userSessionKey=cipherCoordinate4&gossip=" + Math.random() + 4;
		}
		if(index == 5){
			this.document.getElementById(imageId).src = path + "Cipher.jpg?userSessionKey=cipherCoordinate5&gossip=" + Math.random() + 5;
		}
		if(index == 6){
			this.document.getElementById(imageId).src = path + "Cipher.jpg?userSessionKey=cipherCoordinate6&gossip=" + Math.random() + 6;
		}
		//console.log(index);
	}

	var isCoordinateGot = new Array();
	isCoordinateGot[0] = false;
	isCoordinateGot[1] = false;
	isCoordinateGot[2] = false;

	function retrieveCipherCoordinateOnce(imageId, index, path){
		if(isCoordinateGot[index - 1] == false){
			if(index == 1){
				this.document.getElementById(imageId).src = path + "Cipher.jpg?userSessionKey=cipherCoordinate1&gossip=1";
			}
			if(index == 2){
				this.document.getElementById(imageId).src = path + "Cipher.jpg?userSessionKey=cipherCoordinate2&gossip=2";
			}
			if(index == 3){
				this.document.getElementById(imageId).src = path + "Cipher.jpg?userSessionKey=cipherCoordinate3&gossip=3";
			}
		}
		isCoordinateGot[index - 1] = true;
		//console.log(index);
	}


	function retrieveValTicket(imageId, path){
		if(imageId == null || imageId.length == 0){
			imageId = "kaptcha";
		}
		this.document.getElementById(imageId).src = path + "Kaptcha.jpg?gossip=" + Math.random();
		var codeInput = document.getElementById("valCode");
		if(codeInput != null && codeInput != undefined){
			codeInput.value = "";
			codeInput.focus();
		}
	}

	var isTicketGot = false;
	function retrieveValTicketOnce(imageId, path){
		if(isTicketGot == false){
			if(imageId == null || imageId.length == 0){
				imageId = "kaptcha";
			}
			this.document.getElementById(imageId).src = path + "Kaptcha.jpg";
		}
		isTicketGot = true;
	}


	function getUrlParamValue(name) {
		// 如果链接没有参数，或者链接中不存在我们要获取的参数，直接返回空
		if(location.href.indexOf("?")==-1 || location.href.indexOf(name+'=')==-1) {
			return '';
		}
		 
		// 获取链接中参数部分
		var queryString = location.href.substring(location.href.indexOf("?")+1);
		 
		// 分离参数对 ?key=value&key2=value2
		var parameters = queryString.split("&");
		 
		var pos, paraName, paraValue;
		for(var i=0; i<parameters.length; i++)	{
			// 获取等号位置
			pos = parameters[i].indexOf('=');
			if(pos == -1) { continue; }
			 
			// 获取name 和 value
			paraName = parameters[i].substring(0, pos);
			paraValue = parameters[i].substring(pos + 1);
			 
			// 如果查询的name等于当前name，就返回当前值，同时，将链接中的+号还原成空格
			if(paraName == name) {
				return unescape(paraValue.replace(/\+/g, " "));
			}
		}
		return '';
	}


	// Highlight menu item by id.
	function highlightMenu(menuId){
		for(i=1;i<10;i++){
			var menuItem = document.getElementById("menu" + i);
			//console.log("menu" + i + " " + menuItem);
			if(menuItem != null){
				//console.log(menuId);
				if(menuId == i){
					//console.log("on" + i);
					menuItem.style.background = "url(http://res.woniu.com/images/kk.gif) repeat-y";
				} else {
					//console.log("off" + i);
					menuItem.style.background = "url() repeat-y";
				}
				menuItem = null;
			}

		}
	}

	// tabId : ID of tab.
	// tabs  : Count of all tabs.
	function highlightTab(tabId, tabs){
		for(i=0; i<tabs; i++){
			var tab = document.getElementById("tab" + i);
			//console.log("Tab is " + tab);
			if(tab != null){
				if(tabId == i ){
					//console.log("on " + i );
					tab.style.background = "url(http://res.woniu.com/images/huang.gif) repeat-x";
				} else {
					//console.log("off " + i);
					tab.style.background = "url(http://res.woniu.com/images/center1.jpg) repeat-x";
				}
				tab = null;
			}

		}
	}

//TODO
	function hightlightSingTab(tabid){
		var tab = document.getElementById(tabid);
		tab.style.background = "url(../../images/huang.gif) repeat-y";
		//console.log("##");
	}


	function showRealmsByIsp(selected){
		//console.log(selected.value);
		//console.log(realms);
		DWRUtil.removeAllOptions('gameRealmId');
		DWRUtil.addOptions('gameRealmId', ["请选择分区"]);
		
		var showRealms = new Array();
		for(i=0;i<realms.length;i++){
			var realm = realms[i];
			//console.log("  Realm: " + realm[0]);	
			if(realm != undefined){
				if(realm[1] == selected.value && gameid_online!=null && realm[3] == gameid_online){
					//console.log("    Add New ");
					showRealms.push(realm);
				}
			}
		}
		DWRUtil.addOptions('gameRealmId',showRealms, 0, 2);  
	}

var GameTypes = new Array();
GameTypes[1] = "航海世纪";
GameTypes[2] = "PP球";
GameTypes[3] = "机甲世纪";
GameTypes[4] = "舞街区";
GameTypes[5] = "超级武林大富翁";

/**
 * 根据url参数Url中参数获取游戏名称或id
 * @param urlParam Url中参数名称
 * @param str 'id' -- 返回游戏id;'name' -- 返回游戏名称
 * @return
 */
function getGameIdOrName(urlParam,str){
	var gameId = getUrlParamValue(urlParam);
	if (str == 'id'){
		return gameId;
	}
	var gameName = '';
	if (gameId == 1){
		gameName = '航海世纪';
	}else if (gameId == 3){
		gameName = '机甲世纪';
	}else if (gameId == 4){
		gameName = '舞街区';
	}else if (gameId == 6){
		gameName = '机甲世纪II';
	}else if (gameId == 7){
		gameName = '天子';
	}else if (gameId == 8){
		gameName = '龙战';
	}else if (gameId == 9){
		gameName = '英雄之城';
	}
	if (str == 'name'){
		return gameName;
	}
}

