<!--
// Troubleshoot display

var aIndent = 0 ;
var tableName = "" ;
var rows = new Array() ;
var qID = 0 ;
var oID = 0 ;
var qName = "" ;
var qText = "" ;
var nReps = 0 ;

function TableRow ( text , name , id , indent , type )
{
  this . aName = text ;						
  this . aSimpleName = name ;						
  this . aID = id ;
  this . aIndent = indent ;
  this . aType = type ;
  this . aStep = 0 ;
}

var tabRows = new Array() ;

function TScolumn ( id , name )
{
  this . aID = id ;
  this . aName = name ;
}

var columns = new Array() ;

function TS_SetWorkingTable(aName)
{
  tableName = aName ;
}

function TS_ClearIndent()
{
  aIndent = 0 ;
}

function TS_Indent(aMode)
{
  aIndent ++ ;
}

function TS_Deindent()
{
  if ( aIndent > 0 )
    aIndent -- ;
}

function TS_GetImage ( aName , addStdSize )
{
  var s = '<img src="' + GetImage ( aName ) + '" border="0"' ;
  if ( addStdSize != null )
    if ( addStdSize )
      s += ' height="16" width="16"' ;
  return ( s + '>' ) ;
}

function TS_GetIndent(aRowNo)
{
  var i = tabRows [ aRowNo ] . aIndent ;
  var ii , c , isLast ;
  var s = "" ;
  for ( ii = 1 ; ii <= i ; ii++ )
  {
    isLast = true ;
    for ( c = aRowNo + 1 ; c < tabRows . length ; c++ )
      if ( tabRows [ c ] . aIndent <= ii )
      {
        if ( tabRows [ c ] . aIndent == ii )
          isLast = false ;
        c = tabRows . length ;
      }
    if ( ii < i )
    {
      if ( isLast )
        s += TS_GetImage ( "ts_tree_.gif" , true ) ;
      else
        s += TS_GetImage ( "ts_tree_NS.gif" , true ) ;
    }
    else
    {
      if ( isLast )
        s += TS_GetImage ( "ts_tree_NE.gif" , true ) ;
      else
        s += TS_GetImage ( "ts_tree_NES.gif" , true ) ;
    }
  }
  return ( s ) ;
}

function TS_GetValueID ( objID , doc )
{
  if ( ! isInQuestionFrame ( doc ) )
    return ( 0 ) ;
  var vID = GetAnswerValue ( objID ) ;
  if ( vID == 0 )
  {
    var i = GetReplayIndexByID ( objID ) ;
    if ( i >= 0 )
      vID = replay[i].currentValue ;
  }
  return ( vID ) ;
}

function TS_AddColumn(colName,valueID,doc)
{
  t = doc.getElementById("TStable");
  if ( t.rows.length == 0 )
    r = t.insertRow( t.rows.length ) ;
  else
    r = t.rows[ t.rows.length - 1 ] ;
  c = r.insertCell( -1 ) ;
  if ( ! isInQuestionFrame ( doc ) )
    c . innerHTML = TS_GetImage("tiny.gif") ;
  else
  {
    c . innerHTML = "<nobr>&nbsp;&nbsp;&nbsp;" + colName + "&nbsp;&nbsp;&nbsp;</nobr>" ;
    c . align = "center" ;
    c . bgColor = "#9CBEDE" ;
  }
  if ( valueID != 0 )
  {
    var o = new TScolumn ( valueID , colName ) ;
    columns.push(o);
  }
}

function TS_AddFinalColumn(doc)
{
  t = doc.getElementById("TStable");
  if ( t.rows.length == 0 )
    r = t.insertRow( t.rows.length ) ;
  else
    r = t.rows[ t.rows.length - 1 ] ;
  c = r.insertCell( -1 ) ;
  if ( isInQuestionFrame ( doc ) )
    c . bgColor = "#9CBEDE" ;
  c . innerHTML = TS_GetImage("tiny.gif") ;
  c . width = "100%" ;
}

function TS_AddRow(rowText,rowName,objID,aType)
{
  // aType :: 1 = step , 2 = report , 3 = question , 4 = value , 5 = outcome(leaf) , 6 = solutions , 7 = task
  var r = new TableRow ( rowText, rowName , objID , aIndent , aType ) ;
  tabRows . push ( r ) ;
}

