function checkForm(theForm, errorTarget, errorText, errorColor) { // set global variables var formOK = true; // loop through each form element for(i=0; i= 0) { // content required thePattern = /^(.+[\r\n]*)+$/; } else if(theItem.className.indexOf('valid-letters') >= 0) { // letters only thePattern = /^[a-zA-Z]+$/; } else if(theItem.className.indexOf('valid-numbers') >= 0) { // numbers only thePattern = /^[0-9]+$/; } else if(theItem.className.indexOf('valid-email') >= 0) { // email address format thePattern = /^[a-zA-Z0-9\_\-\.]+\@[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}$/;} // get item's label formLabels = theForm.getElementsByTagName('label'); for(x=0; x= 0 && theItem.options[theItem.selectedIndex].value == '') { formOK = false; // change label color theLabel.style.color = errorColor; } else if(theItem.className.indexOf('valid-selection') >= 0 && theItem.options[theItem.selectedIndex].value != '') { // set label color back to default theLabel.style.color = ''; } // if the element was a checkbox and is not checked if(theItem.className.indexOf('valid-checked') >= 0 && theItem.checked == false) { formOK = false; // change label color theLabel.style.color = errorColor; } else if(theItem.className.indexOf('valid-checked') >= 0 && theItem.checked == true) { // set label color back to default theLabel.style.color = ''; } } // display error message if(!formOK && errorTarget != '') { theError = document.getElementById(errorTarget); theError.innerHTML = errorText; theError.style.color = errorColor; theError.style.display = "block"; } // return final value return formOK; }