home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / ScriptBuilder / NOSB30_TRIAL.exe / data1.cab / Program_Files / CompLib / showVisits.js < prev    next >
Encoding:
JavaScript  |  1998-10-05  |  2.1 KB  |  64 lines

  1. // this component must be used with the CookieComponent
  2.  
  3. function com_netobjects_showVisitsComponent( params ) {
  4.  
  5.     this.getVisits = getVisits;
  6.    this.name = params.name;
  7.    this.cookieObject = (params.Cookie+"" != "undefined" && params.Cookie != null ? params.Cookie : null);
  8.    this.timetype = (params.timetype+"" != "undefined" && params.timetype != null ? params.timetype : null);
  9.    this.duration = params.duration;
  10.     
  11.     // date - any instance of the Date object
  12.     // * you should hand all instances of the Date object to this function for "repairs"
  13.     // * this function is taken from Chapter 14, "Time and Date in JavaScript", in "Learn Advanced JavaScript Programming"
  14.     function fixDate(date) {        
  15.         var base = new Date(0);
  16.        var skew = base.getTime(); 
  17.        if (skew > 0)
  18.            date.setTime(date.getTime() - skew);
  19.     }
  20.  
  21.     function getVisits(name) {
  22.        var cookieName = eval(name+ ".cookieObject");
  23.        var now = new Date();
  24.         fixDate(now);
  25.  
  26.         if(eval(name+".cookieObject")+"" == "null" || eval(name + ".timetype")+"" == "null")
  27.           alert("This component is not set up properly. Consult the help pages for proper functionality");
  28.         else
  29.         {
  30.  
  31.           if(eval(name + ".duration")+"" == "day")
  32.              now.setTime(now.getTime() + parseInt(eval(name + ".timetype")) * 24 * 60 * 60 * 1000);
  33.           else
  34.           {
  35.  
  36.               if(eval(name + ".duration")+"" == "hour")
  37.                now.setTime(now.getTime() + parseInt(eval(name + ".timetype")) * 60 * 60 * 1000);            
  38.               else
  39.                    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
  40.           }
  41.           
  42.           var visits = eval(cookieName + ".getCookie('" + cookieName + "');");
  43.           var flag = false;
  44.  
  45.           if (!visits || visits+"" == "undefined" || visits+"" == "null")   
  46.           {
  47.              flag = true;
  48.              visits = 1;
  49.           }
  50.          else {
  51.                if(parseInt(visits)+"" == "NaN")
  52.                  visits = 1;
  53.                else
  54.                  visits = parseInt(visits) + 1;
  55.          }
  56.           eval(cookieName + ".setcookieValue('" + visits + "','" + cookieName + "');");
  57.           if(flag)
  58.             eval(cookieName + ".expires='" + now + "';");
  59.           eval(cookieName + ".setCookie('" + cookieName + "');");
  60.           return visits;
  61.        }
  62.     }
  63. }
  64.