// This is the function that performs form verification. It will be invoked
// from the onSubmit() event handler. The handler should return whatever
// value this function returns.
function verify(f)
{
	var msg;
    var errors = "";
	var e = "";
	var elementnum = 999;
	var sel;
	var radio_choice = false;

//Check Name is Present
	e = document.forms[0].elements[0].value;
	if ((e == null) || (e == "") || isblank(e)) {
		errors += "- Please enter your Name\n";
		if (0 < elementnum) {
			elementnum = 0;
		}
	}

//Check Address is Present
	e = document.forms[0].elements[1].value;
	if ((e == null) || (e == "") || isblank(e)) {
		errors += "- Please enter your Address\n";
		if (1 < elementnum) {
			elementnum = 1;
		}
	}

//Check Date of Birth is Present
	e = document.forms[0].elements[2].value;
	if ((e == null) || (e == "") || isblank(e)) {
		errors += "- Please enter your Date of Birth\n";
		if (2 < elementnum) {
			elementnum = 2;
		}
	}

//Check Age is Present
	e = document.forms[0].elements[3].value;
	if ((e == null) || (e == "") || isblank(e)) {
		errors += "- Please enter your Age\n";
		if (3 < elementnum) {
			elementnum = 3;
		}
	}

//Check Sex is Present
//	e = document.KubMembershipForm.elements["Sex"].value;
//	if ((e == null) || (e == "") || isblank(e)) {
//		errors += "- Please show whether you are Male or Female\n";
//		if (4 < elementnum) {
//			elementnum = 4;
//		}
//	}
// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < KubMembershipForm.Sex.length; counter++) {
		if (KubMembershipForm.Sex[counter].checked) {
			radio_choice = true;
		}
	}
	if (!radio_choice) {
		errors += "- Please show whether you are Male or Female\n";
		if (4 < elementnum) {
			elementnum = 4;
		}
	}

//Check School is Present
	e = document.forms[0].elements[6].value;
	if ((e == null) || (e == "") || isblank(e)) {
		errors += "- Please enter the name of your School\n";
		if (6 < elementnum) {
			elementnum = 6;
		}
	}

//Check Next of Kin is Present
	e = document.forms[0].elements[7].value;
	if ((e == null) || (e == "") || isblank(e)) {
		errors += "- Please give the name of your Next of Kin\n";
		if (7 < elementnum) {
			elementnum = 7;
		}
	}

//Check Next of Kin Tel is Present
	e = document.forms[0].elements[8].value;
	if ((e == null) || (e == "") || isblank(e)) {
		errors += "- Please give the Telephone No. for your Next of Kin\n";
		if (8 < elementnum) {
			elementnum = 8;
		}
	}

//Check Doctor is Present
	e = document.forms[0].elements[9].value;
	if ((e == null) || (e == "") || isblank(e)) {
		errors += "- Please give the name of your Doctor\n";
		if (9 < elementnum) {
			elementnum = 9;
		}
	}

//Check Doctor Tel is Present
	e = document.forms[0].elements[10].value;
	if ((e == null) || (e == "") || isblank(e)) {
		errors += "- Please give the Telephone No. for your Doctor\n";
		if (10 < elementnum) {
			elementnum = 10;
		}
	}

// Now, if there were any errors, display the messages, and
// return false to prevent the form from being submitted. 
// Otherwise return true.
    if (!errors) {
		return true;
    }

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s) \n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

	if (errors) {
		msg += "\n";
    }
    msg += errors;
    alert(msg);
    if (elementnum != 999) {
		document.KubMembershipForm.elements[elementnum].focus();
	}
    return false;
}

// A utility function that returns true if a string contains only 
// whitespace characters.
function isblank(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}