
//*****************************************************
// Copyright:  © 2004 M H Payet
//
// File:       libMain.js
// Language:	JavaScript
// Developer:  MHP
// Date:       Mar 2004
//
// Description:
//    JTC Website - Main library of functions.
//    To be included in all web pages.
//*****************************************************

var screenWidth = 0;
var screenHeight = 0;

//=====================================================
// Browser detection.
//=====================================================

var browserType = navigator.userAgent.toLowerCase();
var browserVer = parseFloat(navigator.appVersion);
var browserID = "";
var browserVer4plus = false;

var macOS = false;
if (browserType.indexOf('mac') != -1) macOS = true;

// Check for non-MSIE and non-NN browsers first for JavaScript functions to
// ignore emulation of these two browsers.  Code will operate according to
// real browser ID otherwise outcome is unpredictable without
// thorough testing on these other browsers.

if (browserType.indexOf('opera') != -1) browserID = "OPERA"
else if (browserType.indexOf('webtv') != -1) browserID = "WEBTV"
else if (browserType.indexOf('msie') != -1) browserID = "MSIE"
else if (browserType.indexOf('mozilla') != -1) browserID = "NN"

// Get actual version number of MSIE browser (NN extracts this) to determine if > V4.0.

if ((browserID == "MSIE") && (browserVer == 4.0)) {
   var ver4 = browserType.substring(browserType.indexOf('msie'), browserType.length);
   browserVer = ver4.substring(ver4.indexOf(' '), ver4.indexOf(';'));

   // In case value returned is not a number, return 4.0 browser version again.
   if (isNaN(browserVer)) browserVer = 4.0;
}

// Check that current browser will support JavaScript code version 1.2+.
// If not, then any JavaScript 1.1- code may be executed.

if (((browserID == "MSIE") || (browserID == "NN")) && (browserVer >= 4.0)) browserVer4plus = true;

//=====================================================
// Browser-specific CSS element definitions.
//=====================================================

document.writeln('<style type="text/css">');
document.writeln('<!--');
if (browserID == "MSIE") {
   if (browserVer < 6.0) {
      document.writeln('   a.linkBar, .live {width: 159px; border: 1px solid #000080; padding-bottom: 1px}');
      document.writeln('   a.linkBar:hover {border: 1px solid #B0C4DE}');
   }
   else {
      getDisplayDimensions();
      if (screenWidth >= 1100) {
         document.writeln('   #study-courses       {width: 50%}');
      }
   }
   document.writeln('   td.sideBar ul, td.sideBarMain ul, td.sideBarPic ul, td.sideBarHdr ul, td.navBar ul, td.navBar2 ul, td.navBar3 ul, td.pageNav ul, ul.special {padding-left: 0px; padding-right: 1px; margin-left: 20px}');
   document.writeln('   .live, a.linkBar {border: 1px solid #000080}');
   document.writeln('   a.linkBar:hover, a.linkBar:visited:hover {border: 1px solid #B0C4DE}');
   document.writeln('   .dashedBdr2 ul {padding-left: 0px; margin-left: 20px; margin-top: 3px; margin-bottom: 0px}');
 
}
else if (browserID == "NN") {
   document.writeln('   .smallerTxt, #smallerTxt, td.gallery, .topPage, td.footerC, td.footerL, td.footerR, td.navBar3 {font-size: 90%}');
   document.writeln('   td.sideBarPic, td.sideBarMain, #pic-cell, a.linkBar2, .dashedBdr2 {font-size: 90%}');
   document.writeln('   td.pageDate, span.itemDate {font-size: 90%}');

   if (browserVer < 5.0) {
      document.writeln('   td.main {padding: 0px}');
      document.writeln('   div.mainHdr {background: none}');
      document.writeln('   .live, td.navBar, td.navBar a, td.navBar2, td.navBar3 {padding: 0px}');
   }
   else {
      document.writeln('   h1 a:hover, h2 a:hover, h3 a:hover, h4 a:hover, h5 a:hover, h6 a:hover {text-decoration: none}');
      document.writeln('   a:hover, a:visited:hover, a.linkBar2:hover, a.linkBar2:visited:hover {text-decoration: none}');
      document.writeln('   td.sideBar ul, td.sideBarMain ul, td.sideBarPic ul, td.sideBarHdr ul, td.navBar ul, td.navBar2 ul, td.navBar3 ul, td.pageNav ul, ul.special {padding-left: 0px; padding-right: 1px; margin-left: 20px}');
      document.writeln('   .live, a.linkBar {border: 1px solid #000080}');
      document.writeln('   a.linkBar:hover, a.linkBar:visited:hover {border: 1px solid #B0C4DE}');
      document.writeln('   .dashedBdr2 ul {padding-left: 0px; margin-left: 20px; margin-top: 3px; margin-bottom: 0px}');

      getDisplayDimensions();
      if (screenWidth >= 1100) {
         document.writeln('   #study-courses       {width: 50%}');
      }
   }
}
else if (browserID == "OPERA") {
   document.writeln('   .smallerTxt, #smallerTxt, td.gallery, .topPage, td.footerC, td.footerL, td.footerR, td.navBar3 {font-size: 90%}');
   document.writeln('   td.sideBarPic, td.sideBarMain, #pic-cell, a.linkBar2, .dashedBdr2 {font-size: 90%}');
   document.writeln('   td.pageDate, span.itemDate {font-size: 90%}');

   document.writeln('   td.sideBar ul, td.sideBarMain ul, td.sideBarPic ul, td.sideBarHdr ul, td.navBar ul, td.navBar2 ul, td.navBar3 ul, td.pageNav ul, ul.special {padding-left: 0px; padding-right: 1px; margin-left: 20px}');
   document.writeln('   .dashedBdr2 ul {padding-left: 0px; margin-left: 20px; margin-top: 3px; margin-bottom: 0px}');
}
else {
   document.writeln('   div.mainHdr {background: none}');
}
document.writeln('-->');
document.writeln('</style>');

