<!--

 function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

 
  function isblank(s)
 {
     for(var i = 0; i < s.length; i++) {
         var c = s.charAt(i);
         if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
     }
     return true;
 }
 
 function isPhoneNumber( value ){
	if(value.length < 12) return false
	var phArray = value.split("-");
	for (var i = 0 ; i < phArray.length; i++){
		if (i <= 1){
			if (phArray[i].length != 3)
				return false;
		}
		else if (i = 2){
			if (phArray[i].length != 4)
				return false;
		}
		if (!isInteger(phArray[i]))
			return false;
	
	}
	return true;
}

 function ValidateEmail(Email) {
  var checkbeg = /^[.+]/;       //Match one or more characters, at the beginning
  var checkmid = /@[\w\-]+\./;  //Match an @ sign, followed by A-Z, a-z, 0-9, _, or - repeated any number of times
  var checkend = /\..{2,3}$/;   //Match a dot followed by 2 or three characters, at the end
  if( (Email.search(checkbeg) != -1) || (Email.search(checkmid) == -1) || (Email.search(checkend) == -1) ) {
    return false;
  }else{
    return true;
  }
 }
 
 function verify(f)
 {
 
    //f = document.PatientQuestionnaireForm;
    //required fields
    f.Email.required = true;

    //required format
    f.Email.emailFormat = true;
    
     var msg;
     var empty_fields = "";
     var errors = "";
 
 
     //Loop through the elements of the form, looking for all 
     //text and textarea elements that don't have an "optional" property
     //defined. Then, check for fields that are empty and make a list of them.
     // Also, if any of these elements have a "min" or a "max" property defined,
     //then verify that they are numbers and that they are in the right range.
     //Put together error messages for fields that are wrong.
     
     for(var i = 0; i < f.length; i++) {
         var e = f.elements[i];
         if (e.type == "text"){
		if (e.value.length > 50 ){
			errors += e.name + " must be less than 50 characters\n";
		}
	 }
	 if (e.type == "textarea"){
		if(e.value.length > 200 ){
				errors += e.name + " must be less than 200 characters\n";
		}

         }
         if (((e.type == "text") || (e.type == "textarea")) && e.required) {
             //first check if the field is empty

             if ((e.value == null) || (e.value == "") || isblank(e.value)) {
                 empty_fields += "\n          " + e.name;
                 continue;
             }
            
            if (e.phoneFormat){
            	if (isPhoneNumber( e.value)) continue;
            	errors += e.name + " must be phone format (xxx-xxx-xxxx)\n";
            	continue;
            }
            
            if (e.emailFormat){
            	if (ValidateEmail( e.value)) continue;
            	errors += e.name + " must be email format (xxx@xxx.xxx)\n";
            	continue;
            }
            
         }
     }
     
     //Now, if there were any errors, then display the messages, and
     //return true to prevent the form from being submitted. Otherwise
     //return false.

     if (!empty_fields && !errors) return true;
     msg  = "______________________________________________________\n\n"
     msg += "The form was not submitted because of the following error(s).\n";
     msg += "Please correct these error(s) and re-submit.\n";
     msg += "______________________________________________________\n\n"
     if (empty_fields) {
         msg += "- The following required field(s) are empty:" 
                 + empty_fields + "\n";
         if (errors) msg += "\n";
     }
     msg += errors;
     alert(msg);
     return false;
 }
 
//-->