JRSpojeni = function(id, w, h, caption, listSpojeni, mov) {
/*    var cssNode = document.createElement('link');
    cssNode.setAttribute('rel', 'stylesheet');
    cssNode.setAttribute('type', 'text/css');
    cssNode.setAttribute('href', 'ccs/tableSpojeni.css');
    document.getElementsByTagName('head')[0].appendChild(cssNode);
    cssNode = document.createElement('link');
    cssNode.setAttribute('rel', 'stylesheet');
    cssNode.setAttribute('type', 'text/css');
    cssNode.setAttribute('href', 'ccs/tableJR.css');
    document.getElementsByTagName('head')[0].appendChild(cssNode);*/
    this.self = this;
    this.movableJR = mov;
    this.output = document.createElement("div");
    this.output.id = id;
    this.w = w;
    this.h = h;
    this.moving = false;
    this.caption = caption;
    if (language == 1) {
      this.caption = "Zadané spojení (od zadaného času do 2 hodin) nenalezeno";
    }
    if (language == 2) {
      this.caption = "Zadané spojenie (od žiadaného času do 2 hodín) sa nenašlo";
    }
    if (language == 3) {
      this.caption = "None connection";
    }


    this.select = document.createElement("table");
    this.select.className = 'tableSpojeni';
    this.select.style.marginLeft = "15px";
    this.select.style.marginRight = "15px";
//    this.select.style.marginTop = "15px";
//    this.select.style.marginBottom = "15px";
    this.prow = this.select.insertRow(0);

    pcol1 = this.prow.insertCell(0);
    pcol1.className = "tableBorderLeftTop";
    pcol2 = this.prow.insertCell(1);
    pcol2.className = "tableBorderCenterTop";
    pcol3 = this.prow.insertCell(2);
    pcol3.className = "tableBorderCenterTop";
    pcol4 = this.prow.insertCell(3);
    pcol4.className = "tableBorderCenterTop";
    pcol5 = this.prow.insertCell(4);
    pcol5.className = "tableBorderCenterTop";
    pcol6 = this.prow.insertCell(5);
    pcol6.className = "tableBorderRightTop";
    pcol7 = this.prow.insertCell(6);
    pcol7.className = "tableBorderRightTop";

    nrow = 1;

    if (listSpojeni != null) {
    for (i = 0; i < listSpojeni.spoj.size(); i++) {

    this.prow = this.select.insertRow(nrow);
    pcol1 = this.prow.insertCell(0);
    pcol1.className = "tableBorderLeftTop";
    pcol2 = this.prow.insertCell(1);
    pcol3 = this.prow.insertCell(2);
    pcol4 = this.prow.insertCell(3);
    this.a = document.createElement("a");
    this.a.style.fontWeight = "bold";
    if (language == 1) {
      this.a.innerHTML = 'příjezd';
    }
    if (language == 2) {
      this.a.innerHTML = 'príchod';
    }
    if (language == 3) {
      this.a.innerHTML = 'arrival';
    }
    this.a.className = "";
    pcol4.appendChild(this.a);

    pcol5 = this.prow.insertCell(4);
    this.a = document.createElement("a");
    this.a.style.fontWeight = "bold";
    if (language == 1) {
      this.a.innerHTML = 'odjezd';
    }
    if (language == 2) {
      this.a.innerHTML = 'odchod';
    }
    if (language == 3) {
      this.a.innerHTML = 'departure';
    }
    this.a.className = "";
    pcol5.appendChild(this.a);

    pcol6 = this.prow.insertCell(5);
    pcol7 = this.prow.insertCell(6);
    pcol7.className = "tableBorderRightTop";

    nrow++;

      for (ii = 0; ii < listSpojeni.spoj.elementAt(i).partSpoj.size(); ii++) {
    this.row = this.select.insertRow(nrow);    

    this.col = this.row.insertCell(0);
    this.col.className = "tableBorderLeftMid";
    this.col = this.row.insertCell(1);
    obr = document.createElement("img");
    if (listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).Linka.doprava == 'A') {
        obr.src = "http://www.mhdspoje.cz/jrw/test_dpb/png/tra19.PNG";
    }
    if (listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).Linka.doprava == 'T') {
        obr.src = "http://www.mhdspoje.cz/jrw/test_dpb/png/bus19.PNG";
    }
    if (listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).Linka.doprava == 'O') {
        obr.src = "http://www.mhdspoje.cz/jrw/test_dpb/png/tro19.PNG";
    }
    this.col.appendChild(obr);

    this.col = this.row.insertCell(2);
    this.col.className = "tableCell";
    this.a = document.createElement("a");
    this.a.style.fontWeight = "bold";
    this.a.innerHTML = listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).Linka.nazevLinky;
    this.a.className = "";
    this.col.appendChild(this.a);

    this.col = this.row.insertCell(3);
    this.col.className = "tableCell1";
    this.a = document.createElement("a");
