
	
function doClear ( form ) {	
 	document.form0.onReset = " return confirm('Are you sure that you want to clear all the data you have entered on this form?')";
  	document.form0.reset();	
}	

function doScore () {
//******************************************************************************* 
//  This rtn is called when the adiqscores.html page is displayed.
//  The actuall rtn is called from hierMenu.js, since this is where the onload
//  event is performed.
//
//  Loop thru the answers and check the appropriate radio buttons with the users
//  answers from the adiq.html page.	
//  This assumes the answers contain only valid Ts and Fs. 
//******************************************************************************* 
	var ans = 1;
	var theAnswers	= getCookie("answers");   // eg "FTTFTTTFTFTTFFFFT..."
	if (theAnswers == null) {
		alert ("Something seems to have gone awry. Can't display your answers.");
		return;	
	}
     
	var len = theAnswers.length
//	alert(theAnswers + " len=" + len);
   	for (ix = 1; ix < len; ix++) {
   		if (theAnswers.substr(ix, 1) == "T") {
   			ans = 0;
   		}	
   		else {
   			ans = 1;
   		}	
   		eval("document.form0.q" + ix + "[" + ans + "].checked = true");  
	} 	
}		

function fillAns () {
    var correctans = new makeArrayImplic("T","T","F","T","T","F","F","F","F","F","F","F","T","F","T","F","T","F","F","T");
    
   	for (ix = 1; ix < 21; ix++) {
   		if (correctans[ix] == "T") 
   			ans = 0;
   		else
   			ans = 1;
   		eval("document.form0.q" + ix + "[" + ans + "].checked = true");  
	}     
}	

function doForm ( form ) {	
//******************************************************************************* 
//  Rtn for adiq.html page
//  1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20  21  22  23  24
// "T","T","F","T","T","F","x","F","F","F","F","x","T","F","T","F","x","T","x","F","T","F","F","T"
//******************************************************************************* 
	var firstmessage="The following questions still need to be answered to determine your ad IQ:\n\n ";
	var errormessage="";
	var answers = "x";
	var isright = "x";  // each char represents 0 wrong, 1 right	eg. x00110001111001... 
	                    // Fill pos 1 with x, we dont use the first slot, 
	
// To remove validation for testing, change one of the numbers to 0.
if (1 == 1) {
	
//  20 questions, but we wont use the first slot in the q array, whcih has 21 slots.
    var correctans = new makeArrayImplic("T","T","F","T","T","F","F","F","F","F","F","F","T","F","T","F","T","F","F","T");
    var q = new makeArrayImplic("x","x","x","x","x","x","x","x","x","x","x","x","x","x","x","x","x","x","x","x","x");    
	
    if (document.form0.q1[0].checked) q[1] = "T";    else if (document.form0.q1[1].checked) q[1] = "F";
    if (document.form0.q2[0].checked) q[2] = "T";    else if (document.form0.q2[1].checked) q[2] = "F";
    if (document.form0.q3[0].checked) q[3] = "T";    else if (document.form0.q3[1].checked) q[3] = "F";
    if (document.form0.q4[0].checked) q[4] = "T";    else if (document.form0.q4[1].checked) q[4] = "F"; 
    if (document.form0.q5[0].checked) q[5] = "T";    else if (document.form0.q5[1].checked) q[5] = "F"; 
    if (document.form0.q6[0].checked) q[6] = "T";    else if (document.form0.q6[1].checked) q[6] = "F"; 
    if (document.form0.q7[0].checked) q[7] = "T";    else if (document.form0.q7[1].checked) q[7] = "F"; 
    if (document.form0.q8[0].checked) q[8] = "T";    else if (document.form0.q8[1].checked) q[8] = "F"; 
    if (document.form0.q9[0].checked) q[9] = "T";    else if (document.form0.q9[1].checked) q[9] = "F"; 
    if (document.form0.q10[0].checked) q[10] = "T";  else if (document.form0.q10[1].checked) q[10] = "F"; 
    if (document.form0.q11[0].checked) q[11] = "T";  else if (document.form0.q11[1].checked) q[11] = "F"; 
    if (document.form0.q12[0].checked) q[12] = "T";  else if (document.form0.q12[1].checked) q[12] = "F"; 
    if (document.form0.q13[0].checked) q[13] = "T";  else if (document.form0.q13[1].checked) q[13] = "F"; 
    if (document.form0.q14[0].checked) q[14] = "T";  else if (document.form0.q14[1].checked) q[14] = "F"; 
    if (document.form0.q15[0].checked) q[15] = "T";  else if (document.form0.q15[1].checked) q[15] = "F"; 
    if (document.form0.q16[0].checked) q[16] = "T";  else if (document.form0.q16[1].checked) q[16] = "F"; 
    if (document.form0.q17[0].checked) q[17] = "T";  else if (document.form0.q17[1].checked) q[17] = "F"; 
    if (document.form0.q18[0].checked) q[18] = "T";  else if (document.form0.q18[1].checked) q[18] = "F"; 
    if (document.form0.q19[0].checked) q[19] = "T";  else if (document.form0.q19[1].checked) q[19] = "F"; 
    if (document.form0.q20[0].checked) q[20] = "T";  else if (document.form0.q20[1].checked) q[20] = "F";         
    
    var score = 0 ; 
    
// Skip first entry [0], to make it easier to read. ie. Answer 1 is stored in q1.       
	for (ix = 1; ix < 21; ix++) {
 		answers = answers + q[ix];
 		
 		if (q[ix] == correctans[ix]) { 
 			score = score + 1;
 			isright = isright + "1"  // right answer
 		}
 		
 		else {
 			isright = isright + "0"   // wrong answer (or incomplete)
 			if (q[ix] == "x") 
 		    	errormessage = errormessage +  ix + "  "
 		}    
	}        
        
//   ret = allowInString(answers,"TF");
//   if (ret == false) {	
//        errormessage = "Please answer all the questions.";
//    }
    
}  // end 1 = 1 test 
   
   if (errormessage!="") { alert (firstmessage + errormessage)}
   else { 
   	
     setCookie("answers", answers); 
     setCookie("isright", isright); 
     setCookie("score", score); 
     location.href = "adiqscore.html";
//	return(0);  
   }
   
}  

function makeArraySimple (NumElements) {
	var Count;
	this.length = NumElements;
	for (Count = 1; Count <= NumElements; Count++)
		this[Count]=0;
	return (this);
} 
function assocArray (NumElements) {
//*-------------------------------------------------------------
//* Make an associative array
//*-------------------------------------------------------------
	this.length = NumElements;
	return(this);
} 

function allowInString (InString, RefString)  {
	if(InString.length==0) return (false);
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
			return (false);
	}
	return (true);
}

function makeArray (NumElements, Fill)  {
	var Count;
	this.length = NumElements;
	for (Count = 1; Count <= NumElements; Count++)  {
		this[Count] = Fill;
	}
	return (this);
}

function makeArrayImplic () {
//*-------------------------------------------------------------
//* Make a 1 dimensional array of from lines.
//*-------------------------------------------------------------
	var count;
	this.length = makeArrayImplic.arguments.length;
	for ( count=1; count < makeArrayImplic.arguments.length+1; count++)
	  {	this[count] = makeArrayImplic.arguments[count-1]; }
	return (this);
}

