<!--

// Imagery functions

// Preload images that may be swapped in/out while page is viewed
// Call from the BODY tag's "onLoad" event
// Arguments are strings of any full file/path names of images needing preloading, comma delimited
function faPreloadImages() {
	if (document.images) {
    var numImages = faPreloadImages.arguments.length;
    var imgURL = new Array(numImages);
		for (i=0; i<numImages; i+=1) {
      imgURL[i] = new Image();
      imgURL[i].src = faPreloadImages.arguments[i];
		}
	}
}

// swap images on an event, indefinite num of args
// args follow pattern: name of image, new image url to switch to, name, url, name, url, ...
// url MUST BE FULL URL (relative or definite), not just filename
function faImgSwap() {
	if (document.images) {
		for (i=0; i<faImgSwap.arguments.length; i+=2) {
			document[faImgSwap.arguments[i]].src = faImgSwap.arguments[i+1];
		}
	}
}

//----------------------------------

// Hub Menu functions

function faMousing(imgName,whichColor) {
  faImgSwap('faMenuBtn_'+imgName,'img/fa-img_menu_'+imgName+'_'+whichColor+'.png');
}

function faMouseOver(imgName) {
  whichMenu = imgName.substr(imgName.indexOf("_")+1);
  faMousing(whichMenu,'lite');
}

function faMouseOut(imgName) {
  whichMenu = imgName.substr(imgName.indexOf("_")+1);
  faMousing(whichMenu,'norm');
}

//----------------------------------

// determine the present year
// write into the document the copyright-eligible years from FirstYear (given argument) to present year
function faCopyrightYears(firstYear) {
  var now_time = new Date();

  var now_year = now_time.getYear();
  if (now_year < 2000)
    now_year = now_year + 1900;
  document.write (firstYear);
  if (now_year>firstYear)
    document.write ('-'+now_year+' ');
}


// --------------------------------------

// E-MAIL SUBMISSION FORM VALIDATION AND SUBMISSION

// E-mail submission form validation
function faIsContactValid(formName,badMessageAlert,badEmailAlert) {
// Determine the valid possible characters in an e-mail address
  var legalEmailChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-.@';

// Get the Email and Message field values from the form
  var valueEmail = document.getElementById(formName).required_email.value;
  var valueMessage = document.getElementById(formName).required_message.value;

// Check the Message - empty message activates alert
  if (valueMessage.length < 2) {
    alert(badMessageAlert);
    return false;
  }

// Initialize the validity of the Email field (to true - any mistakes will falsify it)
  var validEmail = true;
// Empty Email is invalid
  if (valueEmail == "") {
    validEmail = false;
  }
// Email without an "@" in a proper place (between username and domain) is invalid
  if (valueEmail.indexOf("@") < 1 || valueEmail.indexOf("@") > (valueEmail.length-5) || valueEmail.indexOf("@") != valueEmail.lastIndexOf("@")) {
    validEmail = false;
  }
// Email without a "." in a proper place (between domain and TLD) is invalid
  if (valueEmail.indexOf(".") < 1 || valueEmail.lastIndexOf(".") > (valueEmail.length-3)) {
    validEmail = false;
  }
  if (valueEmail.lastIndexOf(".") < valueEmail.indexOf("@") || valueEmail.substr((valueEmail.indexOf("@")-1),1) == "." || valueEmail.substr((valueEmail.indexOf("@")+1),1) == ".") {
    validEmail = false;
  }

// Email with any character that is not in the "Legal Email" character set is invalid
  for (i=0;i<valueEmail.length;i++) {
    if (legalEmailChars.indexOf(valueEmail.substr(i,1)) < 0) {
      validEmail = false;
    }
  }

// An invalid e-mail activates an alert
  if (!validEmail) {
    alert(badEmailAlert);
  }

// A valid e-mail returns true (and goes back to submit the form)
  return validEmail;
}

// E-mail submission form submission
// Checks validation - if good, submits, if not, returns false
function faContactSubmit(formName,badMessageAlert,badEmailAlert) {
  if (faIsContactValid(formName,badMessageAlert,badEmailAlert)) {
    document.getElementById(formName).submit();
  }
}


// --------------------------------------


//-->

