function ValidateAll()
{
	if(CheckName(document.contact.Name.value) == false) return false;
	//if(CheckCompany(document.contact.Company.value) == false) return false;
	//if(CheckAddress(document.contact.Address.value) == false) return false;
	if(CheckPhone(document.contact.Phone.value) == false) return false;
	if(CheckEmail(document.contact.Email.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 CheckName(s_name)
{
	s_name = IsItPresent(s_name,'your full 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.Name.value = s_name;
	return true;
}

function CheckCompany(s_company)
{
	s_company = IsItPresent(s_company,'your company name');
	if(! s_company) return false;
	var i = s_company.indexOf('  ',0);
	while(i> -1)
	{
		s_company = s_company.substring(0,(i + 1)) + 
		s_company.substring((i + 2),s_company.length);
		i = s_company.indexOf('  ',0);
	}
	s_company = s_company.toLowerCase();
	var s = new String(s_company.substring(0,1));
	s = s.toUpperCase();
	s_company = s + s_company.substring(1,s_company.length);
	i = s_company.indexOf(' ',0);
	if(i == (s_company.length - 1)) i = -1;
	var ts = new String("");
	var j = 0;
	while(i> -1)
	{
		i++;
		j = i + 1;
		s = s_company.substring(i,j);
		s = s.toUpperCase();
		ts = '';
		if(i> 0) ts = s_company.substring(0,i);
		s_company = ts + s + s_company.substring(j,s_company.length);
		i = s_company.indexOf(' ',j);
		if(i == (s_company.length - 1)) i = -1;
	}
	document.contact.Company.value = s_company;
	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 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 CheckState(s_state)
{
	s_state = IsItPresent(s_state,'your state');
	if(! s_state) return false;
	var i = s_state.indexOf('  ',0);
	while(i> -1)
	{
		s_state = s_state.substring(0,(i + 1)) + 
		s_state.substring((i + 2),s_state.length);
		i = s_state.indexOf('  ',0);
	}
	s_state = s_state.toUpperCase();
	var s = new String(s_state.substring(0,1));
	s = s.toUpperCase();
	s_state = s + s_state.substring(1,s_state.length);
	i = s_state.indexOf(' ',0);
	if(i == (s_state.length - 1)) i = -1;
	var ts = new String("");
	var j = 0;
	while(i> -1)
	{
		i++;
		j = i + 1;
		s = s_state.substring(i,j);
		s = s.toUpperCase();
		ts = '';
		if(i> 0) ts = s_state.substring(0,i);
		s_state = ts + s + s_state.substring(j,s_state.length);
		i = s_state.indexOf(' ',j);
		if(i == (s_state.length - 1)) i = -1;
	}
	document.contact.State.value = s_state;
	return true;
}

function CheckZip(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);
	}
	s_zipcode = s_zipcode.toLowerCase();
	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.Zip.value = s_zipcode;
	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 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 - 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;
}