The problem is in your last line. getField('Name').setFocus() will set the focus to a field called 'Name' if one exists, NOT the first incomplete field. If 'Name' does not exist it will throw an error which you won't notice because the rest of the code would have executed properly. If you change 'Name' (with quotes) to f.name (no quotes) it will set the focus to one of the empty fields (the last one it found, no the first one).
In my opinion, a more practical approach is to remove the emptyFields array from the code, move the alert inside the loop, set the focus to the first empty field and break the loop as soon as an empty field is found (so as not to have 10 alerts pop up if there are 10 empty required fields).
If for example there are empty required fields, the alert will fire once, name the field, and set the focus to said field. After the user completes the field and clicks the button again, the alert will point out the next empty required field and set the focus to it, and so on until all required fields have been completed. Something like this:
for(var i = this.numFields - 1; i > -1; i--)
{
var fieldName = this.getNthFieldName(i);
if ((
this.getField(fieldName).type!="button" && this.getField(fieldName).required==true) &&
(this.getField(fieldName).value=="" || this.getField(fieldName).value=="Off"))
{
app.alert("You must fill in " +fieldName+ " before you can submit the form.");
this.getField(fieldName).setFocus();
break;
}
}
if(i<0){//your submit code}