// Projekty Js
var g_div        = 'proj_popis';
var g_div_nadpis = 'proj_nadpis';
var g_div_obsah  = 'proj_obsah';
var g_move       = 'FALSE';
var rel          = /&nbsp;/g;
var t_projekty   = new Array("91", "65", "14", "31", "134", "83", "79", "97", "118", "24", "85", "32", "113", "80", "27", "33", "25", "6", "110", "86", "66", "64", "19", "59", "90", "122", "129", "26", "11", "87", "81", "23", "104", "84", "121", "106", "36", "88", "93", "102", "99", "92", "2", "53", "112", "30", "119", "82", "69", "52", "100", "46", "40", "60", "70", "124", "63", "49", "34", "4", "115", "76", "13", "74", "116", "117", "61", "68", "123", "103", "62", "18", "22", "126", "95", "56", "131", "125", "67", "98", "108", "10", "57", "78", "3", "111", "7", "20", "71", "17", "105", "37", "77", "89", "42", "51", "94", "75", "43", "101", "55", "5", "96", "133", "47", "16", "1", "38", "48", "12", "120", "29", "114", "54", "45", "128", "8", "15", "130", "44", "58", "9", "73", "72", "127", "109", "41", "39", "50", "107", "35", "132", "28", "21", "1002", "1007", "1003", "1004", "1009", "1005", "1008", "1006", "1001");

function Center_Description() {
  var t_w = 0;
  var t_h = 0;
  var t_obj = document.getElementById(g_div);
  t_obj.style.left = t_w + "px";
  t_obj.style.top  = t_h + "px";
  if      (window.innerHeight)                                                t_h = window.innerHeight;
  else if (document.documentElement && document.documentElement.clientHeight) t_h = document.documentElement.clientHeight;
  else if (document.body && document.body.clientHeight)                       t_h = document.body.clientHeight;
  else                                                                        t_h = 0;
  if      (window.innerWidth)                                                 t_w = window.innerWidth;
  else if (document.documentElement && document.documentElement.clientWidth)  t_w = document.documentElement.clientWidth;
  else if (document.body && document.body.clientWidth)                        t_w = document.body.clientWidth;
  else                                                                        t_w = 0;
  if      (window.pageXOffset)                                                t_x = window.pageXOffset;
  else if (document.documentElement && document.documentElement.scrollLeft)   t_x = document.documentElement.scrollLeft;
  else if (document.body && document.body.scrollLeft)                         t_x = document.body.scrollLeft;
  else                                                                        t_x = 0;
  if      (window.pageYOffset)                                                t_y = window.pageYOffset;
  else if (document.documentElement && document.documentElement.scrollTop)    t_y = document.documentElement.scrollTop;
  else if (document.body && document.body.scrollTop)                          t_y = document.body.scrollTop;
  else                                                                        t_y = 0;
  if (t_w != 0 ) t_obj.style.left = ( parseInt(t_w / 2) - 250 + parseInt(t_x) ) + "px";
  if (t_h != 0 ) t_obj.style.top  = ( parseInt(t_h / 2) - 150 + parseInt(t_y) ) + "px";
}

function processRequest(httpRequest, kam)
{
  if (httpRequest.readyState == 4) {
    if (( httpRequest.status >= 200 && httpRequest.status < 300 ) || httpRequest.status == 304) {
      if (typeof kam == 'string') {
        document.getElementById(kam).innerHTML = httpRequest.responseText;
      }
    }
    else {
      document.getElementById(kam).innerHTML = "Chyba při načtení stránky " + httpRequest.status +" : "+ httpRequest.statusText;
    }
  }
  else {
    document.getElementById(kam).innerHTML = '<center><br><br><br><br><br><br><br><br><br><br><img border="0" src="image/proj_pro.gif"><br><br><br><br><br><br><br><br><br><br></center>';
  }
}

function processRequestRSS(httpRequest, kam)
{
  if (httpRequest.readyState == 4) {
    if (( httpRequest.status >= 200 && httpRequest.status < 300 ) || httpRequest.status == 304) {
      if (typeof kam == 'string') {
        document.getElementById(kam).innerHTML = httpRequest.responseText;
      }
    }
    else {
      document.getElementById(kam).innerHTML = '';
    }
  }
  else {
    document.getElementById(kam).innerHTML = '';
  }
  if ( document.getElementById(kam).innerHTML == "" ) {
    document.getElementById('pr_row1_feed').style.display = 'none';
    document.getElementById('pr_row2_feed').style.display = 'none';
    document.getElementById('pr_row3_feed').style.display = 'none';
    document.getElementById('pr_row4_feed').style.display = 'none';
  }
  else {
    document.getElementById('pr_row1_feed').style.display = '';
    document.getElementById('pr_row2_feed').style.display = '';
    document.getElementById('pr_row3_feed').style.display = '';
    document.getElementById('pr_row4_feed').style.display = 'none';
  }
}

