// IMAGE PRELOAD --------------------------
preload_image_object = new Image();
preload_image_object.src = '/css/loading.gif';

// VARS -----------------------------------
var CANCEL = false;
var WEB_LOADING_ID = 'web_loading';
var LOADING_PANEL = 'loadingpanel';
var curtime = 0;

// FUNCTIONS ------------------------------
function getinfo(url)
{
  ds = document.getElementById('darkscreen');
  ds.style.height = document.body.clientHeight + 'px';
  ds.style.opacity = .7; 
  ds.style.filter = 'alpha(opacity=70)'; 
  ds.style.display = 'block';
  
  load = document.getElementById(LOADING_PANEL);
  left = Math.round(document.body.clientWidth / 2 - 128);
  load.style.left = left + 'px';
  load.style.display = 'block';
  
  setTimeout("timeup()", 1000);
  
  // AJAX -----------------------------------------------------------
  if (window.ActiveXObject)
  {
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else
  {
    httpRequest = new XMLHttpRequest();
  }
  
  httpRequest.open("GET", url, true);
  httpRequest.onreadystatechange= function () {  
      if(httpRequest.readyState==4) document.location.href = httpRequest.responseText;
    };
  httpRequest.send(null);
}

function getwebinfo(url, table_id)
{ 
  // AJAX -----------------------------------------------------------
  if (window.ActiveXObject)
  {
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else
  {
    httpRequest = new XMLHttpRequest();
  }
  
  httpRequest.open("GET", url, true);
  httpRequest.onreadystatechange= function () {  
      if(httpRequest.readyState==4) 
      {
        lines = httpRequest.responseText.split("\n");
        if (lines[0] == 'false') document.getElementById(WEB_LOADING_ID).style.display = 'none';
        else
        {
          if (lines[0] != 'invalid')
          {
            // PRIDAT RADEK DO TABULKY
            var table = document.getElementById(table_id);
            
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
            
            if (rowCount % 2 == 0) row.className = 'dark';
            else row.className = 'light';

            var cell1 = row.insertCell(0);
            cell1.innerHTML = '<a href="'+lines[1]+'" target="_blank">'+lines[2]+'</a>';
            
            var cell2 = row.insertCell(1);
            cell2.innerHTML = lines[3];
            cell2.className = 'value';
          }
          
          if (CANCEL == false) getwebinfo(url, table_id);
          else document.getElementById(WEB_LOADING_ID).style.display = 'none';
        }
      }
    };
  httpRequest.send(null);
}

function cancelgetwebinfo()
{
  document.getElementById(WEB_LOADING_ID).innerHTML = 'Ruším prověřování ...';
  CANCEL = true;
}

function timeup()
{
  curtime++;
  document.getElementById(LOADING_PANEL).innerHTML = "Čas testování: " + curtime + " s";
  setTimeout("timeup()", 1000);
}
