<!--

// Common functions

// A dummy function in case I want a call to do absolutely NOTHING
function justDoNothing() {
// This function really does do nothing!
}

// 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 cakePreloadImages() {
	if (document.images) {
    var numImages = cakePreloadImages.arguments.length;
    var imgURL = new Array(numImages);
		for (i=0; i<numImages; i+=1) {
      imgURL[i] = new Image();
      imgURL[i].src = cakePreloadImages.arguments[i];
		}
	}
}

// Spawn a new window, with options
// args = URL, name of window, location x, location y, width, height, and type of window
// types: noFrills, withNav, solidSize, default
function cakeSpawn(url, winName, winX, winY, winWidth, winHeight, winType){
  switch (winType) {
    case "noFrills":
      winTypeString = "menubar=0,location=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0"
      break
    case "noScrolls":
      winTypeString = "menubar=0,location=0,resizable=1,scrollbars=0,status=0,titlebar=0,toolbar=0"
      break
    case "withNav":
      winTypeString = "menubar=1,location=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1"
      break
    case "solidSize":
      winTypeString = "menubar=0,location=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0"
      break
    default:
      winTypeString = "menubar=0,location=1,resizable=1,scrollbars=1,status=1,titlebar=0,toolbar=0"
  }
  window.open(url,winName,"width=" + winWidth + ",height=" + winHeight + "," + winTypeString +",left=" + winX + ",top=" + winY + ",screenX=" + winX + ",screenY=" + winY)
}

// simply go back one page
function cakeBack(){
  if (navigator.appName == "Microsoft Internet Explorer"){
    history.back();
  } else {
    window.back();
  }
}

// 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 cakeImgSwap() {
	if (document.images) {
		for (i=0; i<cakeImgSwap.arguments.length; i+=2) {
			document[cakeImgSwap.arguments[i]].src = cakeImgSwap.arguments[i+1];
		}
	}
}

//----------------------------------

// determine the present year
// write into the document the copyright-eligible years from FirstYear (given argument) to present year
function doCopyrightYears(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 cakeIsContactValid(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 cakeContactSubmit(formName,badMessageAlert,badEmailAlert) {
  if (cakeIsContactValid(formName,badMessageAlert,badEmailAlert)) {
    document.getElementById(formName).submit();
  }
}


// --------------------------------------

// --------------------------------------


//-->
