// include this to use  <script src="/js/fixEmails.js"></script> 
// This file depends on js/prototype.js

// Fixes email addresses from <a class='emailFix' href="mailto_shansen_at_ismp-canada_org">email steen hansen</a>
//                         to <a class='emailFix' href="mailto:shansen@ismp-canada.org">shansen@ismp-canada.org</a>
// on hover to stop email harvesting

/* example below, if javascript is turned off then a click on the mailto will result in an non-existant link

<head>
  <script type="text/javascript" src="/js/prototype.js"></script>
  <script type="text/javascript" src="/js/fixEmails.js"></script> 
</head>

<a class='emailFix' href="mailto_shansen_at_ismp-canada_org">email steen hansen</a>
<br>
<a class='emailFixHidden' href="mailto_cmirps_at_ismp-canada_org?subject=The subject&body=The body%0A%0Anew line%A0%A0new line">email cmirps</a> DO NOT CHANGE THE VISIBLE TEXT

*/

Event.observe(window, 'load', function() {

  $$('a.emailFix').each(function(aMailto){            
    aMailto.observe('mouseover', function(event){         // add this event to all the A-emails
      s1=Event.element(event).readAttribute('href');
      s2=s1.gsub('mailto_', 'mailto:');
      s3=s2.gsub('_at_', '@');
      s4=s3.gsub('_', '.');
      Event.element(event).writeAttribute('href', s4);     // Fix the link on hover
      s5=s4.replace(/\?.*/, '')                            // Get rid of subject and or body
      s6=s5.gsub('mailto:', '');
      Event.element(event).innerHTML=s6;                    // fix visible text on hover
      Event.element(event).stopObserving();
    });
  });
  
  $$('a.emailFixHidden').each(function(aMailto){            
    aMailto.observe('mouseover', function(event){         // add this event to all the A-emails
      s1=Event.element(event).readAttribute('href');
      s2=s1.gsub('mailto_', 'mailto:');
      s3=s2.gsub('_at_', '@');
      s4=s3.gsub('_', '.');
      Event.element(event).writeAttribute('href', s4);     // Fix the link on hover
      Event.element(event).stopObserving();     
    });
  });
  
  
});


