// getCookie() : Get Cookie ............................................
  function getCookie( key ) {
    var tmp1, tmp2, xx1, xx2, xx3;
    
    tmp1 = " " + document.cookie + ";";
    xx1 = xx2 = 0;
    len = tmp1.length;
    while (xx1 < len) {
        xx2 = tmp1.indexOf(";", xx1);
        tmp2 = tmp1.substring(xx1 + 1, xx2);
        xx3 = tmp2.indexOf("=");
        if (tmp2.substring(0, xx3) == key) {
            return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
        }
        xx1 = xx2 + 1;
    }
    return("");
  }
  
// setCookie() : Set Cookie ............................................
  function setCookie( key, val, exp ) {
    var tmp;

    tmp  = key + "=" + escape(val) + "; ";
    tmp += "expires=" + exp.toGMTString() + "; ";
    tmp += "path=" + location.pathname + "; ";
    document.cookie = tmp;
  }
  
// clearCookie() : Clear Gookie ........................................
  function clearCookie( key ) {
    document.cookie = key + "=" + "xx; expires=1-Jan-1997 00:00:00;";
  }

// page_SetStat() : Set page statu .....................................
  function page_SetStat( key, name, stat ) {
    var pstat = getCookie(key);
    var expt  = new Date();
    var i, j, pos;
    
    stat = (stat == 0 || stat == 1) ? stat : 0;
    
    pos = pstat.indexOf(name,0);
    if( pos == -1 )
      pstat += "|" + name + ":" + stat;
    else {
      i = pos + name.length + 1;
      j = pstat.length - i - 1;
      pstat = pstat.substr(0, i) + stat + pstat.substr(i+1, j);
    }
    
    expt.setTime(expt.getTime() + (90*24*60*60*1000));
    setCookie( key, pstat, expt );
    location.reload();
}
