var Next_url='';
window.onerror = killErrors;
function killErrors(){return true;}
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 Days = 365;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString();

}

function addlist(mtvid,mtvname){	
					 var address = mtvid;
					 var linkname = mtvname;
                address = address + "~";
                //一条记录之间用~分隔
                wlink = linkname + "^" + address;					 
                //名字与链接之间用^分隔
                old_info = getCookie("history_info");
                var insert = true;
                ////////////////////////
                if (old_info == null)
                //判断cookie是否为空
                {
                    insert = true;						
                }
                else
                {	
                    var old_link = old_info.split("~");
                    for (var j = 0; j <= 17; j++)
                    {	
                        if (old_link[j].indexOf(linkname) != -1)
                        insert = false;
                        if (old_link[j] == "null")
                        break;
                    }
                }
                /////////////////////////////
                if (insert)
                //如果符合条件则重新写入数据
                {
                    wlink += getCookie("history_info");
                    setCookie("history_info", wlink);
                    history_show();
                }
		 return null;
}

//////////////////////////////////////////////////////////////////////////////// 
function history_show()
 {
    var history_info = getCookie("history_info");
    var content = "";
    if (history_info != null)
    {
        history_arg = history_info.split("~");
        var i;
        for (i = 0; i <= 17; i++)
        {
            if (history_arg[i] != "null")
            {
					try{
                var wlink = history_arg[i].split("^");
                content += ("<li><a href='#' onclick=window.open('/play/"+wlink[1]+"_1.htm?1','newwindow','toolbar=1,location=1,directories==1,status=1,menubar=1,scrollbars=1,resizable=1');>" + wlink[0] + "</a><span><input type='button' class='remove' onclick=foldDetail('" + wlink[1] + "'); /></span></li>");
					}catch(err)
					{}
            }
            document.getElementById("history").innerHTML = content;

        }

    }
    else
    {
        document.getElementById("history").innerHTML = "<li class='alert'>无播放列表</li>";
    }

}

function find_history(name)
 {
    var history_info = getCookie("history_info");
    var content = "";
	var myhistory="";
	var fbz=false;
    if (history_info != null)
    {
        history_arg = history_info.split("~");
        var i;
        for (i = 0; i <= 17; i++)
        {
            if (history_arg[i] != null)
            {
					try{
                    wlink = history_arg[i].split("^");
					 if(name==wlink[1])
					 {
							fbz=true;
							if(history_arg[i+1]!=null)
							{
								wlink = history_arg[i+1].split("^");
								myhistory=wlink[1];
							}else
							{
								if(history_arg[0]!=null)
								{
									wlink = history_arg[0].split("^");
									myhistory=wlink[1];
								}
								else
								{myhistory='';}
							}
					 }
					}catch(err)
					{}
            }            
        }
		if(fbz==false){
			wlink = history_arg[0].split("^");
			myhistory=wlink[1];
		}
    }
	 return myhistory;
}

function deleteCookie(name) {
    setCookie(name, "");
    history_show();

}
function foldDetail(name)
{
	var allinfo=getCookie("history_info");
	var subinfo=allinfo.split("~");
	var clink="";
	for(var i=0;i<=17;i++)
	{
		if(subinfo[i]!="null")
		{
			try{
				if (subinfo[i].indexOf(name) == -1)
				{
					clink+=subinfo[i]+"~";
				}
			}catch(err)
			{break;}				
		}
	}
  clink=clink+"null";
  setCookie("history_info", clink);
  history_show();
}
