<!--

var self;
function Oops()
{
    self = this;this.notouch=true;
    this.right=300;this.vocabObj = null;
    this.words=null;
    this.qnum = -1;this.opts = new Array(4);this.shfarr = new Array(3);
    this.letArr = new Array('A.&nbsp;','B.&nbsp;','C.&nbsp;','D.&nbsp;');
    this.clicks=0;
    		
	this.initGame = function(warr)
	{
	    this.notouch=true;
		this.words = warr;
	    this.qnum = -1;
		this.vocabObj = document.getElementById("oopsdef");
	    this.clearBoard();
	}
	
	this.endGame = function()
	{
	    this.notouch=true;
		var str = '<div class="btntxt" style="margin-left:50px;">Check score:</div><div id="lbtn"></div><div id="mbtn" onClick="self.submitfrm();">Score</div><div id="rbtn"></div>';
		var f = document.getElementById("btnbrd"); if (f != null) {f.innerHTML = str;}        
	}
	
	this.showNext = function()
	{
	    this.qnum++; if (this.qnum > 4) {return this.endGame();}
		if (this.vocabObj != null) {this.vocabObj.innerHTML = 'Select the correct spelling.';}
		this.showOptions(this.qnum);
		this.showBoard();
	}
	
	this.showOptions = function(n)
	{
	    this.opts[0] = 0;
	    for (var i = 1; i < 4; i++) {this.shfarr[i-1]=i;}
	    this.shuffleArray(this.shfarr);
	    for (var j = 1; j < 4; j++) {this.opts[j] = this.shfarr[j-1];}
	    var x = this.getRandom(0,3); if (x != 0) {var t = this.opts[0];this.opts[0]=this.opts[x];this.opts[x]=t;}
	    
	    for (var k = 0; k < 4; k++)
	    {
	        var o = document.getElementById("ansid_"+k); if (o != null) {o.innerHTML = this.letArr[k] + this.words[n][this.opts[k]];}
	        var s = document.getElementById("anssts_"+k); if (s != null) {s.innerHTML = '';}
	    }
	}
	
	this.shuffleArray = function(a)
	{
		var len = a.length;
		for (var m = 0; m < len; m++)
		{
			t1 = this.getRandom(0,len-1);t2 = this.getRandom(0,len-1);
			if (t1 != t2) {var tt = a[t1];a[t1]=a[t2];a[t2]=tt;}
		}
	}
	
	this.showMainText = function (str)
	{
	    this.vocabObj.innerHTML = str;
	}
	
	this.checkAns = function(n)
	{
	    if (this.notouch) {return;}
	    this.notouch = true;
	    this.clicks++;
	    if (this.opts[n] == 0)
	    {
	        this.changeClass(n,"&radic;");
	        this.showMainText('Correct');
	    	this.clearBoard();
	    }
	    else
	    {
	        this.changeClass(n,"&times;");
	        this.showMainText('<div class="oops_0"></div>');
	        this.notouch = false;
	    }
	}
	
	this.submitfrm = function()
	{
		var f = document.getElementById("oopsbrd");
		if (f != null) 
		{
		    var str = "Congratulations!</br> Your score is:" + Math.floor(500/this.clicks) + "%";
		    
			f.innerHTML = "";
			var o = f.appendChild(document.createElement('div'));
			o.innerHTML='<input type="hidden" name="helppage" value="oopshelp.html" />';
			var o = f.appendChild(document.createElement('div'));
			o.innerHTML='<input type="hidden" name="gamepage" value="oops.php" />';
			o = f.appendChild(document.createElement('div'));
			o.innerHTML='<input type="hidden" name="msg" value="' + str + '" />';
		}

		document.oops_frm.submit();
	}
		
			
	this.changeClass = function(n,ststxt)
	{
	    var s = document.getElementById("anssts_"+n); if (s != null) {s.innerHTML = ststxt;}
	}
	

	this.getRandom = function(min,max)
	{
		return min + Math.floor(Math.random()*(max-min+1))
	}

	this.clearBoard = function()
	{
	    this.right=310;
	    this.clipRight();
	}
	
	this.clipRight = function ()
	{
		if (self.right > 0) 
		{
			self.right -= 10;
			if (self.vocabObj != null) {self.vocabObj.style.clip = "rect(0px " + self.right + "px 82px 0px)";}
			setTimeout("self.clipRight()", 10);
		}
		else {this.showNext();}
	}

	this.showBoard = function()
	{
	    this.right=0;
	    this.clipLeft();
	}

	this.clipLeft = function()
	{
		if (self.right < 310) 
		{
			self.right += 10;
			if (self.vocabObj != null) {self.vocabObj.style.clip = "rect(0px " + self.right + "px 82px 0px)";}
			setTimeout("self.clipLeft()", 10);
		} else {this.notouch = false;}
	}

}


-->


