var quizlayername = "hecatombquiz1";
var R = 0;
var G = 0;
var U = 0;
var B = 0;
var Rx = 0;
var Gx = 0;
var Ux = 0;
var Bx = 0;
var rtotal = "";
var runningtotal = "test";
var nextq = 0;
var q1 = 2;
var q2 = 2;
var q3 = 2;
var q4 = 2;
var q5 = 2;
var q6 = 2;
var q7 = 2;
var q8 = 2;
var q9 = 2;
var q10 = 2;
var q11 = 2;
var q12 = 2;
var qadv = 0;
var winnervalue = 0;
var winnerdoom = 0;

function questiontally (qnumber) {

	qadv = 0;

	if (qnumber == 1) {
		for (i=0; i<2; i++) {
			if (document.form1.q1[i].checked) { q1 = i }
		}
		if (q1 == 2) { 
			alert("Please select an answer.")
			qadv = 1;
		}			
		if (q1 == 0) { R += 2 }	
		if (q1 == 1) { G += 3 }			
	}
	
	if (qnumber == 2) {
		for (i=0; i<2; i++) {
			if (document.form1.q2[i].checked) { q2 = i }
		}
		if (q2 == 2) { 
			alert("Please select an answer.")
			qadv = 1;
		}			
		if (q2 == 0) { U += 1 }	
		if (q2 == 1) { B += 1 }			
	}	
	
	if (qnumber == 3) {
		for (i=0; i<2; i++) {
			if (document.form1.q3[i].checked) { q3 = i }
		}
		if (q3 == 2) { 
			alert("Please select an answer.")
			qadv = 1;
		}			
		if (q3 == 0) { R += 3 }	
		if (q3 == 1) { B += 3 }			
	}		
	
	if (qnumber == 4) {
		for (i=0; i<2; i++) {
			if (document.form1.q4[i].checked) { q4 = i }
		}
		if (q4 == 2) { 
			alert("Please select an answer.")
			qadv = 1;
		}			
		if (q4 == 0) { U += 2 }	
		if (q4 == 1) { G += 2 }			
	}		

	if (qnumber == 5) {
		for (i=0; i<2; i++) {
			if (document.form1.q5[i].checked) { q5 = i }
		}
		if (q5 == 2) { 
			alert("Please select an answer.")
			qadv = 1;
		}			
		if (q5 == 0) { G += 1 }	
		if (q5 == 1) { B += 1 }			
	}		
	
	if (qnumber == 6) {
		for (i=0; i<2; i++) {
			if (document.form1.q6[i].checked) { q6 = i }
		}
		if (q6 == 2) { 
			alert("Please select an answer.")
			qadv = 1;
		}			
		if (q6 == 0) { R += 1 }	
		if (q6 == 1) { U += 3 }			
	}		
	
	if (qnumber == 7) {
		for (i=0; i<2; i++) {
			if (document.form1.q7[i].checked) { q7 = i }
		}
		if (q7 == 2) { 
			alert("Please select an answer.")
			qadv = 1;
		}			
		if (q7 == 0) { R += 2 }	
		if (q7 == 1) { G += 3 }			
	}		
	
	if (qnumber == 8) {
		for (i=0; i<2; i++) {
			if (document.form1.q8[i].checked) { q8 = i }
		}
		if (q8 == 2) { 
			alert("Please select an answer.")
			qadv = 1;
		}			
		if (q8 == 0) { U += 3 }	
		if (q8 == 1) { B += 3 }			
	}	
	
	if (qnumber == 9) {
		for (i=0; i<2; i++) {
			if (document.form1.q9[i].checked) { q9 = i }
		}
		if (q9 == 2) { 
			alert("Please select an answer.")
			qadv = 1;
		}			
		if (q9 == 0) { R += 1 }	
		if (q9 == 1) { B += 2 }			
	}		
	
	if (qnumber == 10) {
		for (i=0; i<2; i++) {
			if (document.form1.q10[i].checked) { q10 = i }
		}
		if (q10 == 2) { 
			alert("Please select an answer.")
			qadv = 1;
		}			
		if (q10 == 0) { U += 2 }	
		if (q10 == 1) { G += 2 }			
	}		
	
	if (qnumber == 11) {
		for (i=0; i<2; i++) {
			if (document.form1.q11[i].checked) { q11 = i }
		}
		if (q11 == 2) { 
			alert("Please select an answer.")
			qadv = 1;
		}			
		if (q11 == 0) { G += 1 }	
		if (q11 == 1) { B += 2 }			
	}		
	
	if (qnumber == 12) {
		for (i=0; i<2; i++) {
			if (document.form1.q12[i].checked) { q12 = i }
		}
		if (q12 == 2) { 
			alert("Please select an answer.")
			qadv = 1;
		}			
		if (q12 == 0) { R += 3 }	
		if (q12 == 1) { U += 1 }			
	}		
		
	if (qadv == 0) {

		if (R >= winnervalue) { 
			winnervalue = R;			
			winnerdoom = 1;  	
		}
		if (G >= winnervalue) { 
			winnervalue = G;			
			winnerdoom = 2;  	
		}
		if (U >= winnervalue) { 
			winnervalue = U;			
			winnerdoom = 3;  	
		}
		if (B > winnervalue) { 
			winnervalue = B;			
			winnerdoom = 4;  	
		}
		
			 Rx = R; 
			 Gx = G;	
			 Ux = U;
 			 Bx = B;

		
		if (R == winnervalue && winnerdoom == 2) { 
			 Rx = G + R; 
			 Gx = U + G;	
		}

		if (R == winnervalue && winnerdoom == 3) { 
			 Rx = G + R; 
			 Ux = B + U;
		}

		if (R == winnervalue && winnerdoom == 4) { 
			 Rx = G + R; 
			 Bx = R + B;
		}
		
		
		if (G == winnervalue && winnerdoom == 1) { 
			 Gx = U + G;	
			 Rx = G + R; 
		}		
		
		if (G == winnervalue && winnerdoom == 3) { 
			 Gx = U + G;	
			 Ux = B + U;
		}

		if (G == winnervalue && winnerdoom == 4) { 
			 Gx = U + G;	
			 Bx = R + B;		
		}
		
		
		if (U == winnervalue && winnerdoom == 1) { 
			 Ux = B + U;
			 Rx = G + R; 
		}
		
		if (U == winnervalue && winnerdoom == 2) { 
			 Ux = B + U;
			 Gx = U + G;	
		}
		
		if (U == winnervalue && winnerdoom == 4) { 
			 Ux = B + U;
			 Bx = R + B;	
		}		
		
		
		if (B == winnervalue && winnerdoom == 1) { 
			 Bx = R + B;	
			 Rx = G + R; 
		}			
		
		if (B == winnervalue && winnerdoom == 2) { 
			 Bx = R + B;	
			 Gx = U + G;	
		}	
		
		if (B == winnervalue && winnerdoom == 3) { 
			 Bx = R + B;	
			 Ux = B + U;
		}	
		
		winnervalue = 0;
		
		if (Rx >= winnervalue) { 
			winnervalue = Rx;			
			winnerdoom = 1;  	
		}
		if (Gx >= winnervalue) { 
			winnervalue = Gx;			
			winnerdoom = 2;  	
		}
		if (Ux >= winnervalue) { 
			winnervalue = Ux;			
			winnerdoom = 3;  	
		}
		if (Bx > winnervalue) { 
			winnervalue = Bx;			
			winnerdoom = 4;  	
		}								
	
//	rtotal = "R:" + Rx + " G:" + Gx + " U:" + Ux + " B:" + Bx + "(" + winnerdoom + ")\n" + rtotal; 	
//	document.form1.runningtotal.value = rtotal;		

		nextq = qnumber + 1	
		if (nextq == 13) {
			nextq = 12 + winnerdoom 
		}		
		reveal_layer (nextq);

//		document.form1.boardsdoom.value = "Boards Code Goes Here";
//		document.form1.blogdoom.value = "HTML (Blog) Code Goes Here";
	}
}

function reveal_layer (object) {

  object = "hecatombquiz" + object	

  for (qq = 1; qq <= 20; qq++) {	
	quizlayername = "hecatombquiz" + qq; 
	hide_layer (quizlayername);
  }

  if (document.getElementById) {
    document.getElementById(object).style.visibility = 'visible';
  }
  else if (document.layers && document.layers[object]) {
    document.layers[object].visibility = 'visible';
  }
  else if (document.all) {
    document.all[object].style.visibility = 'visible';
  }
}

function hide_layer (object) {
  if (document.getElementById) {
    document.getElementById(object).style.visibility = 'hidden';
  }
  else if (document.layers && document.layers[object]) {
    document.layers[object].visibility = 'hidden';
  }
  else if (document.all) {
    document.all[object].style.visibility = 'hidden';
  }
}