/**
 * Common JavaScript
 *
 * Define global variables and functions common to all applictions.
 */

// Common Global Variables
{
   /**
    * Button Name
    *
    * Name of the submit button that was clicked on the form.
    *
    * Type:     String | Null
    */
   var Nebo_button_name = null;
} // Common Global Variables



// Common Functions
{
   /**
    * Button Clicked
    *
    * Preprocess form when submit button is clicked.
    *
    * Author:   Ron Andrews <ron.andrews@nebo.edu>
    * Version:  2.0
    * Date:     07/19/2008
    *
    * Change History:
    *   - Description
    *     - Author
    *     - mm/dd/yyyy
    *
    * ToDo:
    *   - 
    *
    * Known Issues:
    *   - 
    *
    * Param:    Button
    *   - Name: button
    *   - Type: Button Object
    *
    * Return:   None
    */
   function Nebo_buttonClicked(button)
   {
      // Local Variables
      {
         var forms = '';
         var i = 0;
         var button_hide;

         var rpt_time;
         var currentDate = new Date();
      }

      // Get List of Forms
      forms = document.getElementsByTagName('form');

      // Save Name of Button
      Nebo_button_name = button.getAttribute('name');

      if (Nebo_button_name == 'Nebo_report') {
         // Change form target to open report in a new window.
         for (i = 0; i < forms.length; i++) {
            forms[i].target = "_blank";
         }
      } else {
         // Change Form Target to Use Current Window.  This is necessary incase the current window had just been used to
         // run a report.
         for (i = 0; i < forms.length; i++) {
            forms[i].target = "";
         }

         // Hide Buttons to Guard Against Double Sumitting
         button_hide = Nebo_getElementsByClass('Nebo_ButtonHide');
         for (i = 0; i < button_hide.length; i++) {
            button_hide[i].style.visibility = "hidden";
         }
      }

      // Change Value of 'Nebo_rpt_time' to a New Timestamp Each Time Button Is Clicked
      rpt_time = document.getElementById('Nebo_rpt_time');
      if (rpt_time != null) {
         rpt_time.value = currentDate.getTime();
      }
      // I was going to change the value of the 'Nebo_report' button.  However, that changed the text on the button of
      // the form that remained on the screen when the new window opened up with the report.
   } // Nebo_buttonClicked()



   /**
    * Get Elements By Class
    *
    * Get list of elements by class name.  This only works if the element is not in multiple classes.
    *
    * Author:   David Wadley <david.wadley@nebo.edu> & Ron Andrews <ron.andrews@nebo.edu>
    * Version:  2.0
    * Date:     05/13/2009
    *
    * Change History:
    *   - Description
    *     - Author
    *     - mm/dd/yyyy
    *
    * ToDo:
    *   - 
    *
    * Known Issues:
    *   - 
    *
    * Param:    CSS Class Name
    *   - Name: css_class
    *   - Type: String
    *
    * Return:   Array of Objects
    */
   function Nebo_getElementsByClass(css_class)
   {
      // Local Variables
      {
         var all_html_tags = new Array();
         var tags_in_class = new Array();

         var i = 0;
         var j = 0;
      }

      // Create Array of All HTML Tags
      all_html_tags = document.getElementsByTagName("*");

      // Loop through All Tags
      for (i = 0; i < all_html_tags.length; i++) {

         // Build Array of Tags with Specified Class Name
         if (all_html_tags[i].className == css_class) {
            tags_in_class[j] = all_html_tags[i];
            j++;
         }
      }

      return tags_in_class;
   } // Nebo_getElementsByClass()


   /**
    * Open Window for Report
    *
    * Open a window for a report.  This should be used when a simple report has no criteria.
    *
    * Author:   Ron Andrews <ron.andrews@nebo.edu>
    * Version:  2.0
    * Date:     11/03/2008
    *
    * Change History:
    *   - Description
    *     - Author
    *     - mm/dd/yyyy
    *
    * ToDo:
    *   - 
    *
    * Known Issues:
    *   - 
    *
    * Param:    URL
    *   - Name: url
    *   - Type: String
    *
    * Return:   None
    */
   function Nebo_openWindowForReport(url)
   {
      // Local Variables
      {
         var report_window;
      }

      report_window = window.open(url, "_blank");
   } // Nebo_openWindowForReport()

} // Common Functions
