var mlink = '';
var timer = null;
$(document).ready(function() {
 
  // Creating custom :external selector
  $.expr[':'].external = function(obj){
      return !obj.href.match(/^mailto\:/) && !obj.href.match(/\.gov/);
  };
 
  // Add 'external' CSS class to all external links
  $('a:external').addClass('external');
 
  $('.external').click(function() {
    var link = $(this).attr('href');
 	mlink = link;
	timer = setTimeout('leaveSite()', 10000);
	
    $('<div>You are currently exiting to a site that is not part of the government(.gov) domain. Web sites are places where diverse groups of people interact, so please be aware that you will be subject to a wide variety of experiences beyond our control. Always use good judgment when using these platforms and when following links to other web sites.<br/> <br/>You are headed towards: <br /> '+(link)+' <br /></div>').dialog({
      title: "External Link",
      modal : true,
      overlay: {
        backgroundColor: '#000',
        opacity: 0.5
      },
      buttons: {
        'Okay': function() {
			clearTimeout(timer);
          $(this).dialog('close').remove();
          window.location.href = link;
        },
        'Cancel': function() {
			clearTimeout(timer);
          $(this).dialog('close').remove();
          return false;
        }
      }
    });
 
    return false;
  });
});
function leaveSite()
{

	window.location.href = mlink;

}

	//clear text fields
	function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
	}

