// -----------------------------------------------------------------------------
// rhlib.js		(Copyright 2003 Rick Harvey)
//
// Collection of useful javascript routines
// -----------------------------------------------------------------------------

var oldBrowser = rhOldBrowser()


// -----------------------------------------------------------------------------
// MENU routines			(RHH May 2003)
//
// Interface into Mike Hall's Menu Bar
// * Required because Menu Bar javascript doesn't work in old browsers.
// * For old browsers or no Javascript, the submenu links will be displayed
//   at the bottom of the page (they won't get turned off by the stylesheet)
// -----------------------------------------------------------------------------

// necessary because IE5.0 is missing the array.push() used by menu bar
function _Array_push()
{
  for (var a = 0; a < arguments.length; a++)
    this[this.length] = arguments[a]
  return this.length
}

// necessary to hide CSS2 from old/buggy/JS-disabled browsers
function rhMenuCSS(cssfile)
{
  if (oldBrowser)
    return
  document.write("<link rel=\"stylesheet\" href=\"" + cssfile + "\" type=\"text/css\">")
}

// necessary to avoid calling old/buggy JavaScript
function rhMenu(event, menuId)
{
  if (oldBrowser)
    return
  if (window.Array && Array.prototype && !Array.prototype.push)
    Array.prototype.push = _Array_push
  buttonMouseover(event, menuId)
}


// -----------------------------------------------------------------------------
// OLD BROWSER routines		(RHH June 2003)
//
// Basically, any Browser that supports standard DOM functions is OK
// e.g. document.getElementById, document.getElementsByTagName
//
// However, some browsers are really buggy and the menu misbehaves.
// e.g.	IE 5.2 for MAC, Opera 5.0 (on Linux)
// -----------------------------------------------------------------------------

function rhOldBrowser()
{
  if (! document.getElementById || ! document.getElementsByTagName)
    return true		// old browser
    
  // http://www.mozilla.org/docs/web-developer/sniffer/browser_type.php
  // Note: On IE5, is_major returns 4
  var agt = navigator.userAgent.toLowerCase()
  var is_major = parseInt(navigator.appVersion)
  var is_mac = (agt.indexOf("mac") != -1)
  var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1))
  var is_ie5x = (is_ie && (is_major == 4) && (agt.indexOf("msie 5") != -1))
  var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1)

  if (is_ie5x && is_mac || is_opera5)
    return true		// buggy browser
    
  return false;		// not an old browser
}

function rhDivertToSecureSite(site)
{
  var agt = navigator.userAgent.toLowerCase()
  var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1))
  var is_ie5_0 = (is_ie && (agt.indexOf("msie 5.0") != -1))
  
  if (! rhOldBrowser() && !is_ie5_0 && location.href.substr(0,5) == "http:")
    location.href = site
  return false    
}

// Formatting is for really old browsers (who don't understand style)
function rhPrintOldBrowserWarning()
{
  if (oldBrowser)
    document.write("<br><font color=\"#FF0000\">Your browser is does not support modern"
      + " web standards.  Please <a href=\"http://webstandards.org/upgrade/\">upgrade</a>"
      + " or use a differnet browser to view this site properly.</font><br>&nbsp;")
}

// -----------------------------------------------------------------------------
// DOCUMENT routines		(RHH June 2003)
//
// Document date printing notes:
// (1) Use Date function to normalise document.lastModified formats.
//	MS format   : MM/DD/YYYY HH:MM:SS
//	NN format   : day, month DD, YYYY HH:MM:SS
//	Opera format: day, DD MON YYYY HH:MM:SS GMT
// (2) SSI servers pipe pages so document.lastModified can be "epoch" or "now"
//     If on an SSI server, the calling HTML should insert the date using SSI:
//	<!--#config timefmt="(last modified: %d-%b-%Y)" -->
//	<!--#echo var="LAST_MODIFIED" -->
// -----------------------------------------------------------------------------

// prints date in DD-mmm-YYYY format
function rhPrintDocModDate()
{
  var doc = new Date(document.lastModified)
  var now = new Date()
  var epoch = new Date(0)
  // if SSI enabled IE gives "now" and NN4/NS7/Opera7 gives "epoch"
  if (doc.toString() == now.toString() || doc.toString() == epoch.toString())
    return
  var monthNames = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
  var day = doc.getDate()
  var month = monthNames[doc.getMonth()]
  var year = doc.getFullYear()
  // Must put all the HTML here in case Javascript is disabled or server using SSI
  document.write("(last modified: " + day + "-" + month + "-" + year + ")")
}

// necessary to avoid spam-bots
function rhPrintEmailLink(leadin)
{
  var colon = ":"
  var atsign = "@"
  var address = "info" + atsign + "RangeaireVision.com"
  var mailto = "mailto" + colon + address
  document.write(leadin + "<a href=\"" + mailto +"\">" + address + "</a>")
}

