var booked_LL = new Array();
var booked_LH = new Array();
var booked_RH = new Array();
var booked_RP = new Array();
var booked_DH = new Array();
var booked_DP = new Array();
var booked_DD = new Array();
var booked_DM = new Array();
var matches = new Array();
var match_ids = '';
var js_script1_base = 'http://www.247.tv/jsmatch.php';
var js_script1 = js_script1_base;
var js_interval = 10000;
var get_js_interval;
var js_channeltype;
var js_sport = '';
function showthisscore() {

	if ( document.getElementById('score_date1').className == 'score_date' ) {
		document.getElementById('score_date1').className = 'score_date2';
		document.getElementById('set_score1').className = 'set_score2';
		document.getElementById('showhidescore').innerHTML = 'Show Scores ';
	} else {
		document.getElementById('score_date1').className = 'score_date';
		document.getElementById('set_score1').className = 'set_score';
		document.getElementById('showhidescore').innerHTML = 'Hide Scores ';
	}

}

function main_score( score1,score2,sport,main_score_typ ) {
	if ( js_sport == 'LNB' ) {
		score1_real = score1.substr(0,score1.indexOf('.'));
		score2_real = score2.substr(0,score2.indexOf('.'));
		if ( score1.substr(score1.indexOf('.')) > 0 ) {
			if ( score1_real == 0 ) { 
				score1_real = String.fromCharCode(189);
			} else {
				score1_real = score1_real + String.fromCharCode(189);
			}
		}
		if ( score2.substr(score2.indexOf('.')) > 0 ) {
			if ( score2_real == 0 ) { 
				score2_real = String.fromCharCode(189);
			} else {
				score2_real = score2_real + String.fromCharCode(189);
			}
		}
	} else {
		score1_real = score1.substr(0,score1.indexOf('.'));
		score2_real = score2.substr(0,score2.indexOf('.'));
	}	
//	return "<table ><tr><td class=score_date>"+score1_real+"</td><td class=score_date> - </td><td class=score_date>"+score2_real+"</td></tr></table>";
	return score1_real+" - "+score2_real;
}
function set_score(set11,set12,set21,set22,set31,set32,set41,set42,set51,set52,js_sport,totscor,set_score_typ,set_date,set61,set62,set71,set72,diff) {
	var set_score = '';
	if ( set11 > 0 || set12 > 0) {
		var set_date1 = set_date.substring(6,10)+set_date.substring(3,5);
		set_score = set_score + "( ";
		set_score = set_score + set_score1(set11,set12,'',set_date1);
		set_score = set_score + set_score1(set21,set22,',',set_date1);
		set_score = set_score + set_score1(set31,set32,',',set_date1);
		set_score = set_score + set_score1(set41,set42,',',set_date1);
		set_score = set_score + set_score1(set51,set52,',',set_date1);
		set_score = set_score + set_score1(set61,set62,',',set_date1);
		set_score = set_score + set_score1(set71,set72,',',set_date1);
		set_score = set_score + " )";
		if ( js_sport.toLowerCase()  == 'squ' && diff > 0 ) {
			set_score = set_score + " ("+diff+"m)";		
		}
	}
	return set_score;
}
function set_scoreX(set11,set12,set21,set22,set31,set32,set41,set42,set51,set52,js_sport,totscor,set_score_typ,set61,set62,set71,set72) {
	var set_score = '';
	if ( js_sport == 'SQU' && js_uid_live == 'PSA' ) {
		set_score = set11+"-"+set12;
		if ( totscor >= 1 && (set21 > 0 || set22 > 0 ) ) {
			set_score = set_score+", "+set21+"-"+set22;
		}
		if ( totscor >= 2 && (set31 > 0 || set32 > 0 ) ) {
			set_score = set_score+", "+set31+"-"+set32;
		}
		if ( totscor >= 3 && (set41 > 0 || set42 > 0 ) ) {
			set_score = set_score+", "+set41+"-"+set42;
		}
		if ( totscor >= 4 && (set51 > 0 || set52 > 0 )) {
			set_score = set_score+", "+set51+"-"+set52;
		}
		if ( totscor >= 5 && (set61 > 0 || set62 > 0 ) ) {
			set_score = set_score+", "+set61+"-"+set62;
		}
		if ( totscor >= 6 && (set71 > 0 || set72 > 0 ) ) {
			set_score = set_score+", "+set71+"-"+set72;
		}
	} else {
		set_score = set11+"-"+set12;
		if ( totscor >= 1 && (set21 > 0 || set22 > 0 ) ) {
			set_score = set_score+", "+set21+"-"+set22;
		}
		if ( totscor >= 2 && (set31 > 0 || set32 > 0 ) ) {
			set_score = set_score+", "+set31+"-"+set32;
		}
		if ( totscor >= 3 && (set41 > 0 || set42 > 0 ) ) {
			set_score = set_score+", "+set41+"-"+set42;
		}
		if ( totscor >= 4 && (set51 > 0 || set52 > 0 ) ) {
			set_score = set_score+", "+set51+"-"+set52;
		}
		if ( totscor >= 5 && (set61 > 0 || set62 > 0 ) ) {
			set_score = set_score+", "+set61+"-"+set62;
		}
		if ( totscor >= 6 && (set71 > 0 || set72 > 0 ) ) {
			set_score = set_score+", "+set71+"-"+set72;
		}
	}	
	set_score = "( "+set_score+" )";
	return set_score;
}

