<!--
// QAreport display

var tableName = "" ;

function QA_SetWorkingTable(aName)
{
  tableName = aName ;
}

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

function QA_ClearIndent()
{
  aIndent = 0 ;
}

function QA_Indent()
{
  aIndent += 2 ;
}

function QA_Deindent()
{
  if ( aIndent > 0 )
    aIndent -= 2 ;
}

function QA_BuildIndent()
{
  var c
  var s = "" ;
  for ( c = 0 ; c < aIndent ; c++ )
    s += "&nbsp;&nbsp;" ;
  return( s ) ;
}

function QuestionStep ( id , text )
{
  this . aID = id ;
  this . aText = text ;
}

function QuestionSingleValue ( id , text )
{
  this . aID = id ;
  this . aText = text ;
}

function QuestionValue ( ids , mode , iParam , sParam )
{
  this . values = new Array ( ) ;
  var v = ids.split("|");
  var c = 0 ;
  while ( c < v.length )
  {
    var aID = v [ c ] ;
    c++ ;
    if ( c < v.length )
    {
      var aName = v [ c ] ;
      c++ ;
      var vid = new QuestionSingleValue ( aID , aName ) ;
      this . values . push ( vid ) ;
    }
  }
  this . aMode = mode ;   // 1 = jump , 2 = outcome
  this . iParam = iParam ;
  this . sParam = sParam ;
}

function QuestionEntry ( number , id , text )
{
  this . aNumber = number ;
  this . aID = id ;
  this . aText = text ;
  this . steps = new Array ( ) ;
  this . values = new Array ( ) ;
}

var questionEntries = new Array() ;
var aQuestion = null ;

function QA_Start(questionID,objectID,questionName,questionText)
{
  questionEntries . length = 0 ;
  QA_SetWorkingTable("QAtable");
}

function QA_AddQuestion_Start ( questionNo , attributeID , attributeText )
{
  aQuestion = new QuestionEntry ( questionNo , attributeID , attributeText ) ;
}

function QA_AddStep ( attributeID , attributeText )
{
  if ( aQuestion == null )
    return ( false ) ;
  var s = new QuestionStep ( attributeID , attributeText ) ;
  aQuestion.steps.push(s);
}

function QA_AddGoto ( values , jumpNo )
{
  if ( aQuestion == null )
    return ( false ) ;
  var v = new QuestionValue ( values , 1 , jumpNo , "" ) ;
  aQuestion.values.push(v);
}

function QA_AddOutcome ( values , outcomeID , outcomeText )
{
  if ( aQuestion == null )
    return ( false ) ;
  var v = new QuestionValue ( values , 2 , outcomeID , outcomeText ) ;
  aQuestion.values.push(v);
}

function QA_AddQuestion_End ( )
{
  if ( aQuestion != null )
    questionEntries . push ( aQuestion ) ;
}

function QA_Populate_Text()
{
  var s = "" ;
  var c , cc , ccc , ss ;
  for ( c = 0 ; c < questionEntries . length ; c++ )
  {
    s += "========== Question #" + questionEntries[c].aNumber + " ==========\n" ;
    for ( cc = 0 ; cc < questionEntries[c].steps.length ; cc++ )
    {
      s += questionEntries[c].steps[cc].aText + "\n" ;
    }
    if ( questionEntries[c].aID != 0 )
      s += questionEntries[c].aText + "\n" ;
    for ( cc = 0 ; cc < questionEntries[c].values.length ; cc++ )
    {
      ss = "" ;
      if ( questionEntries[c].values[cc].values.length > 0 )
      {
	for ( ccc = 0 ; ccc < questionEntries[c].values[cc].values.length ; ccc++ )
	{
	  if ( ss.length > 0 )
	    ss += " or " ;
          ss += questionEntries[c].values[cc].values[ccc].aText ;
	}
	ss += " : " ;
      }
      s += "      " + ss ;
      if ( questionEntries[c].values[cc].aMode == 1 )
	s += "Jump to question #" + questionEntries[c].values[cc].iParam + "\n" ;
      else if ( questionEntries[c].values[cc].aMode == 2 )
      {
        if ( questionEntries[c].values[cc].sParam.length == 0 )
          s += "Finished\n" ;
        else
          s += questionEntries[c].values[cc].sParam + "\n" ;
      }
    }
  }
  return ( s ) ;
}

