//Validation for submitted web design page...........

function validate(theForm)
{
	theForm.name.style.backgroundColor = "";
	theForm.phone.style.backgroundColor = "";
	theForm.email.style.backgroundColor = "";
	theForm.address.style.backgroundColor = "";
	theForm.city.style.backgroundColor = "";
	theForm.state.style.backgroundColor = "";
	theForm.zip.style.backgroundColor = "";	
	theForm.url.style.backgroundColor = "";	
	theForm.products.style.backgroundColor = "";	
	theForm.services.style.backgroundColor = "";	
	theForm.serviceProvider.style.backgroundColor = "";

  if (theForm.name.value == "")
  {
   	alert("Please enter a value for the \"Name\" field.");
    theForm.name.focus();
	theForm.name.value = "";	
	theForm.name.style.backgroundColor = '#F5A703';
    return (false);
  }

  if (theForm.name.value.length < 3)
  {
    alert("Please enter at least 4 characters in the \"Name\" field.");
    theForm.name.focus();
	theForm.name.value = "";
	theForm.name.style.backgroundColor = '#F5A703';
    return (false);
  }

  if (theForm.name.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Name\" field.");
    theForm.name.focus();
	theForm.name.value = "";
	theForm.name.style.backgroundColor = '#F5A703';
    return (false);
  }
  
  if (theForm.phone.value == "" || theForm.phone.value == '12345' || theForm.phone.value == '123456')
  {
	alert("Please enter a valid number in the \"Phone Number\" field.");
	theForm.phone.focus();
	theForm.phone.value = "";
	theForm.phone.style.backgroundColor = '#F5A703';
	return (false);
  }

  if (theForm.email.value == "")
  {
    alert("Please enter a value for the \"Email\" field.");
    theForm.email.focus();
	theForm.email.value = "";
	theForm.email.style.backgroundColor = '#F5A703';
    return (false);
  }

  if (theForm.email.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"Email\" field.");
    theForm.email.focus();
	theForm.email.value = "";
	theForm.email.style.backgroundColor = '#F5A703';
    return (false);   
  }

  if (theForm.email.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Email\" field.");
    theForm.email.focus();
	theForm.email.value = "";
	theForm.email.style.backgroundColor = '#F5A703';
    return (false);
  }
	var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/ 
	if(!RegExp.test(theForm.email.value))
	{	
		alert("Please enter a valid Email.");
		theForm.email.focus();
		theForm.email.value = "";
		theForm.email.style.backgroundColor = '#F5A703';
		return (false);
	} 
  
  if (theForm.address.value == "")
  {
	  alert("Please enter a valid address in the \"Address\" field.");
	  theForm.address.focus();
	  theForm.address.value = "";
	  theForm.address.style.backgroundColor = '#F5A703';
	  return (false);
  }  
  
  if (theForm.city.value == "")
  {
	  alert("Please enter a valid City in the \"City\" field.");
	  theForm.city.focus();
	  theForm.city.value = "";
	  theForm.city.style.backgroundColor = '#F5A703';
	  return (false);
  }
  
  if (theForm.state.value == "")
  {
	  alert("Please enter a valid State in the \"State\" field.");
	  theForm.state.focus();
	  theForm.state.value = "";
	  theForm.state.style.backgroundColor = '#F5A703';
	  return (false);
  }
  
  if (theForm.zip.value == "" || theForm.zip.value == '12345' || theForm.zip.value == '123456')
  {
	  alert("Please enter a valid Zip Code in the \"Zip Code\" field.");
	  theForm.zip.focus();
	  theForm.zip.value = "";
	  theForm.zip.style.backgroundColor = '#F5A703';
	  return (false);
  }   
  
  if (theForm.url.value > '')
  {
	  var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/; 
    if(!RegExp.test(theForm.url.value))
	{	
		alert("Please enter a valid URL.");
		theForm.url.focus();
		theForm.url.value = "";
		theForm.url.style.backgroundColor = '#F5A703';
		return (false);
	} 
	if (!theForm.serviceProvider.value > "")
	{
	  	alert("You entered a web site URL above. Please tell us who your Internet Service Provider is.");
	  	theForm.serviceProvider.focus();
	  	theForm.serviceProvider.value = "";
	  	theForm.serviceProvider.style.backgroundColor = '#F5A703';
	  	return (false);
	}
  }
  
  if (theForm.needs1.checked == false && theForm.needs2.checked == false && theForm.needs3.checked == false)
  {
	  alert ("Please select the type of help you need.");
	  theForm.needs1.focus();	  
	  return (false);
  }    
      
  if (theForm.contactByEmail.checked == false && theForm.contactByPhone.checked == false)
  {
	  alert ("Please choose how we can contact you.");
	  theForm.contactByEmail.focus();
	  return (false);
  }
  
  if (theForm.contactByPhone.checked)
  {  
  	if (theForm.timeToCall1.checked == false && theForm.timeToCall2.checked == false && theForm.timeToCall3.checked == false)
  	{
		  alert ("Please choose the time we may contact you");
		  theForm.timeToCall1.focus();
		  return (false);
	}
  } 
  
  if (theForm.sellProducts.checked)
  {
	  if (theForm.products.value == "")
	  {
		alert ("You indicated that you will sell products on your site. Please tell us what type of products you will be selling.");
		theForm.products.focus();
		theForm.products.value = "";
		theForm.products.style.backgroundColor = '#F5A703';
		return (false);
	  }
  }
  
  if (theForm.sellService.checked)
  {
	  if (theForm.services.value == "")
	  {
		alert ("You indicated that you will sell a service on your site. Please tell us what type of services you will be selling.");
		theForm.services.focus();
		theForm.services.value = "";
		theForm.services.style.backgroundColor = '#F5A703';
		return (false);
	  }
  }
  
  if (theForm.comments.value != "")
  	var text = theForm.comments.value;
  	var iChars = "=<>[]:";

	for (var i = 0; i < text.length; i++) {
		if (iChars.indexOf(text.charAt(i)) != -1) {
		alert ("HTML code was found in the comment box! \nThis is not allowed.\n Please remove the HTML code and try again.");
		theForm.comments.focus();
		theForm.comments.style.backgroundColor = '#F5A703';
		return (false);
	}
  }
  
  return (true);
}
