
//*****************************************************
// Copyright:  © 2001 M H Payet
//
// File:       libQuote.js
// Language:	JavaScript
// Developer:  MHP
// Date:       Apr 2001
//
// Description:
//    Personal Website - weekly quote functions.
//    Must appear after libMain.js file.
//    To be included on Home web page only.
//*****************************************************

var currentDate = new Date();
var currentDayOfWeek = currentDate.getDay()
var currentDay = currentDate.getDate();      // dd
var currentMonth = currentDate.getMonth();   // mm
var currentYear = currentDate.getFullYear(); // yyyy

var weeklyQuote = new Array(51);             // One quote for weeks 0 - 51.

//=====================================================
// Cascading style sheet elements for quote table.
//=====================================================

function setQuoteCSS() {
   if (browserVer4plus) {
      document.writeln('<style type="text/css">');
      document.writeln('<!--');
      document.writeln('   div.weeksThought  {float: right}');

      document.writeln('   em.thoughtAuthor  {color: #000080}');

      document.writeln('   p.weeksThoughtTxt {');
      document.writeln('                        margin-left: 5%; margin-right: 5%;');
      document.writeln('                        color: #000080;');
      document.writeln('                     }');

      document.writeln('   td.weeksThought   {');
      document.writeln('                        width: 189px; height: 32px;');
      document.writeln('                        padding-top: 6px; padding-bottom: 14px;');
      document.writeln('                        color: #000080; font-size: 10pt;');
      document.writeln('                        font-weight: bold; text-align: center;');
      document.writeln('                        background-image: url(graphics/bkg/tblBot.gif);');
      document.writeln('                        background-repeat: no-repeat;');
      document.writeln('                     }');
      document.writeln('   td.weeksThoughtTxt');
      document.writeln('                     {');
      document.writeln('                        width: 189px;');
      document.writeln('                        padding: 0px;');
      document.writeln('                        background-image: url(graphics/bkg/tblMid.gif);');
      document.writeln('                     }');

      document.writeln('   th.weeksThought   {');
      document.writeln('                        width: 189px;');
      document.writeln('                        padding-top: 10px; padding-bottom: 6px;');
      document.writeln('                        color: #000080; font-size: 10pt;');
      document.writeln('                        background-image: url(graphics/bkg/tblTop.gif);');
      document.writeln('                        background-repeat: no-repeat;');
      document.writeln('                     }');
      document.writeln('-->');
      document.writeln('</style>');
   }
}

//=====================================================
// Quote list.
//=====================================================
// If browser version is OK for JavaScript 1.2+ then quote table
// will be output, otherwise, nothing will be shown.

// Create a custom object (quoteObj) with text and author properties.

function quoteObj(text, author) {
   this.text = text;
   this.author = author;
}

