/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by ----- filename.js -----
 */

/* ----- formsubmithelpers.js ----- */
function inputSubmitOnClick(event) {
    if (!event) var event = window.event; // IE compatibility

    if (hasClassName(this, 'submitting')) {
        return confirm(window.form_resubmit_message);
    } else {
        addClassName(this, 'submitting');
    }
    return true;
}

function registerSubmitHandler() {
    var nodes = cssQuery('input[type=submit]');
    for (var i=0; i<nodes.length; i++) {
        var node = nodes[i];
        if (!node.onclick) {
            node.onclick = inputSubmitOnClick;
        }
    }
}
registerPloneFunction(registerSubmitHandler);


/* ----- validate-form.js ----- */


 function validate_form(form, mandatory_fields) {


  missing = []
  for (i=0;i<mandatory_fields.length;i++) {
    if ( mandatory_fields[i].field.value ) {
        }
        else {
         missing[missing.length] = mandatory_fields[i].label
        }
  }

  if ( missing.length > 0 ) {
    missing_fields = ""
    for (i=0;i<missing.length;i++) {
          missing_fields = missing_fields + "    " + missing[i] + "\n"
        }

    alert(
              "______________________________________________________________\n\n" +
              "The form was not submitted because of the following error(s).\n" +
                  "Please correct these error(s) and re-submit.\n" +
              "______________________________________________________________\n\n" +
                  " - The following required field(s) are empty:\n" +
                  missing_fields
                  )
        return false
  }

   return true;

 }

