

// include with 'addloadevent(name of function)' after the function
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/* validateContact
S. Clason, stevec@topdogstrategy.com
21 Jun 06
Checks for required fields inRZLP.com contact form
*/
function validateContact() {
  // if insufficient JavaScript support, run.
  if (!document.getElementsByTagName || !document.getElementById) {
    return false;
  }
  // If this is not the contact page, run.
  if (!document.getElementById("contactForm")) {
    return false;
  }
  // Set some variables.
  var form = document.getElementById("contactForm");
  var errFlag = 0; // set if an error is detected
  var sError = "This field must be filled in."; // 
  var sErrorMessage = "Please correct the errors and resubmit." ;
  var emailPattern = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/ ;
  
  // Load all of the input fields into an array.
  var fields = form.getElementsByTagName("input");  

  // Loop through the input fields.
  for (var i=0; i<fields.length; i++) {
    // Only process non-hidden inputs
    if (fields[i].type != "hidden") {
      el = fields[i];
      // reset the color
      el.style.color = "";
      // Check if field is blank or equal to error message
      if (el.value == "" || el.value == sError) {
        // alert(el.name + " is blank!");
        el.style.color = "red";
        el.value = sError;
        errFlag = 1;
      }
      if (el.name == "email") {
       var result = el.value.match(emailPattern);
       if (result == null) {
        // alert(el.name + " is invalid!");
        el.style.color = "red";
        el.value = "Please enter a valid email address.";
        errFlag = 1;
       }
      }
    }
  }
	
	// Check if there's a terms of service agreement.
	if (document.getElementById("copyrightAgree")) {
		// Check for approval of terms of service.		
    // validate myradiobuttons
    var agree = -1;
		var thisForm = document.forms["contactForm"];
    for (i=thisForm.copyrightAgree.length-1; i > -1; i--) {
      if (thisForm.copyrightAgree[i].checked) {
        agree = i; i = -1;
      }
    }
    if (agree != 0) {
      alert("You must agree to the terms of use to continue.");
      return false;
    }
	}
	if (errFlag == 1) {
		alert("Please correct the errors and re-submit.");
		return false;
	}
 return true;  
}

