var utils = {
  baseHref : '',
  ieVersion : -1,
  init : function() {

    this.getIEVersion();
    this.getBaseHref();

    $('a.popupLink').bind('click', function(e) {
      utils.popupWindow($(this).attr('href'), $(this).attr('title').replace(/[^A-z]/ig, ''), 'width=600, height=800, scrollbars');
      e.preventDefault();
    });
  },
  getIEVersion : function () {
    var rv = -1;
    if (navigator.appName === 'Microsoft Internet Explorer') {
      var ua = navigator.userAgent;
      var re = new RegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})");
      if (re.exec(ua) !== null) {
        rv = parseFloat(RegExp.$1);
      }
    }
    this.ieVersion = rv;
  },
  popupWindow : function (url, name, attributes) {
    // Append popup to the URL if it does not already exist
    var queryStringExists = false;
    if (url.match(/\?/)) {
      queryStringExists = true;
    }

    if (queryStringExists) {
      // Only append if we haven't already got the parameter popup defined
      if (!url.match(/(\?|&)popup=/)) {
        url = utils.baseHref + url + '&popup=true';
      }
    } else {
      url = utils.baseHref + url + '?popup=true';
    }

    var newWindow = window.open(url, name.replace(/[^A-z]/ig, ''), attributes);
    newWindow.focus();
  },
  getBaseHref : function () {
    var baseTags = document.getElementsByTagName('base');
    if (baseTags !== undefined && baseTags.length > 0) {
      this.baseHref = baseTags[0].href;
    }
  }
};