function TS_BuildStep ( aIndex )
{
  var c , cc , gotoNum ;
  var aLevel = tabRows[aIndex].aIndent ;
  var s = "" ;
  if ( aLevel > 0 )
    s += Text_StepBreak + "\n" ;
  s += Text_Step + " " + tabRows[aIndex].aStep + "\n" ;
  for ( c = aIndex ; c < tabRows.length ; c++ )
  {
    if ( tabRows[c].aIndent == aLevel )
    {
      if ( tabRows[c].aType == 1 )
        s += tabRows[c].aSimpleName + "\n" ; // step
      else if ( tabRows[c].aType == 3 )
      {
        s += tabRows[c].aSimpleName + "\n" ; // question
	for ( cc = c + 1 ; cc <	tabRows.length ; cc++ )
	{
	  if ( tabRows[cc].aIndent == aLevel+1 )
	  {
	    gotoNum = 0 ;
	    if ( cc < tabRows.length - 1 )
	      if ( tabRows[cc+1].aIndent == aLevel+2 )
	        gotoNum = tabRows[cc].aStep ;
	    // value
            s += Text_ValueIndent + tabRows[cc].aSimpleName + " " + Text_ValueDelim + " " ;
	    if ( gotoNum != 0 )
              s += Text_Goto + " " + Text_Step + " " + gotoNum ; 
	    else
              s += tabRows[cc+1].aSimpleName ; 
	    s += "\n" ;
	  }
	  else if ( tabRows[cc].aIndent <= aLevel )
	    cc = tabRows.length ;
	}
      }
    } 
    else if ( tabRows[c].aIndent < aLevel )
      c = tabRows.length ;
  }
  // Next Steps
  for ( c = aIndex ; c < tabRows.length ; c++ )
  {
    if ( ( tabRows[c].aIndent == aLevel ) && ( tabRows[c].aType == 3 ) )
    {
      for ( cc = c + 1 ; cc < tabRows.length ; cc++ )
      {
        if ( tabRows[cc].aIndent == aLevel+1 )
	{
          if ( cc < tabRows.length - 1 )
            if ( tabRows[cc+1].aIndent == aLevel+2 )
	      if ( tabRows[cc].aStep != 0 )
                s += TS_BuildStep ( cc + 1 ) ;
        }
        else if ( tabRows[cc].aIndent <= aLevel )
          cc = tabRows.length ;
      }
    }
    else if ( tabRows[c].aIndent < aLevel )
      c = tabRows.length ;
  }
  // Done
  return ( s ) ;
}

function TS_AsText()
{
  var s = 1 ;
  for ( c = 0 ; c < tabRows.length ; c++ )
  {
    if ( tabRows[c].aType == 4 )
    {
      var isValid = false ;
      if ( c < tabRows.length - 2 )
        if ( tabRows[c+1].aIndent = tabRows[c].aIndent + 1 )
	  if ( tabRows[c+2].aIndent >= tabRows[c+1].aIndent )
	    isValid = true ;
      if ( isValid )
      {
        s++ ;
        tabRows[c].aStep = s ;
      }
      else
        tabRows[c].aStep = 0 ;
    }
    else
      tabRows[c].aStep = s ;
  }
  return ( TS_BuildStep ( 0 ) ) ;
}

function TS_Populate(doc)
{
  var c , cc , ok ;
  var t = doc.getElementById("TStable");
  var nCols = t.rows[0].cells.length ;

  TS_AddFinalColumn(doc);

  for ( cc = 0 ; cc < tabRows . length ; cc++ )
  {
    var r = t . insertRow( t.rows.length ) ;
    if ( tabRows [ cc ] . aID != 0 )
      clr = "#E0E0E0" ;
    else
      clr = "#FFFFFF" ;
    for ( i = 0 ; i < nCols ; i++ )
    {
      c = r . insertCell( -1 ) ;
      c . bgColor = clr ;
      if ( i == 0 )
      {
        c . innerHTML = "<nobr>" + TS_GetIndent(cc) + tabRows [ cc ] . aName + "</nobr>" ;
        if ( tabRows [ cc ] . aType != 1 )
        {
          i = nCols ;
          c . colSpan = nCols+1 ;
        }
      }
      else
      {
        if ( tabRows [ cc ] . aType == 1 )
        {
          s = "<input type='radio' id='rd_" + tabRows[cc].aID + "_" + columns[i-1].aID + "' name='obj_" + tabRows[cc].aID + "' value='val_" + columns[i-1].aID + "' " ;
          if ( i == columns.length )         //Change to make default
            s += "checked " ;
          s += "/>" ;
          c . innerHTML = s ;
          c . align = "center" ;
        }
        else
          c . innerHTML = "&nbsp;" ;
      }
    }
    if ( tabRows [ cc ] . aType == 1 )
    {
      c = r . insertCell( -1 ) ;
      c . bgColor = clr ;
      c . innerHTML = "&nbsp;" ;
    }
  }
}

