function setCookie(name, value, seconds, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds*1000 );		//失效时间（单位：秒）
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function deleteCookie(name, path, domain) {
	if (getCookie(name))
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
		window.location=""+movieurl+"" ;

}

function getCookie(name) {
	var prefix = name + "=";
	var cookieStartIndex = document.cookie.indexOf(prefix);
	if (cookieStartIndex == -1)	return null;
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex != -1)
		return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
	else
		return unescape(document.cookie.substring(cookieStartIndex + prefix.length));
}


/*******************************点播页使用方法*******************************/
function getData(name) {
	var temp = getCookie(name);
	;
	if (temp == "" || temp == null) return "";
	var temparray = temp.split('$');
	if (temparray.length<1) return "";
	return temparray;
}

function setUlooked() {
	
	var str = movieurl.replace('#','') + "|" + left(title,15);			
	var temp = getCookie("Ulooked");
	if (temp == undefined || temp == "") temp = "";
	if (temp.indexOf(str) != -1) return;	
	if (temp != "")
		str += "$";						
	setCookie("Ulooked",str+temp,8640000,"\/");
}

function showUlooked(objid){
	var obj = document.getElementById(objid);
	
	var temparray = getData("Ulooked");
	var temparray2;
	if (temparray == "" || temparray == undefined) return;
	obj.innerHTML = "";
	for (var i=0;i<temparray.length;i++) {
		if (i>=8) break;				
		temparray2 = temparray[i].split('|');
		if (temparray2.length<2) continue;
		ii=i+1;
		obj.innerHTML += "<LI><span>"+ii+"</span><A href="+ temparray2[0] +">" + temparray2[1] + "</A></LI>";
	}
}

function setCollection() {
	var str = movieurl.replace('#','') + "|" + left(title,10);		// 用|号间隔开articleid和标题
	var temp = getCookie("UserCollection");
	if (temp == undefined || temp == "") temp = "";
	if (temp.indexOf(str) == -1) {		// 不存在cookies里时才添加
		if (temp != "") str += "$";	// 用$号间隔开多条记录
		setCookie("UserCollection",str+temp,8640000,"\/");// 失效时间100天
	}
	alert('《' + title + '》已成功添加到您收藏的节目列表！');
	window.location=""+movieurl+"" ;
}

function showCollection(objid) {
	var obj = document.getElementById(objid);
	var temparray = getData("UserCollection");
	var temparray2;
	if (temparray == "" || temparray == undefined) return;
	for (var i=0;i<temparray.length;i++) {
		if (i>=8) break;				// 最多显示十条
		temparray2 = temparray[i].split('|');
		if (temparray2.length<2) continue;
		obj.innerHTML += "<LI><span>"+i+"</span><A href="+ temparray2[0] +">" + temparray2[1] + "</A></LI>";
	}
}

function left(mainStr,lngLen) { 
 if (lngLen>0) {return mainStr.substring(0,lngLen)+""} 
 else{return null} 
 }  


