// Copyright Neil Ramsden 2004-2006. All rights reserved.

// Neil Ramsden
// DecisionTree.js
// 18 Nov 05 -> 21 Feb 06
//	Renamed as DecisionTree.
// 16 Jul 04 -> 26 Sep 04
//
// Uses: flowChart; SlidePresentation.
//
// This is the primary file for the interactive decision tree interface.
// Clients should include a definition of global variable flowChart.
// There are global variables, so ensure don't get unnecessary reloads, 
// ie. just load once in total.
//
// Assumes frame_0.document.MainForm exists with FinalWord text input; and
// this is the main form.

//---------------------------------------------------------------------------

/* DecisionTree

Typically, clients create a single DecisionTree instance that responds to 
requests from HTML documents.
The decision tree creates and owns a presentation object which links frames
to a cascade of abstract views.
*/

function processOption(pane, index)
//respond to user option index from pane
//  pane -- originating window or frame name
//  index -- option index
{
  var view = this.presentation.getView(pane);
  if (view)
    view.doSelect(index);
}

function resetDecisionTree()
//reset main form and clear all flow panes.
{
  frame_0.document.MainForm.reset();
  if (this.presentation.startView)
    this.presentation.startView.clear();
}

function startDecisionTree()
//initiate display options
//after: this.presentation.startView != null
{
  if (this.presentation.startView)
  {
    this.presentation.startView.clear();
  }
  else
  {
    var start_view = flowChart.makeView(this.presentation);
    this.presentation.startView = start_view;
  }
  var the_form = frame_0.document.MainForm;
  the_form.FinalWord.value = the_form.FinalWord.defaultValue;
  this.presentation.displayView(this.presentation.startView);
}

function DecisionTree()
{
  this.presentation = new SlidePresentation();
  
  this.processOption = processOption;
  this.reset = resetDecisionTree;
  this.start = startDecisionTree;
}
