<SCRIPT LANGUAGE="JavaScript">
<!--
var cookieDays = 20;                                      // cookie的期限
var exp = new Date();                                     // 创建对象
exp.setTime(exp.getTime() + (cookieDays*24*60*60*1000));  // 过期日期
function Who(info)                                        // 获得访问者的信息
{
var VisitorName = GetCookie('VisitorName')   // 从cookie中查找VisitorName字段
if (VisitorName == null) {                   // 如果为空
  VisitorName = prompt("what's your name?");  // 弹出提示窗口
  SetCookie ('VisitorName', VisitorName, exp);   // 将VisitorName写入cookie中
}
return VisitorName;                              // 返回VisitorName
}

function When(info)                              // 返回用户上次访问时间
{
var rightNow = new Date()
var WWHTime = 0;
WWHTime = GetCookie('WWhenH')                    // 从cookie中获取WWhenH
WWHTime = WWHTime * 1
var lastHereFormatting = new Date(WWHTime);
var intLastVisit = (lastHereFormatting.getYear() * 10000)+(lastHereFormatting.getMonth() * 100) + lastHereFormatting.getDate()    
// 转换格式
var lastHereInDateFormat = "" + lastHereFormatting;
var dayOfWeek = lastHereInDateFormat.substring(0,3)             // 获取一周哪天
var dateMonth = lastHereInDateFormat.substring(4,11)            // 获取月份
var timeOfDay = lastHereInDateFormat.substring(11,16)           // 获取日期
var year = lastHereInDateFormat.substring(23,25)                // 获取年
var WWHText = dayOfWeek + ", " + dateMonth + " at " + timeOfDay  // 重新组合日期
SetCookie ("WWhenH", rightNow.getTime(), exp)                  // 写入cookie中
return WWHText
}
function Count(info)                                        // 返回用户访问次数
{
var WWHCount = GetCookie('WWHCount')                 // 从cookie中读取WWHCount
if (WWHCount == null) {
  WWHCount = 0;
}
else{
  WWHCount++;
}
SetCookie ('WWHCount', WWHCount, exp);                       // 写入cookie中
return WWHCount;
}
function getCookieVal (offset)                  // 返回cookie中一定位置的字段
{ 
var endstr = document.cookie.indexOf (";", offset);    
// 获取指定位置字段的末尾位置
if (endstr == -1)    
  endstr = document.cookie.length;  
  return unescape(document.cookie.substring(offset, endstr));
}

function set(){                    // 更改访客信息
VisitorName = prompt("Who are you?");
SetCookie ('VisitorName', VisitorName, exp);
SetCookie ('WWHCount', 0, exp);
SetCookie ('WWhenH', 0, exp);
}


function GetCookie (name)                        // 从cookie中获取字段的值
{  
var arg = name + "="; 
var alen = arg.length;                           // 字段的长度  
var clen = document.cookie.length;               // cookie字段的长度
var i = 0;  
while (i < clen) 
{                                                // 在cookie中
  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)                 // 向cookie中写入
{  
var argv = SetCookie.arguments;                  // 写入变量数组
var argc = SetCookie.arguments.length;           // 变量的个数
var expires = (argc > 2) ? argv[2] : null;       // cookie中的参数
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)) + ((secure == true) ? "; secure" : ""); 
// 按照指定格式写入cookie
}
document.write("Hello " + Who() + ". <br>您已经登录本站" + Count() + " 次了.<br>上次登录是:" + When() +".");
document.write('<a href="javascript:set()">[更改访客信息]</a>');

// -->
</SCRIPT>