/*
  File.......: ex_frameA_nav.js
  Author.....: Michael Thomas
  Orig Date..: 01/31/00
  Version....: v1.0.0
  System.....: ex_frameA_set.htm
  
  Description: Used in ex_frameA_nav.htm.  Controls the middle ("main") frame.

  Modification:

*/

var blnDebug    = false;
var intIndex    = 0;
var aFileList   = new Array();  //Array of pages to display
var hasLayers   = (document.layers);  //as of IE 5.1 & Nav 4.7 only Nav has layers.

//********************************************************************************
function init() { 
//********************************************************************************
  //Do nothing for now.
}

//********************************************************************************
function fFramesLoaded() {
//********************************************************************************
  fBuildFileList();
  setIndex(0);
  parent.main.location = aFileList[getIndex()].strSrc
}

//********************************************************************************
function fBuildFileList() {
//********************************************************************************

i = -1;
i++; aFileList[i] = new fcFileList("ex_frameA_introduction.htm");
i++; aFileList[i] = new fcFileList("ex_frameA_form1.htm");
i++; aFileList[i] = new fcFileList("ex_frameA_form2.htm");
i++; aFileList[i] = new fcFileList("ex_frameA_form3.htm");

if ( blnDebug || false ) fDebugListFiles();

}

//********************************************************************************
function setIndex( intSet ) {
//********************************************************************************

  if ( intSet < 0 ) {
    intSet = 0;
    alert("At the beginning.");
  }
  if ( intSet >= aFileList.length ) {
     intSet = aFileList.length - 1;
     alert("At the end.");
  }

  intIndex = intSet;

  return( intIndex )  //May want to set & get!
}
//********************************************************************************
function getIndex() {
//********************************************************************************
  return(intIndex);
}
//********************************************************************************
function fGoPrior() {
//********************************************************************************
  fNext(-1);
}

//********************************************************************************
function fGoNext() {
//********************************************************************************
  fNext(1);
}

//********************************************************************************
function fNext(intStep) {
//********************************************************************************

  setIndex(getIndex() + intStep);
  if ( blnDebug || false ) alert("getIndex() = " + getIndex());

  parent.main.location = aFileList[getIndex()].strSrc;

}
//********************************************************************************
function fStoreForms() {
//********************************************************************************

  var intIndex = getIndex();            //Get index value of aFileList to store page information.
  var objMain  = parent.main.document;  //This cuts down on the coding.

  for ( i=0; i < objMain.forms.length; i++ ) {

    //Store the aFileList.aobjForm array with the page's form objects.
    aFileList[intIndex].aobjForm[i] = new fcObjForm(objMain.forms[i]);

    for ( x=0; x < objMain.forms[i].elements.length ;x++ ) {

      //From each form, store the elements.
      aFileList[intIndex].aobjForm[i].aobjElem[x] = new fcObjElem(objMain.forms[i].elements[x]);

    }//for -> elements

  }//for -> forms

  //Start: Store Netscape's forms in layers
  if ( hasLayers ) {  

    for ( y=0; y < objMain.layers.length; y++ ) {
      //Store Layers
      aFileList[intIndex].aobjLayers[y] = new fcObjLayers(objMain.layers[y]);

      for ( i=0; i < objMain.layers[y].document.forms.length; i++ ) {
        //Store the layer's forms .
        aFileList[intIndex].aobjLayers[y].aobjForm[i] = new fcObjForm(objMain.layers[y].document.forms[i]);

        for ( x=0; x < objMain.layers[y].document.forms[i].elements.length ;x++ ) {
          //Store layer's form's elements.
          aFileList[intIndex].aobjLayers[y].aobjForm[i].aobjElem[x] = new fcObjElem(objMain.layers[y].document.forms[i].elements[x]);

        }//x, elements
      }//i, forms
    }//y, layers
  }//if hasLayers
  //Stop: Store Netscape's forms in layers

  alert("Form Stored - in Nav's frame!");
}


//********************************************************************************
function fRestoreForms() {
//********************************************************************************

  var intIndex = getIndex();            //Get index value of aFileList to store page information.
  var objMain  = parent.main.document;  //This cuts down on the coding.

  if ( aFileList[intIndex].aobjForm.length == 0 && aFileList[intIndex].aobjLayers.length == 0 ) {

    alert("No form information to restore. Possible reasons: " + "\n" + 
          "1. The page had no forms to store." + "\n" + 
          "2. You need to click on 'Store Form' first." + "\n" + 
          "");

  } else {

  
    for ( i=0; i < objMain.forms.length; i++ ) {
      //Cycle through the forms.

      for ( x=0; x < objMain.forms[i].elements.length ;x++ ) {
        //Cycle through the elements and restore states.

        fRestoreElem(objMain.forms[i].elements[x], 
                     aFileList[intIndex].aobjForm[i].aobjElem[x])
  
      }//for -> elements

    }//for -> forms

    //Start: Restore Netscape's forms in layers
    if ( hasLayers ) {  
      for ( y=0; y < objMain.layers.length; y++ ) {

        for ( i=0; i < objMain.layers[y].document.forms.length; i++ ) {
          //Cycle through the forms.
  
          for ( x=0; x < objMain.layers[y].document.forms[i].elements.length ;x++ ) {
            //Cycle through the elements and restore states.

            fRestoreElem(objMain.layers[y].document.forms[i].elements[x], 
                         aFileList[intIndex].aobjLayers[y].aobjForm[i].aobjElem[x])
  
          }//for -> elements
        }//for -> forms
      } //for ->layers
    } //if hasLayers

    //Stop: Restore Netscape's forms in layers

    alert("Form Restored - from Nav's frame!");  

  } //if

}

//********************************************************************************
function fRestoreElem(elemForm, objElem) {
//********************************************************************************
  //Restore forms element from an objElem passed from the array.

  elemForm.value = objElem.value;

  if ( "|checkbox|radio|".indexOf(objElem.type) != -1 ) {
    elemForm.checked = objElem.checked;
  }

}

//********************************************************************************
function fcFileList( strSrc ) {
//********************************************************************************
//Constructor for aFileList.

  this.strSrc     = strSrc;
  this.aobjForm   = new Array();  //Array of forms in the page.
  this.aobjLayers = new Array();  //Array of layers in the page.

}

//********************************************************************************
function fcObjLayers( objLayer ) { 
//********************************************************************************
  //Constructor for FormObj

  this.name      = objLayer.name;
  this.aobjForm  = new Array();   //An array of elements in the form.

}

//********************************************************************************
function fcObjForm( objForm ) { 
//********************************************************************************
  //Constructor for FormObj

  this.name      = objForm.name;
  this.aobjElem  = new Array();   //An array of elements in the form.

}

//********************************************************************************
function fcObjElem( objElem ) { 
//********************************************************************************

  this.name        = objElem.name;
  this.type        = objElem.type;
  this.value       = objElem.value;
  if ( "|checkbox|radio|".indexOf(objElem.type) != -1) {
    this.checked  = objElem.checked;
  } else {
    this.checked  = null;    
  }

}


//********************************************************************************
function fDebugListFiles() {
//********************************************************************************

  var strMsg = "";

  for ( i=0; i < aFileList.length; i++ ) {
    strMsg += aFileList[i].strSrc + "\n"
  }

  alert(strMsg);
}

