
//*****************************************************
// Copyright:  © 2006 M H Payet
//
// File:       libMain.js
// Language:	JavaScript
// Developer:  MHP
// Date:       Jun 2006
//
// Description:
//    TA Website - Main library of functions.
//    To be included in all web pages.
//*****************************************************

// Global vars
var localCartHandling = 0.10; // Aus: Flat $ added to shipping total
var OSCartHandling = 0.50;    // OS: Flat $ added to shipping total
// pkg costs in nopcart-chk.js

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) {
   }
   else {
      document.writeln('   #contactBkg1 {background: url(graphics/shopBkg.jpg) #ffffff no-repeat; background-position: right top;}');
      document.writeln('   #bayBkg1     {background: url(../../graphics/bkg/bayBkg1.jpg) #ffffff repeat-x; background-position: left bottom;}');

      getDisplayDimensions();
      if (screenWidth >= 1100) {
         document.writeln('   .colContent          {width: 950px}');
         document.writeln('   .colMainContent      {width: 90%}');
         document.writeln('   #bayBkg1             {background: url(../../graphics/bkg/bayBkg2.jpg) #ffffff repeat-x; background-position: left bottom;}');
      }
   }
   document.writeln('   ul.boxIndent, ul.special {padding-left: 0px; padding-right: 1px; margin-left: 20px}');
   document.writeln('   .noMargBot, #noMargBot {margin-bottom: 0px}');
}
else if (browserID == "NN") {
   if (browserVer < 5.0) {
      document.writeln('   span.itemDate {font-size: smaller}');
   }
   else {
      document.writeln('   ul.boxIndent, ul.special {padding-left: 0px; padding-right: 1px; margin-left: 20px}');
      document.writeln('   #contactBkg1 {background: url(graphics/shopBkg.jpg) #ffffff no-repeat; background-position: right top;}');
      document.writeln('   #bayBkg1     {background: url(../graphics/bkg/bayBkg1.jpg) #ffffff repeat-x; background-position: left bottom;}');
      document.writeln('   .smallerTxt, #smallerTxt, input, select, textarea {font-size: 95%}');
      document.writeln('   .cartFooter, .footerL, .footerR, .footerC {font-size: 85%}');
      document.writeln('   .x-smallerTxt, #x-smallerTxt {font-size: 85%}');
      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, .leftNavBar a.norm:hover {text-decoration: none}');

      getDisplayDimensions();
      if (screenWidth >= 1100) {
         document.writeln('   .colContent          {width: 950px}');
         document.writeln('   .colMainContent      {width: 90%}');
         document.writeln('   #bayBkg1             {background: url(../../graphics/bkg/bayBkg2.jpg) #ffffff repeat-x; background-position: left bottom;}');
      }
   }
}
else if (browserID == "OPERA") {
   document.writeln('   ul.boxIndent, ul.special {padding-left: 0px; padding-right: 1px; margin-left: 20px}');
}
else {
}
document.writeln('-->');
document.writeln('</style>');

//=====================================================
// Show date modified - used in page footers.
//=====================================================

function showDateModified() {
   return // Do not use as php states current date & time because it is dynamically generated.
   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;
   }
}

//=====================================================
// Open new browser window
//=====================================================

function openWin(fileName, windowName, windowWidth, windowHeight, windowResize, showbars) {
   var windowAttributes;

   if ((windowWidth == null) || (windowHeight == null)) getDisplayDimensions();
 
   if (windowWidth == null) {
      if (screenWidth <= 640) windowWidth = 450;
      else {
         if (screenWidth <= 800) windowWidth = 700;
         else windowWidth = 775;
      }
   }
   if (windowHeight == null) {
      if (screenHeight <= 480) windowHeight = 250;
      else {
         if (screenHeight <= 600) windowHeight = 350;
         else windowHeight = 400;
      }
   }
   if (windowResize==null) windowResize="no";
   if (showbars=="bars") showbars = ", toolbar=yes, menubar=yes, status=yes, location=yes";
   else showbars = "";

   windowAttributes="'width=" + windowWidth;
   windowAttributes+=",height=" + windowHeight;
   windowAttributes+=",top=0, left=0";
   windowAttributes+=",resizable=" + windowResize;
   windowAttributes+=",scrollbars=yes" + showbars + "'";

   newWindow=window.open(fileName, windowName, eval(windowAttributes));

   // To overcome Netscape bug (in certain versions) re: preventing
   // display of document with window.open method, repeat open
   // statement.

   if ((browserID == "NN") && (browserVer < 5.0)) {
      newWindow=window.open(fileName, windowName, eval(windowAttributes));
   }
   newWindow.focus();
}

//=====================================================
// Status messages.
//=====================================================

function statusMsg(msg) {
   window.status = msg;
   return true;
}

function defaultStatusMsg() {
   window.status = window.defaultStatus;
   return true;
}

//=====================================================
// Money formatting function
//=====================================================

function moneyFormat(input) {
   var dollars = Math.floor(input);
   var tmp = new String(input);
   var cents;

   for (var decimalAt=0; decimalAt<tmp.length; decimalAt++) {
      if (tmp.charAt(decimalAt)==".") break;
   }
   cents  = "" + Math.round(input * 100);
   cents = cents.substring(cents.length-2, cents.length)
   dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

   if (cents == "0") cents = "00";
   return(dollars + "." + cents);
}

//=====================================================
// Email URL to another person.
//=====================================================

function emailURL() {
   var bodyText = "I%20thought%20you%20might%20be%20interested%20in%20this%20website%20link:%20" + window.location;
   var linkRef = "mailto:?Subject=Textile%20Artistry%20Link.&body=" + bodyText;

   document.writeln('<br><a class="centre" href=' + linkRef + ' onMouseOver=\"return statusMsg(\'Email the link to this page to others.\')\" onMouseOut=\"return defaultStatusMsg()\" title="Email the link to this page to others." >Tell a Friend</a><br>');

}

//=====================================================
// 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\"><form action="http://www.google.com/search" method="get" onSubmit="Gsitesearch(this);" style="margin-top: 0px; margin-bottom: 0px;">');
   document.writeln('   <a class=\"norm\" href=\"http://www.google.com/\"><img src=\"http://www.google.com/logos/Logo_25wht.gif\" border=\"0\" alt=\"Google\"></a>');
   document.writeln('   <input name="q" type="hidden" />');
   document.writeln('   <input name="qfront" type="text" size=15 maxlength=255 /> <input type="submit" value="Search" />');
   document.writeln('</form></div>');
}

//=====================================================
//
//=====================================================


