

function Verify(formType) {

	var FormGood=true;
	var MissingMessage='The Following Fields Must Be Filled In or Corrected:\n';
	var msg ='';
	var emailmatch='';
    
	
    if (document.forms['FORM'].Name.value=='' ) {
		FormGood=false;
		MissingMessage+='Name\n';
		}
    else if (!testName(document.forms['FORM'].Name)){
		FormGood=false;
		msg+='Name is invalid.\n';
		}

    if ( document.forms['FORM'].Email.value=='' ) {
		FormGood=false;
		MissingMessage+='E-Mail\n';
		}
	else if (!testEmail(document.forms['FORM'].Email)){
        FormGood=false;		
		msg+='The email address is invalid: '+ document.forms['FORM'].Email.value + '\n';
		}

	if ( document.forms['FORM'].Email2.value=='' ) {
		FormGood=false;
		MissingMessage+='Confirm E-Mail\n';
		}
	else if (!testEmail(document.forms['FORM'].Email2)){
		FormGood=false;
		msg+='The confirmed email address is invalid: '+ document.forms['FORM'].Email2.value + '\n';
		}
		
    if ((document.forms['FORM'].Email.value!='') && (document.forms['FORM'].Email2.value!='')) {
		if(document.forms['FORM'].Email2.value != document.forms['FORM'].Email.value){
			FormGood=false;
			emailmatch ='\nE-Mail addresses do not match.\n';
		}
        }
	if ( document.forms['FORM'].Phone.value=='' ) {
		FormGood=false;
		MissingMessage+='Phone\n';
		}
	//else if (!validateUSPhone(document.forms['FORM'].Phone)){
	    
		//FormGood=false;
		//msg+='The phone number should be (999)999-9999 or (999) 999-9999: '+ document.forms['FORM'].Phone.value + '\n';
    	//	}
    if (((formType == "Candida") || (formType == "Gluten")) || (formType == "Hypoglycemia")){

	if ( document.forms['FORM'].Age.value=='' ) {
		FormGood=false;
		MissingMessage+='Age\n';
	}
    else if ( !testNumber(document.forms['FORM'].Age) ) {
	    FormGood=false;
		msg+='Age should be numeric.\n';
		}	

	if ( document.forms['FORM'].Sex.value=='' ) {
		
		FormGood=false;
		MissingMessage+='Sex\n';
		}
	
//	else if  (!testSex(document.forms['FORM'].Sex)){
//				FormGood=false;
//				msg+="Sex should be 'M' or 'F'.\n";
//			}
	
	if ( document.forms['FORM'].Weight.value=='' ) {
		FormGood=false;
		MissingMessage+='Weight\n';
		}
    else if ( !testNumber(document.forms['FORM'].Weight) ) {
		FormGood=false;
		msg+='Weight should be numeric.\n';
		}

	if ( document.forms['FORM'].Height.value=='' ) {
		FormGood=false;
		MissingMessage+='Height\n';
		}
    else if ( !testNumber(document.forms['FORM'].Height) ) {
		FormGood=false;
		msg+='Height should be numeric.\n';
		}

	}//end if formType		

	if (FormGood==true){
        document.forms['FORM'].submit();
	}
    else{
		alert( MissingMessage+msg+emailmatch);
		if(emailmatch!=''){
	
    		document.forms['FORM'].Email.value='';
			document.forms['FORM'].Email2.value='';
			document.forms['FORM'].Email.focus();
		}

		return false;

	}

} //End Verify

	
function testSex(src) {
    if ((src.value == "M") || (src.value =="F")){
        return true;
    }
    else
    {
        return false;
    }

}// end testSex
function testEmail(src) {

     var emailReg ="^[\\w-\.]{1,}\@([\\da-zA-Z-]{1,}\.){1,}[\\da-zA-Z-]{2,3}$";

     var regex = new RegExp(emailReg);

     return regex.test(src.value);

  }
function validateUSPhone(src) {
    
    var regex  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
    return regex.test(src.value);
}  // End function validateUSPhone(src)


function testNumber(src) {

var allValid = true
var checkNumber = "0123456789"
var numberCheck
			
			numberCheck = src.value
	        for (i = 0;  i < numberCheck.length;  i++)
	        {
                ch = numberCheck.charAt(i);
				        for (j = 0;  j < checkNumber.length;  j++)
                        if (ch == checkNumber.charAt(j))
                                break;
                        if (j == checkNumber.length)
                        {
                                allValid = false;
                                break;
                        }
	        }
	        if (!allValid)
	        {
		     return false;
	        } else
			{
			return true;
			}

}


function testName(src)
{
var checkName = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .,-"
var nameCheck
var allValid = true
            
	        nameCheck = src.value
	        
	        for (i = 0;  i < nameCheck.length;  i++)
	        {
                
                ch = nameCheck.charAt(i);
                
                for (j = 0;  j < checkName.length;  j++)
                {
                    
                    if (ch == checkName.charAt(j)) {
                            break;
                        }
                    if (j == (checkName.length - 1))
                    {       allValid = false;
                            break;
                    }
                }
	        }
	        if (!allValid)
	        {
             return false;
	        }else
			{
			return true;
			}

}

