//
//                                timer
//
//    This provides a method for supporting the timer concept.
//
//    This provides a method for creating up to 5 timers that may be 
//    used in applications.
//
//    When used, 
//        1) a "Timer" must be defined with a timeout delay and the
//           action to be performed on completion of the timeout.
//        2) the "Timer" must be started after definition.
//
//
    timerId = 0 ;
    timer   = new Array(5) ;

    //
    //                      Timer
    //    
    //    This provides a method for defining a timer
    //
    //    Specify timeout and action to take on expiration of timeout.
    //
    

    
    function Timer(timeout, action) {

        timer[timerId] = this      ;       
        this.timerId   = timerId++ ;
        this.strttime = 0          ;
        this.TIMEOUT  = timeout    ;
        this.ACTION   = action     ; 

        this.Start    = Start      ;
    }

    //
    //                      Start
    //
    //   This routine starts the timer.
    //
    function Start() {

        var tmeout ;

        this.strttime = timeGet() ;

        tmeout=window.setTimeout("timeoutCheck(" + this.timerId + ")",1000);       
    }


    //
    // timeGet
    //
    // This provides a method for getting a comparison time.
    //
    //
    function timeGet(){
        var time= new Date();
        hrs= time.getHours();
        mns= time.getMinutes();
        scs= time.getSeconds();
        
        return (hrs*3600+mns*60+scs) ;
    }
    
    //
    //    timeoutCheck()
    // 
    //    This routine provides a method for checking for the timeout
    //    condition.
    //
    //    This routine checks to see if time since we started checking 
    //    has exceeded the timeout.   If so, this routine aborts, otherwise
    //    this routine reschedules for the next check.
    //
    function timeoutCheck(Id){
        var count ;
        var obj = timer[Id] ;
        nowtime = timeGet() ;
        count = nowtime - obj.strttime ;
        if (count > obj.TIMEOUT) {
            obj.ACTION() ;
            
        } else {
            tmeout = window.setTimeout("timeoutCheck(" + Id + ");",1000);
        }    
    }
   
