﻿(function($){
    $(function () {
    
    
    	var version = jQuery.browser.msie && parseInt(jQuery.browser.version) >= 6 && window["XMLHttpRequest"] ? "7.0" : jQuery.browser.version;
		var hostName = "pwcgov.org";
		$("#dialog").dialog({
			autoOpen: false,
			modal: true
		});

    
		var anchorCollection = $('a');
		anchorCollection.each(function(i){
		
			if($(this).attr('href') !== undefined)
			{
				var href = $(this).attr('href');
				if(href.indexOf('http') === 0)
				{				
					if(href.indexOf(hostName) === -1)
					{

						if(version != 7.0)
						{
							$(this).attr('onclick', 'javascript:showjQueryDialog("' + href + '"); return false;');		
							$(this).removeAttr('target').attr('href', '#');	
						}
						else
						{
							$(this).live('click', function(){
								showjQueryDialog(href);
								return false;
							});
						}
					}
				}			
			}			
		});

				
        //$("a[href^='http:']").not("[href*='" + window.location.host + "']").attr('target', '_blank');
        //$("a[href^='http:']").not("[href*='" + window.location.host + "']").attr('onclick', 'showjQueryDialog($(this).attr("href")); return false;');
    });
    

    
})(jQuery);

function showjQueryDialog(href) 
{
    jQuery("#dialog").dialog({
        buttons: {
            "Continue": function () {
                window.open(href, '_blank');
                jQuery("#dialog").dialog("close");
            },
            "Cancel": function () {	
                jQuery("#dialog").dialog("close");
            }
        }
    });
    
    jQuery("#dialog").dialog("open");
    
} 



    

