function jConfirm(url,msg) {
	var $d = jQuery('<div id="dialog" title="Confirmation Required"></div>');

	$d.html(msg).dialog({
		closeOnEscape: true,
		modal: true,
		width: '500',
		height: 'auto',
		minHeight: '50',
		buttons: {
			'Confirm': function() {
				$d.dialog('close');
				window.open(url);
			},
			'Cancel': function() {
				$d.dialog('close');
			}
		}
	});

	$d.dialog("open");
}

jQuery(document).ready(function() {
	jQuery("a[href$='.pdf']").click(function (e){
		var string = jQuery(this).attr('href');
		if (!string.match(/http\:\/\//i)) {
			if (string.indexOf(window.location.hostname) == -1) {
				string = window.location.hostname + '/' + string;
			}
			string = 'http://' + string;
		};
		e.preventDefault();
		jConfirm(string,"IMPORTANT: You are about to load a PDF file, is this what you expected?");
	});

	jQuery("a[href*='http://']").click(function (e){
		var string = jQuery(this).attr('href');
		if (!string.match(/www\.investmentuk\.org/i)) {
			e.preventDefault();
			jConfirm(string,"IMPORTANT: Please be aware that you are now leaving the IMA web site. The views expressed and any advice subsequently offered is not that of the Investment Management Association. If you would like to return to the IMA web site from an external link, please click on the \"back\" button or re-enter our site address. If you do not wish to leave our site, choose another link from the menu. If you would like to continue, please click Yes below.");
		};
	});
});
