home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 November / APC411-2.ISO / multimed / MediaCenter.exe / data1.cab / WorkShop / Pages / update.js < prev    next >
Encoding:
Text File  |  1999-07-27  |  4.7 KB  |  174 lines

  1.  
  2. function handleUpdateDialog()
  3. {
  4.     // if cookies are disabled by user don't show nag dialog, ever
  5.     if ( !window.navigator.cookieEnabled )
  6.         return; 
  7.     
  8.     // if no cookie create one. User deleted or first time app run.
  9.     if ( document.cookie == "" ) 
  10.         createCookie();
  11.         
  12.     // read cookie and parse out fields
  13.     var reminder_date;
  14.     var dialogShown;
  15.     var shouldShowDialog;
  16.     var WS_cookie = document.cookie;
  17.     var WS_cookie_array = WS_cookie.split(",");
  18.     reminder_date         = WS_cookie_array[1];
  19.     dialogShown         = WS_cookie_array[2];
  20.     shouldShowDialog     = WS_cookie_array[3];
  21.  
  22.     var current_date = getCurrentDate();
  23.     
  24.     // see if we need to show dialog. If so, show it
  25.     if ( need_to_show_dialog( current_date, reminder_date, dialogShown, shouldShowDialog ))
  26.     {
  27.         var args = new dialogArgs();
  28.         var strFeatures = "dialogWidth:585px;dialogHeight:300px;" +
  29.                              "help:no;maximize:no;minimize:no;scrollbars:no;status:no";
  30.  
  31.         var cRetValue=showModalDialog( "update.htm", args, strFeatures );
  32.  
  33.         // get user results 
  34.         shouldShowDialog = ( args.showFlag == true ) ? "true" : "false";
  35.         dialogShown = "true";
  36.  
  37.         // set next show date
  38.         var reminder_date = getReminderDate();
  39.         
  40.         // write cookie
  41.         writeCookie( reminder_date, dialogShown, shouldShowDialog );        
  42.         
  43.         // navigate to local SmartUpdate page
  44.         if ( cRetValue == true ) 
  45.         { 
  46.             window.top.navigate( "update_confirm.htm" );
  47.         }
  48.     }
  49. }
  50.  
  51. function need_to_show_dialog( current_date, reminder_date, dialogShown, shouldShowDialog )
  52. {
  53.     if ( shouldShowDialog == "true")
  54.         return evalDate( current_date, reminder_date ); // see if time interval has elapsed
  55.  
  56.     return false;
  57. }
  58.  
  59. function evalDate( current, datetoeval )
  60. {
  61.     if ( datetoeval == "" || current == "" )
  62.         return false;
  63.     
  64.     var currentyear = current.substring(4,8);
  65.     var currentmonth = current.substring(0,2);
  66.     var currentdate = current.substring(2,4);
  67.     var datetoevalyear = datetoeval.substring(4,8);
  68.     var datetoevalmonth = datetoeval.substring(0,2);
  69.     var datetoevaldate = datetoeval.substring(2,4);
  70.     
  71.     //alert("Current\r" + currentyear + "\r" + currentmonth + "\r" + currentdate + "\r\r" + "Date to Eval\r" + datetoevalyear + "\r" + datetoevalmonth + "\r" + datetoevaldate + "\r")
  72.  
  73.     if (currentyear > datetoevalyear)
  74.         return true;
  75.  
  76.     if (currentyear < datetoevalyear)
  77.         return false;
  78.  
  79.     if (currentyear == datetoevalyear)
  80.     {
  81.         if (currentmonth > datetoevalmonth)
  82.             return true;
  83.         if (currentmonth == datetoevalmonth)
  84.         {
  85.             if (currentdate >= datetoevaldate)
  86.                 return true;
  87.         }
  88.     }
  89.     return false;
  90. }
  91.  
  92. // If the Cookie doesn't exist, create it and write it out
  93. function createCookie()
  94. {
  95.     var reminder_date = getReminderDate();
  96.     var dialogShown = "false";// Set up first time this instance flag
  97.     var shouldShowDialog = "true";// Set up ok with user to show flag
  98.  
  99.     writeCookie( reminder_date, dialogShown, shouldShowDialog );
  100.     
  101. } // createCookie
  102.  
  103. // Set up reminder date
  104. function getReminderDate()
  105. {
  106.     var reminder = new Date();
  107.     var remind_month = (reminder.getMonth() + 2);
  108.     var remind_date = (reminder.getDate());
  109.     var remind_year = (reminder.getYear());
  110.     if ((remind_year>"97") && (remind_year<"2000"))
  111.         remind_year = remind_year + 1900;
  112.  
  113.     if (remind_month > 12)
  114.     {
  115.         remind_month = remind_month - 12;
  116.         remind_year = remind_year + 1;
  117.     }
  118.     
  119.     if (remind_month<"10")
  120.         remind_month="0" + remind_month;
  121.  
  122.     if (remind_date<"10")
  123.         remind_date="0" + remind_date;
  124.  
  125.     var reminder_date=(remind_month + "" + remind_date + "" + remind_year);
  126.     
  127.     return reminder_date;
  128.     
  129. }
  130.  
  131. function writeCookie( reminder_date, dialogShown, shouldShowDialog )
  132. {
  133.     // Set up expiration date    
  134.     var the_date = new Date("December 31, 2032");
  135.     var expirationDate = the_date.toGMTString();
  136.  
  137.     // Set up cookie and write it
  138.     var WS_cookie = "workshop_cookie=," + reminder_date + "," + dialogShown + "," + shouldShowDialog;
  139.     WS_cookie = WS_cookie + ";expires=" + expirationDate;
  140.     document.cookie = WS_cookie;
  141.     
  142.     //alert ( "writing cookie: " + WS_cookie );
  143. }
  144.  
  145. // set up normalized current date
  146. function getCurrentDate()
  147. {
  148.     var reminder = new Date();
  149.     var addyear = "";
  150.     var remind_month = (reminder.getMonth() + 1);
  151.     var remind_date = reminder.getDate();
  152.     var remind_year = reminder.getYear();
  153.     
  154.     if ((remind_year > "97") && (remind_year < "2000")) //Sets year to 4 digits
  155.         addyear=19;
  156.  
  157.     if (remind_month < "10") //Makes the month a 2 digit if it isn't
  158.         remind_month = "0" + remind_month;
  159.  
  160.     if (remind_date < "10") //Makes the day a 2 digit if it isn't
  161.         remind_date = "0" + remind_date;
  162.  
  163.     var current_date = (remind_month + "" + remind_date + "" + addyear + remind_year);                
  164.     
  165.     return current_date;
  166. }
  167.  
  168. // Create dialogArgs object & initialize
  169. function dialogArgs() 
  170. {    
  171.     this.showFlag = true;
  172. }
  173.  
  174.