﻿var intervalID;
var _LMHTML = new StringBuilder();
var _CMHTML = new StringBuilder();
var _EHTML = new StringBuilder();
var _liveRowIndex = 0;
var _liveEventIndex = 0;
var _liveMatchCount = 0;
var _tempLiveCount = 0;
var _completedRowIndex = 0;
var _newGoals = '';
var _newsData;




function showCM() {
    cMatches = 1;
    seqVal = -1;
    $('COMPLETEDMATCHES_LOADING_HOLDER').innerHTML = '<font face="Arial" size="3" color="#ff6600"><b>Yükleniyor...</b></font><br /><br /> <font face="Arial" size="5" color="#cccccc"><b>www.sahadan.com</b></font>';
    getMatches();
    cookieVariables.setValue("cm", cMatches);
}


function getMatches() {
    //alert('/LiveScores/LiveScoresAjax.aspx?seq=' + seqVal + '&txtDate=' + sTxtDate + '&filter=' + sFilter + '&ddlGrup=' + sDdlGrup + '&CM=' + cMatches + '&st=' + sportType);
    new Ajax.Request(
         '/LiveScores/LiveScoresAjax.aspx?seq=' + seqVal + '&txtDate=' + sTxtDate + '&iddaa=' + sIddaa + '&canli=' + sCanli + '&allIddaa=' + sAllIddaa + '&ddlGrup=' + sDdlGrup + '&CM=' + cMatches + '&st=' + sportType, {
             method: 'get',
             asynchronous: true,
             evalScripts: true,
             onComplete: function(request) { prepareHTML(request) },
             onFailure: function(request) { }
         });
}


function getNews() {
    new Ajax.Request(
         '/AjaxHandlers/NewsData.aspx', {
             method: 'get',
             asynchronous: true,
             evalScripts: true,
             onComplete: function(request) { collectNewsData(request) },
             onFailure: function(request) { }
         });
}

function collectNewsData(output) {
    if (output.responseText.indexOf("Loading.") == -1 && output.responseText.indexOf("Yükleniyor.") == -1 && output.responseText.indexOf("Yukleniyor.") == -1) {
        if (output.responseText.length > 0) {
            _newsData = eval(output.responseText);
            try {
                prepareNews(_liveMatchCount > 0 ? 2 : 1);
            } catch (e) { }
        }
    }
    setTimeout("getNews()", 5 * 60 * 1000);
}

function prepareNews(columnCount) {

    if (!_newsData) {
        getNews();
        return;
    }


    var preparedHTML, index;

    index = 0;

    var mode = (1 == columnCount) ? "tile" : "block";
    rowCount = 0;
    if ("tile" == mode) {
        $('sonolay-acik-header').style.background = 'url(' + variables.imagePath + 'levents/sonolay-acik-header-2.gif)';
        $('sonolay-acik-rightcoll').display = 'none';
        $('sonolay-acik-rightcoll').style.width = '0px';

        $('sonolay-acik-leftcoll').style.width = '643px';
    } else {
        $('sonolay-acik-header').style.background = 'url(' + variables.imagePath + 'levents/sonolay-acik-header.gif)';
        $('sonolay-acik-rightcoll').display = 'block';
        $('sonolay-acik-rightcoll').style.width = '318px';

        $('sonolay-acik-leftcoll').style.width = '318px';
    }


    preparedHTML = '<table id="levents-leftcol" cellpadding="0" cellspacing="0" width="' + ("tile" == mode ? '625' : '300') + '">';

    for (var i = 0; i < _newsData.data.length; i++) {

        var row = _newsData.data[i];
        if ("block" == mode || ("tile" == mode && index % 2 == 0)) {
            rowCount++;
        }
        preparedHTML += "block" == mode || ("tile" == mode && index % 2 == 0) ? '<tr ' + (rowCount % 2 == 1 ? 'class="row2"' : 'class="row1"') + '>' : '';
        preparedHTML += '<td align="center">' + row.dt + '</td>';
        preparedHTML += '<td><a href="/haberler/' + row.id + '" target="_blank">' + row.head + '</a></td>';
        preparedHTML += "block" == mode || ("tile" == mode && index % 2 == 1) ? '</tr>' : '';

        index++;
    }
    preparedHTML += '</table>';
    if (_newsData.data.length > 0)
        $('sonolay-acik-leftcoll').innerHTML = preparedHTML;
}
function prepareHTML(output) {

    if (output.responseText.indexOf("Loading.") == -1 && output.responseText.indexOf("Yükleniyor.") == -1 && output.responseText.indexOf("Yukleniyor.") == -1) {

        if (output.responseText != "NOP" && output.responseText.length > 0) {
            initStringBuilders();

            try {
                eval(output.responseText);
            } catch (e) {
                //alert(e);
            }

            _tempLiveCount = _liveRowIndex;
            completeStringBuilders();



            _liveRowIndex = 0;
            _completedRowIndex = 0;
            loadLive();



            if (cMatches == 1 || _tempLiveCount == 0) {
                cMatches = 1;
                loadCompleted();
            }
            try {
                if (isRefreshed) {
                    window.scrollTo(0, 240);
                    isRefreshed = false;
                }
            }
            catch (err)
			{ }

            if (_liveMatchCount > 0) {
                loadLatestEvents();
            }

        }
        prepareNews(_liveMatchCount > 0 ? 2 : 1);

        

        if (cookieVariables.lc && cookieVariables.lc == 's') {
            hideAllBannerItems();
        } 
        else {
            relocateBanners();
        }
    }
    else 
    {
        hideAllBannerItems();
    }
}