//    this.a.style.fontWeight = "bold";
//    if (ii / 2 != ii % 2) {
      this.a.innerHTML = '-';//formatHHMM(listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).odH, listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).odM);
//    }
    this.a.className = "";
    this.col.appendChild(this.a);

    this.col = this.row.insertCell(4);
    this.col.className = "tableCell1";
    this.a = document.createElement("a");
//    this.a.style.fontWeight = "bold";
//    if (ii / 2 == ii % 2) {
      this.a.innerHTML = formatHHMM(listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).odH, listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).odM);
//    }
    this.a.className = "";
    this.col.appendChild(this.a);
    
    this.col = this.row.insertCell(5);
    this.col.className = "tableCellZastavka";
    this.a = document.createElement("a");
    this.a.innerHTML = listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).odZastavky;//.nazevZastavky;
    this.a.className = "";
    this.col.appendChild(this.a);

    this.col = this.row.insertCell(6);
    this.col.className = "tableBorderRightMid";

    nrow++;
    
    this.row = this.select.insertRow(nrow);
    if ((ii == listSpojeni.spoj.elementAt(i).partSpoj.size() - 1) && (i < listSpojeni.spoj.size() - 1)) {
      this.row.className = "tableRow";
    } else {
      this.row.className = "";
    }

    this.col = this.row.insertCell(0);
    this.col.className = "tableBorderLeftMid";
    this.col = this.row.insertCell(1);
    this.col = this.row.insertCell(2);

    this.col = this.row.insertCell(3);
    this.col.className = "tableCell1";
    this.a = document.createElement("a");
//    this.a.style.fontWeight = "bold";
//    if (ii / 2 != ii % 2) {
      this.a.innerHTML = formatHHMM(listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).doH, listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).doM);
//    }
    this.a.className = "";
    this.col.appendChild(this.a);

    this.col = this.row.insertCell(4);
    this.col.className = "tableCell1";
    this.a = document.createElement("a");
//    this.a.style.fontWeight = "bold";
//    if (ii / 2 == ii % 2) {
      this.a.innerHTML = '-';//formatHHMM(listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).doH, listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).doM);
//    }
    this.a.className = "";
    this.col.appendChild(this.a);
    
    this.col = this.row.insertCell(5);
    this.col.className = "tableCellZastavka";
    this.a = document.createElement("a");
    this.a.innerHTML = listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).doZastavky;//.nazevZastavky;
    this.a.className = "";
    this.col.appendChild(this.a);

    this.col = this.row.insertCell(6);
    this.col.className = "tableBorderRightMid";

//     + " - " +  + " " +  + " -> " + listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).doH + ":" + listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).doM + " " + listSpojeni.spoj.elementAt(i).partSpoj.elementAt(ii).doZastavky.nazevZastavky;

    nrow++;
      }
    }

    } else {
      this.prow = this.select.insertRow(nrow);
      pcol1 = this.prow.insertCell(0);
      pcol1.className = "tableBorderLeftMid";
      pcol2 = this.prow.insertCell(1);
      this.a = document.createElement("a");
      this.a.innerHTML = this.caption;
      pcol2.appendChild(this.a);
      pcol3 = this.prow.insertCell(2);
      pcol4 = this.prow.insertCell(3);
      pcol5 = this.prow.insertCell(4);
      pcol6 = this.prow.insertCell(5);
      pcol7 = this.prow.insertCell(6);
      pcol7.className = "tableBorderRightMid";
      nrow++;
    }

    this.rowpoznamky = this.select.insertRow(nrow);
    col1 = this.rowpoznamky.insertCell(0);
    col1.className = "tableBorderLeftMid";
    this.colpoznamky = this.rowpoznamky.insertCell(1);
    this.colpoznamky.style.textAlign = "right";
    this.colpoznamky.colSpan = 5;
    this.colpoznamky.style.mode = "auto";
    this.colpoznamky.style.whiteSpace = "pre";
    this.colpoznamky.style.borderTopStyle = "solid";
    this.colpoznamky.style.borderTopWidth = "1px";
    this.colpoznamky.style.borderColor = "#666666";
    a = document.createElement("a");
    a.className = "FS";
    a.innerHTML = "JRw ver. 2.0. - SKELETON &reg FS software s.r.o.";
    this.colpoznamky.appendChild(a);
    pcol7 = this.rowpoznamky.insertCell(2);
    pcol7.className = "tableBorderRightMid";

    nrow++;

    this.prow = this.select.insertRow(nrow);
    pcol1 = this.prow.insertCell(0);
    pcol1.className = "tableBorderLeftBottom";
    pcol2 = this.prow.insertCell(1);
    pcol2.className = "tableBorderCenterBottom";
    pcol3 = this.prow.insertCell(2);
    pcol3.className = "tableBorderCenterBottom";
    pcol4 = this.prow.insertCell(3);
    pcol4.className = "tableBorderCenterBottom";
    pcol5 = this.prow.insertCell(4);
    pcol5.className = "tableBorderCenterBottom";
    pcol6 = this.prow.insertCell(5);
    pcol6.className = "tableBorderCenterBottom";
    pcol7 = this.prow.insertCell(6);
    pcol7.className = "tableBorderRightBottom";

    this.output.appendChild(this.select);
}

