var URL = '/';
function $(el){
return typeof(el) == 'string' ? document.getElementById(el) : el;
}
function getChildren(el, a, v) {
	var ar = new Array();
	var ac = $(el).getElementsByTagName('*');
	var s = '';
	for (c=0; c<ac.length; c++){
	  if (v? (ac[c][a] == v || ac[c].getAttribute(a) == v) : (ac[c][a] || ac[c].getAttribute(a))) {
		ar.push(ac[c]);
	  }
	}
	return ar;
}
function d(){
   console.debug(arguments);
}

function addEvent(obj, type, fn) {
  if (obj.addEventListener) {
    obj.addEventListener(type, fn, false);
  } else if (obj.attachEvent) {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() {obj["e"+type+fn](window.event); }
    obj.attachEvent("on"+type, obj[type+fn]);
  }
}
function eventHander(e) {
   var el;
   if(window.event && window.event.srcElement) el = window.event.srcElement;
   if(e && e.target) el = e.target;
   if(!el)  return;
   (e.preventDefault) ? e.preventDefault() : (e.returnValue = false);
   return el;
}
function isDef(el) {
  return (el != "undefined" && el != null)
}
function cDOM(name, attrs) {
  var i = 1;
  var el = document.createElement(name);

  if(isDef(attrs[0]) && typeof(attrs[0]) != "string") {
    for(k in attrs[0]) {
      if(k == "style")
        el.style.cssText = attrs[0][k];
      else if(k == "class")
        el.className = attrs[0][k];
      else if(k == 'inner')
         el.innerHTML = attrs[0][k];
      else
        el.setAttribute(k, attrs[0][k]);
    }
    for(i; i < attrs.length; i++) {
      var n = attrs[i];
      if(isDef(n)) {
        if(typeof(n) == "string")
          n = document.createTextNode(n);
        el.appendChild(n);
      }
    }
  } else {
    var n = attrs[0];
    if(isDef(n)) {
      n = document.createTextNode(n);
      el.appendChild(n);
    }
  }
  return el;
}
var DIV = function(){return cDOM.apply(this,['DIV',arguments]);};
var IMG = function(){return cDOM.apply(this,['IMG',arguments]);};
var INPUT = function(){return cDOM.apply(this,['INPUT',arguments]);};
var A = function(){return cDOM.apply(this,['A',arguments]);};
var B = function(){return cDOM.apply(this,['B',arguments]);};
var P = function(){return cDOM.apply(this,['P',arguments]);};
var SPAN = function(){return cDOM.apply(this,['SPAN',arguments]);};

$A = function(){

}

Function.prototype.bind = function(obj){
   var fn = this, args = [];

   for (var i = 0; i < arguments.length-1; i++) args[i] = arguments[i+1];
   return function(){
      return fn.apply(obj, args);
   };
}
Function.prototype.bindAsEventListener = function(obj){
   var fn = this, args = [];
   for (var i = 0; i < arguments.length-1; i++) args[i] = arguments[i+1];
   return function(event){
      return fn.apply(obj, [event||window.event].concat(args));
   };
}

function changeBox(el){
   var link = el.options[el.selectedIndex].value;
   if(link)
      location = link;
}
function addHistBack(){
   var b = $('hisBack');
   if(b){
      b.style.display='block';
      addEvent(b,'click',function(){history.go(-1);});
   }
   b = $('hisPrint');
   if(b){
      b.style.display='block';
      addEvent(b,'click',printPage);
   }
}

function printPage(){
         MK.Table.show(true);
         if(typeof(FAQ) != 'undefined')
            FAQ.showAll();
          window.print();
      setTimeout("printPageEnd()",1000);
}
//dla firefoxa musi byc opuznienie 
function printPageEnd(){
         MK.Table.show(false);
         if(typeof(FAQ) != 'undefined')
            FAQ.hideAll();
}

