function getViewportSize()
{
 var size = [0, 0];

 if (typeof window.innerWidth != 'undefined')
 {
   size = [
       window.innerWidth,
       window.innerHeight
   ];
 }
 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
   size = [
       document.documentElement.clientWidth,
       document.documentElement.clientHeight
   ];
 }
 else
 {
   size = [
       document.getElementsByTagName('body')[0].clientWidth,
       document.getElementsByTagName('body')[0].clientHeight
   ];
 }

 return size;
}

function displayPopup(link) {
  text = '<div class="wrapper">'
  text += '<h3>Third Party Site Disclaimer</h3>'
  text += '<p class="title">You are being redirected to <strong>' + link.title + '</strong> <small>(' + link.href + ')</small>' + '</p>'
  text += '<p class="text">You are leaving the First Community Bank web site. First Community Bank';
  text += " does not provide, and is not responsible for, the web site's content or";
  text += ' performance. First Community Bank suggests that you consult the Privacy';
  text += ' Disclosure on the site for further information.</p>';
  text += '<p class="links"><a href="#" id="no_to_external" title="decline">Decline</a>&nbsp;|&nbsp;<a href="' + link.href + '" id="yes_to_external" title="continue">Continue</a></p></div>'
  
  html = '<div id="external_popup" class="external_popup">' + text + '</div>';
  html += '<script type="text/javascript" language="javascript">'
  html += 'observeExtAgree();'
  html += '</script>'
  
  el = $$('body').first();
  if(!$('external_popup')){
    el.insert({top: html});
  }
  
  div = $('external_popup');
  if(div){
    size = getViewportSize();
    div.setStyle({
      left: '150px',
      top: '40%'
    });
  }
};

function observeExtAgree() {
  yes = $('yes_to_external');
  no = $('no_to_external');

  Event.observe(yes, "click", function(e){
    $('external_popup').remove();
  });
  Event.observe(no, "click", function(e){
    $('external_popup').remove();
    Event.stop(e);
  });
  
}

function watchExternalLinks() {
  // watch the external links and display a popup when clicked
  $$('a').each(function(a){
    h = a.href;
    if( ((h.indexOf("http://") == 0) || (h.indexOf("https://") == 0)) && ((h.indexOf("localhost") == -1) && (h.indexOf("firstcommunity.net") == -1 )) ){
      // it must be external at this point, so watch it
      Event.observe(a, "click", function(e){
        Event.stop(e);
        displayPopup(a);
      });
    }
  });
}

Event.observe(window, "load", function(e){
  watchExternalLinks();
});