function QA_Populate(doc)
{
  if ( ! isInQuestionFrame ( doc ) )
  {
    PopulateCopyHTML( QA_Populate_Text(), Text_QA ) ;
    return ;
  }

  var s = "" ;
  var c , cc , ccc , ccc, ss ;
  var isStep

  var t = window.questionFrame.document.getElementById(tableName);

  for ( cc = 0 ; cc < questionEntries . length ; cc++ )
  {
    QA_ClearIndent() ;
    isStep = ( questionEntries[cc].aID == 0 ) ;
    // main question name and operation number
    s = "" ;
    var r = t . insertRow( t.rows.length ) ;

    clr = "#FFFFFF" ;

    r . className = "greyHead" ;
    c = r . insertCell( -1 ) ;
    c . bgColor = clr ;
    s += "<a class='qarep' name='" + questionEntries [ cc ] . aNumber + "'>Question #" + questionEntries [ cc ] . aNumber + "</a><br>" ;
    c . innerHTML = "<nobr>" + s + "</nobr>" ;

    if ( questionEntries [ cc ] . aID != 0 )
    {
      s = "" ;
      var r = t . insertRow( t.rows.length ) ;
      c = r . insertCell( -1 ) ;
      c . bgColor = clr ;
        s += QA_GetImage("ts_question.gif") + questionEntries [ cc ] . aText + "<br />" ;
      c . innerHTML = "<nobr>" + s + "</nobr>" ;
    }

    // now do the steps
    s = "" ;
    var r = t . insertRow( t.rows.length ) ;
    c = r . insertCell( -1 ) ;
    c . bgColor = clr ;
    for ( ccc = 0 ; ccc < questionEntries[cc].steps.length ; ccc++ )
    {
      if ( !isStep )
        QA_Indent() ;
      s += QA_BuildIndent() + QA_GetImage("ts_step.gif") + questionEntries[ cc ] . steps[ ccc ] . aText + "<br />" ;
      if ( !isStep )
        QA_Deindent() ;
    }
    c . innerHTML = "<nobr>" + s + "</nobr>" ;

    if (( questionEntries[cc].steps.length > 0 ) && (!isStep ))
      QA_Indent() ;

    //now for the values
    for ( ccc = 0 ; ccc < questionEntries[ cc ] . values . length ; ccc++  )
    {
      s = "" ;
      if ( !isStep )
      {
        QA_Indent() ;
        var r = t . insertRow( t.rows.length ) ;
        c = r . insertCell( -1 ) ;
        c . bgColor = clr ;

        ss = "" ;
        if ( questionEntries[cc].values[ccc].values.length > 0 )
        {
          for ( cccc = 0 ; cccc < questionEntries[cc].values[ccc].values.length ; cccc++ )
          {
            if ( ss.length > 0 )
              ss += "<b> or </b>" ;
            ss += questionEntries[cc].values[ccc].values[cccc].aText ;
          }
        }

        s += QA_BuildIndent() + QA_GetImage("ts_value.gif") + ss ;
        c . innerHTML = "<nobr>" + s + "</nobr>" ;
        QA_Deindent() ;
      }
      if ( !isStep )
        QA_Indent() ;
      QA_Indent() ;
      ss = "" ;
      s = "" ;
      var r = t . insertRow( t.rows.length ) ;
      c = r . insertCell( -1 ) ;
      c . bgColor = clr ;

      if ( questionEntries[cc].values[ccc].aMode == 1 )
	s += QA_GetImage("ts_task.gif") + "<a class='rqa' href='#" + questionEntries[cc].values[ccc].iParam + "'>Goto Question #" + questionEntries[cc].values[ccc].iParam + "</a><br />" ;
      else if ( questionEntries[cc].values[ccc].aMode == 2 )
      {
        if ( questionEntries[cc].values[ccc].sParam.length > 0 )
          s += QA_GetImage("ts_task.gif") + questionEntries[cc].values[ccc].sParam + "<br />" ;
        else
          s += QA_GetImage("ts_out.gif") + "Finished<br />" ;
      }
      if ( ccc == questionEntries[ cc ] . values . length - 1)
        s += "<br />" ;
      c . innerHTML = "<nobr>" + QA_BuildIndent() + s + "</nobr>" ;

      if ( !isStep )
        QA_Deindent() ;
      QA_Deindent() ;
    }
    if (( questionEntries[cc].steps.length > 0 ) && (!isStep ))
      QA_Deindent() ;

  }
}
-->