function set_score1(set_1,set_2,comma,YEARMONTH) {
	var ret = "";
	if ( set_1 > 0 || set_2 > 0) {
		if ( js_uid_live == 'PSA' && set_1 > 9 && set_2 > 9 && YEARMONTH > 200408) {
			var set1a = set_1 - 10;
			var set2a = set_2 - 10;
			if ( set_1 - set_2 > 1 || set_2 - set_1 > 1 ) {
				if ( set_1 > set_2 ) {
					ret = comma+" 11-10 (set1a-set2a)";
				} else {
					ret = comma+" 10-11 (set1a-set2a)";
				}
			} else {
				ret = comma+" 10-10 (set1a-set2a)";
			}
		} else {
			ret = comma+set_1+"-"+set_2;
		}
	}
	return ret;	
}

function get_js_script() {
	var head = document.getElementsByTagName('head').item(0);
	var old  = document.getElementById('lastLoadedCmds');
	if (old) head.removeChild(old);	
	script = document.createElement('script');
	script.src = js_script1;
	script.type = 'text/javascript';
	script.defer = true;
	script.id = 'lastLoadedCmds';
	void(head.appendChild(script));
	if ( js_channeltype == 'singlematch' ) {
		update_match();
	}
	if ( js_channeltype == 'tournament' ) {
		update_tournament();
	}
//	document.getElementById('heja').innerHTML = matches[0].evening;

	if ( navigator.appName == 'Opera' ) {
		var time = new Date();
		operaextra="&opera="+time.getTime();
		js_script1 = js_script1_base + operaextra;
	}
}

