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.value) == false) return false;
	if(CheckPhone(document.contact.Phone.value) == false) return false;
	if(CheckAddress(document.contact.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_name)
{
	s_name = IsItPresent(s_name,'your first name');
	if(! s_name) return false;
	var i = s_name.indexOf('  ',0);
	while(i> -1)
	{
		s_name = s_name.substring(0,(i + 1)) + 
		s_name.substring((i + 2),s_name.length);
		i = s_name.indexOf('  ',0);
	}
	s_name = s_name.toLowerCase();
	var s = new String(s_name.substring(0,1));
	s = s.toUpperCase();
	s_name = s + s_name.substring(1,s_name.length);
	i = s_name.indexOf(' ',0);
	if(i == (s_name.length - 1)) i = -1;
	var ts = new String("");
	var j = 0;
	while(i> -1)
	{
		i++;
		j = i + 1;
		s = s_name.substring(i,j);
		s = s.toUpperCase();
		ts = '';
		if(i> 0) ts = s_name.substring(0,i);
		s_name = ts + s + s_name.substring(j,s_name.length);
		i = s_name.indexOf(' ',j);
		if(i == (s_name.length - 1)) i = -1;
	}
	document.contact.FirstName.value = s_name;
	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 CheckPhone(s_phone)
{
	s_phone = IsItPresent(s_phone,'your phone number');
	if(! s_phone) return false;
	var i = s_phone.indexOf('  ',0);
	while(i> -1)
	{
		s_phone = s_phone.substring(0,(i + 1)) + 
			s_phone.substring((i + 2),s_phone.length);
		i = s_phone.indexOf('  ',0);
	}
	s_phone = s_phone.toLowerCase();
	var s = new String(s_phone.substring(0,1));
	s = s.toUpperCase();
	s_phone = s + s_phone.substring(1,s_phone.length);
	i = s_phone.indexOf(' ',0);
	if(i == (s_phone.length - 1)) i = -1;
	var ts = new String("");
	var j = 0;
	while(i> -1)
	{
		i++;
		j = i + 1;
		s = s_phone.substring(i,j);
		s = s.toUpperCase();
		ts = '';
		if(i> 0) ts = s_phone.substring(0,i);
		s_phone = ts + s + s_phone.substring(j,s_phone.length);
		i = s_phone.indexOf(' ',j);
		if(i == (s_phone.length - 1)) i = -1;
	}
	document.contact.Phone.value = s_phone;
	return true;
}

function CheckAddress(s_address)
{
	s_address = IsItPresent(s_address,'your full street 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 full street address');
	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 CheckZip(s_zip)
{
	s_zip = IsItPresent(s_zip,'your full street address');
	if(! s_zip) return false;
	var i = s_zip.indexOf('  ',0);
	while(i> -1)
	{
		s_zip = s_zip.substring(0,(i + 1)) + 
		s_zip.substring((i + 2),s_zip.length);
		i = s_zip.indexOf('  ',0);
	}
	s_zip = s_zip.toLowerCase();
	var s = new String(s_zip.substring(0,1));
	s = s.toUpperCase();
	s_zip = s + s_zip.substring(1,s_zip.length);
	i = s_zip.indexOf(' ',0);
	if(i == (s_zip.length - 1)) i = -1;
	var ts = new String("");
	var j = 0;
	while(i> -1)
	{
		i++;
		j = i + 1;
		s = s_zip.substring(i,j);
		s = s.toUpperCase();
		ts = '';
		if(i> 0) ts = s_zip.substring(0,i);
		s_zip = ts + s + s_zip.substring(j,s_zip.length);
		i = s_zip.indexOf(' ',j);
		if(i == (s_zip.length - 1)) i = -1;
	}
	document.contact.Zip.value = s_zip;
	return true;
}

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

function CheckMessage(s_message)
{
	s_message = IsItPresent(s_message,'a messsage');
	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);
	}
	var s = new String(s_message.substring(0,1));
	s_message = s + s_message.substring(1,s_message.length);
	i = s_message.indexOf(' ',0);
	if(i == (s_message.length - 1)) i = -1;
	var ts = new String("");
	var j = 0;
	while(i> -1)
	{
		i++;
		j = i + 1;
		s = s_message.substring(i,j);
		ts = '';
		if(i> 0) ts = s_message.substring(0,i);
		s_message = ts + s + s_message.substring(j,s_message.length);
		i = s_message.indexOf(' ',j);
		if(i == (s_message.length - 1)) i = -1;
	}
	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.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 - 3)) ||
	   (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;
}