//v1.0
//klasa do obsługi programu TV

function TvProgram(id, widthTotal, widthMargin, cols) {
  this.id = id;
  this.html = document.getElementById(this.id);
  this.widthTotal = widthTotal;
  this.widthMargin = widthMargin;
  this.cols = cols;
  this.colWidth = Math.floor((this.widthTotal - (this.cols-1)*this.widthMargin) / this.cols);
  this.firstColWidth = this.widthTotal - (this.cols-1)*(this.widthMargin+this.colWidth);
  this.date = dateOnPage?dateOnPage:jsDate;
  this.date = new Date(this.date.substr(0, 4), parseFloat(this.date.substr(5, 2))-1, this.date.substr(8, 2), this.date.substr(11, 2), this.date.substr(14, 2), this.date.substr(17, 2));
  this.zeroDate = new Date(jsDate.substr(0, 4), parseFloat(jsDate.substr(5, 2))-1, jsDate.substr(8, 2), jsDate.substr(11, 2), jsDate.substr(14, 2), jsDate.substr(17, 2));
  this.programsList = [0];
  this.programsGenres = [0];
  this.panelTop = document.getElementById(this.id+'PanelTop');
  this.panelBottom = document.getElementById(this.id+'PanelBottom');
  this.showChannelSelectors = true;
  this.debug = false;

  this.genreStoplist = new Array();
  this.attributesIcons = {};
  this.titleSeparator = ' : ';
  this.attributesIconTpl = ' <img src="<ico/>" align="top" />';
  this.initChannels = new Array();
  this.xmlFilesPath = '/xml_tv_program/';
  this.weekDays = ['niedziela', 'poniedziałek', 'wtorek', 'środa', 'czwartek', 'piątek', 'sobota'];
  this.textMore = '+ więcej';
  this.textLess = '- mniej';
  this.alertNoChannelData = 'Brak danych dotyczących programu kanału ';
  this.fontSize = '11px';
  this.lineHeight = 'normal';
  this.maxRows = 45;
  this.hourglassWidth = 120;
  this.hourglassTopProg = 30;
  this.hourglassTopMain = 60;
  this.currentProgramInterval = 10000;
  this.prevDays = 2;
  this.TotalDays = 11;
  this.hourglass = null;
  this.initialContent;
  this.programXml;
  this.selectedColumn;
  this.rowForm;

  this.nop = nop;
  this.init = init;
  this.changeColumns = changeColumns;
  this.changeChannel = changeChannel;
  this.clearChannel = clearChannel;
  this.fillChannel = fillChannel;
  this.updateAllChannels = updateAllChannels;
  this.showFullDescription = showFullDescription;
  this.hideFullDescription = hideFullDescription;
  this.highlighPlaying = highlighPlaying;
  this.togglePreviousRow = togglePreviousRow;
  this.showNextDay = showNextDay;
  this.togglePanelBottom = togglePanelBottom;

//nic
  function nop() {}

//inicjalizacja programu TV
  function init() {
    try {
      var siDate, siHour, siGenre, cbxPreviousRow;
      var row, col, colMargin, colSelect;
      var i, j;
      var firstStart = true;
      var initDate = new Date();
      var req = extractReqParams(window.location.href);
      j = new Array();
      for(i = 0; i < this.genreStoplist.length; i++)
        j[this.genreStoplist[i]] = '';
      this.genreStoplist = j;
      this.html.style.display = 'none';
      if(!this.initialContent) {
        this.initialContent = this.html.innerHTML;
        this.rowForm = document.forms[this.id+'Form'];
      } else {
        firstStart = false;
        siDate = this.rowForm.elements[this.id+'Date'].selectedIndex;
        siHour = this.rowForm.elements[this.id+'Hour'].selectedIndex;
        if(this.rowForm.elements[this.id+'Genre'] != undefined)
          siGenre = this.rowForm.elements[this.id+'Genre'].selectedIndex;
        cbxPreviousRow = this.rowForm.elements[this.id+'PreviousRow'].checked;
        this.html.innerHTML = this.initialContent;
      }
      try {
        colSelect = this.rowForm.elements[this.id+'PreviousRow'];
        colSelect.onclick = new Function(this.id+'.togglePreviousRow(this.checked);');
        if(cbxPreviousRow != undefined)
          this.rowForm.elements[this.id+'PreviousRow'].checked = cbxPreviousRow;
      } catch(ex) {}
      try {
        colSelect = this.rowForm.elements[this.id+'Columns'];
        colSelect.onchange = new Function(this.id+'.changeColumns(this.options[this.selectedIndex].value);');
        if(firstStart && req && req.p30) {
          j = 0;
          while(j < colSelect.options.length-1 && colSelect.options[j].value != req.p30)
            j++
          if(colSelect.options[j].value == req.p30) {
            colSelect.selectedIndex = j;
            this.cols = req.p30;
            this.colWidth = Math.floor((this.widthTotal - (this.cols-1)*this.widthMargin) / this.cols);
            this.firstColWidth = this.widthTotal - (this.cols-1)*(this.widthMargin+this.colWidth);
          }
        }
      } catch(ex) {}
      initDate.setTime(this.date.getTime());
      try {
        colSelect = this.rowForm.elements[this.id+'Date'];
        initDate.setTime(initDate.getTime() - 1000*60*60*24*this.prevDays);
        for(i = 0; i < this.TotalDays; i++) {
          colSelect.options[colSelect.options.length] = new Option(initDate.getFullYear()+'-'+(initDate.getMonth()+1>9?'':'0')+(initDate.getMonth()+1)+'-'+(initDate.getDate()>9?'':'0')+initDate.getDate()+' '+this.weekDays[initDate.getDay()], initDate.getFullYear()+'-'+(initDate.getMonth()+1>9?'':'0')+(initDate.getMonth()+1)+'-'+(initDate.getDate()>9?'':'0')+initDate.getDate());
          if(i==this.prevDays)
            colSelect.options[colSelect.options.length - 1].selected = true;
          initDate.setTime(initDate.getTime() + 1000*60*60*24);
        }
        colSelect.onchange = new Function(this.id+'.updateAllChannels();');
        if(siDate != undefined)
          this.rowForm.elements[this.id+'Date'].selectedIndex = siDate;
      } catch(ex) {}
      try {
        colSelect = this.rowForm.elements[this.id+'Hour'];
        for(i = 5; i < 30; i++) {
          colSelect.options[colSelect.options.length] = new Option((i%24>9?'':'0')+i%24+':00', (i>9?'':'0')+i);
          if(i==initDate.getHours())
            colSelect.options[colSelect.options.length - 1].selected = true;
        }
        colSelect.onchange = new Function(this.id+'.updateAllChannels();');
        colSelect = this.rowForm.elements[this.id+'Genre'];
        colSelect.options[colSelect.options.length] = new Option(' --- ', '');
        i = 0;
        while(this.programsGenres[i] != 0) {
          colSelect.options[colSelect.options.length] = new Option(this.programsGenres[i+1], this.programsGenres[i]);
          i += 2;
        }
        colSelect.onchange = new Function(this.id+'.updateAllChannels();');
        if(siHour != undefined)
          this.rowForm.elements[this.id+'Hour'].selectedIndex = siHour;
        if(siGenre != undefined)
          this.rowForm.elements[this.id+'Genre'].selectedIndex = siGenre;
      } catch(ex) {}
      for(var c = 0; c < this.cols; c++) {
        col = document.createElement('div');
        col.className = 'col' + (this.showChannelSelectors ? '' : ' undisplayed');
        colSelect = document.createElement('select');
        colSelect.name = this.id+'selectTvProgram'+c;
        colSelect.id = this.id+'selectTvProgram'+c;
        if(c == 0) {
          col.style.width = this.firstColWidth+'px';
          colSelect.style.width = this.firstColWidth+'px';
        } else {
          colMargin = document.createElement('div');
          colMargin.className = 'margin';
          colMargin.innerHTML = '&nbsp;';
          colMargin.style.width = this.widthMargin+'px';
          this.html.appendChild(colMargin);
          col.style.width = this.colWidth+'px';
          colSelect.style.width = this.colWidth+'px';
        }
        i = 0;
        while(this.programsList[i] != 0) {
          colSelect.options[colSelect.options.length] = new Option(this.programsList[i+1], this.programsList[i]);
          if(this.programsList[i+2] != '')
            colSelect.options[colSelect.options.length-1].style.backgroundColor = this.programsList[i+2];
          i += 3;
        }
        colSelect.onchange = new Function(this.id+'.changeChannel(this, false);');
        col.appendChild(colSelect);
        this.html.appendChild(col);
      }

      row = document.createElement('div');
      row.id = 'row_p';
      row.className = 'rowp';
      row.style.width = this.widthTotal+'px';
      row.style.fontSize = '0px';
      row.style.lineHeight = '0px';
      row.style.height = '0px';
      for(var c = 0; c < this.cols; c++) {
        col = document.createElement('div');
        col.id = 'col_p_'+(c>9?'':'0')+c;
        col.className = 'col';
        if(c == 0) {
          col.style.width = this.firstColWidth+'px';
        } else {
          colMargin = document.createElement('div');
          colMargin.className = 'margin';
          colMargin.innerHTML = '&nbsp;';
          colMargin.style.width = this.widthMargin+'px';
          row.appendChild(colMargin);
          col.style.width = this.colWidth+'px';
        }
        col.innerHTML = '&nbsp;';
        row.appendChild(col);
      }
      this.html.appendChild(row);

      for(var r = 0; r < this.maxRows; r++) {
        row = document.createElement('div');
        row.id = 'row_'+r;
        row.className = 'row'+r%2;
        row.style.width = this.widthTotal+'px';
        row.style.fontSize = '0px';
        row.style.lineHeight = '0px';
        row.style.height = '0px';
        for(var c = 0; c < this.cols; c++) {
          col = document.createElement('div');
          col.id = 'col_'+(c>9?'':'0')+c+'_'+(r>9?'':'0')+r;
          col.className = 'col';
          if(c == 0) {
            col.style.width = this.firstColWidth+'px';
          } else {
            colMargin = document.createElement('div');
            colMargin.className = 'margin';
            colMargin.innerHTML = '&nbsp;';
            colMargin.style.width = this.widthMargin+'px';
            row.appendChild(colMargin);
            col.style.width = this.colWidth+'px';
          }
          col.innerHTML = '&nbsp;';
          row.appendChild(col);
        }
        this.html.appendChild(row);
      }
      this.html.style.width = this.widthTotal+'px';
      this.html.style.display = 'inline';
      this.panelTop.style.display = 'inline';
      this.panelTop.style.width = this.widthTotal + 'px';
      if(this.panelBottom) {
        this.panelBottom.style.display = 'inline';
        this.panelBottom.style.width = this.widthTotal + 'px';
      }
      setInterval(this.id+'.highlighPlaying()', this.currentProgramInterval);

      if(firstStart) {
        for(i = 1; i <= this.rowForm.elements[this.id+'Columns'].options[this.rowForm.elements[this.id+'Columns'].selectedIndex].value; i++) {
          var chn = null;
          if(req && eval('req.p'+i))
            eval('chn = req.p'+i);
          else if(this.initChannels.length > i - 1)
            chn = this.initChannels[i - 1];
          else
            chn = null;
          if(chn) {
            colSelect = document.getElementById(this.id+'selectTvProgram'+(i-1));
            j = 0;
            while(j < colSelect.options.length-1 && colSelect.options[j].value != chn)
              j++
            if(colSelect.options[j].value == chn) {
              colSelect.selectedIndex = j;
              this.changeChannel(colSelect, true);
            }
          }
        }
      }

      if(this.panelBottom && document.getElementById('tvProgramShowNextDay'))
        document.getElementById('tvProgramShowNextDay').onclick = new Function(this.id+'.showNextDay();');
    } catch(ex) { if(this.debug) alert('init\n'+ex); }
  }

//zmiana liczby kolumn
  function changeColumns(n) {
    try {
      if(n != undefined) {
        showHourglass(this);
        this.selectedColumn = n;
        setTimeout(this.id+'.changeColumns();', 10);
      } else {
        var sc = this.rowForm.elements[this.id+'Columns'].selectedIndex;
        var sp = new Array();
        for(var c = 0; c < this.cols; c++)
          sp[c] = this.rowForm.elements[this.id+'selectTvProgram'+c].selectedIndex;
        this.cols = this.selectedColumn;
        this.colWidth = Math.floor((this.widthTotal - (this.cols-1)*this.widthMargin) / this.cols);
        this.firstColWidth = this.widthTotal - (this.cols-1)*(this.widthMargin+this.colWidth);
        this.init();
        this.rowForm.elements[this.id+'Columns'].selectedIndex = sc;
        for(var c = 0; c < this.cols; c++)
          try {
            this.rowForm.elements[this.id+'selectTvProgram'+c].selectedIndex = sp[c];
            this.changeChannel(this.rowForm.elements[this.id+'selectTvProgram'+c], true);
          } catch(ex) {}
        hideHourglass(this);
      }
    } catch(ex) { if(this.debug) alert('changeColumns\n'+ex); }
  }

//zmiana kanału
  function changeChannel(o, force) {
    try {
      var n = o.name.replace(this.id+'selectTvProgram', '');
      if(o.options[o.selectedIndex].value != -1) {
        advAJAX.get({
          url: this.xmlFilesPath+o.options[o.selectedIndex].value+'-'+o.form.elements[this.id+'Date'].options[o.form.elements[this.id+'Date'].selectedIndex].value+'.xml'
          , tag: [this, o, n, force]
          , unique: true
          , onSuccess : function(obj) { 
              try {
                obj.tag[0].fillChannel(obj.tag[2], obj.responseXML, obj.tag[3]);
              } catch(ex) {}
            }
          , onError : function(obj) {
            try {
              alert(obj.tag[0].alertNoChannelData + obj.tag[1].options[obj.tag[1].selectedIndex].text);
//              obj.tag[1].selectedIndex = 0;
              obj.tag[0].clearChannel(obj.tag[2]);
              tidyColums(obj.tag[0]);
            } catch(ex) {}
          }
        });
      } else {
        this.clearChannel(n);
        tidyColums(this);
      }
      this.togglePreviousRow(this.rowForm.elements[this.id+'PreviousRow'].checked);
    } catch(ex) { if(this.debug) alert('changeChannel\n'+ex); }
  }

//wyczyszczenie kolumny kanału
  function clearChannel(n) {
    try {
      for(var i = 0; i < this.maxRows; i++)
        document.getElementById('col_'+(n>9?'':'0')+n+'_'+(i>9?'':'0')+i).innerHTML = '&nbsp;';
      document.getElementById('col_p_'+(n>9?'':'0')+n).innerHTML = '&nbsp;';
    } catch(ex) { if(this.debug) alert('clearChannel\n'+ex); }
  }

//wypełnienie kolumny kanału programem
  function fillChannel(n, xml, force) {
    try {
      var eTime;
      if(force) {
        this.selectedColumn = n;
        this.programXml = xml;
        n = undefined;
        xml = undefined;
      }
      if(n != undefined) {
        var o = this.rowForm.elements[this.id+'selectTvProgram'+n];
        var pos = getObjectPosition(o);
        showHourglass(this, pos.x + (o.offsetWidth - this.hourglassWidth) / 2, this.hourglassTopProg + pos.y);
        this.selectedColumn = n;
        this.programXml = xml;
        setTimeout(this.id+'.fillChannel();', 10);
      } else {
        this.clearChannel(this.selectedColumn);
        var progNode, row, element, currCol, endTime, hours, minutes;
        var pf = false;
        var i = 0;
        while(this.programXml.childNodes.length > i && this.programXml.childNodes[i].nodeName != 'listaProgramow')
          i++;
        if(this.programXml.childNodes[i].nodeName == 'listaProgramow') {
          this.programXml = this.programXml.childNodes[i];
          i = 0;
          currCol = document.getElementById('col_p_'+(n>9?'':'0')+this.selectedColumn);
          while(!pf && i < this.programXml.childNodes.length) {
            if(this.programXml.childNodes[i].nodeName == 'program') {
              progNode = this.programXml.childNodes[i];
              eTime = getValueOfFirstChildByTagName(progNode, 'emisja') ? getValueOfFirstChildByTagName(progNode, 'emisja') : getValueOfFirstChildByTagName(progNode, 'czasPublikacji');
              if(eTime 
                && (
                  (
                    getDateAsText(eTime).substr(0,10) == this.rowForm.elements[this.id+'Date'].options[this.rowForm.elements[this.id+'Date'].selectedIndex].value.substr(0,10)
                    && getDateAsText(eTime).substr(11,2) >= this.rowForm.elements[this.id+'Hour'].options[this.rowForm.elements[this.id+'Hour'].selectedIndex].value
                  ) || (
                    getDateAsText(eTime).substr(0,10) != this.rowForm.elements[this.id+'Date'].options[this.rowForm.elements[this.id+'Date'].selectedIndex].value.substr(0,10)
                    && getDateAsText(eTime).substr(11,2) >= parseFloat(this.rowForm.elements[this.id+'Hour'].options[this.rowForm.elements[this.id+'Hour'].selectedIndex].value)-24
                  )
                ) && (this.rowForm.elements[this.id+'Genre'] == undefined || !this.rowForm.elements[this.id+'Genre'].options[this.rowForm.elements[this.id+'Genre'].selectedIndex].value || getChildrenValuesByTagName(progNode, 'gatunek').indexOf('|'+this.rowForm.elements[this.id+'Genre'].options[this.rowForm.elements[this.id+'Genre'].selectedIndex].value+'|') != -1)
                && i > 0
                ) {
                  while(!pf && i >= 0) {
                    if(--i < 0)
                      pf = true;
                    else if(this.programXml.childNodes[i].nodeName == 'program') {
                      pf = true;
                      progNode = this.programXml.childNodes[i];
                      eTime = getValueOfFirstChildByTagName(progNode, 'emisja') ? getValueOfFirstChildByTagName(progNode, 'emisja') : getValueOfFirstChildByTagName(progNode, 'czasPublikacji');
                    }
                  }
                }
            }
            i++;
          }
          if(pf && i > 0) {
            if(currCol.innerHTML == '&nbsp;' || currCol.innerHTML.length == 1)
              currCol.innerHTML = '';
            row = document.createElement('div');
            row.className = 'row';
            row.style.width = (this.selectedColumn==0?this.firstColWidth:this.colWidth)+'px';
            element = document.createElement('span');
            element.className = 'time';
            element.innerHTML = getDateAsText(eTime).substr(11,5);
            row.appendChild(element);
            /*
            element = document.createElement('span');
            element.className = 'endTime';
            hours = parseFloat(getDateAsText(eTime).substr(11,2));
            minutes = parseFloat(getDateAsText(eTime).substr(14,2));
            endTime = getValueOfFirstChildByTagName(progNode, 'przyblizonyCzasTrwania').replace('PT', '').split('H');
            if(endTime.length == 2)
              hours += parseFloat(endTime[0]);
            if(endTime[endTime.length-1] != '') {
              endTime = endTime[endTime.length-1].split('M');
              endTime = parseFloat(endTime[0])+minutes;
              while(endTime >= 60) {
                endTime -= 60;
                hours++;
              }
              minutes = endTime;
            }
            if(hours > 23)
              hours -= 24;
            element.innerHTML = (hours>9?'':'0') + hours + ':' + (minutes>9?'':'0') + minutes;
            row.appendChild(element);
            */
            if(getValueOfFirstChildByTagName(progNode, 'dyscyplina'))
              row.innerHTML += getValueOfFirstChildByTagName(progNode, 'dyscyplina').toUpperCase() + this.titleSeparator;
            if(getValueOfFirstChildByTagName(progNode, 'tytul'))
              row.innerHTML += getValueOfFirstChildByTagName(progNode, 'tytul');
            if(getValueOfFirstChildByTagName(progNode, 'gatunek') && !(getValueOfFirstChildByTagName(progNode, 'gatunek') in this.genreStoplist))
              row.innerHTML += this.titleSeparator + getValueOfFirstChildByTagName(progNode, 'gatunek');
            if(getValueOfFirstChildByTagName(progNode, 'atrybuty') && getValueOfFirstChildByTagName(progNode, 'atrybuty') in this.attributesIcons)
              row.innerHTML += this.attributesIconTpl.replace('<ico/>', this.attributesIcons[getValueOfFirstChildByTagName(progNode, 'atrybuty')]);
            if(getValueOfFirstChildByTagName(progNode, 'opisKrotki')) {
              element = document.createElement('div');
              element.className = 'descrShort';
              element.style.width = (this.selectedColumn==0?this.firstColWidth:this.colWidth)+'px';
              element.innerHTML = getValueOfFirstChildByTagName(progNode, 'opisKrotki');
              row.appendChild(element);
            }
/*
            if(getValueOfFirstChildByTagName(progNode, 'opisDlugi')) {
              element = document.createElement('a');
              element.id = 'more_'+this.selectedColumn+'_'+i;
              element.className = 'more';
              element.innerHTML = this.textMore;
              element.href = 'javascript:'+this.id+'.showFullDescription("'+element.id+'");';
              row.appendChild(element);
              element = document.createElement('div');
              element.className = 'descrLong';
              element.style.width = (n==0?this.firstColWidth:this.colWidth)+'px';
              element.innerHTML = getValueOfFirstChildByTagName(progNode, 'opisDlugi');
              row.appendChild(element);
              element = document.createElement('a');
              element.id = 'less_'+this.selectedColumn+'_'+i;
              element.className = 'less';
              element.innerHTML = this.textLess;
              element.href = 'javascript:'+this.id+'.hideFullDescription("'+element.id+'");';
              row.appendChild(element);
            }
*/
            currCol.appendChild(row);
          }

          i = 0;
          while(i < this.programXml.childNodes.length) {
            if(this.programXml.childNodes[i].nodeName == 'program') {
              progNode = this.programXml.childNodes[i];
              eTime = getValueOfFirstChildByTagName(progNode, 'emisja') ? getValueOfFirstChildByTagName(progNode, 'emisja') : getValueOfFirstChildByTagName(progNode, 'czasPublikacji');
              if(eTime
                && (
                  (
                    getDateAsText(eTime).substr(0,10) == this.rowForm.elements[this.id+'Date'].options[this.rowForm.elements[this.id+'Date'].selectedIndex].value.substr(0,10)
                    && getDateAsText(eTime).substr(11,2) >= this.rowForm.elements[this.id+'Hour'].options[this.rowForm.elements[this.id+'Hour'].selectedIndex].value
                  ) || (
                    getDateAsText(eTime).substr(0,10) != this.rowForm.elements[this.id+'Date'].options[this.rowForm.elements[this.id+'Date'].selectedIndex].value.substr(0,10)
                    && getDateAsText(eTime).substr(11,2) >= parseFloat(this.rowForm.elements[this.id+'Hour'].options[this.rowForm.elements[this.id+'Hour'].selectedIndex].value)-24
                  )
                ) && (this.rowForm.elements[this.id+'Genre'] == undefined || !this.rowForm.elements[this.id+'Genre'].options[this.rowForm.elements[this.id+'Genre'].selectedIndex].value || getChildrenValuesByTagName(progNode, 'gatunek').indexOf('|'+this.rowForm.elements[this.id+'Genre'].options[this.rowForm.elements[this.id+'Genre'].selectedIndex].value+'|') != -1)
                ) {
                currCol = 'col_'+(this.selectedColumn>9?'':'0')+this.selectedColumn+'_';
                currCol += (getDateAsText(eTime).substr(0,10) == this.rowForm.elements[this.id+'Date'].options[this.rowForm.elements[this.id+'Date'].selectedIndex].value.substr(0,10)?getDateAsText(eTime).substr(11,2):24+parseFloat(getDateAsText(eTime).substr(11,2)));
                currCol = document.getElementById(currCol);
                if(currCol) {
                  if(currCol.innerHTML == '&nbsp;' || currCol.innerHTML.length == 1)
                    currCol.innerHTML = '';
                  row = document.createElement('div');
                  row.className = 'row';
                  row.style.width = (this.selectedColumn==0?this.firstColWidth:this.colWidth)+'px';
                  element = document.createElement('span');
                  element.className = 'time';
                  element.innerHTML = getDateAsText(eTime).substr(11,5);
                  row.appendChild(element);
                  /*
                  element = document.createElement('span');
                  element.className = 'endTime';
                  hours = parseFloat(getDateAsText(eTime).substr(11,2));
                  minutes = parseFloat(getDateAsText(eTime).substr(14,2));
                  endTime = getValueOfFirstChildByTagName(progNode, 'przyblizonyCzasTrwania').replace('PT', '').split('H');
                  if(endTime.length == 2)
                    hours += parseFloat(endTime[0]);
                  if(endTime[endTime.length-1] != '') {
                    endTime = endTime[endTime.length-1].split('M');
                    endTime = parseFloat(endTime[0])+minutes;
                    while(endTime >= 60) {
                      endTime -= 60;
                      hours++;
                    }
                    minutes = endTime;
                  }
                  if(hours > 23)
                    hours -= 24;
                  element.innerHTML = (hours>9?'':'0') + hours + ':' + (minutes>9?'':'0') + minutes;
                  row.appendChild(element);
                  */
                  if(getValueOfFirstChildByTagName(progNode, 'dyscyplina'))
                    row.innerHTML += getValueOfFirstChildByTagName(progNode, 'dyscyplina').toUpperCase() + this.titleSeparator;;
                  if(getValueOfFirstChildByTagName(progNode, 'tytul'))
                    row.innerHTML += getValueOfFirstChildByTagName(progNode, 'tytul');
                  if(getValueOfFirstChildByTagName(progNode, 'gatunek') && !(getValueOfFirstChildByTagName(progNode, 'gatunek') in this.genreStoplist))
                    row.innerHTML += this.titleSeparator + getValueOfFirstChildByTagName(progNode, 'gatunek');
                  if(getValueOfFirstChildByTagName(progNode, 'atrybuty') && getValueOfFirstChildByTagName(progNode, 'atrybuty') in this.attributesIcons)
                    row.innerHTML += this.attributesIconTpl.replace('<ico/>', this.attributesIcons[getValueOfFirstChildByTagName(progNode, 'atrybuty')]);
                  if(getValueOfFirstChildByTagName(progNode, 'opisKrotki')) {
                    element = document.createElement('div');
                    element.className = 'descrShort';
                    element.style.width = (this.selectedColumn==0?this.firstColWidth:this.colWidth)+'px';
                    element.innerHTML = getValueOfFirstChildByTagName(progNode, 'opisKrotki');
                    row.appendChild(element);
                  }
/*
                  if(getValueOfFirstChildByTagName(progNode, 'opisDlugi')) {
                    element = document.createElement('a');
                    element.id = 'more_'+this.selectedColumn+'_'+i;
                    element.className = 'more';
                    element.innerHTML = this.textMore;
                    element.href = 'javascript:'+this.id+'.showFullDescription("'+element.id+'");';
                    row.appendChild(element);
                    element = document.createElement('div');
                    element.className = 'descrLong';
                    element.style.width = (this.selectedColumn==0?this.firstColWidth:this.colWidth)+'px';
                    element.innerHTML = getValueOfFirstChildByTagName(progNode, 'opisDlugi');
                    row.appendChild(element);
                    element = document.createElement('a');
                    element.id = 'less_'+this.selectedColumn+'_'+i;
                    element.className = 'less';
                    element.innerHTML = this.textLess;
                    element.href = 'javascript:'+this.id+'.hideFullDescription("'+element.id+'");';
                    row.appendChild(element);
                  }
*/
                  currCol.appendChild(row);
                }
              }
            }
            i++;
          }
        }
        tidyColums(this);
        this.selectedColumn = null;
        this.programXml = null;
        if(!force)
          hideHourglass(this);
      }
    } catch(ex) { if(this.debug) alert('fillChannel\n'+ex); }
  }

//aktualizacja wszystkich kanałów
  function updateAllChannels(force) {
    try {
      if(force == undefined) {
        showHourglass(this);
        setTimeout(this.id+'.updateAllChannels(true);', 10);
      } else {
        for(var c = 0; c < this.cols; c++)
          this.changeChannel(this.rowForm.elements[this.id+'selectTvProgram'+c], true)
        hideHourglass(this);
      }
    } catch(ex) { if(this.debug) alert('updateAllChannels\n'+ex); }
    this.togglePanelBottom();
  }

//pokazanie pełnego opisu
  function showFullDescription(o) {
    try {
      o = document.getElementById(o);
      if(o.nextSibling && o.nextSibling.nodeName.toLowerCase() == 'div' && o.nextSibling.className == 'descrLong') {
        o.nextSibling.style.display = 'inline';
        if(o.nextSibling.nextSibling && o.nextSibling.nextSibling.nodeName.toLowerCase() == 'a' && o.nextSibling.nextSibling.className == 'less')
          o.nextSibling.nextSibling.style.display = 'inline';
      }
      if(o.previousSibling && o.previousSibling.nodeName.toLowerCase() == 'div' && o.previousSibling.className == 'descrShort')
        o.previousSibling.style.display = 'none';
      o.style.display = 'none';
      tidyColums(this);
    } catch(ex) { if(this.debug) alert('showFullDescription\n'+ex); }
  }

//powrót do krótkiego opisu
  function hideFullDescription(o) {
    try {
      o = document.getElementById(o);
      if(o.previousSibling.previousSibling.previousSibling && o.previousSibling.previousSibling.previousSibling.nodeName.toLowerCase() == 'div' && o.previousSibling.previousSibling.previousSibling.className == 'descrShort')
        o.previousSibling.previousSibling.previousSibling.style.display = 'block';
      if(o.previousSibling.previousSibling && o.previousSibling.previousSibling.nodeName.toLowerCase() == 'a' && o.previousSibling.previousSibling.className == 'more')
        o.previousSibling.previousSibling.style.display = 'block';
      if(o.previousSibling && o.previousSibling.nodeName.toLowerCase() == 'div' && o.previousSibling.className == 'descrLong')
        o.previousSibling.style.display = 'none';
      o.style.display = 'none';
      tidyColums(this);
    } catch(ex) { if(this.debug) alert('hideFullDescription\n'+ex); }
  }

//podświetlanie aktualnie trwającego programu
  function highlighPlaying() {
    try {
      var row, maxHeight, rowDisplay;
      var currDate = new Date();
      currDate.setTime((new Date()).getTime() - this.zeroDate.getTime() + this.date.getTime());
      for(var r = 0; r < this.maxRows; r++) {
        row = document.getElementById('row_'+r);
        if(row.style.height != '0px')
          for(var i = 0; i < row.childNodes.length; i++)
            if(row.childNodes[i].nodeName.toLowerCase() == 'div'  && row.childNodes[i].className == 'col')
              for(var j = 0; j < row.childNodes[i].childNodes.length; j++)
                if(row.childNodes[i].childNodes[j].nodeName.toLowerCase() == 'div' && row.childNodes[i].childNodes[j].className.indexOf('row') == 0)
                  if(row.childNodes[i].childNodes[j].childNodes[0].nodeName.toLowerCase() == 'span' && row.childNodes[i].childNodes[j].childNodes[0].className == 'time' && row.childNodes[i].childNodes[j].childNodes[1].nodeName.toLowerCase() == 'span' && row.childNodes[i].childNodes[j].childNodes[1].className == 'endTime') {
                    if(row.childNodes[i].childNodes[j].childNodes[0].innerHTML <= (currDate.getHours()>9?'':'0')+currDate.getHours()+':'+(currDate.getMinutes()>9?'':'0')+currDate.getMinutes() && row.childNodes[i].childNodes[j].childNodes[1].innerHTML > (currDate.getHours()>9?'':'0')+currDate.getHours()+':'+(currDate.getMinutes()>9?'':'0')+currDate.getMinutes())
                      row.childNodes[i].childNodes[j].className = 'row current';
                    else
                      row.childNodes[i].childNodes[j].className = 'row';
                  }
      }
      row = document.getElementById('row_p');
      if(row.style.height != '0px')
        for(var i = 0; i < row.childNodes.length; i++)
          if(row.childNodes[i].nodeName.toLowerCase() == 'div'  && row.childNodes[i].className == 'col')
            for(var j = 0; j < row.childNodes[i].childNodes.length; j++)
              if(row.childNodes[i].childNodes[j].nodeName.toLowerCase() == 'div' && row.childNodes[i].childNodes[j].className.indexOf('row') == 0)
                if(row.childNodes[i].childNodes[j].childNodes[0].nodeName.toLowerCase() == 'span' && row.childNodes[i].childNodes[j].childNodes[0].className == 'time' && row.childNodes[i].childNodes[j].childNodes[1].nodeName.toLowerCase() == 'span' && row.childNodes[i].childNodes[j].childNodes[1].className == 'endTime') {
                  if(row.childNodes[i].childNodes[j].childNodes[0].innerHTML <= (currDate.getHours()>9?'':'0')+currDate.getHours()+':'+(currDate.getMinutes()>9?'':'0')+currDate.getMinutes() && row.childNodes[i].childNodes[j].childNodes[1].innerHTML > (currDate.getHours()>9?'':'0')+currDate.getHours()+':'+(currDate.getMinutes()>9?'':'0')+currDate.getMinutes())
                    row.childNodes[i].childNodes[j].className = 'row current';
                  else
                    row.childNodes[i].childNodes[j].className = 'row';
                }
    } catch(ex) { if(this.debug) alert('highlighPlaying\n'+ex); }
  }

//pokazywanie i ukrywanie wiersza z niezakończonym poprzednim programem
  function togglePreviousRow(pr) {
    try {
      var row = document.getElementById('row_p');
      var ch = 0;
      for(var c = 0; c < this.cols; c++)
        ch += this.rowForm.elements[this.id+'selectTvProgram'+c].selectedIndex;
      if(pr && ch > 0) {
        row.style.fontSize = this.fontSize;
        row.style.lineHeight = this.lineHeight;
        row.style.height = 'auto';
      } else {
        row.style.fontSize = '0px';
        row.style.lineHeight = '0px';
        row.style.height = '0px';
      }
      tidyColums(this);
    } catch(ex) { if(this.debug) alert('togglePreviousRow\n'+ex); }
  }

//przejście do następnego dnia
  function showNextDay() {
    var siDate = this.rowForm.elements[this.id+'Date'];
    if(siDate && siDate.options.length - 1 > siDate.selectedIndex) {
      siDate.selectedIndex++;
      this.updateAllChannels();
      window.location = '#';
    }
  }

//ukrywanie dolnego panelu
  function togglePanelBottom() {
    var siDate = this.rowForm.elements[this.id+'Date'];
    var nextDayButton = document.getElementById('tvProgramShowNextDay');
    if(nextDayButton && siDate)
      if(siDate.options.length - 1 == siDate.selectedIndex) {
        nextDayButton.style.visibility = 'hidden';
      } else {
        nextDayButton.style.visibility = 'visible';
      }
  }

//prywatne --------------------------------------------
//pobranie wartości pierwszego taga o tagName
  function getValueOfFirstChildByTagName(node, tagName) {
    return (node.getElementsByTagName(tagName).length > 0 && node.getElementsByTagName(tagName)[0].childNodes.length > 0
      ? node.getElementsByTagName(tagName)[0].childNodes[0].nodeValue
      : null
    );
  }

//pobranie wartości elementów potomnych o tagName
  function getChildrenValuesByTagName(node, tagName) {
    var nodes = node.getElementsByTagName(tagName);
    var ret = '|';
    for(var i = 0; i < nodes.length; i++) {
      ret += nodes[i].childNodes[0].nodeValue + '|';
    }
    return ret;
  }

//porządkowanie kolumn po zmianie programu
  function tidyColums(o) {
    try {
      var row, maxHeight, rowDisplay;
      var visibleRowCount = 0;
      for(var r = 0; r < o.maxRows; r++) {
        row = document.getElementById('row_'+r);
        rowDisplay = false;
        for(var i = 0; i < row.childNodes.length; i++)
          if(row.childNodes[i].nodeName.toLowerCase() == 'div'  && row.childNodes[i].className == 'col')
            if(row.childNodes[i].innerHTML != '&nbsp;' || (row.childNodes[i].innerHTML != '&nbsp;' && row.childNodes[i].innerHTML.length > 1))
              rowDisplay = true;
        if(rowDisplay) {
          row.className = 'row'+(visibleRowCount%2);
          row.style.fontSize = o.fontSize;
          row.style.lineHeight = o.lineHeight;
          row.style.height = 'auto';
          visibleRowCount++;
        } else {
          row.style.fontSize = '0px';
          row.style.lineHeight = '0px';
          row.style.height = '0px';
        }
        maxHeight = 0;
        for(var i = 0; i < row.childNodes.length; i++)
          if(row.childNodes[i].nodeName.toLowerCase() == 'div'  && row.childNodes[i].className == 'col')
            maxHeight = Math.max(row.childNodes[i].offsetHeight, maxHeight);
        for(var i = 0; i < row.childNodes.length; i++)
          if(row.childNodes[i].nodeName.toLowerCase() == 'div'  && row.childNodes[i].className == 'margin')
            row.childNodes[i].style.height = maxHeight+'px';
      }
      row = document.getElementById('row_p');
      rowDisplay = false;
      if(document.forms[o.id+'Form'].elements[o.id+'PreviousRow'].checked)
        for(var i = 0; i < row.childNodes.length; i++)
          if(row.childNodes[i].nodeName.toLowerCase() == 'div'  && row.childNodes[i].className == 'col')
            if(row.childNodes[i].innerHTML != '&nbsp;' || (row.childNodes[i].innerHTML != '&nbsp;' && row.childNodes[i].innerHTML.length > 1))
              rowDisplay = true;
      if(rowDisplay) {
        row.style.fontSize = o.fontSize;
        row.style.lineHeight = o.lineHeight;
        row.style.height = 'auto';
      } else {
        row.style.fontSize = '0px';
        row.style.lineHeight = '0px';
        row.style.height = '0px';
      }
      maxHeight = 0;
      for(var i = 0; i < row.childNodes.length; i++)
        if(row.childNodes[i].nodeName.toLowerCase() == 'div'  && row.childNodes[i].className == 'col')
          maxHeight = Math.max(row.childNodes[i].offsetHeight, maxHeight);
      for(var i = 0; i < row.childNodes.length; i++)
        if(row.childNodes[i].nodeName.toLowerCase() == 'div'  && row.childNodes[i].className == 'margin')
          row.childNodes[i].style.height = maxHeight+'px';
      o.highlighPlaying();
    } catch(ex) { if(o.debug) alert('tidyColums\n'+ex); }
  }

//pokazanie klepsydry
  function showHourglass(o, x, y) {
    try {
      if(o.hourglass == null) {
        var pos = getObjectPosition(o.html);
        o.hourglass = document.createElement("div");
        o.hourglass.id = o.id+'Hourglass';
        o.hourglass.innerHTML = '&nbsp;';
        document.body.appendChild(o.hourglass);
        o.hourglass.style.left = (x != undefined?x:(pos.x + (o.html.offsetWidth - o.hourglass.offsetWidth) / 2))+ 'px';
        o.hourglass.style.top = (y != undefined?y:(o.hourglassTopMain + pos.y)) + 'px';
        o.hourglass.style.visibility = 'visible';
      }
    } catch(ex) { if(o.debug) alert('showHourglass\n'+ex); }
  }

//ukrycie klepsydry
  function hideHourglass(o) {
    try {
      if(o.hourglass != null) {
        document.body.removeChild(o.hourglass);
        o.hourglass = null;
      }
    } catch(ex) { if(this.debug) alert('hideHourglass\n'+ex); }
  }

//zmienia datę z formatu XML na tekst
  function getDateAsText(t) {
    try {
      var date = new Date(t.substr(0, 4), parseFloat(t.substr(5, 2))-1, t.substr(8, 2), t.substr(11, 2), t.substr(14, 2), t.substr(17, 2));
      if(t.length > 19) {
        if(t.charAt(19) == 'Z') {
          date.setUTCFullYear(t.substr(0, 4));
          date.setUTCMonth(parseFloat(t.substr(5, 2))-1);
          date.setUTCDate(t.substr(8, 2));
          date.setUTCHours(t.substr(11, 2));
          date.setUTCMinutes(t.substr(14, 2));
          date.setUTCSeconds(t.substr(17, 2));
/*
          date.setTime(1000*60*60+date.getTime());
          if(parseFloat(t.substr(5, 2)) >= 4  && parseFloat(t.substr(5, 2)) <= 10) {
            date.setTime(1000*60*60+date.getTime());
          }
*/
          return date.getFullYear()+'-'+(date.getMonth()+1>9?'':'0')+(date.getMonth()+1)+'-'+(date.getDate()>9?'':'0')+date.getDate()+' '+(date.getHours()>9?'':'0')+date.getHours()+':'+(date.getMinutes()>9?'':'0')+date.getMinutes()+':'+(date.getSeconds()>9?'':'0')+date.getSeconds();
        } else {
          return t.replace('T', ' ');
        }
      } else {
        return t.replace('T', ' ');
      }
    } catch(ex) { return null; }
  }
}
