var checkData = {

  init : function() {

    if (!document.getElementsByTagName || !document.getElementsByName) {return;}

    // isolate the form element node and assign a function when submit occurs
    var theForm = document.getElementsByTagName('form')[2];
    checkData.addEvent(theForm, 'submit', checkData.validateInput);

  },

  // use the 'e' parameter to represent the event object that is automatically passed
  validateInput : function(e) {

    // by default, the alert message is empty, which translates to false
    var msg = "";

	// locate all the form elements, since everything is required
    var allInputs = document.getElementsByTagName('input');
	
	for (var i=0, totalInputs=allInputs.length; i<totalInputs; i++) {
		if (allInputs[i].getAttribute('name') == 'from') {
		   var emailAddress = allInputs[i].value;
		   emailAddress = emailAddress.match(/^([\w\.\-])+\@(([\w\-])+\.)+([\w]{2,6})+$/);
		   if (!emailAddress) {
			  msg+= 'Please enter a valid email address.\n';
		  }
		}
	}
    // if anything was added to msg, show an alert and stop the default action of the form submitting
    if (msg) {
       alert(msg);

       // pass along the event object to stopDefault so that it knows what event to stop defaults for
       checkData.stopDefault(e);
    }
  },

  stopDefault : function(e) {
     // track down the event in IE
     if (!e) {e = window.event;}

     // create a preventDefault function for IE
     if (!e.preventDefault) {
        e.preventDefault = function() { this.returnValue = false; }
     }

     // call either the W3C standard method or the one created just for IE
     e.preventDefault();

     // for DOM0-only browsers as a final safety net
     return false;
  },

  addEvent : function(obj, type, func) {
    if (obj.addEventListener) {obj.addEventListener(type, func, false);}
    else if (obj.attachEvent) {
      obj["e" + type + func] = func;
      obj[type + func] = function() {obj["e" + type + func] (window.event);}
      obj.attachEvent("on" + type, obj[type + func]);
    }
    else {obj["on" + type] = func;}
  }

}

checkData.addEvent(window, 'load', checkData.init);