﻿function timeSpinnerOnKeyPress(e, min, max, lTwoNumbers) {
    var keynum = 0;
    if (window.event) // IE
    { keynum = e.keyCode }
    else if (e.which) // Netscape/Firefox/Opera
    { keynum = e.which }

    if (e.keyCode == 38) {
        //window.alert('up');
        increaseNumber(e.target.id, max, lTwoNumbers);
    }
    if (e.keyCode == 40) {
        //window.alert('down');
        decreaseNumber(e.target.id, min, lTwoNumbers);
    }

    if (e.keyCode == 9 || e.keyCode == 8 || e.keyCode == 46
    || e.keyCode == 13 || e.keyCode == 37 || e.keyCode == 39) { // tab, backspace, delete , enter, lftarr, rgharrw
        return true;
    }


    if (keynum < 48 || keynum > 57) {return false; }
}

function increaseNumber(textboxID, maxValue, lTwoNumbers) {
    var control = document.getElementById(textboxID);
    control.value++;
    if (control.value > maxValue) { control.value = maxValue; }
    if (lTwoNumbers) {
        control.value = formatTwoNumbers(control.value);
    }
}
function decreaseNumber(textboxID, minValue, lTwoNumbers) {
    var control = document.getElementById(textboxID);
    control.value--;
    if (control.value < minValue) { control.value = minValue; }
    if (lTwoNumbers) {
        control.value = formatTwoNumbers(control.value);
    }
}

function timeSpinnerOnBlur(control, min, max, lTwoNumbers) {
    if (isNaN(control.value)) { control.value = min; }
    if (control.value.length == 0) { control.value = min; }
    if (control.value > max) { control.value = max; }
    if (control.value < min) { control.value = min; }

    /*if (lTwoNumbers) {
    control.value = formatTwoNumbers(control.value);
    alert(control.value);
    }*/
}
/*
function formatTwoNumbers(cText) {
alert(2);
if (cText.length == 1) {
alert(3);
return "0" + cText;
}
alert(4);
return cText;
}*/

