function GetCookieVal(offset)
//获得Cookie解码后的值
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name, value)
//设定Cookie值
{
var expdate = new Date("December   31,   3666"); 
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie = name + "=" + escape (value) + ";domain=.xuanxuan.com;expires="   + expdate.toGMTString() + ";path=/";
}
function DelCookie(name)
//删除Cookie
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
function GetCookie(name)
//获得Cookie的原始值
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function setHistory(type,id,title){
  if (GetCookie("his") == null)
  {
      SetCookie("his",type+"|"+id+"|"+title);
  } else {
     if (GetCookie("his").indexOf(type+"|"+id+"|"+title)<0)
     {
	    
		var historystr = GetCookie("his");
		var historyarray = historystr.split(":");
		var num= historyarray.length;
		var newhis="";
		if (num>17){num=17;}
		for (i=0;i< num;i++ )
		{
			var row = historyarray[i].split("|");
			newhis= newhis+":"+row[0]+"|"+row[1]+"|"+row[2]+"|";
		}
		newhis=type+"|"+id+"|"+title+"|"+newhis;
		SetCookie("his",newhis);
     } else {
		var historystr = GetCookie("his");
		var historyarray = historystr.split(":");
		var num= historyarray.length;
		var newhis="";
		for (i=0;i< num;i++ )
		{
			if (historyarray[i] != type+"|"+id+"|"+title+"|")
			{
			   var row = historyarray[i].split("|");
			   newhis= newhis+":"+row[0]+"|"+row[1]+"|"+row[2]+"|";
			}

		}
		newhis=type+"|"+id+"|"+title+"|"+newhis;
		SetCookie("his",newhis);
	 
	 }
	   
  }

}

function listHistroy(){
  var histr="";
  if (GetCookie("his") == null)
  {
      return null;
  } else {
    var historystr = GetCookie("his");
	var historyarray = historystr.split(":");
	for (i=0;i< historyarray.length;i++ )
	{
	    var row = historyarray[i].split("|");
		histr=histr+"<li><a href=http://www.xuanxuan.com/games/game"+row[1]+".html target=_blank>"+row[2]+"</a></li>";
	}
	return histr;
  }
}

function histroyblock(){
 if (GetCookie("his") != null) {
  document.write("<div id=\"hislist\">最近玩过的小游戏<ul id=\"hislist\">");
  document.write(listHistroy());
  document.write("</ul></div>");
  }
}

