function validate() {
	var aryQuestions = new Array(16);
	var aryAnswers = new Array(16);
	var bolError = false;
	var aryIncorrect = new Array();
	var intIncorrectCounter = 0;
				
	aryAnswers[0] = "b"
	aryAnswers[1] = "b"
	aryAnswers[2] = "a"
	aryAnswers[3] = "c"
	aryAnswers[4] = "b"
	aryAnswers[5] = "a"
	aryAnswers[6] = "c"
	aryAnswers[7] = "c"
	aryAnswers[8] = "c"
	aryAnswers[9] = "b"
	aryAnswers[10] = "a"
	aryAnswers[11] = "c"
	aryAnswers[12] = "c"
	aryAnswers[13] = "a"
	aryAnswers[14] = "a"
	aryAnswers[15] = "a"
	
	var counter = 0; 

	for (counter=0; counter<aryQuestions.length; counter++)
		aryQuestions[counter] = new Array('q' + (counter + 1), aryAnswers[counter],'');
   		
   	for (counter=0; counter<aryQuestions.length; counter++) {
   	
   		var radGroup = document.getElementsByName(aryQuestions[counter][0]);
   		aryQuestions[counter][2] = selectedRadio(radGroup);
   		
   		if (aryQuestions[counter][2] == undefined) {
   			bolError = true;
   		}
   	}
	
	if (bolError == true) {
		alert('You must answer each question.\n');
	} else {
		//check how many are correct.  If all, alert.  Otherwise, offer to try again!
		var questCounter = 0;
		
		for (counter=0; counter<aryQuestions.length; counter++) {
	   		if(aryQuestions[counter][1] == aryQuestions[counter][2]) {
	   			questCounter = (questCounter + 1);
	   		} else {
	   			aryIncorrect[intIncorrectCounter] = aryQuestions[counter][0];
	   			
	   			intIncorrectCounter++
	   		}
	   				   		
	   	}
	   	
	   	if (questCounter == aryQuestions.length) {
	   		alert('Congratulations, you got all ' + aryQuestions.length + ' questions correct!');
	   	} else {
	   		var strIncorrect = ''
	   		
	   		for (counter=0; counter<aryIncorrect.length; counter++) {
	   			if(strIncorrect == '') {
	   				strIncorrect = aryIncorrect[counter].replace(/q/,'');
	   			} else {
	   				strIncorrect = strIncorrect + ', ' + aryIncorrect[counter].replace(/q/,'');
	   			}
	   			   			
	   		}
	   		
	   		if (confirm('You got ' + questCounter + ' out of ' + aryQuestions.length + ' question correct.\n\nYou answered the following questions incorrectly:\n' + strIncorrect + '\n\n Would you like to try again?')) {
	   			window.location.href='questions.html';
	   		}			   		
	   	}		
		
	}
}

function selectedRadio(radiogroup){
	for(i=0;i<radiogroup.length;i++){
		if(radiogroup[i].checked==true) return radiogroup[i].value;
	}
}

function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(a_name,"Name cannot be blank! Please enter your name.")==false)
  {return false;}

  else if
  (validate_required(b_phonenumber,"Phone number cannot be blank! Please enter a phone number.")==false)
  {return false;}
  
  else if
  (validate_required(b_email,"Email address cannot be blank! Please enter an email address.")==false)
  {return false;}
  }
}