if (browserVer4plus) {
   // Create instances of the quote object in an array (weeklyQuote).

   weeklyQuote[0] = new quoteObj("For it isn't what we own or buy<br> " +
                                 "That signifies our wealth,<br>" +
                                 "It's the special gifts that have no price -<br>" +
                                 "Our family, friends, and health.",
                                 "Anonymous");
   weeklyQuote[1] = new quoteObj("You may be only one person in the world,<br>" +
                                 "But you may be the world to one person.",
                                 "D R");
   weeklyQuote[2] = new quoteObj("Do not follow where the path may lead.<br>" +
                                 "Go instead where there is no path and leave " +
                                 "a trail.", "Anonymous");
   weeklyQuote[3] = new quoteObj("For it is in giving that we receive.",
                                 "Saint Francis of Assisi");
   weeklyQuote[4] = new quoteObj("A smile costs nothing but gives so much.<br>" +
                                 "It enriches those who receive,<br>" +
                                 "Without making poorer those who give."
                                 , "Author Unknown");
   weeklyQuote[5] = new quoteObj("Multiply joys and divide sorrow<br>" +
                                 "By your presence and understanding.",
                                 "M H P");
   weeklyQuote[6] = new quoteObj("Depth of friendship does not depend upon " +
                                 "length of acquaintance.",
                                 "Rabindranath Tagore");
   weeklyQuote[7] = new quoteObj("To receive a present handsomely and in a " +
                                 "right spirit, even when you have none to " +
                                 "give in return, is to give one in return.",
                                 "Leigh Hunt");
   weeklyQuote[8] = new quoteObj("I'm not a failure if I don't make it...<br>" +
                                 "I'm a success because I tried.",
                                 "Author Unknown");
   weeklyQuote[9] = new quoteObj("Forgiveness is the fragrance the violet " +
                                 "sheds on the heel that has crushed it.",
                                 "Mark Twain");
   weeklyQuote[10] = new quoteObj("Some people are too tired to give you a smile<br>" +
                                  "Give them one of yours, as none need to smile<br>" +
                                  "So much as he/she who has no more to give.",
                                  "Author Unknown");
   weeklyQuote[11] = new quoteObj("I long to accomplish a great and noble " +
                                  "task, but it is my chief duty to accomplish " +
                                  "small tasks as if they were great and noble.",
                                  "Helen Keller");
   weeklyQuote[12] = new quoteObj("Each day grow older, and learn something " +
                                  "new.", "Solon");
   weeklyQuote[13] = new quoteObj("Experience is the hardest kind of teacher. " +
                                  "It gives you the test first, and the " +
                                  "lesson afterward.", "Anonymous");
   weeklyQuote[14] = new quoteObj("A richer present I design,<br>" +
                                  "A finished form, of work divine,<br>" +
                                  "Surpassing all the power of art;<br>" +
                                  "A thinking head, a grateful heart.<br>",
                                  "Mary Barber");
   weeklyQuote[15] = new quoteObj("The real measure of our wealth is our " +
                                  "worth if we lost our money.", "Anonymous");
   weeklyQuote[16] = new quoteObj("I want you to know that if you see " +
                                  "something worthwhile in what I am doing, " +
                                  "it is not by accident but because of " +
                                  "real direction and purpose.",
                                  "Vincent Van Gogh");
   weeklyQuote[17] = new quoteObj("The longings after something lost,<br>" +
                                  "The spirit's yearning cry,<br>" +
                                  "The striving after better hopes -<br>" +
                                  "These things can never die.",
                                  "Author Unknown");
   weeklyQuote[18] = new quoteObj("A diamond is a chunk of coal that made " +
                                  "good under pressure.", "Anonymous");
   weeklyQuote[19] = new quoteObj("Here's to your love, health, and wealth - " +
                                  "and time to enjoy each.", "Spanish Proverb");
   weeklyQuote[20] = new quoteObj("A thirst for knowledge may be quenched " +
                                  "by seeking truth.", "M H P");
   weeklyQuote[21] = new quoteObj("A kind word is like a Spring day.",
                                  "Russian Proverb");
   weeklyQuote[22] = new quoteObj("There is no living in love without some " +
                                  "sorrow; but the greatest sorrow is not to " +
                                  "love.", "St John of the Cross");
   weeklyQuote[23] = new quoteObj("As we grow old, the beauty steals inward.",
                                  "Ralph Waldo Emerson");
   weeklyQuote[24] = new quoteObj("Never discourage anyone who continually " +
                                  "makes progress, no matter how slow.",
                                  "Plato");
   weeklyQuote[25] = new quoteObj("Happiness is like jam.  You can't spread " +
                                  "even a little without getting some on " +
                                  "yourself.", "Anonymous");
   weeklyQuote[26] = new quoteObj("Freedom is the oxygen of the soul.",
                                  "Moshe Dayan");
   weeklyQuote[27] = new quoteObj("Excellence is never an accident.",
                                  "Anonymous");
   weeklyQuote[28] = new quoteObj("Every gift, though it be small, is in " +
                                  "reality great if given with affection.",
                                  "Pindar");
   weeklyQuote[29] = new quoteObj("No pessimist ever discovered the secrets " +
                                  "of the stars, or sailed to an uncharted " +
                                  "land, or opened a new heaven to the human " +
                                  "spirit.", "Helen Keller");
   weeklyQuote[30] = new quoteObj("Think that this day will never dawn again.",
                                  "Dante");
   weeklyQuote[31] = new quoteObj("Nothing is lost that thou didst give,<br>" +
                                  "Nothing destroyed that thou hast done.",
                                  "Anne Bront&#235");
   weeklyQuote[32] = new quoteObj("A smile creates happiness in the home, " +
                                  "fosters goodwill in business, and is the " +
                                  "countersign of friendship.",
                                  "Author Unknown");
   weeklyQuote[33] = new quoteObj("If there were no books,<br>" +
                                  "How would we know,<br>" +
                                  "The great minds at work?<br>" +
                                  "We cannot read minds -<br>" +
                                  "But we can read books.", "M H P");
   weeklyQuote[34] = new quoteObj("We are not primarily put on Earth to see " +
                                  "through one another, but to see one another " +
                                  "through.", "Peter de Vries");
   weeklyQuote[35] = new quoteObj("Kindness is more important than wisdom; " +
                                  "and the recognition of this is the " +
                                  "beginning of wisdom.", "Author Unknown");
   weeklyQuote[36] = new quoteObj("Never mistake knowledge for wisdom. " +
                                  "One helps you make a living; the other " +
                                  "helps you make a life.", "Sandra Carey");
   weeklyQuote[37] = new quoteObj("If there is any kindness I can show, or " +
                                  "any good thing I can do to any fellow " +
                                  "being, let me do it now, and not deter or " +
                                  "neglect it, as I shall not pass this way " +
                                  "again.", "William Penn");
   weeklyQuote[38] = new quoteObj("Dost thou love life?  Then do not squander " +
                                  "time, for that's the stuff life is made of.",
                                  "Benjamin Franklin");
   weeklyQuote[39] = new quoteObj("Far away there in the sunshine are my " +
                                  "highest aspirations.  I may not reach " +
                                  "them, but I can look up and see their " +
                                  "beauty, believe in them and try to follow " +
                                  "where they lead.", "Louisa May Alcott");
   weeklyQuote[40] = new quoteObj("We need more laugh wrinkles and less " +
                                  "worry warts.", "Author Unknown");
   weeklyQuote[41] = new quoteObj("The only way to have a friend is to " +
                                  "be one.", "Ralph Waldo Emerson");
   weeklyQuote[42] = new quoteObj("The best work is done with the heart " +
                                  "breaking, or overflowing.",
                                  "Mignon McLaughlin");
   weeklyQuote[43] = new quoteObj("It is one of life's laws that as soon as " +
                                  "one door closes, another opens.  But the " +
                                  "tragedy is that we look at the closed door " +
                                  "and disregard the open one.", "Andr&#233 Gide");
   weeklyQuote[44] = new quoteObj("In order to create there must be a " +
                                  "dynamic force, and what force is more " +
                                  "potent than love.", "Igor Stravinsky");
   weeklyQuote[45] = new quoteObj("Laughter is a tranquillizer with no side " +
                                  "effects.", "Anonymous");
   weeklyQuote[46] = new quoteObj("Life is no brief candle to me.  It is a " +
                                  "sort of splendid torch which I've got to " +
                                  "hold up for the moment and I want to make " +
                                  "it burn as brightly as possible before " +
                                  "handing it on to future generations.",
                                  "George Bernard Shaw");
   weeklyQuote[47] = new quoteObj("Happiness lies in the joy of achievement " +
                                  "and the thrill of creative effort.",
                                  "Franklin Roosevelt");
   weeklyQuote[48] = new quoteObj("The highest reward for a person's toil " +
                                  "is not what they get for it, but what " +
                                  "they become by it.", "John Ruskin");
   weeklyQuote[49] = new quoteObj("A smile... cannot be bought, begged, " +
                                  "borrowed, or stolen, for it is something " +
                                  "that is of no value to anyone until it is " +
                                  "given away.", "Author Unknown");
   weeklyQuote[50] = new quoteObj("Rest is not idleness, and to lie " +
                                  "sometimes on the grass under the trees " +
                                  "on a summer's day, listening to the " +
                                  "murmur of water, or watching the clouds " +
                                  "float across the sky, is by no means a " +
                                  "waste of time", "Sir J. Lubbock");
   weeklyQuote[51] = new quoteObj("Let us be grateful to people who make us " +
                                  "happy; they are the charming gardeners who " +
                                  "make our souls blossom.", "Marcel Proust");
}
         