function loadLatestEvents() {
    //$('LATEST_EVENTS_LOADING_HOLDER').style.display = 'none';
    $('sonolay-acik-rightcoll').innerHTML = _EHTML.toString();
    _EHTML.clear();
}


function loadLive() {
    hideAllBannerItems();
    $('LIVEMATCHES_LOADING_HOLDER').style.display = 'none';
    $('LIVEMATCHES_HOLDER').innerHTML = _LMHTML.toString();
    _LMHTML.clear();
    initVariables();
    showHideMatches();
    if ($("spntercihgizle").style.display == 'none') {
        tercihGG('h');
    }
    playGoalSound(_newGoals);
    _newGoals = '';
}

function loadCompleted() {
    $('COMPLETEDMATCHES_LOADING_HOLDER').style.display = 'none';
    $('COMPLETEDMATCHES_HOLDER').innerHTML = _CMHTML.toString();
    _CMHTML.clear();
}


function SETSEQ(val) {
    seqVal = val;
}
function SETDATE(val) {
    //alert($('dvClock'));
    $('dvClock').innerHTML = val;
}



function SETLMC(val) {
    _liveMatchCount = val;
    if (1 == sAllIddaa && 0 == val) {
        refreshScoresInterval(3000);
    }
    else if (1 == sAllIddaa && 0 < val) {
        refreshScoresInterval(60);
    }
    else if (val == 0) {
        refreshScoresInterval(30);
    }
    else {
        refreshScoresInterval(iRefreshSecond);
    }
}