function Nav_Populate(doc)
{
  var i = GetReplayIndexByID ( oID ) ;
  if ( i >= 0 )
    NavigationJump ( replay[i].currentValue ) ;
  else
  {
    var c , cc ;
    var t = doc.getElementById("TStable");

    for ( cc = 0 ; cc < tabRows . length ; cc++ )
    {
      var r = t . insertRow( t.rows.length ) ;
      if ( tabRows [ cc ] . aID != 0 )
        clr = "#E0E0E0" ;
      else
        clr = "#FFFFFF" ;
      c = r . insertCell( -1 ) ;
      c . bgColor = clr ;
      c . innerHTML = "<nobr>" + TS_GetIndent(cc) + tabRows [ cc ] . aName + "</nobr>" ;
    }
  }
}

function TS_AddStep ( aText , aURL , objectID )
{
  s = TS_GetImage("ts_step.gif") ;
  if ( aURL != "" )
    s += '<a href="javascript:parent.Spawn(\'' + aURL + '\',0,0);">' ;
  s += aText ;
  if ( aURL != "" )
    s += "</a>" ;
  TS_AddRow(s,aText,objectID,1) ;
  var f = false ;
  var c ;
  for ( c = 0 ; c < rows . length ; c++ )
    if ( rows [ c ] == objectID )
      f = true ;
  if ( ! f )
    rows . push ( objectID ) ;
}

function TS_AddRep ( aText , questionID , aBody, doc ) // Report on a troubleshoot tree
{
  nReps++ ;
  s = TS_GetImage("ts_rep.gif") ;

  if ( ( doc != null ) && ( !isInQuestionFrame( doc ) ) ) 
    s += aText ;
  else
  {
  //  s += "<a class='rqa' href='javascript:parent.QuestionJump(" + questionID + ");'>" ;
    s += "<a class='rqa' href='javascript:parent.ShowDiv(\"rep" + nReps + "\");'>" ;
    s += aText ;
    s += "</a>" ;
    s += "<div id='rep" + nReps + "' style='display:none;width:100%;' class='TSreportPopup'>" + aBody + "</div>" ;
  }
  TS_AddRow(s,aText,0,2) ;
}

function TS_AddNRep ( aText , questionID , aBody ) // Report on a navigation tree
{
  nReps++ ;
  s = TS_GetImage("ts_rep.gif") ;
//  s += "<a class='rqa' href='javascript:parent.NavigationJump(" + questionID + ",\"" + aText + "\");' title='" + aBody + "'>" ;
//  s += "<a class='rqa' href='javascript:parent.QuestionJump2(" + questionID + ");'>" ;
  s += "<a class='rqa' href='javascript:parent.ShowDiv(\"rep" + nReps + "\");'>" ;
  s += aText ;
  s += "</a>" ;
  s += "<div id='rep" + nReps + "' style='display:none;width:100%;' class='TSreportPopup'>" + aBody + "</div>" ;
  TS_AddRow(s,aText,0,2) ;
}

function TS_AddSols ( aText , questionID, doc ) // Solution leaf on a navigation tree
{
  s = TS_GetImage("ts_sols.gif") ;
  if ( ( doc != null ) && ( !isInQuestionFrame( doc ) ) ) 
    s += aText ;
  else
  {
    s += "<a class='rqa' href='javascript:parent.NavigationJump(" + questionID + ",\"" + aText + "\");'>" ;
  //  s += "<a class='rqa' href='javascript:parent.QuestionJump2(" + questionID + ");'>" ;
    s += aText ;
    s += "</a>" ;
  }
  TS_AddRow(s,aText,0,6) ;
}

function TS_AddSol ( aText , attachment , nextID, doc ) // Solution leaf on a navigation tree
{
  s = TS_GetImage("ts_sols.gif") ;
  if ( ( doc != null ) && ( !isInQuestionFrame( doc ) ) ) 
    s += aText ;
  else
  {
    if ( attachment . length > 0 )
      s += "<a class='rqa' href='javascript:parent.ShowAttachment(\"" + attachment + "\");'>" ;
    else if ( nextID != 0 )
      s += "<a class='rqa' href='javascript:parent.NavigationJump(" + nextID + ",\"" + aText + "\");'>" ;
    s += aText ;
    if ( ( attachment . length > 0 ) || ( nextID != 0 ) )
      s += "</a>" ;
  }
  TS_AddRow(s,aText,0,6) ;
}