//=====================================================
// Get week of the year.
//=====================================================

function weekOfTheYear() {
   // Get first day of year, string date format must be (mm dd, yyyy).
   // Create instance of date object for the first day of the current year,
   // and for the current date, then get the milliseconds value of these
   // (baseline date is January 01, 1970).

   var stringDate = "January 01, " + currentYear;
   var firstDayOfYear = new Date(stringDate);
   var firstDayOfYearNum = firstDayOfYear.valueOf();
   var currentDateNum = currentDate.valueOf();

   // Get current date to calculate how many days have elapsed since the first
   // day of the current year.  This will then be used to obtain the current
   // week of the year.

   var daysElapsed = (currentDateNum - firstDayOfYearNum);
   var dayOfYear = (daysElapsed/1000/60/60/24 + 1);   // Add 1 as zero-based.
   weekOfYear = Math.floor(dayOfYear/7 + 1);          // Add 1 as zero-based.

   // Calculation for weekOfYear should be within range of 0 - 51 but
   // just in case, set back to zero if out of this range otherwise will
   // have problem with array.

   if ((weekOfYear < 0) || (weekOfYear > 51)) weekOfYear = 0;
   return weekOfYear
}

//=====================================================
// Get current day name.
//=====================================================

function getCurrentDayName(currentDayOfWeekNumber) {
   dayName = new Array(7);

   dayName[0] = "Sun";
   dayName[1] = "Mon";
   dayName[2] = "Tues";
   dayName[3] = "Wed";
   dayName[4] = "Thur";
   dayName[5] = "Fri";
   dayName[6] = "Sat";

   return dayName[currentDayOfWeekNumber];
}           
            
