$(document).ready(function() {
 
  // Creating custom :external selector
  $.expr[':'].external = function(obj){
	  
      return !obj.href.match(/^mailto\:/)
			  && obj.href!=null                  // This condition exists for onclick() calls - javascript
			  && obj.href!='' 
	          && !obj.href.match(/^javascript/) 
			  && !obj.href.match(/^http\:\/\/entp.hud.gov/) 
			  && !obj.href.match(/^https\:\/\/entp.hud.gov/) 
			  && !obj.href.match(/^http\:\/\/blog.hud.gov/) 
			  && !obj.href.match(/^http\:\/\/hud.gov/) 
			  && !obj.href.match(/^http\:\/\/www.hud.gov/) 
			  && !obj.href.match(/^http\:\/\/www3.hud.gov/) 
			  && !obj.href.match(/^https\:\/\/www3.hud.gov/) 
			  && !obj.href.match(/^http\:\/\/www5.hud.gov/)  
			  && !obj.href.match(/^https\:\/\/www5.hud.gov/) 
			  && !obj.href.match(/^https\:\/\/www5.hud.gov/) 
			  && !obj.href.match(/^https\:\/\/hudapps.hud.gov/)  
			  && !obj.href.match(/^https\:\/\/pic.hud.gov/)  
			  && !obj.href.match(/^https\:\/\/webapps1.hud.gov/)  
			  && !obj.href.match(/^http\:\/\/lnshhq05w.hud.gov/)  
			  && !obj.href.match(/^http\:\/\/www.hudoig.gov/)  
			  && !obj.href.match(/^http\:\/\/ptp.hud.gov/)  
			  && !obj.href.match(/^http\:\/\/hwvauap407.hud.gov:8080/)  
			  && !obj.href.match(/^http\:\/\/*.hud.gov/)
			  && !obj.href.match(/^http\:\/\/[^ ]*gov/)
			  && !obj.href.match(/^https\:\/\/[^ ]*gov/)
			  && (obj.hostname != location.hostname);
  };
 
  // Add 'external' CSS class to all external links
  $('a:external').addClass('external');
 
  $('.external').click(function() {
    var link = $(this).attr('href');
 
    $('<div>You are currently leaving the www.hud.gov website, and headed towards: <br /> '+(link)+'. <br \/><br /> Are you sure you want to proceed?<\/div>').dialog({
      title: 'Leaving HUD.GOV',
	  width: 600,
      modal : true,
      overlay: {
        backgroundColor: '#000',
        opacity: 0.5
      },
      buttons: {
        'Okay': function() {
          $(this).dialog('close').remove();
          window.open(link);
        },
        'Cancel': function() {
          $(this).dialog('close').remove();
          return false;
        }
      }
    });
 
    return false;
  });
});