Validate and Save As Button PDF Form

Please can someone help me. I have a PDF form which I have added a button to that when clicked validates that all required fields have been completed (code below). What I would like to add is have the save as window open if all required fields are filled in.

Thanks for all help!

var emptyFields = [];

for (var i=0; i<this.numFields; i++) {

     var f= this.getField(this.getNthFieldName(i));

     if (f.type!="button" && f.required ) {

          if (f.valueAsString==f.defaultValue)emptyFields.push(;



if (emptyFields.length>0) {

     app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));