//
// FBFcommon.js
//
// Author: Susan Brindley
// Created: 09/09/2004
// Version: 1.2
//
// PURPOSE
// -------
// Holds JavaScript functions common to all FBF sites.
//
// 
// HISTORY
// -------
// 06/11/2006 1.0 SB	File Created.

ns6 = (document.getElementById)? true:false
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false


// *********
// getObject
// *********
// INPUTS
//  name        the name or ID for an object
//
// OUTPUTS
//	objectRef   a reference to the object identified by name
//
// PURPOSE
//  Returns the object referenced by name.
// 
//	NOTE: Make sure that all objects have an ID - Netscape doesn't recognise
//	objects with a NAME and requires then to have an ID attribute for this to work.
//	
//  
function getObject(name)
{
	if (ie4)
		return document.all[name];
	else if (ns6)
		return document.getElementById(name);
	else
		return document.layers[name];
}

// **************
// goToPage
// **************
// INPUTS
//  formName		the DOM name of the form to submit.
//
// OUTPUTS
//	NONE
//
// PURPOSE
//  Submits the supplied form which will submit to the action specified with the
// form.
//	
//  
function goToPage(formName)
{
	var formObject = getObject(formName);

	formObject.submit();	
}


// ************
// processEmail
// ************
// INPUTS
//  emailAddressString	email address(es) to be validated.
//
// OUTPUTS
//	boolean     true - means that the email address was valid
//              false - means that the email address was invalid
//
// PURPOSE
//  Tests that a valid set of email addresses have been supplied. The comma
// character is defined as the separator for multiple email addresses.
// NOTE: checkEmail is a generic function contained in the standard Athens 
// common.js file.
//	
//  
function validateEmail( emailAddressString )
{
	//alert('**** validateEmail **** emailAddressString [' + emailAddressString + ']');
	var emailOK = false;
	var message = '';
	var emailAddressArray = new Array();

	if ( ( emailAddressString == null ) || 
				( emailAddressString == '' ) || 
				( emailAddressString.length == 0 ) )
  {    
  	message += "*  You MUST supply an email address.\n"
	}
	else
	{
		//alert('validateEmail: emailAddressString [' + emailAddressString + ']');
		emailAddressArray = emailAddressString.split(",");
		//alert('validateEmail: emailAddressArray [' + emailAddressArray + ']');
		for ( emailAddress in emailAddressArray )
		{
			//alert('validateEmail: emailAddress [' + emailAddress + '] value [' + emailAddressArray[emailAddress] + ']' );
			if ( ! isEmail ( emailAddressArray[emailAddress] ) )
			{
				message += "*  Invalid email address: " + emailAddressArray[emailAddress] + "\n"
			}
		}
	}
		
	if ( ( message != null ) && ( message != '' ) && ( message.length > 0 ) )
  {    
    message = 'The following errors occured with the email address(es) you supplied:\n\n' + message + '\n\n';  
    alert(message);
  }
  else
  {
  	emailOK = true;
  }
  
	return ( emailOK );
}

