/*
##############################################################################
## <SOURCE
## Company  = "Four J's Development Tools"
## Project  = "Four J's Web Front End"
## Type     = "Module"
## Name     = "fglhtmld.js"
## Comment  = "Output sub-system"
## Version  = "1.1.00.00"
## Language = "Javascript"
## />
##############################################################################
## <UPDATE Version="1.0.00.00" Date="2001/07/05" Author="es">
##   <DESCRIPTION>
##      Creation. 
##   </DESCRIPTION>
## </UPDATE>
##############################################################################
## <DESCRIPTION> <![CDATA[ 
## ]]></DESCRIPTION>
##############################################################################
## <CVS_INFO><![CDATA[
## ]]></CVS_INFO>
##############################################################################
*/
//////////////////////////////////////////////////////////////////////////////
//                        GLOBAL VARIABLES
//////////////////////////////////////////////////////////////////////////////
 var g_fjsNextField='';   // Use to force the next field
                          // NULL go to the next field like in BDL
                          // !NULL go to the specified field
 var g_fjsBrowserInfo = new Object;       // Contain information on the browser                          

/////////////////////////////////////////////////////////////////
// Function:  fjsSetCharacterCase
//
// Parameter: Current field name
//            Flag: D - Lowercase
//                  U - Uppercase
// Returning: non
//
// Comments: set the value to lower, upper or as it is
///////////////////////////////////////////////////////////////// 
 function fjsSetCharacterCase( m_field, nFlag ) {
  var m_value = m_field.value;

  if ( m_value != "" ) {
    if ( nFlag == 'D' ) {
      m_field.value = m_value.toLowerCase();
    }
    
    if ( nFlag == 'U' ) {     
       m_field.value = m_value.toUpperCase();   
    } 
  }

 }

/////////////////////////////////////////////////////////////////
// Function:  fjsGetFieldValue
//
// Parameter: Current field name
//
// Returning: non
//
// Comments: Return the current field value
/////////////////////////////////////////////////////////////////
 function fjsGetFieldValue ( m_field ) {
   var m_value;

   if (m_field.tagName != "SELECT") {
     m_value = m_field.value;
   } else {
     m_value = m_field.options(m_field.selectedIndex).text;
   }
   
   return m_value;
 }

/////////////////////////////////////////////////////////////////
// Function:  fjsIsInteger
//
// Parameter: Current field name
//
// Returning: non
//
// Comments: Test if an integer field is correct
/////////////////////////////////////////////////////////////////
 function fjsIsInteger ( m_field ) {

   var m_value = fjsGetFieldValue(m_field);
   
   if (m_value.indexOf('.') != -1) {
     alert("Error in field");
     g_fjsNextField = m_field;
     fjsSetFieldFocus ( g_fjsNextField );            
   } else {
     m_value = fjsRemoveCharFromString( m_value, "," );
     if (isNaN(m_value)) { // if the entire is not a number
       alert("Character to numeric conversion error");    
       g_fjsNextField = m_field;
       fjsSetFieldFocus(g_fjsNextField);
     }
   }
 }

/////////////////////////////////////////////////////////////////
// Function:  fjsIsDecimal
//
// Parameter: Current field name
//
// Returning: non
//
// Comments: Test if an decimal field is correct
///////////////////////////////////////////////////////////////// 
 function fjsIsDecimal( m_field ) {
   var m_value = fjsGetFieldValue(m_field);

   m_value = fjsRemoveCharFromString( m_value, "," ); 
   m_value = fjsRemoveCharFromString( m_value, "." );
   
   if (isNaN(m_value)) { // if the entire is not a number
    alert("Character to numeric conversion error");    
    g_fjsNextField = m_field;    
    fjsSetFieldFocus(g_fjsNextField);    
   } 
 }
/////////////////////////////////////////////////////////////////
// Function:  fjsRemoveCharFromString
//
// Parameter: field value
//            Char to remove
//
// Returning: Value without char value
//
// Comments: Remove a char from a string
/////////////////////////////////////////////////////////////////  
 function fjsRemoveCharFromString(m_value, m_char) {
   if (m_value.indexOf( m_char ) != -1) {
     nFieldValue = m_value.split(m_char);
     m_value = nFieldValue.join('');
   }
   return m_value;
 }
/////////////////////////////////////////////////////////////////
// Function:  fjsBeforeFieldStatement
//
// Parameter: Reference of an object
//
// Returning: none
//
// Comments:  Determine if a next field action should be done
/////////////////////////////////////////////////////////////////  
 function fjsBeforeFieldStatement(currField) {
  
   // Set the current field   
   fjsSetCurrentField(currField);
   
   //dummy (currField);  	
   if ( g_fjsNextField ) {
     fjsSetFieldFocus( g_fjsNextField );
     g_fjsNextField = '';
   }
 } 	
/////////////////////////////////////////////////////////////////
// Function:  fjsSetCurrentField
//
// Parameter: Field name
//
// Returning: none
//
// Comments:  Set the name of the currentField
/////////////////////////////////////////////////////////////////   
 function fjsSetCurrentField ( currField ) {
    document.forms(gbl_fjsFormName).fjsCurrentField.value = currField.name;
    //window.status = 'Current element name: ' + document.forms(gbl_fjsFormName).fjsCurrentField.value;
 } 
