// JavaScript Document
function validatePhone(campo) {
    var RegExPattern = /^[0-9]{3}-?[0-9]{3}-?[0-9]{4}$/;
    if ((campo.value.match(RegExPattern)) && (campo.value!='')) {
		return true;
    } else {
		return false;
    } 
}
function validateDate(campo) {
    var RegExPattern = /^\d{1,2}\/\d{1,2}\/\d{2,4}$/;
    if ((campo.value.match(RegExPattern)) && (campo.value!='')) {
		return true;
    } else {
		return false;
    } 
}

function validateZip(campo) {
    var RegExPattern = /^([1-9]{2}|[0-9][1-9]|[1-9][0-9])[0-9]{3}$/;
    if ((campo.value.match(RegExPattern)) && (campo.value!='')) {
		return true;
    } else {
		return false;
    } 
}

function validate(form) {
	var elementos = document.getElementById('form1').elements.length;
	for( i=0;i < elementos;i++) {
		clase = document.getElementById('form1').elements[i].className;
		if ((clase == 'required') && (document.getElementById('form1').elements[i].value == '')) {
			alert (document.getElementById('form1').elements[i].id+' is required');
			document.getElementById('form1').elements[i].focus();
			return false;
		}
	}
	
	

	if (!validateDate(document.getElementById('Date of Birth'))){
		alert(document.getElementById('Date of Birth').id+' format is incorrect');
		document.getElementById('Date of Birth').focus();
		return false;
	}
	if (!validateDate(document.getElementById('ETS'))){
		alert(document.getElementById('ETS').id+' format is incorrect');
		document.getElementById('ETS').focus();
		return false;
	}
	if (!validatePhone(document.getElementById('Work Phone'))){
		alert(document.getElementById('Work Phone').id+' format is incorrect');
		document.getElementById('Work Phone').focus();
		return false;
	}
	if (!validatePhone(document.getElementById('Home Phone'))){
		alert(document.getElementById('Home Phone').id+' format is incorrect');
		document.getElementById('Home Phone').focus();
		return false;
	}
	if (!validatePhone(document.getElementById('Cell Phone'))){
		alert(document.getElementById('Cell Phone').id+' format is incorrect');
		document.getElementById('Cell Phone').focus();
		return false;
	}
	if (!validateZip(document.getElementById('Zip'))){
		alert(document.getElementById('Zip').id+' format is incorrect');
		document.getElementById('Zip').focus();
		return false;
	}
							
		
}



function validate_mh(form) {
	
	
	if (document.getElementById('First Name').value == '')
	{
		alert('First Name is required.');
		document.getElementById('First Name').focus();
		return false;
	}
	
	if (document.getElementById('Last Name').value == '')
	{
		alert('Last Name is required.');
		document.getElementById('Last Name').focus();
		return false;
	}
	
	if (!validatePhone(document.getElementById('PhoneHome'))){
		alert('Home Phone format is incorrect.');
		document.getElementById('PhoneHome').focus();
		return false;
	}
	
	if (!validatePhone(document.getElementById('PhoneCell'))){
		alert('Cell Phone format is incorrect.');
		document.getElementById('PhoneCell').focus();
		return false;
	}
	
	if (!validatePhone(document.getElementById('PhoneWork'))){
		alert('Work Phone format is incorrect.');
		document.getElementById('PhoneWork').focus();
		return false;
	}
	
	if (document.getElementById('Primary Email Address').value == '')
	{
		alert('Primary Email Address is required.');
		document.getElementById('Primary Email Address').focus();
		return false;
	}
	
	if (document.getElementById('SpanishSpeak').value == '')
	{
		alert('Please tell us if you speak Spanish.');
		document.getElementById('SpanishSpeak').focus();
		return false;
	}
	
	if (document.getElementById('Facility/ Practice Name').value == '')
	{
		alert('Facility/ Practice Name is required.');
		document.getElementById('Facility/ Practice Name').focus();
		return false;
	}
	
	if (document.getElementById('Street Address').value == '')
	{
		alert('Street Address is required.');
		document.getElementById('Street Address').focus();
		return false;
	}
	
	if (document.getElementById('City').value == '')
	{
		alert('City is required.');
		document.getElementById('City').focus();
		return false;
	}
	
	if (document.getElementById('Zip Code').value == '')
	{
		alert('Zip Code is required.');
		document.getElementById('Zip Code').focus();
		return false;
	}
	
	if (!validateZip(document.getElementById('Zip Code'))) {
		alert(document.getElementById('Zip Code').id+' format is incorrect.\n Example 55555.');
		document.getElementById('Zip Code').focus();
		return false;
	}
	
	if (document.getElementById('Zip Code').value == '')
	{
		alert('Zip Code is required.');
		document.getElementById('Zip Code').focus();
		return false;
	}
		
	checkUpdates();	
}


function validate_contact_us()
{
	var er_email = /^(.+\@.+\..+)$/
	email = document.getElementById('email').value;
	
	if (document.getElementById('last').value == '')
	{
		alert('Last Name is required');
		document.getElementById('last').focus();
		return false;
	}
	
	if (document.getElementById('first').value == '')
	{
		alert('First Name is required');
		document.getElementById('first').focus();
		return false;
	}
	if( email == ''){
		alert('Email is required');
		document.getElementById('email').focus();
		return false;
	} 
	else if(!er_email.test(document.getElementById('email').value)) { 
		alert('The Email is not valid.')
		document.getElementById('email').focus();
		return false;
	} 
	
	if (document.getElementById('comments').value == '')
	{
		alert('Comments are required');
		document.getElementById('comments').focus();
		return false;
	}
}