  var status_names = '~-~1ტ.~2ტ.~დამთ.~შეწყ.~გაუქ.~გად.~დამ. დრო~შესვ.'.split("~");
  var reloadInterval=30;
  var begTime=new Date();
  var gm;
  var xmlhttp, alerted;
  var st="00:00";
  var h="0";
	
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  // JScript gives us Conditional compilation, we can cope with old IE versions.
  try {
    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      alert("You must have Microsofts XML parsers available");
    }
  }
  @else
    alert("You must have JScript version 5 or above.");
    xmlhttp=false;
    alerted=true;
  @end @*/

  if (!xmlhttp && !alerted) 
  {
    try {
      if (window.ActiveXObject)  
        xmlhttp = new ActiveXObject(Microsoft.XMLHTTP);
      else
        xmlhttp = new XMLHttpRequest();
    } catch (e) 
    {
      alert("You need a browser which supports an XMLHttpRequest Object.")
    }
  }


  function setZero()
  {
    h="0";
  }
	
  function initConst()
  {
    gm = document.getElementById("scores");
  }
	
  function parseVars() {
    if (xmlhttp.readyState==4) {
      if(xmlhttp.status == 200)
      {
        sa = xmlhttp.responseText.split("~");
        if (h != sa[1]) {
          h = sa[1];
          st = sa[0]; 
          loadData();
        } 
        if (st != sa[0]) {
          st = sa[0];
          setServerTimes();
	  setTimes();
        }
      }
    }
  }

  function parseData() {
    if (xmlhttp.readyState==4) {
      if(xmlhttp.status == 200) {
        generateTables(xmlhttp.responseText);		
      }
    }
  }
  

  function getVars(url) {
    if (xmlhttp) {
      xmlhttp.open("GET", url,true);
      xmlhttp.onreadystatechange=parseVars;
      xmlhttp.send(null);
    }
  }
  
	
  function getData(url) {
    if (xmlhttp) {
      xmlhttp.open("GET", url,true);
      xmlhttp.onreadystatechange=parseData;
      xmlhttp.send(null);
    }
  }
	
  function loadVars()	
  {
    getVars("live1_1.html?rnd="+Math.random());
  }

  function loadData()
  {
    getData("live1_2.html?rnd="+Math.random());
  }

  function createTD(S1, S2)
  {
    if (eval(S1) != 0)
      return '<td class=' + S2 + '>' + S1 + '</td>';
    else
      return '<td></td>';
  }

  function initAll()
  {
    window.location.reload(true);
  }

  function processLoad()
  {
    loadVars();
    window.setTimeout("processLoad()", 1000 * reloadInterval);
  }
	
  function createGameList(S, tid){
    if (S == "" || S == null)
      return "";
    dataArray = S.split("#");
    html =  [];
    html.push("<table border=1 id=tbl_curr cellpadding=0 cellspasing=0 style='border-collapse: collapse;'>");
    html.push("<colgroup><col width=80><col width=95><col width=60><col width=30><col>");
    html.push("<col width=90><col><col width=30></colgroup>");
    html.push("<tr><td colspan=8 style='text-align:left;' id='srt1'>");
    html.push("<b>დრო: ");
    html.push(st);
    html.push("</b></td></tr>");
    html.push("<tr class='header2'><td >დრო</td><td colspan=2>სტატ.</td>");
    html.push('<td class="r"></td><td>1-ი გუნდი</td><td>ანგ.</td>');
    html.push('<td>2-ე გუნდი </td><td class="r"></td></tr>');
	
    for (i=1; i<dataArray.length; i++)
    {
      data = dataArray[i].split("~");
      if (data[0] == 'h' ) {
        html.push('<tr valign=top><td colspan=8 class="header">');
        html.push(data[1]);
        html.push("&nbsp;-&nbsp;");
        html.push(data[2]);
        html.push('&nbsp;</td></tr>');
      } else
      {
        html.push('<tr><td class=tm>');
        html.push(data[1] );
        html.push('</td><td class=stat id=st');
        html.push(data[2]);
        html.push(">");
        html.push(status_names[eval(data[2])] );
        html.push('</td><td class=tm  id=ct');
        html.push(eval(data[13]));
        html.push('>');
        html.push(gameTime(data[1], data[13], data[2]));
        html.push('</td>');
        html.push(createTD(data[5], "r"));
        html.push('<td class=gm >');
        html.push(data[3]);
        html.push('</td><td class=res>');
        html.push(data[10] );
        html.push('</td>');
        html.push('<td class=gm>');
        html.push(data[6]);
        html.push('</td>');
        html.push(createTD(data[8], "r"));
        html.push('</tr>');
      }
    }
    
    html.push('<tr><td colspan=8 class="ll"></td></tr>');
    html.push("</table>");
    return html.join('');
  }
	
  function convertToMinute(AS)
  {
    if (AS.charAt(0) == "(") 
      AS = AS.substring(1, S.length-1);  
    ii = AS.indexOf(":");
    ii = eval(AS.substring(0, ii)) * 60 + eval(AS.substring(ii+1));
    return ii;
  }

  function gameTime(adt, act, atp)
  {
    if (atp=='1' || atp == '4' || atp=='5' || atp=='6' ||  atp=='7' || atp=='9')
      return '-';
    gtm = convertToMinute(st) - convertToMinute(adt) + eval(act);
    if (gtm < 0) gtm += 24 * 60;
    if(atp == "2") {
      if(gtm < 1) return "1'";
      if(gtm> 45) return "45'";
    }
    if(atp == "3") {
      gtm-= 18;
      if(gtm< 46) return "46'";
      if(gtm > 90) return "90'";
    }
    if(atp == "8")  {
      gtm -= 36;
      if( gtm< 91) return "91'";
      if(gtm > 120) return "120'";
    }
    return gtm + "'";
  }
  
  function setTimes()
  {
    var tbl=document.getElementById("tbl_curr");
    if (tbl != null)
      for (ti=0; ti < tbl.rows.length; ti++)
      {
        row = tbl.rows[ti];
        if (row.cells.length  == 8 ) {
          dtt=row.cells[0].innerHTML;
          stt=row.cells[1].id.substring(2);
          ctt=row.cells[2].id.substring(2);
          row.cells[2].innerHTML = gameTime(dtt, ctt, stt);
        }
      }
  }
  
  function setServerTimes(){
    if (document.getElementById("srt1") != null)
    {
          document.getElementById("srt1").innerHTML = "<b>დრო: " + st + "</b>";
    }
    return;
  }
  
  function generateTables(S)
  {
    j = S.indexOf("#E");
    Scurr=S.substring(0, j );
    gm.innerHTML=createGameList(Scurr);
  }
