home *** CD-ROM | disk | FTP | other *** search
- // this component must be used with the CookieComponent
-
- function com_netobjects_showVisitsComponent( params ) {
-
- this.getVisits = getVisits;
- this.name = params.name;
- this.cookieObject = (params.Cookie+"" != "undefined" && params.Cookie != null ? params.Cookie : null);
- this.timetype = (params.timetype+"" != "undefined" && params.timetype != null ? params.timetype : null);
- this.duration = params.duration;
-
- // date - any instance of the Date object
- // * you should hand all instances of the Date object to this function for "repairs"
- // * this function is taken from Chapter 14, "Time and Date in JavaScript", in "Learn Advanced JavaScript Programming"
- function fixDate(date) {
- var base = new Date(0);
- var skew = base.getTime();
- if (skew > 0)
- date.setTime(date.getTime() - skew);
- }
-
- function getVisits(name) {
- var cookieName = eval(name+ ".cookieObject");
- var now = new Date();
- fixDate(now);
-
- if(eval(name+".cookieObject")+"" == "null" || eval(name + ".timetype")+"" == "null")
- alert("This component is not set up properly. Consult the help pages for proper functionality");
- else
- {
-
- if(eval(name + ".duration")+"" == "day")
- now.setTime(now.getTime() + parseInt(eval(name + ".timetype")) * 24 * 60 * 60 * 1000);
- else
- {
-
- if(eval(name + ".duration")+"" == "hour")
- now.setTime(now.getTime() + parseInt(eval(name + ".timetype")) * 60 * 60 * 1000);
- else
- now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
- }
-
- var visits = eval(cookieName + ".getCookie('" + cookieName + "');");
- var flag = false;
-
- if (!visits || visits+"" == "undefined" || visits+"" == "null")
- {
- flag = true;
- visits = 1;
- }
- else {
- if(parseInt(visits)+"" == "NaN")
- visits = 1;
- else
- visits = parseInt(visits) + 1;
- }
- eval(cookieName + ".setcookieValue('" + visits + "','" + cookieName + "');");
- if(flag)
- eval(cookieName + ".expires='" + now + "';");
- eval(cookieName + ".setCookie('" + cookieName + "');");
- return visits;
- }
- }
- }
-