/* Validation Functions */

function MM_validateForm5() {
	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 zipCodeFilter = /^\d{5}$/;
	
	var name = ''+document.forms[0].name.value;
	var phone = ''+document.forms[0].phone.value;
	var email = ''+document.forms[0].email.value;
	var zipCode = ''+document.forms[0].zipCode.value;
	
	if (name.length < 1) {
	  	errors = '    - Name\n';
		//document.getElementById('nameerror').style.display="block";
	} else {
	    var tmp = new Array();
	    tmp = name.split(' ');
	    
	    if(tmp.length == 1) {
	        document.forms[0].firstName.value = tmp[0];
	        document.forms[0].lastName.value = tmp[0];
	    } else if(tmp.length == 2) {
	        document.forms[0].firstName.value = tmp[0];
	        document.forms[0].lastName.value = tmp[1];
	    } else {
	        document.forms[0].firstName.value = tmp[0];
	        document.forms[0].lastName.value = tmp[tmp.length-1];
	    }	    
	}	

	  if (phone.length < 1) {
	  	errors += '    - Phone\n';
		//document.getElementById('phoneerror').style.display="block";
	  } else {
		  if (!phoneFilter.test(phone)) {
			errors += '    - Invalid phone number. Examples: 234-555-5678.\n';
			//document.getElementById('phoneerror').style.display="block";
		  }
	  }
	  
	  if (email.length < 1) {
		errors += '    - Email\n';
		//document.getElementById('emailerror').style.display="block";
	  } else {
		  if (!emailFilter.test(email)) {
			errors += '    - Invalid email address. Examples: abc@xyz.com.\n';
			//document.getElementById('emailerror').style.display="block";
		  }
	  }
	  
	  if (zipCode.length < 1) {
	  	errors += '    - Zip\n';
		//document.getElementById('ziperror').style.display="block";
	  } else {
		  if (!zipCodeFilter.test(zipCode)) {
			errors += '    - Invalid zip code. Examples: 12345.\n';
			//document.getElementById('ziperror').style.display="block";
		  }
	  }
	  
	  document.returnValue5 = (errors == '');

	  if (errors) {
	  	alert('Thank you for your interest in the AMBA program. In order for us to process your request \n we will need the following information:\n'+errors);
		return false;
	  } else {
		  return true;
	  }
}


function MM_validateForm6() {
  var errors = '';
  
  var address = ''+document.forms[0].address1.value;
  var city = ''+document.forms[0].city.value;
  var state = ''+document.forms[0].state.value;
  var howHeardAbout = ''+document.forms[0].howHeardAbout.value;
  
  if (address.length < 1) {
  	errors += '    - Address\n';
	//document.getElementById('addresserror').style.display="block";
  }
  if (city.length < 1) {
  	errors += '    - City\n';
	//document.getElementById('cityerror').style.display="block";
  }
  if (state.length < 1) {
  	errors += '    - State\n';
	//document.getElementById('stateerror').style.display="block";
  }
  if (howHeardAbout.length < 1) {
  	errors += '    - How You Heard About Us\n';
	//document.getElementById('howHeardAbouterror').style.display="block";
  }
  
  /*var numChecked = 0;
  if(services != null) {
	  for(i = 0; i < services.length; i++) {
		  if(services[i].checked)
			  numChecked ++;
	  }
	  if(numChecked < 1)
		  errors += '    - Services interested in\n';
  }*/
  
  document.returnValue6 = (errors == '');

  if (errors) {
  	alert('Thank you for your interest in the AMBA program. In order for us to process your request \n we will need the following information:\n'+errors);
	return false;
  } else {
	  return true;
  }
};


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;
};