function shuffle(){

	for (x=0; x < n; x++)
	{
		r = Math.floor(Math.random()*x);
		randomized[x]=randomized[r];
		randomized[r] = original[x];
	}
}

function settitle() {
	document.getElementById('form_1').title_prompt.value = quiz_title;
}

//
function reinitialize(){
	i=0;
	correct =0;
	wrong =0;
	shuffle();
	settitle();
	document.getElementById('form_1').outbox_3.value = '';
	document.getElementById('form_1').outbox_4.value = '';
	document.getElementById('form_1').outbox_5.value = '';
	document.getElementById('form_1').outbox_6.value = '';
	document.getElementById('form_1').outbox_7.value = '';
}

//
function stepback(){
	if (i>=1){
		i--;
		correct--;
		showRandom(i);
		document.getElementById('form_1').outbox_4.value=correct;
		document.getElementById('form_1').outbox_5.value=correct+wrong;
		document.getElementById('form_1').outbox_6.value=n;
		document.getElementById('form_1').outbox_7.value=(n-correct);
		
	} 
}


//
function TorF(r)
{
	torf = randomstr[r].match("%%");
	if ( torf == "%%")
	{
		correct++;
		document.bgColor="lightgreen";
		document.getElementById('form_1').outbox_3.value = "Correct. Next question!";
		if(i+1<n) 
		{i++;
		setTimeout("document.bgColor='white'",50);
			showRandom(i);
		}
		else 
		{
			correct =n;
			document.bgColor="lightgreen";
			randomized[i]="Done!|%%|%%|%%"
			document.getElementById('form_1').outbox_3.value = "  Congratulations!";
			showRandom(i);	
		}

	} else {
		wrong++;
		document.bgColor="gray";
		setTimeout("document.bgColor='white'",50);
		document.getElementById('form_1').outbox_3.value = "Wrong. Please Try again.";
	}
	
	if (correct <= n){
	document.getElementById('form_1').outbox_4.value=correct;
	document.getElementById('form_1').outbox_5.value=correct+wrong;
	
	document.getElementById('form_1').outbox_6.value=n;
	
	document.getElementById('form_1').outbox_7.value=(n-correct);
	}
}

//
function showRandom(i)
{
	
	str = randomized[i].split("|");
	question = str[0]; 
	m = str.length-1;

	//

	randomstr = new Array(m) ;
	for (j=0; j < m; j++)
	{
	r = Math.floor(Math.random()*(j+1));
	randomstr[j] = randomstr[r];
	randomstr[r] = str[j+1];
	}

	displaystr = new Array;
	for(k=0; k<3; k++) 
	{	
		displaystr[k] =  "  " + randomstr[k];
		displaystr[k] = displaystr[k].replace("%%","");
	}
	
	document.getElementById('form_1').outbox_q.value = "  " + question;
	document.getElementById('form_1').outbox_0.value = displaystr[0];
	document.getElementById('form_1').outbox_1.value = displaystr[1];
	document.getElementById('form_1').outbox_2.value = displaystr[2];
}
//-->
