/*  yoga.js, last tweaked November 7, 2011  */

/*************************************
 *  In the function below the window-width sniffer works fine in over a dozen browsers that 
 *  howtocreate.co.uk and I have tested. (It failed in IE 5 for Mac, but nobody uses that anymore.)
 *
 *  This function first reads the pixel width of the window, depending on the browser. When it finds the 
 *  usual wider window, it writes the #left_lotus stylesheet ID and attributes into the document's HTML. 
 *  It simultaneously turns off display of #right_lotus, which would otherwise be displayed by default. 
 *  Yoga.css then uses the ID of #left_lotus to position and display it. (That styling could also have 
 *  been done here in the document.write.)
 *
 *  The original source and most testing for the first part of this is at http://www.howtocreate.co.uk.
*/
                                                               //
function displayLotus() {                                      // First get the window width:
  var winWidth = 0;                                            //   Declare the (global) variable.
  if (typeof (window.innerWidth) == 'number') {                //   Test if property exists and then
    winWidth = window.innerWidth;                              //   get it, for all browsers except IE.
  }                                                            //   If that fails, for IE 6+ in strict mode
  else if (document.documentElement && document.documentElement.clientWidth){ // test for object & property 
    winWidth = document.documentElement.clientWidth;           //   and get the width if successful.
  }                                                            //   And if that fails, then ditto
  else if (document.body && document.body.clientWidth ) {      //   for IE 4 and 5-7 in quirks mode.
    winWidth = document.body.clientWidth;                      // Second,   
  }                                                            //   Test the window width, then  
  if (winWidth > 870) {                                        //   write the image ID and its attributes
    document.write( "<img id='left_lotus' src='images/transparentwikilotus146x100.png' width='146' height='100'>" 
    + "<style>#right_lotus{display:none}</style>" );           //   and override the default #right_lotus style.
  }                                                            // 
}

/*************************************
 *  This next function just produces today's date, seen on each page at the top of the right-hand column.
 *
 *  JavaScript's built-in class Date contains the methods getDay and getMonth which return integers. 
 *  To translate those integers into words, Sunday for example, this script uses each integer to access 
 *  that element of an array of days. 
 *
 *  The script in the HTML simply invokes this function as document.write(showDate());
 *  Since it runs in the browser, it depends on the user's computer calendar being correct.
*/

function showDate() {                                       // 
  var dateObject = new Date();                              // Instantiate/create a Date named dateObject.
  var daysArray = ['Sunday','Monday','Tuesday',             // Create an array of days...
    'Wednesday','Thursday','Friday','Saturday'];            // 
  var monthsArray = ['Jan','Feb','March','April','May',     // ...and an array of months.
    'June','July','August','Sept','Oct','Nov','Dec'];       //
                                                            // Build the string to be written:
  var dateString =                                          // Two methods are used in two arrays:
      daysArray[dateObject.getDay()] + ', '                 //   element [0] becomes 'Sunday' and
    + monthsArray[dateObject.getMonth()] + ' '              //   element [0] becomes 'Jan'.
    + dateObject.getDate() + ', '                           // Date's method getDate returns 1 thru 31 and
    + dateObject.getFullYear() + '.';                       //   getFullYear returns the 4-digit year.
  return dateString;                                        // Define the function's return value.
}                                                           //

/*************************************
* This font re-size function changes the text-size of #maincontent, but not the top header or bottom
* footer. It was originally to be only for Safari (which seemed to handle my font-sizes a little oddly),
* but was thought useful enough to be extended for users of all browsers.
*
* This is a modified version of the effective and elegantly compact code provided at
* http://davidwalsh.name/change-text-size-onclick-with-javascript . For comments, see that page.
*
* In the HTML this is invoked simply as onclick="resizeText(-1)" or onclick="resizeText(1)"
* so that it changes the text size by its current size minus or plus 5% (defaulting to 100%).
* It does not persist, however; that feature would require the use of a cookie.
*/

function resizeText(multiplier) {                                                 //
  if (document.getElementById("maincontent").style.fontSize == "") {              //
    document.getElementById("maincontent").style.fontSize = "100%";               //
  }                                                                               //
  var newSize = parseFloat(document.getElementById("maincontent").style.fontSize) //
   + (multiplier * 5) + "%";                                                      //
  document.getElementById("maincontent").style.fontSize = newSize;                //
}                                                                                 //

/*************************************
* This function creates one new (carefully sized) printWindow for displaying the printable pages,
* from the URL's specified on their pages. It might look unnecessarily complicated, but it's not.
* It's modified from the Mozilla Developer Network code at https://developer.mozilla.org .
* (Note that the window.open method does not open a new window for a named window that's already open.)
*/

var printWindow = null;                                     // Start fresh.
                                                            //
function openPrintWindow(Url) {                             // If the printWindow object doesn't exist
  if(printWindow == null || printWindow.closed) {           //  or the window is closed,
    printWindow = window.open(Url, "printWindow",           // Then create and open it, if necessary .
      "left=20,screenX=20,width=780,height=650,resizable=yes,scrollbars=yes"); // No spaces between quotes.
    printWindow.focus();                                    //  Make sure it's on top.
  }else if (printWindow) {                                  // If printWindow exists and is open, then
    printWindow = window.open(Url, "printWindow",           //  load the (new) Url.
      "left=20,screenX=20,width=780,height=650,resizable=yes,scrollbars=yes");
    printWindow.focus();                                    //  Bring it back on top, if needed, 
  }else {                                                   //   since Internet Explorer has issues.
    printWindow.focus();                                    //  Just to make sure (or try again).
  }                                                         // 
return false;
}


