//helper for displayData() function
//simply ensures that user enters first, second names, selects a radio button
//and at least one checkboxfunction 
function validate(){

  if (document.studentForm.firstName.value == ""){
    alert("Please enter first name");
	return false;
  }
  if (document.studentForm.secondName.value == ""){
    alert("Please enter second name");
	return false;
  }
  var isRadChecked = false;
  var j;
  for (j = 0; j<5; j++) {
   //if rad button is checked, set isRadChecked to true
     if (document.studentForm.points[j].checked)
	    isRadChecked = true; 
  }
  if (!isRadChecked){
    alert("Please press a radio button");
	return false;
  }
  var isBoxChecked = false;
  var k;
  for (k = 0; k<5; k++) {
   //if checkbox is checked, set isBoxChecked to true
     if (document.studentForm.reason[k].checked)
	    isBoxChecked = true;  
  }
  if (!isBoxChecked){
    alert("Please select at least one checkbox");
	return false;
  }
  return true; 
}//end

function displayData(form) {
var radVal; //value of checked radio button
var data; //the string that will be written to the window document, includes all the html markup
var dataWindow; // for displaying data entered in the form
//validate the form
 if (validate()){
  //if OK, loop through the radio buttons
  var count;
   for (count = 0; count < 5; count++) {
   //if rad button is checked, break out and set radVal to the value of the checked radio button
     if (form.points[count].checked)
     break;
     }
   radVal = form.points[count].value;
   var reasonStr = "";//initialize 
   //loop through the checkboxes
   for (var i=0; i<5; i++)
     {
      //test each checkbox for checked
      if (form.reason[i].checked)
        {
	    //concatenate the string - uses bullet points to display
        reasonStr =  reasonStr + "<li>" + form.reason[i].value + "</li>";
        }
   }
   var coursesStr;
   if (form.courses.value == "") {
     coursesStr = "None";
   }
   else{
      coursesStr = form.courses.value;
  }
   
   data = "<html><head><title>Student Data</title><link rel='stylesheet' href='../../homestyle.css'></head>" + "<body><h1>Student Data</h1><p><b>First name:</b> "
   + form.firstName.value + "</p><p><b>Second name:</b> " + form.secondName.value + "</p><p><b>Number of courses studied in 2004:</b> "
   + form.noCourses.value + "</p><p><b>Previous courses:</b> "
   + coursesStr + "</p><p><b>Number of points studied in 2004:</b> "
   + radVal + "</p><p><b>Reasons for study are:</b></p><ul>"
   + reasonStr + "</ul></body></html>";
   dataWindow = window.open("","","toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=400");
   dataWindow.document.write(data);
   dataWindow.document.close();
 }
 }