function L1M(altgId, altgAdi, altgKisaadi, altgEleme, grupAdi, macId, macDurum, macSezon, takim1ID, takim1Adi, takim2ID, takim2Adi, iySonuc, sonuc, macIddaaID, macSaat, kks1, kks2, u1, u2, imoMs1, imoMs0, imoMs2, info, altgGrup, kalanSaat, kalanDakika, imoUnder, imoOver, tahminId, tip, iyH1, iyH2, distMacId, H1, H2) {
    var rowBgColor = _liveRowIndex % 2 == 0 ? '#f0f0f4' : '#ffffff';
    if (u1 > 0 || u2 > 0) {
        _newGoals += distMacId + '_' + sonuc.replace(' ', '').replace('-', '_') + "|";
        rowBgColor = '#bdf899';
    }
    var isLiveMatch = "1,2,3,5,7".indexOf(macDurum) != -1;
    _LMHTML.append('<tr style="background-color:' + rowBgColor + '" onmouseover="HLon(this)">');
    _LMHTML.append('<td style="border-left-width: 0px;" nowrap><IMG height=11 width=16 src="' + _EXT_IMG_PATH + "img/groups/" + altgGrup + '.gif" ' + (document.all ? 'alt="' + grupAdi + '-' + altgAdi + '"' : '') + '></td>');
    _LMHTML.append('<td class="linked_cell" nowrap>' + (altgEleme == 0 || altgEleme == 2 ? '<a href="javascript:PDc(' + altgId + ',' + altgEleme + ',\'' + grupAdi + ' ' + altgAdi + '\')"  title="Puan durumu">' + altgKisaadi + '</a>' : altgKisaadi) + '</td>');
    _LMHTML.append('<td><input type=checkbox  name=chkboxes value=' + distMacId + ' id=chkboxes  class=canlichkb onclick="setChoicedMatches()"></td>');
    _LMHTML.append('<td class="linked_cell" align=center>&nbsp;<a href="javascript:Kc(' + macId + ',' + takim1ID + ',' + takim2ID + ',' + macSezon + ',' + altgId + ',\'' + takim1Adi + '\',' + '\'' + takim2Adi + '\')">' + macIddaaID + '</a></td>');
    _LMHTML.append('<td class="table_header" align=center title="' + (kks1 > 0 ? kks1 + ' Kırmızı Kart : ' + takim1Adi : '') + '">&nbsp;<b style="color:Red;">' + (kks1 > 0 ? kks1 : '') + '</b></TD>');
    _LMHTML.append('<td class="linked_cell" style="padding-left:3px" align="left"><a href="javascript:Tc(' + takim1ID + ',' + altgId + ',\'' + takim1Adi + '\')">' + takim1Adi + '</a>' + (parseInt(H1) > 0 ? ' <span style="color:red;">(H:' + parseInt(H1) + ')</span>' : '') + '</td>');
    _LMHTML.append('<td class="linked_cell" style="padding-left:3px" align="left"><a href="javascript:Tc(' + takim2ID + ',' + altgId + ',\'' + takim2Adi + '\')">' + takim2Adi + '</a>' + (parseInt(H2) > 0 ? ' <span style="color:red;">(H:' + parseInt(H2) + ')</span>' : '') + '</td>');
    _LMHTML.append('<td class="table_header" align=center title="' + (kks2 > 0 ? kks2 + ' Kırmızı Kart : ' + takim2Adi : '') + '">&nbsp;<b style="color:Red;">' + (kks2 > 0 ? kks2 : '') + '</b></TD>');
    _LMHTML.append('<td id=chkbtd><input type=checkbox name=chkboxes1 value=' + distMacId + '_1 id=chkboxes1 hnd="' + parseInt(H1) + '" class=canlichkb onclick=MMCheckBox(this,' + _liveRowIndex + ',1) title="' + imoMs1 + '"></td>');
    _LMHTML.append('<td id=chkbtd><input type=checkbox name=chkboxes0 value=' + distMacId + '_0 id=chkboxes0  class=canlichkb onclick=MMCheckBox(this,' + _liveRowIndex + ',1) title="' + imoMs0 + '"></td>');
    _LMHTML.append('<td id=chkbtd><input type=checkbox name=chkboxes2 value=' + distMacId + '_2 id=chkboxes2 hnd="' + parseInt(H2) + '" class=canlichkb onclick=MMCheckBox(this,' + _liveRowIndex + ',1) title="' + imoMs2 + '"></td>');
    _LMHTML.append('<td id=chkbtd><input type=checkbox name=chkboxesU value=' + distMacId + '_U id=chkboxesU  class=canlichkb onclick=MMCheckBox(this,' + _liveRowIndex + ',1) title="' + imoUnder + '"></td>');
    _LMHTML.append('<td id=chkbtd><input type=checkbox name=chkboxesO value=' + distMacId + '_O id=chkboxesO  class=canlichkb onclick=MMCheckBox(this,' + _liveRowIndex + ',1) title="' + imoOver + '"></td>');
    _LMHTML.append('<td class="table_header" align=center>&nbsp;' + iySonuc.replace(' ', '').replace(' ', '') + '</td>');

    if (macDurum != 0) {
        _LMHTML.append('<td class="linked_cell" align=center> <a href="javascript:MSc(' + macId + ',\'' + takim1Adi + '\',' + '\'' + takim2Adi + '\')"><b><span ' + (isLiveMatch ? 'id=S' + distMacId : '') + '>' + (u1 > 0 ? '<img src=' + variables.imagePath + 'ball.gif border=0>' : '') + sonuc + (u2 > 0 ? '<img src=' + variables.imagePath + 'ball.gif border=0>' : '') + '</span></b></a></td>');
    }
    else {
        _LMHTML.append('<td class="linked_cell" align=center><a href="javascript:Kc(' + macId + ',' + takim1ID + ',' + takim2ID + ',' + macSezon + ',' + altgId + ',\'' + takim1Adi + '\',' + '\'' + takim2Adi + '\')">vs</a></td>');
    }

    _LMHTML.append('<td class="table_header" align=center ' + (macDurum == 0 ? 'title="' + ((kalanSaat > 0 ? kalanSaat + ' Saat,' : '') + (kalanDakika > 0 ? kalanDakika + ' Dakika' : '')) + '"' : '') + '><span ' + (isLiveMatch ? 'class="green" id=D' + distMacId : '') + '>' + macSaat.replace('@@', '<blink>+</blink>').replace('@', '<blink>\'</blink>') + '</span></td>');
    _LMHTML.append('<td class="table_header" align="center">' + (info.length != 0 ? '<IMG height=12 width=12 src="' + variables.imagePath + 'info.gif" alt="' + info + '" style="cursor:pointer" onclick=\'alert("' + info + '")\'>' : '&nbsp;') + '</td>');
    _LMHTML.append('<td class="table_header" style="border-right-width:1px" align="center">' + (tahminId > 0 ? '<a href=javascript:Tahmin(' + tahminId + ')><img height=11 src="' + variables.imagePath + 'tahmin-ikon.gif"  border="0" alt="T" style="cursor:pointer"/></a>' : '&nbsp;') + '</td>');
    _LMHTML.append('</tr>');

    _liveRowIndex++;


}

