	var strErrorSelect = "";
	var strErrorAjax = "";
	
    function isEmpty(str) {
      for(var intLoop=0; intLoop<str.length; intLoop++)
        if(str.charAt(intLoop)!=" ")
          return false;
      return true;
    }
	
    function setFocus(value) {
      if (strErrorSelect == "") {
        strErrorSelect = value;
      }
    }
	
    function checkRequired () {
      var f= document.requestForm;
      var strError= "";
      
      if (isEmpty(f.name.value)) {
        strError +="\n-- Name";
        setFocus("name");
      } else if (f.name.value.length > 50) {
        strError +="\n-- Name is too long";
        setFocus("name");
      }
      if (isEmpty(f.email.value)) {
        strError +="\n-- Email";
        setFocus("email");
      } else if (!validEmail(f.email.value)) {
        strError +="\n-- Invalid Email Address";
        setFocus("email");
      }
      if (f.company.value.length > 50) {
        strError +="\n-- Company or Organization Name is too long";
        setFocus("company");
      }
      if (isEmpty(f.interest.value)) {
        strError +="\n-- Interested Area";
        setFocus("interest");
      }
	  
	  
      if ((f.interest.value == "Home Care") && (isEmpty(f.office.value))) {
        strError +="\n-- Office";
        setFocus("office");
      }
      if ((f.interest.value == "Home Health") && (isEmpty(f.office.value))) {
        strError +="\n-- Person";
        setFocus("office");
      }
	  
	  
      if (f.comments.value.length > 65535) {
        strError +="\n-- Comments and Questions is too long";
        setFocus("comments");
      }
      if (isEmpty(f.C0D3.value)) {
        strError +="\n-- Code";
        setFocus("C0D3");
      }
      
      //display error message
      if(strError !="") {
        alert("The following required data is missing or not valid:\n" + strError);
        document.getElementById(strErrorSelect).focus();
        strErrorSelect = "";
        return false;
      } else {
        return true;
      }
    }
    
    /* ################ AJAX BEGIN ################ */
    var xmlhttp
    var regen = false;
    
    function ajaxPost(ajax_url, ajax_var) {
      if (window.XMLHttpRequest) { // IE7+, Firefox, Safari, Chrome, Opera
        xmlhttp = new XMLHttpRequest();
      } else if (window.ActiveXObject) { // IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } else {
        alert('Problem with XMLHTTP');
        return false;
      }
      xmlhttp.onreadystatechange = ajaxFeedBack;
      xmlhttp.open('POST', ajax_url, true);
      xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlhttp.setRequestHeader("Content-length", ajax_var.length);
      xmlhttp.setRequestHeader("Connection", "close");
      xmlhttp.send(ajax_var);
      xmlhttp.close
    }
    
    function ajaxFeedBack() {
      if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
        db_feedback = xmlhttp.responseText;
        if (db_feedback == "wrongcode") {
          alert("Wrong Code");
          document.getElementById('C0D3').focus();
        } else if (db_feedback == "error") {
          document.getElementById('ajax-form-before').style.display = "none";
          document.getElementById("contentheader").innerHTML = "<h1 style='color: red;'>Submission Error</h1>";
          document.getElementById('ajax-form-after-error').style.display = "block";
          alert("Submission Error");
        } else if (db_feedback == "success") {
          document.getElementById('ajax-form-before').style.display = "none";
          //document.getElementById("contentheader").innerHTML = "<h1>Submission Successful</h1>";
          document.getElementById('ajax-form-after-success').style.display = "block";
          alert("Submission Successful");
        } else {
          alert("Submission Error");
        }
      } else {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status != 200)) {
          window.location="/scripts-loc/email-update-error-ajax-log.asp?n=" + xmlhttp.status;
        }
      }
    }
    
    function ajaxTryFormAgain() {
      document.getElementById('ajax-form-before').style.display = "block";
      document.getElementById('ajax-form-after-error').style.display = "none";
      document.getElementById('ajax-form-after-wrongcode').style.display = "none";
      document.getElementById('C0D3').focus();
    }
    
    function ajaxReadForm() {
      if (document.getElementById('office')) {
        document.getElementById('read_office').value = document.getElementById('office').value;
      }
      var ajax_post_var = "name=" + encodeURI((document.getElementById('name').value).replace("&","and")) +
      "&email=" + encodeURI((document.getElementById('email').value).replace("&","")) +
      "&company=" + encodeURI((document.getElementById('company').value).replace("&","and")) +
      "&interest=" + encodeURI(document.getElementById('interest').value) +
      "&read_office=" + encodeURI(document.getElementById('read_office').value) +
      "&comments=" + encodeURI((document.getElementById('comments').value).replace("&","and")) +
      "&C0D3=" + encodeURI(document.getElementById('C0D3').value) +
      "&C0D3_ref=" + encodeURI(document.getElementById('C0D3_ref').value) +
      "&C0D3_ref_domain=" + encodeURI(document.getElementById('C0D3_ref_domain').value);
      ajaxPost('/scripts-loc/contact-submit-ajax.asp', ajax_post_var);
	  strErrorAjax = ajax_post_var;
    }
    /* ################# AJAX END ################# */
	
    function validEmail(emailS) {
      if (emailS.length < 70 && emailS.indexOf("@") > 0 && emailS.indexOf(".") != -1 && emailS.lastIndexOf(".") < (emailS.length-2) && emailS.lastIndexOf(".")>0 && (emailS.lastIndexOf(".") - emailS.lastIndexOf("@") > 1) ) {
        return true;
      } else {
        return false;
      }
    }
    
    function formSubmit() {
      if (checkRequired()) {
        ajaxReadForm();
      }
    }
    
    function formReset() {
      for (i=0; i<document.requestForm.elements.length; i++) {
        if ((document.requestForm.elements[i].type.toLowerCase() != "submit") && (document.requestForm.elements[i].type.toLowerCase() != "button") && (document.requestForm.elements[i].type.toLowerCase() != "reset") && (document.requestForm.elements[i].type.toLowerCase() != "hidden") && (document.requestForm.elements[i].id != "C0D3_js2")) {
          document.requestForm.elements[i].value = "";
          document.getElementById("C0D3").value = "";
          document.getElementById("C0D3_feedback").innerHTML = ""; 
		  document.getElementById('name').focus();
        }
      }
    }
    
    function newC0D3() {
      //document.getElementById("C0D3_new").value = "NEW CODE";
      //document.getElementById("C0D3_feedback").innerHTML = "";
      //document.requestForm.submit();
      //location.reload(true);
      var f = document.getElementById('C0D3_AJAX');
      f.src = f.src;
    }