JRSpojeni.prototype.getHeight = function() {
    return this.select.offsetHeight;
}

JRSpojeni.prototype.show = function(tag) {
    ntag = document.getElementById(tag);
    for(x = 0; ntag.childNodes[x]; x++) {
        ntag.removeChild(ntag.childNodes[x]);
    }
    ntag = document.getElementById(tag);
    for(x = 0; ntag.childNodes[x]; x++) {
        ntag.removeChild(ntag.childNodes[x]);
    }

//    ntag.appendChild(this.output);

    this.pozaditab = document.createElement("table");
    this.pozaditab.className = "jrtable";
    this.pozadirow = this.pozaditab.insertRow(0);
    this.pozadicol = this.pozadirow.insertCell(0);

    this.pozadidiv = document.createElement("div");
    this.pozadidiv.className = "pozadi";
    if (this.movableJR == true) {
      this.pozadidiv.style.backgroundColor = '#ffffff';
    }

    this.pozadidiv.appendChild(this.output);

    this.obloukdiv = document.createElement("div");
    this.obloukdiv.className = "pozadioblouk"
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_1";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_2";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_3";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_4";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_5";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_6";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_7";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_8";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_9";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);

    if (this.movableJR == true) {
    moving = false;

    this.obloukdiv.onmousedown = function mouseDown(ev) {
      this.moving = true;
      ev = ev || window.event;
      var mousePos = mouseCoords(ev);
      mx = mousePos.x;
      my = mousePos.y;
      moving = true;
      document.onselectstart = function(ev) {return false;};
    }

    this.obloukdiv.onmouseup = function() {
      this.moving = false;
      moving = false;
      document.onselectstart = null;
    }
    
    this.obloukdiv.style.height = '25px';
    this.obloukdiv.style.cursor = 'move';
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
//    }

    closemoving = false;
  this.obrclose = document.createElement('img');
  this.obrclose.className = "close";
  this.obrclose.src = "http://www.mhdspoje.cz/jrw20/png/closeinactive.png";
  this.obrclose.onmouseover = function closeOver(ev) { this.src = "http://www.mhdspoje.cz/jrw20/png/closeactive.png"; };
  this.obrclose.onmouseout = function closeOut(ev) { this.src = "http://www.mhdspoje.cz/jrw20/png/closeinactive.png"; };
  this.obrclose.onmousedown = function closeDown(ev) { closemoving = true; };
  this.obrclose.onmouseup = function closeup(ev) { closemoving = false; };
  this.obrclose.onmousemove = null;//function closeDown(ev) { /*moving = false;*/ };
  this.obrclose.onclick = function closeclick(ev) {
    document.body.removeChild(document.getElementById('divSpojeni'));
  }
  this.obloukdiv.appendChild(this.obrclose);
  }

    this.pozadicol.appendChild(this.obloukdiv);
    this.pozadicol.appendChild(this.pozadidiv);

    this.obloukdiv = document.createElement("div");
    this.obloukdiv.className = "pozadioblouk"
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_10";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_9";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_8";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_7";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_6";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_5";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_4";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_3";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_2";
    this.obloukdiv.appendChild(this.obloukelement);
    this.obloukelement = document.createElement("div");
    this.obloukelement.className = "pozadi1_1";
    this.obloukdiv.appendChild(this.obloukelement);

    this.pozadicol.appendChild(this.obloukdiv);

    ntag.appendChild(this.pozaditab);

//    document.getElementById("load").style.visibility = "hidden";
    document.getElementById('divSpojeni').style.visibility = 'visible';
    if (this.movableJR == true) {
    document.onmousemove = function mouseMove(ev){
      if (moving == true) {
        ev = ev || window.event;
        var mousePos = mouseCoords(ev);
        document.getElementById('divSpojeni').style.left = document.getElementById('divSpojeni').offsetLeft + (mousePos.x - mx) + 'px';
        document.getElementById('divSpojeni').style.top = document.getElementById('divSpojeni').offsetTop + (mousePos.y - my) + 'px';
        mx = mousePos.x;
        my = mousePos.y;
      }
    }
  }
}
