var confEmail = {

   init : function() {
       //object detection
       if (!document.getElementById && !getElementsByTagName) {
          return;
          }
       
       //run checkData fxn when form is submitted
       var theForm = document.getElementsByTagName('form')[0];
       confEmail.addEvent(theForm, 'submit', confEmail.checkData);
   },
   
   checkData : function(e) {
      
      //get the two email inputs
	  var email = document.getElementById('email');
	  var email2 = document.getElementById('email2');
	  
	  //check the values of the two emails against each other
      if (email.value != email2.value) {
		  //insert the error message content
		  var errorPara = document.createElement('p');
		  errorPara.appendChild(document.createTextNode('Please make sure your email address is entered correctly both times.'));
		  errorPara.className = 'boldorange';
		  var myForm = document.getElementById('theForm');
		  var emailfield = document.getElementById('emailfield');
          myForm.insertBefore(errorPara, emailfield);
		  //stop the default behavior of submitting the form
		  confEmail.stopDefault(e);
         }
   },
   
   stopDefault : function(e) {
      if (!e) {
         e = window.event;
         }
      if (!e.preventDefault) {
         e.preventDefault = function() { this.returnValue = false; }
         }
	  e.preventDefault();
	  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;}
   }    

}

confEmail.addEvent(window, 'load', confEmail.init);