function L2M(altgId, altgAdi, altgKisaadi, altgEleme, grupAdi, macId, macDurum, macSezon, takim1ID, takim1Adi, takim2ID, takim2Adi, iySonuc, sonuc, macIddaaID, macSaat, kks1, kks2, u1, u2, imoMs1, imoMs0, imoMs2, info, altgGrup, kalanSaat, kalanDakika, imoUnder, imoOver, tahminId, tip, iyH1, iyH2, distMacId, H1, H2) {

    var rowBgColor = _liveRowIndex % 2 == 0 ? '#f0f0f4' : '#ffffff';
    if (u1 > 0 || u2 > 0) {
        _newGoals += distMacId + '_' + sonuc.replace(' ', '').replace('-', '_') + "|";
        rowBgColor = '#bdf899';
    }

    var isLiveMatch = macDurum != 12;

    _LMHTML.append('<tr style="background-color:' + rowBgColor + '" onmouseover="HLon(this)" title="' + ((parseInt(iyH1) != 0 ? 'IYH1 : ' + iyH1 : '') + (parseInt(iyH2) != 0 ? ' IYH2 : ' + iyH2 : '') + (parseInt(H1) != 0 ? ' H1 : ' + H1 : '') + (parseInt(H2) != 0 ? ' H2 : ' + H2 : '') + (parseInt(imoUnder) != 0 ? ' TS : ' + imoUnder : '')) + '">');
    _LMHTML.append('<td style="border-left-width: 0px;"><IMG height=11 width=16 src="' + _EXT_IMG_PATH + 'img/basket_groups/' + altgGrup + '.gif" ' + (document.all ? 'alt="' + grupAdi + '-' + altgAdi + '"' : '') + '></td>');
    _LMHTML.append('<td class="linked_cell" nowrap>' + altgKisaadi + '</td>');
    _LMHTML.append('<td><input type=checkbox  name=chkboxes value=' + distMacId + ' id=chkboxes  class=canlichkb onclick="setChoicedMatches()"></td>');
    _LMHTML.append('<td class="linked_cell" align=center>&nbsp;' + macIddaaID + '</td>');
    _LMHTML.append('<td class="table_header" align=center>&nbsp;</td>');
    _LMHTML.append('<td class="linked_cell" style="padding-left:3px" align="left">' + takim1Adi + '</td>');
    _LMHTML.append('<td class="linked_cell" style="padding-left:3px" align="left">' + takim2Adi + '</td>');
    _LMHTML.append('<td class="table_header" align=center>&nbsp;</td>');
    _LMHTML.append('<td id=chkbtd><input type=checkbox name=chkboxes1 value=' + distMacId + '_1 id=chkboxes1  class=canlichkb onclick=MMCheckBox(this,' + _liveRowIndex + ',2) title="' + ('' != H1 ? H1 : '') + '"></td>');
    _LMHTML.append('<td id=chkbtd><img src="' + variables.imagePath + 'b-top.gif" border=0 width=12 height=12><input type=checkbox name=chkboxes2 value=' + distMacId + '_2 id=chkboxes0  style="display:none"></td>');
    _LMHTML.append('<td id=chkbtd><input type=checkbox name=chkboxes2 value=' + distMacId + '_2 id=chkboxes2  class=canlichkb onclick=MMCheckBox(this,' + _liveRowIndex + ',2) title="' + ('' != H2 ? H2 : '') + '"></td>');
    _LMHTML.append('<td id=chkbtd><input type=checkbox name=chkboxesU value=' + distMacId + '_U id=chkboxesU  class=canlichkb onclick=MMCheckBox(this,' + _liveRowIndex + ',2) title="' + imoUnder + '"></td>');
    _LMHTML.append('<td id=chkbtd><input type=checkbox name=chkboxesO value=' + distMacId + '_O id=chkboxesO  class=canlichkb onclick=MMCheckBox(this,' + _liveRowIndex + ',2) title="' + imoUnder + '"></td>');
    _LMHTML.append('<td class="table_header" align=center>&nbsp;' + iySonuc.replace(' ', '').replace(' ', '') + '</td>');

    if (macDurum != 12) {
        _LMHTML.append('<td class="linked_cell" align=center><a href="javascript:BBMSc(' + macId + ')"><b><span ' + (isLiveMatch ? 'id=S' + distMacId : '') + '>' + sonuc + '</span></b></a></td>');
    }
    else {
        _LMHTML.append('<td class="linked_cell" align=center>vs</td>');
    }

    _LMHTML.append('<td class="table_header" align=center ' + (macDurum == 12 ? 'title="' + ((kalanSaat > 0 ? kalanSaat + ' Saat,' : '') + (kalanDakika > 0 ? kalanDakika + ' Dakika' : '')) + '"' : '') + '><span ' + (isLiveMatch ? 'class="green" id=D' + distMacId : '') + '>' + macSaat + '</span></td>');
    _LMHTML.append('<td class="table_header" align="center">' + (info.length != 0 ? '<IMG height=12 width=12 src="' + variables.imagePath + 'info.gif" alt="' + info + '" style="cursor:pointer" onclick=\'alert("' + info + '")\'>' : '&nbsp;') + '</td>');
    _LMHTML.append('<td class="table_header" style="border-right-width:1px" align="center">' + (tahminId > 0 ? '<a href=javascript:Tahmin(' + tahminId + ')><img height=11 src="' + variables.imagePath + 'tahmin-ikon.gif"  border="0" alt="T" style="cursor:pointer"/></a>' : '&nbsp;') + '</td>');
    _LMHTML.append('</tr>');

    _liveRowIndex++;
}

