function getCookieVal(offset){
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1) endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function getCookie(name){
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 setCookie(name,value){
var exp = new Date();
exp.setTime (exp.getTime()+3600000000);
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + "; path=/";
}

function history_show(){
var history_info="";
if(getCookie("history_info")!="undefined" && getCookie("history_info")!=null){
history_info=getCookie("history_info");
}
var content="";
if(history_info!=""){
history_arg=history_info.split("|");
var i;
for(i=0;i<=5;i++){
if(history_arg[i]!=null && history_arg[i]!=""){
var wlink=history_arg[i].split("+");
if(wlink[0]!="" && wlink[0]!=null){
  content+=("<div onmouseover=\"showx("+i+")\" onmouseout=\"offx("+i+")\"><a href='"+wlink[1]+"'>"+wlink[0]+"</a><input id='fclose"+i+"' type='button' class='off' onclick=\"delCookie('"+wlink[0]+"')\"/></div></div>");
}
}
}
content+=("<span onclick=\"delAllCookie('history_info')\" >清空记录</span>");
document.getElementById("showhistory").innerHTML=content;
}
else{
document.getElementById("showhistory").innerHTML="<span>暂无玩过的游戏记录！</span>";
}
}

function glog(itemname,itemurl)
{
var wlink=itemname+"+"+itemurl+"|";
var old_info="";
if(getCookie("history_info")!=null){
old_info=getCookie("history_info");
}
var old_link1=old_info.split("|");
var newcookie=wlink;
var length=old_link1.length;
   if(old_info.indexOf(itemname)==-1)
  {
     for(var j=0;length<=6?j<=length-1:j<=5;j++)
	{
	  if(j==length-1||j==5)
      {
       newcookie=newcookie+old_link1[j];
      }
      else
      {
       newcookie=newcookie+old_link1[j]+'|';
      }
    }
	setCookie("history_info",newcookie);
  }
}
function delAllCookie(name){
    var exp = new Date();
    exp.setTime (exp.getTime()+3600000000);
    document.cookie = name + "=;expires=" + exp.toGMTString() + "; path=/";
	history_show();
}
function delCookie(name){
  var history_info=getCookie("history_info");
  var old_link1=history_info.split("|");
  var length=old_link1.length;
  var new_info="";
  if(history_info.indexOf(name)!=-1)
  {
	  for(var j=0;length<=6?j<=length-1:j<=5;j++)
	{
	  if(old_link1[j].indexOf(name)==-1)
		{
	       if(j==length-1||j==5)
           {
            new_info=new_info+old_link1[j];
           }
           else
           {
            new_info=new_info+old_link1[j]+'|';
           }
		}
    }
	setCookie("history_info",new_info);
	history_show()
  }
}
function showx(i){
	document.getElementById("fclose"+i).className="on";
}
function offx(i){
	document.getElementById("fclose"+i).className="off";
}
