//Setup the global vars.
var FI_objChar1;
var FI_objChar2;
var FI_objChar3;
var FI_objChar4;
var FI_objChar5;
var FI_objChar6;
var FI_objChar7;
var FI_objChar8;
var FI_objChar9;
var FI_objChar10;
var FI_objChar11;
var FI_objChar12;
var FI_objChar13;
var FI_objChar14;

/*********************************************************************************************
* Setup and Page Display functions
*********************************************************************************************/
//Preloads the question elements and starts up app.
function FI_fcnStartQuestionsUp()
{
  //Load the global vars and reset the drop down options.
  FI_objChar1  = document.FI_Score_1.Q1;
  FI_fcnResetQuestion(FI_objChar1);
  FI_objChar2  = document.FI_Score_1a.Q1a;
  FI_fcnResetQuestion(FI_objChar2);
  FI_objChar3  = document.FI_Score_2.Q2;
  FI_fcnResetQuestion(FI_objChar3);
  FI_objChar4  = document.FI_Score_3.Q3;
  FI_fcnResetQuestion(FI_objChar4);
  FI_objChar5  = document.FI_Score_4.Q4;
  FI_fcnResetQuestion(FI_objChar5);
  FI_objChar6  = document.FI_Score_5.Q5;
  FI_fcnResetQuestion(FI_objChar6);
  FI_objChar7  = document.FI_Score_6.Q6;
  FI_fcnResetQuestion(FI_objChar7);
  FI_objChar8  = document.FI_Score_7.Q7;
  FI_fcnResetQuestion(FI_objChar8);
  FI_objChar9  = document.FI_Score_7a.Q7a;
  FI_fcnResetQuestion(FI_objChar9);
  FI_objChar10 = document.FI_Score_8.Q8;
  FI_fcnResetQuestion(FI_objChar10);
  FI_objChar11 = document.FI_Score_8a.Q8a;
  FI_fcnResetQuestion(FI_objChar11);
  FI_objChar12 = document.FI_Score_9.Q9;
  FI_fcnResetQuestion(FI_objChar12);
  FI_objChar13 = document.FI_Score_10.Q10;
  FI_fcnResetQuestion(FI_objChar13);
  FI_objChar14 = document.FI_Score_10a.Q10a;
  FI_fcnResetQuestion(FI_objChar14);

  //Display the first page.
  FI_fcnDisplayQuestion(1, false)
}