//=====================================================
// Show date modified - used in page footers.
//=====================================================

function showDateModified() {
   if (lastDateModified() != "") document.writeln("<span>Last modified: " + lastDateModified() + ", EST Australia.</span>");
   else  document.writeln("<span>Last modified: " + document.lastModified +  ".</span>");
}

//=====================================================
// Last date modified.
//=====================================================

function lastDateModified() {
   var someDate = new Date(document.lastModified);
   return someDate.toLocaleString();
}

//=====================================================
// Screen & Window Width & Height - global variables.
// Function must be called (in function called) within
// <body> section of web page.
//=====================================================

function getDisplayDimensions() {
   if ((browserVer4plus) || ((browserID == "OPERA") && (browserVer >= 6.0))) {
      screenWidth = screen.width;
      screenHeight = screen.height;
   }
}

//=====================================================
// Get current date name.
//=====================================================

var currentDateName = '&nbsp;';
var currentDate = new Date();
var currentDayOfWeek = currentDate.getDay()
var currentDay = currentDate.getDate();      // dd
var currentMonth = currentDate.getMonth();   // mm
var currentYear = currentDate.getFullYear(); // yyyy

function getCurrentDateShortName() {
   if ((browserVer4plus) || ((browserID == "OPERA") && (browserVer >= 6.0))) currentDateName = (getCurrentDayShortName(currentDayOfWeek) + ' ' + currentDay + ' ' + getCurrentMonthShortName(currentMonth) + ' ' + currentYear);
   return currentDateName;
}

//=====================================================
// Get current day name.
//=====================================================

function getCurrentDayShortName(currentDayOfWeekNumber) {
   var dayName = new Array(7);

   dayName[0] = "Sun";
   dayName[1] = "Mon";
   dayName[2] = "Tue";
   dayName[3] = "Wed";
   dayName[4] = "Thu";
   dayName[5] = "Fri";
   dayName[6] = "Sat";
   return dayName[currentDayOfWeekNumber];
}           

//=====================================================
// Get current month name.
//=====================================================

