function ValidatorProvider( func ) 
{
    this.validator_function = func;
}

ValidatorProvider.prototype.requestValidation = function (oAutoValidation) 
{
    // validator must return [bool, info]
    res = this.validator_function( oAutoValidation.textbox.value );
    oAutoValidation.warnbox.style.color = res[0] ? 'green' : 'red';     
    oAutoValidation.warnbox.innerHTML = res[1];
};

function AutoValidation(oTextbox, oWarnbox, oValidator) 
{
    // Highlight cell
    this.validator = oValidator;
    this.textbox = oTextbox;
    this.warnbox = oWarnbox;
    this.timeoutId = null;
    this.init();
}
AutoValidation.prototype.init = function () 
{
    var oThis = this;
    this.textbox.onkeyup = function (oEvent) 
    {
        if (!oEvent)
            oEvent = window.event;
        oThis.handleKeyUp(oEvent);
    };
};
AutoValidation.prototype.handleKeyUp = function (oEvent) 
{
    var iKeyCode = oEvent.keyCode;
    var oThis = this;
    
    clearTimeout(this.timeoutId);

    if (iKeyCode == 8 || iKeyCode == 46) 
        this.timeoutId = setTimeout(function(){oThis.validator.requestValidation(oThis);}, 250);
    else if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode <= 46) || (iKeyCode >= 112 && iKeyCode <= 123)) 
    {
        //ignore
    }
    else 
        this.timeoutId = setTimeout(function(){oThis.validator.requestValidation(oThis);}, 250);
};