

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *                                     Print function                                *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	function bodyLoad()
	{
		
		for ( i = 0 ; i < document.getElementsByName("words").length; i++) 
		{
			var wordObj = document.getElementsByName("words").item(i)
			wordObj.orgTop = parseInt(wordObj.style.top);
			wordObj.orgLeft = parseInt(wordObj.style.left);
		}	
		scroll(0)
	}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *                                     Print function                                *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	function prw() {
   	 var OK
						
	 OK = verifyAns(false);
	// if (OK) {

		// Prints
       print();
       //)
     }		

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *  First click: defines the Answer-Object to be moved                               *	
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	function mouseClick1(obj) {
		currentObj = obj;    // ansver-object		
	}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *  Second click:  defines the Question-Object to place the Answer-Object into       *	
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	function mouseClick2(ansObj) {		//<--Added a parameter ansObj
		
		if(ansObj.curAns != "null")
		{			
			reposition(ansObj.curAns)
		}
		removeFromAnswer(currentObj);
	  	ansObj.curAns = currentObj;	  	
		currentObj.style.posLeft = ansObj.offsetLeft 
		currentObj.style.posTop = ansObj.offsetTop - 5
    }
    
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *            repositions the specified object back to its original position         *	
// *			offseted by the scrollPos											   *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  function reposition(obj)
    {			
		
		obj.style.posLeft = obj.orgLeft;
		obj.style.posTop = parseInt(obj.orgTop) + scrollPos;
		
    }
    
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *            Removes any possibility that the same answer be used for 2			   *
// *			different answers											           *	
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
   function removeFromAnswer(obj)
    {
		for (j = 0 ; j < document.getElementsByName("blank1").length; j++)
		{				
			if ( obj == document.getElementsByName("blank1").item(j).curAns)
			{								
				document.getElementsByName("blank1").item(j).curAns = "null"
				break;
			} 			  				
		}
    }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *            If the word is double clicked the word is returned to the list of      *	
// *            available answer.													   *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  function doubleClick(obj)
    {	
		removeFromAnswer(obj);
		reposition(obj);		
	}
    

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *            Holds the list of words in the same position on the screen             *	
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    function scroll(varSc) {
		// varSc - scrolled Y dimention    	
		scrollPos = varSc;				
		
		//If the scroll bar is scrolling lower then minSCroll or higher then maxScroll in 
		//value the words do not need to scroll that far.  The max and min
		//scroll value for the words are thus stored in a variable instead
		//of readjusting the varSc value.  The varSc value is a reference to the scrollbar
		//value and changing the varSc value will reposition the scroll bar thus the
		//scroll bar could never go lower then minScroll or higher then maxScroll.
		if (varSc > maxScroll) {				
			scrollPos  = maxScroll;			
		}
		if (varSc < minScroll)				
		{								
			scrollPos = minScroll;			
		}								
		
		
		//loop through each word, if the word is used as an answer do not do anything with it, 
		//otherwise reposition it at its original location.  And make it scroll down so it is 
		//always visible.
		for ( i = 0 ; i < document.getElementsByName("words").length; i++) 
		{
			var found = false		
			for (j = 0 ; j < document.getElementsByName("blank1").length; j++)
			{				
				if ( document.getElementsByName("words").item(i) == document.getElementsByName("blank1").item(j).curAns)
				{								
					found = true
					break;
				} 			  				
			}
			if (! found)
			{
				reposition(document.getElementsByName("words").item(i))
			}				
		}
		
    }
	
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// *  Verifies to see if the answers are correct			                           *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	function verifyAns() {
		
		//Loop through each question to see if the answer is correct
          
		var correct = 0
		for ( i = 0 ; i < document.getElementsByName("blank1").length; i++) {
			if ( document.getElementsByName("blank1").item(i).curAns.innerText == document.getElementsByName("blank1").item(i).ans) {
				correct++
			} 			  
		}	

		//display a message informing of the amount of right answers have been entered
		if ( correct == (document.getElementsByName("blank1").length )) {
			alert ("Congradulations!!!  You got them all correct!!!")
		} else {
			alert("Sorry!! You have only " +  correct + " correct answers out of " + document.getElementsByName("blank1").length)
		}
	}
