// functions to help with forms

// To use this file include it on your page with the following syntax
// <script language="JavaScript" src=".../form.js"></script>
// Don't include the opening and closing <script> tags in this file!


/**
 * By using this function we can submit a form with a hyperlink
 * or image.  Ex: onclick:JavaScript submitForm(form_name). Only
 * works on one form per page and the form must be named 'form'.
 *
 * @param form is the name of the form to submit.
 */
function submitForm(name){
    if(document.forms[name] != null){
        setStatusBar("Submitting form: " + name);
        document.forms[name].submit();
        setStatusBar("Done");
    } else {
        setStatusBar("Error: no form named: " + name);
    }
}

/**
 * Method to verify that an entireform is non empty.
 *
 * @param is the name of the form to validate.
 */
function validateAndSubmit(name) {

   var message = "";
   var form    = document.forms[name];
   var count   = form.elements.length;
   var i       = 0;

   for(i=0; i<count; i++){
       if(form.elements[i].value.length == 0){
           message = message + form.elements[i].name + " is empty!\n";
       } 
   }
   if(message == "") {
       submitForm(name);
   } else {
       alert(message);
   }
}

/**
 * Method to set the status of the window
 * @param text to write on the status bar.
 */
function setStatusBar(text){
    window.status = text;
}