function StavProjektu(projekt, adresa)
{
  var kam = 'pr_data_stat';
  document.getElementById('pr_row1_appl').style.display = 'none';
  document.getElementById('pr_row2_appl').style.display = 'none';
  document.getElementById('pr_row3_appl').style.display = 'none';
  document.getElementById('pr_row4_appl').style.display = 'none';
  document.getElementById(kam).innerHTML = '';
  document.getElementById('pr_row1_stat').style.display = '';
  document.getElementById('pr_row2_stat').style.display = '';
  document.getElementById('pr_row3_stat').style.display = '';
  document.getElementById('pr_row4_stat').style.display = '';
  var httpRequest;
  if (typeof window.ActiveXObject != 'undefined') {
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else {
    httpRequest = new XMLHttpRequest();
  }
  if      ( projekt == 'SETI' ) {
    httpRequest.open("GET", './ajax_server_status_seti.php?projekt=' + projekt + '&adresa=' + adresa, true);
  }
  else if ( projekt == 'QMC' ) {
    httpRequest.open("GET", './ajax_server_status_qmc.php?projekt=' + projekt + '&adresa=' + adresa, true);
  }
  else if ( projekt == 'GPUGRID/PS3GRID' ) {
    httpRequest.open("GET", './ajax_server_status_46.php?projekt=' + projekt + '&adresa=' + adresa, true);
  }
  else {
    httpRequest.open("GET", './ajax_server_status.php?projekt=' + projekt + '&adresa=' + adresa, true);
  }
  httpRequest.onreadystatechange = function ()
  {
    processRequest(httpRequest, kam)
  };
  httpRequest.send(null);
}

function Aplikace(projekt, adresa)
{
  var kam = 'pr_data_appl';
  document.getElementById('pr_row1_stat').style.display = 'none';
  document.getElementById('pr_row2_stat').style.display = 'none';
  document.getElementById('pr_row3_stat').style.display = 'none';
  document.getElementById('pr_row4_stat').style.display = 'none';
  document.getElementById(kam).innerHTML = '';
  document.getElementById('pr_row1_appl').style.display = '';
  document.getElementById('pr_row2_appl').style.display = '';
  document.getElementById('pr_row3_appl').style.display = '';
  document.getElementById('pr_row4_appl').style.display = '';
  var httpRequest;
  if (typeof window.ActiveXObject != 'undefined') {
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else {
    httpRequest = new XMLHttpRequest();
  }
  httpRequest.open("GET", './ajax_aplikace.php?projekt=' + projekt + '&adresa=' + adresa, true);
  httpRequest.onreadystatechange = function ()
  {
    processRequest(httpRequest, kam)
  };
  httpRequest.send(null);
}

function RSS_Feed(projekt, adresa)
{
  var kam = 'pr_data_feed';
//  document.getElementById(kam).style.display = 'none';
  document.getElementById(kam).innerHTML = '';
  var httpRequest;
  if (typeof window.ActiveXObject != 'undefined') {
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else {
    httpRequest = new XMLHttpRequest();
  }
  httpRequest.open("GET", './ajax_rss.php?projekt=' + projekt + '&adresa=' + adresa, true);
  httpRequest.onreadystatechange = function ()
  {
    processRequestRSS(httpRequest, kam)
  };
  httpRequest.send(null);
}

function Show_Description(proj,pid) {
  document.getElementById(g_div).style.display = '';
  document.getElementById(g_div_nadpis).innerHTML = proj;
  document.getElementById(g_div_obsah).innerHTML = '<center><br><br><br><br><br><br><br><br><br><br><img border="0" src="image/proj_pro.gif"></center>';
  Center_Description();
  document.getElementById(g_div).style.display = 'block';

  var httpRequest;
  if (typeof window.ActiveXObject != 'undefined') {
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else {
    httpRequest = new XMLHttpRequest();
  }
  httpRequest.open("GET", './projekty_description.php?pid=' + pid, true);
  httpRequest.onreadystatechange = function ()
  {
    processRequest(httpRequest, g_div_obsah)
  };
  httpRequest.send(null);
}

function HideServerStatus() {
  document.getElementById('pr_row1_stat').style.display = 'none';
  document.getElementById('pr_row2_stat').style.display = 'none';
  document.getElementById('pr_row3_stat').style.display = 'none';
  document.getElementById('pr_row4_stat').style.display = 'none';
  return false;
}

function HideApplication() {
  document.getElementById('pr_row1_appl').style.display = 'none';
  document.getElementById('pr_row2_appl').style.display = 'none';
  document.getElementById('pr_row3_appl').style.display = 'none';
  document.getElementById('pr_row4_appl').style.display = 'none';
  return false;
}

function HideRSSFeed() {
  if ( document.getElementById('but_zmena').src.indexOf('but_up') != '-1' ) {
    document.getElementById('pr_row4_feed').style.display = 'none';
    document.getElementById('but_zmena').src = 'image/but_down.png';
  }
  else {
    document.getElementById('pr_row4_feed').style.display = '';
    document.getElementById('but_zmena').src = 'image/but_up.png';
  }
  return false;
}

function DownThisDiv() {
  g_move = 'TRUE';
  var t_obj = document.getElementById(g_div);
}

function UpThisDiv() {
  g_move = 'FALSE';
}

function MoveThisDiv() {
  if ( g_move == 'TRUE' ) {
  }
  else {
  }
}

function OdesliEmail(komu){
	if (!komu)
    return;
	var adresa = new String("") + komu.replace(" (at) ", "@");
	adresa = adresa.replace(" (dot) ", ".");
	document.location = "mailto:" + adresa;
	
}

function VyhledejText() {
  var ts = document.getElementById('textsearch');
  var ts_text = ts.value;
  if (ts_text.length < 3) {
    ts.focus();
  }
  else { 
    location.href = 'http://projekty.czechnationalteam.cz/index.php?akce=projekty_search&text=' + ts_text;
//    document.getElementById('menu65').style.display = 'none';
//    window.status = '[' + document.getElementById('menu65').innerHTML + ']';
  }
}

function VyhledejTextE(e) {
  var ts = document.getElementById('textsearch');
  var ts_text = ts.value;
  var klavesa = '';
       if(window.event) klavesa = e.keyCode;
  else if(e.which)      klavesa = e.which;
  if (klavesa == 13) {
    VyhledejText();
  }
}

function FiltrujProjektyE(e,v) {
  if (v.length > 0) {
    v = v.toLowerCase();
    var pr = '';
    var po = 0;
    for (i = 0; i < t_projekty.length; i++) {
      var pr = document.getElementById('menu' + t_projekty[i]).innerHTML;
      pr = pr.toLowerCase();
      po = pr.indexOf(v);
      if ( po < 0 ) {
        document.getElementById('menu' + t_projekty[i]).style.display = 'none';
      }
      else {
        document.getElementById('menu' + t_projekty[i]).style.display = '';
      }
    }
  }
  else {
    for (i = 0; i < t_projekty.length; i++) {
      document.getElementById('menu' + t_projekty[i]).style.display = '';
    }
  }
}

function Nacti_Grafiku() {
/*
  var g_bac = new Image();  g_bac.src = "image/proj_backg.png";  // pozadí
  var g_rig = new Image();  g_rig.src = "image/proj_right.png";  // pravý konec
  var g_ast = new Image();  g_ast.src = "image/proj_ast.png";    // Astrologie
  var g_bio = new Image();  g_bio.src = "image/proj_bio.png";    // Biologie
  var g_fyz = new Image();  g_fyz.src = "image/proj_fyz.png";    // Fyzika
  var g_gra = new Image();  g_gra.src = "image/proj_gra.png";    // Grafika
  var g_hry = new Image();  g_hry.src = "image/proj_hry.png";    // Hry
  var g_kry = new Image();  g_kry.src = "image/proj_kry.png";    // Kryptografie
  var g_mat = new Image();  g_mat.src = "image/proj_mat.png";    // Matematika
  var g_nte = new Image();  g_nte.src = "image/proj_nte.png";    // Nové technologie
  var g_ost = new Image();  g_ost.src = "image/proj_ost.png";    // Ostatní
  var g_tes = new Image();  g_tes.src = "image/proj_tes.png";    // Testovací
  var g_zem = new Image();  g_zem.src = "image/proj_zem.png";    // Země
  var g_boi = new Image();  g_boi.src = "image/proj_boi.png";    // BOINC
  var g_neb = new Image();  g_neb.src = "image/proj_neb.png";    // Ne BOINC
*/
  var g_pro  = new Image();  g_pro.src = "image/proj_pro.gif";    // progress
  var g_up   = new Image();  g_pro.src = "image/but_up.png";      // sipka nahoru
  var g_down = new Image();  g_pro.src = "image/but_down.png";    // sipka dolu
}
// Projekty Js

