﻿
var spinnerTimeout = null;
var spinnerInterval = null;

document.onmouseup = StopSpinner;

function StartSpinner( boxId, modifier )
{
    var spinCode = "DoSpin( '" + boxId + "', " + modifier + " )";
    eval( spinCode );
    
    var intervalCode = "spinnerInterval = window.setInterval( \"" + spinCode + "\", 50 )";    
    spinnerTimeout = window.setTimeout( intervalCode, 500 );       
}

function DoSpin( boxId, modifier )
{
    var box = document.getElementById( boxId );    
        
    var newValue = parseInt( box.value ) + parseInt( modifier );
    if( newValue < 0 )
        newValue = 0;
        
    box.value = newValue;
}

function StopSpinner()
{
    if( spinnerTimeout != null )
        window.clearTimeout( spinnerTimeout );
    if( spinnerInterval != null )
        window.clearInterval( spinnerInterval );    
}
