function writeError(msg) {
   document.getElementById('errorMsg').innerHTML = msg
   document.getElementById('errorMsg').style.display = "block";
}
function removeError() {
   document.getElementById('errorMsg').style.display = "none";
}

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

  //IMPORTANT - ADD YOUR FIELD NAMES HERE THAT ARE TO BE VALIDATED

  if (theForm._fid_6) { reason += validateFName(theForm._fid_6) }
  if (theForm._fid_7) { reason += validateLName(theForm._fid_7) }
  if (theForm._fid_14) { reason += validateDropdown(theForm._fid_14) }

  for (i=0, n=theForm._fid_9.length; i<n; i++) {
      if (theForm._fid_9[i].checked) {
          var checkvalue = theForm._fid_9[i].value;
          break;
      } 
  }
  reason += checkRadio(checkvalue);

  if (theForm._fid_13) { reason += validateStory(theForm._fid_13) }  
  
  if (reason != "") {
  	writeError("<p>OOPS! Some fields are required and need your attention:<ul style='margin-bottom: 16px;'>\n" + reason + "</ul></p>");  
    return false;
  }
	document.getElementById('wcgButtons').style.display='none'; 
	document.getElementById('submitMessage').style.display='block';
  return true;
}
function validateFName(fld) {
    var error = "";
    if (fld.value.length == 0) {
        error = "<li>Please enter your first name</li>\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}
function validateLName(fld) {
    var error = "";
    if (fld.value.length == 0) {
        error = "<li>Please enter your last name</li>\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}
function checkRadio(checkvalue) {
	var error = "";
	   if (!(checkvalue)) {
		   error = "<li>Please let us know if you are a ProAdvisor</li>\n";
	    }
	return error;    
}
function validateDropdown(fld) {
    var error = "";
    if (fld.selectedIndex == "") {
       error = "<li>Please choose a product you currently use</li>\n";
    }    
return error;
}
function validateStory(fld) {
    var error = "";
    if (fld.value.length == 0) {
        error = "<li>Please share your knowledge and insights</li>\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}