

<!--
function K2TopLayer(id, type, variant, srcEl, w, h) {
 if (arguments.length>0) {
  this.init(id, type, variant, srcEl, w, h)
 }
}
K2TopLayer.prototype.init = function (id, type, variant, srcEl, w, h) {
 this._name = 'K2TopLayer';
 this.id = id;
 this.type = type;
 this.srcEl = srcEl;
 this.variant = variant;
 this.isShowing = false;
 this.w = w;
 this.h = h;
 this.destinationNode = document.forms['aspnetForm'];
 this.sourceNode = (variant != 'HTMLIFrame') ? srcEl.parentNode : null;
 if (document.documentElement) { 
  this.area = document.documentElement;
 } else {
  this.area = document.body;
 }
 this.fixedTop = 100; //px
 this.tmpFixedTop = 0;
 this.setSmoothly = false;
 this._K2TopLayer = null; /* K2TopLayer */
 this._K2TopLayer = this.getTopLayer();
 this._K2ButtonClose = this.getButtonClose();
 this._K2Layer = this.getLayer();
 this._K2TopLayer._K2Layer = this._K2Layer;
 this._K2Trigger = this.getTrigger();
 window._K2TopLayer = this;
 this.render();
}
K2TopLayer.prototype.render = function () {
 this._K2Layer.insertBefore(this._K2ButtonClose, this._K2Layer.childNodes[0]);
 this.destinationNode.insertBefore(this._K2Layer, this.destinationNode.childNodes[0]);
 this.destinationNode.insertBefore(this._K2TopLayer, this.destinationNode.childNodes[0]);
 if (this.type == 'HTMLImage') {}
 if (this.type == 'HTMLElement') document.getElementById(this.srcEl.id).style.display = 'block';
 if (this.type == 'HTMLIFrame') document.getElementById(this.id+'_iframe').src = this.srcEl;
 this.refresh();
}
K2TopLayer.prototype.refresh = function () {
 this.resizeTopLayer();
 this.setLayerPosition();
}
K2TopLayer.prototype.resizeTopLayer = function () {
 if (this._K2TopLayer.offsetWidth != this.area.scrollWidth-1 || this._K2TopLayer.offsetHeight != this.area.scrollHeight-1 )
 {
  this._K2TopLayer.style.width = 0;
  this._K2TopLayer.style.height = 0;
  this._K2TopLayer.style.width = this.area.scrollWidth-0.1 + 'px';
  this._K2TopLayer.style.height = this.area.scrollHeight-0.1 + 'px';
 }
}
K2TopLayer.prototype.resizeLayer = function () {
 var frame = document.getElementById(this.id+'_iframe');
 var frameDoc = frame.contentWindow.document;
 if (frameDoc.documentElement) { 
  var frameBody = frameDoc.documentElement;
 } else if (frameDoc.body) {
  var frameBody = frameDoc.body;
 } else {
  var frameBody = null;
 }
 if (frameBody != null)
 {
  if (frameBody.clientHeight < frameBody.scrollHeight) frame.style.height = frameBody.scrollHeight+'px';
 }
}
K2TopLayer.prototype.setLayerPosition = function () {
 if (this.type == 'HTMLIFrame') this.resizeLayer();
 if ((Math.abs(this.area.scrollTop + this.fixedTop - this._K2Layer.offsetTop) > 3)
  || (Math.abs(this.area.clientWidth / 2 - this._K2Layer.offsetWidth / 2 - this._K2Layer.offsetLeft) > 3)) {
/*
 if (this.setSmoothly)
 {
  if (this.area.clientHeight > this._K2Layer.offsetHeight + this.fixedTop) {
   if(this._K2Layer.offsetTop != Math.round(this.area.scrollTop + this.fixedTop)) {
    this._K2Layer.style.top = Math.round(this._K2Layer.offsetTop + (this.area.scrollTop + this.fixedTop - this._K2Layer.offsetTop) / 2) + 'px';
   }
  } else {
   this._K2Layer.style.top = this.fixedTop + 'px';
  }
  if(this._K2Layer.offsetLeft != Math.round(this.area.clientWidth / 2 - this._K2Layer.offsetWidth / 2)) {
   this._K2Layer.style.left = Math.round(this._K2Layer.offsetLeft + (this.area.clientWidth / 2 - this._K2Layer.offsetWidth / 2 - this._K2Layer.offsetLeft) / 4) + 'px';
  }
 } else {
*/
  if (this.area.clientHeight > this._K2Layer.offsetHeight + this.fixedTop) {
   this._K2Layer.style.top = this.area.scrollTop + this.fixedTop + 'px';
  } else {
    this.tmpFixedTop = (this.tmpFixedTop == 0) ? this.area.scrollTop+20 : this.tmpFixedTop;
    this._K2Layer.style.top = this.tmpFixedTop + 'px';
  }
  this._K2Layer.style.left = this.area.clientWidth / 2 - this._K2Layer.clientWidth / 2 + 'px';
/* } */
 }
}
K2TopLayer.prototype.remove = function () {
 clearInterval(this._K2Trigger);
 if (this.type == 'HTMLElement') {
  var el = document.getElementById(this.srcEl.id);
  el.style.display = 'none';
  this.sourceNode.appendChild(el);
  //this.destinationNode.insertBefore(el,this.destinationNode.childNodes[0]);
 } else if (this.type == 'HTMLImage') {
 } else if (this.type == 'HTMLIFrame') {
 }
 this.destinationNode.removeChild(this._K2Layer);
 this.destinationNode.removeChild(this._K2TopLayer);
}
K2TopLayer.prototype.getTopLayer = function () {
 var tl = document.createElement('div');
 tl.id = this._name + '_' + this.id;
 tl.className = this._name;
 return tl;
}
K2TopLayer.prototype.getLayer = function () {
 var el = document.createElement('div');
 el.id = 'K2Layer_'+this.id;
 el.className = 'K2Layer ' + this.type + ' ' + this.variant + ' K2Layer_' + this.variant;
 if (this.type == 'HTMLElement') {
  if (!this.srcEl.className.match(/K2LayerElement/)) this.srcEl.className += ' K2LayerElement';
//  this.srcEl.title = 'zamknij';
//  this.srcEl.onclick = function() {window._K2TopLayer.remove() }
  el.appendChild(this.srcEl);
 } else if (this.type == 'HTMLImage') {
  var img = new Image();
  img.src = this.srcEl;
  if (this.w != 0) img.width = this.w;
  if (this.h != 0) img.height = this.h;
  img.onclick = function () { window._K2TopLayer.remove() }
  img.style.cursor = 'pointer';
  img.title = 'zamknij';
  el.appendChild(img);
 } else if (this.type == 'HTMLIFrame') {
  if (document.all) {
   var doc = '<ifr'+'ame src="'+this.srcEl+'" style="border:0px;" width="' + this.w + '" height="' + this.h + '" frameborder="0" name="'+this.id+'_iframe" id="'+this.id+'_iframe" class="K2LayerIFrame K2LayerElement"></ifr'+'ame>';
   el.innerHTML = doc;
  } else {
   var doc = document.createElement('iframe');
   doc.id = this.id+'_iframe';
   doc.name = this.id+'_iframe';
   doc.frameborder = 0;
   doc.width = this.w;
   doc.height = this.h;
   doc.style.border = '0px';
   el.appendChild(doc);
  }
 }
 return el;
}
K2TopLayer.prototype.getButtonClose = function () {
 var cls = document.createElement('span');
 var cl = document.createElement('a');
 var txt = 'x';
 cl.id = 'K2ButtonClose_' + this.id;
 cl.className = 'K2Button K2ButtonClose';
 cls.appendChild(document.createTextNode(txt));
 cl.appendChild(cls);
 cl.href = '#';
 cl.title = 'zamknij';
 cl.onclick = function () {
  window._K2TopLayer.remove(); return false;
 }
 return cl;
}
K2TopLayer.prototype.getTrigger = function () {
 return window.setInterval('window._K2TopLayer.refresh()',50);
}
//-->
