
//this is a function to detect the event
//there is an or condition since IE and other browsers
//detect event objects differently
function getEventTarget(e) { 
e = e || window.event; 
return e.target || e.srcElement; 
} 

//this is the actual code that generates the disclaimer
function shout(e)
{
  var target = getEventTarget(e); 
  //alert('here'+target.tagName);
  //alert(target.parentNode.tagName);
  
  //do this for images
  if(target.tagName.toLowerCase() === 'img')
  {
    target = target.parentNode;
  }
  
  if(target.tagName.toLowerCase() === 'a') { 
     // Now shout the disclaimer
     var target_href = target.href.toString();
     var server_address = window.location.host.toString();
     
     //check if the target href is going to another link
     //alert(target_href);
     if(target_href.search('<?php echo DOMAIN_STRING;?>')<0 && target_href.search('mailto:')<0 && target_href.search('javascript:{}')<0 && target_href.search('wwwshop.com.au')<0)
     {
       //alert(server_address);
        if(target_href.indexOf(server_address)<0)
        {
           //if the current server addy is not found, shout a disclaimer
           var result = confirm("Thank you for visiting the Orphan Australia website. "+
                                  "You are now leaving the website.\n\nPlease note:\n"+
                                  "The information you are about to be referred to may not comply with the Australian regulatory environment. "+
                                  "Please refer to the Consumer Medicine Information (CMI) for products to "+
                                  "fully understand the terms of a product's registration in Australia.\n"+
                                  "\nThe intent of providing this material is informational and not as advice. "+
                                  "\n\nAny information provided by this source should be discussed with your healthcare "+
                                  "professional and does not replace their advice.");
           if(result==false)
           {
              //alert("false");
              if (e.preventDefault) {
              // mozilla
              e.preventDefault();
              } else {
              e.returnValue = false;
              }
           }
        }
     }
     
  }
}
