/*

ProtoNum, Specialy designed for the CapTech Website shopping system by Andreas Gotfredsen , Holviks Advertise Agency 2008
	
This Class handels numbers only functionality in the text input areas. It also clears the input area on focus.

*/
if (!window.ProtoNum)
    var ProtoNum = new Object();

ProtoNum.Methods = {

    check: function(elem) {
        this.numField = $(elem);
        this.mem = this.numField.value;
        this.numField.value = "";

        //Bind Toogle Reset on keydown
        var bindkey = this.keyer.bindAsEventListener(this);
        Event.observe(this.numField, 'keyup', bindkey);

        //Bind Blur Function for Search Field
        var bindOnBlur = this.blur.bindAsEventListener(this);
        Event.observe(this.numField, 'blur', bindOnBlur);
    },
    rangeValidator: function(value) {
        if (value < 46) {
            return true;
        }
        else if (value > 57) {
            if (value < 96) {
                return true;
            }
            else if (value > 105) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }

    },

    keyer: function(evt) {


        if (evt.keyCode != 8) {

            if (this.rangeValidator(evt.keyCode)) {
                this.numField.value = this.mem;
                // evt.keyCode = 8; // Removed by Martin A, because evt.keyCode is ReadOnly
            }

            if (this.numField.value == "") {
                this.numField.value = this.mem;
            }
        }

        if (this.numField.value != "") {
            this.mem = this.numField.value;
        }


    },

    blur: function() {

        if (this.numField.value == "") {
            this.numField.value = this.mem;
        }
    }



};

Object.extend(ProtoNum, ProtoNum.Methods);