function checkRadio (frmName, rbGroupName) {
 var radios = document[frmName].elements[rbGroupName];
 for (var i=0; i <radios.length; i++) {
  if (radios[i].checked) {
   return true;
  }
 }
 return false;
} 


function CheckTheForm() {
    var result = true;
    var msg="";
	var anchor ="#formreturn";
   
	
	//Course selection
if (!checkRadio("form1","applicationfor")) {
 		msg+="Please indicate which course you wish to take. \n";
		document.getElementById('applicationfor').style.background="#F8DFDF";
		result = false;
		anchor ="#formreturn";
		}
	
	if (document.form1.title.value=="") {
			msg+="Please select your preferred Title. \n";
			document.getElementById('title').style.color="red";
			document.getElementById('title_field').style.background="#F8DFDF";
			result = false;
			anchor ="#formreturn";
		    }

    if (document.form1.firstname.value=="") {
            msg+="Please enter your First Name. \n";
            document.getElementById('firstname').style.color="red";
			document.getElementById('firstname_field').style.background="#F8DFDF";
            result = false;
			anchor ="#formreturn";
            }

	if (document.form1.lastname.value=="") {
			msg+="Please enter your Last Name. \n";
			document.getElementById('lastname').style.color="red";
			document.getElementById('lastname_field').style.background="#F8DFDF";
			result = false;
			anchor ="#formreturn";
		    }
		
    if (document.form1.upload_field.value=="") {
            msg+="Please browse to find the file you wish to upload. \n";
            document.getElementById('upload_label').style.color="red";
			document.getElementById('upload_field').style.background="#F8DFDF";
            result = false;
			anchor ="#formreturn";
            }	
			
	if (document.form1.test1.value=="") {
		msg+="Please answer the first confirmation question.\n";
		document.getElementById('test1_text').style.color="red";
		document.getElementById('test1').style.background="#F8DFDF";
		result = false;
		anchor ="#captcha";
		}
		
	if (document.form1.test2.value=="") {
		msg+="Please answer the second confirmation question.\n";
		document.getElementById('test2_text').style.color="red";
		document.getElementById('test2').style.background="#F8DFDF";
		result = false;
		anchor ="#captcha";
		}
			
	if ((document.form1.test1.value!=5) && (document.form1.test1.value!="")) {
		msg+="Sorry -- The answer to the first confirmation question is incorrect.\n";
		document.getElementById('test1_text').style.color="red";
		document.getElementById('test1').style.background="#F8DFDF";
		result = false;
		anchor ="#captcha";
		}

	if ((document.form1.test2.value!=8) && (document.form1.test2.value!="")) {
		msg+="Sorry -- The answer to the second confirmation question is incorrect.\n";
		document.getElementById('test2_text').style.color="red";
		document.getElementById('test2').style.background="#F8DFDF";
		result = false;
		anchor ="#captcha";
		}
			

    if(msg==""){
    return result;
    }{
    alert(msg);
	location.href="#formreturn";
    return result;
    }
}