var IE = document.all?true:false

var INFORMATION='information';
var NO_ICON='no_icon';
var WARNING='warning';
var ERROR='error';
var PERMISSION='permission';
var CALENDAR='calendar';
var HIDE_LONG=10000;
var NO_HIDE=-1;
var NORMAL_TOP = 170;
var CALENDAR_TOP = 150;
var FADE_ON=1;
var FADE_OFF=0;
var FADE=FADE_ON;
var FADE_TIME=50;

function showMessage(msg, type, hide, top, width) {
  var sm = document.getElementById("SystemMessage");
  
  if (hide==null) {
    hide=HIDE_LONG;
  } else {
    hide = NO_HIDE;
  }
  if (top==null)
    top=NORMAL_TOP;
    
  if (width==null)
    width=380;
  else
    sm.style.width=width+'px';

  if(IE) {
    var poz_y = (document.documentElement.scrollTop + top) + 'px';
  } else {
    var poz_y = (window.pageYOffset + top) +'px';
  }
  var poz_x = ((document.body.clientWidth/2)-(width/2)) +'px';
  
  var was_visible=false;
  if (document.getElementById("SystemMessage").style.display=="block")
    was_visible=true;

  sm.style.display = "none";
  sm.style.opacity = 1;
  sm.style.filter = 'alpha(opacity=100)';
  sm.style.left = poz_x; sm.style.top = poz_y;

  clearTimeout(sm.czas);
  
  if (was_visible && hide!=NO_HIDE && sm.no_hide!=NO_HIDE && sm.ile_komunikatow<2) {
    sm.ile_komunikatow++;
    document.getElementById('SystemMessageTxt').innerHTML += "<br/><br/>"+msg;
  } else {
    sm.ile_komunikatow=0;
    if (FADE==FADE_ON && hide!=NO_HIDE) {
      sm.style.opacity = 0;
      sm.style.filter = 'alpha(opacity=0)';
      sm.alfa = 0;
      sm.przezroczystosc = setTimeout('fadeIn(\'SystemMessage\')', FADE_TIME);
    }
    document.getElementById('SystemMessageTxt').innerHTML = msg;
  }
  sm.no_hide=hide;
  
  if (type=='') type='information';
  document.getElementById('SystemMessageIco').src="../gfx/dialog-"+type+".png";

  if (type=='no_icon')
    document.getElementById('SystemMessageIco').style.display='none';
  else
    document.getElementById('SystemMessageIco').style.display='block';
  sm.style.display = "block";

  if (hide!=NO_HIDE)
    sm.czas = setTimeout('hideDivTime(\'SystemMessage\', 0)', hide);
}
function HideMessage() {
  var div = document.getElementById('SystemMessage');
  div.style.display = "none";
  if (FADE==FADE_ON) {
    div.style.opacity = 0;
    div.style.filter = 'alpha(opacity=0)';
  }
}
function hideDivTime(d, t) {
  var div = document.getElementById(d);

  div.style.display = "none";

  if (t==0)
    clearTimeout(div.czas);
  else
    div.czas = setTimeout('showHideDivTime("'+d+'", 0)', t);
}
function fadeIn(d) {
  var div = document.getElementById(d);

  div.alfa = div.alfa+40;

  div.style.opacity = div.alfa/100;
  div.style.filter = 'alpha(opacity=' + div.alfa + ')';

  if (div.alfa>=100) {
    clearTimeout(div.przezroczystosc);
    div.alfa=0;
  } else
    div.przezroczystosc = setTimeout('fadeIn(\''+d+'\')', FADE_TIME);
}


function LoadingOff() {



document.getElementById('loading2').style.display = "none";
document.getElementById('covering').style.display = "none";
}
function LOff() {
  var mc = document.getElementById('mainContainer');
//  clearTimeout(mc.loadingDelay);
  LoadingOff();
}

function LoadingOn() {

var rozmiar = getPageSize();


if(IE) {
  var poz_y = (rozmiar[3]/2) + document.documentElement.scrollTop + 'px';
} else {
  var poz_y = (rozmiar[3]/2) + window.pageYOffset + 'px';
}

var poz_x = ((rozmiar[2]/2)-155) +'px';

document.getElementById("loading2").style.top = poz_y;
document.getElementById("loading2").style.left = poz_x;
document.getElementById('loading2').style.display = "block";
Cover();
document.getElementById('covering').style.display = "block";

}
function LOn() {
LoadingOn();
  //var mc = document.getElementById('mainContainer');
  //mc.loadingDelay = setTimeout('', 50);
}

function getPageSize(){

  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY) {
     xScroll = document.body.scrollWidth;
     yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
     xScroll = document.body.scrollWidth;
     yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
     xScroll = document.body.offsetWidth;
     yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;
  if (self.innerHeight) {   // all except Explorer
     windowWidth = self.innerWidth;
     windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
     windowWidth = document.documentElement.clientWidth;
     windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
     windowWidth = document.body.clientWidth;
     windowHeight = document.body.clientHeight;
  }

  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
     pageHeight = windowHeight;
  } else {
     pageHeight = yScroll;
  }

  // for small pages with total width less then width of the viewport
  if(xScroll < windowWidth){
     pageWidth = windowWidth;
  } else {
     pageWidth = xScroll;
  }


  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
  return arrayPageSize;
}

function Cover() {
var wymiary = getPageSize();
document.getElementById('covering').style.height = wymiary[1] + 'px';
document.getElementById('covering').style.width = '100%';
}
function sP(e) {
  e=e||event;
  e.stopPropagation? e.stopPropagation() : e.cancelBubble=true;
}

