
//
//                   light hearted support
//
//    This file contains general support for a light hearted ... animated query
//    for answers to problems.
//

    //
    //                            check
    //
    //    This provides a method for checking the student response.
    //
    function check(){
        var entered     ;
        var explanation ;
        var expectation ;

        entered     = document.math.Answer.value ;
        expectation = document.math.expectation.value ; 
                                          
	                              // If we have a student response submitted,
        if (clicked==0){
                                      // Determine if the answer equals the
                                      // expected value.
            if ((entered != "") && ((eval(entered) - expectation) == 0)) {
                                      // If we match the expectation, 
                                      //    mark things correct,
                correct++; 
                document.math.correct.value = correct;
                showCheshire() ;      //    show the Cheshire cat.
                
            } else  {
                                      // Otherwise, mark things as wrong.
                if (entered == "") {
                    explanation = "Enter a number before pressing CHECK.  "
                    document.math.dcomment.value = "No value entered ..." ;
                    click = 1                                             ;
                    return ;
                } else  {
                    wrong++; 
                    document.math.dcomment.value = document.math.problem.value + " = " + expectation ;                  
		             explanation = an_explanation() ;
                    showGarfield()                     ;
                    showThought()                      ;
                    explanation_assert(explanation)    ;
                    document.math.wrong.value   = wrong;
		             
                }
		
                clicked                     = 1    ;
            }
                                     // Now determine total results checked
            total = correct + wrong ;
        
                                     // Determine the percent correct
            document.math.percent.value = Math.floor(correct/total*100) ;
                                     //    and go for the next problem.
            iterator();
        }

	autoadvance() ;              // Check for a need to automatically advance to the next level of difficulty.
    }

    function init() {
    
        correct = "" ;
        wrong   = "" ;
        click   = 0  ;

        document.math.Answer.value      = "" ;
        document.math.correct.value     = "" ;
        document.math.wrong.value       = "" ;
        document.math.percent.value     = "" ;
        document.math.expectation.value = "-" ;
        document.math.problem.value     = "" ;
        hidelayer("cheshire")            ;
        hidelayer("garfield")            ;
        hidelayer("thought")             ;
        comment_assert("&nbsp;&nbsp;Help Ernie solve his problem.") ;
        level_init(level1)               ;
        autoadvance_init()               ;
    }

    function comment_assert(txt) {
        if (IE) {
            document.all["comment"].innerHTML = txt ;
        } else if (NS4) {
            document["comment"].document.write(txt);
            document["comment"].document.close();
        }         
    }
    
    function explanation_assert(txt) {
        if (IE) {
            document.all["explanation"].innerHTML = txt ;
        } else if (NS4) {
            document["explanation"].document.write(txt);
            document["explanation"].document.close();
        }       
    
    }
    
    function question(txt) {
    
        if (IE) {
            document.all["question"].innerHTML = txt ;
        } else if (NS4) {
            document["question"].document.write(txt);
            document["question"].document.close();
        }    
    }
    
    function test(x) {
        alert(x) ;
    }
    
    function run() {

        clicked = 1           ;
        iterator()            ;

    }
    
    //
    //                             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
    //    5) Display the first problem.
    //
    function strt() {
        start_level = level6 ;            
        init()               ;
        run()                ;              // Run the body.
    }