function update_tournament() {
//	alert(current_ids+'  '+match_ids);
	if ( matches ) {
		if ( matches.length > 0 ) {
			if ( current_ids != match_ids ) {
				var refreshurl = window.location.href;
				window.location.href = refreshurl;
			}
			for (ii = 0; ii < matches.length; ii++ ) {
				var obj= 'matchAlink_'+matches[ii].replay_id; 
			if ( document.getElementById(obj) ) {
				if ( matches[ii].status2 == 'L' && matches[ii].sc_show_no_stream == '1'  ) {
					document.getElementById(obj).innerHTML = '';
				} else if ( matches[ii].shw == 'Y'   ) {
					if (  matches[ii].bookable == 'Y' ) {
						document.getElementById(obj).innerHTML = 'Watch';
					} else {
						document.getElementById(obj).innerHTML = '<img src=graphics/live_small_animated.gif  border=0 > Watch';
					}
				} else if ( matches[ii].status == 'W' ) {
					document.getElementById(obj).innerHTML = 'Watch';
				} else if ( matches[ii].status2 == 'R' && matches[ii].replay == '' &&  matches[ii].bookable == ''  &&  matches[ii].hiresP == '' &&  matches[ii].divx == '' ) {
					document.getElementById(obj).innerHTML = 'Replay coming soon';
				} else if ( matches[ii].replay == 's' ||  matches[ii].bookable == '' ) {
					document.getElementById(obj).innerHTML = 'Watch';
				} else if ( matches[ii].status2 == 'R' ) {
					document.getElementById(obj).innerHTML = 'Watch';
				} else {

				}
			}

				var obj= 'score_date_'+matches[ii].replay_id; 
			if ( document.getElementById(obj) ) {
				if ( matches[ii].status == 'W' ) {
					document.getElementById(obj).innerHTML = '<table><tr><td>Starting soon</td></tr></table>';
				}
				if ( tournonames != 'Y' && tournoscore != 'Y' ) {
				if (  matches[ii].status2 == 'L' && tournonames != 'L' ) {
					if (  matches[ii].status2 == 'R' || matches[ii].shw == 'Y' || matches[ii].status == 'I'  ) {
						var totscor = parseFloat(matches[ii].score1) + parseFloat(matches[ii].score2) ;
						var totalscores = main_score(matches[ii].score1,matches[ii].score2,js_sport,1);
						if ( matches[ii].sprt == 'bwt' ) { 
							var setscore =  "";
						} else {
							var setscore = set_score(matches[ii].set11,matches[ii].set12,matches[ii].set21,matches[ii].set22,matches[ii].set31,matches[ii].set32,matches[ii].set41,matches[ii].set42,matches[ii].set51,matches[ii].set52,js_sport,totscor,1,matches[ii].date,matches[ii].set61,matches[ii].set62,matches[ii].set71,matches[ii].set72,matches[ii].diff);
						}
						var thiscookiename1 = 'showplayer'+matches[ii].replay_id;
						var thiscookiename = getcookie_1(thiscookiename1);
//alert(cookiename);
						if ( SHOWPLAYERS == 'Y' || thiscookiename == 'Y' ) {
							var jsshowplayers = 'visible';		
						} else {
							var jsshowplayers = 'hidden';		
						}
						var thiscookiescore1 = 'show_score'+matches[ii].replay_id;
						var thiscookiescore = getcookie_1(thiscookiescore1);
						if ( ( SHOWPLAYERS == 'Y' && thiscookiescore == '' ) || thiscookiescore == 'Y' ) {
							var jsshowscore = 'visible';		
						} else {
							var jsshowscore = 'hidden';		
						}
						var tmp_scoretable = '<table><tr><td class=list_matchcell nowrap><div id=sc1_';
						var tmp_scoretable = tmp_scoretable+matches[ii].replay_id+' style="visibility:'+jsshowscore+' ">';
						var tmp_scoretable = tmp_scoretable+totalscores;
						var tmp_scoretable = tmp_scoretable+'</div></td><td class=list_matchcell nowrap><div id=setscore_';
						var tmp_scoretable = tmp_scoretable+matches[ii].replay_id;
						var tmp_scoretable = tmp_scoretable+' style="visibility:'+jsshowscore+'" >';
						var tmp_scoretable = tmp_scoretable+setscore;
						var tmp_scoretable = tmp_scoretable+'</div></td></tr></table>';
//alert(tmp_scoretable);
						document.getElementById(obj).innerHTML = tmp_scoretable;
					}
				}
				}
			}
			}
		}
	}
}
function update_match() {
	if ( matches ) {
		if ( matches.length > 0 ) {
			if ( current_status2 != matches[0].status2 || current_replay != matches[0].replay ) {
				var refreshurl = window.location.href;
				window.location.href = refreshurl;
			}
			if ( tournonames != 'Y' && tournoscore != 'Y' ) {
			if (  matches[0].status2 == 'L' && tournonames != 'L' ) {
				document.getElementById('player_1').innerHTML = matches[0].team1a+"<br>"+matches[0].team1b;
				document.getElementById('player_2').innerHTML = matches[0].team2a+"<br>"+matches[0].team2b;

				if ( matches[0].status2 == 'R' || matches[0].shw == 'Y' || matches[0].status == 'I' ) {
					var totscor = parseFloat(matches[0].score1) + parseFloat(matches[0].score2) ;
					document.getElementById('score_date1').innerHTML =  main_score(matches[0].score1,matches[0].score2,js_sport,1);
					if ( matches[0].sprt != 'bwt' ) { 
						document.getElementById('set_score1').innerHTML =  set_score(matches[0].set11,matches[0].set12,matches[0].set21,matches[0].set22,matches[0].set31,matches[0].set32,matches[0].set41,matches[0].set42,matches[0].set51,matches[0].set52,js_sport,totscor,1,matches[0].date,matches[0].set61,matches[0].set62,matches[0].set71,matches[0].set72,matches[0].diff);
					}
				} else {
					document.getElementById('score_date1').innerHTML =  "";
					document.getElementById('set_score1').innerHTML =  "";
				}
				document.getElementById('match_adv1').innerHTML = "";
			}
			}
			var matchinfo = matches[0].matchcom;

			if ( matches[0].status == 'W' ) {
				matchinfo = "Warming Up<br>"+matchinfo;
				document.getElementById('match_info1').innerHTML = matchinfo;
			}
			if ( matches[0].status == 'I' && matches[0].shw == 'Y' ) {
				matchinfo = "Live<br>"+matchinfo;
				document.getElementById('match_info1').innerHTML = matchinfo;
			}
			if ( matches[0].status2 == 'R'  ) {
				document.getElementById('match_info1').innerHTML =  matchinfo;
			}
			if ( matches[0].shw == 'Y' ) {
				if ( js_logged == 'Y' ) {
					var purchaseid = booked_LH[matches[0].replay_id];
					if ( purchaseid > 0 ) {
						if ( matches[0].substreams == '' ) {
							if ( live_streamtype == '1' ) {
						//		document.getElementById('watchnow1').innerHTML = "<a href="+site_url+"flashplayer.php?purchaseid="+purchaseid+" target=_blank>WATCH NOW</a>";
								document.getElementById('watchnow1').innerHTML = "<a href=\"javascript:void(0)\" onclick=\"javascript:window.open('"+site_url+"flashplayer.php?purchaseid="+purchaseid+"','flashplayerX','fullscreen=no,screenX=25,screenY=25,width=540,height=560,resizable=no,toolbar=no,scrollbars=no,location=no,menubar=no,status=no')\" > WATCH NOW</a>";
							} else {
								document.getElementById('watchnow1').innerHTML = "<a href="+site_url+"rams/ram1.php?purchaseid="+purchaseid+">WATCH NOW</a>";
							}
						} else {
							var innertextlink = "";
							var substreams_arr = new Array();
							substreams_arr = matches[0].substreams.split(',');

							for (ii2 = 0; ii2 < substreams_arr.length; ii2++ ) {
								if ( substreams_arr[ii2] != '' ) { 
									if (ii2>0) { 
										innertextlink = innertextlink + "<br>";
									} 
							
									if ( live_streamtype == '1' ) {
								//		innertextlink = innertextlink + "<a href="+site_url+"flashplayer.php?purchaseid="+purchaseid+"&sub="+ii2+"  target=_blank>"+substreams_arr[ii2]+" WATCH NOW</a>";
										innertextlink = innertextlink + "<a href=\"javascript:void(0)\" onclick=\"javascript:window.open('"+site_url+"flashplayer.php?purchaseid="+purchaseid+"&sub="+ii2+"','flashplayerX','fullscreen=no,screenX=25,screenY=25,width=540,height=560,resizable=no,toolbar=no,scrollbars=no,location=no,menubar=no,status=no')\" >"+substreams_arr[ii2]+" WATCH NOW</a>";
									} else {
										innertextlink = innertextlink + "<a href="+site_url+"rams/ram1.php?purchaseid="+purchaseid+"&sub="+ii2+">"+substreams_arr[ii2]+" WATCH NOW</a>";
									} 
								} 
							}
							document.getElementById('watchnow1').innerHTML = innertextlink;
						}
					} else {
//						document.getElementById('watchnow1').innerHTML = "<a href="+site_url+current_pagelink2+"&purchase=H>BOOK</a>";
					}
				}
			}
		}
	}
}

