    function wnopen(wnm, pgname){
        var scrh=(.8*screen.availHeight);
        var scrw=(.8*screen.availWidth);
        if (wnm=="n") {
            nwwin = window.open(pgname, "_blank", "width=" + scrw + ",height=" + scrh + ",status=yes,resizable=yes"); 
            nwwin.focus();
        }
        else {
            parent.location = pgname 
        }
    }
    
    function the_maxscore(game) {

        if (game == 1) {
	    if ( document.play.maxscore1.value < correct ) {
                alert(congradulations[game]) ;
		document.play.maxscore1.value = correct ;
            }
	} else if ( game == 2) {
	    if ( document.play.maxscore2.value < correct ) {
                alert(congradulations[game]) ;
                document.play.maxscore2.value = correct ;
            }
        } else if ( game == 3) {
            if (document.play.maxscore3.value > (count - 1)) {
                alert(congradulations[game]) ;
	        document.play.maxscore3.value = count ;
            }
        }

    }
 
    //
    //                      strtTimer
    //
    //   This routine stores the strt time in a variable called 
    //   strttime.
    //
    function strtTimer(){
        var time = new Date();
        hrs= time.getHours();
        mns= time.getMinutes();
        scs= time.getSeconds();
        strttime=hrs*3600+mns*60+scs;  
        clock();
    }

    function clock_decrement() {
        dir = "down" ;
    }

    function clock_increment() {
        dir = "up" ;
    }

    function clock_stop() {
        dir = "__" ;
    }

    //                     clock
    //
    //    This routine gets the current time on the clock.   The results
    //    are called nowtime.
    //
    function clock(){
        var time= new Date();
        hrs= time.getHours();
        mns= time.getMinutes();
        scs= time.getSeconds();
        nowtime=hrs*3600+mns*60+scs;
        totaltime();
    }
    
    //
    //                              totaltime
    //
    //    This routine provides a method for determining the time between
    //    the strttime and nowtime.
    //
    function totaltime() {
        
        if (dir == "__") {

        } else if (dir=="up") {
                
            count = nowtime - strttime;            // determine the time between strt and now
            if ((correct-wrong) > dlimit) {
                alert("You completed " + tlimit + " questions in " + count + " seconds");
                dlimit=1000;
                window.clearTimeout(tmeout);       // 
                the_maxscore(game);                //
                wnopen('s','#section3');
                game=0;                            
                document.tmr.cntr.value = 0 ;
            } else if (count < 0) {
                count = 0 ;
                document.tmr.cntr.value = 1000 ;
            }
        }
        else { 
        
            count = (timestrt + strttime - nowtime) // We are counting down, to determine when
                                                  // we are 60 seconds passed strt time.
            if (count < 1){                       // If we are 60 seconds passed strt time,
                                                  //    and we have not yet reported,
                if (report_done == 0) {
                                                  //    we will report on the score, reset timeout, 
                                                  //       update the score,
                    alert("your score is " + (correct - wrong))    
                    report_done = 1    ;
                    window.clearTimeout(tmeout);
                    the_maxscore(game)    ;
                    wnopen('s','#section3');      //    and reset the strt time.
                    game    = 0    ;
                    dir    = "__" ;
                    document.tmr.cntr.value = 0 ;
                }
            }
        }
        if (count > 3600){
            hour = parseInt(count/3600)
        } else {
            hour = 0
        };
        if (count > 60) {
            minutes = parseInt(count/60)
        } else {
            minutes = 0
        };
        if (minutes < 10) { 
            minutes = "0" + minutes
        };
        sec = parseInt(count - minutes*60);
        if (sec < 10) {
            sec = "0" + sec
        };
        document.tmr.cntr.value = minutes + ":" + sec;
        tmeout=window.setTimeout("clock()",1000);

    }
    
    //
    //                             strt
    //
    //    This provides a method for strting the problem
    //    quiz.   Starting involves:
    //    1) Initializing the random array
    //    2) Initializing to the first array element.
    //    3) clearing of the result, answer, and pctright
    //    4) Start the timer.
    //    5) Display the first problem.
    //
    function strt() {
    
        wnopen('s','#section2');            // Jump to section 2.
        clock_increment()  ;                    
        init(0)      ;
        dlimit  = 10000    ;                // We will do 20 problems.
        tlimit  = 20       ;
        document.math.dcomment.value = "GO ..."
        run()              ;                // Run the body.
    }

    
    function countdown(){
        
        wnopen('s','#section2');            // Jump to section 2.
        clock_decrement() ;
        init(1)           ;
    
        timestrt = 60     ; 
        document.math.dcomment.value = "GO ..."
        run()             ;                 // Run the body.
    }
    
    //
    //                                    givemetime
    //
    //    This routine initializes for the running of the givemetime game.
    //
    function givemetime(){

        wnopen('s','#section2');                // Jump to section 2.
        clock_decrement()  ;
	     init(2)            ;
        timestrt = 60      ; 
    
        strtTimer()        ;                // Start the timer.
        document.math.dcomment.value = "GO ..."
        run()              ;                // Run the body.
    }
    
    //
    //                                   twentyquestions
    //
    //    This routine initializes for the running of the twenty question game.
    //
    function twentyquestions() {

        wnopen('s','#section2');             // Jump to section 2.
        clock_increment()   ;
        init(3)             ;
        dlimit  = 19        ;                // We will do 20 problems.
        tlimit  = 20        ;

        strtTimer()         ;                // Start the timer.
        document.math.dcomment.value = "GO ..."
        run()               ;                // Run the body.
    }

