﻿
/*
    Computer Science Group, LLC
    225-766-2397 office
    225-205-0263 cell
    darrell@computersciencegroup.com
    Copyright © 2008 Computer Science Group, LLC, All rights reserved.
*/

//csgTextBoxInteger(<opCsgTextBoxID>)
//09/06/2008
function csgTextBoxInteger(opCsgTextBoxID)
{
    //cannot continue if textbox is not found.
    if (!document.getElementById(opCsgTextBoxID))
    {
        alert("TextBox " + opCsgTextBoxID + " not found.");
        return;
    }
    /****************************************************************************************
    //Inherits from csgTextBox
    ****************************************************************************************/
    this.parent = new csgTextBox(opCsgTextBoxID);
    var oCsgTextBoxInteger = this;
    /****************************************************************************************
    properties
    ****************************************************************************************/
    /****************************************************************************************
    events
    ****************************************************************************************/
    //onkeypress - replace onkeypress event from csgTextBox
    this.onKeyPress = function()
    {
        if (oCsgTextBoxInteger.parent.isNumericKeyCode(event.keyCode ) == false) { event.keyCode  = null; }
        if (ocsgPage.textBoxOnKeyPress) { ocsgPage.textBoxOnKeyPress(oCsgTextBoxInteger.parent); }
    }
    this.parent.textBox.onkeypress = oCsgTextBoxInteger.onKeyPress;	
    //onblur - replace onblur event from csgTextBox
    this.onBlur = function()
    {
        event.srcElement.className = oCsgTextBoxInteger.parent.cssClassCsgTextBox;
        var oValue = oCsgTextBoxInteger.formatTheNumber(oCsgTextBoxInteger.parent.textBox.value);
        if (oValue)
        {
            if (oCsgTextBoxInteger.parent.isANumber(oValue) == false) { event.srcElement.className = oCsgTextBoxInteger.parent.cssClassCsgTextBoxBadValue; }
        }
        event.srcElement.value = oValue;
        if (ocsgPage.textBoxOnBlur) { ocsgPage.textBoxOnBlur(oCsgTextBoxInteger.parent); }
    }
    this.parent.textBox.onblur = oCsgTextBoxInteger.onBlur;	
    /****************************************************************************************
    methods
    ****************************************************************************************/
    //formatTheNumber(<opValue>)
    //09/07/2008
    this.formatTheNumber = function(opValue)
    {
        var oValue;
        var sValue = "";
        if (opValue)
        {
            oValue = opValue;
            if (oCsgTextBoxInteger.parent.isANumber(oValue) == true)
            {
                sValue = oCsgTextBoxInteger.parent.roundedNumber(oValue, 1).toString();
            }
        }
        return sValue
    }
}