
function validate_contact_form(f)
{

	if (!validName(f.name.value))
	{
		alert('Please enter you name in the Name field.');
		f.name.focus();
		return false;
	}

	if (!validCountry(f.country.value))
	{
		alert('Please enter your country of residence.');
		f.country.focus();
		return false;
	}

	if (!validEmail(f.email.value))
	{
		alert('The e-mail address you entered is invalid.  You must enter a valid e-mail address (e.g. person@company.com) in the Enter your e-mail address field.');
		f.email.focus();
		return false;
	}

	if( !confirmEmail(f.email.value, f.email2.value) ) {
		alert('The e-mail addresses that you entered do not match. You must type the same e-mail address into the "E-mail" field and the "Confirm E-mail" field to verify your e-mail address.');
		f.email.focus();
		return false;
	}

	return true;
}


function validName(name)
{
	if ( name == '' )
	{
		return false;
	}
	return true;
}

function validCountry(country)
{
	if ( country == '' )
	{
		return false;
	}
	return true;
}

function validMessage(message)
{
	if ( message == '' )
	{
		return false;
	}
	return true;
}

function validEmail(email)
{
	var invalidChars = " /:,;"; // NOTE - first char is a SPACE

	for (i = 0;  i < invalidChars.length; i++) { // does it contain any invalid characters?
		var badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar, 0) > -1) return false;
	}

	var atPos = email.indexOf("@", 1);  // there must be one "@" symbol
	if (atPos == -1) return false;
	// and only one "@" symbol
	if (email.indexOf("@", atPos + 1) != -1) return false;

	periodPos = email.indexOf(".", atPos);
	// and at least one "." after the "@"
	if (periodPos == -1) return false;
	// must be at least 2 characters after the "."
	if (periodPos + 3 > email.length)  return false;

	return true;
}

function confirmEmail(email1, email2) {
	if( email1 != email2 )
		return false;

	return true;
}
