//IMPORTANT NOTE WHEN EDITING TAX RATE !!!!!!
//When ever the tax value is changed the value that is sent to the tax var should also be changed
//THIS IS VERY IMPORTANT !!!!!!
var tax;
var taxval;
var statement = "";          // Contains the math statement
var displayString;      // Contains the displayed string
var newDisplay = true;  // Flag to used to signal formation of a new number
var hasOperator = false;  // Flag used to update the display for an operator
var temp;
/**********************************************************************
*
* Function     - clr
* Parameters   - 
* Description  - This function clears all the variables and display
* Called by    - onclick event handler
**********************************************************************/
function clr(tax) {
    //clear all variables and display
    displayString = "";
    hasOperator = false;
    statement = "";
    newDisplay = true;
    DisplayString();
    document.javascriptCalculator.calcResult.value = "";
    document.javascriptCalculator.TaxDisplay.value = "";
}

/**********************************************************************
*                                                                     *
*  Function    - Operator                                             *
*  Parameters  - opString                                             *
*  Description - This function handles button presses of the          *
*                +,-,*,/, and = operators.                            *
*  Called By   - onclick event handler                                *
*                                                                     *
**********************************************************************/
function Operator(opString, tax) {

    // If the operator is an equals sign calculate the result,
    // otherwise add the operator to the statement string.

    // temp = eval(statement + displayString + '*' + tax);
    temp = document.javascriptCalculator.TaxDisplay.value.replace(/,/,'') * document.javascriptCalculator.displayResult.value;
    temp = temp * .01;
    displayString = document.javascriptCalculator.displayResult.value;
    document.javascriptCalculator.calcResult.value = temp;
    document.javascriptCalculator.taxval = temp;
    statement = "";
    hasOperator = false;



    // Reset the display when an operator is typed.
    newDisplay = true;

    // Update the display.
    DisplayString();
}

/**********************************************************************
*                                                                     *
*  Function    - Data                                                 *
*  Parameters  - numberString                                         *
*  Description - This function handles number or decimal key press.   *
*  Called By   - onclick event handler                                *
*                                                                     *
**********************************************************************/
function Data(numberString) {

    //  If an operator has previously been pressed start with a
    //  new string, otherwise concatonate the number to the current
    //  display.
    //if (newDisplay == true) {
    //newDisplay = false;
    //displayString = numberString;
    //displayString = document.javascriptCalculator.displayResult.value;
    //} else {
    displayString = document.javascriptCalculator.displayResult.value;
    displayString += numberString;
    //}

    // Update the display.
    DisplayString();
}

/**********************************************************************
*                                                                     *
*  Function    - DisplayString                                        *
*  Parameters  - None                                                 *
*  Description - Prints the displayString global to the display.      *
*  Called By   - Operator and Data functions.                         *
*                                                                     *
**********************************************************************/
function DisplayString() {
    //  Print the new display string
    document.javascriptCalculator.displayResult.value = displayString;
}

/**********************************************************************
*
* Function     - opencalc   
* Parameters   - tax(tax value)
* Description  - This function opens the calculator window
* Called by    - onclick event handler
**********************************************************************/
function opencalc(tax) {
    clr();
    document.javascriptCalculator.TaxDisplay.value = tax;
    document.tax = tax;
    //window.scrollTo(6, 2);
}