/**
 * BCTForms
 * A object for locating and defining forms 
 * @author CW
 * @usage: var formWithSaveInput = BCTForms.getFormWithElementName('save');
 *         var oForm = BCT_MAIN_FORM; OR var oForm = BCTForms.getFormWithAct() OR var oForm = BCTForms.getFormWithElementName('act')
 */

var BCTForms = {

  /**
   * getFormWithElementName
   * @param elementName : Filter the forms by this element's name
   * @param returnFormCollection : Should this return the form collection if we find more then one matching form, default: false
   */
  "getFormWithElementName" : function(elementName, returnFormCollection) {
    var returnFormCollection = ( typeof(returnFormCollection) != 'undefined' ) ? returnFormCollection : false;
    var documentForms        = document.getElementsByTagName('form');
    var formCollection       = new Array();
    var currentForm;
    for( index = 0; index < documentForms.length; index++ ) {
      currentForm = documentForms[index];
      if( eval("currentForm." + elementName) ) { // If the form has the desired element return that htmlElement Form
        formCollection.push(currentForm);
      }
    }
    if( formCollection.length > 0 ) {
      var includeFormCollection = ( returnFormCollection === true ) ? formCollection : false;
      return ( formCollection.length > 1 ) ? includeFormCollection : formCollection[0];
    }
    return false;
  },

  /**
   * getFormWithAct
   * return the form on the page with the act variable
   */
  "getFormWithAct" : function() {
    return this.getFormWithElementName("act");
  }

}

// This is an encapsulation for global variables that we could use across all clients
// For things like finding the form with the act variable
window.onload = function() {

  // Placeholder variable to contain the form element which contains the act variable indiciation the mainForm
  var BCT_MAIN_FORM = BCTForms.getFormWithAct();

}

