function fcenter() {
  ob = document.getElementById('loading');
  ob.style.display = "block";
  
  width = document.body.offsetWidth;
  height = document.body.offsetHeight;
  
  wh = alertSize();
  scr = getScrollXY();
  w = Math.min(wh[0], width);
  
  widthCont = ob.offsetWidth;
  heightCont = ob.offsetHeight;
  
  ob.style.left = (wh[0]/2+scr[0]-widthCont/2)+'px';
  ob.style.top = (wh[1]/2+scr[1]-heightCont/2)+'px';
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth, myHeight ];
}


function dodajZdarzenie(odnosnik, zdarzenie, funkcja) {
	if (odnosnik.addEventListener) {
		odnosnik.addEventListener(zdarzenie, funkcja, false);
	}
	else {
		odnosnik.attachEvent("on"+zdarzenie, funkcja);
	}
}

function searchLoading() {
  array = new Array('show_player','show_tribe','show_village','tribe_pl_c','villages_cont','vill_war_s','vill_war_s_m');
  ile2 = array.length;
  wyrreg = /(([\w]|[\d]|[-_])*)\.php/;
  
  arr = document.getElementsByTagName("a");
  ile = arr.length;
  for (i=0;i<ile;i++) {
    attr = arr[i].getAttribute('href');
    if (attr) {
      file = attr.match(wyrreg);
      if (file) {
        for (j=0;j<ile2;j++) {
          if (file[1]==array[j]) {
            dodajZdarzenie(arr[i], 'click', fcenter);
          }
        }
      }
    }
  }  
}