/////////////////////////////////////////////////////////////////
// Function:  fjsActivateCurrentField
//
// Parameter: none
//
// Returning: none
//
// Comments:  Active current field
/////////////////////////////////////////////////////////////////   
   function fjsActivateCurrentField() {          
      for (i=0;i<document.forms(gbl_fjsFormName).length;i++) {
       if ( document.forms(gbl_fjsFormName).elements[i].name == document.forms(gbl_fjsFormName).fjsCurrentField.value ) {
       	if ( ! document.forms(gbl_fjsFormName).elements[i].disabled && 
             document.forms(gbl_fjsFormName).elements[i].type != "hidden" &&
             document.forms(gbl_fjsFormName).elements[i].style.visibility != "hidden" ) {
          eval (document.forms(gbl_fjsFormName).elements[i].focus());	
        }
        break;
       }
      }
   } 
/////////////////////////////////////////////////////////////////
// Function:  fjsSetFieldFocus
//
// Parameter: Field name
//
// Returning: none
//
// Comments:  Set the focus on the specified field name
/////////////////////////////////////////////////////////////////   
 function fjsSetFieldFocus ( m_field ) { 
   if ( ! m_field.disabled ) {
    eval("m_field.focus()");
   }
 } 
/////////////////////////////////////////////////////////////////
// Function:  fjsCallPrinterDialog
//
// Parameter: none
//
// Returning: none
//
// Comments:  Call the print method of the window class 
//            if the browser major version is equal or
//            than 4
/////////////////////////////////////////////////////////////////   
 function fjsCallPrinterDialog(){
  if (g_fjsBrowserInfo.version >= 4)  {
    window.print();
   }
 }
/////////////////////////////////////////////////////////////////
// Function:  fjsGetNavigatorInfo
//
// Parameter: none
//
// Returning: none
//
// Comments:  Get the navigator information
/////////////////////////////////////////////////////////////////   
function fjsGetNavigatorInfo () {  
  // Set the browser major version info
  g_fjsBrowserInfo.version = parseInt(navigator.appVersion);
 
  g_fjsBrowserInfo.isNavigator = false;
  g_fjsBrowserInfo.isIE        = false;
  
  if ( navigator.appName.indexOf("Netscape") != -1)
    g_fjsBrowserInfo.isNavigator = true;
  else if ( navigator.appName.indexOf("Microsoft") != -1 )
     g_fjsBrowserInfo.isIE        = true;
  else 
     g_fjsBrowserInfo.isIE        = true;

}

/////////////////////////////////////////////////////////////////
// Function:  fjsMouseOverMenu
//
// Parameter: none
//
// Returning: none
//
// Comments:  Do action when the mouse is over the menu bar
/////////////////////////////////////////////////////////////////   
function fjsMouseOverMenu(m_menu) {
  
  if ( ! m_menu.disabled ) {
	m_menu.className = "fjsMouseOverMenuButton fjsMenuFontSystem";
  }
}
	
/////////////////////////////////////////////////////////////////
// Function:  fjsMouseOutMenu
//
// Parameter: none
//
// Returning: none
//
// Comments:  Do action when the mouse go out from the menu bar
/////////////////////////////////////////////////////////////////   
function fjsMouseOutMenu(m_menu) {
  if ( ! m_menu.disabled ) {
	m_menu.className = "fjsMouseLeaveMenuButton fjsMenuFontSystem";
  }
}

/////////////////////////////////////////////////////////////////
// Function:  fjsMouseClickMenu
//
// Parameter: none
//
// Returning: none
//
// Comments:  
/////////////////////////////////////////////////////////////////   
function fjsMouseClickMenu(m_menu) {
  if ( ! m_menu.disabled ) {
	m_menu.className = "fjsMouseClickMenuButton fjsMenuFontSystem";
  }
}

/////////////////////////////////////////////////////////////////
// Function:  fjsSetApplication
//
// Parameter: none
//
// Returning: none
//
// Comments:  set application default
/////////////////////////////////////////////////////////////////   
function fjsSetApplication() {
 // Determine Navigator version
 fjsGetNavigatorInfo();
 // Set focus on the first element
 fjsActivateCurrentField();
 // configure menu
 configureMenuLayers();
}

/////////////////////////////////////////////////////////////////
// Function:  configureMenuLayers
//
// Parameter: event type
//
// Returning: none
//
// Comments:  Parse the HTML page to find layers for menu
/////////////////////////////////////////////////////////////////   
function configureMenuLayers()
{     
    var divArray = document.all.tags("DIV");// Retrieve the number of DIV element for the current page    
    var bProcessLayers = false;             // Bool means the first DIV proceed
    var nLeftPx        = 0;                 // Left pixel position
    var nOldWidthPx    = 0;                 // Width of the last element
    var szPattern      = /fjsMenuLayer/i;   // Set the pattern to compare with the DIV id
  	for(i=0;i<divArray.length;i++) {
     // Test if the current element is DIV generated by fjs (DHTMLIE55)
     // the name of this element should be fjsMenuLayer<Menu rank>      	 
  	 if ( szPattern.test(divArray[i].id) ) {
  	   // Stores the value of the offsetLeft for the first element.
  	   // This is the only position we know.    	   
  	   if ( ! bProcessLayers ) {
  	    nLeftPx = divArray[i].offsetLeft; 
  	    bProcessLayers = true;
  	   } else {
  	    // New left position is last position and the width of 
  	    // the previous element.
  	    nLeftPx += nOldWidthPx;
  	   }
  	   // Set the style of the current element  	   
  	   divArray[i].style.position = "absolute";
  	   divArray[i].style.zIndex   = i;
  	   divArray[i].style.left     = nLeftPx + "px";
  	   divArray[i].style.width    = divArray[i].clientWidth + "px";
  	   // Store the width of the current element
  	   nOldWidthPx = divArray[i].clientWidth;
       nOldWidthPx += 4;
  	 }
  	}
  	
}

