function ValidateAll()
{
	if(CheckFirstName(document.contact.FirstName.value) == false) return false;
	if(CheckLastName(document.contact.LastName.value) == false) return false;
	if(CheckEmail(document.contact.Email_Address.value) == false) return false;
	//if(CheckMessage(document.contact.Message.value) == false) return false;
	return true;
}

function StripSpacesFromEnds(s)
{
	while((s.indexOf(' ',0) == 0) && (s.length> 1))
	{
		s = s.substring(1,s.length);
	}
	while((s.lastIndexOf(' ') == (s.length - 1)) && (s.length> 1))
	{
		s = s.substring(0,(s.length - 1));
	}
	if((s.indexOf(' ',0) == 0) && (s.length == 1)) s = '';
	return s;
}

function IsItPresent(s,explanation)
{
	s = StripSpacesFromEnds(s);
	if(s.length) return s;
	alert('Please enter ' + explanation + '.');
	return '';
}

function CheckFirstName(s_firstname)
{
	s_firstname = IsItPresent(s_firstname,'your first name');
	if(! s_firstname) return false;
	var i = s_firstname.indexOf('  ',0);
	while(i> -1)
	{
		s_firstname = s_firstname.substring(0,(i + 1)) + 
			s_firstname.substring((i + 2),s_firstname.length);
		i = s_firstname.indexOf('  ',0);
	}
	s_firstname = s_firstname.toLowerCase();
	var s = new String(s_firstname.substring(0,1));
	s = s.toUpperCase();
	s_firstname = s + s_firstname.substring(1,s_firstname.length);
	i = s_firstname.indexOf(' ',0);
	if(i == (s_firstname.length - 1)) i = -1;
	var ts = new String("");
	var j = 0;
	while(i> -1)
	{
		i++;
		j = i + 1;
		s = s_firstname.substring(i,j);
		s = s.toUpperCase();
		ts = '';
		if(i> 0) ts = s_firstname.substring(0,i);
		s_firstname = ts + s + s_firstname.substring(j,s_firstname.length);
		i = s_firstname.indexOf(' ',j);
		if(i == (s_firstname.length - 1)) i = -1;
	}
	document.contact.FirstName.value = s_firstname;
	return true;
}

function CheckLastName(s_lastname)
{
	s_lastname = IsItPresent(s_lastname,'your last name');
	if(! s_lastname) return false;
	var i = s_lastname.indexOf('  ',0);
	while(i> -1)
	{
		s_lastname = s_lastname.substring(0,(i + 1)) + 
			s_lastname.substring((i + 2),s_lastname.length);
		i = s_lastname.indexOf('  ',0);
	}
	s_lastname = s_lastname.toLowerCase();
	var s = new String(s_lastname.substring(0,1));
	s = s.toUpperCase();
	s_lastname = s + s_lastname.substring(1,s_lastname.length);
	i = s_lastname.indexOf(' ',0);
	if(i == (s_lastname.length - 1)) i = -1;
	var ts = new String("");
	var j = 0;
	while(i> -1)
	{
		i++;
		j = i + 1;
		s = s_lastname.substring(i,j);
		s = s.toUpperCase();
		ts = '';
		if(i> 0) ts = s_lastname.substring(0,i);
		s_lastname = ts + s + s_lastname.substring(j,s_lastname.length);
		i = s_lastname.indexOf(' ',j);
		if(i == (s_lastname.length - 1)) i = -1;
	}
	document.contact.LastName.value = s_lastname;
	return true;
}

function CheckDaytimePhone(s_daytimephone)
{
	s_daytimephone = IsItPresent(s_daytimephone,'your daytime phone number');
	if(! s_daytimephone) return false;
	var i = s_daytimephone.indexOf('  ',0);
	while(i> -1)
	{
		s_daytimephone = s_daytimephone.substring(0,(i + 1)) + 
			s_daytimephone.substring((i + 2),s_daytimephone.length);
		i = s_daytimephone.indexOf('  ',0);
	}
	s_daytimephone = s_daytimephone.toLowerCase();
	var s = new String(s_daytimephone.substring(0,1));
	s = s.toUpperCase();
	s_daytimephone = s + s_daytimephone.substring(1,s_daytimephone.length);
	i = s_daytimephone.indexOf(' ',0);
	if(i == (s_daytimephone.length - 1)) i = -1;
	var ts = new String("");
	var j = 0;
	while(i> -1)
	{
		i++;
		j = i + 1;
		s = s_daytimephone.substring(i,j);
		s = s.toUpperCase();
		ts = '';
		if(i> 0) ts = s_daytimephone.substring(0,i);
		s_daytimephone = ts + s + s_daytimephone.substring(j,s_daytimephone.length);
		i = s_daytimephone.indexOf(' ',j);
		if(i == (s_daytimephone.length - 1)) i = -1;
	}
	document.contact.DaytimePhone.value = s_daytimephone;
	return true;
}