function getCurrentMonthShortName(currentMonthNumber) {
   var monthName = new Array(12);

   monthName[0] = "Jan";
   monthName[1] = "Feb";
   monthName[2] = "Mar";
   monthName[3] = "Apr";
   monthName[4] = "May";
   monthName[5] = "Jun";
   monthName[6] = "Jul";
   monthName[7] = "Aug";
   monthName[8] = "Sep";
   monthName[9] = "Oct";
   monthName[10] = "Nov";
   monthName[11] = "Dec";
   return monthName[currentMonthNumber];
}

//=====================================================
// Current Page Date Heading.
//=====================================================

function pageDateHeading() {
   return currentDateStr = getCurrentDateShortName();
}

//=====================================================
// Status messages.
//=====================================================

function statusMsg(msg) {
   window.status = msg;
   return true;
}

function defaultStatusMsg() {
   window.status = window.defaultStatus;
   return true;
}

//=====================================================
// Show link to Search page.
//=====================================================

function searchLink() {
   var showSearchLink = true; // Deactivate if required.
   if (showSearchLink)  document.writeln('<div class="right"><strong class="highlight">&laquo;</strong>&nbsp;<a href="http://www.jtc.edu.au/search.html">Search</a>&nbsp;<strong class="highlight">&raquo;</strong></div>')
   else                 document.writeln('&nbsp;');
}

//=====================================================
// Search site
//=====================================================

// Google Internal Site Search script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use

function Gsitesearch(curobj) {
   return curobj.q.value="site:"+domainroot+" "+curobj.qfront.value
}

function searchSite() {
   document.writeln('<div class="centre">');
   document.writeln('<form action="http://www.google.com/search" method="get" onSubmit="Gsitesearch(this);" style="margin-top: 0px; margin-bottom: 0px;">');
   document.writeln('   <span style="vertical-align: top"><a href="http://www.google.com/"><img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google"></a></span>');
   document.writeln('   <input name="q" type="hidden" />');
   document.writeln('   <input name="qfront" type="text" size=30 maxlength=255 /> <input type="submit" value="Site Search" title="Search our site"/>');
   document.writeln('</form></div>');
}

//=====================================================
// Show links to download various free viewers.
//=====================================================

function viewerLinks() {
   var showViewerLinks = true; // Deactivate if required.
   if (showViewerLinks) {
      document.writeln('<div class="centre" style="padding-left: 5px; padding-right: 5px;">');
      document.writeln('   <a class="linkBar2" href="http://get.adobe.com/reader/" target="_blank"><img src="http://www.jtc.edu.au/graphics/artwork/getacro.gif" width=76 height=27 alt="Get Adobe Reader." border=3 style="border-color: #000080;"><br>Get Adobe Reader to view PDF files</a>.<br><br>');
      document.writeln('   <a class="linkBar2" href="http://search.microsoft.com/results.aspx?mkt=en-US&setlang=en-US&q=%22PowerPoint+Viewer%22" target="_blank"><img src="http://www.jtc.edu.au/graphics/artwork/getppt.gif" width=76 height=25 alt="Get Microsoft PowerPoint Viewer." border=3 style="border-color: #000080;"><br>Get Microsoft PowerPoint Viewer</a>.</p><br><br>');
      document.writeln('</div>');
   }
   else document.writeln('&nbsp;');
}

//=====================================================
// Show common links on second-level pages.
//=====================================================

function showNavBarLinks() {
   document.writeln('<a class="linkBar2" href="http://www.express.org.au/" target="_blank" title="More news from around the Province."><img src="graphics/artwork/pe-logo01.gif" width=120 height=32 alt="Read the latest news from the Society of Jesus." border=3 style="border-color: #000080;"><br>Province Express</a><br><br>');
   document.writeln('<a class="linkBar2" href="http://www.jesuit.org.au/" target="_blank"><img src="graphics/artwork/sjLink01.gif" width=120 height=68 alt="Visit the Society of Jesus website." border=0><br>Society of Jesus</a><br><br>');
}

//=====================================================
//
//=====================================================
