
function MM_validateForm() { 

  var errors = '';
  var phoneFilter = /^\d{3}-\d{3}-\d{4}$/;
  var emailFilter = /^[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;

  var name = ''+document.forms[0].name.value;
  var phone = ''+document.forms[0].phone.value;
  var email = ''+document.forms[0].email.value;
  var URL = ''+document.forms[0].URL.value;
  var businessName = ''+document.forms[0].businessName.value;
  var jobFunc = ''+document.forms[0].jobfunction.value;

  if (name.length < 1)
  	errors = '    - Name\n';

  if (jobFunc.length < 1)
  	errors += '    - Job Function\n';

  if (URL.length < 1)
  	errors += '    - URL\n';

  if (businessName.length < 1)
  	errors += '    - Business Name\n';
  
  if (phone.length < 1)
  	errors += '    - Phone number\n';
  else
	  if (!phoneFilter.test(phone))
		errors += '    - Invalid phone number. Examples: 234-555-5678.\n';

  if (email.length < 1)
	errors += '    - Email\n';
  else
	  if (!emailFilter.test(email))
		errors += '    - Invalid email address. Examples: abc@xyz.com .\n';
	
  document.returnValue = (errors == '');

  if (errors) {
  	alert('Thank you for requesting your iMap. In order for us to process your request for a FREE SnapShot\n we will need the following information:\n'+errors);
	return false;
  } else {
	  return true;
  }
  
  
};

function quiz_validateForm() { //v4.0
  var success = false;
  var errors='';
  var phoneFilter = /^\d{3}-\d{3}-\d{4}/;
  var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    
  if (document.forms["contact"].name.value == "") {
  	errors += '- Your name is required\n';
  }
  if (document.forms["contact"].title.value == "") {
  	errors += '- Title is required\n';
  }
  if (document.forms["contact"].company.value == "") {
  	errors += '- Non-Profit name is required\n';
  }
  if (document.forms["contact"].url.value == "") {
  	errors += '- Site URL is required\n';
  }
  if (!phoneFilter.test(document.forms["contact"].Phone.value)) {
	  errors += '- A valid phone number is required (123-456-7890)\n';
  }
  if (!emailFilter.test(document.forms["contact"].Email.value)) {
  	errors += '- A valid email address is required (abc@xyz.com)\n';
  }

  if (errors) {
  	alert('The following error(s) occurred:\n'+errors);
  } else {
  	success = true;
  }
  return success;
}

function formatPhoneNumber(textField) {
	var tempString = textField.value;
	tempString = tempString.replace(/[^0-9]/gi, "");
	tempString = tempString.toUpperCase();
	if (tempString.length>9) {
		if (tempString.length==11 && tempString.substring(0,1)=="1")
			tempString = tempString.substring(1);
		tempString = tempString.substring(0,3)+"-"+tempString.substring(3,6)+"-"+tempString.substring(6,10);
	}
	textField.value = tempString;
}

function textCounter(field, maxlimit) {
    if (field.value.length > maxlimit) {
        alert("Comments too long. Only "+maxlimit+" characters allowed.");
        field.value = field.value.substring(0, maxlimit);
    }
}
