function getInnerText(elt) {
    var _innerText = elt.innerText;
    if (!_innerText) {
            _innerText = elt.innerHTML.replace(/<[^>]+>/g,"");
    }
    return _innerText;
}

function addRowToTable(sira,mackodu, macadi,oran,oyuntipi,MBS,tercih)
{
  var iteration = "";
  if( parent.document.getElementById('addedmatchcodes').value.indexOf("#" + mackodu + "#") == -1 || oyuntipi == 'SC' || oyuntipi == 'UV' ) {
      
      parent.document.getElementById('addedmatchcodes').value = parent.document.getElementById('addedmatchcodes').value + "#" + mackodu + "#" + oyuntipi + "#" ;
      document.getElementById('itera').value = (document.getElementById('itera').value *1 ) + 1;
      
      var tbl = parent.document.getElementById('erkut');
      var lastRow = tbl.rows.length;
      // if there's no header row in the table, then iteration = lastRow + 1
      iteration = lastRow;
      //var iteration = document.getElementById('itera').value;
      
      //<TR><TD COLSPAN="4"><IMG SRC="http://images.bilyoner.com/site/1px.gif" WIDTH="1" HEIGHT="3" BORDER="0"><BR></TD></TR>      
      var row = tbl.insertRow(lastRow);      
      var cellLeft = row.insertCell(0);
      var textNode = parent.document.createTextNode(iteration);
      cellLeft.setAttribute('colspan','4');
      cellLeft.appendChild(textNode);
      cellLeft.innerHTML="<IMG SRC=\"http://images.bilyoner.com/site/1px.gif\" WIDTH=\"1\" HEIGHT=\"3\" BORDER=\"0\"><BR>";
      
      //<TR><TD WIDTH="15"><IMG SRC="http://images.bilyoner.com/site/delete_9x9.gif" ALT="Sil" WIDTH="9" HEIGHT="9" BORDER="0" STYLE="margin-top:1px; cursor:pointer"><BR></TD></TR>
      
      var row = tbl.insertRow(lastRow+1);      
      row.setAttribute('id',mackodu);      
           
      var cellLeft = row.insertCell(0);
      cellLeft.setAttribute('width','27');
      var textNode = parent.document.createTextNode(iteration);
      cellLeft.appendChild(textNode);
      cellLeft.innerHTML="<input type=checkbox  STYLE=\"margin-left:2px\" onClick=\"hesapla();\" title=Banko name='banko' id=banko" + mackodu + "><BR>";      
       
      //Mac Kodu

      var cellLeft = row.insertCell(1);
      var textNode = parent.document.createTextNode(mackodu);
      var yazacak = "";
      if (oyuntipi != "UV") yazacak ="<font class='v9px'><B>"+mackodu+"</B></font><BR>";
      cellLeft.setAttribute('width','24');
      cellLeft.setAttribute('className','v9px');
      cellLeft.appendChild(textNode);
      cellLeft.innerHTML=yazacak;
      
      //Mac Adi
      var cellLeft = row.insertCell(2);
      var textNode = parent.document.createTextNode(macadi);
      cellLeft.setAttribute('width','179');
      cellLeft.setAttribute('className','v10px');      
      cellLeft.appendChild(textNode);
      cellLeft.innerHTML="<font class='v10px'>" + macadi+"</font><BR>";      

      //remove..    
      var cellLeft = row.insertCell(3);
      //var textNode = parent.document.createTextNode(iteration);
      cellLeft.setAttribute('width','15');      
      
      var sorsde = "http://images.bilyoner.com/site/delete_9x9.gif";
     

     
      var ttt = "DIGER";
      
      if (oyuntipi == "SC" || oyuntipi == "UV" ) {
        ttt = "SC";
      } else {
        ttt = "DIGER";
      }
      //İNCELE!!!!
      
      cellLeft.innerHTML = "<img src=" + sorsde + " onclick=\"rrft('" + ttt + "'," + iteration +"-1,\'\#" + mackodu + "\#\',"+mackodu+",1,"+ sira +",event);\" STYLE='margin-top:1px; cursor:pointer'>";

      //alert(cellLeft.innerHTML);
      
      var row = tbl.insertRow(lastRow+2);        
      row.setAttribute('id', mackodu + "*");

      var cellLeft = row.insertCell(0);

      //oyuntipi
      var cellLeft = row.insertCell(1);      
      var myHint =  ""; 
      if(oyuntipi=="F")  {imagelink = "http://images.bilyoner.com/site/kuponicon_ms.gif"; myHint = "Oyun Tipi : Maç Sonucu"; }
      if(oyuntipi=="FS") {imagelink = "http://images.bilyoner.com/site/kuponicon_c.gif";  myHint = "Oyun Tipi : Çifte Şans"; }
      if(oyuntipi=="SF") {imagelink = "http://images.bilyoner.com/site/kuponicon_im.gif"; myHint = "Oyun Tipi : İlk Yarı/Maç Sonucu"; }
      if(oyuntipi=="SC") {imagelink = "http://images.bilyoner.com/site/kuponicon_sk.gif"; myHint = "Oyun Tipi : Maç Skoru"; }
      if(oyuntipi=="UV") {imagelink = "http://images.bilyoner.com/site/kuponicon_uv.gif"; myHint = "Oyun Tipi : Uzun Vadeli"; }
      if(oyuntipi=="UO") {imagelink = "http://images.bilyoner.com/site/kuponicon_au.gif"; myHint = "Oyun Tipi : Uzun Vadeli"; }
      oyuntipiStr = "<IMG SRC=\" " + imagelink + "\" ALT=\"" + myHint + "\" WIDTH=\"16\" HEIGHT=\"11\" BORDER=\"0\" STYLE=\"margin-top:1px\"><BR> ";
      var textNode = parent.document.createTextNode(oyuntipi);
      cellLeft.appendChild(textNode);
      cellLeft.innerHTML=oyuntipiStr;

      var tire = "";
      if (oyuntipi != "UV") tire = " - ";

      //tercih
      var cellLeft = row.insertCell(2);
      cellLeft.id= mackodu + "K";            
      cellLeft.setAttribute('className','v9px');
      cellLeft.innerHTML = "<font class='v9px'>" + tercih + tire + oran + "</font>";

      var cellLeft = row.insertCell(3);
      
      var row = tbl.insertRow(lastRow+3);           
      var cellLeft = row.insertCell(0);
      var textNode = parent.document.createTextNode(iteration);
      cellLeft.setAttribute("colspan",4);
      cellLeft.innerHTML="<IMG SRC=\"http://images.bilyoner.com/site/1px.gif\" WIDTH=\"1\" HEIGHT=\"7\" BORDER=\"0\"><BR>";


      var row = tbl.insertRow(lastRow+4);   
      
      if ( document.all ) 
      {
        var a = parent.document.createElement('td');
        a.colSpan =4;
        a.background = 'http://images.liberonette.com/site/dots_1x3.gif';
        a.innerHTML = "<IMG SRC=\"http://images.liberonette.com/site/x.gif\" WIDTH=\"1\" HEIGHT=\"1\" BORDER=\"0\"><BR>";
        row.appendChild(a);
       } else {
        row.innerHTML = "<td background = 'http://images.bilyoner.com/site/dots_1x3.gif' colspan = 4> <IMG SRC=\"http://images.bilyoner.com/site/1px.gif\" WIDTH=\"1\" HEIGHT=\"1\" BORDER=\"0\"><BR></td>";
       }
      
      

      
  } else {
      
         var tire = "";
         if (oyuntipi != "UV") tire = " - ";

         if (parent.document.getElementsByTagName) {
            var tableCells = parent.document.getElementsByTagName("TD");
            var tableCells = parent.document.getElementsByTagName("TD");
            var usesInnerText = false;
            for (var i=0; i<tableCells.length; i++) {
               if (tableCells[i].id == mackodu+"K") {            
                  if (getInnerText(tableCells[i]).indexOf("/") == -1) {                      
                      var ilkTercih  = getInnerText(tableCells[i]).substring(0,getInnerText(tableCells[i]).indexOf("-"));
                      var ilkOran    = getInnerText(tableCells[i]).substring(getInnerText(tableCells[i]).indexOf("-")+1,getInnerText(tableCells[i]).length-1);
                      tableCells[i].innerHTML = "<font class='v10px'>" + ilkTercih + "/" + tercih + tire + ilkOran + "/" + oran + "</font><br>";
                  } else {
                      var ilkTercih  = getInnerText(tableCells[i]).substring(0,getInnerText(tableCells[i]).indexOf("/"));
                      var ilkOran = getInnerText(tableCells[i]).substring(getInnerText(tableCells[i]).indexOf("-")+1,getInnerText(tableCells[i]).lastIndexOf("/"));
                      parent.kuponAreaIkinciSecilenRemove("areaTR" + mackodu); 
                      tableCells[i].innerHTML = "<font class='v10px'>" + ilkTercih + "/" + tercih + tire + ilkOran.substring(1,ilkOran.length) + "/" + oran + "</font><br>";
                  }
                    
               }
               
            }
            
         }
  }
  
  
  if (oyuntipi == "F" || oyuntipi == "FS" || oyuntipi == "UO" || MBS == 1) {
    
    kuponAreaAdd(mackodu,oran,oyuntipi,sira,MBS,macadi,tercih);  

  } else {
   
    kuponAreaAdd(mackodu,oran,oyuntipi,sira,oyuntipi,macadi,tercih);    

  }

}

