function listenToClicks() {
	var domains    = ['wsb.bydgoszcz.pl','wsb.chorzow.pl','wsb.gda.pl','wsb.gdynia.pl','wsb.opole.pl','wsb.poznan.pl','wsb.szczecin.pl','wsb.torun.pl','wsb.wroclaw.pl','emba.wsb.pl','franklinmba.pl','efs.pl','wsb.pl','portal.wsb.pl','studiamba.wsb.pl'];

	if (document.getElementsByTagName) {
    var aTags = document.getElementsByTagName('a');

    ANCHOR:
    for (var i = 0; i < aTags.length; i++) {
      if (aTags[i]=="")                                         {continue ANCHOR; }
      if (typeof aTags[i].hostname == "undefined")              {continue ANCHOR; }
      if (aTags[i].protocol.indexOf("javascript") != -1)        {continue ANCHOR; }
      if (aTags[i].protocol.indexOf("mailto") != -1)            {continue ANCHOR; }

      DOMAIN:
      for (var j = 0; j < domains.length; j++) {
				var domain = domains[j].replace('\.','\\.');
				var regexp = new RegExp('http(s)?://(www\.)?'+domain,'i');

				if(regexp.test(aTags[i].href)) {
            if (!regexp.test(window.location.href)){ // check to see if we are on the domain of the anchor tag, if not use linker
            startListening(aTags[i],"click",useLinker);         continue ANCHOR;

          } else {continue ANCHOR; } // this anchor must be for the same domain, don't do anything special for this.
        }
      }

     continue ANCHOR; // this anchor tag didn't match a domain from our array, it must be an external link
    }
	}
}

// creates an event handler using browser specific method (addEventListener or AttachEvent) for our 3 functions below.
function startListening (obj,evnt,func) {
  if (obj.addEventListener) {
    obj.addEventListener(evnt,func,false);
  } else if (obj.attachEvent) {
    obj.attachEvent("on" + evnt,func);
  }
}

// useLinker:  calls _link(); on the href in the <a> tag in question
function useLinker (evnt) {

  if (typeof(_gaq) == "object") { // make sure gaq is defined
		var e = (evnt.srcElement) ? evnt.srcElement : this; //for IE8, it can't use normal events...

		if(e.target == "_blank"){ //if target="_blank" get url manually and open new window
			_gaq.push(function() {
			  var pageTracker = _gat._getTrackerByName('zbiorcze');
			  window.open(pageTracker._getLinkerUrl(e.href));
			});
		} else { //else push link to google and redirect current page to new one
	  	_gaq.push(['zbiorcze._link', e.href]);
		}

    if (evnt.preventDefault){ evnt.preventDefault();}
		evnt.returnValue = false;
	}
}

startListening(window, 'load', listenToClicks); // register an event listener to run the script when the load event fires.
