function promptBeforeOpening () {
  if (confirm("LEAVING THE CHILDREN'S BUREAU EXPRESS\n\nYou are about to leave the Children's Bureau Express website to go to another location that is not maintained by the Clearinghouse. The Clearinghouse takes no responsibility for and exercises no control over the views that may be represented, or the accuracy, privacy policies, copyright or trademark compliance, or the legality of any material contained on external sites.  \n\nTo proceed to the website, please select the OK button.")) {
    // confirmed: thank you, drive through
    return true;
  } else {
    // user has cancelled, don't go to link
    return false;
  }
}

/* Find a case-insensitive string within a substring (returns boolean) */
function findNoCase(substr, str) {
  var found = (str.toUpperCase().indexOf(substr.toUpperCase()) != -1);
  return found;
}

/* The following function will take every link on the page, and modify it to
** use a prompt (if appropriate)
*/
function disclaimExternalLinks(urlExclusions) {  
  // loop over all links
  for (var i=0; i < document.links.length; i++) {
    // reset some vars to their defaults
    var matchFound = false;
    var link = document.links[i];
    // loop over all exclusions
    for (var j=0; j < urlExclusions.length; j++) {
      if ( findNoCase(urlExclusions[j], link.href) ) {
        // exclusion pattern matched, set matchFound to true, and break loop
        matchFound = true;
        break;
      }
    }
    // if matchFound is false, tweak the link's attributes
    if (! matchFound ) {
      // debug output
      // document.write("<h4 style='color: blue'>(Before) onClick:" + link.onclick + " Href:" + link.href + "</h4>");
      // save a copy of any onClick that the link may have originally had
      link.originalOnclick = link.onclick;
      link.onclick = function (evt) {
      if (this.originalOnclick) {
        this.originalOnclick(evt);
      }
        return promptBeforeOpening();
      };
      // debug output
      // document.write("<h4 style='color: blue'>(After) onClick:" + link.onclick + " Href:" + link.href + "</h4>");
    }
  }
}


/* URL Exclusion Array
** URLs that have this substring should not be disclaimed
*/
urlExclusions = new Array(
  "localhost",
  "cbexpress.stage.calib.com",
  "cbexpress.dev.calib.com",
  "cbexpressredesign.stage.calib.com",
  "basis.caliber.com/cwig/ws/library/docs/gateway/SearchForm",
  ".gov",
  "mailto:",
  "excludeMeFromDisclaimer",
  "199.223.17.54",
  "local"
);
// Switch all of the document's links now
disclaimExternalLinks(urlExclusions);