MK = {};
MK.shell ={
   point : function(x,y){
      return {x:x,y:y};
   },
   scrollOffset : function(){
      
      var x = 0;
      var y = 0;
      if( typeof( window.pageYOffset ) == 'number' ) {
         y = window.pageYOffset;
         x = window.pageXOffset;
      }else
         if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
            y= document.body.scrollTop;
            x= document.body.scrollLeft;
         }else
            if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
             //IE6
             y = document.documentElement.scrollTop;
             x= document.documentElement.scrollLeft;
         }
      return this.point(x,y);
   },

   screenSize : function() {
      var x = 0;
      var y = 0;
      if (window.innerHeight >= 0) {
         x = window.innerWidth;
         y = window.innerHeight;
      } else if (document.documentElement) {
         x = document.documentElement.clientWidth;
         y = document.documentElement.clientHeight;
      } else if (document.body.clientHeight >= 0) {
         x = document.body.clientWidth;
         y = document.body.clientHeight;
      }
      return this.point(x,y);
   },
   pageSize : function() {
      var x = 0;
      var y = 0;
      var test1 = document.body.scrollHeight;
      var test2 = document.body.offsetHeight
      var test3 = document.documentElement.offsetHeight;
      var y = test1;
      if(y < test2){
         y = test2;
      }
      if(y < test3){
         y = test3;
      }
      if (test1 > test2) {
         // all but Explorer Mac
         x = document.body.scrollWidth;
      }
      else{
         // Explorer Mac;
         //would also work in Explorer 6 Strict, Mozilla and Safari
         x = document.body.offsetWidth;
      }
      return this.point(x,y);
   }
}
MK.Table = {
   dom: {},
   obj:{},
   org:{},
   init : function(){
      if(!$('body'))
         return;
      var temp = getChildren($('page'),'className','popupTable');
      var h5,p,a,b;
      for(var i = 0;i< temp.length; i++){
         this.obj[i] = temp[i].cloneNode(true);
         h5 = this.obj[i].getElementsByTagName('h5')[0];
         a = A({href:'#a',inner:h5.innerHTML});
         p = P();
         b = B();
         
         b.appendChild(a);
         p.appendChild(b);
         addEvent(a,'click',MK.Table.open.bind(this,i));
         temp[i].parentNode.insertBefore(p,temp[i]);
         temp[i].style.display = 'none';
         this.org = temp;
      }
   },
   open: function(index){
      min = 20;
      var viewer = $('viewerTable');
      var body = $('viewerTableBody');
      viewer.style.left = (MK.shell.pageSize().x - 700)/2 + 'px';
      viewer.style.top = (20 + MK.shell.scrollOffset().y ) + 'px';
      viewer.style.width = '700px';
      viewer.style.height = '500px';
      body.innerHTML = ' ';
      body.appendChild(this.obj[index].cloneNode(true));
      this.obj[index].style.display = 'block';
      MK.Mask.show();
      $('viewerTable').style.visibility = 'visible';
      return false;

   },
   close : function(e){
      $('viewerTable').style.visibility = 'hidden';
      MK.Mask.hide();
   },
   show: function(opt){
      for(var i = 0;i< this.org.length; i++){
         if(opt){
            this.org[i].style.display = 'block';
            this.selectApp(this.org[i],true);
         }else{
            this.org[i].style.display = 'none';
            this.selectApp(this.org[i],false);
         }
      }
   },
   selectApp: function(cont,show){
      var table = getChildren(cont,'tagName','TABLE');
      for(var i = 0;i<table.length;i++){
         if(table[i] && table[i].className == 'app' && $('appImgL') && $('appImgD')){
	    if(show){
               this.addText(table[i],'rec',$('appImgL').getAttribute('alt'));
               this.addText(table[i],'hirec',$('appImgD').getAttribute('alt'));

            }else{
               this.addText(table[i],'rec','&nbsp;');
               this.addText(table[i],'hirec','&nbsp;');
            }
         }
      }
   },
   addText: function(obj,klass,text){
	alert(text);
      var c = getChildren(obj,'className',klass);
      for(var a in c){
         c[a].innerHTML = text;
      }
   },
   addImg: function(obj,klass,img){
      var c = getChildren(obj,'className',klass);
      for(var a in c){
         c[a].appendChild(img);
      }
   }

}

MK.Mask = {
   show: function(){
      inputSelect(false);
      var mask = $('pageMask');
      mask.style.display = 'block';
      var ua = navigator.userAgent;
      var f = "MSIE 6";
      if ((i = ua.indexOf(f)) >= 0) {
         mask.style.top = $('container').offsetTop;
         mask.style.marginLeft = $('container').offsetLeft;
         mask.style.width = $('container').offsetWidth;
         mask.style.height = $('container').offsetHeight;
      }
   },
   hide: function(){
      $('pageMask').style.display = 'none';
      inputSelect(true);
   }
}

function inputSelect(hide){
      var el =document.body.getElementsByTagName('SELECT');
      for(var i = 0 ;i < el.length;i++)
         if(hide)
            el[i].style.visibility = 'visible';
         else
            el[i].style.visibility = 'hidden';
}


function hideTables(){
   
   MK.Table.init();

}
addEvent(window,'load',function(){
   addEvent($('select_appl'),'change',select_appl);
   addHistBack();
   hideTables();
   //popupPrepare();
});

function popupPrepare(){
var popu=$("popupmain");
addEvent(popu,"click",closepopup);
}

function closepopup(){
this.style.display="none";
}

function select_appl(){
   var value = this.options[this.selectedIndex].value;
   if(value != 0){
      location = URL + "appl/"+value;
   }
}

function fixFlashPosition(){
var container = document.getElementById('container');
var body = document.getElementsByTagName('body')[0];

container.style.display="none";
//body.style.backgroundColor="#275c92";
//body.style.backgroundImage="url('')";
//body.style.backgroundAttachment="nn";
}

function closeFlash(){
var body = document.getElementsByTagName('body')[0];
var container = document.getElementById('container');
var flash=document.getElementById('flashslideshow');


//body.style.backgroundImage="../img/tlo.gif";
container.style.display="block";
flash.style.display="none";
}

