﻿function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值
{
	var temp;
    var Days = 30; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
	if (name == "youxi")
	{
		if (getCookie(name) != "")
		{
			temp = getCookie(name) + ","
			temp = temp.replace(value + ",","");
			temp = temp.substring(0,temp.length-1);
			if (temp.split(',').length == 10)
			{
				temp = value + "," + temp.substring(0,temp.lastIndexOf(','));
			}else{
				if (temp != "")
				{
					temp = value + "," + temp;	
				}else{
					temp = value ;	
				}
			}
		}else{
			temp = value;
		}
		document.cookie = name + "="+ escape (temp) + ";expires=" + exp.toGMTString() + ";path=/;domain=olxyx.com";
	}else if (name == "shoucang"){
		if (getCookie(name) != "")
		{
			temp = getCookie(name) + ","
			temp = temp.replace(value + ",","");
			temp = temp.substring(0,temp.length-1);
			if (temp != "")
			{
				temp = value + "," + temp;	
			}else{
				temp = value ;	
			}
		}else{
			temp = value;
		}
		document.cookie = name + "="+ escape (temp) + ";expires=" + exp.toGMTString() + ";path=/;domain=olxyx.com";
		alert('收藏成功!');
	}else{
		document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString() + ";path=/;domain=olxyx.com";
	}
}
function getCookie(name)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return "";

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
function showCookie()//显示已浏览过小游戏
{
	if (getCookie('youxi') == "")
	{
		return false;
	}
	var arr = new Array();
	var arr1 = new Array();
	arr = getCookie('youxi').split(",");
	if (arr.length > 0)
	{
		for (i=0;i<arr.length ;i++ )
		{
			arr1 = arr[i].split("|");
			document.write('<div id="showcookie_' + i + '"><li><a title="' + arr1[0] + '" href="' + arr1[1] + '" target="_blank">' + arr1[0].substring(0,9) + '</a><a href="javascript:void(0)" title="删除该游戏浏览记录" onclick="delShow('+ i +',\''+ arr1[0] +'|' + arr1[1] + '\');"><font color="#FF0000">×</font></a></li></div>');
		}
	}	
}
function delShow(s,name)//删除已浏览过小游戏
{
	var temp;
	var Days = 30; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
	//document.getElementById("showcookie_" + s).innerHTML = '';
	var div = document.getElementById("showcookie_" + s);   
	div.parentNode.removeChild(div);   //删除
	temp = getCookie('youxi') + ","
	temp = temp.replace(name + ",","");
	if (temp != "")
	{
		temp = temp.substring(0,temp.length-1);		
	}
	document.cookie = "youxi="+ escape (temp) + ";expires=" + exp.toGMTString() + ";path=/;domain=olxyx.com";
}

//----------------------------------------------------------------------------------------------------
function showtitle()
{
	var state = document.getElementsByName("state");
	if (getCookie('url') !="")
	{
		document.getElementById("url").value = getCookie('url');
	}else{
		document.getElementById("url").value = "http://www.baidu.com";
	}
	if (getCookie('title') !="")
	{
		document.getElementById("title").value = getCookie('title');
	}else{
		document.getElementById("title").value = "百度搜索";
	}
	if (getCookie('state') == "0" || getCookie('state') == "")
	{
		state[1].checked = true;
	}else{
		top.document.title = getCookie('title');
		state[0].checked = true;
		document.getElementById("switch").style.display = "";
		document.getElementById("switch_link").href = getCookie('url');
		document.getElementById("switch_link").title = getCookie('title');
	}
}
