
	var ErrorControl;
	var ErrorText;
	
	// Make sure the select box has a valid value.  Here is is assumed that 0 is not a valid value
	// (it is used to indicate the "please make a selection" option for single-value selects.
	function AddError(Control,Msg)
	{
		ErrorText = ErrorText + '\n' + Msg;
			if (ErrorControl == null)
			ErrorControl = Control;
	}
	
	function CheckSelect(SelectControl,SelectText)
	{
		if ((SelectControl.type == 'select-one' && SelectControl.selectedIndex == 0) ||
			(SelectControl.selectedIndex == -1))
		{
			AddError(SelectControl,'You must select ' + SelectText);
		}
		return true;
	}

	function CheckText(TextControl,Msg)
	{
		if  (!hasValue(TextControl, "TEXT" ))
		{
			AddError(TextControl,'You must ' + Msg);
		}
		return true;
	}

/*	function CheckEmailAddr(TextControl,Msg)
	{
		var DefaultError = "A valid e-mail address must be in the form <user>@<host>.<domain>";
		var TestAddress = new String();
		TestAddress = TextControl.value;
		var atloc = TestAddress.indexOf('@',1);
		var dotloc = TestAddress.indexOf('.');
		var InvalidChars = "~`!#$%^&*()+={[}]\|:;'\"<,>?/";
		
		// Make sure it's not blank
		CheckText(TextControl,Msg);
		// Make sure it has an @ and a ., in more or less the right spots.
		if ( atloc == -1 || dotloc >= TestAddress.length - 2 || dotloc <= atloc + 1)
			AddError(TextControl,DefaultError);
		
		// Make sure there are no invalid characters
		for (i=0;i<TestAddress.length;i++)
			if (InvalidChars.indexOf(TestAddress.substr(i,1)) != -1)
			{
				AddError(TextControl,"Your e-mail address contains invalid characters");
				break;
			}
	}
*/

	function CheckEmailAddr(TextControl,Msg)
	{
		var DefaultError = "A valid e-mail address must be in the form <user>@<host>.<domain>";
		var TestAddress = new String();
		TestAddress = TextControl.value;
		var atloc = TestAddress.indexOf('@',1);
		var len = TestAddress.length;
		var dotloc = TestAddress.lastIndexOf ( '.', len - 1 ) + 1;
   
		var InvalidChars = "~`!#$%^&*()+={[}]\|:;'\"<,>?/";
		
		// Make sure it's not blank
		CheckText(TextControl,Msg);
		// Make sure it has an @ and a ., in more or less the right spots.
		
		 if ( (len - dotloc ) < 2  || ( len - dotloc ) > 4 )
			AddError(TextControl,DefaultError);
		
		// Make sure there are no invalid characters
		for (i=0;i<TestAddress.length;i++)
			if (InvalidChars.indexOf(TestAddress.substr(i,1)) != -1)
			{
				AddError(TextControl,"Your e-mail address contains invalid characters");
				break;
			}
	}


	function hasValue(obj, obj_type)
	{
 		// Check for NULL in TEXT or PASSWORD type field
		if (obj_type == "TEXT" || obj_type == "PASSWORD")
		{
			if (obj.value.length == 0) 
				return false;
			else 
				return true;
		}
		// Check for NULL in SELECT type field
		else if (obj_type == "SELECT")
		{
			for (i=0; i < obj.length; i++)
			{
				if (obj.options[i].selected)
					return true;
			}
			return false;   
		}
		// Check for NULL in Single value radio or checkbox type field
		else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX")
		{
			if (obj.checked)
				return true;
			else
				return false;   
		}
		// Check for NULL in Radio or Checkbox type field
		else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
		{
			for (i=0; i < obj.length; i++)
			{
				if (obj[i].checked)
					return true;
			}
			return false;   
		}
	}

	function ValidateForm(thing)
	{
		ErrorControl = null;
		ErrorText = '';

		CheckText(thing.SenderName,'enter your name');
		CheckEmailAddr(thing.SenderEmail1,'enter your e-mail address');
		CheckEmailAddr(thing.SenderEmail2,'confirm your e-mail address');
		if (thing.SenderEmail1.value != thing.SenderEmail2.value)
		{
 			AddError(thing.SenderEmail1,'E-mail addresses must match');
		}
        CheckText(thing.EmailSubject,'enter a subject');
        CheckText(thing.EmailMessage,'enter a message');   

		if (ErrorText == '')
			return true;
		else
		{
			alert(ErrorText);
			ErrorControl.focus;
			return false;
		}
	}