function CheckAddress(s_address)
{
	s_address = IsItPresent(s_address,'your address');
	if(! s_address) return false;
	var i = s_address.indexOf('  ',0);
	while(i> -1)
	{
		s_address = s_address.substring(0,(i + 1)) + 
			s_address.substring((i + 2),s_address.length);
		i = s_address.indexOf('  ',0);
	}
	s_address = s_address.toLowerCase();
	var s = new String(s_address.substring(0,1));
	s = s.toUpperCase();
	s_address = s + s_address.substring(1,s_address.length);
	i = s_address.indexOf(' ',0);
	if(i == (s_address.length - 1)) i = -1;
	var ts = new String("");
	var j = 0;
	while(i> -1)
	{
		i++;
		j = i + 1;
		s = s_address.substring(i,j);
		s = s.toUpperCase();
		ts = '';
		if(i> 0) ts = s_address.substring(0,i);
		s_address = ts + s + s_address.substring(j,s_address.length);
		i = s_address.indexOf(' ',j);
		if(i == (s_address.length - 1)) i = -1;
	}
	document.contact.Address.value = s_address;
	return true;
}

function CheckCity(s_city)
{
	s_city = IsItPresent(s_city,'your city');
	if(! s_city) return false;
	var i = s_city.indexOf('  ',0);
	while(i> -1)
	{
		s_city = s_city.substring(0,(i + 1)) + 
			s_city.substring((i + 2),s_city.length);
		i = s_city.indexOf('  ',0);
	}
	s_city = s_city.toLowerCase();
	var s = new String(s_city.substring(0,1));
	s = s.toUpperCase();
	s_city = s + s_city.substring(1,s_city.length);
	i = s_city.indexOf(' ',0);
	if(i == (s_city.length - 1)) i = -1;
	var ts = new String("");
	var j = 0;
	while(i> -1)
	{
		i++;
		j = i + 1;
		s = s_city.substring(i,j);
		s = s.toUpperCase();
		ts = '';
		if(i> 0) ts = s_city.substring(0,i);
		s_city = ts + s + s_city.substring(j,s_city.length);
		i = s_city.indexOf(' ',j);
		if(i == (s_city.length - 1)) i = -1;
	}
	document.contact.City.value = s_city;
	return true;
}

function CheckZipCode(s_zipcode)
{
	s_zipcode = IsItPresent(s_zipcode,'your zip code');
	if(! s_zipcode) return false;
	var i = s_zipcode.indexOf('  ',0);
	while(i> -1)
	{
		s_zipcode = s_zipcode.substring(0,(i + 1)) + 
		s_zipcode.substring((i + 2),s_zipcode.length);
		i = s_zipcode.indexOf('  ',0);
	}
	var s = new String(s_zipcode.substring(0,1));
	s_zipcode = s + s_zipcode.substring(1,s_zipcode.length);
	i = s_zipcode.indexOf(' ',0);
	if(i == (s_zipcode.length - 1)) i = -1;
	var ts = new String("");
	var j = 0;
	while(i> -1)
	{
		i++;
		j = i + 1;
		s = s_zipcode.substring(i,j);
		ts = '';
		if(i> 0) ts = s_zipcode.substring(0,i);
		s_zipcode = ts + s + s_zipcode.substring(j,s_zipcode.length);
		i = s_zipcode.indexOf(' ',j);
		if(i == (s_zipcode.length - 1)) i = -1;
	}
	document.contact.ZipCode.value = s_zipcode;
	return true;
}

/*
function CheckMessage(s_message)
{
	s_message = IsItPresent(s_message,'your message');
	if(! s_message) return false;
	var i = s_message.indexOf('  ',0);
	while(i> -1)
	{
		s_message = s_message.substring(0,(i + 1)) + 
			s_message.substring((i + 2),s_message.length);
		i = s_message.indexOf('  ',0);
	}

	document.contact.Message.value = s_message;
	return true;
}
*/

function CheckEmail(s_email)
{
	s_email = IsItPresent(s_email,'your email address');
	if(! s_email) return false;
	var i = s_email.indexOf(' ',0);
	while(i> -1)
	{
		s_email = s_email.substring(0,i) + 
			s_email.substring((i + 1),s_email.length);
		i = s_email.indexOf(' ',0);
	}
	document.contact.Email_Address.value = s_email;
	if((s_email.length <6) ||
	   (s_email.indexOf('@',0) <1) ||
	   (s_email.lastIndexOf('@') != s_email.indexOf('@',0)) ||
	   (s_email.lastIndexOf('@') > (s_email.length - 5)) ||
	   (s_email.lastIndexOf('.') < (s_email.length - 4)) ||
	   (s_email.indexOf('..',0)> -1) ||
	   (s_email.indexOf('@.',0)> -1) ||
	   (s_email.indexOf('.@',0)> -1) ||
	   (s_email.indexOf(',',0)> -1))
	{
		alert('Sorry, the email address "' + s_email + '" is not valid. Please enter a valid email address.');
		return false;
	}
	return true;
}