//Validate phone number for 10 digit US numbers.

//phoneField - The HTML input field containing the phone number to validate.

//format - Integer value that defines how to format the text field.

function validatePhone(phoneField, format) {
   var num = phoneField.value.replace(/[^\d]/g,'');
   if(num.length != 10) {
        //Alert the user that the phone number entered was invalid.
        alert('Favor entrar un número de teléfono válido, incluyendo código de área.  Ejemplo: (787)555-5555');                    
		return	false;
   } else {
        //Email was valid.  If format type is set, format the Phone to the desired style.
      switch(format) {
            case '0': //Format (xxx)-xxx-xxxx
               phoneField.value = "(" + num.substring(0,3) + ")" + 
                                    num.substring(3, 6) + "-" + num.substring(6);
               break;
            case '1': //Format xxx-xxx-xxxx
               phoneField.value = num.substring(0,3) + "-" + 
                                    num.substring(3, 6) + "-" + num.substring(6);
                break;
            default: //Format xxxxxxxxxx
               phoneField.value = num;
                return	true;
        }
   }
}

