/*
*  Copyright Crickett Software Limited, 2004. All rights reserved.
* 
*  The "Software", below, refers to the software below (in either 
*  source code, or binary form and accompanying documentation). 
*  Each licensee is addressed as "you" or "Licensee." 
* 
*  The copyright holder shown above hereby grants the Licensee a 
*  royalty-free non-exclusive license to use the software. 
* 
*  You may modify and make a copy or copies of the Software for use 
*  within your organization, if you meet the following conditions: 
*    a. Copies in source code must include the copyright notice and 
*       this Software License Agreement. 
*    b. Copies in binary form must include the copyright notice and 
*       this Software License Agreement in the documentation and/or
*       other materials provided with the copy. 
* 
*  You may not distribute copies outside your organization.
* 
*  You may nor modify a copy or copies of the Software or any portion
*  of it, thus forming a work based on the Software, and distribute 
*  such copies outside your organization.
* 
*  This software is provided "as is" without express or implied 
*  warranty, and with no claim as to its suitability for any purpose.
*/

function trim(str)
{
	return str.replace(/^\s+|\s+$/g, '')
}

function validate_non_empty_text(id)
{
	text = document.getElementById(id);

	return trim(text.value).length > 0;
}

function validate_telephone(id)
{
	if (validate_non_empty_text(id))
	{
		text = document.getElementById(id);

		var telephone_number = /^\+?[0-9 ()-]+[0-9]$/;

		return telephone_number.test(trim(text.value));
	}
	return false;
}

function validate_email(id)
{
	if (validate_non_empty_text(id))
	{
		text = document.getElementById(id);

		var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/

		return email.test(trim(text.value));
	}
	return false;
}

function validate_selection(id)
{
	selection = document.getElementById(id);

	var value = selection.options[selection.selectedIndex].text;

	return ((trim(value).length > 0) && (trim(value) != "-- please select --"));
}



