home *** CD-ROM | disk | FTP | other *** search
/ Freelog 117 / FreelogNo117-OctobreNovembre2013.iso / Theme / 8GadgetPack / 8GadgetPackSetup.msi / calendar.js < prev    next >
Text (UTF-16)  |  2012-05-19  |  65KB  |  1,230 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // THIS CODE IS NOT APPROVED FOR USE IN/ON ANY OTHER UI ELEMENT OR PRODUCT COMPONENT.
  4. // Copyright (c) 2009 Microsoft Corporation. All rights reserved.
  5. //
  6. ////////////////////////////////////////////////////////////////////////////////
  7.  
  8.  
  9.  var L_PREVIOUS_text = "Vorheriger";
  10.  var L_NEXT_text = "Weiter";
  11.  var g_filter = 1;
  12.  var g_todayView = true;
  13.  var g_calendar_top_margin_unDocked = 20;
  14.  var g_calendar_top_margin_docked = 20;
  15.  var g_dayView_monthHdr = 5;
  16.  var g_dayView_dayOfWeekHdr = 90;
  17.  var g_calendar_date = new Date().toDateString();
  18.  var g_initDate = new Date().toDateString();
  19.  var g_currentDate = new Date().toDateString();
  20.  var g_defaultView = "";
  21.  var g_defaultDOW = "";
  22.  var gView = "month";
  23.  var g_curl_img = null;
  24.  var g_curl_hitRegion = null;
  25.  var g_day_view = null;
  26.  var BIDI = "";
  27.  var temp;
  28.  var g_calendarAlarm = null;
  29.  var g_mySettings = new calendarSettings();
  30.  var g_monthYearLayout = "";
  31.  var loc = new locClass();
  32.  var g_userLanguage = "";
  33.  
  34.  
  35. ////////////////////////////////////////////////////////////////////////////////
  36. //
  37. // SETTINGS UTILITIES
  38. //
  39. ////////////////////////////////////////////////////////////////////////////////
  40.  
  41. ////////////////////////////////////////////////////////////////////////////////
  42. //
  43. // saveSetting(string theSettingName, string aSettingValue)- Saves a Setting
  44. //
  45. ////////////////////////////////////////////////////////////////////////////////
  46. function saveSetting(theSettingName, aSettingValue) 
  47. {
  48.  try
  49.  {
  50.     System.Gadget.Settings.write(theSettingName, aSettingValue);
  51.  }
  52.  catch (objException) 
  53.  {
  54.  }
  55. }
  56. ////////////////////////////////////////////////////////////////////////////////
  57. //
  58. // readSetting(string theSettingName)- Reads a Setting
  59. //
  60. ////////////////////////////////////////////////////////////////////////////////
  61. function readSetting(theSettingName) 
  62. {
  63.  var retVal = "";
  64.  try
  65.  {
  66.     retVal = System.Gadget.Settings.read(theSettingName);
  67.  }
  68.  catch (objException) 
  69.  {
  70.     retVal = null;
  71.  }
  72.  return retVal;
  73. }
  74.  
  75. ////////////////////////////////////////////////////////////////////////////////
  76. //
  77. // Initialize
  78. //
  79. ////////////////////////////////////////////////////////////////////////////////
  80. BIDI = document.getElementsByTagName("HTML")(0).dir;
  81.  
  82. if (BIDI == "rtl" || BIDI == "RTL")
  83. {
  84.     temp = L_PREVIOUS_text;
  85.     
  86.     L_PREVIOUS_text = L_NEXT_text;
  87.     L_NEXT_text = temp;
  88.     
  89.     BIDI = "rtl";
  90. }
  91. else
  92. {
  93.     BIDI = "ltr";
  94. }
  95.  
  96. btnPrevious.alt = L_PREVIOUS_text;
  97. btnNext.alt    = L_NEXT_text;
  98.  
  99. g_mySettings.loadSettings();
  100.  
  101. loc.load();
  102.  
  103. setCalendarAlarm(true);
  104.  
  105. System.Gadget.visibilityChanged=checkVisibility;
  106. System.Gadget.onDock=Dock;
  107. System.Gadget.onUndock=unDock;
  108. window.onload = System.Gadget.docked ? Dock : unDock;
  109.  
  110.  
  111. ////////////////////////////////////////////////////////////////////////////////
  112. //
  113. // Calendar Object
  114. //
  115. ////////////////////////////////////////////////////////////////////////////////
  116. function locClass()
  117. {
  118.     this.load = function()
  119.     {
  120.         this.day=
  121.         {
  122.             first: null,
  123.             short: null,
  124.             long : null,
  125.             dayofweek: null
  126.         };
  127.         this.month=
  128.         {
  129.             short: null,
  130.             long : null
  131.         };
  132.     };
  133.     
  134.     this.parseNode = function(xmlStr, nloc)
  135.     {
  136.         var dayStr = nloc.selectSingleNode(xmlStr);
  137.         
  138.         if (dayStr)
  139.         {
  140.             return dayStr.text.split(";");
  141.         }
  142.         else
  143.         {
  144.             return [];
  145.         }
  146.     };
  147. }
  148. ////////////////////////////////////////////////////////////////////////////////
  149. //
  150. // Initialize calendar to user locale settings
  151. //
  152. ////////////////////////////////////////////////////////////////////////////////
  153. function reLoad()
  154. {        
  155.     clearTimeout(g_calendarAlarm);
  156.     setCalendarAlarm(true);
  157.     
  158.     if (g_userLanguage != navigator.userLanguage )
  159.     { 
  160.         g_userLanguage = navigator.userLanguage;
  161.         
  162.         loc.day.first = vbsFirstDayOfWeek()-1;
  163.         
  164.         if (loc.day.short != null)
  165.         {
  166.             loc.day.short.splice();
  167.             loc.day.long.splice();
  168.             loc.month.short.splice();
  169.             loc.month.long.splice();
  170.         }
  171.         
  172.         var bIsMonthNameLong = monthNameLong.documentElement.selectSingleNode("lang[@id='"+g_userLanguage.toLowerCase()+"']");
  173.  
  174.         loc.day.short = buildWeekDayNameShort();
  175.         loc.day.long = buildWeekDayNameLong();
  176.  
  177.         if (bIsMonthNameLong)
  178.         {
  179.             loc.month.short = buildMonthNameLong();
  180.         }
  181.         else
  182.         {
  183.             loc.month.short = buildMonthNameShort();
  184.         }
  185.         loc.month.long = buildMonthNameLong();
  186.         
  187.         loc.day.dayofweek = null;
  188.         
  189.         var nloc = xloc.documentElement.selectSingleNode("lang[@id='"+g_userLanguage.toLowerCase()+"']");
  190.         
  191.         if (nloc)
  192.         {
  193.             loc.day.dayofweek = loc.parseNode("day/@dayofweek", nloc);
  194.         }
  195.         
  196.         setYearBeforeMonthFlag(); 
  197.     }
  198.  
  199. ////////////////////////////////////////////////////////////////////////////////
  200. //
  201. // Initialize Year before Month flag
  202. //
  203. ////////////////////////////////////////////////////////////////////////////////
  204. function setYearBeforeMonthFlag()
  205. {
  206.  var testDate = new Date("january 25, 1999").toLocaleString();
  207.     
  208.  if (testDate.indexOf("25") < testDate.indexOf("99") )
  209.  {
  210.         g_monthYearLayout = "MM YY";
  211.  }
  212.  else
  213.  {
  214.         g_monthYearLayout = "YY MM";
  215.  }
  216. }
  217.  
  218. ////////////////////////////////////////////////////////////////////////////////
  219. //
  220. // Initialize Long Name Day of Week Array
  221. //
  222. ////////////////////////////////////////////////////////////////////////////////
  223. function buildWeekDayNameLong()
  224. {
  225.     var arr = [];
  226.     for (var i = 0 ; i < 7 ; i++)
  227.     {
  228.         arr[i] = vbsWeekDayNameLong(i+1);
  229.     } 
  230.     return arr;
  231. }
  232. ////////////////////////////////////////////////////////////////////////////////
  233. //
  234. // Initialize Short Name Day of Week Array
  235. //
  236. ////////////////////////////////////////////////////////////////////////////////
  237. function buildWeekDayNameShort()
  238. {
  239.     var arr = [];
  240.     for (var i = 0 ; i < 7 ; i++)
  241.     {
  242.         arr[i] = vbsWeekDayNameShort(i+1,true);
  243.     } 
  244.     return arr;
  245. }
  246. ////////////////////////////////////////////////////////////////////////////////
  247. //
  248. // Initialize Short Month Name Array
  249. //
  250. ////////////////////////////////////////////////////////////////////////////////
  251. function buildMonthNameShort()
  252. {
  253.     var arr = [];
  254.     
  255.     setYearBeforeMonthFlag();
  256.     
  257.     for (var i = 0 ; i < 12 ; i++)
  258.     {
  259.         arr[i] = vbsMonthNameShort(i+1,true);
  260.     } 
  261.     return arr;
  262. }
  263. ////////////////////////////////////////////////////////////////////////////////
  264. //
  265. // Initialize Long Month Name Array
  266. //
  267. ////////////////////////////////////////////////////////////////////////////////
  268. function buildMonthNameLong()
  269. {
  270.     var arr = [];
  271.     for (var i = 0 ; i < 12 ; i++)
  272.     {
  273.         arr[i] = vbsMonthNameLong(i+1);
  274.     } 
  275.     return arr;
  276. }        
  277.                 
  278. ////////////////////////////////////////////////////////////////////////////////
  279. //
  280. // Settings object
  281. //
  282. ////////////////////////////////////////////////////////////////////////////////
  283. function calendarSettings()
  284. {
  285.     this.dockedCalendarView    = readSetting("dockedCalendarView") || "";
  286.     this.dockedCalendarDivType    = readSetting("dockedCalendarDivType") || "reset";
  287.     this.unDockedCalendarView    = readSetting("unDockedCalendarView") || "";
  288.  
  289. ////////////////////////////////////////////////////////////////////////////////    
  290.     this.save = function(dockedCalendarView, dockedCalendarDivType)
  291.     {
  292.         if (dockedCalendarDivType == "reset")
  293.         {
  294.             dockedCalendarDivType = "year";
  295.         }
  296.         
  297.         if (dockedCalendarView == "" || dockedCalendarView == "curlDocked" )
  298.         {
  299.             dockedCalendarView = "DAY_DOCKED";
  300.             dockedCalendarDivType = "dow";
  301.         } 
  302.         
  303.         saveSetting("dockedCalendarView", dockedCalendarView );
  304.         saveSetting("dockedCalendarDivType", dockedCalendarDivType );
  305.         this.dockedCalendarView = dockedCalendarView;
  306.         this.dockedCalendarDivType = dockedCalendarDivType;
  307.     }
  308. ////////////////////////////////////////////////////////////////////////////////    
  309.     this.saveUnDocked = function(unDockedCalendarView)
  310.     {
  311.         if (unDockedCalendarView != "MONTH_UNDOCKED" )
  312.         {
  313.             unDockedCalendarView = "MONTH_UNDOCKED";
  314.         }
  315.         saveSetting("unDockedCalendarView", unDockedCalendarView );
  316.         this.unDockedCalendarView = unDockedCalendarView; 
  317.     }
  318. ////////////////////////////////////////////////////////////////////////////////    
  319.     this.loadSettings = function()
  320.     { 
  321.         this.dockedCalendarView    = readSetting("dockedCalendarView") || "";
  322.         this.dockedCalendarDivType = readSetting("dockedCalendarDivType") || "reset"; 
  323.         this.unDockedCalendarView = readSetting("unDockedCalendarView") || "";
  324.  
  325.         if (this.dockedCalendarView == "")
  326.         {
  327.             this.save("DAY_DOCKED","dow");
  328.         } 
  329.         
  330.         if (this.unDockedCalendarView == "")
  331.         {
  332.             this.saveUnDocked("MONTH_UNDOCKED");
  333.         }            
  334.     }
  335. }
  336. ////////////////////////////////////////////////////////////////////////////////
  337. //
  338. // determine if gadget is visible
  339. //
  340. ////////////////////////////////////////////////////////////////////////////////
  341. function checkVisibility()
  342. {
  343.     var isVisible = System.Gadget.visible;
  344.     var now = new Date().toDateString();
  345.     var initDtd = new Date(g_initDate).toDateString();
  346.  
  347.     if (g_userLanguage != navigator.userLanguage)
  348.     {
  349.         if ( System.Gadget.docked )
  350.         {
  351.             Dock();
  352.         }
  353.         else
  354.         {
  355.             unDock();
  356.         }
  357.     } 
  358.  
  359.     if (! isVisible)
  360.     {
  361.         clearTimeout(g_calendarAlarm);
  362.     }
  363.         
  364.     if (isVisible)
  365.     {
  366.         setCalendarAlarm(false);
  367.     }
  368. }
  369. ////////////////////////////////////////////////////////////////////////////////
  370. //
  371. // 
  372. //
  373. ////////////////////////////////////////////////////////////////////////////////
  374. function setCalendarAlarm(isFirstPass)
  375. {
  376.     var now = new Date();
  377.     var delta = 0;
  378.     var hours = 0;
  379.     var minutes = 0;
  380.     var seconds = 0;
  381.     var MilliSecondsPerDay = (24 * 60 * 60 * 1000);
  382.     var today = null;
  383.     var now = new Date();
  384.     
  385.     hours = now.getHours();
  386.     minutes = now.getMinutes();
  387.     seconds = now.getSeconds();
  388.     
  389.     delta = MilliSecondsPerDay - (hours * 60 * 60 * 1000) - (minutes * 60 * 1000) - (seconds * 1000);
  390.     
  391.     g_calendar_date = now.toDateString();
  392.     
  393.     if (! isFirstPass)
  394.     {
  395.         if ( System.Gadget.docked )
  396.         {
  397.             today=new Date(DAY_DOCKED.d);
  398.             if (today.toDateString() != DAY_DOCKED.d)
  399.                 today.setDate(today.getDate()+1);
  400.                 
  401.             isToday=today.toDateString()==new Date().toDateString();
  402.  
  403.             if ( isToday
  404.                 || today.toDateString()==new Date(now.getYear(),now.getMonth(),now.getDate()-1).toDateString() 
  405.                 || today.toDateString()==g_currentDate )
  406.             {
  407.                     g_currentDate = g_initDate = DAY_DOCKED.d = new Date().toDateString();
  408.                     Calendar(DAY_DOCKED).day.initDay(new Date());                
  409.             }
  410.             
  411.             Dock();
  412.         }
  413.         else
  414.         {
  415.             today=new Date(DAY_UNDOCKED.d);
  416.             if (today.toDateString() != DAY_UNDOCKED.d)
  417.                 today.setDate(today.getDate()+1);
  418.             isToday=today.toDateString()==new Date().toDateString();
  419.             
  420.             if ( isToday
  421.                 || today.toDateString()==new Date(now.getYear(),now.getMonth(),now.getDate()-1).toDateString()
  422.                 || today.toDateString()==g_currentDate )
  423.             {
  424.                     g_currentDate = g_initDate = DAY_UNDOCKED.d = new Date().toDateString();
  425.                     Calendar(DAY_UNDOCKED).day.initDay(new Date());                
  426.             }
  427.                     
  428.             unDock();
  429.         }
  430.     }
  431.     
  432.     g_calendarAlarm = setTimeout('setCalendarAlarm(false)',delta); 
  433. }
  434.  
  435. ////////////////////////////////////////////////////////////////////////////////
  436. //
  437. // 
  438. //
  439. ////////////////////////////////////////////////////////////////////////////////
  440. function setBackground(path)
  441. {
  442.     // if you switch backgrounds on the fly, you must set the style size to zero
  443.     // so it dynamically refreshes
  444.     calendarbackground.style.width = 0;
  445.     calendarbackground.style.height = 0;
  446.     calendarbackground.src = path;        
  447. }
  448.  
  449.  
  450. ////////////////////////////////////////////////////////////////////////////////
  451. //
  452. // 
  453. //
  454. ////////////////////////////////////////////////////////////////////////////////
  455. function swapBackgrounds()
  456. {
  457.     divPrevNext.style.visibility = "visible";
  458.  
  459.     setBackground("url(images/calendar_single.png)");
  460. }
  461. ////////////////////////////////////////////////////////////////////////////////
  462. //
  463. // Docked
  464. //
  465. ////////////////////////////////////////////////////////////////////////////////
  466. function Dock(){
  467.     reLoad();
  468.     docked.style.display = "none";
  469.     unDocked.style.display = "none"; 
  470.     gView = "month";
  471.     g_curl_img = curlDocked;
  472.     g_curl_hitRegion = dockedHitRegion;
  473.     
  474.     g_day_view = DAY_DOCKED;
  475.  
  476.     divPrevNext.className = "prevnext";    
  477.     
  478.  
  479.     with(document.body.style)
  480.     {
  481.         width = 130,
  482.         height = 141,
  483.         backgroundRepeat = "no-repeat";
  484.     }
  485.     setBackground(checkBackground());
  486.  
  487.     var today = new Date(g_initDate);
  488.     if (today.toDateString() != g_initDate)
  489.         today.setDate(today.getDate()+1)
  490.     Calendar(YEAR_DOCKED).year.initYear(today);
  491.     Calendar(MONTH_DOCKED).month.initMonth(today);
  492.     Calendar(DAY_DOCKED).day.initDay(today);
  493.  
  494.     MONTH_DOCKED.style.visibility = "hidden";
  495.     DAY_DOCKED.style.visibility    = "hidden";
  496.     YEAR_DOCKED.style.visibility    = "hidden";
  497.     divPrevNext.style.visibility    = "hidden";
  498.     g_mySettings.loadSettings();
  499.     
  500.     eval( g_mySettings.dockedCalendarView + ".divType = g_mySettings.dockedCalendarDivType");
  501.     swap( eval( g_mySettings.dockedCalendarView ) );
  502.     
  503.     docked.style.display = "";
  504.     g_mySettings.saveUnDocked("");
  505. };
  506. ////////////////////////////////////////////////////////////////////////////////
  507. //
  508. // UnDock
  509. //
  510. ////////////////////////////////////////////////////////////////////////////////
  511. function unDock()
  512. {
  513.     reLoad();
  514.     docked.style.display = "none";
  515.     g_curl_img = curlUnDocked;
  516.     g_curl_hitRegion = unDockedHitRegion;
  517.     g_day_view = DAY_UNDOCKED;
  518.     gView = "month";
  519.     tID.divType = "year";
  520.  
  521.     
  522.     with(document.body.style)
  523.     {
  524.         width = 129;
  525.         height = 264;
  526.     }
  527.     setBackground(checkBackground());
  528.     
  529.     divPrevNext.className = "prevnext_unDocked";
  530.     divPrevNext.style.visibility = "hidden";
  531.  
  532.     var today = new Date(g_initDate);
  533.     if (today.toDateString() != g_initDate)
  534.         today.setDate(today.getDate()+1)
  535.     Calendar(YEAR_UNDOCKED).year.initYear(today);
  536.     Calendar(MONTH_UNDOCKED).month.initMonth(today);
  537.     Calendar(DAY_UNDOCKED).day.initDay(today);
  538.     
  539.     MONTH_UNDOCKED.style.visibility = "hidden";
  540.     YEAR_UNDOCKED.style.visibility    = "hidden";
  541.     
  542.     swap( eval( g_mySettings.unDockedCalendarView ) );
  543.     
  544.     unDocked.style.display = ""; 
  545.     g_mySettings.save("","");
  546. };
  547. ////////////////////////////////////////////////////////////////////////////////
  548. //
  549. //
  550. //
  551. ////////////////////////////////////////////////////////////////////////////////
  552. function checkBackground()
  553. {
  554.     var sRetVal = "";
  555.     var initDate = new Date(g_initDate);
  556.     if (initDate.toDateString() != g_initDate)
  557.         initDate.setDate(initDate.getDate()+1);
  558.     var isToday = ( initDate.toDateString()== new Date().toDateString() );    
  559.  
  560.     if (System.Gadget.docked)
  561.     {
  562.             if ( isToday )
  563.             {
  564.                 sRetVal = "url(images/calendar_single_orange.png)";
  565.                 divBgImageDocked.style.backgroundImage = "url(images/calendar_single_orange.png)";
  566.                 dockedCalendarRing.style.visibility = "hidden"; 
  567.                 g_curl_img.style.visibility    = "hidden";
  568.                 g_curl_hitRegion.style.visibility = "hidden";
  569.             }
  570.             else
  571.             {
  572.                 sRetVal = "url(images/calendar_single.png)";
  573.                 divBgImageDocked.style.backgroundImage = "url(images/calendar_single.png)";
  574.                 g_curl_img.style.visibility    = "visible";
  575.                 g_curl_hitRegion.style.visibility = "visible";
  576.                 dockedCalendarRing.style.visibility = "visible";    
  577.             }        
  578.     }
  579.     else
  580.     {
  581.             if ( isToday )
  582.             {
  583.                 sRetVal = "url(images/calendar_double_orange.png)";
  584.                 divBgImageUnDocked.style.backgroundImage = "url(images/calendar_single_bkg_orange.png)";
  585.             }
  586.             else
  587.             {
  588.                 sRetVal = "url(images/calendar_double.png)";
  589.                 divBgImageUnDocked.style.backgroundImage = "url(images/calendar_single_bkg.png)";
  590.                 g_curl_img.style.visibility    = "visible";
  591.                 g_curl_hitRegion.style.visibility    = "visible"; 
  592.             }        
  593.     }
  594.     
  595.     return sRetVal; 
  596. }
  597. ////////////////////////////////////////////////////////////////////////////////
  598. //
  599. // Calendar object 
  600. //
  601. ////////////////////////////////////////////////////////////////////////////////
  602. function Calendar(o)
  603. {
  604. ////////////////////////////////////////////////////////////////////////////////
  605. //
  606. // Day view
  607. //
  608. ////////////////////////////////////////////////////////////////////////////////
  609.     o.day={
  610.         d:new Date(),
  611.         
  612.         html:function(d)
  613.         {
  614.             if (System.Gadget.docked)
  615.             {
  616.                 divPrevNext.style.visibility = "hidden";
  617.             }
  618.             
  619.             this.d = new Date(d);
  620.             if (this.d.toDateString() != d.toDateString())
  621.                 this.d.setDate(this.d.getDate()+1);
  622.             
  623.             g_day_view.d = d.toDateString();
  624.             
  625.             var isToday=d.toDateString() == new Date().toDateString();
  626.             var layout = g_monthYearLayout;
  627.             
  628.             if (System.Gadget.docked)
  629.             {
  630.                 g_initDate = d.toDateString();
  631.             }
  632.  
  633.             if (isToday)
  634.             {
  635.                 g_curl_img.style.visibility = "hidden";
  636.                 g_curl_hitRegion.style.visibility = "hidden";
  637.             }
  638.             else
  639.             {
  640.                 g_curl_img.style.visibility = "visible";
  641.                 g_curl_hitRegion.style.visibility = "visible";
  642.                 g_curl_img.d = ( new Date().toDateString() );
  643.             }
  644.     
  645.             layout = layout.replace("YY",d.getFullYear());
  646.             layout = layout.replace("MM",loc.month.long[d.getMonth()]);            
  647.             
  648.         return "<table id='dowId' valign=center width='100%' cellpadding=0 cellspacing=0><tr><td align=center style='"+(isToday?"color:white;":"color:black;")+"'><span id='ellipsisHeadingTop'>"+loc.day.long[d.getDay()]+"</span></td></tr><tr><td align=center><div id='ellipsisMiddle' style='"+ (isToday?"color:white;":"color:black;") +"'>"+d.getDate()+"</div></td></tr><tr><td align=center valign=top style='"+(isToday?"color:white;":"color:black;")+"'><span id='ellipsisHeadingBottom'>"+layout+"</span></td></tr></table>";
  649.         },
  650.  
  651.         initDay:function(d)
  652.         {
  653.             o.innerHTML = this.html(d);
  654.         }
  655.  
  656.     };
  657.     
  658. ////////////////////////////////////////////////////////////////////////////////
  659. //
  660. // Month view
  661. //
  662. ////////////////////////////////////////////////////////////////////////////////
  663.     o.month=
  664.     {
  665.         html:function(d)
  666.         {
  667.             var layout = g_monthYearLayout;
  668.             if(d)
  669.             {
  670.                 this.d=new Date(d);
  671.                 if (this.d.toDateString() != d.toDateString())
  672.                     this.d.setDate(this.d.getDate()+1);
  673.             }
  674.             else
  675.             {
  676.                 d=this.d;
  677.             }
  678.             layout = layout.replace("YY",d.getFullYear().toString().substr(2));
  679.             layout = layout.replace("MM",loc.month.short[d.getMonth()]);
  680.             
  681.             return "<span UNSELECTABLE='on'>"+prevNext(layout,monthGrid(d.getYear(),d.getMonth()) )+"</span>";
  682.         },
  683.  
  684.         initMonth:function(d)
  685.         {
  686.             tID.omo = "";            
  687.             o.innerHTML=this.html(d);
  688.         }
  689.     };
  690. ////////////////////////////////////////////////////////////////////////////////
  691. //
  692. // Year view
  693. //
  694. ////////////////////////////////////////////////////////////////////////////////
  695.     o.year=
  696.     {
  697.         html:function(d){
  698.             if(d)
  699.             {
  700.                 this.d=new Date(d);
  701.                 if (this.d.toDateString() != d.toDateString())
  702.                     this.d.setDate(this.d.getDate()+1);
  703.             }
  704.             else
  705.             {
  706.                 d=this.d;
  707.             }
  708.             var s="<div UNSELECTABLE='on' style='margin:5 0 0 5'>",m=0,y,x;
  709.             var currentMonthElement = "";
  710.             var currentMonthRow = "";
  711.  
  712.             for(y=0; y<3; y++, s+="<br>")
  713.             {
  714.                 currentMonthRow = "";
  715.                 for(x=0; x<4; x++, m++)
  716.                 {
  717.                 currentMonthElement = "<var omo tabindex=" + ( m + 1 ) + " divType='zoomMonth' onkeypress='swap(this);' onmouseup='swap(this)' m='"+m+"'>"+loc.month.short[m]+"</var>";
  718.                     if ( BIDI == "rtl" )
  719.                     {
  720.                     currentMonthRow = currentMonthElement + currentMonthRow;
  721.                     }
  722.                     else
  723.                     {
  724.                     currentMonthRow = currentMonthRow + currentMonthElement;
  725.                     }
  726.                 }
  727.                 s += currentMonthRow;
  728.             }
  729.             s+="</div>";
  730.             return "<span >"+
  731.                 prevNext(this.d.getFullYear(),s)+
  732.                 "</span>";
  733.         },
  734.         initYear:function(d){
  735.         tID.removeAttribute("omo");
  736.         tID.className = "";
  737.         o.innerHTML = this.html(d);
  738.         }
  739.     };
  740. ////////////////////////////////////////////////////////////////////////////////
  741.     function prevNext(tIDle,body)
  742.     {
  743.     tID.innerHTML = tIDle;
  744.  
  745.     return "<div UNSELECTABLE='on' class='divMonthView_docked'>"+ body + "</div>";
  746.     };
  747. ////////////////////////////////////////////////////////////////////////////////
  748.     function monthGrid(year,month){
  749.         
  750.         var dow = vbsDayOfWeek();
  751.         var d=new Date(year,month,1-new Date(year,month,1).getDay()+loc.day.first);
  752.         var d2 = new Date(d.getYear(),d.getMonth(),d.getDate(),d.getHours()+1);
  753.         if(d.getDate() != d2.getDate())
  754.             d.setDate(d.getDate()+1);
  755.         var dateString = d.toDateString();
  756.         
  757.         if(d.getMonth()==month && d.getDate()>1)
  758.             d.setDate(d.getDate()-7);
  759.         var s="",today=new Date().toDateString();
  760.         var currentWeekRow = "";
  761.         var currentDayElement = "";
  762.  
  763.         for(var y=0; y<7 && (d.getMonth()<=month || d.getYear()<year); y++)
  764.         {
  765.             currentWeekRow = "";
  766.             for(var x=0; x<7; x++)
  767.             {
  768.                 currentDayElement = "";
  769.                 currentDayElement += "<q divType='dow' class='day"+(x?" lb":"") ;
  770.                 if(y)
  771.                 {
  772.                     if(d.getMonth()!=month)
  773.                         currentDayElement += " dim'";
  774.                     else if(d.toDateString()==today)
  775.                         currentDayElement += " today' tabindex=" + d.getDate() + "";
  776.                     else
  777.                         currentDayElement += "' omo tabindex=" + d.getDate() + "";
  778.  
  779.                     currentDayElement += " d='"+d.toDateString()+"' onkeypress='swap(this);' onmouseup='swap(this);' >"+d.getDate()+"</q>";
  780.                     dateString = d.toDateString();
  781.                     d.setDate(d.getDate()+1);
  782.                     if(d.toDateString() == dateString)
  783.                         d.setDate(d.getDate()+1);
  784.                 }
  785.                 else
  786.                     currentDayElement += (dow != x ? " name ": ckCurrentMonth(year,month) ) +"' title='"+loc.day.long[(x+loc.day.first)%7]+"'>"+(loc.day.dayofweek != null ? loc.day.dayofweek[(x+loc.day.first)%7] : loc.day.short[(x+loc.day.first)%7].substr(0,1))+"</q>";
  787.  
  788.                 if ( BIDI == "rtl" )
  789.                 {
  790.                 currentWeekRow = currentDayElement + currentWeekRow;
  791.                 }
  792.                 else
  793.                 {
  794.                 currentWeekRow = currentWeekRow + currentDayElement;
  795.                 }
  796.             }
  797.             currentWeekRow += "<br>";
  798.             s += currentWeekRow;
  799.         }
  800.  
  801.         return s;
  802.     };
  803. ////////////////////////////////////////////////////////////////////////////////    
  804.     function ckCurrentMonth(year,month)
  805.     { 
  806.         var oDate = new Date(g_calendar_date);
  807.         if (oDate.toDateString() != g_calendar_date)
  808.             oDate.setDate(oDate.getDate()+1);
  809.         var sRetVal = " name";
  810.         
  811.         if (year == oDate.getFullYear() && month == oDate.getMonth() )
  812.         {
  813.             sRetVal = " dow";
  814.         }
  815.         return sRetVal;
  816.     }
  817. ////////////////////////////////////////////////////////////////////////////////
  818.     function dayPos(d){
  819.         var x=(d.getDay()-loc.day.first)%7,
  820.             y=parseInt((d.getDate()+6+loc.day.first-d.getDay())/7);
  821.         if(x<0)x+=7,y--;
  822.         return {x:2+x*17,y:39+y*13}
  823.     };
  824. ////////////////////////////////////////////////////////////////////////////////
  825.     function monthPos(d){
  826.         var x=d.getMonth()%4,
  827.             y=parseInt(d.getMonth()/4);
  828.         return {x:7+x*28,y:27+y*28}
  829.     };
  830.  
  831.     o.tabIndex=1;
  832.     return o;
  833. }
  834. ////////////////////////////////////////////////////////////////////////////////
  835. //
  836. //
  837. //
  838. ////////////////////////////////////////////////////////////////////////////////
  839. function evalPrevNext(direction,o)
  840. {
  841.     var oDate = new Date(g_initDate);
  842.     if (oDate.toDateString() != g_initDate)
  843.         oDate.setDate(oDate.getDate()+1);
  844.  
  845.     if (BIDI == "rtl")
  846.     {
  847.         direction *= -1;
  848.     }
  849.     
  850.     
  851.     switch (gView)
  852.     {
  853.         case "month":
  854.                 o.divType = "changeMonth";
  855.                 oDate.setMonth(oDate.getMonth()+ direction);
  856.                 
  857.                 break;
  858.         case "year":
  859.                 o.divType = "changeYear";
  860.                 oDate.setFullYear(oDate.getFullYear()+ direction);
  861.                 break;                
  862.     }
  863.  
  864.     g_initDate = oDate.toDateString();
  865.     
  866.     if (event.button == 2)
  867.     {
  868.         if (direction == -1)
  869.         {
  870.             o.src = 'images/bprev.png';
  871.         }
  872.         else
  873.         {
  874.             o.src = 'images/bnext-hot.png';
  875.         }
  876.     }
  877.     swap(o);
  878. }
  879. ////////////////////////////////////////////////////////////////////////////////
  880. //
  881. //
  882. //
  883. ////////////////////////////////////////////////////////////////////////////////
  884. function swap(o)
  885. {
  886.     if (event)
  887.     {
  888.         if (event.button == 2)
  889.         {
  890.             return;
  891.         }
  892.     }
  893.     
  894.     if (System.Gadget.docked)
  895.     {
  896.         renderDocked(o);
  897.     }
  898.     else
  899.     {
  900.         renderUnDocked(o);
  901.     }
  902.     g_filter = 1;
  903. }
  904. ////////////////////////////////////////////////////////////////////////////////
  905. //
  906. //
  907. //
  908. ////////////////////////////////////////////////////////////////////////////////
  909. function setInitDate(o)
  910. {
  911.     g_filter = 0;
  912.     oDate = new Date(g_initDate);
  913.     if (oDate.toDateString() != g_initDate)
  914.         oDate.setDate(oDate.getDate()+1);
  915.  
  916.     oDOW = new Date(o.d);
  917.     if (oDOW.toDateString() != o.d)
  918.         oDOW.setDate(oDOW.getDate()+1);
  919.     
  920.     if (oDate.getMonth() != oDOW.getMonth() | oDate.getFullYear() != oDOW.getFullYear() | gView == "year" )
  921.     { 
  922.         g_initDate = oDOW.toDateString();
  923.         swap(o);
  924.     }
  925. }
  926. ////////////////////////////////////////////////////////////////////////////////
  927. //
  928. //
  929. //
  930. ////////////////////////////////////////////////////////////////////////////////
  931. function renderUnDocked(o)
  932. {
  933.     var sType = o.divType;
  934.     var today = null;
  935.     var isToday = null;
  936.     var oDate = null;
  937.     var viewMode = "";
  938.  
  939.     if (o.id == "btnPrevious" || o.id == "btnNext")
  940.     {
  941.         if (sType == "changeMonth")
  942.         {
  943.             viewMode = "MONTH_UNDOCKED";
  944.         }
  945.         else if (sType == "year")
  946.         {
  947.             viewMode = "tID";
  948.         }
  949.     }
  950.     else
  951.     {
  952.         viewMode = o.id;
  953.     }
  954.  
  955.     g_mySettings.saveUnDocked(viewMode);
  956.  
  957.     switch (sType)
  958.     {
  959.         case "dow": 
  960.                 gView = "month";
  961.                 if (! System.Gadget.docked)
  962.                 {
  963.                     g_filter = 1;
  964.                 }
  965.                 divFilterBottomUndocked.filters[g_filter].enabled = true;
  966.                 divFilterBottomUndocked.filters[g_filter].Apply();
  967.                 today = new Date(o.d);
  968.                 if (o.d != today.toDateString())
  969.                     today.setDate(today.getDate()+1);
  970.                 DAY_UNDOCKED.day.initDay(today);
  971.                 g_initDate = today.toDateString();
  972.                 isToday=today.toDateString()==new Date().toDateString(); 
  973.             
  974.                 if (isToday)
  975.                 {                                
  976.                     divBgImageUnDocked.style.backgroundImage = "url(images/calendar_single_bkg_orange.png)";
  977.                     g_todayView = true;
  978.                     setTimeout("showBackground(0);",0);
  979.                 }
  980.                 else
  981.                 {
  982.                     divBgImageUnDocked.style.backgroundImage = "url(images/calendar_single_bkg.png)";
  983.                     g_todayView = false;
  984.                     setTimeout("showBackground(1);",0);
  985.                 }
  986.                 divFilterBottomUndocked.filters[g_filter].Play(); 
  987.                 if (o.id == "curlUnDocked")
  988.                 {
  989.                     swap(DAY_UNDOCKED);
  990.                 }
  991.                 break;
  992.                     
  993.         case "year":
  994.                 gView = "year";
  995.                 
  996.                 divFilterTopUndocked.filters[g_filter].enabled = true;
  997.                 divPrevNext.className = "prevnext_unDocked";
  998.                 divPrevNext.style.visibility = "visible";                
  999.                 divFilterTopUndocked.filters[g_filter].Apply();
  1000.                 today = new Date(g_initDate);
  1001.                 if (g_initDate != today.toDateString())
  1002.                     today.setDate(today.getDate()+1);
  1003.                 YEAR_UNDOCKED.year.initYear(today);
  1004.                 YEAR_UNDOCKED.style.visibility = "visible";
  1005.                 MONTH_UNDOCKED.style.visibility = "hidden";
  1006.             
  1007.                 divFilterTopUndocked.filters[g_filter].Play();
  1008.                 tID.divType="reset"; 
  1009.                 break;
  1010.                 
  1011.         case "zoomMonth":
  1012.                 oDate = new Date(g_initDate);
  1013.                 if (g_initDate != oDate.toDateString())
  1014.                     oDate.setDate(oDate.getDate()+1);
  1015.                 oDate.setMonth(o.m);
  1016.                 g_initDate = oDate.toDateString();
  1017.                 o.divType = 'day';
  1018.                 swap(o);
  1019.                 break;
  1020.  
  1021.         case "changeMonth": 
  1022.                 o.divType = 'day';
  1023.                 g_filter = 0;
  1024.                 swap(o);
  1025.                 break;
  1026.                 
  1027.         case "changeYear": 
  1028.                 o.divType = 'year';
  1029.                 g_filter = 0;
  1030.                 swap(o);
  1031.                 break; 
  1032.                 
  1033.         case "day":
  1034.                 gView = "month";
  1035.                 MONTH_UNDOCKED.month.initMonth(new Date(g_initDate));
  1036.                 divFilterTopUndocked.filters[g_filter].enabled = true;            
  1037.                 divFilterTopUndocked.filters[g_filter].Apply();
  1038.                 YEAR_UNDOCKED.style.visibility = "hidden";
  1039.                 MONTH_UNDOCKED.style.visibility = "visible";
  1040.                 divFilterTopUndocked.filters[g_filter].Play();
  1041.                 showControls(true);
  1042.                 tID.divType="year";
  1043.                 break;
  1044.     }
  1045. }
  1046. ////////////////////////////////////////////////////////////////////////////////
  1047. //
  1048. //
  1049. //
  1050. ////////////////////////////////////////////////////////////////////////////////
  1051. function renderDocked(o)
  1052.     var sType = o.divType;
  1053.     var today = null;
  1054.     var isToday = null;
  1055.     var oDate = null;
  1056.     
  1057.  g_mySettings.save(o.id,o.divType);
  1058.  
  1059.  switch (sType)
  1060.     {
  1061.         case "changeMonth": 
  1062.                 o.divType = 'day';
  1063.                 g_filter = 1;
  1064.                 swap(o);
  1065.                 break;
  1066.                 
  1067.         case "changeYear": 
  1068.                 o.divType = 'year';
  1069.                 g_filter = 1;
  1070.                 swap(o);
  1071.                 break;
  1072.                 
  1073.         case "zoomMonth":
  1074.                 oDate = new Date(g_initDate);
  1075.                 if (g_initDate != oDate.toDateString())
  1076.                     oDate.setDate(oDate.getDate()+1);
  1077.                 oDate.setMonth(o.m);
  1078.                 g_initDate = oDate.toDateString();
  1079.                 o.divType = 'day';
  1080.                 g_filter = 0;
  1081.                 swap(o);
  1082.                 break;
  1083.                 
  1084.         case "resetMonth":
  1085.                 g_initDate = new Date().toDateString();
  1086.                 o.divType = 'day';
  1087.                 swap(o);
  1088.                 break;
  1089.  
  1090.         case "dow":
  1091.                 gView = "dow";
  1092.                 if (o.id != "curlDocked")
  1093.                 {
  1094.                     o.divType = "day";
  1095.                 }
  1096.                 divFilterDocked.filters[g_filter].enabled = true;
  1097.                 divFilterDocked.filters[g_filter].Apply();
  1098.                 today=new Date(o.d);
  1099.                 if (o.d != today.toDateString())
  1100.                     today.setDate(today.getDate()+1);
  1101.                 Calendar(DAY_DOCKED).day.initDay(today);            
  1102.                 DAY_DOCKED.style.visibility = "visible";
  1103.                 MONTH_DOCKED.style.visibility = "hidden"; 
  1104.                 isToday=today.toDateString()==new Date().toDateString(); 
  1105.             
  1106.                 if (isToday)
  1107.                 {            
  1108.                     divBgImageDocked.style.backgroundImage = "url(images/calendar_single_orange.png)";
  1109.                     g_todayView = true;
  1110.                     setTimeout("showBackground(0);",0);
  1111.                 }
  1112.                 else
  1113.                 {
  1114.                     divBgImageDocked.style.backgroundImage = "url(images/calendar_single.png)";
  1115.                     g_todayView = false;
  1116.                     setTimeout("showBackground(1);",0);
  1117.                 }
  1118.                 divFilterDocked.filters[g_filter].Play();
  1119.                 showControls(false); 
  1120.                 break;
  1121.                 
  1122.         case "day":
  1123.                 g_curl_img.style.visibility = "hidden";
  1124.                 g_curl_hitRegion.style.visibility = "hidden";
  1125.                 gView = "month";
  1126.                 today=new Date(g_initDate);
  1127.                 if (g_initDate != today.toDateString())
  1128.                     today.setDate(today.getDate()+1);
  1129.                 MONTH_DOCKED.month.initMonth(today);
  1130.                 divFilterDocked.filters[g_filter].enabled = true;            
  1131.                 divFilterDocked.filters[g_filter].Apply();
  1132.                 YEAR_DOCKED.style.visibility = "hidden";
  1133.                 DAY_DOCKED.style.visibility = "hidden";
  1134.                 MONTH_DOCKED.style.visibility = "visible";
  1135.                 divBgImageDocked.style.backgroundImage = "url(images/calendar_single.png)";
  1136.                 divFilterDocked.filters[g_filter].Play();
  1137.                 showControls(true);
  1138.                 showBackground(1);
  1139.                 tID.divType="year";
  1140.                 break;
  1141.  
  1142.         case "year":
  1143.                 gView = "year";
  1144.                 
  1145.                 g_curl_img.style.visibility = "hidden";
  1146.                 g_curl_hitRegion.style.visibility = "hidden";
  1147.                 divFilterDocked.filters[0].enabled = true;
  1148.                 divFilterDocked.filters[0].Apply();
  1149.                 today=new Date(g_initDate);
  1150.                 if (g_initDate != today.toDateString())
  1151.                     today.setDate(today.getDate()+1);
  1152.                 YEAR_DOCKED.year.initYear(today);
  1153.                 YEAR_DOCKED.style.visibility = "visible";
  1154.                 MONTH_DOCKED.style.visibility = "hidden";
  1155.                 divBgImageDocked.style.backgroundImage = "url(images/calendar_single.png)";
  1156.                 divFilterDocked.filters[0].Play(); 
  1157.                 showBackground(1); 
  1158.                 showControls(true);
  1159.                 tID.divType="reset"; 
  1160.                 break;                
  1161.     }
  1162.     
  1163.  
  1164. }
  1165. ////////////////////////////////////////////////////////////////////////////////
  1166. //
  1167. //
  1168. //
  1169. ////////////////////////////////////////////////////////////////////////////////
  1170. function showBackground(skin)
  1171. {
  1172.     var bgFile = "url(images/calendar_single.png)";
  1173.     
  1174.     switch (skin)
  1175.     {
  1176.         case 0 :
  1177.             if (System.Gadget.docked)
  1178.             {
  1179.                 bgFile = "url(images/calendar_single_orange.png)";
  1180.             }
  1181.             else
  1182.             {
  1183.                 bgFile = "url(images/calendar_double_orange.png)";
  1184.             }
  1185.             break;
  1186.             
  1187.         case 1 :
  1188.             if (System.Gadget.docked)
  1189.             {
  1190.                 bgFile = "url(images/calendar_single.png)";
  1191.             }
  1192.             else
  1193.             {
  1194.                 bgFile = "url(images/calendar_double.png)";
  1195.             }        
  1196.             break;    
  1197.     }
  1198.  
  1199.     setBackground(bgFile);
  1200. }
  1201. ////////////////////////////////////////////////////////////////////////////////
  1202. //
  1203. //
  1204. //
  1205. ////////////////////////////////////////////////////////////////////////////////
  1206. function showControls(show)
  1207. {
  1208.     var showHide = "hidden";
  1209.     
  1210.     if (show)
  1211.     {
  1212.         showHide = "visible";
  1213.     }
  1214.     
  1215.     dockedCalendarRing.style.visibility = showHide;
  1216.     divPrevNext.style.visibility = showHide;
  1217. }
  1218. ////////////////////////////////////////////////////////////////////////////////
  1219. //
  1220. //
  1221. //
  1222. ////////////////////////////////////////////////////////////////////////////////
  1223. document.onmouseover=document.onmouseout=function(){
  1224.     var e=event.srcElement;
  1225.     if(e.omo!=null)
  1226.         e.className=event.type=="mouseout"?e.className.replace(/ hot/,""):e.className+" hot";
  1227. }
  1228.