/*
 * SPP site common Javascripts
 * makeAddy creates an address object that holds an email address
 * sendMail sends an email to the address stored in the address object
 * WM_preloadImages() loads images ahead of time.
 */


function makeAddy(tld, domain, addy, subj){
/* Create an Address object to hold an email address
   you want to hide from spambots.

   This routine allows for constructing an address with or 
   without specifying a subject.

   Note that these address objects must be created on the page
   on which they will be used.
   
   Usage:
   obj_name = new makeAddy('edu', 'pubpolicy.gatech', 'webmaster');
   obj_name = new makeAddy('edu', 'pubpolicy.gatech', 'webmaster', 'testing');

    */
	this.tld = tld;
	this.domain = domain;
	this.addy = addy;
	this.subject = ''; //set subject to nothing in case subj isn't defined
	if (subj != null){ //if subj is defined (isn't null), change subject accordingly
		this.subject = subj;
	}
	this.getAddy = getAddy;
	this.sendMail = sendMail;
}


function getAddy(){
/* Get the address from an address object.

   Like makeAddy, getAddy includes provisions for subject 
   lines if specified, but doesn't require them.

   Usage:
   obj_name.getAddy();

   */
	var assembledAddy;
	assembledAddy = 'mail';
	assembledAddy = assembledAddy + 'to:';
	assembledAddy = assembledAddy + this.addy + '@' + this.domain + '.' + this.tld + '';
	if (this.subject != ''){
		assembledAddy = assembledAddy + '?subject=' + this.subject;
	}
	return assembledAddy;
}


function sendMail(){
/* Send mail to the address in an address object.

   Usage:
   obj_name.sendMail();
   
   */
//	alert(this.getAddy()); //alert to help debugging
	document.location.href = this.getAddy();
}


function WM_preloadImages() {
/*
WM_preloadImages()
Loads images into the browser's cache for later use.
Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Nadav Savio
Author Email: nadav@wired.com

Usage: WM_preloadImages('image 1 URL', 'image 2 URL', 'image 3 URL', ...);
*/

  // Don't bother if there's no document.images
  if (document.images) {
    // Make an array (on the document.WM object) to hold the images.
    document.WM = new Object;
    document.WM.WM_preloadImages = new Object;
    document.WM.WM_preloadImages.daImages = new Array;

    // Loop through all the arguments.
    for(arg=0;arg<WM_preloadImages.arguments.length;arg++) {

      // For each arg, create a new image.
      document.WM.WM_preloadImages.daImages[arg] = new Image;

      // Then set the source of that image to the current argument.
      document.WM.WM_preloadImages.daImages[arg].src = WM_preloadImages.arguments[arg];
    }
  }
}
