// ---------------------------------------------------------------------------
//  Filename: utility.js
//   Version: 3.0
//      Date: 12/3/2007
//    Author: B. Zink
//   Purpose: Miscellaneous utility javascript functions
// ---------------------------------------------------------------------------
// Copyright© 2004-2010 Brz, Inc. All Rights Reserved
// ---------------------------------------------------------------------------
// Note: NO portion of this code may be copied, manipulated, viewed, or used
//       in ANY way without express written permission of the author and
//       BRZ, Inc.
// ---------------------------------------------------------------------------
// Revisions:
//
// 1. 12/3/2007 - bz
//    3.0.0 - Initial creation
// ---------------------------------------------------------------------------

// ---------------------------------------------------------------------------
// Setup some global variables
// ---------------------------------------------------------------------------
var dayIncrement           = 1000 * 60 * 60 * 24;
var currentPanel;

var pageTimerId       = 0;
var displayTimerId    = 0;
var displayTheCounter = 0;
var theTimerObject    = '';
var secondsToLogout   = 0;

var pageOpenDate;
var pageCloseDate;

//----------------------------------------------------------------------------
//UpdateClass
//
//   Purpose: Update the class of 'anchor' to show 'selected' in a menu
//Parameters: menuItem - anchor object (passed as this) 
//          
//   Returns: true
//----------------------------------------------------------------------------
function UpdateClass ( menuItem )
{
   // ------------------------------------------------------------------------
   // get the href of item passed for comparison
   // ------------------------------------------------------------------------
   var href = menuItem.href;
   
   // ------------------------------------------------------------------------
   // get all anchor elements in this menu
   // ------------------------------------------------------------------------
   var liElements = document.getElementsByTagName('a');
   
   // ------------------------------------------------------------------------
   // go through all of the anchors
   // ------------------------------------------------------------------------
   for (var i=0;i<liElements.length;i++) {
	   // --------------------------------------------------------------------
	   // shortcut to the <a> element
	   // --------------------------------------------------------------------
	   var theElement = liElements[i];
	   
	   // --------------------------------------------------------------------
	   // get href for this tag
	   // --------------------------------------------------------------------
	   var eHref = theElement.href;
	   
	   // --------------------------------------------------------------------
	   // set class to active if this one was clicked, otherwise, remove class
	   // --------------------------------------------------------------------
	   theElement.className = (eHref == href) ? 'active' : '';
   }

   // ------------------------------------------------------------------------
   // always return true to pass on processing
   // ------------------------------------------------------------------------
   return true;
}

function OpenPageInfo ( )
{
	pageOpenDate = new Date();
}

function UpdateInfo ( )
{
	pageCloseDate = new Date();
	
	var start	=	pageOpenDate.getTime();
	var end		=	pageCloseDate.getTime();
		
	var time    = (end - start) / 1000;
	
	var form    = document.forms[0];
	
	form.javascriptVar.value = time;
}

function AutoLogout (theDelay)
{
	if (arguments.length != 1) {
		theDelay = 30;
	}
	
	location.href='logout.php?auto=¿'+theDelay;
}

function StartPageTimer ( delayCount )
{
   // ------------------------------------------------------------------------
   // cancel any pending timeout when starting this page
   // ------------------------------------------------------------------------
   CancelPageTimer();
	
   // ------------------------------------------------------------------------
   // default to 15 minutes
   // ------------------------------------------------------------------------
   switch (arguments.length) {
      case 0:
         delayCount = 900000;
   }

   // ------------------------------------------------------------------------
   // calculate actual seconds (vs. milliseconds)
   // ------------------------------------------------------------------------
   var mySeconds = delayCount / 1000;
	
   // ------------------------------------------------------------------------
   // set the timer id to call autologout ...
   // ------------------------------------------------------------------------
   pageTimerId = setTimeout('AutoLogout('+mySeconds+')', delayCount);
}

function CancelPageTimer ( )
{
   // ------------------------------------------------------------------------
   // cancel any pending timer
   // ------------------------------------------------------------------------
   clearTimeout(pageTimerId);
}

function Trim (string)
{
	var	trimmed	=	string.replace(/^\s+|\s+$/g, '');
	
	return trimmed;
}

// ---------------------------------------------------------------------------
// ErrorMsg
//
//    Purpose: Format / make "standard" output for user input error
// Parameters: msg   - error message to display
//             title - optional title (e.g. warning, look out, etc.)
//    Returns: Nothing
// ---------------------------------------------------------------------------
function ErrorMsg ( msg, title, separator )
{
   // ------------------------------------------------------------------------
   // allow use of default
   // ------------------------------------------------------------------------
   switch( arguments.length) {
      case 1:
         title = 'Data Entry Error';
      case 2: 
         separator = '\n';
   }
   
   // ------------------------------------------------------------------------
   // holds completed error message
   // ------------------------------------------------------------------------
   var errorMsg;
   var message = '';
      
   // ------------------------------------------------------------------------
   // looking for an array (object) instead of string...
   // ------------------------------------------------------------------------
   if ( typeof(msg) == 'object' ) {
      for (var i=0;i<msg.length;i++) {
         message = message + msg[i] + separator;
      }
   }
   else {
      message = msg;
   }
   
   // ------------------------------------------------------------------------
   // Error message separator
   // ------------------------------------------------------------------------
   var separator = "___________________________________________\n\n";
   
   // ------------------------------------------------------------------------
   // Build error message
   // ------------------------------------------------------------------------
   errorMsg =  separator + 
               "  " + 
               title + 
               "\n" + 
               separator + 
               message;
   
   errorMsg = Replace(errorMsg, '**', '\n');
   
   // ------------------------------------------------------------------------
   // Display error message to user
   // ------------------------------------------------------------------------
   alert(errorMsg);   
}

function SetAction ( action, scope, recordId, submit )
{
	switch (arguments.length) {
	   case 0:
	   case 1:
	   case 2:
	       alert ('BRZ Error::SetAction');
	       return false;
	   case 3:
		   submit = 1;
		   break;
	}
	
	var form = document.forms[0];
	
	form.actionName.value = action;
	form.sqlscope.value = scope;
	form.javascriptVar.value = recordId;
	
	if (submit) {
	   form.submit();
	}
}

// ---------------------------------------------------------------------------
// ConfirmMsg
//
//    Purpose: Insure user is doing desired action
// Parameters: msg   - reminder message to display
//    Returns: bool - confirmed action or not confirmed
// ---------------------------------------------------------------------------
function ConfirmMsg ( msg, title )
{
   // ------------------------------------------------------------------------
   // if title was passed, use it otherwise, use default title
   // ------------------------------------------------------------------------
   if ( arguments.length != 2 ) {
      title = 'Please Confirm Suggested Action';
   }
   
   // ------------------------------------------------------------------------
   // holds completed error message
   // ------------------------------------------------------------------------
   var confirmMsg;
   
   // ------------------------------------------------------------------------
   // Error message separator
   // ------------------------------------------------------------------------
   var topSep     = "___________________________________________\n";
   var bottomSep  = "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\n";
   
   // ------------------------------------------------------------------------
   // Build error message
   // ------------------------------------------------------------------------
   confirmMsg = topSep + title + '\n' + bottomSep + msg;
   
   // ------------------------------------------------------------------------
   // Display error message to user
   // ------------------------------------------------------------------------
   return confirm(confirmMsg);   
}

// ---------------------------------------------------------------------------
// Submit
//
//    Purpose: Call forms submit method
// Parameters: nothing
//    Returns: nothing
// ---------------------------------------------------------------------------
function Submit ( formIndex )
{
   // ------------------------------------------------------------------------
   // if index was passed, use it otherwise, use default index - zero(0)
   // ------------------------------------------------------------------------
   if ( arguments.length != 1 ) {
      formIndex = 0;
   }
   
   // ------------------------------------------------------------------------
   // shortcut for form access - assumes only one form on page
   // ------------------------------------------------------------------------
   var form = document.forms[formIndex];
   
   // ------------------------------------------------------------------------
   // call submit method of form
   // ------------------------------------------------------------------------
   form.submit();   
}

// ---------------------------------------------------------------------------
// SubmitValidateCloseReload
//
//    Purpose: Call forms submit method with validation
// Parameters: validate - name validation function
//    Returns: nothing
// ---------------------------------------------------------------------------
function SubmitValidateCloseReload ( validateFunc, formIndex, useConfirm, isIE )
{
   // ------------------------------------------------------------------------
   // if title was passed, use it otherwise, use default title
   // ------------------------------------------------------------------------
   switch ( arguments.length ) {
      case 1:
         formIndex = 0;
      case 2:
         useConfirm = 1;
      case 3:
         isIE = 1;
   }

   // ------------------------------------------------------------------------
   // shortcut for form access
   // ------------------------------------------------------------------------
   var form = document.forms[formIndex];

   // ------------------------------------------------------------------------
   // insure that all required items are available, if so, submit the form
   // Note: This uses an eval to call a function passed as a string. This took
   //       me a LONG time to figure out.
   // ------------------------------------------------------------------------
   if ( eval(validateFunc)(form, useConfirm) ){                   
      form.submit();   
      if (isIE) {
         parent.opener.location.reload();
      }
      else {
         window.opener.parent.history.go(0);
      }
      for (var i=0;i<99999;i++);
      for (var i=0;i<99999;i++);
      for (var i=0;i<99999;i++);
      
      // setTimeout("window.close();",1000);
   }
}

// ---------------------------------------------------------------------------
// SubmitValidate
//
//    Purpose: Call forms submit method with validation
// Parameters: validate - name validation function
//    Returns: nothing
// ---------------------------------------------------------------------------
function SubmitValidate ( validateFunc, formIndex, useConfirm, update )
{
   // ------------------------------------------------------------------------
   // if title was passed, use it otherwise, use default title
   // ------------------------------------------------------------------------
   switch ( arguments.length ) {
      case 1:
         formIndex = 0;
      case 2:
         useConfirm = 0;
      case 3:
         update = 0;
   }

   // ------------------------------------------------------------------------
   // shortcut for form access
   // ------------------------------------------------------------------------
   var form = document.forms[formIndex];

   // ------------------------------------------------------------------------
   // insure that all required items are available, if so, submit the form
   // Note: This uses an eval to call a function passed as a string. This took
   //       me a LONG time to figure out.
   // ------------------------------------------------------------------------
   if ( eval(validateFunc)(form, useConfirm) ){                   
      if (update) {
    	  UpdateInfo();
      }
      form.submit();
      
   }
}

// ---------------------------------------------------------------------------
// SubmitValidateParams
//
//    Purpose: Call forms submit method with validation
// Parameters: validate - name validation function
//    Returns: nothing
// ---------------------------------------------------------------------------
function SubmitValidateParams ( validateFunc, param1, param2, param3 )
{
   // ------------------------------------------------------------------------
   // if title was passed, use it otherwise, use default title
   // ------------------------------------------------------------------------
   switch ( arguments.length ) {
      case 1:
         param1 = '';
      case 2:
         param2 = '';
      case 3:
         param3 = '';
   }

   // ------------------------------------------------------------------------
   // shortcut for form access
   // ------------------------------------------------------------------------
   var form = document.forms[0];

   // ------------------------------------------------------------------------
   // insure that all required items are available, if so, submit the form
   // Note: This uses an eval to call a function passed as a string. This took
   //       me a LONG time to figure out.
   // ------------------------------------------------------------------------
   if ( eval(validateFunc)(param1,param2,param3) ){                   
      form.submit();   
   }
}

// ---------------------------------------------------------------------------
// SubmitDelete
//
//      Purpose: Perform action to delete a record - confirm first
// ---------------------------------------------------------------------------
function SubmitDelete ( recordId, tableName, recordName, lastTab )
{
   // ------------------------------------------------------------------------
   // have default arguments for all but last one
   // ------------------------------------------------------------------------
   switch(arguments.length) {
      case 1:
         tableName = '';
      case 2:
         recordName='';
      case 3:
         lastTab = '';
   }

   if ( tableName != '' ) {
      tableName = '|' + tableName;
   }
   
   if ( recordName != '' ) {
      recordName = '|' + recordName;
   }
   
   if (lastTab != '') {
      lastTab = '|' + lastTab;
   }
   
   // ------------------------------------------------------------------------
   // get shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];
   
   // ------------------------------------------------------------------------
   // Build confirmation message
   // ------------------------------------------------------------------------
   var confirmMsg = "Are You Sure You Want To Delete This Record ?";
   
   // ------------------------------------------------------------------------
   // Display confirm message to user - asking to continue
   // ------------------------------------------------------------------------
   if ( ConfirmMsg(confirmMsg) == false )
      return;
      
   // ------------------------------------------------------------------------
   // set hidden field to value - allows javascript to talk to php
   // Note: Form MUST have a 'deletemode' hidden form element
   // ------------------------------------------------------------------------
   form.deletemode.value = recordId + tableName + recordName + lastTab;
   
   // ------------------------------------------------------------------------
   // submit the form - passes all hidden variables and form variables to php
   // ------------------------------------------------------------------------
   form.submit();
}

// ---------------------------------------------------------------------------
// SubmitConfirm
//
//      Purpose: Confirm normal form submission
// ---------------------------------------------------------------------------
function SubmitConfirm ( msg, formIndex )
{
   // ------------------------------------------------------------------------
   // if index was passed, use it otherwise, use default index - zero(0)
   // ------------------------------------------------------------------------
   switch (arguments.length) {
      case 0:
         msg = "Are You Sure You Want To Submit This Form?";
      case 1:
         formIndex = 0;
   }
   
   // ------------------------------------------------------------------------
   // get shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[formIndex];
      
   // ------------------------------------------------------------------------
   // Build confirmation message
   // ------------------------------------------------------------------------
   var confirmMsg = Replace(msg,"**","\n");
   confirmMsg     = Replace(confirmMsg,"##", "\t");
   
   // ------------------------------------------------------------------------
   // Display confirm message to user - asking to continue
   // ------------------------------------------------------------------------
   if ( ConfirmMsg(confirmMsg) == false )
      return;
      
   // ------------------------------------------------------------------------
   // submit the form - passes all hidden variables and form variables to php
   // ------------------------------------------------------------------------
   form.submit();
}