function TB(id, index) {
    _LMHTML.append('<tr style="background-color:#ddd;display=none;" id="' + id + '"><td colspan="18" class="linked_cell"  align="center" style="height:15px;border:1px solid #888">');
    _LMHTML.append('</td></tr>');
}

function C2M(altgId, altgKisaadi, altgAdi, altgEleme, altgGrup, grupAdi, takim1Id, takim2Id, macId, macSezon, macIddaaid, takim1Adi, takim2Adi, iySonuc, sonuc, macEledi, kks1, kks2, macDurum, durum, info, macSonuc1, macSonuc2, tahminId, tip) {

    _CMHTML.append('<tr style="background-color:' + (_completedRowIndex % 2 == 0 ? '#f0f0f4' : '#ffffff') + '" onmouseover="HLon(this)">');
    _CMHTML.append('<td style="border-left-width: 0px;"><IMG height=11 width=16 src="' + _EXT_IMG_PATH + 'img/basket_groups/' + altgGrup + '.gif" ' + (document.all ? 'alt="' + grupAdi + '-' + altgAdi + '"' : '') + '></td>');
    _CMHTML.append('<td class="linked_cell" nowrap>' + altgKisaadi + '</td>');
    _CMHTML.append('<td class="linked_cell">&nbsp;' + macIddaaid + '</td>');
    _CMHTML.append('<td class="table_header" align=center >&nbsp;<b>&nbsp;</b></td>');
    _CMHTML.append('<td class="linked_cell" style="padding-left:3px" align="left">' + (macSonuc1 > macSonuc2 ? '<b>' : '') + (macEledi == 1 ? '<span style="color:Red;">' : '') + takim1Adi + (macEledi == 1 ? '</span>' : '') + (macSonuc1 > macSonuc2 ? '</b>' : '') + '</td>');
    _CMHTML.append('<td class="linked_cell" style="padding-left:3px" align="left">' + (macSonuc2 > macSonuc1 ? '<b>' : '') + (macEledi == 2 ? '<span style="color:Red;">' : '') + takim2Adi + (macEledi == 2 ? '</span>' : '') + (macSonuc2 > macSonuc1 ? '</b>' : '') + '</td>');
    _CMHTML.append('<td class="table_header" align=center >&nbsp;<b>&nbsp;</b></td>');
    _CMHTML.append('<td class="table_header" align=center>&nbsp;' + iySonuc.replace(' ', '').replace(' ', '') + '</td>');

    _CMHTML.append('<td class="linked_cell" align="center"><a href="javascript:BBMSc(' + macId + ')"><b>' + sonuc + '</b></a></td>');

    _CMHTML.append('<td align="center" class="table_header">&nbsp;' + durum + '</td>');
    _CMHTML.append('<td align="center" class="table_header"><img src="' + variables.imagePath + 'b-top.gif" border=0 width=12 height=12></td>');
    _CMHTML.append('<td class="table_header" align="center">&nbsp;</td>');
    _CMHTML.append('</tr>');


    _completedRowIndex++;
}

