<!--
/* PAGE ONLOAD EVENTS */

window.onload = function() {
  createMouseovers();
  };

// MOUSEOVER CREATION AND PRELOAD SCRIPT

function createMouseovers() {
  var overExt = "-ON";
  if (document.getElementsByTagName) {
    var imgs = document.getElementsByTagName("IMG")
    var i, dotAt, imgFile, imgExt, preloads = new Array(imgs.length);
    for (i = 0; i < imgs.length; i++) {
      if (hasClassName(imgs[i], "mouseover")) {
        dotAt  = imgs[i].src.lastIndexOf(".");
        if (dotAt > 0) {
          imgFile = imgs[i].src.substr(0,dotAt);
          imgExt  = imgs[i].src.substr(dotAt+1);
          if (imgFile.lastIndexOf(overExt) == imgFile.length - overExt.length) {
            // do nothing; image is already on
            }
          else {
            eval("imgs[i].onmouseover = function () {this.src = '" + imgFile + overExt + "." + imgExt + "'};");
            eval("imgs[i].onmouseout = function () {this.src = '" + imgFile + "." + imgExt + "'};");
            preloads[i]     = new Image;
            preloads[i].src = imgFile + overExt+ "." + imgExt;
            }
          }
        }
      }
    }
  }

/* MISCELLANEOUS SCRIPTS */

function writeEmailAddress(addressee,subject,domain) {
  if (writeEmailAddress.arguments.length < 3 || domain == "") {
    domain = "slocoastalliance.org";
    }
  var emailAddress = addressee + "@" + domain;
  if (writeEmailAddress.arguments.length < 2) {
    subject = "Inquiry from " + domain;
    }
  document.write("<a href=\"mailto:" + emailAddress + "?subject=" + subject + "\">" + emailAddress + "</a>");
  }

function openInNewWindow(whichLink,whichLinkText) {
  if (openInNewWindow.arguments.length < 2) whichLinkText = "this link";
  if (window.confirm("Would you like to open " + whichLinkText + " in a new browser window, so that the " + siteName + " site can remain open?\n\nIf so, you may need to disable any pop-up blockers you have installed.")) {
    if (!whichLink.oTarget) whichLink.oTarget = whichLink.target;
    whichLink.target = "_blank";
    }
  else {
    if ((whichLink.oTarget) && (whichLink.oTarget != "_blank")) whichLink.target = whichLink.oTarget;
    else whichLink.target = "";
    }
  }

function removeExtraSpaces(str) {
/*
  Remove any redundant spaces or line returns within the string and eliminate
  leading & trailing spaces and line returns. Requires regular expressions (availabe as of JavaScript 1.2).
  (Note that we use an eval statement to prevent earlier browsers from choking on the regex syntax.
  Also note that all the backslashes in the regex pattern have to be escaped as a result.)
*/
  var output = str;
  if (window.RegExp) {
    output = eval("output.replace(/[ \\t]{2,}/g,' ')");
    output = eval("output.replace(/[\\r\\n]{2,}/g,'\\r\\n')");
    output = eval("output.replace(/^[\\s]*/,'')");
    output = eval("output.replace(/[\\s]*$/,'')");
    }
  return output;
  }

// Iterates through all class names for an object and returns true if specified class name is found
function hasClassName(obj, className) {
  if (obj && obj.className) {
    var objClass = removeExtraSpaces(obj.className);
    arrClasses = objClass.split(" ");
    for (var c=0; c<arrClasses.length; c++) {
      if (className == arrClasses[c])
        return true;
      }
    }
  return false;
  }
//-->
