
function isValidRadio(radio) {
    var error = "";
    var found = 0;

var radiolength =  document.forms[0][radio.name].length;
    for (var i = 0; i < radiolength; i++) {
        if (document.forms[0][radio.name][i].checked) {
             found=1;
             radio.style.outline=""; 
             radio.style.background = '';
             }
      }

if(found == 0){
     radio.style.background = 'Yellow';
     radio.style.outline="thick solid yellow";
     error = "The required field has not been filled in.\n";
     
}

 return error; 
}


function validateEmpty(fld) {
    var error = "";
  
    if (fld.value.length == 0 ) {
        fld.style.background = 'Yellow'; 
        error = "The required field has not been filled in.\n";
    } else { fld.style.background = '';}

    return error;   
}


function validateFormOnSubmit(theForm) {
var reason = "";

for (i=0; i<theForm.elements.length;i++){

if(theForm.elements[i].type == "radio" && theForm.elements[i].name != "rpractices9"){
   reason += isValidRadio(theForm.elements[i]);
}

if(theForm.elements[i].type !== "radio" && theForm.elements[i].type !== "submit"
	&& theForm.elements[i].name != "universityname" && theForm.elements[i].name != "householdincome"

		){
   reason += validateEmpty(theForm.elements[i]);
}

}

  if (reason !== "") {
    alert(" There are some empty fields in your submission. Please fill out any items highlighted in yellow. Thank you. ");
    return false;
  }

  return true;
}

