var is_new_goal = false;
var is_whistle = false;
var oRequest = "";
var xml_content = "";
var position_display = true;
var commentary_display = true;
var league_info_display = true;
var odds_display = true;
var whistle_display = true;
var live_time_stamp = 0;
var display_screen_flag = true;
var goal_popup = true;
var to_day = '';
var half_flag = 0;
function print_date(value) {
	var theDate = new Date(value * 1000 + parseInt(time_zone*3600)*1000 + 3600*1000);
	dateString = theDate.toGMTString();
	arrDateStr = dateString.split(" ");
	theDate = null;
	return arrDateStr[4].substr(0,5);
}
function print_date_ts(value) {
	var theDate = new Date(value * 1000 + parseInt(time_zone*3600)*1000);
	dateString = theDate.toGMTString();
	arrDateStr = dateString.split(" ");
	theDate = null;
	return new Array(arrDateStr[1]+ " "+arrDateStr[2],arrDateStr[4].substr(0,5));
}
function requestObject () {
	var oXML = "";
	if(window.XMLHttpRequest){
		try{
			oXML = new XMLHttpRequest();
		} catch(e){
			oXML = false;
		}
	} else if(window.ActiveXObject){
		try{
			oXML = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e){
			try{
				oXML = new ActiveXObject("Microsoft.XMLHTTP");
				objServerUpdateTimes = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){
				oXML = false;
			}
		}
	}
	return oXML;
}
function load_scoreboard(auto_start) {
	if(!oRequest) {
		oRequest = new requestObject();
	} else {
		oRequest.abort();
	}
	oRequest.onreadystatechange = function () {
		if(oRequest.readyState == 4) {
			is_new_goal = false;
			var oXMLDocument = oRequest.responseText;
			xml_content = oXMLDocument;
			oXMLDocument = null;
			display_screen();
			if(sport == "s"){
				if(is_whistle && whistle_display){
					doplayW();
				}
				if(is_new_goal){
					doplay();
				}
			}
		}
	}
	if(!auto_start){
		live_time_stamp = 0;	
	}
	if(live_time_stamp){
		timestamp_url = livescoresPath + "xml/live.php?langFK=" + langFK + "&sport=" + sport + "&date=" + g_date + "&live_time_stamp=" + live_time_stamp + "&nk=" + Math.random();
		check_timestamp = procRequest(timestamp_url);
	} else {
		check_timestamp = "1";
	}
	if(check_timestamp == "1"){
		display_screen_flag = true;
		oRequest.open("GET",livescoresPath + "xml/live.php?langFK=" + langFK + "&sport=" + sport + "&date=" + g_date + "&nk=" + Math.random(),true);
		oRequest.send("");
	} else {
		if(half_flag){
			rotate_time();
		}
	}
	if(auto_start){
		setTimeout("load_scoreboard(true)", 30000);
	}
}
function calc_time(value, status){
	var theDateC = new Date();
	time_difference = Math.round(theDateC.getTime()/1000 - value);
	minute = Math.round(time_difference/60);
	if(current_country == "PK"){
		minute = minute - 60;
	}
	if(status == "1H" && minute > 45){
		minute = 45;
	} else if(status == "2H"){
		minute = minute - 15;
		if(minute > 90){
			minute = 90;
		}
	}
	theDateC = null;
	return minute;
}
function rotate_time(){
	for (var cd=0;cd <  minute_flag_content.length;cd++ ){
		document.getElementById("min_" + minute_flag_content[cd][0]).innerHTML = minute_flag_content[cd][1] + "-" + calc_time(minute_flag_content[cd][2],minute_flag_content[cd][1]);
	}
}
function parse_cards(vc){
	var vtext = "";
	var avc = vc.split(",");
	for(var hm_c=0; hm_c < avc.length; hm_c++){
		vtext += '<img src="' + livescoresPath + 'img/v1/cards/' + avc[hm_c] + '.gif">';
	}
	avc = null;
	return vtext;
}
