// -----------------------------------------------------------------------------

function ValidateAndExecuteRequest(
            LanguageChoice,
            FactorList_Main,
            Form_MainUI) {
// Purpose :  Validate data to be submitted, submit if OK.
// Input :
//    LanguageChoice :  "English", "French"
//    FactorList_Main :  "FactorList" object.
//    Form_MainUI :  Form which we wish to submit.
// Output :
//    <Return value> :
//       false :  If we found bad data in the form.  Warning was posted.
//       true :  ExecuteRequest() was executed.
// Author :  Jerome Daoust, 2003/12/15.

   var FunctionalitySubmitted = false

   // Save the FORM elements, before the UI form is no longer visible.
   SaveFormValues(Form_MainUI)

   // Verify LanguageChoice.
   if ( ( "English" != LanguageChoice ) && 
        ( "French"  != LanguageChoice ) ){
      alert( "Bad value for LanguageChoice :  " + LanguageChoice )
      return FunctionalitySubmitted
   }

   // Convert string values into integer.
   // HeadWind = parseFloat( Form_MainUI.Select_HeadWind.options[Form_MainUI.Select_HeadWind.selectedIndex].value)

   // Loop on each FORM element.
   for (var i_element=0 ; i_element<Form_MainUI.elements.length ; i_element++ ) {
      // Establish FORM element object.
      FormElement = Form_MainUI.elements[i_element]

      // Deal with SELECT form elements.
      if ( "select-one" == FormElement.type ) {
         // Find a matching factor in of list.
         Factor_IndexFound = -1
         for (var i_Factor=0 ; i_Factor < FactorList_Main.length ; i_Factor++ ) {
            Factor = FactorList_Main[i_Factor]
            if ( FormElement.name == Factor.SelectorName ) {
               // Set selected option.
               Factor.SetOptionChosenIndex( FormElement.selectedIndex )

               // Note that the appropriate Factor was found.
               Factor_IndexFound = i_Factor
               i_Factor = FactorList_Main.length // Exit sooner.
            }
         }
         if ( Factor_IndexFound < 0 ) {
            alert( "Unable to find matching Factor in ValidateAndExecuteRequest()")
            return FunctionalitySubmitted
         }
      }
   }

   // Process the request.
   FactorList_Main.CreateDiagnostic( LanguageChoice)
   FunctionalitySubmitted = true

   return FunctionalitySubmitted
}
// -----------------------------------------------------------------------------

