var xmlHttp8 = [];
var minutes = [];
var seconds = [];
var resyncSeconds = [];
var skipResync = [];
var liveHomeGoals = [];
var liveAwayGoals = [];
var liveTextArray = [];
var lastShownAction = [];
var nextShownAction = [];

function print_r (array, return_val) {
    // Prints out or returns information about the specified variable  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/print_r    // +   original by: Michael White (http://getsprink.com)
    // +   improved by: Ben Bryan
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +      improved by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    // -    depends on: echo
    // *     example 1: print_r(1, true);
    // *     returns 1: 1
    
    var output = "", pad_char = " ", pad_val = 4, d = this.window.document;    var getFuncName = function (fn) {
        var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn);
        if (!name) {
            return '(Anonymous)';
        }        return name[1];
    };
 
    var repeat_char = function (len, pad_char) {
        var str = "";        for (var i=0; i < len; i++) {
            str += pad_char;
        }
        return str;
    }; 
    var formatArray = function (obj, cur_depth, pad_val, pad_char) {
        if (cur_depth > 0) {
            cur_depth++;
        } 
        var base_pad = repeat_char(pad_val*cur_depth, pad_char);
        var thick_pad = repeat_char(pad_val*(cur_depth+1), pad_char);
        var str = "";
         if (typeof obj === 'object' && obj !== null && obj.constructor && getFuncName(obj.constructor) !== 'PHPJS_Resource') {
            str += "Array\n" + base_pad + "(\n";
            for (var key in obj) {
                if (obj[key] instanceof Array) {
                    str += thick_pad + "["+key+"] => "+formatArray(obj[key], cur_depth+1, pad_val, pad_char);                } else {
                    str += thick_pad + "["+key+"] => " + obj[key] + "\n";
                }
            }
            str += base_pad + ")\n";        } else if (obj === null || obj === undefined) {
            str = '';
        } else { // for our "resource" class
            str = obj.toString();
        } 
        return str;
    };
 
    output = formatArray(array, 0, pad_val, pad_char); 
    if (return_val !== true) {
        if (d.body) {
            this.echo(output);
        }        else {
            try {
                d = XULDocument; // We're in XUL, so appending as plain text won't work; trigger an error out of XUL
                this.echo('<pre xmlns="http://www.w3.org/1999/xhtml" style="white-space:pre;">'+output+'</pre>');
            }            catch (e) {
                this.echo(output); // Outputting as plain text may work in some plain XML
            }
        }
        return true;    } else {
        return output;
    }
}

function jumpToTime(startMin, startSec, jumpToMin, jumpToSec, homeTeamNo, awayTeamNo, homeHex, awayHex, homeTeamName, awayTeamName, matchNo) {
    
    // Cast startSec and jumpToSec to string
    startSec = "" + startSec;
    jumpToSec = "" + jumpToSec;

    if(startSec.length < 2) { startSec = "0" + startSec; }
    if(jumpToSec.length < 2) { jumpToSec = "0" + jumpToSec; }
    
    var startMinSec = parseFloat(startMin+"."+startSec);
    var jumpMinSec = parseFloat(jumpToMin+"."+jumpToSec);
    
    var thisMinFloat = null;
    
    for(var i=0; i<liveTextArray[matchNo].length; i++) {
        thisMinFloat = parseFloat(liveTextArray[matchNo][i][0]);
        if(thisMinFloat > startMinSec && thisMinFloat < jumpMinSec) {
            printCommentary(liveTextArray[matchNo][i], homeTeamNo, awayTeamNo, homeHex, awayHex, homeTeamName, awayTeamName, matchNo);
        }
    }

}

