//sludinaajumu POPam funkcijas
var _light = document.createElement('div');
_light.className = 'white_content';
var _fade = document.createElement('div');
_fade.className = 'black_overlay';
document.body.appendChild(_light);
document.body.appendChild(_fade);
_fade.onclick = aizvertPop;

var cw = 0;
var ch = 0;
var st = 0;
var sl = 0;

function windowOnResize() {
      ch = document.documentElement.scrollHeight;
      ch = document.body.scrollHeight;
      cw = document.documentElement.scrollWidth;
      cw = document.body.scrollWidth;
      _fade.style.width = cw + 'px';
      _fade.style.height = ch + 'px';
}
windowOnResize();
window.onresize = windowOnResize;

function windowOnScroll() {
      sl = document.documentElement.scrollLeft + document.body.scrollLeft;
      st = document.documentElement.scrollTop + document.body.scrollTop;
      //_light.style.top = (st + 50) + 'px';
}
window.onscroll = windowOnScroll;

var http = false;

if(navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
      http = new XMLHttpRequest();
}

function atvertPop(url) {
      windowOnScroll();
      _fade.style.display = 'block';
      _light.style.display = 'block';
      _light.innerHTML = '<img src="/images/loadingAnimation.gif" width="208" height="13" border="0">';
      _light.style.width = '208px';
      _light.style.height = '13px';
      _light.style.background = 'none';
      _light.style.left = (cw - 208 > 0 ? cw - 208 : 0) / 2 + 'px';
      http.abort();
      http.open("GET", url, true);
      http.onreadystatechange = function() {
            if(http.readyState == 4) {
                  if(http.responseText.indexOf('slud_pop') != -1) {
                        _light.innerHTML = http.responseText;
                        popVieta(20);
                        //setTimeout('popVieta(2)', 500);
                  } else {
                        _fade.style.display = 'none';
                        _light.style.display = 'none';
                        _light.innerHTML = '';
                  }
            }
      }
      http.send(null);
}

function popVieta(x) {
      _slud_pop = document.getElementById('slud_pop');
      _w = _slud_pop.clientWidth + x;
      _h = _slud_pop.clientHeight + x;
      _light.style.width = _w + 'px';
      _light.style.height = _h + 'px';
      _light.style.left = (cw - _w > 0 ? cw - _w : 0) / 2 + 'px';
      _light.style.top = (st + 50) + 'px';
}

function aizvertPop() {
      _fade.style.display = 'none';
      _light.style.display = 'none';
      _light.innerHTML = '';
}

function epastiem(url) {
      window.location = url;
}

function epastiem_new(SIM, VER) {
      var RAA = '';
      for(var j = 0; j < SIM.length; j++) {
            b = SIM.charCodeAt(j);
            b -= (b > 91 ? 41 : 40);
            RAA += VER.charAt(b);
      }
      window.location = RAA;
}

var bildes = 0;
function atverBildi(bilde) {
      //pirmajaa reizee verot saskaita bildes
      if(bildes == 0) {
            i = 1;
            while(document.getElementById('mb' + i) != undefined) {
                  bildes++;
                  i++;
            }
      }

      for(i = 1; i <= bildes; i++) {
            document.getElementById('bilde' + i).style.display = bilde == i ? 'block' : 'none';
            document.getElementById('mb' + i).className = bilde == i ? 'bilde_akt' : 'bilde';
      }
      
      _left = 0;
      if(bildes > 5) {
            if(bilde <= 3) {
                  _left = 0;
            } else if(bilde >= bildes - 2) {
                  _left = -(bildes - 5) * 87;
            } else {
                  _left = -(bilde - 3) * 87;
            }
      }
      document.getElementById('mbTable').style.left = _left + 'px';
}

