﻿function ShowCookie(cName){//展示cookie中的每个键值对
  var i;
  var value = document.cookie;
  var arr1 = value.split(";");
  var sCookie = ""; 
  for(i=0;i<arr1.length;i++){
  	try {
	    if(value.length == 0){
	      break;
	    }
	    sName =  strim(arr1[i].split("=")[0]);
	    sValue =  strim(arr1[i].split("=")[1]);
		if (sName == cName) {
			sCookie = sValue; 
		}
	} catch(e) {}
  }
  return sCookie;
}

function strim(sT)  
{  
  if(sT == null) {
   return "";
 }
  if(sT.length > 0){
   return  sT.replace(/(^\s*)|(\s*$)/g,  "");
  }
  else{
   return sT;
  }
}









/*
function SetUCookie(name, value)
{
    var expdate = new Date();
	var argv = SetUCookie.arguments;
	var argc = SetUCookie.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 + "=" + encodeURIComponent (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
	+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
	+((secure == true) ? "; secure" : "");
}
*/

function showTips(_str,_mode) {
	var _ymd=_str.split("-");
	_ymd[1]=(_ymd[1].indexOf("0")==0)?_ymd[1].substr(1):_ymd[1];
	_ymd[2]=(_ymd[1].indexOf("0")==0)?_ymd[2].substr(1):_ymd[2];
	var _pubDate=new Date(_ymd[0],parseInt(_ymd[1])-1,parseInt(_ymd[2]));	
	var _today=new Date();
	var _dis=(_today-_pubDate)/3600000/24;
	var _info;
	if (_mode==2) {
		_info='<img src="/images/playtips.gif"/>';
	} else {
		_info='本片刚刚发布，可能点播过程会有点卡，敬请谅解';
		_info='（'+_info+'）';
		_info='<font style="color:red;font-weight:bold">'+_info+'</font>';
	}	
	if (_dis<2) {document.write(_info)};
}



/*
Cookie操作，自动记录并显示用户历史操作，可控制显示记录数！
By Crping 2008-9-23
*/

function GetUCookie(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 getCookieUVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}

function SetUCookie(name, value)
{
    var argv = SetUCookie.arguments;
    var argc = SetUCookie.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;
    document.cookie = name + "=" + escape(value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain));
}

function DeleteCookie(name)
{
	//document.getElementById("lookNew").innerHTML="";
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = GetUCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    ShowCookieUserName("ppCookie",3);
}

function DeleteUcCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = GetUCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    ShowCookieUserName("ppCookie",3);
}

function getCookieUVal(offset)
{
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function ShowCookieUserName(cookieName, itemTotal) //itemTotal 显示记录数。显示样式在外层容器控制，不需改此处！
{	
	var _s = "";
    var _l = "";
    itemTotal=3;
    _s="<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
    if (GetUCookie(cookieName) == null)
    {
 	 	 _l+="<tr>";
		 _l+="<td>";
         _l+="暂无观看记录";
         _l+="</td>";
         _l+="<td>&nbsp;</td>";
         _l+="<td>";
         _l+="&nbsp";
         _l+="</td>";
         _l+="</tr>";
         _l+="<tr>";
		 _l+="<td>";
         _l+="&nbsp;";
         _l+="</td>";
         _l+="<td>&nbsp;</td>";
         _l+="<td>";
         _l+="&nbsp;";
         _l+="</td>";
         _l+="</tr>";
    }
	else{
	    var urlArr = GetUCookie(cookieName).split("$");
	    for (i = 0, j = 0; i < urlArr.length, j < itemTotal; i++, j++)
	    {
	    	var itemArr=null;
	    	if(urlArr[i]=="undefined" || urlArr[i]==null || urlArr==""){
	    		itemArr=null;	 
	    	}
	    	else{
	    		if(itemArr==null){
	    			itemArr = urlArr[i].split("|");
	    		}    		
		    	if (itemArr.length > 1)
		        {
		        	 _l+="<tr>";
					 _l+="<td>";
		             _l+="<a href='" + itemArr[0] + "'>" + itemArr[1] + "</a>";
		             _l+="</td>";
		             _l+="<td>&nbsp;</td>";
		             _l+="<td>";
		             _l+=itemArr[2];
		             _l+="</td>";
		             _l+="</tr>";
		        }
	    	}	        
	    }
	}
    _s = _s+_l+"</table>";
    document.getElementById("lookNew").innerHTML=_s;
}

function IsExist(urlStr, url)
{
    if (urlStr.indexOf(url) > -1)
    {
        return true
    }
    return false
}


function InitCookie(cookieName,url, value)    //titleID 存有页面标题或文章标题的控件ID
{
    var expdate = new Date();
    expdate.setTime(expdate.getTime() + (1 * 24 * 60 * 60 * 1000));
	var date = new Date();
	var md = date.getMonth()+1 + "-" + date.getDate();
    if (GetUCookie(cookieName) == null)
    {
        SetUCookie(cookieName, url + "|" + value + "|" + md, expdate);
    }
    else
    {
        if (!IsExist(GetUCookie(cookieName), url))
        {
            SetUCookie(cookieName, url + "|" + value + "|" + md + "$" + GetUCookie(cookieName), expdate);
        }
    }
    ShowCookieUserName("ppCookie", 3);
}













//原150下cooking.js里的函数，且原150下cooking.js前32行与此文件前32行相同。
function setcookie(cname,cvalue,cdate)
{
   var expires = new Date();
   expires.setTime(expires.getTime() + cdate);
   document.cookie=cname + "=" + escape(cvalue) + ";path=/;expires=" + expires.toGMTString();
   //alert("设置了一个名为" + cname + "的cookie.值是:" + cvalue + "过期时间是:" + expires.toGMTString());
}