
// Function to change letters that are not part of the correct answer
var wrong=0;
var right=0;
var score=0;

function chlet(rw,layername,imgid,imgsrc) {
	a=layername; b=imgid; c=imgsrc;
	changeimg(a,b,c);
	if (rw=="wr") wrong=wrong+1;
	if (rw=="ri") right=right+1;
}


function checkAnswer (form) {
	//alert (right);    userans = form.answer.value.toUpperCase();    
    rightans = form.correct.value;
    wordcount = form.nowords.value;
    lettercount = form.nolets.value;
    good=lettercount*0.9;
    ok=lettercount*0.75;
    guess=lettercount*0.5;
    if (right<=guess) {
    	//alert(guess);
    	response="You found less than half the letters in the "; 
    }else{
    	if (right>guess) response="You found over half the letters in the ";
    	if (right>ok) response="You found most of the letters in the ";
    	if (right>good) response="Good. You found almost all the letters in the ";
    	if (right==lettercount) response="Well done. You found all the ";
    	
    }
    response += wordcount +" words";
    //alert(response);
	if (userans==rightans)   {
		score=score+10;
		if (right<=guess) {
			response+= ", but guessed the right answer."; 
		}else{
	   		response+=" and the right answer.";
		}
    }else{
    	
    	response+=". The answer should be: "+ rightans + ".";
    }
    score=score+right; score=score-wrong;
    if (score<0) score=0;
    response+="<br/> Your score is "+score; 
    writelayer('trueans',response);	}  
