/* This function prevents spam robots from gathering email addresses      */
/* Set up the link as <a href="#" address1="username" address2"domain">Contact</a> */
/* If Contact is left blank, it will be replaced by email address         */
/* Include this line in head section of html file: <script language="JavaScript" src="EssentialScript.js"> </script>   */
/* Script provided by Mark Reed, June 2006    */
function view_address() {
  if (document.getElementsByTagName) {
    var a = document.getElementsByTagName("a");
    var i;
    for (i = 0; i < a.length; i++)  {
      var part1 = a[i].getAttribute("address1");
      var part2 = a[i].getAttribute("address2");      
      if (typeof part1 == 'string' && typeof part2 == 'string') {
        if (part1.length > 1 && part2 .length > 1) { 
          real_address = part1 + "@" + part2
          a[i].setAttribute("href", "mailto:" + real_address);
          var tag = a[i].innerHTML;
          if (typeof tag == 'string') {
            if (tag.length < 1 || tag == ' ') {
              a[i].innerHTML = real_address;  
            }
          }
        }
      }
    }
    /* Added this section to insert business email address into forms for paypal buttons - for the purpose of hiding the address */
    var forms = document.getElementsByTagName("form");
    for(var i = 0; i < forms.length; i++) {
      var form = forms[i];
      if(form.getAttribute("action").substring(0, 22) == "https://www.paypal.com") {
      	if (form.business) {
	  form.business.value = "treasurer@delawarephotographicsociety.org";
	}
      }
    }
  }
}

/* This line runs the script when page is loaded */
/* If there is an onload statement in the body tag, you must add view_address to the list */
window.onload = function() { view_address(); }