function match_class (evening,fixnum,status,status2,graph,hist,serve,singl,freetext,court,rnd,start,diff,team1a,team1b,team2a,team2b,from1,from2,pic1a,pic1b,pic2a,pic2b,flag1,flag2,score1,score2,set11,set12,set21,set22,set31,set32,set41,set42,set51,set52,game1,game2,det1,det2,whoserve,bowl1,bowl2,shw,resolution,replay,replay_id,date,time,matchcom,sprt,bookable,hiresP,divx,set61,set62,set71,set72,substreams,sc_show_no_stream) {
	this.evening = evening;
	this.fixnum = fixnum;
	this.status = status;
	this.status2 = status2;
	this.graph = graph;
	this.hist = hist;
	this.serve = serve;
	this.singl = singl;
	this.freetext = freetext;
	this.court = court;
	this.rnd = rnd;
	this.start = start;
	this.diff = diff;
	this.team1a = team1a;
	this.team1b = team1b;
	this.team2a = team2a;
	this.team2b = team2b;
	this.from1 = from1;
	this.from2 = from2;
	this.score1 = score1;
	this.score2 = score2;
	this.pic1a = pic1a;
	this.pic1b = pic1b;
	this.pic2a = pic2a;
	this.pic2b = pic2b;
	this.flag1 = flag1;
	this.flag2 = flag2;
	this.set11 = set11;
	this.set12 = set12;
	this.set21 = set21;
	this.set22 = set22;
	this.set31 = set31;
	this.set32 = set32;
	this.set41 = set41;
	this.set42 = set42;
	this.set51 = set51;
	this.set52 = set52;
	this.set61 = set61;
	this.set62 = set62;
	this.set71 = set71;
	this.set72 = set72;
	this.game1 = game1;
	this.game2 = game2;
	this.det1 = det1;
	this.det2 = det2;
	this.whoserve = whoserve;
	this.bowl1 = bowl1;
	this.bowl2 = bowl2;
	this.shw = shw;
	this.resolution = resolution;
	this.replay = replay;
	this.replay_id = replay_id;
	this.date = date;
	this.time = time;
	this.matchcom = matchcom;
	this.sprt = sprt;
	this.bookable = bookable;
	this.hiresP = hiresP;
	this.divx = divx;
	this.substreams = substreams;
	this.sc_show_no_stream = sc_show_no_stream;
}

function booking_class (replayid,purchase,resolution,live,download) {
	this.replayid = replayid;
	this.purchase = purchase;
	this.resolution = resolution;
	this.live = live;
	this.download = download;
}