function getMatchTimer2(matchNo, matchServerNo, matchEngineVersion, divSelector, watchAsLive) {
	
	var result;
	var resultArray;
	var xmlHttp8temp;
	
	result = null;

    if(watchAsLive == null) {
        watchAsLive = false;
    }
    

	xmlHttp8temp=GetXmlHttpObject();

	if(xmlHttp8[matchNo] == null) {
		xmlHttp8[matchNo] = [];
	}

	xmlHttp8[matchNo][divSelector] = xmlHttp8temp;
	
	if (xmlHttp8temp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	
	if(watchAsLive == false) {
	
	    // checking code goes here
	    var url="/modules/includes/match/ajax/resyncMatchTimer.php";
	    url=url+"?matchNo="+matchNo+"&matchServerNo="+matchServerNo+"&randNum="+Math.random();
	    xmlHttp8temp.onreadystatechange=function () {
		    if ((xmlHttp8temp.readyState == 4 || xmlHttp8temp.readyState == "complete") && xmlHttp8temp.responseText != "error") {
			    stateChangedMatchTimer(matchNo, matchServerNo, matchEngineVersion, divSelector);
		    }
	    };
	    
	    xmlHttp8temp.open("GET",url,true);
	    xmlHttp8temp.send(null);
	
	    setTimeout("getMatchTimer2("+matchNo+","+matchServerNo+","+matchEngineVersion+",'"+divSelector+"');", 60000);
	    
    }
}

function stateChangedMatchTimer(matchNo, matchServerNo, matchEngineVersion, divSelector)  { 

	var result;
	var resultArray;
	
	var xmlHttp8temp = xmlHttp8[matchNo][divSelector];
	
	result = xmlHttp8temp.responseText;
	
	if(result.length > 0) {
		
		result = result.split("#");
	
		minutes[matchNo][divSelector] = result[1];
		seconds[matchNo][divSelector] = result[2];
		
	}
	
 
}

function getLiveMatchScore(zminutes, zseconds, matchNo, matchServerNo, matchEngineVersion, divSelector, updateScore) {
	
	var xmlHttp8temp = xmlHttp8[matchNo][divSelector];
	
	// checking code goes here
	var url="/modules/includes/match/ajax/getMatchScore.php";
	url=url+"?matchNo="+matchNo+"&matchServerNo="+matchServerNo+"&mev="+matchEngineVersion+"&minutes="+zminutes+"&seconds="+zseconds+"&randNum="+Math.random();

	xmlHttp8temp.onreadystatechange=function () {
	    
		if ((xmlHttp8temp.readyState == 4 || xmlHttp8temp.readyState == "complete") && xmlHttp8temp.responseText != "error") {
			
			var result;
			result = xmlHttp8temp.responseText;
			result = result.split("#");
			liveHomeGoals[matchNo] = parseInt(result[0], 10);
			liveAwayGoals[matchNo] = parseInt(result[1], 10);
            
			if(updateScore == true && isNaN(liveHomeGoals[matchNo]) == false && isNaN(liveAwayGoals[matchNo]) == false) {
			    if(document.getElementById("homeScoreline_"+divSelector)) {
				document.getElementById("homeScoreline_"+divSelector).innerHTML=liveHomeGoals[matchNo];
				document.getElementById("awayScoreline_"+divSelector).innerHTML=liveAwayGoals[matchNo];
				}
			}
			
		}
	};

	xmlHttp8temp.open("GET",url,true);
	xmlHttp8temp.send(null);
	
}

function printCommentary(result, homeTeamNo, awayTeamNo, homeHex, awayHex, homeTeamName, awayTeamName, matchNo)  { 

	var newContent;
	var timeArray = result[0].split(".");
	timeArray[0] = parseInt(timeArray[0], 10);
	timeArray[1] = parseInt(timeArray[1], 10);

	if(result[1] == "SP") {
	
		newContent = "<tr><td colspan='3' style='padding-top:7px;'>"+result[2]+"</td></tr>";

		document.getElementById("matchCommentary").innerHTML = "<table width='100%' cellspacing='0px' cellpadding='0px'>" + newContent + "</table>" + document.getElementById("matchCommentary").innerHTML;

	} else {
	
	if(timeArray[0] >= 137 && timeArray[1] >= 0) {
		timeArray[0] -= 17;
	 } else if((timeArray[0] == 121 && timeArray[1] > 0) || timeArray[0] > 121) {
		timeArray[0] -= 17;
	 } else if(timeArray[0] == 121 && timeArray[1] == 0) {
		timeArray[0] -= 16;
	 } else if(timeArray[0] >= 106) {
		timeArray[0] -= 16;
	 } else if(timeArray[0] >= 60) {
		timeArray[0] -= 15;
	 }
	
	if(timeArray[0] < 10 && timeArray[1] >= 0) {
		timeArray[0] = "0" + timeArray[0];
	}
	
	if(timeArray[1] < 10) {
		timeArray[1] = "0" + timeArray[1];
	}
	
	
	switch (result[1]) {
		case "N":
			if(result[5] == homeTeamNo) {
				newContent = "<tr><td width='3%' valign='middle' align='center'><img src='/includes/matchTeamBlob.php?hex=" + homeHex + "' style='border:solid; border-width:1px; border-color:#000000;'></td><td class='matchNormal' style='padding-left:8px;' width='10%'><b>" + timeArray[0] + ":" + timeArray[1] + "</b></td><td width='87%' class='matchNormal' style='padding-right:4px;padding-left:2px;'>"+result[2]+"</td></tr>";
			} else {
				newContent = "<tr><td width='3%' valign='middle' align='center'><img src='/includes/matchTeamBlob.php?hex=" + awayHex + "' style='border:solid; border-width:1px; border-color:#000000;'></td><td class='matchNormal' style='padding-left:8px;' width='10%'><b>" + timeArray[0] + ":" + timeArray[1] + "</b></td><td width='87%' class='matchNormal' style='padding-right:4px;padding-left:2px;'>"+result[2]+"</td></tr>";	
			}
			break;
		case "G":
			var teamName;
			if(result[2] == homeTeamNo) {
				teamName = homeTeamName;	
				// Update homeGoals count
				liveHomeGoals[matchNo] = parseInt(liveHomeGoals[matchNo], 10);
				liveHomeGoals[matchNo] = liveHomeGoals[matchNo] + 1;
				document.getElementById("homeScoreline_ingame").innerHTML = liveHomeGoals[matchNo];
			} else if(result[2] == awayTeamNo) {
				teamName = awayTeamName;	
				// Update homeGoals count
				liveAwayGoals[matchNo] = parseInt(liveAwayGoals[matchNo], 10);
				liveAwayGoals[matchNo] = liveAwayGoals[matchNo] + 1;
				document.getElementById("awayScoreline_ingame").innerHTML = liveAwayGoals[matchNo];
			}
			newContent = "<tr><td width='3%' valign='middle' align='center'><img src='/includes/matchTeamBlob.php?hex=" + homeHex + "' style='border:solid; border-width:1px; border-color:#000000;'></td><td width='10%' style='background-color:#000000; color:gold; padding-left:6px; padding-top:4px;' valign='top'><b>" + timeArray[0] + ":" + timeArray[1] + "</b></td><td width='87%' style='background-color:#000000; color:gold; padding-left:4px; padding-top:4px; padding-bottom:4px;'>GOAL - " + result[4] + " (" + teamName + ")<br/>" + result[3] + "</td></tr>";
			break;
		case "Y":
			newContent = "<tr><td width='3%' valign='middle' align='center'><img src='/includes/matchTeamBlob.php?hex=" + homeHex + "' style='border:solid; border-width:1px; border-color:#000000;'></td><td width='10%' style='background-color:yellow; padding-left:6px; padding-top:4px;' valign='top'><b>" + timeArray[0] + ":" + timeArray[1] + "</b></td><td width='87%' style='background-color:yellow; padding-left:4px;padding-top:4px; padding-bottom:4px;'><img src='/images/misc/yellowCardMini.png'> "+result[2]+"</td></tr>";
			break;
		case "R":
			newContent = "<tr><td width='3%' valign='middle' align='center'><img src='/includes/matchTeamBlob.php?hex=" + homeHex + "' style='border:solid; border-width:1px; border-color:#000000;'></td><td width='10%' style='background-color:red; color:#FFFFFF; padding-left:6px; padding-top:4px;' valign='top'><b>" + timeArray[0] + ":" + timeArray[1] + "</b></td><td width='87%' style='background-color:red; color:#FFFFFF; padding-left:4px;padding-top:4px; padding-bottom:4px;'>SENT OFF<br/>"+result[2]+"</td></tr>";
			break;
		case "X":
		case "HT":
		case "HTR": 
		case "HTET": 
		case "ETS": 
		case "PNS": 
		case "HTETR":
			newContent = "<tr><td width='3%' valign='middle' align='center'>&nbsp;</td><td width='10%' style='background-color:#CCCCCC; padding-left:6px; padding-top:4px;' valign='top'><b>" + timeArray[0] + ":" + timeArray[1] + "</b></td><td width='87%' style='background-color:#CCCCCC;padding-left:4px;padding-top:4px; padding-bottom:4px;'>"+result[2]+"</td></tr>";
			break;
		default:
			newContent = "<tr><td width='3%' valign='middle' align='center'><img src='/includes/matchTeamBlob.php?hex=" + homeHex + "' style='border:solid; border-width:1px; border-color:#000000;'></td><td width='10%' style='padding-left:6px; padding-top:4px;' valign='top'><b>" + timeArray[0] + ":" + timeArray[1] + "</b></td><td width='87%' style='padding-left:4px; padding-top:5px; padding-bottom:5px;'>"+result[2]+"</td></tr>";
	}
	
	document.getElementById("matchCommentary").innerHTML = "<table width='100%' cellspacing='0px' cellpadding='0px'>" + newContent + "</table>" + document.getElementById("matchCommentary").innerHTML;

	}	

	if(result[1] == "HT" || result[1] == "HTET") {
	
		newContent = "<tr><td colspan='3'>-------------------------------------------------------------------------------</td></tr>";
		document.getElementById("matchCommentary").innerHTML = "<table width='100%' cellspacing='0px' cellpadding='0px'>" + newContent + "</table>" + document.getElementById("matchCommentary").innerHTML;
		
	} 

}


function loadLiveText(matchNo, matchServerNo, matchEngineVersion) {
    
    var url = "/modules/includes/match/ajax/loadLiveText.php?matchNo="+matchNo+"&matchServerNo="+matchServerNo+"&mev="+matchEngineVersion;
    liveTextArray[matchNo] = ajaxLoadURL(url, null, false);
    liveTextArray[matchNo] = liveTextArray[matchNo].split("###");

    for(var i=0; i<liveTextArray[matchNo].length; i++) {
        liveTextArray[matchNo][i] = liveTextArray[matchNo][i].split("##");
    }

}

function displayStatus(init, initMins, initSecs, matchType, matchNo, matchServerNo, matchEngineVersion, divSelector, updateScore, homeTeamNo, awayTeamNo, homeHex, awayHex, homeTeamName, awayTeamName, watchAsLive) {

	var tempMinutes;
	var tempSeconds;
	
	if(init == true) {
	
	    if(initSecs <= 49) {
	        resyncSeconds[matchNo] = 50 + Math.floor(Math.random()*9);
	        skipResync[matchNo] = false;
	    } else {
	        resyncSeconds[matchNo] = 50 + Math.floor(Math.random()*9);
	        skipResync[matchNo] = initMins;
	    }
	    
		if(minutes[matchNo] == null) {
			minutes[matchNo] = [];
			seconds[matchNo] = [];
		}
		minutes[matchNo][divSelector] = initMins;
		seconds[matchNo][divSelector] = initSecs;
		
		liveTextArray[matchNo] = [];
        loadLiveText(matchNo, matchServerNo, matchEngineVersion);
		
		getLiveMatchScore(minutes[matchNo][divSelector], seconds[matchNo][divSelector], matchNo, matchServerNo, matchEngineVersion, divSelector, updateScore);
	} else if(seconds[matchNo][divSelector] == 0) {
		getLiveMatchScore(minutes[matchNo][divSelector], seconds[matchNo][divSelector], matchNo, matchServerNo, matchEngineVersion, divSelector, updateScore);
	}
	
	if(minutes[matchNo][divSelector] < 0 || (minutes[matchNo][divSelector] == 0 && seconds[matchNo][divSelector] < 0)) {
		
		tempMinutes = Math.abs(minutes[matchNo][divSelector]);
		tempSeconds = Math.abs(seconds[matchNo][divSelector]);
		if(tempMinutes < 10) {
			tempMinutes = "0" + tempMinutes;
		}
		if(tempSeconds < 10) {
			tempSeconds = "0" + tempSeconds;
		}
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>Kick off in " + tempMinutes  + ":" + tempSeconds + "</font>";	
		
	} else if(minutes[matchNo][divSelector] < 45) {
		
		tempMinutes = Math.abs(minutes[matchNo][divSelector]);
		tempSeconds = Math.abs(seconds[matchNo][divSelector]);
		if(tempMinutes < 10) {
			tempMinutes = "0" + tempMinutes;
		}
		if(tempSeconds < 10) {
			tempSeconds = "0" + tempSeconds;
		}
		
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>Current Time: <b>" +tempMinutes + "</b>:<b>" + tempSeconds + "</b></font>";	
	} else if(minutes[matchNo][divSelector] < 60) {
		
		if(seconds[matchNo][divSelector] > 49) { tempSeconds = "0" + (59-seconds[matchNo][divSelector]); } else { tempSeconds = (59-seconds[matchNo][divSelector]); }
		
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>Current Time: <b>Half Time</b> (Game restarts in "+((60-minutes[matchNo][divSelector])-1)+":"+tempSeconds+")</font>";
		
	} else if(minutes[matchNo][divSelector] < 105) {
		
		tempMinutes = Math.abs(minutes[matchNo][divSelector] - 15);
		tempSeconds = Math.abs(seconds[matchNo][divSelector]);
		
		if(tempSeconds < 10) {
			tempSeconds = "0" + tempSeconds;
		}
		
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>Current Time: <b>" + tempMinutes + "</b>:<b>" + tempSeconds + "</b></font>";
			
	} else if(minutes[matchNo][divSelector] < 106 && (matchType == "C" || matchType == "P") && liveHomeGoals[matchNo] == liveAwayGoals[matchNo] /* scores level */) {
		
		if(seconds[matchNo][divSelector] > 49) { tempSeconds = "0" + (59-seconds[matchNo][divSelector]); } else { tempSeconds = (59-seconds[matchNo][divSelector]); }
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>Current Time: <b>Full Time</b> (Extra time starts in 0:"+tempSeconds+")</font>";	
		
	} else if(minutes[matchNo][divSelector] < 106) {
		
		if(seconds[matchNo][divSelector] > 49) { tempSeconds = "0" + (59-seconds[matchNo][divSelector]); } else { tempSeconds = (59-seconds[matchNo][divSelector]); }
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>Current Time: Ending Match</font>";	
	
	} else if(minutes[matchNo][divSelector] < 121) {
		
	tempMinutes = minutes[matchNo][divSelector] - 16;
	tempSeconds = seconds[matchNo][divSelector];
	if(tempMinutes < 10) {
		tempMinutes = "0" + tempMinutes;
	}
	if(tempSeconds < 10) {
		tempSeconds = "0" + tempSeconds;
	}
	
	document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>Current Time: <b>" + tempMinutes + "</b>:<b>" + tempSeconds + "</b> (Extra time)</font>";	
	
	} else if(minutes[matchNo][divSelector] < 122) {
		
		if(seconds[matchNo][divSelector] > 49) { tempSeconds = "0" + (59-seconds[matchNo][divSelector]); } else { tempSeconds = (59-seconds[matchNo][divSelector]); }
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>Current Time: <b>Half Time</b> (Extra time restarts in 0:"+tempSeconds+")</font>";	
	} else if(minutes[matchNo][divSelector] < 137) { 
		
		tempMinutes = minutes[matchNo][divSelector] - 17;
		tempSeconds = seconds[matchNo][divSelector];
		if(tempMinutes < 10) {
			tempMinutes = "0" + tempMinutes;
		}
		if(tempSeconds < 10) {
			tempSeconds = "0" + tempSeconds;
		}
		
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>Current Time: <b>" + tempMinutes + "</b>:<b>" + tempSeconds + "</b> (Extra time)</font>";	
	
	} else if(minutes[matchNo][divSelector] == 137 && liveHomeGoals[matchNo] != liveAwayGoals[matchNo]) {
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>Current Time: Ending Match</font>";
	} else if(minutes[matchNo][divSelector] == 137) {
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>Current Time: <b>Full Time</b> (Penalty Shootout starts in 0:"+tempSeconds+")</font>";	
	} else if(minutes[matchNo][divSelector] < 152) { 
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>Current Time: Penalty Shootout in progress...</font>";	
	}

	// Here we show commentary
	if(init == false) {
	    var tempSecs = ""+seconds[matchNo][divSelector];
	    if(tempSecs.length < 2) { tempSecs = "0" + tempSecs; }
	    var commentaryMinSec = minutes[matchNo][divSelector]+"."+tempSecs;
	    for(var i=0; i<liveTextArray[matchNo].length; i++) {
            if(liveTextArray[matchNo][i][0] == commentaryMinSec) {
                printCommentary(liveTextArray[matchNo][i], homeTeamNo, awayTeamNo, homeHex, awayHex, homeTeamName, awayTeamName, matchNo);
            }
        }
	}
	
	
	
	// We reload the commentary between 50 and 58 seconds, depending on the resyncSeconds value
	if(seconds[matchNo][divSelector] == resyncSeconds[matchNo]) {
	    if(skipResync[matchNo] == initMins) {
	        // We are skipping this minute
	        resyncSeconds[matchNo] = 50 + Math.floor(Math.random()*9);
	        skipResync[matchNo] = false;
	    } else {
	        // We are not skipping this minute
	        resyncSeconds[matchNo] = 50 + Math.floor(Math.random()*9);
	        skipResync[matchNo] = initMins;
	        loadLiveText(matchNo, matchServerNo, matchEngineVersion);
	    }
	}
	
	seconds[matchNo][divSelector]++;
	if(seconds[matchNo][divSelector] == 60) {
		seconds[matchNo][divSelector] = 0;
		minutes[matchNo][divSelector]++;
	} else if(seconds[matchNo][divSelector] == 0) {
		seconds[matchNo][divSelector] = -59;
		minutes[matchNo][divSelector]++;
		
		// Case that we have gone from KO in 0:01 to 0:01
		if(minutes[matchNo][divSelector] == 1) {
			seconds[matchNo][divSelector] = 0;
			minutes[matchNo][divSelector] = 0;
		}
	}

	setTimeout("displayStatus(" + false + ", " + minutes[matchNo][divSelector] + "," + seconds[matchNo][divSelector] + ",'" + matchType + "',"+matchNo+","+matchServerNo+","+matchEngineVersion+",'"+divSelector+"', "+updateScore+", '"+homeTeamNo+"', '"+awayTeamNo+"', '"+homeHex+"', '"+awayHex+"', \""+homeTeamName+"\", \""+awayTeamName+"\");", 985);
	
}

function displayStatusMini(init, initMins, initSecs, matchType, matchNo, matchServerNo, matchEngineVersion, divSelector, updateScore) {
	
	var tempMinutes;
	var tempSeconds;
	
	if(init == true) {
		if(minutes[matchNo] == null) {
			minutes[matchNo] = [];
			seconds[matchNo] = [];
		}
		minutes[matchNo][divSelector] = initMins;
		seconds[matchNo][divSelector] = initSecs;
		
		getLiveMatchScore(minutes[matchNo][divSelector], seconds[matchNo][divSelector], matchNo, matchServerNo, matchEngineVersion, divSelector, updateScore);
		
	} else if(seconds[matchNo][divSelector] % 10 == 0) {
		getLiveMatchScore(minutes[matchNo][divSelector], seconds[matchNo][divSelector], matchNo, matchServerNo, matchEngineVersion, divSelector, updateScore);
	}
	
	if(minutes[matchNo][divSelector] < 0 || (minutes[matchNo][divSelector] == 0 && seconds[matchNo][divSelector] < 0)) {
		
		tempMinutes = Math.abs(minutes[matchNo][divSelector]);
		tempSeconds = Math.abs(seconds[matchNo][divSelector]);
		if(tempMinutes < 10) {
			tempMinutes = "0" + tempMinutes;
		}
		if(tempSeconds < 10) {
			tempSeconds = "0" + tempSeconds;
		}
		
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>KO in:" + tempMinutes + ":"+ tempSeconds + "</font>";	
		
	} else if(minutes[matchNo][divSelector] < 45) {
		
		tempMinutes = Math.abs(minutes[matchNo][divSelector]);
		tempSeconds = Math.abs(seconds[matchNo][divSelector]);
		if(tempMinutes < 10) {
			tempMinutes = "0" + tempMinutes;
		}
		if(tempSeconds < 10) {
			tempSeconds = "0" + tempSeconds;
		}
		
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'><b>" +tempMinutes + "</b>:<b>" + tempSeconds + "</b></font>";	
	} else if(minutes[matchNo][divSelector] < 60) {
		
		if(seconds[matchNo][divSelector] > 49) { tempSeconds = "0" + (59-seconds[matchNo][divSelector]); } else { tempSeconds = (59-seconds[matchNo][divSelector]); }
		
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'><b>HT</b> (45:00)";
		
	} else if(minutes[matchNo][divSelector] < 105) {
		
		tempMinutes = minutes[matchNo][divSelector] - 15;
		tempSeconds = seconds[matchNo][divSelector];
		
		if(tempSeconds < 10) {
			tempSeconds = "0" + tempSeconds;
		}
		
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'><b>" + tempMinutes + "</b>:<b>" + tempSeconds + "</b></font>";
			
	} else if(minutes[matchNo][divSelector] < 106 && (matchType == "C" || matchType == "P") && liveHomeGoals[matchNo] == liveAwayGoals[matchNo] /* scores level */) {
		
		if(seconds[matchNo][divSelector] > 49) { tempSeconds = "0" + (59-seconds[matchNo][divSelector]); } else { tempSeconds = (59-seconds[matchNo][divSelector]); }
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'><b>90:00</b> (ET)</font>";	
		
	} else if(minutes[matchNo][divSelector] < 106) {
		
		if(seconds[matchNo][divSelector] > 49) { tempSeconds = "0" + (59-seconds[matchNo][divSelector]); } else { tempSeconds = (59-seconds[matchNo][divSelector]); }
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>FT</font>";	
	
	} else if(minutes[matchNo][divSelector] < 121) {
		
	tempMinutes = minutes[matchNo][divSelector] - 16;
	tempSeconds = seconds[matchNo][divSelector];
	if(tempMinutes < 10) {
		tempMinutes = "0" + tempMinutes;
	}
	if(tempSeconds < 10) {
		tempSeconds = "0" + tempSeconds;
	}
	
	document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'><b>" + tempMinutes + ":" + tempSeconds + "</b> (ET)</font>";	
	
	} else if(minutes[matchNo][divSelector] < 122) {
		
		if(seconds[matchNo][divSelector] > 49) { tempSeconds = "0" + (59-seconds[matchNo][divSelector]); } else { tempSeconds = (59-seconds[matchNo][divSelector]); }
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'><b>105:00</b> (ET)</font>";	
	} else if(minutes[matchNo][divSelector] < 137) { 
		
		tempMinutes = minutes[matchNo][divSelector] - 17;
		tempSeconds = seconds[matchNo][divSelector];
		if(tempMinutes < 10) {
			tempMinutes = "0" + tempMinutes;
		}
		if(tempSeconds < 10) {
			tempSeconds = "0" + tempSeconds;
		}
		
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'><b>" + tempMinutes + "</b>:<b>" + tempSeconds + "</b> (ET)</font>";	
	
	} else if(minutes[matchNo][divSelector] == 137 && liveHomeGoals[matchNo] != liveAwayGoals[matchNo]) {
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'>FT</font>";
	} else if(minutes[matchNo][divSelector] == 137) {
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'><b>FT</b> (Penalties)</font>";	
	} else if(minutes[matchNo][divSelector] < 152) { 
		document.getElementById("matchTime_"+divSelector).innerHTML="<font style='font-size:11px;'><b>FT</b> (Penalties)</font>";	
	}
	
	seconds[matchNo][divSelector]++;
	if(seconds[matchNo][divSelector] == 60) {
		seconds[matchNo][divSelector] = 0;
		minutes[matchNo][divSelector]++;
	} else if(seconds[matchNo][divSelector] == 0) {
		seconds[matchNo][divSelector] = -59;
		minutes[matchNo][divSelector]++;
		
		// Case that we have gone from KO in 0:01 to 0:01
		if(minutes[matchNo][divSelector] == 1) {
			seconds[matchNo][divSelector] = 0;
			minutes[matchNo][divSelector] = 0;
		}
	}

	setTimeout("displayStatusMini(" + false + ", " + minutes[matchNo][divSelector] + "," + seconds[matchNo][divSelector] + ",'" + matchType + "',"+matchNo+","+matchServerNo+","+matchEngineVersion+",'"+divSelector+"', "+updateScore+");", 985);
	
}
