var StartPicker;
var StartEngine;
var _img = null;
var Started = 0;


Number.prototype.zeroFormat = function(n, f, r){
    return n = new Array((++n, f ? (f = (this + "").length) < n ? n - f : 0 : n)).join(0), r ? this + n : n + this;
};

function Stop(img, value)
{	    
    try{
        if(value == 1)
            img.src='./img/btnUp.gif';
	    else
    	    img.src='./img/btnDown.gif';
        	 
	    clearInterval(StartPicker);
	    _img = null;
	    Started = 0;
	} catch (e) {}  
}

function UpHour(Img, Name, Max, Min)
{
    try{
        if(_img != null) _img.src='./img/btnUpPress.gif';
        
        Value = document.getElementById(Name).value;
    	
        if(Value == Max)
	        Value = Min;
        else
	        Value ++;
    		
        document.getElementById(Name).value = Value.zeroFormat(2, true);
    } catch (e) {}  
}

function DownHour(Img, Name, Max, Min)
{	
    try{
        if(_img != null) _img.src='./img/btnDownPress.gif';
    
        Value = document.getElementById(Name).value;
    		
        if(Value == Min)
	        Value = Max;
        else
	        Value --;
		
        document.getElementById(Name).value = Value.zeroFormat(2, true);
     } catch (e) {}  
}

function StartPickerEngine(value, Name, Max, Min)
{
    try {
        if(Started == 1)
        {        
            if(value == 1)
		        StartPicker = setInterval("UpHour(null, '" + Name + "', " + Max + "," + Min + ")",90);
	        else
		        StartPicker = setInterval("DownHour(null, '" + Name + "', " + Max + "," + Min + ")", 90);	    
        }    
        clearInterval(StartEngine);
     } catch (e) {}
}

function Start(img, value, Name, Max, Min)
{	
    try {
        if(Started == 0)
        {
            
           if(value == 1)
                img.src='./img/btnUpPress.gif';
            else
	            img.src='./img/btnDownPress.gif';
    	        
	        Started = 1;
            _img = img;
            clearInterval(StartEngine);
		    StartEngine = setInterval("StartPickerEngine(" + value + ", '" + Name + "', " + Max + "," + Min + ")", 200);    
        }
    } catch (e) {}
}

function ValidateNumeric() {
    var keyCode = window.event.keyCode;
    if (keyCode > 57 || keyCode < 48)
        window.event.returnValue = false;
}

function ValidateMaximum(Max, obj) {
    try {
        if (eval(obj.value) > Max) obj.value = Max;
        obj.value = eval(obj.value).zeroFormat(2, true);
    } catch (e) { obj.value = '' }
    return;
}