function C1M(altgId, altgKisaadi, altgAdi, altgEleme, altgGrup, grupAdi, takim1Id, takim2Id, macId, macSezon, macIddaaid, takim1Adi, takim2Adi, iySonuc, sonuc, macEledi, kks1, kks2, macDurum, durum, info, macSonuc1, macSonuc2, tahminId, tip) {

    _CMHTML.append('<tr style="background-color:' + (_completedRowIndex % 2 == 0 ? '#f0f0f4' : '#ffffff') + '" onmouseover="HLon(this)">');
    _CMHTML.append('<td style="border-left-width: 0px;"><IMG height=11 width=16 src="' + _EXT_IMG_PATH + "img/groups/" + altgGrup + '.gif" ' + (document.all ? 'alt="' + grupAdi + '-' + altgAdi + '"' : '') + '></td>');
    _CMHTML.append('<td class="linked_cell" nowrap>' + (altgEleme == 0 || altgEleme == 2 ? '<a href="javascript:PDc(' + altgId + ',' + altgEleme + ',\'' + grupAdi + ' ' + altgAdi + '\')"  title="Puan durumu">' + altgKisaadi + '</a>' : altgKisaadi) + '</td>');
    _CMHTML.append('<td class="linked_cell">&nbsp;<a href="javascript:Kc(' + macId + ',' + takim1Id + ',' + takim2Id + ',' + macSezon + ',' + altgId + ',\'' + takim1Adi + '\',' + '\'' + takim2Adi + '\')">' + macIddaaid + '</a></td>');
    _CMHTML.append('<td class="table_header" align=center title="Kırmızı Kart : ' + takim1Adi + '" style="color:Red;">&nbsp;<b>' + (kks1 > 0 ? kks1 : '') + '</b></td>');
    _CMHTML.append('<td class="linked_cell" style="padding-left:3px" align="left"><a href="javascript:Tc(' + takim1Id + ',' + altgId + ',\'' + takim1Adi + '\')">' + (macSonuc1 > macSonuc2 ? '<b>' : '') + (macEledi == 1 ? '<span style="color:Red;">' : '') + takim1Adi + (macEledi == 1 ? '</span>' : '') + (macSonuc1 > macSonuc2 ? '</b>' : '') + '</a></td>');
    _CMHTML.append('<td class="linked_cell" style="padding-left:3px" align="left"><a href="javascript:Tc(' + takim2Id + ',' + altgId + ',\'' + takim2Adi + '\')">' + (macSonuc2 > macSonuc1 ? '<b>' : '') + (macEledi == 2 ? '<span style="color:Red;">' : '') + takim2Adi + (macEledi == 2 ? '</span>' : '') + (macSonuc2 > macSonuc1 ? '</b>' : '') + '</a></td>');
    _CMHTML.append('<td class="table_header" align=center title="Kırmızı Kart : ' + takim2Adi + '" style="color:Red;">&nbsp;<b>' + (kks2 > 0 ? kks2 : '') + '</b></td>');
    _CMHTML.append('<td class="table_header" align=center>&nbsp;' + iySonuc.replace(' ', '').replace(' ', '') + '</td>');

    if (macDurum != 0 && macDurum != 9 && macDurum != 10 && macDurum != 11) {
        _CMHTML.append('<td class="linked_cell" align="center">&nbsp;<a href="javascript:MSc(' + macId + ',\'' + takim1Adi + '\',' + '\'' + takim2Adi + '\')"><b>' + sonuc + '</b></a></td>');
    }
    else {
        _CMHTML.append('<td class="linked_cell" align="center">&nbsp;<a href="javascript:Kc(' + macId + ',' + takim1Id + ',' + takim2Id + ',' + macSezon + ',' + altgId + ',\'' + takim1Adi + '\',' + '\'' + takim2Adi + '\')">vs</a></td>');
    }

    _CMHTML.append('<td align="center" class="table_header">&nbsp;' + durum + '</td>');
    _CMHTML.append('<td align="center" class="table_header">' + (info.length != 0 ? '<IMG height=12 style="cursor:pointer;" onclick=\'alert("' + info + '")\' width=12 src="' + variables.imagePath + 'info.gif" alt="' + info + '">' : '&nbsp;') + '</td>');
    _CMHTML.append('<td class="table_header" align="center">' + (tahminId > 0 ? '<a href=javascript:Tahmin(' + tahminId + ')><img height=11 src="' + variables.imagePath + 'tahmin-ikon.gif" alt="T" style="cursor:pointer" border="0"/></a>' : '&nbsp;') + '</td>');
    _CMHTML.append('</tr>');


    _completedRowIndex++;
}

