function HTMLLayer( name )
{
	if( typeof(name)=='string' )
	{
		this.name=name;
		this.getObj(name);
	}
	else
	{
		this.obj = name;
		this.style = this.obj.style?this.obj.style:this.obj;
	}
}
HTMLL=HTMLLayer.prototype
HTMLL.getObj=function(name)
{
	this.name=name;
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
  }
  else if (document.all)
  {
		this.obj = document.all[name];
  }
  else if (document.layers)
  {
		this.obj = this.getObjNN4(document,name);
  }
  if( this.obj==null)
	{
		this.notFound=true
	}
  else
  {
  	this.notFound=false
		this.style = this.obj.style?this.obj.style:this.obj;
	}
  return;
}
HTMLL.getObjNN4=function (obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}
HTMLL.write=function(text)
{
	if (document.getElementById || document.all)
	{
		this.obj.innerHTML = '';
		this.obj.innerHTML = text;
	}
	else if (document.layers)
	{
		text2 = '<P CLASS="testclass">' + text + '</P>';
		this.obj.document.open();
		this.obj.document.write(text2);
		this.obj.document.close();
	}
}
var SIMPLE_QUIZES = new Object();
function SimpleQuiz( id )
{
	this.id = id;
	this.numberOfQuestions = 0;
	SIMPLE_QUIZES[ id ]= this;
	this.answers = Array();
	this.allowUncheck = true;
	this.layerDisplay = Array();
	this.showLayersMode = 1;
}
SQUIZ=SimpleQuiz.prototype
SQUIZ.setOnlyShowResultLayersIfComplete = function()
{
	this.showLayersMode = 2;
}
SQUIZ.setOnlyShowResultLayersIfStarted = function()
{
	this.showLayersMode = 1;
}
SQUIZ.setAllwaysShowResultLayers = function()
{
	this.showLayersMode = 0;
}
SQUIZ.setAllowUncheck=function( vl )
{
	this.allowUncheck = vl;
}
SQUIZ.init=function()
{
	var kg = true;
	while( kg )
	{
		i = this.numberOfQuestions + 1;		
		var l = new HTMLLayer( 'the_quiz_correct' + i );
		if( l.notFound )
		{
			kg = false;
		}
		else		
		{
			var l2 = new HTMLLayer( 'the_quiz_incorrect' + i );
			if( l2.notFound )		
			{
				kg = false;
				alert( "Error Unable To Find Incorrect Answer Area "+i)
			}
			else
			{
				this.answers[ i ] = 0;
				this.numberOfQuestions = i;
				l.write( '<span class="quiz_unanswered" id="the_quiz_correct' + i+'_inner"><span class="quiz_click_region_position"><span onclick="SIMPLE_QUIZES[\''+this.id+'\'].changeAnswer('+i+',true);return false;" class="quiz_click_region">&nbsp;</span></span></span>');			
				l2.write( '<span class="quiz_unanswered" id="the_quiz_incorrect' + i+'_inner"><span class="quiz_click_region_position"><span onclick="SIMPLE_QUIZES[\''+this.id+'\'].changeAnswer('+i+',false);return false;" class="quiz_click_region">&nbsp;</span></span></span>');
			}
		}
	}
	this.updateOnResults();
}
SQUIZ.changeAnswer=function( nm, correct )
{
	var newState = correct?1:-1;
	if( this.allowUncheck && newState == this.answers[nm] )
	{
		newState = 0;
	}	
	this.answers[nm] = newState;
	var l = new HTMLLayer( 'the_quiz_correct' + nm+'_inner' );
	l.obj.className = newState == 1?'quiz_answered_correct':'quiz_unanswered';
	l = new HTMLLayer( 'the_quiz_incorrect' + nm+'_inner' );
	l.obj.className = newState == -1?'quiz_answered_incorrect':'quiz_unanswered';
	this.updateOnResults();
}
SQUIZ.updateOnResults=function()
{
	var correct = 0;
	var incorrect = 0;
	for( var i = 1; i <= this.numberOfQuestions; i++ )
	{
		switch( this.answers[ i ] )
		{
			case -1:
			{
				incorrect++;
			}
			break;
			case 1:
			{
				correct++;
			}
			break;
		}		
	}
	var answered = incorrect+correct;
	for( var i = 0; i < this.layerDisplay.length; i++ )
	{
		var l = new HTMLLayer( this.layerDisplay[ i ][ 1 ] );
		if( !l.notFound )
		{
			var display = false;
			if( this.showLayersMode ==0 || (this.showLayersMode == 1 && answered > 0 ) || answered == this.numberOfQuestions )
			{
				if( this.layerDisplay[ i ][ 0 ] )
				{
					display = correct >= this.layerDisplay[ i ][ 2 ] 
										&& ( this.layerDisplay[ i ][ 3 ] == -1 || correct <= this.layerDisplay[ i ][ 3 ] )
				}
				else
				{
					display = incorrect >= this.layerDisplay[ i ][ 2 ] 
										&& ( this.layerDisplay[ i ][ 3 ] == -1 || incorrect <= this.layerDisplay[ i ][ 3 ] )
				}
			}
			l.style.display = display?'':'none';
		}
	}
}
SQUIZ.addLayerDisplayOnIncorrectRange=function( id, start, finish )
{
	this.layerDisplay[this.layerDisplay.length] = Array( false, id, start, finish );
}