//=====================================================
// Get current month name.
//=====================================================

function getCurrentMonthName(currentMonthNumber) {
   monthName = new Array(12);

   monthName[0] = "January";
   monthName[1] = "February";
   monthName[2] = "March";
   monthName[3] = "April";
   monthName[4] = "May";
   monthName[5] = "June";
   monthName[6] = "July";
   monthName[7] = "August";
   monthName[8] = "September";
   monthName[9] = "October";
   monthName[10] = "November";
   monthName[11] = "December";

   return monthName[currentMonthNumber];
}

//=====================================================
// Output quote of the week.
//=====================================================

function outputQuoteOfTheWeek() {
   var weekOfYear = weekOfTheYear();

   if (browserVer4plus) {
      if (browserID == "MSIE") document.writeln('<br>');

      document.writeln('<div class="weeksThought">');
      document.writeln('   <table cellSpacing=0 cellPadding=3 width="189px" border=0>');
      document.writeln('      <tr><th class="weeksThought">Thought for the Week</th></tr>');
      document.writeln('      <tr>');
      document.writeln('         <td class="weeksThoughtTxt">');
      document.writeln('            <p class="weeksThoughtTxt">');
      document.writeln(                weeklyQuote[weekOfYear].text + '<br>');
      document.writeln('               <em class="ThoughtAuthor">- ' + weeklyQuote[weekOfYear].author + '</em>');
      document.writeln('            </p>');
      document.writeln('         </td>');
      document.writeln('      </tr>');
      document.writeln('      <tr>');
      document.writeln('         <td class="weeksThought">' + getCurrentDayName(currentDayOfWeek) + ' ' +
                                    currentDay + ' ' + getCurrentMonthName(currentMonth) + ' ' + currentYear + '</td>');
      document.writeln('      </tr>');
      document.writeln('   </table>');
      document.writeln('</div>');
   }
}

//=====================================================
//
//=====================================================