function LE(eventId, eventHour, team1, team2, matchId, type, subType, homeScore, awayScore, red1, red2, minute, iddaaId, altgAdi, altgId, team1Id, team2Id) {
    _EHTML.append('<tr ' + (_liveEventIndex % 2 == 1 ? 'class="row2"' : 'class="row1"') + '>');
    _EHTML.append('<td width="30">' + eventHour + '</td>');
    _EHTML.append('<td width="35"><a title="Puan durumu" href="javascript:PDc(' + altgId + ',0,\'' + altgAdi + '\')">' + altgAdi + '</a></td>');
    _EHTML.append('<td width="20">' + (iddaaId > 0 ? iddaaId : '') + '</td>');

    _EHTML.append('<td  width="140"><div style="width:140px;overflow:hidden;height:15px;white-space:nowrap">' + writeTeams(team1, team2, subType, red1, red2, type, altgId, team1Id, team2Id) + '</div></td>');
    _EHTML.append('<td width="35" align="center" nowrap><a href="javascript:MSc(' + matchId + ',\'' + team1 + '\',\'' + team2 + '\')">' + writeScore(homeScore, awayScore, type, subType) + '</a></td>');
    _EHTML.append('<td ' + (type != 2 && type != 4 ? 'style="color:green"' : 'style="font-weight:bold"') + ' align="center" width="25">' + minute + '</td>');
    _EHTML.append('<td width="15" align="center">' + writeEventImage(type) + '</td>');


    _EHTML.append('</tr>');
    _liveEventIndex++;

}



function writeTeams(team1, team2, subtype, red1, red2, type, altgId, team1Id, team2Id) {

    var retVal;
    retVal = '<a href="javascript:Tc(' + team1Id + ',' + altgId + ',\'' + team1 + '\')">' + ((type == 1 && subtype == 1) ? '<span style="color:red">' : '') + team1 + ((type == 1 && subtype == 1) ? '</span>' : '') + '</a>';

    if (red1 > 0) {
        retVal += ' <sup style="color:red;font-size:8px">[' + red1 + ']</sup>';
    }
    retVal += ' - ';

    if (red2 > 0) {
        retVal += '<sup style="color:red;font-size:8px">[' + red2 + ']</sup> ';
    }
    retVal += '<a href="javascript:Tc(' + team2Id + ',' + altgId + ',\'' + team2 + '\')">' + ((type == 1 && subtype == 2) ? '<span style="color:red">' : '') + team2 + ((type == 1 && subtype == 1) ? '</span>' : '') + '</a>';

    return retVal;
}

function writeEventImage(type) {
    switch (type) {
        case 1:
            return '<img src="' + variables.imagePath + 'ball.gif" width="12" width="9"/>';
            break;
        case 2:
            return '';
            break;
        case 3:
            return '<img src="' + variables.imagePath + 'red.gif" width="10" width="12"/>';
            break;
        case 4:
            return '';
            break;
        case 5:
            return '<img src="' + variables.imagePath + '/levents/ecancel.gif" width="10" width="12"/>';
            break;            

    }
}

function writeScore(score1, score2, type, subtype) {
    var retVal;
    retVal = '<b>';
    if (type == 1) {
        if (subtype == 1) {
            retVal += '<span style="color:red">' + score1 + '</span> - ' + score2;
        }
        if (subtype == 2) {
            retVal += score1 + ' - <span style="color:red">' + score2 + '</span>';
        }
    } else {
        retVal += '<b>' + score1 + ' - ' + score2 + '</b>';
    }

    retVal += '</b>';
    return retVal;
}


