var alertStr="Please Note: You have clicked on a link to a web site maintained by a third party and are about to leave the California Avocado Commission's web site. The Commission provides this link as a convenience to you; the link should not be considered an endorsement by the Commission of the third-party web site or the company who owns it. The Commission is not responsible for the quality, safety, completeness, accuracy or nature of the content of the linked web site. To return to www.avocado.org, simply close the new browser window.";
var confStr=alertStr+"\n\nClick 'OK' to continue, or 'Cancel' to return to www.avocado.org now.";
function  extLink() {
  return confirm(confStr);
}

function  extLinkOut(loc) {
  if(confirm(confStr)){
     nw = window.open();
     nw.location = loc;
  }
}

// Js created to automate the adding of the extLink func to outbound urls.
$(document).ready(function(){

   var page_links_array = $("body").find('a');  // Array of all links on the page.
   var pattern_samesite = new RegExp( location.hostname ); //test if href in same site
   var pattern_cac = /avocado\.org|scawt\.com|avocadosource\.com|californiaavocado\.com|javascript|mailto/; //known allowed site/protocol
   var pattern_extlink = /extLink|window\.open/; // legacy a tag may already have onclick
   var i = 0;
   
   // Iterate over the links and check for a matching pattern.
   for (i = 0; page_links_array.length > i; i++) {
      var e  = page_links_array.get(i);
      // If matching pattern is found we'll add the extLinkOut() func.
      if ((!pattern_cac.test(e.href)) && (!pattern_samesite.test(e.href)) && (!pattern_extlink.test(e.onclick)) && (!$(e).attr('name') && $(e).attr('href') == '')) {
         if (e.target){e.target = null;}
         $(e).attr('href', 'javascript:extLinkOut(\''+e.href+'\')'); //assign to href because IE doesn't allow assigned onclick
      }
   }
});
