function isGovernmentURL(url) {

  var government_hostnames = new Array(  // add gov't ip addresses and hostnames here
    '204.193.232.34',
    '204.193.232.41'
  );

  var isGovernment = false;

  var p_scheme = "([A-Za-z][A-Za-z0-9+.-]*)";
  var slash = "\/";
  var user = "[A-Za-z0-9$_.+!*'(),\"%-]+";
  var password = "[A-Za-z0-9$_.+!*'(),\"%-]+";
  var p_host = "([A-Za-z0-9.-]+)";
  var opt_p_port = "(:[0-9]+)?";

  if ( typeof isGovernmentURL.javascript_url == 'undefined' ) {
    isGovernmentURL.javascript_url = new RegExp( "^javascript:" );
  }

  if ( isGovernmentURL.javascript_url.test(url.strip()) ) {
    return true;  // do nothing with javascript: URLs
  }

  if ( typeof isGovernmentURL.common_syntax == 'undefined' ) {
    isGovernmentURL.common_syntax = new RegExp( "^" + p_scheme + ":" + slash.times(2) + "(" + user + ":" + password + "@)?" + p_host + opt_p_port + "([?/].*)?" + "$" );
  }

  if ( isGovernmentURL.common_syntax.test(url.strip()) ) {
    //url_scheme = RegExp.$1.toLowerCase();
    url_host = RegExp.$3.toLowerCase();

    for (var i = 0, len = government_hostnames.length; i < len; ++i) {
      if ( government_hostnames[i] == url_host ) {
        isGovernment = true;
      }
    }

    if ( ! isGovernment ) {
      domain_labels = url_host.split('.').reverse();
      if ( domain_labels.length > 1 ) {
        if ( (domain_labels[0] == 'gov') || (domain_labels[0] == 'mil') || (domain_labels[0] == 'us' && domain_labels[1] == 'fed') ) {
          isGovernment = true;
        }
      }
    }
    return isGovernment;

  } else {  // not common_syntax

    if ( typeof isGovernmentURL.other_syntax == 'undefined' ) {
      isGovernmentURL.other_syntax = new RegExp( "^" + p_scheme + ":" + "(.+)" + "$" );
    }
    if ( isGovernmentURL.other_syntax.test(url.strip()) ) {
      url_scheme = RegExp.$1.toLowerCase();
      if ( url_scheme == 'mailto' ) {
        isGovernment = true;
      }
    } else {  // no scheme--relative URL
      isGovernment = true;
    }
  }

  return isGovernment;
}

function NotifyOffSite(url) {
  var MsgText = "You are about to leave this U.S. Department of Commerce web site for a destination outside of the Federal Government."
    + " You may wish to review each privacy notice since their information collection practices may differ from ours."
    + " In addition, our linking to these sites does not constitute an endorsement of any products or services."
    + " This link will take you to:"
    + "\n\n" + url
    + "\n\nClick OK if you wish to continue to the web site, otherwise click cancel to return to our site.";
  if ( confirm(MsgText) ) {
    window.location.href=url;
  }
}

function addOffSiteNotification() {
  var anchors = $$('a[href]');
  for (var i = 0, len = anchors.length; i < len; ++i) {
    if (!isGovernmentURL(anchors[i].readAttribute("href"))) {
      anchors[i].writeAttribute("target", null);
      anchors[i].writeAttribute("href", "javascript:NotifyOffSite('" + anchors[i].readAttribute("href") + "')");
    }
  }
}

Event.observe(window, 'load', function() {
  addOffSiteNotification();
});
