var Clean = {

   init : function() {
      for (var i in document.forms) {
         var form = document.forms[i];

         var fieldNames = [ "email", "u_email", "from", "category3", "web_email" ];

         for (var i in fieldNames) {

            var fieldName = fieldNames[i];

            if (form[fieldName] && form[fieldName].type == "text") {
               Clean.apply(form, form[fieldName]);
            }
         }
      }
   },

   apply : function(obj, param) {
      obj.onsubmit = function() { return verify(obj, param); }
   }
};

var req = null;
var currentForm = null;
var currentField = null;

function verify(obj, param) {
   var result = null;

   currentForm = obj;
   currentField = param;

   if (param.value == '') {
	   alert("E-mail address cannot be left blank.");
	   currentField.focus();
	   return false;
   }

   url = "http://www.mrgoodman.com/protect.php?email=" + param.value;

   // Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (req == null && typeof XMLHttpRequest != "undefined") {
      req = new XMLHttpRequest();
   }
   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.onreadystatechange = processChange;
      req.open("GET", url, true);
      req.send(null);
      return false;
   }
   return true;
}

function processChange(evt) {
   // The page has loaded and the HTTP status code is 200 OK
   if (req.readyState == 4) {
      if (req.status == 200) {
         var data = req.responseXML;
         result = data.getElementsByTagName('approved')[0].firstChild.data;
         //alert(result);

         if (result == "good") {
            currentForm.submit();
         }
		 else if (result == "badly formed") {
            alert("Your e-mail address contains typos.\n\nPlease fix and retry.");
			currentField.focus();
			currentField.select();
		 }
         else if (result == "banned") {
            alert("That ISP is banned from our lists.\n\nPlease enter an e-mail address from another provider.");
            currentField.value = '';
            currentField.focus();
         }
		 currentForm = null;
		 currentObject = null;
      }
   }
}

Clean.init();
