﻿// JScript 文件
function addGameToHistory(gameID,name)
{
    var gameHistory = getCookie("gmHistory");
    if(gameHistory == null || gameHistory == "")
    {
        gameHistory = gameID + "," + name;
        SetCookie("gmHistory",gameHistory);
        return;
    }
    var games = gameHistory.split('|');
    var i;
    for(i = 0; i < games.length; i++)
    {
        if(games[i].split(',')[0] == gameID)
        {
            return;
        }
    }
    
    if(games.length < 4)
    {
        gameHistory += "|" + gameID + "," + name;
        SetCookie("gmHistory",gameHistory);
        return;
    }
    
    gameHistory = gameHistory.substring(gameHistory.indexOf("|") + 1) + "|" + gameID + "," + name;
    SetCookie("gmHistory",gameHistory);
}

function getGameHistory()
{
    var gameHistory = getCookie("gmHistory");
    if(gameHistory == null || gameHistory == "")
    {        
        return "";
    }
    var games = gameHistory.split('|');
    var lineHeight = 24;
    var returnStr = "<table cellpadding='0' border='0' align='left' height='" + lineHeight + "px'><tr>";
    for(var i = games.length - 1; i >= 0; i--)
    {
        returnStr += "<td style='height:" + lineHeight + "px' class='text12' onmouseover=\"this.className='bgdeepcolor text12'\" onmouseout=\"this.className='text12'\" onclick=\"gameClicked(" + games[i].split(',')[0] + ",'" + games[i].split(',')[1] + "')\" align='left'><div class='autoHidden hand' style='width:110px;text-align:center;height:" + lineHeight + "px;'>" + games[i].split(',')[1] + "</div></td>"; 
    }
    returnStr +="</tr></table>";
    return returnStr;
}

function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值
{
    var Days = 30; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";domain=uu898.com;expires=" + exp.toGMTString();
}
function getCookie(name)//读取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;
}