// ---------------------------------------------------------------------------
// BuildElementCode
//
//    Purpose: Build javascript to be evaluated to get element
// Parameters: elementName - name of element to build
//             formIndex   - index of desired form (optional - default 0)
//    Returns: code to evaluate to get element
// ---------------------------------------------------------------------------
function BuildElementCode ( elementName, formIndex )
{
   // ------------------------------------------------------------------------
   // if formIndex not passed, default to zero(0)
   // ------------------------------------------------------------------------
   if (arguments.length != 2 ) {
      formIndex = 0;
   }
   
   // ------------------------------------------------------------------------
   // return the string for evaluation
   // ------------------------------------------------------------------------
   return 'document.forms[' + formIndex + '].' + elementName;
}

// ---------------------------------------------------------------------------
// VerifyFormElementExists
//
//    Purpose: Determine if a named element exists in a form
// Parameters: theForm     - form to check
//             elementName - name of the element to check
//    Returns: Whether or not element was found (boolean)
// ---------------------------------------------------------------------------
function VerifyFormElementExists ( form, elementName )
{   
   // ------------------------------------------------------------------------
   // go through each element in the form looking for the element    
   // ------------------------------------------------------------------------
   for ( var i=0; i<form.elements.length; i++ ) {
      var theElement = form.elements[i];
      
      // ---------------------------------------------------------------------
      // fieldsets and legends don't have name properties
      // ---------------------------------------------------------------------
      if ( theElement.name == undefined || theElement.name == 'undefined' ) {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // compare and ignore the case of the names
      // ---------------------------------------------------------------------      
      if ( theElement.name.toUpperCase() == elementName.toUpperCase() )
         // ------------------------------------------------------------------
         // found it, so indicate
         // ------------------------------------------------------------------
         return true;
   }
   
   // ------------------------------------------------------------------------
   // element name was not found
   // ------------------------------------------------------------------------
   return false;
}

// ---------------------------------------------------------------------------
// ForceCase
//
//    Purpose: Force an element to be upper/lower case
// Parameters: elementName - name of element to use
//             upper       - flag for upper case   (optional - default 1)
//             formIndex   - index of desired form (optional - default 0)
//    Returns: whether browswer meets version passed
// ---------------------------------------------------------------------------
function ForceCase ( element, upper )
{
   // ------------------------------------------------------------------------
   // if desired level was not passed, default to version 4
   // ------------------------------------------------------------------------
   if ( arguments.length != 2) {
      upper = 1;
   }

   // ------------------------------------------------------------------------
   // if upper, then force to upper case, otherwise lower case
   // ------------------------------------------------------------------------
   if ( upper ) {
      element.value = element.value.toUpperCase();
   }
   else {
      element.value = element.value.toLowerCase();
   }
}

// ---------------------------------------------------------------------------
// TitleCase
//
//    Purpose: Convert a string to title case
// Parameters: string   - string to convert
//    Returns: converted string
// ---------------------------------------------------------------------------
function TitleCase ( string )
{
   // ------------------------------------------------------------------------
   // split the string on space word boundaries
   // ------------------------------------------------------------------------
   var words = string.split(' ');
   
   // ------------------------------------------------------------------------
   // initialize result 
   // ------------------------------------------------------------------------
   var result = '';
   
   // ------------------------------------------------------------------------
   // go through all words
   // ------------------------------------------------------------------------
   for (i=0;i<words.length;i++) {
      // ---------------------------------------------------------------------
      // shortcut to array element
      // ---------------------------------------------------------------------
      var word = words[i];
      
      // ---------------------------------------------------------------------
      // add first character as upper case, rest as lower case
      // ---------------------------------------------------------------------
      result = result + 
               word.charAt(0).toUpperCase() + 
               word.substring(1,word.length).toLowerCase();

      // ---------------------------------------------------------------------
      // separate with a space if not the last word
      // ---------------------------------------------------------------------
      if ( i!= words.length - 1 ) {
         result = result + ' ';
      }
   }
   
   // ------------------------------------------------------------------------
   // return converted string, e.g hello world ==> Hello World
   // ------------------------------------------------------------------------
   return result;
}   
   
// ---------------------------------------------------------------------------
// BuildFriendlyName 
//
//    Purpose: Build friendly name from 'separated' string
// Parameters: name        - name of form to search
//             separator   - word boundary separator
//    Returns: converted name
// ---------------------------------------------------------------------------
function BuildFriendlyName ( name, separator )
{
   // ------------------------------------------------------------------------
   // if no separator passed, use underscore
   // ------------------------------------------------------------------------
   if ( arguments.length != 2 ) {
      separator = VALID_RANGE_SEPARATOR;
   }
   
   var realName;
   var extraName='';
   
   var specialParts = name.split('~~');
   
   if ( specialParts.length > 1) {
      realName    =  specialParts[0];
      extraName   =  ' (' + specialParts[1] + ')';
      extraName   =  extraName.replace(/_/g,' ');      
   }
   else {
      realName = name;
   }
   // ------------------------------------------------------------------------
   // initialize result variable to null
   // ------------------------------------------------------------------------
   var friendlyName = "";
   
   // ------------------------------------------------------------------------
   // split the name into parts based on separator
   // ------------------------------------------------------------------------
   var parts = realName.split(separator);
   
   // ------------------------------------------------------------------------
   // go through all parts and convert to title case
   // ------------------------------------------------------------------------
   for ( var i=0;i<parts.length;i++ ) {
      var word = parts[i].toLowerCase();
      // ---------------------------------------------------------------------
      // use "special" separator to be a slash, e.g. single 'z'
      // ---------------------------------------------------------------------
      if ( word == SPECIAL_SLASH ) {
         friendlyName = friendlyName + "/ ";
         continue;
      }
      // ---------------------------------------------------------------------
      // use "special" separator to be a slash, e.g. single 'z'
      // ---------------------------------------------------------------------
      if ( word == SPECIAL_COMMA ) {
         friendlyName = friendlyName + ", ";
         continue;
      }
      
      // ---------------------------------------------------------------------
      // use "special" separator to be a slash, e.g. single 'z'
      // ---------------------------------------------------------------------
      if ( word == SPECIAL_PERIOD ) {
         friendlyName = friendlyName + ".";
         continue;
      }
      
      // ---------------------------------------------------------------------
      // convert this word
      // ---------------------------------------------------------------------
      friendlyName = friendlyName + TitleCase(parts[i]);

      // ---------------------------------------------------------------------
      // add space if not the last one
      // ---------------------------------------------------------------------
      if ( i != parts.length - 1 ) {
         friendlyName = friendlyName + ' ';
      }
   }      

   friendlyName = friendlyName + extraName;
   
   // ------------------------------------------------------------------------
   // return the friendly / converted name
   // ------------------------------------------------------------------------
   return friendlyName;
}

// ---------------------------------------------------------------------------
// GetObjectFromName 
//
//    Purpose: Get a reference to an object with a "php" name, e.g. sel[]
// Parameters: theForm       - name of form to search
//             theObjectName - name of object to find
//    Returns: reference to the "named" object
// ---------------------------------------------------------------------------
function GetObjectFromName ( objectName, form )
{
   // ------------------------------------------------------------------------
   // use default form if not passed
   // ------------------------------------------------------------------------
   if (arguments.length == 1) {
      form = document.forms[0];
   }

   // ------------------------------------------------------------------------
   // get the length of the name passed to find
   // ------------------------------------------------------------------------
   var searchLength = objectName.length;
   objectName = objectName.toLowerCase();
   
   // ------------------------------------------------------------------------
   // go through each element in the form
   // ------------------------------------------------------------------------
   for (var i=0;i<form.elements.length;i++) {
      // ---------------------------------------------------------------------
      // check to see if the name matches, if so return the object
      // ---------------------------------------------------------------------
      var elementName = form.elements[i].name;
      
      // ---------------------------------------------------------------------
      // fieldsets and legends don't have name properties
      // ---------------------------------------------------------------------
      if ( elementName == undefined || elementName == 'undefined' ) {
         continue;
      }
      
      if ( elementName.substring(0,searchLength).toLowerCase() == objectName )
         return form.elements[i];
   }

   // ------------------------------------------------------------------------
   // not found, indicate by returning null
   // ------------------------------------------------------------------------
   return null;
}

// ---------------------------------------------------------------------------
// TextCounter
//
//    Purpose: Count characters in an element and write count to another
// Parameters: elementToCount - name of element to count characters
//             elementToWrite - name of element where count is written
//             formIndex      - index of form (optional - default 0 )
//    Returns: whether browswer meets version passed
// ---------------------------------------------------------------------------
function TextCounter ( elementToCount, elementToWrite, maxlimit ) 
{
   // ------------------------------------------------------------------------
   // Limit the length to maxlimit
   // ------------------------------------------------------------------------
   LimitLength( elementToCount, maxlimit );
   
   // ------------------------------------------------------------------------
   // update the counter element
   // ------------------------------------------------------------------------
   elementToWrite.value = maxlimit - elementToCount.value.length;
}

// ---------------------------------------------------------------------------
// LimitLength
//
//    Purpose: Limit length of a form element - typically a textarea
// Parameters: element     - element to limit
//             maxLength   - maximum length allowed
//    Returns: whether browswer meets version passed
// ---------------------------------------------------------------------------
function LimitLength ( element, maxLength )
{
   // ------------------------------------------------------------------------
   // check the length of the element
   // ------------------------------------------------------------------------
   if (element.value.length > maxLength ) {
      // ---------------------------------------------------------------------
      // notify user and truncate the text
      // ---------------------------------------------------------------------
      ErrorMsg ( 'Maximum Length (' + maxLength + ' chars) Reached' );
      element.value = element.value.substring(0, maxLength);
   }
}   

// ---------------------------------------------------------------------------
// pageWidth 
//
//    Purpose: Get width of current page window
// Parameters: none
//    Returns: page width in pixels
// ---------------------------------------------------------------------------
function pageWidth ( ) 
{
   return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;
}

// ---------------------------------------------------------------------------
// pageHeight 
//
//    Purpose: Get height of current page window
// Parameters: none
//    Returns: page height in pixels
// ---------------------------------------------------------------------------
function pageHeight ( ) 
{
   return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;
}

// ---------------------------------------------------------------------------
// pageLeft 
//
//    Purpose: Get left side of current page window
// Parameters: none
//    Returns: pixel position of left side of page
// ---------------------------------------------------------------------------
function pageLeft ( ) 
{
   return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
}

// ---------------------------------------------------------------------------
// pageTop 
//
//    Purpose: Get top side of current page window
// Parameters: none
//    Returns: pixel position of top side of page
// ---------------------------------------------------------------------------
function pageTop() 
{
   return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}

// ---------------------------------------------------------------------------
// pageRight 
//
//    Purpose: Get right side of current page window
// Parameters: none
//    Returns: pixel position of right side of page
// ---------------------------------------------------------------------------
function pageRight ( ) 
{
   return pageLeft()+pageWidth();
}

// ---------------------------------------------------------------------------
// pageBottom 
//
//    Purpose: Get bottom side of current page window
// Parameters: none
//    Returns: pixel position of bottom side of page
// ---------------------------------------------------------------------------
function pageBottom ( ) 
{
   return pageTop()+pageWidth();
}

// ---------------------------------------------------------------------------
// OpenInfoWindow 
//
//    Purpose: Open a new browser window with specific size
// Parameters: name     - name of the window
//             URL      - url for window to go
//             height   - height of window in pixels
//             width    - width of window in pixels
//             debug    - optional debug flag
//    Returns: nothing
// ---------------------------------------------------------------------------
function OpenInfoWindow ( name, URL, height, width, debug, center, scrollbar )
{
   // ------------------------------------------------------------------------
   // if debug/center was not passed, default to no debug and no center
   // ------------------------------------------------------------------------
   switch ( arguments.length ) {
      case 4:
         debug    =  0;
      case 5:
         center   =  0;
      case 6:
         scrollbar = 'no';
         break;
   }
   
   // ------------------------------------------------------------------------
   // setup parameters for window.open function
   // ------------------------------------------------------------------------
   var strURL     =  URL;      
   var strSize    =  'height=' + height + ',width=' + width + ',';      
   var strTools   =  'toolbar=no,menubar=no,';      
   var strStyle   =  'location=no,directories=no,';      
   var strPos     = '';
   
   // ------------------------------------------------------------------------
   // add 'dressing' if debuging flag is set
   // ------------------------------------------------------------------------
   if ( debug != 0 ) {
      strTools = strTools + 'scrollbars=yes,';
      strStyle = strStyle + 'resizable=yes,status=yes';      
   }
   else {
      strTools = strTools + 'scrollbars=' + scrollbar + ',';
      strStyle = strStyle + 'resizable=no,status=no';
   }   
   
   // ------------------------------------------------------------------------
   // center on screen if center flag is set
   // ------------------------------------------------------------------------
   if ( center != 0 ) {
      var left    = (screen.width - width) / 2;
      var top     = (screen.height - height) / 2;
      var strPos  = ',left=' + left + ',top=' + top;
   }

   // ------------------------------------------------------------------------
   // build complete configuration string 
   // ------------------------------------------------------------------------
   var strConfig  = strSize + strTools + strStyle + strPos;      
   
   // ------------------------------------------------------------------------
   // open the window
   // ------------------------------------------------------------------------
   thewindow = window.open( strURL, name, strConfig );
}

// ---------------------------------------------------------------------------
// GetDataFromURL
//
//    Purpose: Bring up a window for data entry and then return results
//             back to calling window.
// Parameters: windowName  - name/title of browser window
//             URL         - url of code to call for data collection
//             height      - height in pixels of browser window
//             width       - width in pixels of browser window
//             elementName - name of element to put value on closing
//             formIndex   - index of form - typically zero(0)
//             params      -  extra parameters for url
//    Returns: nothing
// ---------------------------------------------------------------------------
// GetDataFromURL(
//					'window049197', 
//					'php.php?code=select_divisions4&scope=commons', 
//					'300', 
//					'480', 
//					'qqq__ytdrpt__A__divisionId', 
//					'0', 
//					'&across=5&colWidth=100',
//					'no'
//				);
/*
function GetDataFromURL ( windowName, URL, height, width, elementName, formIndex, params, scrollbar )
{
   // ------------------------------------------------------------------------
   // if debug was not passed, default to no debug
   // ------------------------------------------------------------------------
   switch (arguments.length) {
      case 5:
         formIndex = 0;
      case 6:
         params = '';
      case 7:
         scrollbar = 'no';
   }
   
   // ------------------------------------------------------------------------
   // shortcut for form access
   // ------------------------------------------------------------------------
   var form = document.forms[formIndex];

   // ------------------------------------------------------------------------
   // build element from name passed (MUST do this for IE 4)
   // ------------------------------------------------------------------------
   var javascript = BuildElementCode( elementName );
   
   var theElement = eval( javascript );
   
   // ------------------------------------------------------------------------
   // sometimes pass ? as part of initial URL - dont do it twice
   // ------------------------------------------------------------------------
   separator = (URL.indexOf('?') < 1 ) ? '?' : '&';
   
   // ------------------------------------------------------------------------
   // build parameters to pass to URL - elem is element name and val is value
   // ------------------------------------------------------------------------
   var params = separator + 
                "elem=" + form.name + "." + theElement.name + 
                "&val=" + theElement.value +
                params;
   
   // ------------------------------------------------------------------------
   // build complete url with parameters
   // ------------------------------------------------------------------------
   var newUrl = URL + params;
 
   // ------------------------------------------------------------------------
   // open window
   // ------------------------------------------------------------------------
   OpenInfoWindow( windowName, newUrl, height, width,0,0,scrollbar );
}
*/

function GetDataFromURL ( windowName, URL, height, width, elementName, scrollbar )
{
   // ------------------------------------------------------------------------
   // build element from name passed (MUST do this for IE 4)
   // ------------------------------------------------------------------------
   var javascript = BuildElementCode( elementName );
      
   // ------------------------------------------------------------------------
   // get element object from above javascript
   // ------------------------------------------------------------------------
   var theElement = eval( javascript );
   
   // ------------------------------------------------------------------------
   // build complete url with parameters
   // ------------------------------------------------------------------------
   var newUrl = URL + theElement.value;
 
   // ------------------------------------------------------------------------
   // open window
   // ------------------------------------------------------------------------
   OpenInfoWindow( windowName, newUrl, height, width,0,0,scrollbar );
}

// ---------------------------------------------------------------------------
// Replace
//
//    Purpose: Replace part of a string with another string
// Parameters: string            - string holding text
//             textToReplace     - what to replace (old text)
//             replacementText   - new text
//    Returns: modified string
// ---------------------------------------------------------------------------
function Replace ( string, textToReplace, replacementText )
{
   // ------------------------------------------------------------------------
   // get string lengths for easy initial comparison
   // ------------------------------------------------------------------------
   var strLength = string.length;    
   var txtLength = textToReplace.length;      
   
   // ------------------------------------------------------------------------
   // if either is empty, nothing to do
   // ------------------------------------------------------------------------
   if ((strLength == 0) || (txtLength == 0)) 
      return string;    

   // ------------------------------------------------------------------------
   // if strings are equal, return string
   // ------------------------------------------------------------------------
   if ( textToReplace == replacementText ) {
      return string;
   }
   
   // ------------------------------------------------------------------------
   // determine if text to replace exists in string
   // ------------------------------------------------------------------------
   var pos = string.indexOf(textToReplace);    
   
   // ------------------------------------------------------------------------
   // if it doesn't exist, then return string
   // ------------------------------------------------------------------------
   while ( pos != -1 ) {      
      // ---------------------------------------------------------------------
      // text to replace exists, so build a new string
      // ---------------------------------------------------------------------
      var strLength  = string.length;
      var startStr   = string.substring(0,pos) + replacementText;    
      var endStr     = string.substring(pos+txtLength,strLength);
      string         = startStr + endStr;
      pos            = string.indexOf(textToReplace);
   }
   
   // ------------------------------------------------------------------------
   // return the "new" string with all replacements made
   // ------------------------------------------------------------------------
   return string;
}

// ---------------------------------------------------------------------------
// FirstString
//
//    Purpose: Match first part of a string
// Parameters: string   - string for comparison
//             match    - string to match
//    Returns: if match is successful
// ---------------------------------------------------------------------------
function FirstString ( string, match )
{
   // ------------------------------------------------------------------------
   // get length of string to match
   // ------------------------------------------------------------------------
   var length = match.length;
   
   // ------------------------------------------------------------------------
   // get appropriate number of characters and conver to lower case
   // ------------------------------------------------------------------------
   var first  = string.substr(0,length).toLowerCase();
   var second = match.toLowerCase();
   
   // ------------------------------------------------------------------------
   // return if they match
   // ------------------------------------------------------------------------
   return (first == second );
}

// ---------------------------------------------------------------------------
// GetBrowserName
//
//    Purpose: Return browser name
// Parameters: nothing
//    Returns: name of browser
// ---------------------------------------------------------------------------
function GetBrowserName ( )
{
   // ------------------------------------------------------------------------
   // get name of browser into temp variable
   // ------------------------------------------------------------------------
   var browser = navigator.appName;
   
   // ------------------------------------------------------------------------
   // convert it to uppercase
   // ------------------------------------------------------------------------
   broswer.touppercase();
   
   // ------------------------------------------------------------------------
   // check for Microsoft - Internet Explorer
   // ------------------------------------------------------------------------
   if ( broswer.indexOf("MICROSOFT") != -1 ) {
      return "IE";
   }
   
   // ------------------------------------------------------------------------
   // check for Netscape - Netscape Navigator
   // ------------------------------------------------------------------------
   if (browser.indexOf("NETSCAPE") != -1 ) {
      return "NN";
   }
   
   // ------------------------------------------------------------------------
   // other browser
   // ------------------------------------------------------------------------
   return "OT";
}   

// ---------------------------------------------------------------------------
// CheckBrowserVersion
//
//    Purpose: Determine if browser version is a particular version or greater
// Parameters: level    - level to check
//    Returns: whether browswer meets version passed
// ---------------------------------------------------------------------------
function CheckBrowserVersion ( version )
{
   // ------------------------------------------------------------------------
   // if desired level was not passed, default to version 4
   // ------------------------------------------------------------------------
   if ( arguments.length != 1 ) {
      version = 4;
   }
   
   // ------------------------------------------------------------------------
   // get browser version
   // ------------------------------------------------------------------------
   var ver = parseInt( navigator.appVersion.charAt(0), 10 );
  
   // ------------------------------------------------------------------------
   // return result
   // ------------------------------------------------------------------------
   return (ver >= version );
}

// ---------------------------------------------------------------------------
// SetFocus
//
//      Purpose: Set focus to particular element of form
//   Parameters: elementName  - name of element to find
//      Returns: nothing
// ---------------------------------------------------------------------------
function SetFocusElement ( element )
{
   element.focus();
   
   if (element.type == 'text') {
      element.select();
   }
}

// ---------------------------------------------------------------------------
// SetFocus
//
//      Purpose: Set focus to particular element of form
//   Parameters: elementName  - name of element to find
//      Returns: nothing
// ---------------------------------------------------------------------------
function SetFocusName ( elementName )
{
   var theElement = GetObjectFromName(elementName);
   theElement.focus();
   
   return true;
}

// ---------------------------------------------------------------------------
// SetFocus
//
//      Purpose: Set focus to particular element of form
//   Parameters: elementName  - name of element to find
//      Returns: nothing
// ---------------------------------------------------------------------------
function SetFocus ( elementName, formIndex )
{
   // ------------------------------------------------------------------------
   // initialize to NOT using first field
   // ------------------------------------------------------------------------
   var first = 0;
   
   // ------------------------------------------------------------------------
   // if desired level was not passed, default to version 4
   // ------------------------------------------------------------------------
   switch (arguments.length) {
      case 0:
         first = 1;
      case 1:
         formIndex = 0;
   }
   
   // ------------------------------------------------------------------------
   // get shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[formIndex];
   
   // ------------------------------------------------------------------------
   // go through each form element looking for one passed
   // ------------------------------------------------------------------------
   for (var i=0;i<form.elements.length;i++) {
      var type = form.elements[i].type;
      var name = form.elements[i].name;
      
      // ---------------------------------------------------------------------
      // fieldsets and legends don't have name properties
      // ---------------------------------------------------------------------
      if ( name == undefined || name == 'undefined' ) {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // radio / hidden dont need/want focus
      // ---------------------------------------------------------------------
      if ( type == 'radio' ||
           type == 'hidden' ) 
         continue;
 
      // ---------------------------------------------------------------------
      // if first element desired, set focus and return
      // ---------------------------------------------------------------------
      if ( first ) {
         // ------------------------------------------------------------------
         // if first element desired, set focus to it
         // ------------------------------------------------------------------
         form.elements[i].focus();
         
         // ------------------------------------------------------------------
         // if a text element, select all the text in the field
         // ------------------------------------------------------------------
         if ( type == 'text' ) {
            form.elements[i].select();
         }

         // ------------------------------------------------------------------
         // focus complete, return
         // ------------------------------------------------------------------
         return;
      }
      
      // ---------------------------------------------------------------------
      // if desired element found, set focus and return
      // ---------------------------------------------------------------------
      if ( name.substr(0,elementName.length) == elementName ) {
         form.elements[i].focus();
         if ( type == 'text' ) 
            form.elements[i].select();
         return;
      }
   }
}

// ---------------------------------------------------------------------------
// ReorderIndex
//
//      Purpose: Re-order index starting at first value in list by 10
// ---------------------------------------------------------------------------
function ReorderIndex ( indexName, increment )
{
   // ------------------------------------------------------------------------
   // default index name and increment
   // ------------------------------------------------------------------------
   switch (arguments.length) {
      case 0:
         indexName = 'INDEXORDER';
      case 1:
         increment = 10;         
   }
   
   var nameLength = indexName.length;
   
   // ------------------------------------------------------------------------
   // default shortcut access to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];
   
   // ------------------------------------------------------------------------
   // looking for first one 
   // ------------------------------------------------------------------------
   var first = true;
   
   // ------------------------------------------------------------------------
   // go through each element in form and look for select item
   // ------------------------------------------------------------------------
   for (var i=0;i<form.elements.length;i++) {
      var theElement = form.elements[i];
      var name       = theElement.name;
      var value      = theElement.value;
      
      // ---------------------------------------------------------------------
      // fieldsets and legends don't have name properties
      // ---------------------------------------------------------------------
      if ( theElement.name == undefined || theElement.name == 'undefined' ) {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // if not an indexOrder field, then skip it
      // ---------------------------------------------------------------------
      if (name.substr(0,nameLength) != indexName ) {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // if this is the first one, get the value and remove 'first' flage
      // ---------------------------------------------------------------------
      if (first) {
         sequence = value;
         first    = false;
         continue;
      }

      // ---------------------------------------------------------------------
      // update the value by adding 10
      // ---------------------------------------------------------------------
      sequence = parseInt(sequence,10) + increment;
      theElement.value = sequence;
   }
}

// ---------------------------------------------------------------------------
// HandleDivisionChange
//
//      Purpose: Handle changes in divisions
//   Parameters: none
//      Returns: nothing
// ---------------------------------------------------------------------------
function HandleDivisionChange ( )
{
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];
   
   var total = 0;
   var textElement;
   
   // ------------------------------------------------------------------------
   // go through each element in form and look for select item
   // ------------------------------------------------------------------------
   for (var i=0;i<form.elements.length;i++) {
      // ---------------------------------------------------------------------
      // get shortcut to this element and its attributes
      // ---------------------------------------------------------------------
      var theElement = form.elements[i];
      var type       = theElement.type;
      var name       = theElement.name;
      var value      = theElement.value;
      
      // ---------------------------------------------------------------------
      // if this is not a radio button, check for text input
      // ---------------------------------------------------------------------
      if (type.substr(0,5) != "radio") {
         // ------------------------------------------------------------------
         // if text, then save the element object
         // ------------------------------------------------------------------
         if (name == "division") {
            textElement = theElement;
         }
         continue;
      }
      
      // ---------------------------------------------------------------------
      // add total of all radio buttons checked
      // ---------------------------------------------------------------------
      if (theElement.checked)      
         total += parseInt(value,10);
   }
      
   // ------------------------------------------------------------------------
   // put the total in the textbox
   // ------------------------------------------------------------------------
   textElement.value = total;   
}

// ---------------------------------------------------------------------------
// HandleDivisionChange2
//
//      Purpose: Handle changes in divisions
//   Parameters: none
//      Returns: nothing
// ---------------------------------------------------------------------------
function HandleDivisionChange2 ( )
{
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];
   
   var total = 0;
   var textElement;
   var totalString = '';
   var totalArray = new Array;
   
   // ------------------------------------------------------------------------
   // go through each element in form and look for select item
   // ------------------------------------------------------------------------
   for (var i=0;i<form.elements.length;i++) {
      // ---------------------------------------------------------------------
      // get shortcut to this element and its attributes
      // ---------------------------------------------------------------------
      var theElement = form.elements[i];
      var type       = theElement.type;
      var name       = theElement.name;
      var value      = theElement.value;
      
      // ---------------------------------------------------------------------
      // if this is not a radio button, check for text input
      // ---------------------------------------------------------------------
      if (type == "text") {
         // ------------------------------------------------------------------
         // if text, then save the element object
         // ------------------------------------------------------------------
         if (name == "division") {
            textElement = theElement;
         }
         continue;
      }

      if (type != 'radio') {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // add total of all radio buttons checked
      // ---------------------------------------------------------------------
      if (theElement.checked) {
         if ( theElement.value != 0 ) {
            totalArray[total++] = value;
         }
      }
         
   }
      
   var length = totalArray.length;
   
   totalArray.sort(function(a,b) { return a-b;});
   totalString = totalArray.join();
   
   //for (var i=0;i<length;i++) {
   //   var additive = (i == length - 1) ?
   //                  totalArray[i] :
   //                  totalArray[i] + ',';
   //   totalString += additive;
   //}
   
   // ------------------------------------------------------------------------
   // put the total in the textbox
   // ------------------------------------------------------------------------
   textElement.value = totalString;   
}

// ---------------------------------------------------------------------------
// HandleDivisionChange3
//
//      Purpose: Handle changes in divisions
//   Parameters: none
//      Returns: nothing
// ---------------------------------------------------------------------------
function HandleDivisionChange3 ( )
{
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];
   
   var total = 0;
   var textElement;
   var totalString = '';
   var totalArray = new Array;
   
   // ------------------------------------------------------------------------
   // go through each element in form and look for select item
   // ------------------------------------------------------------------------
   for (var i=0;i<form.elements.length;i++) {
      // ---------------------------------------------------------------------
      // get shortcut to this element and its attributes
      // ---------------------------------------------------------------------
      var theElement = form.elements[i];
      var type       = theElement.type;
      var name       = theElement.name;
      var value      = theElement.value;
      
      // ---------------------------------------------------------------------
      // if this is not a radio button, check for text input
      // ---------------------------------------------------------------------
      if (type == "text") {
         // ------------------------------------------------------------------
         // if text, then save the element object
         // ------------------------------------------------------------------
         if (name == "division") {
            textElement = theElement;
         }
         continue;
      }

      if (type != 'checkbox') {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // add total of all radio buttons checked
      // ---------------------------------------------------------------------
      if (theElement.checked) {
         var parts = name.split(DATA_SEPARATOR);
         totalArray[total++] = parts[1];
      }
      UpdateCheckboxStyle(theElement);   
   }
      
   var length = totalArray.length;
   
   totalArray.sort(function(a,b) { return a-b;});
   totalString = totalArray.join();
   
   //for (var i=0;i<length;i++) {
   //   var additive = (i == length - 1) ?
   //                  totalArray[i] :
   //                  totalArray[i] + ',';
   //   totalString += additive;
   //}
   
   // ------------------------------------------------------------------------
   // put the total in the textbox
   // ------------------------------------------------------------------------
   textElement.value = totalString;   
}

//---------------------------------------------------------------------------
//HandleDivisionChange3
//
//   Purpose: Handle changes in divisions
//Parameters: none
//   Returns: nothing
//---------------------------------------------------------------------------
function HandleCapabilityChange ( )
{
	// ------------------------------------------------------------------------
	// shortcut to form
	// ------------------------------------------------------------------------
	var form = document.forms[0];
	
	var total = 0;
	var textElement;
	var totalString = '';
	var totalArray = new Array;
	
	// ------------------------------------------------------------------------
	// go through each element in form and look for select item
	// ------------------------------------------------------------------------
	for (var i=0;i<form.elements.length;i++) {
	   // ---------------------------------------------------------------------
	   // get shortcut to this element and its attributes
	   // ---------------------------------------------------------------------
	   var theElement = form.elements[i];
	   var type       = theElement.type;
	   var name       = theElement.name;
	   var value      = theElement.value;
	   
	   // ---------------------------------------------------------------------
	   // if this is not a radio button, check for text input
	   // ---------------------------------------------------------------------
	   if (type == "text") {
	      // ------------------------------------------------------------------
	      // if text, then save the element object
	      // ------------------------------------------------------------------
	      if (name == "capability") {
	         textElement = theElement;
	      }
	      continue;
	   }
	
	   if (type != 'checkbox') {
	      continue;
	   }
	   
	   // ---------------------------------------------------------------------
	   // add total of all radio buttons checked
	   // ---------------------------------------------------------------------
	   if (theElement.checked) {
	      var parts = name.split(DATA_SEPARATOR);
	      totalArray[total++] = parts[1];
	   }
	   UpdateCheckboxStyle(theElement);   
	}
	   
	var length = totalArray.length;
	
	totalArray.sort(function(a,b) { return a-b;});
	totalString = totalArray.join();
	
	// ------------------------------------------------------------------------
	// put the total in the textbox
	// ------------------------------------------------------------------------
	textElement.value = totalString;   
}


// ---------------------------------------------------------------------------
// UpdateCheckBoxStyle
//
//      Purpose: Update checkbox style
// ---------------------------------------------------------------------------
function UpdateCheckboxStyle ( checkbox, chkStyle ) 
{
   switch(arguments.length) {
      case 1:
         chkStyle = 'checkbox';
         break;
   }
   
   var style   =  (checkbox.checked == true) ? chkStyle : '';
   
   checkbox.className = style;   
}


// ---------------------------------------------------------------------------
// ClearSetCheckboxes
//
//      Purpose: Update appropriate checkboxes - all or none
// ---------------------------------------------------------------------------
function ClearSetCheckboxes ( radioElement, idname, namePart )
{
   // ------------------------------------------------------------------------
   // get default id of textbox to set/clear
   // ------------------------------------------------------------------------
   switch ( arguments.length ) {
      case 1:
         idname   =  'txt_division';
      case 2:
    	  namePart =  '';
         break;
   }
   
   // ------------------------------------------------------------------------
   // initialize variables
   // ------------------------------------------------------------------------
   var radioValue = radioElement.value;
   var isChecked;
   var textValue='';
   var total=0;
   var totalString = '';
   var totalArray = new Array;
   
   // ------------------------------------------------------------------------
   // setup appropriate values based on radio value
   // ------------------------------------------------------------------------
   switch(radioValue) {
      case 'X':
         return;
      case 'A':
         isChecked = true;
         break;
      case 'N':
         isChecked = false;
         textValue = '';
         break
   }
   
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];
   var parts;
   
   // ------------------------------------------------------------------------
   // go through all elements on the form
   // ------------------------------------------------------------------------
   for (var i=0; i < form.elements.length; i++) {
      // ---------------------------------------------------------------------
      // shortcut to the element
      // ---------------------------------------------------------------------      
      var theElement = form.elements[i];
      
      // ---------------------------------------------------------------------
      // fieldsets and legends don't have name properties
      // ---------------------------------------------------------------------
      if ( theElement.name == undefined || theElement.name == 'undefined' ) {
         continue;
      }

      // ---------------------------------------------------------------------
      // not a checkbox, so continue
      // ---------------------------------------------------------------------
      if (theElement.type != 'checkbox') {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // split the name into parts (allows for multiples on same form)
      // ---------------------------------------------------------------------
      parts	=	theElement.name.split(DATA_SEPARATOR);
      
      // ---------------------------------------------------------------------
      // see if 'special' name is passed - allows setting multiple checkboxes
      // ---------------------------------------------------------------------
      if (namePart != '') {
    	  if (parts[1] != namePart) 
    	  	continue;
      }
      
      // ---------------------------------------------------------------------
      // set checkbox appropriately
      // ---------------------------------------------------------------------
      theElement.checked = isChecked;
      
      if (isChecked) {
         var index = (namePart == '') ? 1 : 2;
         totalArray[total++] = parts[index];
      }
      
      // ---------------------------------------------------------------------
      // update the checkbox style
      // ---------------------------------------------------------------------
      UpdateCheckboxStyle(theElement);
   }
   
   // ------------------------------------------------------------------------
   // if name is passed, then update the text element
   // ------------------------------------------------------------------------
   if ( idname != '' && idname != 'none') {
      totalArray.sort(function(a,b) { return a-b;});
      textValue = totalArray.join();
      var obj = document.getElementById(idname);
      obj.value = textValue;
   }
} 

// ---------------------------------------------------------------------------
// FindAuthUser
//
//      Purpose: Find auth user
// ---------------------------------------------------------------------------
function FindAuthUser ( code, fieldName )
{
   // ------------------------------------------------------------------------
   // setup default field name to find
   // ------------------------------------------------------------------------
   switch (arguments.length ) {
      case 0:
	     alert("'code' Argument Cannot Be Blank...");
	     break;
      case 1:
	     fieldName = 'username';
	     break;
   }
   
   // ------------------------------------------------------------------------
   // get length of field passed
   // ------------------------------------------------------------------------
   var theElement = GetObjectFromName(fieldName);
   var length = theElement.length;
   
   // ------------------------------------------------------------------------
   // get the current value of this element
   // ------------------------------------------------------------------------
   var value = theElement.value;

   // ------------------------------------------------------------------------
   // find cant be blank
   // ------------------------------------------------------------------------
   if (IsBlank(value) ) {
      alert( 'Username Cant Be Blank For Search' );
      theElement.focus();
      theElement.select();
      return;
   }

   // ------------------------------------------------------------------------
   // build the url to look for
   // ------------------------------------------------------------------------
   var url  = code + value;      

   // ------------------------------------------------------------------------
   // go to the url
   // ------------------------------------------------------------------------      
   location.href  = url;   
}

// ---------------------------------------------------------------------------
// FindPoc
//
//      Purpose: Find POC from name
// ---------------------------------------------------------------------------
function FindPoc ( formIndex, code )
{
   var scope = '';
   
   // ------------------------------------------------------------------------
   // if nothing passed, use default form index 
   // ------------------------------------------------------------------------
   switch ( arguments.length) {
      case 0:
         formIndex = 1;
      case 1:
         code  = 'update_poc';
         scope ='&scope=systems';
         break;
   }
   
   // ------------------------------------------------------------------------
   // need first and last names
   // ------------------------------------------------------------------------
   var foundFirst = false;
   var foundLast  = false;
   var params     = '';   
   var returnFirst;
   var returnLast;
   
   // ------------------------------------------------------------------------
   // get shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[formIndex];
   
   // ------------------------------------------------------------------------
   // go through each element looking for 'username'
   // ------------------------------------------------------------------------
   for (var i=0;i<form.elements.length;i++) {
      var firstName        = 'firs';
      var lastName         = 'last';
      var theElement       = form.elements[i];
      var theElementName   = theElement.name;
      
      // ---------------------------------------------------------------------
      // fieldsets and legends don't have name properties
      // ---------------------------------------------------------------------
      if ( theElement.name == undefined || theElement.name == 'undefined' ) {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // if not username, go to next element
      // ---------------------------------------------------------------------
      var partial = theElementName.substring(0,4);
      
      if ( partial != firstName && partial != lastName) {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // get the current value of this element
      // ---------------------------------------------------------------------
      var value = theElement.value;
      
      // ---------------------------------------------------------------------
      // determine message for type (first/last)
      // ---------------------------------------------------------------------
      var msg = (partial=='firs') ? 
                 'First' :
                 'Last'

      // ---------------------------------------------------------------------
      // find cant be blank
      // ---------------------------------------------------------------------
      if (IsBlank(value) ) {
         alert( msg + ' Name Cannot Be Blank For Search' );
         theElement.focus();
         theElement.select();
         return;
      }

      // ---------------------------------------------------------------------
      // validate this element - if not numeric, indicate and go back
      // ---------------------------------------------------------------------
      if ( !IsAlpha(value) ) {
         alert( msg + ' Name Contains Non-AlphaNumeric Values' );
         theElement.focus();
         theElement.select();
         return;
      }
      
      if (msg == 'First') {
         foundFirst = true;
         params = params + '&firstName=' + value;
         returnFirst = value;
      }
      
      if (msg == 'Last') {
         foundLast = true;
         params = params + '&lastName=' + value;
         returnLast = value;
      }
   }
   
   if ( foundFirst && foundLast ) {
      params = params + '&id=' + returnLast + ',' + returnFirst;
      
      // ---------------------------------------------------------------------
      // build the url to look for
      // ---------------------------------------------------------------------
      var url  = "php.php?code=" + code + scope + "&type=name" + params;      
      
      // ---------------------------------------------------------------------
      // go to the url
      // ---------------------------------------------------------------------      
      location.href  = url;   
   }
}

// ---------------------------------------------------------------------------
// Subject
//
//    Purpose: 'Class' to simulate subject object
// ---------------------------------------------------------------------------
function Subject()
{
   // ------------------------------------------------------------------------
   // subject 'object' has three properties
   // ------------------------------------------------------------------------
   this.id     = 0;
   this.name   = '';
   this.catId  = 0;
}

// ---------------------------------------------------------------------------
// Dependent
//
//    Purpose: 'Class' to simulate dependent object
// ---------------------------------------------------------------------------
function Dependent()
{
   // ------------------------------------------------------------------------
   // subject 'object' has three properties
   // ------------------------------------------------------------------------
   this.subId     = 0;
   this.display   = '';
   this.mainId    = 0;
}

//---------------------------------------------------------------------------
//Aircraft
//
// Purpose: 'Class' to simulate aircraft object
//---------------------------------------------------------------------------
function Aircraft()
{
   // ------------------------------------------------------------------------
   // subject 'object' has three properties
   // ------------------------------------------------------------------------
   this.type 	= 	0;
   this.model	=	0;
   this.series	=	0;
}
   
// ---------------------------------------------------------------------------
// HandleCorrectiveCategoryChange
//
//    Purpose: Fill subject list based on category selected
// ---------------------------------------------------------------------------
function HandleCorrectiveCategoryChange ( subjectName, categoryName, formIndex )
{
   // ------------------------------------------------------------------------
   // if desired level was not passed, default to version 4
   // ------------------------------------------------------------------------
   switch ( arguments.length ) {
      case 0:
         subjectName = 'SUBJECTID';
      case 1:
         categoryName = 'CATEGORYID';
      case 2:
         formIndex = 0;
   }
   
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[formIndex];
   
   // ------------------------------------------------------------------------
   // dont do anything initially if pageLoad is zero
   // ------------------------------------------------------------------------
   if ( form.npl == undefined || form.npl == 'undefined' ) {
      
   }
   else {
      if (form.npl.value == 1) {
         return;
      }
   }
   
   // ------------------------------------------------------------------------
   // get the object holding the 'subject' list
   // ------------------------------------------------------------------------
   var theSelectionList = GetObjectFromName(subjectName);

   var selectionValue = GetFirstSelectedValue(theSelectionList);
   
   // ------------------------------------------------------------------------
   // clear out all values in the 'subject' combobox (select)
   // ------------------------------------------------------------------------
   EmptySelectionList(theSelectionList);
   
   // ------------------------------------------------------------------------
   // get the category id from the newly selected value
   // ------------------------------------------------------------------------
   var categoryObj = GetObjectFromName(categoryName);
   var categoryId  = categoryObj.value;

   // ------------------------------------------------------------------------
   // fill the subject list based on that category id
   // ------------------------------------------------------------------------
   FillSubjectList( categoryId, subjectName );
   
   if (selectionValue != '') {
	   SelectByValue(subjectName,selectionValue);
   }
}

// ---------------------------------------------------------------------------
// ChangeMailText
//
//    Purpose: Display email text based on selection
// ---------------------------------------------------------------------------
function ChangeMailText(nameStr)
{
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];

   // ------------------------------------------------------------------------
   // build element from name passed (MUST do this for IE 4)
   // ------------------------------------------------------------------------
   var theElement    = GetObjectFromName(nameStr);
   var elementName   = theElement.name;
   var elementValue  = theElement.value;
      
   // ------------------------------------------------------------------------
   // if the email value is not null, then get the value from hidden field
   // ------------------------------------------------------------------------
   if ( elementValue != '' ) {
      var hiddenName = 'email' + elementValue;
      var hiddenElement = GetObjectFromName(hiddenName);
      var hiddenValue = hiddenElement.value;
      
      // ---------------------------------------------------------------------
      // replace all tildes with crlfs
      // ---------------------------------------------------------------------
      hiddenValue = Replace( hiddenValue, "~", "\n");
   }
   else {
      hiddenValue = '';
   }
   
   // ------------------------------------------------------------------------
   // go through each element in form and look for text area
   // ------------------------------------------------------------------------
   for (var i=0;i<form.elements.length;i++ ) {
      var theElement = form.elements[i];
      var type       = theElement.type;
      // ---------------------------------------------------------------------
      // if this is a text area, then fill in the value
      // ---------------------------------------------------------------------
      if ( (type == "textarea") ) {
         theElement.value = hiddenValue;
         break;
      }
   }
}

function DisplaySpecificInstructions ( formIndex )
{
   // ------------------------------------------------------------------------
   // if desired level was not passed, default to version 4
   // ------------------------------------------------------------------------
   if ( arguments.length != 1 ) {
      formIndex = 0;
   }
   
   // ------------------------------------------------------------------------
   // setup shortcuts for easier access to form elements
   // ------------------------------------------------------------------------
   var form   = document.forms[formIndex];   // actual form
   var radio  = form.queryType;      // name of radio buttons (hard coded)
   var length = radio.length;        // calculate number of radion buttons
   var inst   = form.instructions;   // handle to the instructions

   // ------------------------------------------------------------------------
   // determine which radio button is checked, and get its value
   // ------------------------------------------------------------------------
   for ( var i=0;i<length;i++) {
      if ( radio[i].checked ) {
         value = radio[i].value;
         break;
      }
   }   
   
   // ------------------------------------------------------------------------
   // assign a default value of 'Nothing Required' to the instruction text
   // ------------------------------------------------------------------------
   var instructionText  = 'No Search Value Required';

   // ------------------------------------------------------------------------
   // change text to reflect appropriate radion button selected
   // ------------------------------------------------------------------------
   switch (value) {
      case 'ssn':   // SSN radion button selected
         instructionText = 'Enter SSN of Candidate (Digits Only)';
         break;
      case 'name':  // name of applicant selected
         instructionText = 'Format: Last, First ( put only as many as known)';
         break;
      case 'empId': // employee id of recommendation submitter
         instructionText = 'Enter Employee Id to Find';
         break;
   }
   
   // ------------------------------------------------------------------------
   // update instructions on the screen
   // ------------------------------------------------------------------------
   inst.value = instructionText;
}

function HandleTimeSelect ( formIndex )
{
   // ------------------------------------------------------------------------
   // if desired level was not passed, default to version 4
   // ------------------------------------------------------------------------
   if ( arguments.length != 1 ) {
      formIndex = 0;
   }
   
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[formIndex];
   
   var time = 0;
   var textElement;
   
   var hour, minute, ampm;
   
   // ------------------------------------------------------------------------
   // go through each element in form and look for select item
   // ------------------------------------------------------------------------
   for (var i=0;i<form.elements.length;i++) {
      // ---------------------------------------------------------------------
      // get shortcut to this element and its attributes
      // ---------------------------------------------------------------------      
      var theElement = form.elements[i];
      var type       = theElement.type;
      var name       = theElement.name;
      var value      = theElement.value;
      
      // ---------------------------------------------------------------------
      // elements like fieldset and legend dont have names, so ignore them
      // ---------------------------------------------------------------------      
      if ( name == undefined || name == 'undefined' ) {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // if this is not a radio button, check for text input
      // ---------------------------------------------------------------------
      if (type.substr(0,5) != "radio" ) {
         // ------------------------------------------------------------------
         // if text, then save the element object
         // ------------------------------------------------------------------
         if (name == "time") {
            textElement = theElement;
         }
         continue;
      }
      
      // ---------------------------------------------------------------------
      // add total of all radio buttons checked
      // ---------------------------------------------------------------------
      if (!theElement.checked)      
         continue;

      // ---------------------------------------------------------------------
      // add total of all radio buttons checked
      // ---------------------------------------------------------------------      
      switch (name) {
         case 'hour':
            hour = parseInt(value,10);         
            break;
         case 'minute':
            minute   = parseInt(value,10);
            break;
         case 'ampm':
            ampm  = value;
            break;
      }
         
      // ---------------------------------------------------------------------
      // add 12 to hour if this is pm
      // ---------------------------------------------------------------------      
      if (ampm == 'P') {
         hour += 12;
      }      
   }
      
   // ------------------------------------------------------------------------
   // create a military time from hour and minute
   // ------------------------------------------------------------------------
   var time = hour * 100 + minute;
   
   // ------------------------------------------------------------------------
   // put the total in the textbox
   // ------------------------------------------------------------------------
   textElement.value = time;
   
}

var marked_row = new Array;

function SetRowColor ( theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor )
{
   // ------------------------------------------------------------------------
   // initialze to null
   // ------------------------------------------------------------------------
   var theCells = null;

   // ------------------------------------------------------------------------
   // if no colors or cant get style, then cant handle it
   // ------------------------------------------------------------------------
   if ( (thePointerColor == '' && theMarkColor == '') ||
         typeof(theRow.style) == 'undefined' ) {
      return false;
   }

   // ------------------------------------------------------------------------
   // Gets the current row and exits if the browser can't get it
   // ------------------------------------------------------------------------
   if (typeof(document.getElementsByTagName) != 'undefined') {
      theCells = theRow.getElementsByTagName('td');
   }
   else if (typeof(theRow.cells) != 'undefined') {
      theCells = theRow.cells;
   }
   else {
      return false;
   }

   // ------------------------------------------------------------------------
   // setup variables
   // ------------------------------------------------------------------------
   var rowCellsCnt  = theCells.length;
   var domDetect    = null;
   var currentColor = null;
   var newColor     = null;

   // ------------------------------------------------------------------------
   // with DOM except opera
   // ------------------------------------------------------------------------
   if ( typeof(window.opera) == 'undefined' && 
        typeof(theCells[0].getAttribute) != 'undefined') {
      currentColor = theCells[0].getAttribute('bgcolor');
      domDetect    = true;
   }
   else {
      currentColor = theCells[0].style.backgroundColor;
      domDetect    = false;
   } 

   // ------------------------------------------------------------------------
   // Opera changes colors set via HTML to rgb(r,g,b) format so fix it
   // ------------------------------------------------------------------------
   if (currentColor.indexOf("rgb") >= 0) {
      var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                  currentColor.indexOf(')'));
      var rgbValues = rgbStr.split(",");
      currentColor = "#";
      var hexChars = "0123456789ABCDEF";
      for (var i = 0; i < 3; i++) {
         var v = rgbValues[i].valueOf();
         currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
      }
   }

   // ------------------------------------------------------------------------
   // Current color is the default one
   // ------------------------------------------------------------------------
   if ( currentColor == '' || 
        currentColor.toLowerCase() == theDefaultColor.toLowerCase() ) {
      if (theAction == 'over' && thePointerColor != '') {
         newColor = thePointerColor;
      }
      else if (theAction == 'click' && theMarkColor != '') {
         newColor = theMarkColor;
         marked_row[theRowNum] = true;
      }
   }
   // ------------------------------------------------------------------------
   // Current color is the pointer one
   // ------------------------------------------------------------------------
   else if ( currentColor.toLowerCase() == thePointerColor.toLowerCase() && 
            (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum]) ) {
      if (theAction == 'out') {
         newColor = theDefaultColor;
      }
      else if (theAction == 'click' && theMarkColor != '') {
         newColor                = theMarkColor;
         marked_row[theRowNum]   = true;
      }
   }
   // ------------------------------------------------------------------------
   // Current color is the marker one
   // ------------------------------------------------------------------------
   else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
      if (theAction == 'click') {
         newColor = ( thePointerColor != '' ) ? 
                      thePointerColor : 
                      theDefaultColor;
         marked_row[theRowNum]   = ( typeof(marked_row[theRowNum]) == 'undefined' || 
                                     !marked_row[theRowNum] ) ? 
                                     true : 
                                     null;
      }
   }

   // ------------------------------------------------------------------------
   // 5. Sets the new color...
   // ------------------------------------------------------------------------
   if (newColor) {
      var c = null;
      // 5.1 ... with DOM compatible browsers except Opera
      if (domDetect) {
         for (c = 0; c < rowCellsCnt; c++) {
            theCells[c].setAttribute('bgcolor', newColor, 0);
         } 
      }
      // 5.2 ... with other browsers
      else {
         for (c = 0; c < rowCellsCnt; c++) {
            theCells[c].style.backgroundColor = newColor;
         }
      }
   }

   return true;
}

// ---------------------------------------------------------------------------
// GetFirstSelectedValue
//
//    Purpose: Get first <select> selected item value
// Parameters: theSelectionList - handle to the list to be searched
//    Returns: value selected
// ---------------------------------------------------------------------------
function GetFirstSelectedValue ( theSelectionList )
{
   // ------------------------------------------------------------------------
   // go through the entire list
   // ------------------------------------------------------------------------
   for (var i=0; i<theSelectionList.length; i++) {
      // ---------------------------------------------------------------------
      // if this item is selected
      // ---------------------------------------------------------------------      
      if ( theSelectionList.options[i].selected ) {
         return theSelectionList.options[i].value;
      }
   }
   
   // ------------------------------------------------------------------------
   // nothing selected ...
   // ------------------------------------------------------------------------
   return '';
}

// ---------------------------------------------------------------------------
// FindLastDayOfMonth
//
//      Purpose: Find last day of month of a given date
// ---------------------------------------------------------------------------
function FindLastDayOfMonth ( date )
{
   // ------------------------------------------------------------------------
   // cut down calculation time by starting near end of month
   // ------------------------------------------------------------------------
   date.setDate(28);
   
   // ------------------------------------------------------------------------
   // get current information from date passed
   // ------------------------------------------------------------------------
   var month         = date.getMonth();
   var milliseconds  = date.getTime();   
   
   // ------------------------------------------------------------------------
   // keep adding a day to the date until the month changes
   // ------------------------------------------------------------------------
   while ( date.getMonth() == month ) {
      milliseconds += dayIncrement;
      date = new Date(milliseconds);
   }
   
   // ------------------------------------------------------------------------
   // go back one, as above will increment past
   // ------------------------------------------------------------------------
   milliseconds -= dayIncrement;
   
   // ------------------------------------------------------------------------
   // create a new date from the milliseconds and return it
   // ------------------------------------------------------------------------
   lastDay = new Date(milliseconds);
  
   return lastDay;
}

// ---------------------------------------------------------------------------
// GetThisWeek
//
//      Purpose: Format date for output to date form element
// ---------------------------------------------------------------------------
function GetThisWeek ( date, range )
{
   // ------------------------------------------------------------------------
   // get day of week and milliseconds for date passed
   // ------------------------------------------------------------------------
   var dayofweek = date.getDay();
   var milliseconds = date.getTime();
   
   // ------------------------------------------------------------------------
   // go back until day of week is 1 (Monday)
   // ------------------------------------------------------------------------
   while ( dayofweek > 1 ) {
      milliseconds -= dayIncrement;
      dayofweek--;
   }
   
   // ------------------------------------------------------------------------
   // create start date of this week and save in array
   // ------------------------------------------------------------------------
   var start = new Date(milliseconds);
   range[0] = start;
      
   // ------------------------------------------------------------------------
   // start again
   // ------------------------------------------------------------------------
   dayofweek = date.getDay();
   milliseconds = date.getTime();
   
   // ------------------------------------------------------------------------
   // go forward until day is Friday
   // ------------------------------------------------------------------------
   while ( dayofweek < 5 ) {
      milliseconds += dayIncrement;
      dayofweek++;
   }

   // ------------------------------------------------------------------------
   // create end date and save in array
   // ------------------------------------------------------------------------
   var end = new Date(milliseconds);
   range[1] = end;   
}

// ---------------------------------------------------------------------------
// GetThisMonth
//
//      Purpose: get date ranges for this month
// ---------------------------------------------------------------------------
function GetThisMonth(date,range)
{
   // ------------------------------------------------------------------------
   // set today to the date passed
   // ------------------------------------------------------------------------
   var today = date;
   
   // ------------------------------------------------------------------------
   // set the day to first day of month, create day and set start range
   // ------------------------------------------------------------------------
   today.setDate(1);
   var start = new Date(today);
   range[0] = start;   

   // ------------------------------------------------------------------------
   // use function to get last day of month
   // ------------------------------------------------------------------------
   range[1] = FindLastDayOfMonth(today);
}

// 770-265-0893   
// ---------------------------------------------------------------------------
// GetNextMonth
//
//      Purpose: Get starting and ending dates of next month
// ---------------------------------------------------------------------------
function GetNextMonth (today,range)
{
   // ------------------------------------------------------------------------
   // get last day of current month
   // ------------------------------------------------------------------------
   var lastDay = FindLastDayOfMonth(today);
   
   var next = new Date(lastDay.getTime() + dayIncrement);
   range[0] = next;

   var change = new Date(next);   
   var newLastDay = FindLastDayOfMonth(change);   
   range[1] = newLastDay;   
}

// ---------------------------------------------------------------------------
// GetLastMonth
//
//      Purpose: Get last month date range
// ---------------------------------------------------------------------------
function GetLastMonth (today,range)
{
   // ------------------------------------------------------------------------
   // set 'today' equal to date passed using 1st day of month
   // ------------------------------------------------------------------------
   today.setDate(1);
   
   // ------------------------------------------------------------------------
   // go back one day from first and save as last day in range
   // ------------------------------------------------------------------------
   var milliseconds = today.getTime() - dayIncrement;
   lastDay  = new Date(milliseconds);
   range[1] = lastDay;
   
   // ------------------------------------------------------------------------
   // set first day of month and save as start day in range
   // ------------------------------------------------------------------------
   var firstDay = new Date(lastDay);
   firstDay.setDate(1);
   range[0] = firstDay;
}

// ---------------------------------------------------------------------------
// FormatDate
//
//      Purpose: Format date for output to date form element
// ---------------------------------------------------------------------------
function FormatDate (date)
{
   // ------------------------------------------------------------------------
   // get day/month/year
   // ------------------------------------------------------------------------
   var day     = date.getDate();
   var month   = date.getMonth() + 1;
   var year    = date.getFullYear();

   // ------------------------------------------------------------------------
   // build format, e.g. 2/24/2001
   // ------------------------------------------------------------------------
   var formatted = month + '/' + day + '/' + year;
   
   // ------------------------------------------------------------------------
   // return the formatted date
   // ------------------------------------------------------------------------
   return formatted;
}   

// ---------------------------------------------------------------------------
// IncrementDate
//
//      Purpose: Increment/decrement date by number of days (plus/minus)
// ---------------------------------------------------------------------------
function IncrementDate (date,increment)
{
   // ------------------------------------------------------------------------
   // calculate number of milliseconds to add/subtract (dayIncrement is global)
   // ------------------------------------------------------------------------
   var inc = dayIncrement * increment;
   
   // ------------------------------------------------------------------------
   // add it to the date passed
   // ------------------------------------------------------------------------
   var milliseconds = date.getTime() + inc;
   
   // ------------------------------------------------------------------------
   // create a new date based on milliseconds
   // ------------------------------------------------------------------------
   var newDay = new Date(milliseconds);
   
   // ------------------------------------------------------------------------
   // return the new date
   // ------------------------------------------------------------------------
   return newDay;
}      
   
   
function UpdateSummaryColor ( elementName, id )
{
   var form = document.forms[0];
   
   var total = 0;
   
   var parts = elementName.split(DATA_SEPARATOR);
   var namePart   =  parts[0];
   var length     =  namePart.length;
   
   // ------------------------------------------------------------------------
   // go through each form element looking for one passed
   // ------------------------------------------------------------------------
   for (var i=0;i<form.elements.length;i++) {
      var theElement = form.elements[i];
      var type       = theElement.type;
      var name       = theElement.name;
      
      // ---------------------------------------------------------------------
      // fieldsets and legends don't have name properties
      // ---------------------------------------------------------------------
      if ( name == undefined || name == 'undefined' ) {
         continue;
      }      
      
      // ---------------------------------------------------------------------
      // radio / hidden dont need/want focus
      // ---------------------------------------------------------------------
      if ( type != 'text' ) 
         continue;
      // ---------------------------------------------------------------------
      // if not field, then skip it
      // ---------------------------------------------------------------------
      if (name.substr(0,length) != namePart ) {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // get total
      // ---------------------------------------------------------------------
      var theValue = parseInt(theElement.value,10);
      if (!isNaN(theValue)) {
         total += theValue;
      }
   }
   
   var obj = document.getElementById(id);
   
   if ( total > 0) {
      ChangeCol( obj, 'white', 'blue');
   }
   else {
      ChangeCol( obj, 'white', 'gray');
   }
   
   
   
}
// ---------------------------------------------------------------------------
// IncrementElement
//
//      Purpose: Increment an element value by defined increment
// ---------------------------------------------------------------------------
function IncrementElement ( elementName, increment, limit )
{
   // ------------------------------------------------------------------------
   // default the increment to 1
   // ------------------------------------------------------------------------
   switch (arguments.length) {
      case 1:
         increment = 1;
      case 2:
         limit = 99;
   }   
   
   // ------------------------------------------------------------------------
   // get the element object from the name passed
   // ------------------------------------------------------------------------
   var theElement = GetObjectFromName(elementName);
   
   // ------------------------------------------------------------------------
   // get the element value and convert it to a number
   // ------------------------------------------------------------------------
   var value      = theElement.value;
   var theValue   = parseInt(theElement.value,10);
   
   // ------------------------------------------------------------------------
   // if not a number ( must be blank ), convert it to number
   // ------------------------------------------------------------------------
   if ( isNaN(theValue)) {
      theValue = 0;
   }
   // ------------------------------------------------------------------------
   // add incremental value and update the element with new value
   // ------------------------------------------------------------------------
   theValue += increment;
   
   // ------------------------------------------------------------------------
   // limit the number appropriately
   // ------------------------------------------------------------------------
   if ( theValue > limit ) {
      return;
   }
   theElement.value = theValue;
   
   var summaryName    = 'sum_' + elementName;
   var summaryElement = GetObjectFromName(summaryName);
   if ( summaryElement == null) {
      return;
   }
   
   var parts = elementName.split(DATA_SEPARATOR);
   var first = parts[0];
   var parts = first.split('_');
   var id    = parts[1];

   UpdateSummaryColor ( elementName, id );
   
   summaryElement.value = theValue;
}

// ---------------------------------------------------------------------------
// DecrementElement
//
//      Purpose: Decrement an element value by defined increment
// ---------------------------------------------------------------------------
function DecrementElement ( elementName, increment, limit )
{
   // ------------------------------------------------------------------------
   // default the increment to 1
   // ------------------------------------------------------------------------
   switch (arguments.length) {
      case 1:
         increment = 1;
      case 2:
         limit = 0;
   }
   
   // ------------------------------------------------------------------------
   // get the element object from the name passed
   // ------------------------------------------------------------------------
   var theElement = GetObjectFromName(elementName);

   // ------------------------------------------------------------------------
   // get the element value and convert it to a number
   // ------------------------------------------------------------------------
   var theValue   = parseInt(theElement.value,10);
   
   // ------------------------------------------------------------------------
   // if not a number ( must be blank ), convert it to number
   // ------------------------------------------------------------------------
   if ( isNaN(theValue)) {
      theValue = 1;
   }
   
   theValue -= increment;
   
   // ------------------------------------------------------------------------
   // don't allow negative values unless specifically designated
   // ------------------------------------------------------------------------
   if ( theValue < limit ) {
      return;
   }
   // ------------------------------------------------------------------------
   // add incremental value and update the element with new value
   // ------------------------------------------------------------------------
   theElement.value = theValue;
      
   var summaryName    = 'sum_' + elementName;
   var summaryElement = GetObjectFromName(summaryName);
   if (summaryElement == null) {
      return;
   }
   
   var parts = elementName.split(DATA_SEPARATOR);
   var first = parts[0];
   var parts = first.split('_');
   var id    = parts[1];

   UpdateSummaryColor ( elementName, id );
   
   summaryElement.value = theValue;
}

// ---------------------------------------------------------------------------
// HandleShortDateChange
//
//      Purpose: update dates based on date ranges enter
// ---------------------------------------------------------------------------
function HandleShortDateChange ( theSelectElement )
{
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];
   
   // ------------------------------------------------------------------------
   // get the value of the selected element
   // ------------------------------------------------------------------------
   var value = GetFirstSelectedValue(theSelectElement);
         
   // ------------------------------------------------------------------------
   // declare these OUTSIDE of the for loop - start and end date elements
   // ------------------------------------------------------------------------
   var startElement;
   var endElement;
   
   // ------------------------------------------------------------------------
   // get elements for start and end dates
   // ------------------------------------------------------------------------
   for (i=0;i<form.elements.length;i++) {
      var theElement = form.elements[i];      
      var name       = theElement.name;
      
      // ---------------------------------------------------------------------
      // fieldsets and legends don't have name properties
      // ---------------------------------------------------------------------
      if ( theElement.name == undefined || theElement.name == 'undefined' ) {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // if start was found, save it
      // ---------------------------------------------------------------------
      if ( name.substring(0,9) == 'STARTDATE' ) {
         startElement = theElement;
      }
      // ---------------------------------------------------------------------
      // if end was found, save it
      // ---------------------------------------------------------------------
      if ( name.substring(0,7) == 'ENDDATE' )
         endElement = theElement;
   }
         
   // ------------------------------------------------------------------------
   // get today's date
   // ------------------------------------------------------------------------
   var today = new Date();
   var dt;
   
   var range = new Array(2);

   var start = new Date();
   var end   = new Date();
      
   // ------------------------------------------------------------------------
   // determine the value of the date selection
   // ------------------------------------------------------------------------
   switch ( value ) {
      case 'thisquarter':
            var thisMonth = today.getMonth() + 1;
            var thisQuarter = (Math.floor((thisMonth - 1) / 3) + 1);
            switch(thisQuarter) {
               case 1:
                  start.setDate(1);
                  start.setMonth(0);
                  end.setMonth(2);
                  end.setDate(31);
                  break;
               case 2:
                  start.setDate(1);
                  start.setMonth(3);
                  end.setMonth(5);
                  end.setDate(30);
                  break;
               case 3:
                  start.setDate(1);
                  start.setMonth(6);
                  end.setMonth(8);
                  end.setDate(30);
                  break;
               case 4:
                  start.setDate(1);
                  start.setMonth(9);
                  end.setMonth(11);
                  end.setDate(31);
                  break;
            }
            range[0] = start;
            range[1] = end;
         break;
      case 'lastquarter':
            var thisMonth = today.getMonth() + 1;
            var thisQuarter = (Math.floor((thisMonth - 1) / 3) + 1);
            var lastQuarter = thisQuarter - 1;
            var year = start.getFullYear();
            if (lastQuarter == 0) {
               lastQuarter = 4;
               year--;
            }
            start.setYear(year);
            end.setYear(year);
            switch(lastQuarter) {
               case 1:
                  start.setDate(1);
                  start.setMonth(0);
                  end.setMonth(2);
                  end.setDate(31);
                  break;
               case 2:
                  start.setDate(1);
                  start.setMonth(3);
                  end.setMonth(5);
                  end.setDate(30);
                  break;
               case 3:
                  start.setDate(1);
                  start.setMonth(6);
                  end.setMonth(8);
                  end.setDate(30);
                  break;
               case 4:
                  start.setDate(1);
                  start.setMonth(9);
                  end.setMonth(11);
                  end.setDate(31);
                  break;
            }
            range[0] = start;
            range[1] = end;
         break;
      case 'ytd':
         var ytd = new Date();
         ytd.setDate(1);
         ytd.setMonth(0);
         var last = new Date();
         last.setMonth(11);
         
         range[0] = ytd; // today;
         range[1] = today;
         break;
      case 'last12':
         var year = today.getFullYear() - 1;
         var month = today.getMonth();
         var last12 = new Date();
         last12.setDate(1);
         last12.setYear(year);
         last12.setMonth(month);

         today.setDate(1);
         today = IncrementDate(today,-1);
         
         range[0] = last12; // today;
         range[1] = today;
         break;
      case 'last3':
         var year = today.getFullYear();
         var month = today.getMonth();
         month -= 3;
         if (month < 0) {
            month += 11;
            year--;
         }
         var last3 = new Date();
         last3.setDate(1);
         last3.setYear(year);
         last3.setMonth(month);
         
         range[0] = last3; // today;
         range[1] = today;
         break;
      case 'today':
         range[0] = today;
         range[1] = today;
         break;
      case 'tomorrow':
         var tomorrow = IncrementDate(today,1);
         range[0] = tomorrow;
         range[1] = tomorrow;
         break;
      case 'yesterday':
         var yesterday = IncrementDate(today,-1);
         range[0] = yesterday;
         range[1] = yesterday;
         break;
      case 'thisweek':
         GetThisWeek(today,range);
         break;
      case 'nextweek':
         var next = today.getTime() + (dayIncrement * 7);
         var nextDt = new Date(next);
         GetThisWeek(nextDt,range);
         break;
      case 'lastweek':
         var last = today.getTime() - (dayIncrement * 7);
         var lastDt = new Date(last);
         GetThisWeek(lastDt,range);
         break;
      case 'thismonth':
         GetThisMonth(today,range);
         break;
      case 'lastmonth':
         GetLastMonth(today,range);
         break;
      case 'nextmonth':
         GetNextMonth(today,range);
         break;
      case 'all':
    	  var all = new Date(2009,0,1);
          range[0] = all;
          range[1] = today;
    	  break;
   }
      
   startElement.value   = FormatDate(range[0]);
   endElement.value     = FormatDate(range[1]);
}   

// ---------------------------------------------------------------------------
// HandleEmail
//
//      Purpose: Update email address from first and last name
// ---------------------------------------------------------------------------
function HandleEmail ( domain )
{
   // ------------------------------------------------------------------------
   // default to cargo 360
   // ------------------------------------------------------------------------
   if ( arguments.length != 1 ) {
      domain = '@cargo360.aero';
   }
   
   // ------------------------------------------------------------------------
   // get shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];
   
   // ------------------------------------------------------------------------
   // get objects from name ( removes validation problem )
   // ------------------------------------------------------------------------
   var firstObj   = GetObjectFromName('firstName');
   var lastObj    = GetObjectFromName('lastName');
   
   // ------------------------------------------------------------------------
   // get first and last name and convert to lowercase
   // ------------------------------------------------------------------------
   var first   = firstObj.value.toLowerCase();
   var last    = lastObj.value.toLowerCase();
   
   // ------------------------------------------------------------------------
   // add all parts to form email address ( bob.smith@cargo360.aero )
   // ------------------------------------------------------------------------
   email = first + '.' + last + domain;
   
   // ------------------------------------------------------------------------
   // get object from name for email
   // ------------------------------------------------------------------------
   var emailObj = GetObjectFromName('email');
   
   // ------------------------------------------------------------------------
   // update the object with the newly created value for the email address
   // ------------------------------------------------------------------------
   emailObj.value = email;
}

function HandleCheckCombo ( prefix, name, number, suffix )
{
   if ( arguments.length == 3) {
      suffix = '_cb';
   }
   
   var check   = prefix + '_ck' + DATA_SEPARATOR + name;
   var hidden   = prefix + suffix + DATA_SEPARATOR + name;
   
   var checkObj = GetObjectFromName( check );
   var hiddenObj = GetObjectFromName( hidden );
   var spacing  = prefix + 'spacing' + DATA_SEPARATOR + number;
   var staticObj = document.getElementById(spacing);
   if (checkObj.checked == true) {
      hiddenObj.style.display = 'inline';
      staticObj.style.display = 'inline';      
   }
   else{
      //hiddenObj.selectedIndex = -1;
      hiddenObj.style.display = 'none';
      staticObj.style.display = 'none';
   }
}

function HandleJti( checkbox, separator )
{
   switch (arguments.length) {
      case 1:
         separator = 'jti_';
         break;
   }
   var name = checkbox.name;
   var parts = name.split('_');
   
   var divName = separator + parts[1];
   
   var divObj = document.getElementById(divName);   
   
   var evalStr = 'form.' + divName + '.style.display = ';
   
   if ( checkbox.checked == true) {
      divObj.style.display =  'inline';   
   }
   else {
      divObj.style.display =  'none';   
   }
}

function ShowHideCheckbox( checkbox, objName )
{
   var name = checkbox.name;
   var parts = name.split('_');
   var divName;
   
   if ( parts.length > 1) {
      divName = objName + '_' + parts[1];
   }
   else {
      divName = name;
   }

   
   var divObj = document.getElementById(divName);   
   
   if ( checkbox.checked == true) {
      divObj.style.display =  'inline';   
   }
   else {
      divObj.style.display =  'none';   
   }
}

function ClickTab ( tabName )
{
	var theElement = GetObjectFromName(tabName);
	
	if (theElement.checked == false) {
		theElement.click();
	}
}

function HandleFieldTypes( combobox, tabname )
{
   var id = combobox.options[combobox.selectedIndex].value;

   var form = document.forms[0];

   var tags = document.getElementsByTagName('tr');
   
   for (var i=0;i<tags.length;i++) {
      var theElement = tags[i];
      
      var attribute = theElement.getAttribute('id');
      
      if (attribute.substr(0,5) != 'type_') {
         continue;
      }
      
      var name = 'type_' + id + '_' + tabname;
      
      if (attribute == name) {
         theElement.style.display = 'inline';
      }
      else {
         theElement.style.display = 'none';
      }
   }
}

function ShowHideRows ( checkbox, rowName ) 
{
   var name = rowName;
   var divName;
   var idName = name + '0';
   var count = 0;
   var max = 400;
   
   while ( (divObj = document.getElementById(idName)) != undefined ) {
      if ( checkbox.checked == true) {
         divObj.style.display =  'inline';   
      }
      else {
         divObj.style.display =  'none';   
      }
      count++;
      idName = name + count;
      max--;

      if ( max < 1) {
         alert('Oops: Max Reached');
         break;
      }
   }
}
function HandleSurveyComment( checkbox, initials )
{
   if ( arguments.length < 2 ) {
      initials = 'sur';
   }
   var name    = checkbox.name;
   var parts = name.split('_');
   
   var divName = initials + '_' + parts[1] + '_' + parts[2];
   var divObj = document.getElementById(divName);   
   
   var evalStr = 'form.' + divName + '.style.display = ';
   
   if ( checkbox.checked == true) {
      divObj.style.display =  'inline';   
   }
   else {
      divObj.style.display =  'none';   
   }
}

function SetBackgroundColor ( element, bgcolor, textColor )
{
   if (arguments.length == 2) {
      textColor = '#000000';
   }
   element.style.backgroundColor = bgcolor;
   element.style.color = textColor;
}

function HandleFieldTypeChange( theElement )
{
   var value = theElement.value;
   var typeArray = new Array( 'textbox', 'textarea', 'combobox', 'comboboxdb', 'yesno', 'radiobutton', 'checkbox');
   
   for (var i=0;i<typeArray.length;i++) {
      var typeName   = typeArray[i];
      var fullName   = 'att_' + typeName;
      
      var object;

      if (object = document.getElementById(fullName) ) {
         if ( typeName == value ) {
            object.style.display = 'inline';
         }
         else {
            object.style.display = 'none';
         }
      }
   }
}

// ---------------------------------------------------------------------------
// ToggleButton
//
//      Purpose: Large radio button simulation
// ---------------------------------------------------------------------------
function ToggleButton ( elementObj, idRegex, tagName, doToggle, mainPrefix ) 
{
   // ------------------------------------------------------------------------
   // default arguments
   // ------------------------------------------------------------------------
   switch (arguments.length) {
      case 2:
         tagName = 'SPAN';
      case 3:
         doToggle = 1;
      case 4:
         mainPrefix = 'across';
   }
      
   // ------------------------------------------------------------------------
   // get all tag elements in body with appropriate tag name
   // ------------------------------------------------------------------------
   var arrayTags = document.body.getElementsByTagName(tagName);
   
   // ------------------------------------------------------------------------
   // go through all appropriate tags
   // ------------------------------------------------------------------------
   for(var i = 0; i < arrayTags.length; i++)
   {
      // ---------------------------------------------------------------------
      // if regex match, then handle it ( regex are NOT strings )
      // ---------------------------------------------------------------------
      if(arrayTags[i].id.match(idRegex))
      {
         // ------------------------------------------------------------------
         // look at id of tag (e.g. cf_1010_ or cf_1010_1210
         // ------------------------------------------------------------------
         var length = arrayTags[i].id.length;
         var last   = arrayTags[i].id.charAt(length-1);
         
         // ------------------------------------------------------------------
         // if last char in id is '_', then must be title, otherwise, value
         // ------------------------------------------------------------------
         if ( last != '_') {    
           arrayTags[i].className = 'raised';
         }
         else {
           arrayTags[i].className = 'descriptionBold'; 
         }
      }
   }

   // ------------------------------------------------------------------------
   // set variables for updating data
   // ------------------------------------------------------------------------
   var id         = elementObj.id;
   var parts      = id.split('_');
   var theName    = parts[0] + '_' + parts[1] + '_' + parts[2];
   var theValue   = parts[3];
   
   // ------------------------------------------------------------------------
   // clicked on a value, so handle the look and feel and set value
   // ------------------------------------------------------------------------
   if ( doToggle) {
     elementObj.className = 'depressed';
     var theValueObject = GetObjectFromName(theName);
     theValueObject.value = theValue;
   }
   else {
      elementObj.className = 'description';
      var theValueObj   = GetObjectFromName(theName);
      theValueObj.value = -1;
   }
}


function ToggleButton2 ( elementObj, idRegex, tagName, button, selected )
{
   // ------------------------------------------------------------------------
   // default arguments
   // ------------------------------------------------------------------------
   switch (arguments.length) {
      case 2:
         tagName = 'DIV';
      case 3:
    	 button = 'bz-button';
      case 4:
    	 selected = 'bz-selected';
   }

   // ------------------------------------------------------------------------
   // get all tag elements in body with appropriate tag name
   // ------------------------------------------------------------------------
   var arrayTags = document.body.getElementsByTagName(tagName);
   var theId     = '';

   // ------------------------------------------------------------------------
   // go through all appropriate tags
   // ------------------------------------------------------------------------
   for(var i = 0; i < arrayTags.length; i++)
   {
      // ---------------------------------------------------------------------
      // if regex match, then handle it ( regex are NOT strings )
      // ---------------------------------------------------------------------
      if(arrayTags[i].id.match(idRegex))
      {
         arrayTags[i].className = button;
         theId = arrayTags[i].id;
      }
   }

   // ------------------------------------------------------------------------
   // set variables for updating data
   // ------------------------------------------------------------------------
   var theId      = elementObj.id;
   var parts      = theId.split('_');
   var valueId    = 'h_' + parts[0] + '_' + parts[1] + '_' + parts[2];
   var theValue   = parts[3];

   // ------------------------------------------------------------------------
   // clicked on a value, so handle the look and feel and set value
   // ------------------------------------------------------------------------
   elementObj.className = selected;
   var obj = document.getElementById(valueId);
   obj.value = theValue;
}

// ---------------------------------------------------------------------------
// ResetButtons
//
//      Purpose: Large radio button simulation
// ---------------------------------------------------------------------------
function ResetButtons ( idRegex, tagName, className )
{
   // ------------------------------------------------------------------------
   // default arguments
   // ------------------------------------------------------------------------
   switch (arguments.length) {
      case 1:
         tagName = 'DIV';
      case 2:
         className = 'bz-button';
   }

   // ------------------------------------------------------------------------
   // get all tag elements in body with appropriate tag name
   // ------------------------------------------------------------------------
   var arrayTags = document.body.getElementsByTagName(tagName);
   var theId     = '';

   // ------------------------------------------------------------------------
   // go through all appropriate tags
   // ------------------------------------------------------------------------
   for(var i = 0; i < arrayTags.length; i++)
   {
      // ---------------------------------------------------------------------
      // if regex match, then handle it ( regex are NOT strings )
      // ---------------------------------------------------------------------
      if(arrayTags[i].id.match(idRegex))
      {
         arrayTags[i].className = className;
         theId = arrayTags[i].id;
      }
   }

   // ------------------------------------------------------------------------
   // set variables for updating data
   // ------------------------------------------------------------------------
   var parts      = theId.split('_');
   var valueId    = 'h_' + parts[0] + '_' + parts[1] + '_' + parts[2];

   // ------------------------------------------------------------------------
   // clicked on a value, so handle the look and feel and set value
   // ------------------------------------------------------------------------
   var theValueObj   = document.getElementById(valueId);
   theValueObj.value = -1;
}

// ---------------------------------------------------------------------------
// GetRadioValue
//
//      Purpose: The purpose of this function is to get the value of a checked
//               radio button.
// ---------------------------------------------------------------------------
function GetRadioValue ( elementName )
{
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];

   // ------------------------------------------------------------------------
   // build an element name (for the radio passed) and get the length
   // ------------------------------------------------------------------------
   var eName   = "form." + elementName
   var length  = eval(eName + ".length");
   
   // ------------------------------------------------------------------------
   // initialize value to null
   // ------------------------------------------------------------------------
   var value = '';
   
   // ------------------------------------------------------------------------
   // go through each radio button and click the appropriate one
   // ------------------------------------------------------------------------
   for ( var i=0; i<length; i++ ) {
      // ---------------------------------------------------------------------
      // build radio element name, e.g. form.radio[i] and get its value
      // ---------------------------------------------------------------------
      var element = eval(eName + "[" + i + "]");
      if (element.checked) {
         value = element.value;
         break;
      }
   }
   return value;
}

function ChangeCol(element, color, bgcolor) 
{
   element.style.backgroundImage = "url('')";
   element.style.backgroundColor = bgcolor;
   element.style.color = color;
}

function RestoreImg( element, image)
{
   $cmd  = "element.style.backgroundImage='url(" + image + ")'";
   eval($cmd);
}

// ---------------------------------------------------------------------------
// ShowHideId
//
//      Purpose: Hide/Show element, block, etc.
// ---------------------------------------------------------------------------
function ShowHideId ( checkbox, elementId )
{  
   // ------------------------------------------------------------------------
   // form object to hide/show
   // ------------------------------------------------------------------------
   var formObject;
   
   // ------------------------------------------------------------------------
   // get the object by its id
   // ------------------------------------------------------------------------
   formObject  = document.getElementById(elementId);   
      
   // ------------------------------------------------------------------------
   // based on the value, hide/show element/block
   // ------------------------------------------------------------------------
   if (checkbox.checked==true) {
      formObject.style.display   = 'inline';
   }
   else {
      formObject.style.display   = 'none';
   }
}

// ---------------------------------------------------------------------------
// HideAllTabs
//
//      Purpose: Hide all 'Tab' elements
// ---------------------------------------------------------------------------
function HideAllTabs ( tagName, prefix )
{  
   // ------------------------------------------------------------------------
   // allow default parameters
   // ------------------------------------------------------------------------
   switch ( arguments.length ) {
      case 0:
         tagName = 'DIV';
      case 1:
         prefix  = 'tab_';
   }

   var prefixLength = prefix.length;
   
   // ------------------------------------------------------------------------
   // get appropriate tags
   // ------------------------------------------------------------------------
   var tags = document.body.getElementsByTagName(tagName);
   
   // ------------------------------------------------------------------------
   // go through all tags and look for appropriate ones
   // ------------------------------------------------------------------------
   for ( var i=0;i < tags.length; i++) {
      var theTag  =  tags[i];      
      var id      =  theTag.id;
      
      if (id.substring(0,prefixLength) == prefix) {
         theTag.style.display = 'none';
      }
   }
}

// ---------------------------------------------------------------------------
// UncheckAllTabsExcept
//
//      Purpose: Hide all 'Tab' elements
// ---------------------------------------------------------------------------
function UncheckAllTabsExcept ( checkbox, prefix )
{  
   // ------------------------------------------------------------------------
   // form
   // ------------------------------------------------------------------------
   var form = document.forms[0];
   var name	= 'chk_' + prefix;
   var length = name.length;
   
   for (var i=0; i < form.elements.length; i++) {
      var theElement = form.elements[i];
      // ---------------------------------------------------------------------
      // fieldsets and legends don't have name properties
      // ---------------------------------------------------------------------
      if ( theElement.name == undefined || theElement.name == 'undefined' ) {
         continue;
      }

      if (theElement.type != 'checkbox') {
         continue;
      }
            
      if ( theElement.name.substring(0,length) == name) {
         if ( checkbox.name != theElement.name) {
            theElement.checked = false;
         }
      }
   }
   
   checkbox.checked = true;
}

// ---------------------------------------------------------------------------
// ShowHideTabs
//
//      Purpose: Hide/Show element, block, etc.
// ---------------------------------------------------------------------------
function ShowHideTabs ( checkbox, elementId, tagName, prefix, onlyOne )
{  
   switch (arguments.length) {
      case 2:
         tagName = 'DIV';
      case 3:
         prefix = 'tab_';
      case 4:
         onlyOne = 1;
   }
   
   // ------------------------------------------------------------------------
   // if only one tab at once desired, then only show one
   // ------------------------------------------------------------------------
   if (onlyOne) {
      HideAllTabs(tagName, prefix);
      UncheckAllTabsExcept(checkbox,prefix);
   }
   
   // ------------------------------------------------------------------------
   // form object to hide/show
   // ------------------------------------------------------------------------
   var formObject;
   
   // ------------------------------------------------------------------------
   // get the object by its id
   // ------------------------------------------------------------------------
   formObject  = document.getElementById(elementId);   
   var form = document.forms[0];
   
   
   // ------------------------------------------------------------------------
   // based on the value, hide/show element/block
   // ------------------------------------------------------------------------
   if (checkbox.checked==true) {
      formObject.style.display   = 'inline';
      var name = checkbox.name;
      // chk_ is four(4) characters
      var length = 4 + prefix.length;
      name = name.substring(length);
      
      var lastTab = prefix + 'lastTab';
      
      var cmd = 'form.' + lastTab + ".value='" + name + "'";
      eval(cmd);
      //form.lastTab.value = name;
   }
   else {
      formObject.style.display   = 'none';
   }
}

// ---------------------------------------------------------------------------
// BrzClip
//
//      Purpose: Scrolling window functions
// ---------------------------------------------------------------------------
function BrzClip ( contWidth, contHeight, speed ) 
{
   // ------------------------------------------------------------------------
   // if title was passed, use it otherwise, use default title
   // ------------------------------------------------------------------------
   switch ( arguments.length ) {
      case 0:
         contWidth   = 150;  // width of the banner container
      case 1:
         contHeight  = 300; // height of the banner container
      case 2:
         speed       = 50;
   }

   // ------------------------------------------------------------------------
   // get the 'div' ids of slide a and b
   // ------------------------------------------------------------------------
   var id1 = document.getElementById('slideA');
   var id2 = document.getElementById('slideB');
   
   var height = id1.offsetHeight;

   id1.style.top = parseInt(id1.style.top)-1 + 'px';

   document.getElementById('slideCont').style.height = contHeight + "px";
   document.getElementById('slideCont').style.clip = 'rect(auto,'+ contWidth +'px,' + contHeight +'px,auto)';
   
   id2.style.display = '';
   
   if(parseFloat(id1.style.top) == -(height/2)) {
      id1.style.top = '0px';
   }
   
   var clipFunction = "BrzClip(" + contWidth + "," + contHeight + "," + speed + ")";
   setTimeout(clipFunction,speed)
}

// ---------------------------------------------------------------------------
// BrzAddLoadEvent
//
//      Purpose: Scrolling window functions
// ---------------------------------------------------------------------------
function BrzAddLoadEvent ( func ) 
{
  var oldonload = window.onload;
  
  if (typeof window.onload != 'function') {
    window.onload = func;
  } 
  else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// ---------------------------------------------------------------------------
// HandleFilterSelection
//
//      Purpose: select all/no checkboxes
// ---------------------------------------------------------------------------
function HandleFilterSelection ( radioElement, filter ) 
{
   // ------------------------------------------------------------------------
   // setup prefix string for search - default to fil
   // ------------------------------------------------------------------------
   if (arguments.length == 1) {
      filter = 'fil';
   }
   
   // ------------------------------------------------------------------------
   // get the value of the radio button
   // ------------------------------------------------------------------------
   var theValue = radioElement.value;
   
   var form = document.forms[0];
   for (var i=0; i < form.elements.length; i++) {
      var theElement = form.elements[i];
      // ---------------------------------------------------------------------
      // fieldsets and legends don't have name properties
      // ---------------------------------------------------------------------
      if ( theElement.name == undefined || theElement.name == 'undefined' ) {
         continue;
      }

      if (theElement.type != 'checkbox') {
         continue;
      }
      
      if ( theElement.name.substring(0,3) == filter) {
         switch(theValue) {
            case 'A':
               theElement.checked = true;
               break;
            case 'N':
               theElement.checked = false;
               break;
            case 'X':
               window.location.reload(true);
               return;
         }
      }
   }
}

function CheckAnchor ( anchorId )
{
   var anchorObject = document.getElementById(anchorId);
   
   var theOldText   = anchorObject.innerHTML;
      
   anchorObject.innerHTML = "&nbsp;Receipt Info&nbsp;";
   
   window.print();
   
   anchorObject.innerHTML = theOldText;
}

function UpdateSelectedText(elementName, tex)
{
	var radioObject = GetObjectFromName(radioName);
	radioObject.value = radioValue;
}

// ---------------------------------------------------------------------------
// ToggleEmail
//
//      Purpose: Hide/Show Email (reply requested) in pulse form based on radio button
// ---------------------------------------------------------------------------
function ToggleEmail ( radio )
{  
   var emailObj, staticObj;
   
   // ------------------------------------------------------------------------
   // get email object from name
   // ------------------------------------------------------------------------
   emailObj    = GetObjectFromName('email');

   // ------------------------------------------------------------------------
   // get 'title' of email with internal function
   // ------------------------------------------------------------------------
   staticObj   = document.getElementById('static');   
   
   // ------------------------------------------------------------------------
   // radio object passed (this)
   // ------------------------------------------------------------------------
   var value   = radio.value;
   
   // ------------------------------------------------------------------------
   // if 'y', then email is desired - display title and text entry area
   // ------------------------------------------------------------------------
   if (radio.value == 'Y') {
      emailObj.style.display = 'inline';
      staticObj.style.display = 'inline';
   }
   // ------------------------------------------------------------------------
   // otherwise, hide these objects
   // ------------------------------------------------------------------------
   else {
      emailObj.style.display = 'none';
      staticObj.style.display = 'none';
   }   
}

// ---------------------------------------------------------------------------
// SetDivisions
//
//      Purpose: Set divisions same as first one 
// ---------------------------------------------------------------------------
function SetDivisions ( )
{
   // ------------------------------------------------------------------------
   // default shortcut access to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];
   
   // ------------------------------------------------------------------------
   // looking for first one 
   // ------------------------------------------------------------------------
   var first = true;
   
   // ------------------------------------------------------------------------
   // go through each element in form and look for select item
   // ------------------------------------------------------------------------
   for (var i=0;i<form.elements.length;i++) {
      var theElement = form.elements[i];
      var name       = theElement.name;
      var value      = theElement.value;
      
      // ---------------------------------------------------------------------
      // fieldsets and legends don't have name properties
      // ---------------------------------------------------------------------
      if ( theElement.name == undefined || theElement.name == 'undefined' ) {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // if not a division id field, then skip it
      // ---------------------------------------------------------------------
      if (name.substr(0,10) != "divisionId") {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // if this is the first one, get the value and remove 'first' flage
      // ---------------------------------------------------------------------
      if (first) {
         sequence = value;
         first = false;
         continue;
      }
      
      // ---------------------------------------------------------------------
      // update the value to first one of these (as above)
      // ---------------------------------------------------------------------
      theElement.value = sequence;
   }
}

// ---------------------------------------------------------------------------
// ClickRadioValue
//
//      Purpose: The purpose of this function is to click a radio button
//               based on the name and value - allows clicking anywhere in
//               a table column
//               first item in their select list.
// ---------------------------------------------------------------------------
function ClickRadioValue ( elementName, pValue )
{
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];

   // ------------------------------------------------------------------------
   // build an element name (for the radio passed) and get the length
   // ------------------------------------------------------------------------
   var eName   = "form." + elementName
   var len     = eval(eName + ".length");
   
   // ------------------------------------------------------------------------
   // go through each radio button and click the appropriate one
   // ------------------------------------------------------------------------
   for ( var i=0; i<len; i++ ) {
      // ---------------------------------------------------------------------
      // build radio element name, e.g. form.radio[i] and get its value
      // ---------------------------------------------------------------------
      var element = eval(eName + "[" + i + "]");
      eValue = element.value;
      
      // ---------------------------------------------------------------------
      // if the value is the same as the one passed, then click this radio btn
      // ---------------------------------------------------------------------
      if ( eValue == pValue) {
         element.click();
         element.style.color = 'red';
      }
      else {
         //element.style.background-color = 'darkgray';
      }
   }
}

// ---------------------------------------------------------------------------
// ClickRadioId
//
//      Purpose: The purpose of this function is to click a radio button
//               based on the name and value - allows clicking anywhere in
//               a table column
//               first item in their select list.
// ---------------------------------------------------------------------------
function ClickRadioId ( id )
{
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   var radioObj;
   
   // ------------------------------------------------------------------------
   // get 'title' of email with internal function
   // ------------------------------------------------------------------------
   radioObj   = document.getElementById(id);   
   
   // ------------------------------------------------------------------------
   // build an element name (for the radio passed) and get the length
   // ------------------------------------------------------------------------
   radioObj.click();
}

// ---------------------------------------------------------------------------
// SelectRadioByValue
//
//      Purpose: Display instructions for search based on button clicked
// ---------------------------------------------------------------------------
function SelectRadioByValue ( strValue, radioName )
{   
   // ------------------------------------------------------------------------
   // save for backward compatibility
   // ------------------------------------------------------------------------
   switch (arguments.length) {
      case 1:
         radioName = 'queryType';
         break;
   }
   
   // ------------------------------------------------------------------------
   // shortcut to form 
   // ------------------------------------------------------------------------
   var form = document.forms[0];
   
   var result;
   
   var name    = 'form.' + radioName;
   var length  =  eval(name + '.length');
   
   // ------------------------------------------------------------------------
   // indicate that this is a click initiated internally and NOT by a click
   // ------------------------------------------------------------------------
   internalChange = 1;
   
   // ------------------------------------------------------------------------
   // go through all radio buttons (hard coded here) and find
   // the one associated with this select item
   // ------------------------------------------------------------------------
   for (i=0;i<length;i++) {
      // ---------------------------------------------------------------------
      // get the value of this radio button
      // ---------------------------------------------------------------------
      var element = name + '[' + i + ']';
      var val = eval(element + '.value');
      
      // ---------------------------------------------------------------------
      // if the value is exact same (char match) as select object passed
      // ---------------------------------------------------------------------
      if ( val.substr(0,strValue.length) == strValue ) {
         // ------------------------------------------------------------------
         // check this radio button
         // ------------------------------------------------------------------
         eval (element + '.click()');
         // ------------------------------------------------------------------
         // save the result and exit the loop
         // ------------------------------------------------------------------
         result = i;         
         // ------------------------------------------------------------------
         // exit the loop
         // ------------------------------------------------------------------
         break;
      }
   }
   
   // ------------------------------------------------------------------------
   // reset internal change indicator
   // ------------------------------------------------------------------------
   internalChange = 0;   
   
   // ------------------------------------------------------------------------
   // return the result
   // ------------------------------------------------------------------------
   return result;
}

function ModifyStaticText ( elementId, text, className )
{
	switch (arguments.length) {
		case 1:
			text = 'Need Text';
		case 2:
			className = '';
			break;
	}
	
	var staticElement = document.getElementById(elementId);
	
	if ('' != className) {
		staticElement.className 	= 	className;
	}
	
	staticElement.innerHTML	=	text;

}


// ---------------------------------------------------------------------------
// HasText
//
//      Purpose: Find an element by partial name
// ---------------------------------------------------------------------------
function HasText ( partialName, valueName )
{
   // ------------------------------------------------------------------------
   // use default for backward compatibility
   // ------------------------------------------------------------------------
   if ( arguments.length == 1) {
      valueName = 'queryValue';
   }
   
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   var form = document.forms[0];
   var valueObj = GetObjectFromName(valueName,form);
   
   // ------------------------------------------------------------------------
   // go through each element in form
   // ------------------------------------------------------------------------
   for ( var i=0;i<form.elements.length;i++) {
      var type  = form.elements[i].type;
      var name  = form.elements[i].name;
      var value = form.elements[i].value;
      
      // ---------------------------------------------------------------------
      // cant work for radio buttons, as they have same name
      // ---------------------------------------------------------------------
      if ( type == 'radio' )
         continue;
         
      // ---------------------------------------------------------------------
      // fieldsets and legends don't have name properties
      // ---------------------------------------------------------------------
      if ( name == undefined || name == 'undefined' ) {
         continue;
      }
      
      // ---------------------------------------------------------------------
      // if name matches, then get the value of this element 
      // ---------------------------------------------------------------------
      if ( name.substr(0,partialName.length) == partialName ) {         
         // form.queryValue.value = value;
         valueObj.value = value;
         if ( value == '' )
            return false;
         else
            return true;
      }
   }
   
   return false;
}

// ---------------------------------------------------------------------------
// ClearSubjectSelectsExcept
//
//      Purpose: clear all select items, e.g. reset them to no selection,
//               except for the one passed as a parameter
// ---------------------------------------------------------------------------
function ClearSubjectSelectsExcept (elementName,useSub)
{
   if ( arguments.length != 2 ) {
      useSub = 1;
   }
   
   // ------------------------------------------------------------------------
   // shortcut to form
   // ------------------------------------------------------------------------
   form = document.forms[0];
   
   // ------------------------------------------------------------------------
   // go through each element in form and look for select item
   // ------------------------------------------------------------------------
   for (var i=0;i<form.elements.length;i++) {
      var type = form.elements[i].type;
      var name = form.elements[i].name;
      // ---------------------------------------------------------------------
      // if this is a select, and NOT the one passed, then reset to first item
      // ---------------------------------------------------------------------
      if ( (type.substr(0,6) == "select") && 
           (name != elementName) ) {
           if ( useSub && name.substr(0,4) != 'sub_') {
             continue;
           }
         form.elements[i].selectedIndex = 0;
      }
   }
}

// ---------------------------------------------------------------------------
// UserAdminSquadron
//
//      Purpose: Access User admin with specific squadron
// ---------------------------------------------------------------------------
function UserAdminSquadron (theElement, code)
{
   // ------------------------------------------------------------------------
   // build url
   // ------------------------------------------------------------------------      
   var url = code + theElement.value;
   
   // ------------------------------------------------------------------------
   // go to the url
   // ------------------------------------------------------------------------      
   location.href  = url;      
}

function AddUserToList ( )
{
   var value;
   var theElement;
   var parts = new Array();
   
   var ctr = 0;
   // ------------------------------------------------------------------------
   // username cant be blank
   // ------------------------------------------------------------------------
   theElement = GetObjectFromName('USERNAME');	
   value = theElement.value;
   if (IsBlank(value) ) {
      alert( 'Username Cant Be Blank' );
      theElement.focus();
      theElement.select();
      return;
   }
   parts[ctr++] = value;
   	
   theElement = GetObjectFromName('PASSWORD');
   value = theElement.value;
   if (IsBlank(value) ) {
      alert( 'Password Cant Be Blank' );
      theElement.focus();
      theElement.select();
      return;
   }
   parts[ctr++] = value;
   
   theElement = GetObjectFromName('ROLE');
   value = theElement.value;
   if (IsBlank(value) ) {
      alert( 'Role Cant Be Blank' );
      theElement.focus();
      theElement.select();
      return;
   }
   parts[ctr++] = value;
	
   theElement = GetObjectFromName('DIVISIONID');
   value = theElement.value;
//   if (IsBlank(value) ) {
//      alert( 'Workgroup Cant Be Blank' );
//      theElement.focus();
//      theElement.select();
//      return;
//   }
   parts[ctr++] = value;
	
   theElement = GetObjectFromName('SQUADRONID');
   value = theElement.value;
   if (IsBlank(value) ) {
      alert( 'Squadron Cant Be Blank' );
      theElement.focus();
      theElement.select();
      return;
   }
   parts[ctr++] = value;
		
   theElement = GetObjectFromName('UNIT_ACCESS');
   value = theElement.value;
   if (IsBlank(value) ) {
      alert( 'Unit Access Cant Be Blank' );
      theElement.focus();
      theElement.select();
      return;
   }
   parts[ctr++] = value;

   theElement = GetObjectFromName('EXPIREDATE');
   value = theElement.value;
   if (IsBlank(value) ) {
      alert( 'Date Cant Be Blank' );
      theElement.focus();
      theElement.select();
      return;
   }
	
   var dateValid = IsSlashDate(value);
	
   // ------------------------------------------------------------------
   // not good, so set the focus to it and select it, return false
   // ------------------------------------------------------------------
   if ( !dateValid[0]) {
      HandleBadElement(theElement, dateValid[1]);                        
      return;
   }
   parts[ctr++] = value;
   var allParts = parts.join('|');
   var textObj = GetObjectFromName('USERTEXT');
   var theData = textObj.value + '\n' + allParts;
   textObj.value = theData;                  
}