function initStringBuilders() {

    _LMHTML.append('<table class="sahadancanli" cellpadding="0" cellspacing="0" border="0" id=QueryGrid_CanliMaclar width="646px" onmouseout="HLoff()">');
    _LMHTML.append('<tr style="background-image: url(' + variables.imagePath + 'canlisonuclar_tabs.gif);" height="22px">');
    _LMHTML.append('<td style="border-left-width: 0px;" colspan="2" class="iddaa_white_txt" style="border-left-style:none;"  width="10%" >Lig</td>')
    _LMHTML.append('<td align="left" width="2%"><input type="checkbox" name="chkall" value="ON" id="chkall" class="canlichkb" onclick="checkUnCheckAll()" title="Tümünü Seç"></td>');
    _LMHTML.append('<td class="iddaa_white_txt" width="3%">Kod</td>');
    _LMHTML.append('<td class="iddaa_white_txt" width="2%">&nbsp</td>');
    _LMHTML.append('<td class="iddaa_white_txt" width="22%">Ev Sahibi</td>');
    _LMHTML.append('<td class="iddaa_white_txt" width="22%">Misafir</td>');
    _LMHTML.append('<td class="iddaa_white_txt" width="2%">&nbsp</td>');
    _LMHTML.append('<td class="iddaa_white_txt" id=chkbtd width="3%" align="center">1</td>');
    _LMHTML.append('<td class="iddaa_white_txt" id=chkbtd width="3%" align="center">0</td>');
    _LMHTML.append('<td class="iddaa_white_txt" id=chkbtd width="3%" align="center">2</td>');
    _LMHTML.append('<td class="iddaa_white_txt" id=chkbtd width="3%" align="center">A</td>');
    _LMHTML.append('<td class="iddaa_white_txt" id=chkbtd width="3%" align="center">U</td>');
    _LMHTML.append('<td class="iddaa_white_txt" width="5%" align="center">IY</td>');
    _LMHTML.append('<td class="iddaa_white_txt" width="9%" align="center">MS</td>');
    _LMHTML.append('<td class="iddaa_white_txt" width="3%">Saat</td>');
    _LMHTML.append('<td style="border-right-width:1px" class="iddaa_white_txt" width="5%" colspan="2">Not</td>');
    _LMHTML.append('</tr>');

    _CMHTML.append('<table  class="sahadancanli" cellpadding="0" cellspacing="0" border="0" width="645px" onmouseout="HLoff()">');
    if (cMatches == 1) {
        _CMHTML.append('<tr style="background-image: url(' + variables.imagePath + 'canlisonuclar_tabs.gif);" height="22px">');
        _CMHTML.append('<td class="iddaa_white_txt" style="border-left-style:none;" style="border-left-width: 0px;" colspan=2 width="12%">Lig</td>');
        _CMHTML.append('<td class="iddaa_white_txt" width="4%">Kod</td>');
        _CMHTML.append('<td class="iddaa_white_txt" width="3%">&nbsp;</td>');
        _CMHTML.append('<td class="iddaa_white_txt" width="24%">Ev Sahibi</td>');
        _CMHTML.append('<td class="iddaa_white_txt" width="24%">Misafir</td>');
        _CMHTML.append('<td class="iddaa_white_txt" width="3%">&nbsp;</td>');
        _CMHTML.append('<td class="iddaa_white_txt" width="8%" align="center">IY</td>');
        _CMHTML.append('<td class="iddaa_white_txt" width="10%" align="center">MS</td>');
        _CMHTML.append('<td class="iddaa_white_txt" width="7%">&nbsp;</td>');
        _CMHTML.append('<td class="iddaa_white_txt" colspan="2" width="5%">Not</td>');
        _CMHTML.append('</tr>');
    }

    _EHTML.append('<table id="levents-rightcol" cellpadding="0" cellspacing="0">');
    _EHTML.append('<tr>');

}

function completeStringBuilders() {
    if (_liveRowIndex == 0) {
        _LMHTML.append('<tr  style="background-color:#f0f0f4">');
        _LMHTML.append('<td class="iddaa_black_txt" colspan=17 align="center">Şu anda maç yok.</td>');
        _LMHTML.append('</tr>');
    }
    _LMHTML.append('</table>');

    if (_completedRowIndex == 0 && (cMatches == 1 || _liveRowIndex == 0)) {
        _CMHTML.append('<tr style="background-color:#f0f0f4">');
        _CMHTML.append('<td class="iddaa_black_txt" colspan=11 align="center">Biten maç yok.</td>');
        _CMHTML.append('</tr>');
    }
    _EHTML.append('</tr>');
    _EHTML.append('</table>');


    _CMHTML.append('</table>');

}


function StringBuilder(initialValue) {
    this.buffer = new Array();
    this.bufferLength = 0;

    if (initialValue != null)
        this.append(initialValue);
}

StringBuilder.prototype.append = function(appendValue) {
    // ** validate data
    if (appendValue == null) {
        return;
    }

    // ** Increase the internal bufferlength
    this.bufferLength += appendValue.length;

    // ** And add the new value to the array.
    this.buffer.push(appendValue)
}

StringBuilder.prototype.clear = function() {
    this.buffer = new Array();
    this.bufferLength = 0;
}

StringBuilder.prototype.length = function() {
    return this.bufferLength;
}

StringBuilder.prototype.toString = function() {
    return this.buffer.join("");
}
