function validateForm(form) {

// Make sure that the form objects - to, name, email address are filled in
     for (var i = 0; i < 3; i++) {
       	var theElement = form.elements[i];
       	if (!checkFilled(theElement))
            return false;
     }
  
  return true;
}

//--  End of function validateForm(form)


//-- Start of functions called from main sub procedure

// Make sure that a required field is filled in.
function checkFilled(textfield) {
    if (textfield.value.length == 0) {
      	alert("The field " + textfield.name + " is required.");
       	textfield.focus();
       	textfield.select();
       	return false;
    }
    return true;
}

// Validates that the phone number is in the correct format
function validatePhone(textfield) {
    phoneOK = true;
    var digits = 0;
    
    for (var i=0; i < textfield.value.length; i++) {
    	var theChar = textfield.value.charAt(i);
    	if ((theChar >= "0") && (theChar <= "9")) {
    	   digits++;
    	   continue;
    	}
    	if (theChar == " ") continue;
    	if (theChar == "-") continue;
    	if (theChar == "(") continue;
    	if (theChar == ")") continue;
    	if (theChar == ".") continue;
    	phoneOK = false;
    }
    
    phoneOK = phoneOK && (digits == 10);
    if (!phoneOK) {
    	alert("Please enter a phone number in the format (555) 555-5555");
    	textfield.focus();
    	textfield.select();
    }
    
    return phoneOK;    
}
