/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

jQuery.extend(
  jQuery.expr[ ":" ],
  {
    /*
      /:\/\// is simply looking for a protocol definition.
      technically it would be better to check the domain
      name of the link, but i always use relative links
      for internal links.
    */

    external: function(obj, index, meta, stack)
    {
      return !obj.href.match(/^mailto\:/) && (obj.hostname != location.hostname);
    },

    internal: function(obj, index, meta, stack)
    {
      return obj.href.match(/^mailto\:/) || (obj.hostname == location.hostname);
    }
  }
);

jQuery(document).ready(function() {
    jQuery('a:external').addClass('external');

    jQuery('a:external').click(function() {
        if(jQuery(this).attr('id') != 'login-button') {
            var link = $(this).attr('href');

            $content = '<div class="external-warning">';
            $content += '<p><span class="error">WARNING!</span> You are leaving the Citizens Bank & Trust website. Links that may be accessed via this sire are for the convenience of informational purposes only. Any products and services accessed through this link are not provided or guaranteed by Citizens Bank and Trust.</p>';
            $content += '<p>The site you are about to visit may have a privacy policy that is different than Citizens Bank & Trust. Please review their privacy policy. Citizens Bank & Trust does not endorse the content contained in these sites, nor the organizations publishing those sites, and hereby disclaims any responsibility for such content.</p>';
            $content += '<p class="redirect-url">You are being redirected to:<br /><br /><strong>'+(link)+'</strong></p>';
            $content += '<p class="redirect-url">Are you sure you want to proceed?</p></div>';
            $($content).dialog({
                title: "Third Party Site Disclaimer",
                modal : true,
                resizable: false,
                width: 700,
                overlay: {
                },
                buttons: {
                    'Continue': function() {
                        $(this).dialog('close').remove();
                        window.open(link);
                    },
                    'Cancel': function() {
                        $(this).dialog('close').remove();
                        return false;
                    }
                }
            });
            return false;
        }
    });
});