function TS_AddTask ( aText , questionID, doc ) // Fwd chain task on a navigation tree
{
  s = TS_GetImage("ts_task.gif") ;
  if ( ( doc != null ) && ( !isInQuestionFrame( doc ) ) ) 
    s += aText ;
  else
  {
    s += "<a class='rqa' href='javascript:parent.NavigationJump(" + questionID + ",\"" + aText + "\");'>" ;
    s += aText ;
    s += "</a>" ;
  }
  TS_AddRow(s,aText,0,7) ;
}

function TS_AddOutcome ( aText , valueID ) // Outcome on a troubleshoot tree
{
  s = TS_GetImage("ts_out.gif") ;
  s += aText ;
  TS_AddRow(s,aText,0,5) ;
}

function TS_AddNOutcome ( aText , valueID ) // Outcome on a navigation tree
{
  s = TS_GetImage("ts_out.gif") ;
  s += aText ;
  TS_AddRow(s,aText,0,5) ;
}

function TS_AddQues ( aText , aQuestion, doc )
{
  if ( ( aQuestion != 0 ) && ( aQuestion != null ) )
  {
    TS_AddTask ( aText , aQuestion, doc ) ;
    TS_Indent() ;
  }
  else
  {
    var s = TS_GetImage("ts_question.gif") ;
    aAttachment = "" ;
    if ( aAttachment . length > 0 )
    {
      if ( ( doc != null ) && ( !isInQuestionFrame( doc ) ) )
        s += "<b>"+aText+"</b>" ;
      else
        s += "<a class='rqa' href='javascript:parent.ShowAttachment(\"" + aAttachment + "\");'>" + aText + "</a>" ;
    } else
      s += "<b>"+aText+"</b>" ;
    TS_AddRow(s,aText,0,3) ;
    TS_Indent() ;
  }
}

function TS_AddAns ( aText )
{
  // This needs to deal with multi-value splits
  if ( tabRows . length > 0 )
    if ( tabRows [ tabRows . length - 1 ] . aType == 4 )
    {
      tabRows [ tabRows . length - 1 ] . aName += " <b>or</b> " + aText ;
      return ;
    }
  TS_AddRow(TS_GetImage("ts_value.gif")+aText,aText,0,4) ;
  TS_Indent() ;
}

function TS_SelRule ( aRule , doc )
{
  var s , ep , found , i , cc , valArr , ruleArr ;
  ruleArr = aRule.split("|") ;
  for ( i = 0 ; i < ruleArr . length ; i++ )
  {
    s = ruleArr [ i ] ;
    ep = s . indexOf ( "=" ) ;
    if ( ep != -1 )
    {
      objectID = s.substring( 0 , ep ) ;
      vID = TS_GetValueID ( objectID , doc ) ;
      if ( vID != 0 )
      {
        s = s.substring ( ep + 1 , s . length ) ;
        valArr = s.split(",") ;
        found = false ;
        for ( cc = 0 ; cc < valArr . length ; cc++ )
          if ( valArr [ cc ] == vID )
            found = true ;
        if ( ! found )
          return ( false ) ;
      }
    }
  }
  return ( true ) ;
}

function TS_EndString(TSname,TSid,doc)
{
  var c , i , s , rd ;
  var added = false ;
  for ( c = 0 ; c < tabRows . length ; c++ )
  {
    for ( i = 0 ; i < columns . length ; i++ )
    {
      s = "rd_" + tabRows[c].aID + "_" + columns[i].aID ;
      rd = doc.getElementById ( s ) ;
      if ( rd != null )
        if ( rd . checked )
	{
	  AddTSanswer ( qID , tabRows[c].aID , tabRows[c].aSimpleName , tabRows[c].aSimpleName , columns[i].aID , columns[i].aName ) ;
	  added = true ;
	}
    }
  }
  if ( added )
    AddDummyAnswer ( )
  QuestionJump ( -1 ) ;
}

function TS_Start(questionID,objectID,questionName,questionText)
{
  nReps = 0 ;
  qID = questionID ;
  oID = objectID ;
  qName = questionName ;
  qText = questionText ;
  columns . length = 0;
  rows . length = 0 ;
  tabRows . length = 0 ;
  TS_SetWorkingTable("TStable");
  TS_ClearIndent();
}

function TS_Begin(doc)
{
  TS_AddColumn(Text_Steps,0,doc);
}

function Nav_Start(questionID,objectID,questionName,questionText)
{
  nReps = 0 ;
  qID = questionID ;
  oID = objectID ;
  qName = questionName ;
  qText = questionText ;
  columns . length = 0;
  rows . length = 0 ;
  tabRows . length = 0 ;
  TS_SetWorkingTable("TStable");
  TS_ClearIndent();
}

-->