//Display the page the user is on.
function FI_fcnDisplayQuestion(a_intPageID, a_blnGoingBack)
{
  var SCORE_RANGE = 25;

  var blnGoToExitPage = false;
  var intScore        = 0;
  var intLowScore     = 0;
  var intHighScore    = 0;
  var intPosition     = 0;
  var strResultsName  = '';
  var objResultsLayer;

  //To page one.
  if (a_intPageID == 1)
  {
    //Hide Page two layers if going back.
    if (a_blnGoingBack == true)
    {
      //Hide the second set of questions.
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_3'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_4'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_5'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_6Top'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_6Mid'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_6Bot'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_7'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_7a'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Page3Link'));
    }

    //Hide the exit layer.
    FI_fcnHideLayer(FI_fcnGetLayer('FI_Exit'));
    //Display the Header, Intro text, and first set of questions.
    FI_fcnMoveToShow('FI_Header', FI_intDivStartX, FI_intDivStartY);
    FI_fcnMoveToShow('FI_Intro', FI_intDivStartX, FI_fcnFindY('FI_Header' + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_Question_1', FI_intDivStartX, 
                     FI_fcnFindY('FI_Intro' + FI_IMAGE_SUFFIX));

    //Only show follow up question if it is needed and position next question accordingly.
    if ((FI_fcnAnySelected(FI_objChar1) == false) || 
        (FI_fcnIsSelected(FI_objChar1, 0) == true))
    {
      FI_fcnMoveToHide('FI_Question_1a', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_1' + FI_IMAGE_SUFFIX));
      FI_fcnMoveToShow('FI_Question_2', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_1' + FI_IMAGE_SUFFIX));
    }
    else
    {
      FI_fcnMoveToShow('FI_Question_1a', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_1' + FI_IMAGE_SUFFIX));
      FI_fcnMoveToShow('FI_Question_2', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_1a' + FI_IMAGE_SUFFIX));
    }

    FI_fcnMoveToShow('FI_Content', FI_intDivStartX, 
                     FI_fcnFindY('FI_Question_2' + FI_IMAGE_SUFFIX));
  }
  //To page two.
  else if (a_intPageID == 2)
  {
    //Only validate if going forward.
    if (a_blnGoingBack == false)
    {
      if (FI_fcnValidatePageOne() == false)
      {
        alert(FI_ERROR_MESSAGE);
        return;
      }
    }

    //Check to see if you can get credit score.
    if ((FI_fcnIsSelected(FI_objChar3, 0)) || (FI_fcnIsSelected(FI_objChar3, 1)))
    {
      if (FI_fcnIsSelected(FI_objChar1, 0))
        blnGoToExitPage = true;
      else
      {
        if (FI_fcnIsSelected(FI_objChar2, 0))
          blnGoToExitPage = true;
      }
    }

    //Hide Page three layers if going back else hide page one questions.
    if (a_blnGoingBack == true)
    {
      //Hide the third set of questions.
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_8'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_8a'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_9Top'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_9Mid'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_9Bot'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_10'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_10a'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Page4Link'));
    }
    else
    {
      //Hide the first set of questions.
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Intro'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_1'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_1a'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_2'));
    }

    //Show Exit Page.
    if (blnGoToExitPage == true)
    {
      //Display the exit page and move it to the correct place.
      FI_fcnMoveToShow('FI_Exit', FI_intDivStartX, 
                       FI_fcnFindY('FI_Header' + FI_IMAGE_SUFFIX));
      //Display the exit page and move it to the correct place.
      FI_fcnMoveToShow('FI_Content', FI_intDivStartX, 
                       FI_fcnFindY('FI_Exit' + FI_IMAGE_SUFFIX));

      //Scroll to top of window.
      window.scrollTo(0, 0);
      return;
    }

    //Show the second set of questions.
    FI_fcnMoveToShow('FI_Question_3', FI_intDivStartX, 
                     FI_fcnFindY('FI_Header' + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_Question_4', FI_intDivStartX, 
                     FI_fcnFindY('FI_Question_3' + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_Question_5', FI_intDivStartX, 
                     FI_fcnFindY('FI_Question_4' + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_Question_6Top', FI_intDivStartX, 
                     FI_fcnFindY('FI_Question_5' + FI_IMAGE_SUFFIX));
    FI_fcnMoveToHide('FI_Question_6Mid', FI_intDivStartX, 
                     FI_fcnFindY('FI_Question_6Top' + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_Question_6Bot', FI_intDivStartX, 
                     FI_fcnFindY('FI_Question_6Top' + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_Question_7', FI_intDivStartX, 
                     FI_fcnFindY('FI_Question_6Bot' + FI_IMAGE_SUFFIX));

    //Only show follow up question if it is needed and position next question accordingly.
    if ((FI_fcnAnySelected(FI_objChar8) == false) || 
        (FI_fcnIsSelected(FI_objChar8, 0) == true))
    {
      FI_Question_7avis = 0;
      FI_fcnMoveToHide('FI_Question_7a', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_7' + FI_IMAGE_SUFFIX));
      FI_fcnMoveToShow('FI_Page3Link', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_7' + FI_IMAGE_SUFFIX));
    }
    else
    {
      FI_Question_7avis = 1;
      FI_fcnMoveToShow('FI_Question_7a', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_7' + FI_IMAGE_SUFFIX));
      FI_fcnMoveToShow('FI_Page3Link', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_7a' + FI_IMAGE_SUFFIX));
    }

    FI_fcnMoveToShow('FI_Content', FI_intDivStartX, 
                     FI_fcnFindY('FI_Page3Link' + FI_IMAGE_SUFFIX));
  }
  //To page three.
  else if (a_intPageID == 3)
  {
    //Only validate if going forward.
    if (a_blnGoingBack == false)
    {
      if (FI_fcnValidatePageTwo() == false)
      {
        alert(FI_ERROR_MESSAGE);
        return;
      }
    }

    //Hide Page three layers if going back else hide page one questions.
    if (a_blnGoingBack == true)
    {
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ScoreResults'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ResultsTop_740'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ResultsBottom_740'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ResultsTop_699'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ResultsBottom_699'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ResultsTop_679'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ResultsBottom_679'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ResultsTop_620'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ResultsBottom_620'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ResultsTop_560'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ResultsBottom_560'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ResultsTop_300'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_ResultsBottom_300'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Results_Graph_Back'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Results_Graph_Front'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Results_Graph_Bead'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Results_Graph_Range'));
    }
    else
    {
      //Hide the second set of questions.
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_3'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_4'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_5'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_6Top'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_6Mid'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_6Bot'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_7'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_7a'));
      FI_fcnHideLayer(FI_fcnGetLayer('FI_Page3Link'));
    }

    //Show the third set of questions.
    FI_fcnMoveToShow('FI_Question_8', FI_intDivStartX, 
                     FI_fcnFindY('FI_Header' + FI_IMAGE_SUFFIX));
    //Only show follup question if it is needed.
    if ((FI_fcnAnySelected(FI_objChar10) == false) || 
        (FI_fcnIsSelected(FI_objChar10, 0) == true))
    {
      FI_fcnMoveToHide('FI_Question_8a', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_8' + FI_IMAGE_SUFFIX));
      FI_fcnMoveToShow('FI_Question_9Top', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_8' + FI_IMAGE_SUFFIX));
    }
    else
    {
      FI_fcnMoveToShow('FI_Question_8a', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_8' + FI_IMAGE_SUFFIX));
      FI_fcnMoveToShow('FI_Question_9Top', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_8a' + FI_IMAGE_SUFFIX));
    }

    FI_Question_9Midvis = 0;
    FI_fcnMoveToHide('FI_Question_9Mid', FI_intDivStartX, 
                     FI_fcnFindY('FI_Question_9Top' + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_Question_9Bot', FI_intDivStartX, 
                     FI_fcnFindY('FI_Question_9Top' + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_Question_10', FI_intDivStartX, 
                     FI_fcnFindY('FI_Question_9Bot' + FI_IMAGE_SUFFIX));

    //Only show follup question if it is needed.
    if ((FI_fcnAnySelected(FI_objChar13) == false) || 
        (FI_fcnIsSelected(FI_objChar13, 1) == true))
    {
      FI_Question_10avis = 0;
      FI_fcnMoveToHide('FI_Question_10a', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_10' + FI_IMAGE_SUFFIX));
      FI_fcnMoveToShow('FI_Page4Link', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_10' + FI_IMAGE_SUFFIX));
    }
    else
    {
      FI_Question_10avis = 1;
      FI_fcnMoveToShow('FI_Question_10a', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_10' + FI_IMAGE_SUFFIX));
      FI_fcnMoveToShow('FI_Page4Link', FI_intDivStartX, 
                       FI_fcnFindY('FI_Question_10a' + FI_IMAGE_SUFFIX));
    }

    FI_fcnMoveToShow('FI_Content', FI_intDivStartX, 
                     FI_fcnFindY('FI_Page4Link' + FI_IMAGE_SUFFIX));
  }
  //To page four.
  else if (a_intPageID == 4)
  {
    if (FI_fcnValidatePageThree() == false)
    {
      alert(FI_ERROR_MESSAGE);
      return;
    }

    //Hide the third set of questions.
    FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_8'));
    FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_8a'));
    FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_9Top'));
    FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_9Mid'));
    FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_9Bot'));
    FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_10'));
    FI_fcnHideLayer(FI_fcnGetLayer('FI_Question_10a'));
    FI_fcnHideLayer(FI_fcnGetLayer('FI_Page4Link'));

    //Get the score.
    intScore = FI_fcnComputeScore()
    //Store the High and Low range.
    intLowScore  = intScore - SCORE_RANGE;
    intHighScore = intScore + SCORE_RANGE;

    //Resize the text boxes for other browsers than IE.
    if (FI_IS_IE == false)
    {
      document.FI_Results.LowCreditRange.size  = 3;
      document.FI_Results.HighCreditRange.size = 3;
    }

    //Display the High and low range.
    document.FI_Results.LowCreditRange.value  = intLowScore;
    document.FI_Results.HighCreditRange.value = intHighScore;

    //Get the starting position for the graph bead and score range.
    intPosition = FI_fcnStartPosition(intLowScore)

    //Update the bead and score range images for the result graph.
    FI_fcnUpdateImageSizes(intLowScore, intHighScore);

    //Get the results name depending on the Score.
    if (intScore > 740)
      strResultsName = '740';
    else if (intScore > 699)
      strResultsName = '699';
    else if (intScore > 679)
      strResultsName = '679';
    else if (intScore > 620)
      strResultsName = '620';
    else if (intScore > 560)
      strResultsName = '560';
    else if (intScore >= 300)
      strResultsName = '300';

    //Show the results.
    FI_fcnMoveToShow('FI_ScoreResults', FI_intDivStartX, 
                     FI_fcnFindY('FI_Header' + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_ResultsTop_' + strResultsName, FI_intDivStartX, 
                     FI_fcnFindY('FI_ScoreResults' + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_Results_Graph_Back', FI_intDivStartX, 
                     FI_fcnFindY('FI_ResultsTop_' + strResultsName + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_Results_Graph_Front', FI_intDivStartX, 
                     FI_fcnFindY('FI_ResultsTop_' + strResultsName + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_Results_Graph_Bead', FI_intDivStartX + intPosition, 
                     FI_fcnFindY('FI_ResultsTop_' + strResultsName + FI_IMAGE_SUFFIX) + 43);
    FI_fcnMoveToShow('FI_Results_Graph_Range', FI_intDivStartX + intPosition, 
                     FI_fcnFindY('FI_ResultsTop_' + strResultsName + FI_IMAGE_SUFFIX) + 15);
    FI_fcnMoveToShow('FI_ResultsBottom_' + strResultsName, FI_intDivStartX, 
                     FI_fcnFindY('FI_Results_Graph_Back' + FI_IMAGE_SUFFIX));
    FI_fcnMoveToShow('FI_Content', FI_intDivStartX, 
                     FI_fcnFindY('FI_ResultsBottom_' + strResultsName + FI_IMAGE_SUFFIX));
  }

  //Scroll to top of window.
  window.scrollTo(0, 0);
}

//Display the Show Example Layer.
function FI_fcnShowExample(a_strLayerName)
{
  eval(a_strLayerName + "vis = 0");
  FI_fcnMinMaxDiv(a_strLayerName);
}

/*********************************************************************************************
* Graph Setup functions
*********************************************************************************************/
//Correctly set the width of the images for the graph.
function FI_fcnUpdateImageSizes(a_intLowScore, a_intHighScore)
{
  var TOTAL_BEAD_EDGE_WIDTH  = 6;
  var TOTAL_RANGE_EDGE_WIDTH = 2;

  var objBeadImage;
  var objRangeImage;
  var intImageWidth = 0;

  intImageWidth = FI_fcnStartPosition(a_intHighScore) - FI_fcnStartPosition(a_intLowScore);

  objBeadImage = document.images['FI_Bead'];
  objBeadImage.width = intImageWidth - TOTAL_BEAD_EDGE_WIDTH;

  objRangeImage = document.images['FI_BlackLine'];
  objRangeImage.width = intImageWidth - TOTAL_RANGE_EDGE_WIDTH;
}

//Find the start X position for the Bead and Range Line.
function FI_fcnStartPosition(a_intScore)
{
  //Declare the Constants.
  var POSITION_OF_500       = 68;
  var START_OF_DOUBLE_RANGE = 620;
  var START_OF_NORMAL_RANGE = 500;
  var END_OF_DOUBLE_RANGE   = 770;

  var intPosition = 0;

  //Compute the score range depending on where the low score is located.
  if (a_intScore < 500)
  {
    //This position is condensed so the range must be divided by 3.
    intPosition = POSITION_OF_500 - Math.round(((START_OF_NORMAL_RANGE - a_intScore) / 3));
  }
  else if (a_intScore <= START_OF_DOUBLE_RANGE)
    intPosition = POSITION_OF_500 + (a_intScore - START_OF_NORMAL_RANGE);
  else if (a_intScore <= END_OF_DOUBLE_RANGE)
    intPosition = POSITION_OF_500 + (START_OF_DOUBLE_RANGE - START_OF_NORMAL_RANGE) + 
                  ((a_intScore - START_OF_DOUBLE_RANGE) * 2);
  else
    intPosition = POSITION_OF_500 + (START_OF_DOUBLE_RANGE - START_OF_NORMAL_RANGE) + 
                  ((END_OF_DOUBLE_RANGE - START_OF_DOUBLE_RANGE) * 2) + 
                  (a_intScore - END_OF_DOUBLE_RANGE);
  return(intPosition);
}

/*********************************************************************************************
* Select element functions
*********************************************************************************************/
//Get the boolean if the element's item is selected.
function FI_fcnIsSelected(a_objElement, a_intItem)
{
  return(a_objElement[a_intItem].checked);
}

//Get the boolean if any of the element's item are selected.
function FI_fcnAnySelected(a_objElement)
{
  var intCount = 0;
  //Check to see if any are checked.
  for (intCount = 0; intCount < a_objElement.length; intCount++)
  {
    if (a_objElement[intCount].checked == true)
      return(true);
  }

  return(false);
}

//Takes the element and returns the selected item number from the element.
function FI_fcnGetSelectedID(a_objElement)
{
  for (var intCount = 0; intCount < a_objElement.length; intCount++)
  {
    if (FI_fcnIsSelected(a_objElement, intCount) == true)
      return(intCount);
  }
}

//Resets the selected question.
function FI_fcnResetQuestion(a_objElement)
{
  var intCount = 0;

  //Loop through all of the radio buttons.
  for (intCount = 0; intCount < a_objElement.length; intCount++)
  {
    a_objElement[intCount].checked = false;
  }
}

//Check to see if follow up question should be present.
function FI_fcnFollowUpCheck(a_strFollowupLayerName, a_blnShowFollowupLayer)
{
  //Do not display the follow up question.
  if (a_blnShowFollowupLayer == false)
  {
    eval(a_strFollowupLayerName + "vis = 1");
    FI_fcnMinMaxDiv(a_strFollowupLayerName);
  }
  //Display the follow up question.
  else
  {
    eval(a_strFollowupLayerName + "vis = 0");
    FI_fcnMinMaxDiv(a_strFollowupLayerName);
  }
}

/*********************************************************************************************
* Validation functions
*********************************************************************************************/
//Validate all of the radio boxes in the form.
function FI_fcnValidateForm(a_objForm)
{
  var objElement;
  var blnItemChecked = false;

  //Loop through the elements.
  for (i = 0; i < a_objForm.length; i++)
  {
    objElement = a_objForm.elements[i];
    if (objElement.type == 'radio')
    {
      //Loop throught the selected select elements.
      for (j = 0; j < a_objForm[objElement.name].length; j++)
      {
        if (a_objForm[objElement.name][j].checked == true)
        {
          blnItemChecked = true;
        }
      }
      //Return False.
      if (blnItemChecked == false)
        return(false);
    }
  }
  return(true);
}

//Validate question page one.
function FI_fcnValidatePageOne()
{
  if (FI_fcnValidateForm(document.FI_Score_1) == false)
    return(false);

  if (FI_fcnValidateForm(document.FI_Score_2) == false)
    return(false);

  //If the followup question is present validate it.
  if (FI_fcnIsSelected(FI_objChar1, 0) == false)
  {
    if (FI_fcnValidateForm(document.FI_Score_1a) == false)
      return(false);
  }
  return(true);
}

//Validate question page two.
function FI_fcnValidatePageTwo()
{
  if (FI_fcnValidateForm(document.FI_Score_3) == false)
    return(false);

  if (FI_fcnValidateForm(document.FI_Score_4) == false)
    return(false);

  if (FI_fcnValidateForm(document.FI_Score_5) == false)
    return(false);

  if (FI_fcnValidateForm(document.FI_Score_6) == false)
    return(false);

  if (FI_fcnValidateForm(document.FI_Score_7) == false)
    return(false);

  //If the followup question is present validate it.
  if ((FI_fcnIsSelected(FI_objChar8, 0) == false))
  {
    if (FI_fcnValidateForm(document.FI_Score_7a) == false)
      return(false);
  }
  return(true);
}

//Validate question page three.
function FI_fcnValidatePageThree()
{
  if (FI_fcnValidateForm(document.FI_Score_8) == false)
    return(false);

  if (FI_fcnValidateForm(document.FI_Score_9) == false)
    return(false);

  if (FI_fcnValidateForm(document.FI_Score_10) == false)
    return(false);

  //If the followup question is present validate it.
  if (FI_fcnIsSelected(FI_objChar10, 0) == false)
  {
    if (FI_fcnValidateForm(document.FI_Score_8a) == false)
      return(false);
  }

  //If the followup question is present validate it.
  if (FI_fcnIsSelected(FI_objChar13, 1) == false)
  {
    if (FI_fcnValidateForm(document.FI_Score_10a) == false)
      return(false);
  }
  return(true);
}

/*********************************************************************************************
* Scoring functions
*********************************************************************************************/
//Compute the score.
function FI_fcnComputeScore()
{
  var intScore    = 0;
  var strScoreEnd = '';

  //Get the set ID.
  var intSetID = FI_fcnGetSetID();

  //Compute score.
  intScore += FI_fcnGetChar1(intSetID);
  intScore += FI_fcnGetChar2(intSetID);
  intScore += FI_fcnGetChar4(intSetID);
  intScore += FI_fcnGetChar5(intSetID);
  intScore += FI_fcnGetChar6(intSetID);
  intScore += FI_fcnGetChar7(intSetID);
  intScore += FI_fcnGetChar8(intSetID);
  intScore += FI_fcnGetChar9(intSetID);
  intScore += FI_fcnGetChar10(intSetID);
  intScore += FI_fcnGetChar11(intSetID);
  intScore += FI_fcnGetChar12(intSetID);
  intScore += FI_fcnGetChar14(intSetID);
  intScore += FI_fcnGetChar15(intSetID);

  //Get the first 2 chars of the score.
  strScoreStart = intScore.toString().substr(0,2);
  //Get the last char of the score.
  strScoreEnd = intScore.toString().substr(2, 1);

  //Round the Score to the nearest 5 increment.
  if (strScoreEnd == '9')
    intScore = intScore + 1;
  else if (strScoreEnd == '8')
    intScore = intScore + 2;
  else if (strScoreEnd == '7')
    intScore = intScore - 2;
  else if (strScoreEnd == '6')
    intScore = intScore - 1;
  else if (strScoreEnd == '4')
    intScore = intScore + 1;
  else if (strScoreEnd == '3')
    intScore = intScore + 2;
  else if (strScoreEnd == '2')
    intScore = intScore - 2;
  else if (strScoreEnd == '1')
    intScore = intScore - 1;

  return(intScore);
}

//Gets the integer set ID to use.
function FI_fcnGetSetID()
{
  if ((FI_fcnIsSelected(FI_objChar13, 0)) || (FI_fcnIsSelected(FI_objChar8, 1)) ||
      (FI_fcnIsSelected(FI_objChar8, 2)) || (FI_fcnIsSelected(FI_objChar8, 3)) ||
      (FI_fcnIsSelected(FI_objChar9, 2)) || (FI_fcnIsSelected(FI_objChar9, 3)) ||
      (FI_fcnIsSelected(FI_objChar12, 6)) || (FI_fcnIsSelected(FI_objChar12, 7)) ||
      (FI_fcnIsSelected(FI_objChar12, 8)) || (FI_fcnIsSelected(FI_objChar12, 9))
     )
  {
    return(81);
  }
  else
  {
    return(82);
  }
}

//Char 1.
function FI_fcnGetChar1(a_intSetID)
{
  //If 81.
  if (a_intSetID == 81)
  {
    return(0);
  }
  //Else 82.
  else
  {
    //Get the selected item ID.
    var intItemID = FI_fcnGetSelectedID(FI_objChar1);
    if (intItemID == 0)
      return(65);
    else if (intItemID == 1)
      return(68);
    else if (intItemID == 2)
      return(72);
    else
      return(78);
  }
}

//Char 2.
function FI_fcnGetChar2(a_intSetID)
{
  //If 81.
  if (a_intSetID == 81)
  {
    return(0);
  }
  //Else 82.
  else
  {
    //Return default if Char 1 does not require follow up question.
    if (FI_fcnIsSelected(FI_objChar1, 0))
    {
      return(72);
    }
    //Get the selected item ID.
    var intItemID = FI_fcnGetSelectedID(FI_objChar2);
    if ((intItemID == 0) || (intItemID == 1) || (intItemID == 2))
      return(72);
    else if ((intItemID == 3) || (intItemID == 4))
      return(74);
    else if ((intItemID == 5) || (intItemID == 6))
      return(85);
    else
      return(87);
  }
}

//Char 4.
function FI_fcnGetChar4(a_intSetID)
{
  //Get the selected item ID.
  var intItemID = FI_fcnGetSelectedID(FI_objChar4);
  //If 81.
  if (a_intSetID == 81)
  {
    if (intItemID == 0)
      return(72);
    else if (intItemID == 1)
      return(68);
    else if (intItemID == 2)
      return(67);
    else if (intItemID == 3)
      return(56);
    else
      return(47);
  }
  //Else 82.
  else
  {
    if (intItemID == 0)
      return(84);
    else if (intItemID == 1)
      return(82);
    else if (intItemID == 2)
      return(77);
    else
      return(65);
  }
}

//Char 5.
function FI_fcnGetChar5(a_intSetID)
{
  //If 81.
  if (a_intSetID == 81)
  {
    return(0);
  }
  //Else 82.
  else
  {
    //Get the selected item ID.
    var intItemID = FI_fcnGetSelectedID(FI_objChar5);
    if (intItemID == 0)
      return(65)
    else if (intItemID == 1)
      return(68);
    else
      return(73);
  }
}

//Char 6.
function FI_fcnGetChar6(a_intSetID)
{
  //Get the selected item ID.
  var intItemID = FI_fcnGetSelectedID(FI_objChar6);
  //If 81.
  if (a_intSetID == 81)
  {
    if (intItemID == 0)
      return(73)
    else if (intItemID == 1)
      return(71);
    else if (intItemID == 2)
      return(62);
    else
      return(47);
  }
  //Else 82.
  else
  {
    if (intItemID == 0)
      return(86)
    else if (intItemID == 1)
      return(83);
    else if (intItemID == 2)
      return(78);
    else
      return(65);
  }
}

//Char 7.
function FI_fcnGetChar7(a_intSetID)
{
  //If 81.
  if (a_intSetID == 81)
  {
      return(0);
  }
  //Else 82.
  else
  {
    //Get the selected item ID.
    var intItemID = FI_fcnGetSelectedID(FI_objChar7);
    if (intItemID == 0)
      return(65)
    else if (intItemID == 1)
      return(84);
    else if (intItemID == 2)
      return(83);
    else if (intItemID == 3)
      return(72);
    else if (intItemID == 4)
      return(71);
    else if (intItemID == 5)
      return(70);
    else
      return(66);
  }
}

//Char 8.
function FI_fcnGetChar8(a_intSetID)
{
  //Get the selected item ID.
  var intItemID = FI_fcnGetSelectedID(FI_objChar8);
  //If 81.
  if (a_intSetID == 81)
  {
    if (intItemID == 0)
      return(91);
    else if (intItemID == 1)
      return(47);
    else if (intItemID == 2)
      return(49);
    else if ((intItemID == 3) || (intItemID == 4))
      return(66);
    else if ((intItemID == 5) || (intItemID == 6))
      return(75);
    else
      return(88);
  }
  //Else 82.
  else
  {
    if (intItemID == 0)
      return(105);
    else if ((intItemID == 1) || (intItemID == 2) || (intItemID == 3))
      return(0);
    else if (intItemID == 4)
      return(65);
    else if (intItemID == 5)
      return(73);
    else
      return(79);
  }
}

//Char 9.
function FI_fcnGetChar9(a_intSetID)
{
  //If 81.
  if (a_intSetID == 81)
  {
    //Return default if Char 10 does not require follow up question.
    if (FI_fcnIsSelected(FI_objChar8, 0))
    {
      return(85);
    }
    //Get the selected item ID.
    var intItemID = FI_fcnGetSelectedID(FI_objChar9);
    if (intItemID == 0)
      return(74);
    else if (intItemID == 1)
      return(57);
    else
      return(47);
  }
  //Else 82.
  else
  {
    return(0);
  }
}

//Char 10.
function FI_fcnGetChar10(a_intSetID)
{
  //If 81.
  if (a_intSetID == 81)
  {
    //Get the selected item ID.
    var intItemID = FI_fcnGetSelectedID(FI_objChar10);
    if (intItemID == 0)
      return(80);
    else if (intItemID == 1)
      return(62);
    else
      return(51);
  }
  //Else 82.
  else
  {
    return(0);
  }
}

//Char 11.
function FI_fcnGetChar11(a_intSetID)
{
  //If 81.
  if (a_intSetID == 81)
  {
    //Return default if Char 8 does not require follow up question.
    if (FI_fcnIsSelected(FI_objChar10, 0))
    {
      return(65);
    }
    //Get the selected item ID.
    var intItemID = FI_fcnGetSelectedID(FI_objChar11);
    if (intItemID == 0)
      return(65);
    else
      return(47);
  }
  //Else 82.
  else
  {
    return(0);
  }
}

//Char 12.
function FI_fcnGetChar12(a_intSetID)
{
  //Get the selected item ID.
  var intItemID = FI_fcnGetSelectedID(FI_objChar12);
  //If 81.
  if (a_intSetID == 81)
  {
    if (intItemID == 0)
      return(48);
    else if ((intItemID == 1) || (intItemID == 2))
      return(106);
    else if ((intItemID == 3) || (intItemID == 4) || (intItemID == 5))
      return(83);
    else if (intItemID == 6)
      return(77);
    else if (intItemID == 7)
      return(67);
    else if (intItemID == 8)
      return(53);
    else
      return(47);
  }
  //Else 82.
  else
  {
    if (intItemID == 0)
      return(81);
    else if (intItemID == 1)
      return(102);
    else if (intItemID == 2)
      return(89);
    else if (intItemID == 3)
      return(78);
    else if (intItemID == 4)
      return(74);
    else
      return(65);
  }
}

//Char 14.
function FI_fcnGetChar14(a_intSetID)
{
  //If 81.
  if (a_intSetID == 81)
  {
    //Return default if Char 10 does not require follow up question.
    if (FI_fcnIsSelected(FI_objChar13, 1))
    {
      return(83);
    }
    //Get the selected item ID.
    var intItemID = FI_fcnGetSelectedID(FI_objChar14);
    if (intItemID == 0)
      return(47);
    else if (intItemID == 1)
      return(72);
    else
      return(73);
  }
  //Else 82.
  else
  {
    return(0);
  }
}

//Char 15.
function FI_fcnGetChar15(a_intSetID)
{
  //Get the selected item ID for Char 2.
  var intItemID1 = FI_fcnGetSelectedID(FI_objChar2);
  //Get the selected item ID for Char 3.
  var intItemID2 = FI_fcnGetSelectedID(FI_objChar3);

  //If question 1a was not available set value to zero.
  if (intItemID1 == null)
    intItemID1 = 0;

  //If 81.
  if (a_intSetID == 81)
  {
    //Convert Char 3 Item ID to Char 2 Item ID.
    if (intItemID2 == 4)
      intItemID2 = 4;
    else if (intItemID2 == 5)
      intItemID2 = 6;
    else if (intItemID2 == 6)
      intItemID2 = 7;
    else if (intItemID2 == 7)
      intItemID2 = 8;

    //Update to get the highest ID value.
    if (intItemID2 > intItemID1)
      intItemID1 = intItemID2;

    if (intItemID1 == 0)
      return(0);
    else if ((intItemID1 == 1) || (intItemID1 == 2) || (intItemID1 == 3))
      return(47);
    else if ((intItemID1 == 4) || (intItemID1 == 5))
      return(77);
    else if (intItemID1 == 6)
      return(92);
    else if (intItemID1 == 7)
      return(96);
    else
      return(103);
  }
  //Else 82.
  else
  {
    //Convert Char 3 Item ID to Char 2 Item ID.
    if (intItemID2 == 2)
      intItemID2 = 1;
    else if (intItemID2 == 4)
      intItemID2 = 4;
    else if (intItemID2 == 5)
      intItemID2 = 6;
    else if (intItemID2 == 6)
      intItemID2 = 7;
    else if (intItemID2 == 7)
      intItemID2 = 8;

    //Update to get the highest ID value.
    if (intItemID2 > intItemID1)
      intItemID1 = intItemID2;

    if (intItemID1 == 0)
      return(0);
    else if (intItemID1 == 1)
      return(65);
    else if ((intItemID1 == 2) || (intItemID1 == 3))
      return(81);
    else if ((intItemID1 == 4) || (intItemID1 == 5))
      return(90);
    else if ((intItemID1 == 6) || (intItemID1 == 7))
      return(101);
    else
      return(108);
  }
}

