﻿function setStartTime() {
    $("td.start_time").each(function(index, obj) {

        var sd = $(this).text();
        var sdh = parseInt(rem_zero(sd.split(':')[0].replace(/^\s+|\s+$/, '')));
        var sdm = parseInt(rem_zero(sd.split(':')[1].replace(/^\s+|\s+$/, '')));
        var sdate = new Date();
        var num = new String(sd.split(':')[0]);


        sdate.setHours(sdh + vto, sdm, sdate.getSeconds(), sdate.getMilliseconds());
        // if (parseInt(sdate.getDay()) != parseInt(date.getDay())) $(this).parent().css({ display:"none"});
        // else
        $(this).text(fill_zero(sdate.getHours()) + ":" + fill_zero(sdate.getMinutes()));
        $(this).css({ display: "table-cell" });

    });
}


function playSound(sound) {

    var file = '';
    var elm;
    if (sound == SoundType.Goal) {
        elm = $("#playsound #_goal");
        file = '/Content/Scripts/flash/goal.swf';
    }
    
    if (sound == SoundType.StartFinish) {
        elm = $("#playsound #_startfinish");
        file = '/Content/Scripts/flash/ref.swf';
    }
    

    if (browser_detect('ie')) {
        var fsound = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="1" height="1" name="playsoundname" id="playsoundid">' +
						'<param name="allowScriptAccess" value="sameDomain" />' +
						'<param name="movie" value="' + file + '" />' +
						'<param name="bgcolor" value="#ffffff" />' +
						'<param name="quality" value="high" />' +
						'<embed src="' + file + '" quality="high" bgcolor="#ffffff" width="1" height="1" name="rozcestnik" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
					'</object>';
        SetHtml(elm, fsound);
    }
    else {
        var fsound = '<object type="application/x-shockwave-flash" data="' + file + '" width="1" height="1">';
        SetHtml(elm, fsound);
    }
}

function highlight(el) {
    var newCssClass = $(el).attr("class");
    if (isUndefined(newCssClass)) return;
    if (newCssClass.indexOf(MatchLSTableDetail.MatchTdHighlightCssClass) < 0)
        newCssClass += " " + MatchLSTableDetail.MatchTdHighlightCssClass;

    $(el).attr("class", newCssClass);
}

function unhighlight(match_id_livescore, detail) {
    var el = getMatchDetailCellElm(match_id_livescore, detail);
    unhighlightByElm(el);
}

function unhighlightByElm(el) {
    var newCssClass = $(el).attr("class");

    if (isUndefined(newCssClass)) return;
    if (newCssClass.indexOf(MatchLSTableDetail.MatchTdHighlightCssClass) >= 0)
        newCssClass = newCssClass.replace(MatchLSTableDetail.MatchTdHighlightCssClass, "");

    $(el).attr("class", newCssClass);
}

function getMatchDetailCellElm(match_id_livescore, detail) {
    if (detail == MatchLSTableDetail.MatchTdCurrentScoreCssClass) return $("tr#m" + match_id_livescore + " td." + detail + " a");
    return $("tr#m" + match_id_livescore + " td." + detail);
}

function getMatchRowElm(match_id_livescore) {
    return $("tr#m" + match_id_livescore);
}



function styleMatchFinished(m) {
    var mel = getMatchRowElm(m.ID_livescore);
    AddCssClass(mel, MatchLSTableDetail.MatchTdFinishedCssClass);
    RemCssClass(mel, MatchLSTableDetail.MatchTdLiveCssClass);
    var score = getMatchScore(m);
    if (score.HomeTeamScore != score.AwayTeamScore) {
        if (score.HomeTeamScore > score.AwayTeamScore)
            AddCssClass(getMatchDetailCellElm(m.ID_livescore, MatchLSTableDetail.MatchTdHomeTeamCssClass),
            MatchLSTableDetail.MatchTdWinnerCssClass);
        else
            AddCssClass(getMatchDetailCellElm(m.ID_livescore, MatchLSTableDetail.MatchTdAwayTeamCssClass),
            MatchLSTableDetail.MatchTdWinnerCssClass);
    }
}

//score:{HomeTeamScore:"", AwayTeamScore:""}
function getMatchScore(m) {
    var score = {};
    for (var ios = 0; ios < m.Scores.length; ios++)
        if (m.Scores[ios].Status == MatchScoreStatus.Current || m.Scores[ios].Status == MatchScoreStatus.Finished) {
        score.HomeTeamScore = m.Scores[ios].HomeTeamScore;
        score.AwayTeamScore = m.Scores[ios].AwayTeamScore;
    }
    return score;
}

function showMatchDetails(url) {
    window.open(url, "", 'hotkeys=no, resizable=no, toolbar=no, status=no, toolbar=no,top=100,left=300 dependent=yes, scrollbars=1, width=640, height=620');
}


