﻿// JScript File
function nbincrement(txtctrl)
{   
    var ctrl = document.getElementById(txtctrl);
    var value =nbparseValue(ctrl);
    value = value + 1;
    if(value>ctrl.max)
        value=ctrl.max;
   
    if(value!=0) 
        ctrl.value = value;
    else
        ctrl.value='0';
    ctrl.select();
    
    if(ctrl.onchange)
        ctrl.onchange()
}

function nbparseValue(ctrl)
{
    if(ctrl.value!='') 
        return parseInt(ctrl.value);
    else
        return 0; 
} 

function nbdecrement(txtctrl)
{  

   var ctrl = document.getElementById(txtctrl);
    var value =nbparseValue(ctrl);
    value = value - 1;
    if(value<ctrl.min)
        value=ctrl.min;
    
    if(value!=0) 
        ctrl.value = value;
    else
        ctrl.value='0';
    ctrl.select();

    if(ctrl.onchange)
        ctrl.onchange()
}

function nbwriteFocus(txtctrl,lastvalctrl)
{

   document.getElementById(lastvalctrl).value=document.getElementById(txtctrl).value;                      
}
                
 function nbcheckValue(txtctrl,lastvalctrl)
{
    var ctrl = document.getElementById(txtctrl);
    
        if(ctrl.value=='')
            return;
        
        if(isNaN(ctrl.value))
        {
            //revert old value
            ctrl.value=document.getElementById(lastvalctrl).value
        }
        else
        {
            currentValue=Math.abs(nbparseValue(ctrl));
            if(currentValue>ctrl.max)
                ctrl.value=ctrl.max;
            else if(currentValue < ctrl.min)
                ctrl.value=ctrl.min;
            else
                ctrl.value=currentValue;
        }
} 