/** 
 * This is the FofXInputForm class.  It manages the 
 * input of a FofX, the data involved, and any event(s).
 */
PrtFofXInputForm.prototype = new InputForm();

function PrtFofXInputForm() {
  this.intDegree = 5; // The degree of the equation that is handled by this class.
  // Methods:
  this.priGetEquationHtml = FofXInputForm_priGetEquationHtml;
  this.getData            = FofXInputForm_getData;
  this.priGetEquationData = FofXInputForm_priGetEquationData;
  // We can leave this object construction in the prototype because the values are constant.
  this.arrFofXDefaults = new Array();
  this.arrFofXDefaults[0]  = "2*(Math.sin(x/2))";
  this.arrFofXDefaults[1]  = "Math.sqrt( (Math.abs(Math.pow(x,2)-49)) )";
  this.arrFofXDefaults[2]  = "2*(Math.pow(x,5))";
  this.arrFofXDefaults[3]  = "function(x) {  if ( (Math.pow(x,2)-49) < 0 ) { return ( 0 - Math.sqrt(Math.abs(Math.pow(x,2)-49)) ) ; } else { return Math.sqrt(Math.pow(x,2)-49); } }";
  this.arrFofXDefaults[4]  = "Math.pow(x,3) - (Math.pow(x,2)) - (4*x) + 2";
  this.arrFofXDefaults[5]  = "function(x) { return { \"a\":(Math.sqrt(Math.abs(Math.pow(x,2)-49)) * -1), \"b\":(Math.sqrt(Math.abs(Math.pow(x,2)-49))) }; } ";
  this.arrFofXDefaults[6]  = "function(x) { return { \"a\":(Math.sqrt(Math.abs(1-(Math.pow(x,2)/16))) * -3), \"b\":(Math.sqrt(Math.abs(1-(Math.pow(x,2)/(2+Math.pow(x,2)-x)))) * 3) }; }";
  this.arrFofXDefaults[7]  = "function(x) { return { \"a\":(Math.sqrt(Math.abs(1-(Math.pow(x,2)/19))) * -6), \"b\":(Math.sqrt(Math.abs(1-(Math.pow(x,2)/19))) * 6) }; }";
  this.arrFofXDefaults[8]  = "Math.pow(x,4) - (Math.pow(x,3)) - (5*Math.pow(x,2)) + 3";
  this.arrFofXDefaults[9]  = "Math.pow(x,4) + (4*Math.pow(x,3)) + (8*Math.pow(x,2)) + (16*x) - 12";
  this.arrFofXDefaults[10] = "Math.pow(x,4) + (2*Math.pow(x,3)) - (47*Math.pow(x,2)) - (48*x) + 252";
  this.arrFofXDefaults[11] = "Math.pow(x,4) + (2*Math.pow(x,3)) - (47*Math.pow(x,2)) - (48*x) + 900";
}

// Static values:
FofXInputForm.prototype = new PrtFofXInputForm();
FofXInputForm.intDegree = 5;

function FofXInputForm(intNumDivContainers, hshVisibleXYranges) {
  // Invoke the superclass constructor to complete inheritance.
  if (arguments.length < 2) {
    this.inputForm(intNumDivContainers);
  } else {
    this.inputForm(intNumDivContainers, hshVisibleXYranges); 
  }
}


/** 
 * This method overrides the one from the superclass.  It is 
 * overloaded to support both getting the data for a particular equation to be 
 * graphed and support getting the data that specified the range of the visible
 * graph axes to display. 
 * @param intEquationNumber OPTIONAL  * If this parameter is not passed, getData returns the
 *                                      data specifying the visible range of the graph axes.
 *                                    * This parameter, if passed, specifies which equatioh 
 *                                      to get the data for (for example, in the case of a FofX, it 
 *                                      would return the coefficients in an array).
 * @return objXYRange (if no parameter passed -- see InputForm_priGetVisibleRangeData.
 * @return array      (if intEquationNumber is passed) This contains the coefficient values for the 
 *                    equation in question.
 */
function FofXInputForm_getData(intEquationNumber) {
  if (arguments.length == 0) { // Get the data specifying the range of axes to display.
    return this.priGetVisibleRangeData();
  } else { // Get the equation data.
    return this.priGetEquationData(intEquationNumber);
  }
}

/* - - - - - - - -  Private Methods: */

/**
 * This method overrides the corresponding method in the superclass to 
 * provide the necessary markup with the correct document element i.d. values
 * for the panel on the display that handles the input of the data that 
 * specify the equations.
 * @param intEquationNum  The number that identifies the equation input display to be rendered.
 *                        This number corresponds with a number identifying a graph on the screen.
 * @return strHtml  The string containing the constructed markup.
 */
function FofXInputForm_priGetEquationHtml(intEquationNum) {
  var strHtml = "\n<table><tr>\n";
  strHtml += "\n <td>"
    + "       \n   <input  type='text'  id='" + InputForm.EQUATION + intEquationNum + "' "
    + "                    size='30' maxlength='30000'   "
    + "                    value='" + (this.arrFofXDefaults[intEquationNum]) + "' "
    + "                    class='eqINPUT' >"
    + "       \n </td> ";
  strHtml += "\n </tr></table>";    
  // alert("strHtml: "+strHtml);
  return strHtml;
}


/** 
 * This method overrides that from the superclass.  Its purpose is to 
 * return the data corresponding to the equation specified by 'intEquationNum'.
 * @intEquationNum  An number identifying an equation that corresponds to a graph on
 *                  the screen.
 * @return arrCoefficients  The coefficients, in the order of degree 5 to degree 0, 
 *                          of the equation.
 */
function FofXInputForm_priGetEquationData(intEquationNum) {
  if (intEquationNum < 0 || intEquationNum > this.intNumDivContainers) {
    alert("DevTime Alert @ FofXInputForm_priGetEquationData: intEquationNum is out of bounds.");
  }
    strId = InputForm.DOC_PATH_TO_ENTRY_BOXES + InputForm.EQUATION + intEquationNum;    
    return (GloScope.CrossPlatformCode.getReferenceToDocProperty(window.top.input, strId).value);
}
         /* - - - - - - - - - */







