
      //<![CDATA[

      var fieldNullability = new Object;
      var strError = "";
      window.onload = function ()
      {
	      document.getElementById("ContestEntry").onsubmit = function()
	      {
	      return validateContestEntry()
	      }
      }

      fieldNullability.FullName = new Object;
      fieldNullability.FullName.label = "Your Full Name";
      fieldNullability.FullName.type = "true";

      fieldNullability.Organization = new Object;
      fieldNullability.Organization.label = "Your Organization";
      fieldNullability.Organization.type = "true";
      
      fieldNullability.Email = new Object;
      fieldNullability.Email.label = "Your Email Address";
      fieldNullability.Email.type = "emailRequired";
      
      fieldNullability.PhoneNumber = new Object;
      fieldNullability.PhoneNumber.label = "Phone Number";
      fieldNullability.PhoneNumber.type = "true";
      
      fieldNullability.URL = new Object;
      fieldNullability.URL.label = "URL of Submission";
      fieldNullability.URL.type = "true";
      
	function textCounter(field, countfield, maxlimit) 
	{
		if (field.value.length > maxlimit) // if too long...trim it!
			field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
		else 
			countfield.value = maxlimit - field.value.length;
	}


      function validateContestEntry()
      {
	      var formOK = true;
	      var currentField;
	      var errImgIndex = 0;
	      strError = "";
	      strInfo = "";
	      removeErrImgContestEntry();
	           
	      for (i in fieldNullability)
	      {
		      switch(fieldNullability[i].type)
		      {
		        case "true":
		            currentField = document.getElementById(i);
		            if (!currentField.value)
		            {
		                strError = strError + "<li>'" + fieldNullability[i].label + "' is a required field<\/li>";
		                addErrImgContestEntry(currentField,errImgIndex++,true); 
		                if (formOK) currentField.focus();
		                formOK = false;                
		            }    
		            break;
		        case "email":
		            currentField = document.getElementById(i);
		            if (currentField.value != "" && !isEmail(currentField.value))
		            {
		                strError = strError + "<li>'" + fieldNullability[i].label + "' should be a valid email address<\/li> ";
		                addErrImgContestEntry(currentField,errImgIndex++,true); 
		                if (formOK) currentField.focus();
		                formOK = false;                
		            }    
		            break;
		        case "emailRequired":
		            currentField = document.getElementById(i);
		            if (!currentField.value)
		            {
		                strError = strError + "<li>'" + fieldNullability[i].label + "' is a required email address<\/li> ";
		                addErrImgContestEntry(currentField,errImgIndex++,true); 
		                if (formOK) currentField.focus();
		                formOK = false;                
		            } 
		            else if (!isEmail(currentField.value))
		            {
		                strError = strError + "<li>'" + fieldNullability[i].label + "' should be a valid email address<\/li> ";
		                addErrImgContestEntry(currentField,errImgIndex++,true); 
		                if (formOK) currentField.focus();
		                formOK = false;                
		            }                         
		            break;   
		        case "radio":                 
		            var isChecked = false;
		            currentCol = document.getElementsByName(i);
		            for (var j = 0; j < currentCol.length;j++)
		            {
		                if (currentCol[j].checked) isChecked = true;
		            }
		            if (!isChecked)
		            {
		                strError = strError + "<li>'" + fieldNullability[i].label + "' is a required field<\/li> ";
		                addErrImgContestEntry(currentCol[0],errImgIndex++,true); 
		                for (var k = 1; k < currentCol.length; k++)
		                    addErrImgContestEntry(currentCol[k],errImgIndex++,false);
		                formOK = false;                
		            }                    
		            break;
		        case "likert":
		            var isChecked = false;
		            currentCol = document.getElementsByName(i);
		            for (var j = 0; j < currentCol.length;j++)
		            {
		                if (currentCol[j].checked) isChecked = true;
		            }
		            if (!isChecked)
		            {
		                strError = strError + "<li>'" + fieldNullability[i].label + "' is a required field<\/li> ";
		                addErrImgContestEntry(currentCol[0],errImgIndex++,true); 
		                formOK = false;                
		            }           
		            break;
		        case "checkbox":
		            currentField = document.getElementById(i);
		            if(!currentField.checked)
		            {
		                strError = strError + "<li>'" + fieldNullability[i].label + "' is a required field<\/ul> ";
		                addErrImgContestEntry(currentField,errImgIndex++,true); 
		                if (formOK) currentField.focus();
		                formOK = false;                
		            }
		            break;                    
		        default:        
		            break;
		      }

	      }
	      if (!formOK) 
	      {
	      strErrorHeader = "Please enter or change the fields marked with a <img src='http://www.missouristate.edu/assets/webpress/errorImage.gif' alt='Error warning' /> :";
	      strError = strErrorHeader + "<ul>" + strError + "<\/ul>";
	      document.getElementById("form33270Error").innerHTML = strError;
	      document.getElementById("form33270Error2").innerHTML = strError;
	      }
	      return formOK;            
	      }
	      function addErrImgContestEntry(elem,index,visible)
	      {
	      // create image and add to erred field 'elem'
	      var errAlt = "This field has an error.";
	      var errTitle = errAlt;
	      if (visible)
	      var errSrc = "http://www.missouristate.edu/assets/webpress/errorImage.gif";
	      else
	      var errSrc = "http://www.missouristate.edu/assets/webpress/spacer_15_15.JPG";
	      var errorImage = document.createElement('img');
	      errorImage.style.verticalAlign = "top";
	      errorImage.alt = errAlt;
	      errorImage.title = errTitle;
	      errorImage.src = errSrc;
	      errorImage.id = "errorImage" + index;
	      elem.parentNode.insertBefore(errorImage,elem);
      }

      function removeErrImgContestEntry()
      {
	      var j = 0;
	      while (true)
	      {
	      if (document.getElementById("errorImage"+j)==undefined || document.getElementById("errorImage"+j)==null) break;
	      currentNode = document.getElementById("errorImage" + j);
	      currentNode.parentNode.removeChild(currentNode);
	      j++;
      }
      }
      function isEmail(str)
      {
	      return (str.search(/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/) != -1);        
      }
      //]]>
