var objRequest=false;

function createXMLHttp()
{
		
	if(window.XMLHttpRequest)
	{
		objRequest=new XMLHttpRequest();
		
		if(objRequest==null)
			objRequest=new ActiveXObject("Microsoft.XMLHTTP");
		if(objRequest==null)
			objRequest=new ActiveXObject("MSXML2.XMLHTTP");
		if(objRequest==null)
			objRequest=new ActiveXObject("MSXML2.XMLHTTP.3.0");
		if(objRequest==null)
			objRequest=new ActiveXObject("Msxml2.XMLHTTP.4.0");
		if(objRequest==null)
			objRequest=new ActiveXObject("Msxml2.XMLHTTP.5.0");
		if(objRequest==null)
			objRequest=new ActiveXObject("Msxml2.XMLHTTP.6.0");
		if(objRequest==null)
			objRequest=new ActiveXObject("Msxml2.XMLHTTP.7.0")
		//objRequest.overrideMimeType("text/xml");
		
	}
	else if(window.ActiveXObject)
	{

		objRequest=new ActiveXObject("Microsoft.XMLHTTP");
		if(objRequest==null)
			objRequest=new ActiveXObject("MSXML2.XMLHTTP");
		if(objRequest==null)
			objRequest=new ActiveXObject("MSXML2.XMLHTTP.3.0");
		if(objRequest==null)
			objRequest=new ActiveXObject("Msxml2.XMLHTTP.4.0");
		if(objRequest==null)
			objRequest=new ActiveXObject("Msxml2.XMLHTTP.5.0");
		if(objRequest==null)
			objRequest=new ActiveXObject("Msxml2.XMLHTTP.6.0");
		if(objRequest==null)
			objRequest=new ActiveXObject("Msxml2.XMLHTTP.7.0");

	}
	
}

function showMatchDetail(matchid,tournamentid,typ)
{
	
	$.blockUI({ message: '<img src=image/loader.gif></img>',css: { backgroundColor: '#292929', color: '#fff', width: '100', height: '100', border: '0px solid #f00', left: '50%', top: '50%'} });
	if(objRequest)
	{
		objRequest.open("POST","matchscore.php?r="+ new Date().getTime());
		objRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		objRequest.onreadystatechange=function()
		{
		
		if(objRequest.readyState==4 && objRequest.status==200)
			{
				
				var doc=objRequest.responseXML;
				var matchNode=doc.documentElement;
				
				var club1substitute=new Array();
				var club2substitute=new Array();
				
				
				if(matchNode)
				{
					try
					{
						
					var str="";
					str="<br/><br/>";
					var idNode=matchNode.childNodes[0];
					var matchid=idNode.childNodes[0].nodeValue;
					var club1id=matchNode.childNodes[16].childNodes[0].childNodes[1];
					var club1name=club1id.childNodes[0].nodeValue;
					var club2id=matchNode.childNodes[16].childNodes[1].childNodes[1];
					var club2name=club2id.childNodes[0].nodeValue;
					var dateNode=matchNode.childNodes[1];
					var dateval=dateNode.childNodes[0].nodeValue;
					var groundNode=matchNode.childNodes[4];
					var groundName=groundNode.childNodes[0].nodeValue;
					var timeval=matchNode.childNodes[2].childNodes[0].nodeValue+" - " + matchNode.childNodes[3].childNodes[0].nodeValue;
					var tosswonby=matchNode.childNodes[6].childNodes[0].nodeValue;
					var decision=matchNode.childNodes[7].childNodes[0].nodeValue;
					
					var result=""
					var manofthematch=""
					
					if(matchNode.childNodes[10].childNodes.length>0) // if result is not null
					{
														
						if(matchNode.childNodes[10].childNodes[0].nodeValue=="R") // if result is win
						{
							if(matchNode.childNodes[10].childNodes.length>0 && matchNode.childNodes[14].childNodes.length) // if description & won clubname is available
							{
								
								result=matchNode.childNodes[9].childNodes[0].nodeValue+" won by "+matchNode.childNodes[14].childNodes[0].nodeValue
							}
							
						}
						else // if result is draw or no result
						{
							if(matchNode.childNodes[14].childNodes.length>0) // if description is available
							{
								result=matchNode.childNodes[14].childNodes[0].nodeValue
							}
							
						}
					}
					
					var club1name=matchNode.childNodes[16].childNodes[0].childNodes[1].childNodes[0].nodeValue
					var club2name=matchNode.childNodes[16].childNodes[1].childNodes[1].childNodes[0].nodeValue
					
					if(typ==1)
					{
						str=str+"<div style='text-align:right; margin:0 7px 7px 0; font-weight:bold;' ><span style='cursor:pointer' onclick='matchdetailtoschedule()'>Back</span></div>"
					}
					else if(typ==2)
					{
						str=str+"<div style='text-align:right; margin:0 7px 7px 0; font-weight:bold;' ><span style='cursor:pointer' onclick='matchdetailtoscore()'>Back</span></div>"
					}
					else if(typ==3)
					{
						str=str+"<div style='text-align:right; margin:0 7px 7px 0; font-weight:bold;' ><span style='cursor:pointer' onclick='matchdetailtosingleschedule()'>Back</span></div>"
					}
					
					
					str=str+"<table width='600' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:15px;'>"
                    str=str+ "<tr height='20' bgcolor='#000'>"
					str=str+"<td width='50'>&nbsp;</td>"//Match No. : 10
                    str=str+"<td width='400' style='text-align:center;'><strong style='color:#FFFF00;'>"+document.getElementById("txttournament").value+"</strong></td>"  //- 4th match       
                    str=str+ "<td width='150' style='text-align:right;'>"+fromsession+" - "+tosession+" Season&nbsp;</td></tr><tr height='10'></tr><tr height='30' bgcolor='#000'>"       
                    //str=str+"<td width='1'>&nbsp;</td>"
					str=str+"<td width='600' style='text-align:center;' colspan='3'>"        
                    str=str+"<b style='color:#FF6600; font-size:15px;'>"+club1name+"</b>&nbsp;&nbsp; vs.&nbsp;&nbsp;<b style='color:#FF6600; font-size:15px;'>"+club2name+"</b></td>"      
                    //str=str+"<td width='1' style='text-align:right;'>&nbsp;</td>
					str=str+"</table>"      
    				str=str+"<table width='600' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:10px;'>"
                    str=str+"<tr height='30' bgcolor='#000'>"
                    str=str+"<td width='100'>&nbsp;&nbsp;<strong style='color:#FFFF00;'>Played At :</strong></td>"
                    str=str+"<td width='500' style='text-align:left;'>"+groundName+", on "+dateval+" "+timeval+"</td>"
                    str=str+"</tr>"
                    str=str+"<tr height='10'></tr>"
					str=str+"<tr height='30' bgcolor='#000'>"
                    str=str+"<td width='100'>&nbsp;&nbsp;<strong style='color:#FFFF00;'>Toss :</strong></td>"
                    str=str+"<td width='500' style='text-align:left;'>&nbsp;"+tosswonby+" won the toss and decided to "+decision+"</td>"
					str=str+"</tr>"
					str=str+"<tr height='10'></tr>"
                    str=str+"<tr height='30' bgcolor='#000'>"
                    str=str+"<td width='100'>&nbsp;&nbsp;<strong style='color:#FFFF00;'>Result :</strong></td>"
                    str=str+"<td width='500' style='text-align:left;'>&nbsp;"+result+"</td>"
					str=str+"</tr>"
                    str=str+"</table>"
					
					
					
					str=str+"<table width='600' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:15px;'>"
                    str=str+"<tr height='24px' style='background-image:url(image/group-header-bg.png);'>"
                    str=str+"<td width='360' colspan='2'>&nbsp;<strong style='color:#000;'>"+club1name+" - Innings</strong></td>"
                    
                    str=str+"<td width='50' style='text-align:right; color:#000;'><b>R</b></td>"
                    str=str+"<td width='50' style='text-align:right; color:#000;'><b>B</b></td>"
                    str=str+"<td width='40' style='text-align:right; color:#000;'><b>4s</b></td>"
                    str=str+"<td width='40' style='text-align:right; color:#000;'><b>6s</b></td>"
                    str=str+"<td width='60' style='text-align:right; color:#000;'><b>SR</b>&nbsp;</td>"
                    str=str+"</tr>"
					
					//================= create array of substitute ids for both teams==============================
					var playersNode=matchNode.childNodes[16].childNodes[0].childNodes[4];
					for(var m=0;m<playersNode.childNodes.length;m++)
					{
						var playerNode=playersNode.childNodes[m];
						if(playerNode.childNodes[23].childNodes[0].nodeValue==1)
						{
							club1substitute.push(playerNode.childNodes[0].childNodes[0].nodeValue)
						}
					}
					
					playersNode=matchNode.childNodes[16].childNodes[1].childNodes[4];
					for(var m=0;m<playersNode.childNodes.length;m++)
					{
						var playerNode=playersNode.childNodes[m];
						if(playerNode.childNodes[23].childNodes[0].nodeValue==1)
						{
							club2substitute.push(playerNode.childNodes[0].childNodes[0].nodeValue)
						}
					}
					
					
					//=============================================================================================
					
					
					playersNode=matchNode.childNodes[16].childNodes[0].childNodes[4];
					
					var captain1id=matchNode.childNodes[16].childNodes[12].childNodes[0].nodeValue;
					var captain2id=matchNode.childNodes[16].childNodes[13].childNodes[0].nodeValue;
					var wk1id=matchNode.childNodes[16].childNodes[14].childNodes[0].nodeValue;
					var wk2id=matchNode.childNodes[16].childNodes[15].childNodes[0].nodeValue;
					
					for(var m=0;m<playersNode.childNodes.length;m++)
					{
						
						
						var playerNode=playersNode.childNodes[m];
						var outmode=playerNode.childNodes[4].childNodes[0].nodeValue;
						var twelveman=playerNode.childNodes[23].childNodes[0].nodeValue;
						
						if(outmode!="DNB" && twelveman==0)
						{
								
								
								
								var runsscored=playerNode.childNodes[2].childNodes[0].nodeValue;
								var ballsfaced=playerNode.childNodes[3].childNodes[0].nodeValue;
								var strikerate=0.00;
								if(ballsfaced>0)
								{
									strikerate=(runsscored/ballsfaced)*100
								}
								
								var outstring=""
								switch(outmode)
								{
									case "Caught Out":
										
										if(playerNode.childNodes[6].childNodes[0]==undefined)
										{
											outstring="c Unknown b "+playerNode.childNodes[5].childNodes[0].nodeValue;
											break;
										}						
										else if(playerNode.childNodes[6].childNodes[0].nodeValue==playerNode.childNodes[5].childNodes[0].nodeValue)
										{
											outstring="c &amp; b "+playerNode.childNodes[6].childNodes[0].nodeValue;
										}
										else
										{
											if(playerNode.childNodes[24].childNodes[0].nodeValue==club2substitute[0])
											{
												outstring="c sub ("+playerNode.childNodes[6].childNodes[0].nodeValue+")  b "+playerNode.childNodes[5].childNodes[0].nodeValue;
											}
											else
											{
											outstring="c "+playerNode.childNodes[6].childNodes[0].nodeValue+" b "+playerNode.childNodes[5].childNodes[0].nodeValue;
											}
										}
										break;
									case "LBW":
										outstring="lbw b "+playerNode.childNodes[5].childNodes[0].nodeValue;
										break;
									case "Not Out":
										outstring="not out";
										break;
									case "Retired Hurt":
										outstring="retired hurt";
										break;
									case "Stumped Out":
										outstring="st. "+playerNode.childNodes[6].childNodes[0].nodeValue+" b "+playerNode.childNodes[5].childNodes[0].nodeValue;
										break;
									case "Bowled Out":
										outstring="b "+playerNode.childNodes[5].childNodes[0].nodeValue;
										break;
									case "Run Out":
										outstring="run out";
										break;
									case "Obstructing The Field":
										outstring="obstructing the field";
										break;
									case "Timed Out":
										outstring="timed out";
										break;
									case "Handling The Ball":
										outstring="handling the ball b "+playerNode.childNodes[5].childNodes[0].nodeValue;
										break;
									case "Hit Wicket":
										outstring="hit wicket b "+playerNode.childNodes[5].childNodes[0].nodeValue;
										break;
									
									case "Unknown":
										outstring="unknown";
										break;
								}
								var id=playerNode.childNodes[0].childNodes[0].nodeValue;
								
								str=str+"<tr height='24px'>"
								
								if(id==captain1id)
								{
									
									if(id==wk1id)
									{
										if(outmode=="Not Out")
											str=str+"<td width='140' style='color:#ff9900'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" * &dagger;</td>"
										else
											str=str+"<td width='140'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" * &dagger;</td>"
										
									}
									else
									{
										if(outmode=="Not Out")
											str=str+"<td width='140' style='color:#ff9900'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" *</td>"
										else
											str=str+"<td width='140'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" *</td>"
									}
									
								}
								else
								{
									if(id==wk1id)
									{
										if(outmode=="Not Out")
											str=str+"<td width='140' style='color:#ff9900'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" &dagger;</td>"
										else
											str=str+"<td width='140'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" &dagger;</td>"
									}
									else
									{
										if(outmode=="Not Out")
											str=str+"<td width='140' style='color:#ff9900'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+"</td>"
										else
											str=str+"<td width='140'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+"</td>"
									}
									
								}
								if(playerNode.childNodes[7].childNodes[0].nodeValue==1)
								{
									manofthematch=manofthematch+playerNode.childNodes[1].childNodes[0].nodeValue+", "
								}
								
								if(outmode=="Not Out")
								{
									str=str+"<td width='140'  style='color:#ff9900'>"+outstring+"</td>"
									str=str+"<td width='46' style='text-align:right; color:#ff9900;'><b>"+runsscored+"</b></td>"
									str=str+"<td width='46' style='text-align:right; color:#ff9900;'>"+ballsfaced+"</td>"
									str=str+"<td width='30' style='text-align:right; color:#ff9900;'>"+playerNode.childNodes[13].childNodes[0].nodeValue+"</td>"
									str=str+"<td width='30' style='text-align:right; color:#ff9900;'>"+playerNode.childNodes[15].childNodes[0].nodeValue+"</td>"
									str=str+"<td width='58' style='text-align:right; color:#ff9900;'>"+strikerate.toFixed(2)+"</td>"
								}
								else
								{
									str=str+"<td width='140'>"+outstring+"</td>"
									str=str+"<td width='46' style='text-align:right; color:#fff;'><b>"+runsscored+"</b></td>"
									str=str+"<td width='46' style='text-align:right; color:#fff;'>"+ballsfaced+"</td>"
									str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[13].childNodes[0].nodeValue+"</td>"
									str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[15].childNodes[0].nodeValue+"</td>"
									str=str+"<td width='58' style='text-align:right; color:#fff;'>"+strikerate.toFixed(2)+"</td>"
								}
								
								str=str+"</tr>"
						}
					}
					
                    
					var didnotbatname="";
					for(var m=0;m<playersNode.childNodes.length;m++)
					{
						
						var playerNode=playersNode.childNodes[m];
						var id=playerNode.childNodes[0].childNodes[0].nodeValue;
						
						
						var outmode=playerNode.childNodes[4].childNodes[0].nodeValue;
						var twelveman=playerNode.childNodes[23].childNodes[0].nodeValue;
						
						if(outmode=="DNB" && twelveman==0)
						{
								if(id==captain1id)
								{
									if(id==wk1id)
									{
										didnotbatname=didnotbatname+playerNode.childNodes[1].childNodes[0].nodeValue+" * &dagger;, "
									}
									else
									{
										didnotbatname=didnotbatname+playerNode.childNodes[1].childNodes[0].nodeValue+" *, "
									}
								}
								else
								{
									if(id==wk1id)
									{
										didnotbatname=didnotbatname+playerNode.childNodes[1].childNodes[0].nodeValue+" &dagger;, "
									}
									else
									{
										didnotbatname=didnotbatname+playerNode.childNodes[1].childNodes[0].nodeValue+", "
									}
								}
								
								if(playerNode.childNodes[7].childNodes[0].nodeValue==1)
								{
									manofthematch=manofthematch+playerNode.childNodes[1].childNodes[0].nodeValue+", "
								}
						}
					}
					
					didnotbatname=didnotbatname.slice(0,-1);
					didnotbatname=didnotbatname.slice(0,-1);
					str=str+"<tr height='24px' >"
					str=str+"<td colspan='7'>&nbsp;</td>"
					str=str+"</tr>"
					if(didnotbatname!="")
					{
						str=str+"<tr height='24px'>"
						str=str+"<td colspan='7' style='text-align:left;'><b>Did not bat : </b> "+didnotbatname+"</td>"
						str=str+"</tr>"
					}
					
					
			        str=str+"<tr height='24px'>"
                    str=str+"<td width='140' style='text-align:left;'>&nbsp;<strong>Extras :</strong></td>"
					var b=matchNode.childNodes[16].childNodes[1].childNodes[2].childNodes[0].nodeValue;
					var lb=matchNode.childNodes[16].childNodes[1].childNodes[3].childNodes[0].nodeValue;
					var w=matchNode.childNodes[16].childNodes[11].childNodes[0].nodeValue;
					var nb=matchNode.childNodes[16].childNodes[10].childNodes[0].nodeValue;
					
                    str=str+"<td width='200'>(b "+b+", lb "+lb+", w "+w+", nb "+nb+")"
					str=str+"</td>"
                    str=str+"<td width='30' style='text-align:right; color:#fff; border-bottom:1px solid #fff;'>"+(parseInt(b)+parseInt(lb)+parseInt(w)+parseInt(nb))+"</td>"
                    str=str+"<td width='30' style='text-align:right; color:#fff; border-bottom:1px solid #fff;'></td>"
                    str=str+"<td width='30' style='text-align:right; color:#fff; border-bottom:1px solid #fff;'></td>"
                    str=str+"<td width='30' style='text-align:right; color:#fff; border-bottom:1px solid #fff;'></td>"
                    str=str+"<td width='30' style='text-align:right; color:#fff; border-bottom:1px solid #fff;'></td>"
                    str=str+"</tr>"
                    str=str+"<tr height='24px'>"
                    str=str+"<td width='140'>&nbsp;<strong>Total :</strong></td>"
					
					
					
					var totalballs=(parseFloat(matchNode.childNodes[16].childNodes[4].childNodes[0].nodeValue)-parseInt(matchNode.childNodes[16].childNodes[4].childNodes[0].nodeValue)).toFixed(2)*10;
					totalballs=totalballs+parseInt(matchNode.childNodes[16].childNodes[4].childNodes[0].nodeValue)*6
					
					
					
                    //str=str+"<td width='200'>("+matchNode.childNodes[16].childNodes[3].childNodes[0].nodeValue+" wickets; "+parseFloat(matchNode.childNodes[16].childNodes[4].childNodes[0].nodeValue).toFixed(1)+" overs)</td>"
					str=str+"<td width='200'>("+matchNode.childNodes[16].childNodes[3].childNodes[0].nodeValue+" wickets; "+convertBallsToOvers(totalballs)+" overs)</td>"
                    str=str+"<td width='30' style='text-align:right; color:#fff;'><b>"+matchNode.childNodes[16].childNodes[2].childNodes[0].nodeValue+"</b></td>"
                    str=str+"<td colspan='4' style='text-align:center; color:#fff;'>("+(parseFloat(matchNode.childNodes[16].childNodes[2].childNodes[0].nodeValue)*6/totalballs).toFixed(2)+" runs per over)</td>"
                    str=str+"</tr>"
                    str=str+"</table>"
					
					
					
					str=str+"<table width='500' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:15px;'>"
    				str=str+"<tr height='24px' bgcolor='#666666'>"
     				str=str+"<td width='140'>&nbsp;&nbsp;<strong style='color:#000;'>Bowling</strong></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>O</b></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>M</b></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>R</b></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>W</b></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>NB</b></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>WB</b></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>Econ</b>&nbsp;</td>"
                    str=str+"</tr>"
					
					var bowlingOrder=new Array();
					playersNode=matchNode.childNodes[16].childNodes[1].childNodes[4];
					for(var m=0;m<playersNode.childNodes.length;m++)
					{
						
						var playerNode=playersNode.childNodes[m];
						
						if(playerNode.childNodes[22].childNodes[0].nodeValue!=0)
						{
							bowlingOrder.push(playerNode.childNodes[22].childNodes[0].nodeValue)
						}
						
					}
					bowlingOrder.sort(function(a,b){return a - b});
					
					
					for(var p=0;p<bowlingOrder.length;p++)
					{
						for(var m=0;m<playersNode.childNodes.length;m++)
						{
							
							var playerNode=playersNode.childNodes[m];
							
							if(playerNode.childNodes[22].childNodes[0].nodeValue==bowlingOrder[p])
							{
								var totalballs=(parseFloat(playerNode.childNodes[19].childNodes[0].nodeValue)-parseInt(playerNode.childNodes[19].childNodes[0].nodeValue)).toFixed(2)*10;
								totalballs=totalballs+parseInt(playerNode.childNodes[19].childNodes[0].nodeValue)*6
								var totalruns=playerNode.childNodes[21].childNodes[0].nodeValue;
								var econ="";
								if(totalballs==0)
								{
									econ="-";
								}
								else
								{
									econ=(totalruns/totalballs)*6;
									econ=econ.toFixed(2);
								}
								
								str=str+"<tr height='24px'>"
      							str=str+"<td width='140'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[19].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[20].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[21].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[18].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[16].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[17].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+econ+"</td>"
                    			str=str+"</tr>"
								
								
							}
							
						}
						
					}
					
					
    				
  					str=str+"</table>"
					
				//===============================================================================================================	
					
					
					str=str+"<table width='600px' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:15px;'>"
                    str=str+"<tr height='24px' style='background-image:url(image/group-header-bg.png);'>"
                    str=str+"<td width='360px' colspan='2'>&nbsp;<strong style='color:#000;'>"+club2name+" - Innings</strong></td>"
                    
                    str=str+"<td width='50px' style='text-align:right; color:#000;'><b>R</b></td>"
                    str=str+"<td width='50px' style='text-align:right; color:#000;'><b>B</b></td>"
                    str=str+"<td width='40px' style='text-align:right; color:#000;'><b>4s</b></td>"
                    str=str+"<td width='40px' style='text-align:right; color:#000;'><b>6s</b></td>"
                    str=str+"<td width='60px' style='text-align:right; color:#000;'><b>SR</b>&nbsp;</td>"
                    str=str+"</tr>"
					
					playersNode=matchNode.childNodes[16].childNodes[1].childNodes[4];
					
					for(var m=0;m<playersNode.childNodes.length;m++)
					{
						var playerNode=playersNode.childNodes[m];
						var outmode=playerNode.childNodes[4].childNodes[0].nodeValue;
						var twelveman=playerNode.childNodes[23].childNodes[0].nodeValue;
						if(outmode!="DNB" && twelveman==0)
						{
								
								
								
								var runsscored=playerNode.childNodes[2].childNodes[0].nodeValue;
								var ballsfaced=playerNode.childNodes[3].childNodes[0].nodeValue;
								var strikerate=0.00;
								if(ballsfaced>0)
								{
									strikerate=(runsscored/ballsfaced)*100
								}
								
								var outstring=""
								switch(outmode)
								{
									case "Caught Out":
										
										if(playerNode.childNodes[6].childNodes[0]==undefined)
										{
											outstring="c Unknown b "+playerNode.childNodes[5].childNodes[0].nodeValue;
											break;
										}	
										else if(playerNode.childNodes[6].childNodes[0].nodeValue==playerNode.childNodes[5].childNodes[0].nodeValue)
										{
											outstring="c &amp; b "+playerNode.childNodes[6].childNodes[0].nodeValue;
										}
										else
										{
											
											if(playerNode.childNodes[24].childNodes[0].nodeValue==club1substitute[0])
											{
												outstring="c sub ("+playerNode.childNodes[6].childNodes[0].nodeValue+")  b "+playerNode.childNodes[5].childNodes[0].nodeValue;
											}
											else
											{
											outstring="c "+playerNode.childNodes[6].childNodes[0].nodeValue+" b "+playerNode.childNodes[5].childNodes[0].nodeValue;
											}
										}
										break;
									case "LBW":
										outstring="lbw b "+playerNode.childNodes[5].childNodes[0].nodeValue;
										break;
									case "Not Out":
										outstring="not out";
										break;
									case "Retired Hurt":
										outstring="retired hurt";
										break;
									case "Stumped Out":
										outstring="st. "+playerNode.childNodes[6].childNodes[0].nodeValue+" b "+playerNode.childNodes[5].childNodes[0].nodeValue;
										break;
									case "Bowled Out":
										outstring="b "+playerNode.childNodes[5].childNodes[0].nodeValue;
										break;
									case "Run Out":
										outstring="run out";
										break;
									case "Obstructing The Field":
										outstring="obstructing the field";
										break;
									case "Timed Out":
										outstring="timed out";
										break;
									case "Handling The Ball":
										outstring="handling the ball b "+playerNode.childNodes[5].childNodes[0].nodeValue;
										break;
									case "Hit Wicket":
										outstring="hit wicket b "+playerNode.childNodes[5].childNodes[0].nodeValue;
										break;
									
									case "Unknown":
										outstring="unknown";
										break;
								}
								
								var id=playerNode.childNodes[0].childNodes[0].nodeValue;
								
								str=str+"<tr height='24px'>"
								if(id==captain2id)
								{
									
									if(id==wk2id)
									{
										if(outmode=="Not Out")
											str=str+"<td width='140px' style='color:#ff9900'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" * &dagger;</td>"
										else
											str=str+"<td width='140px'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" * &dagger;</td>"
									}
									else
									{
										if(outmode=="Not Out")
											str=str+"<td width='140px' style='color:#ff9900'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" *</td>"
										else
											str=str+"<td width='140px'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" *</td>"
									}
									
								}
								else
								{
									if(id==wk2id)
									{
										if(outmode=="Not Out")
											str=str+"<td width='140px' style='color:#ff9900'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" &dagger;</td>"
										else
											str=str+"<td width='140px'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" &dagger;</td>"
									}
									else
									{
										if(outmode=="Not Out")
											str=str+"<td width='140px' style='color:#ff9900'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+"</td>"
										else
											str=str+"<td width='140px'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+"</td>"
									}
									
								}
								if(playerNode.childNodes[7].childNodes[0].nodeValue==1)
								{
									manofthematch=manofthematch+playerNode.childNodes[1].childNodes[0].nodeValue+", "
								}
								
								if(outmode=="Not Out")
								{
									str=str+"<td width='140px' style='color:#ff9900'>"+outstring+"</td>"
									str=str+"<td width='46px' style='text-align:right; color:#ff9900;'><b>"+runsscored+"</b></td>"
									str=str+"<td width='46px' style='text-align:right; color:#ff9900;'>"+ballsfaced+"</td>"
									str=str+"<td width='30px' style='text-align:right; color:#ff9900;'>"+playerNode.childNodes[13].childNodes[0].nodeValue+"</td>"
									str=str+"<td width='30px' style='text-align:right; color:#ff9900;'>"+playerNode.childNodes[15].childNodes[0].nodeValue+"</td>"
									str=str+"<td width='58px' style='text-align:right; color:#ff9900;'>"+strikerate.toFixed(2)+"</td>"
								}
								else
								{
									str=str+"<td width='140px'>"+outstring+"</td>"
									str=str+"<td width='46px' style='text-align:right; color:#fff;'><b>"+runsscored+"</b></td>"
									str=str+"<td width='46px' style='text-align:right; color:#fff;'>"+ballsfaced+"</td>"
									str=str+"<td width='30px' style='text-align:right; color:#fff;'>"+playerNode.childNodes[13].childNodes[0].nodeValue+"</td>"
									str=str+"<td width='30px' style='text-align:right; color:#fff;'>"+playerNode.childNodes[15].childNodes[0].nodeValue+"</td>"
									str=str+"<td width='58px' style='text-align:right; color:#fff;'>"+strikerate.toFixed(2)+"</td>"
								}
								
								str=str+"</tr>"
						}
								
					}// end of for
					
					didnotbatname="";
					for(var m=0;m<playersNode.childNodes.length;m++)
					{
						
						var playerNode=playersNode.childNodes[m];
						var id=playerNode.childNodes[0].childNodes[0].nodeValue;
						var outmode=playerNode.childNodes[4].childNodes[0].nodeValue;
						var twelveman=playerNode.childNodes[23].childNodes[0].nodeValue;
						
						if(outmode=="DNB"  && twelveman==0)
						{
								if(id==captain2id)
								{
									if(id==wk2id)
									{
										didnotbatname=didnotbatname+playerNode.childNodes[1].childNodes[0].nodeValue+" * &dagger;, "
									}
									else
									{
										didnotbatname=didnotbatname+playerNode.childNodes[1].childNodes[0].nodeValue+" *, "
									}
								}
								else
								{
									if(id==wk2id)
									{
										didnotbatname=didnotbatname+playerNode.childNodes[1].childNodes[0].nodeValue+" &dagger;, "
									}
									else
									{
										didnotbatname=didnotbatname+playerNode.childNodes[1].childNodes[0].nodeValue+", "
									}
								}
								if(playerNode.childNodes[7].childNodes[0].nodeValue==1)
								{
									manofthematch=manofthematch+playerNode.childNodes[1].childNodes[0].nodeValue+", "
								}
								
						}
					}
					didnotbatname=didnotbatname.slice(0,-1);
					didnotbatname=didnotbatname.slice(0,-1);
					str=str+"<tr height='24px'>"
					str=str+"<td colspan='7'>&nbsp;</td>"
					str=str+"</tr>"
					if(didnotbatname!="")
					{
						str=str+"<tr height='24px'>"
						str=str+"<td colspan='7'><b>Did not bat : </b> "+didnotbatname+"</td>"
						str=str+"</tr>"
					}
					
					str=str+"<tr height='24px'>"
                    str=str+"<td width='140px'>&nbsp;<strong>Extras :</strong></td>"
					var b=matchNode.childNodes[16].childNodes[0].childNodes[2].childNodes[0].nodeValue;
					var lb=matchNode.childNodes[16].childNodes[0].childNodes[3].childNodes[0].nodeValue;
					var w=matchNode.childNodes[16].childNodes[6].childNodes[0].nodeValue;
					var nb=matchNode.childNodes[16].childNodes[5].childNodes[0].nodeValue;
					
                    str=str+"<td width='200px'>(b "+b+", lb "+lb+", w "+w+", nb "+nb+")"
					str=str+"</td>"
                    str=str+"<td width='30px' style='text-align:right; color:#fff; border-bottom:1px solid #fff;'>"+(parseInt(b)+parseInt(lb)+parseInt(w)+parseInt(nb))+"</td>"
                    str=str+"<td width='30px' style='text-align:right; color:#fff; border-bottom:1px solid #fff;'></td>"
                    str=str+"<td width='30px' style='text-align:right; color:#fff; border-bottom:1px solid #fff;'></td>"
                    str=str+"<td width='30px' style='text-align:right; color:#fff; border-bottom:1px solid #fff;'></td>"
                    str=str+"<td width='30px' style='text-align:right; color:#fff; border-bottom:1px solid #fff;'></td>"
                    str=str+"</tr>"
                    str=str+"<tr height='24px'>"
                    str=str+"<td width='140px'>&nbsp;<strong>Total :</strong></td>"
					
					var totalballs=(parseFloat(matchNode.childNodes[16].childNodes[8].childNodes[0].nodeValue)-parseInt(matchNode.childNodes[16].childNodes[8].childNodes[0].nodeValue)).toFixed(2)*10;
					totalballs=totalballs+parseInt(matchNode.childNodes[16].childNodes[8].childNodes[0].nodeValue)*6
					//str=str+"<td width='200px'>("+matchNode.childNodes[16].childNodes[9].childNodes[0].nodeValue+" wickets; "+parseFloat(matchNode.childNodes[16].childNodes[8].childNodes[0].nodeValue).toFixed(1)+" overs)</td>"
                    str=str+"<td width='200px'>("+matchNode.childNodes[16].childNodes[9].childNodes[0].nodeValue+" wickets; "+convertBallsToOvers(totalballs)+" overs)</td>"
                    str=str+"<td width='30px' style='text-align:right; color:#fff;'><b>"+matchNode.childNodes[16].childNodes[7].childNodes[0].nodeValue+"</b></td>"
                    str=str+"<td colspan='4' style='text-align:center; color:#fff;'>("+(parseFloat(matchNode.childNodes[16].childNodes[7].childNodes[0].nodeValue)*6/totalballs).toFixed(2)+" runs per over)</td>"
                    str=str+"</tr>"
					str=str+"</table>"
					
					
					
					str=str+"<table width='500' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:15px;'>"
    				str=str+"<tr height='24px' bgcolor='#666666'>"
     				str=str+"<td width='140'>&nbsp;&nbsp;<strong style='color:#000;'>Bowling</strong></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>O</b></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>M</b></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>R</b></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>W</b></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>NB</b></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>WB</b></td>"
                    str=str+"<td width='30' style='text-align:right; color:#000;'><b>Econ</b>&nbsp;</td>"
                    str=str+"</tr>"
					
					bowlingOrder=new Array();
					playersNode=matchNode.childNodes[16].childNodes[0].childNodes[4];
					for(var m=0;m<playersNode.childNodes.length;m++)
					{
						
						var playerNode=playersNode.childNodes[m];
						
						if(playerNode.childNodes[22].childNodes[0].nodeValue!=0)
						{
							bowlingOrder.push(playerNode.childNodes[22].childNodes[0].nodeValue)
						}
						
					}
					
					bowlingOrder.sort(function(a,b){return a - b});
					
					
					for(var p=0;p<bowlingOrder.length;p++)
					{
						for(var m=0;m<playersNode.childNodes.length;m++)
						{
							
							var playerNode=playersNode.childNodes[m];
							
							if(playerNode.childNodes[22].childNodes[0].nodeValue==bowlingOrder[p])
							{
								var totalballs=(parseFloat(playerNode.childNodes[19].childNodes[0].nodeValue)-parseInt(playerNode.childNodes[19].childNodes[0].nodeValue)).toFixed(2)*10;
								totalballs=totalballs+parseInt(playerNode.childNodes[19].childNodes[0].nodeValue)*6
								//var totalballs=0(parseFloat(playerNode.childNodes[19].childNodes[0].nodeValue)-parseInt(playerNode.childNodes[19].childNodes[0].nodeValue)).toFixesd(2)*10
								//totalballs=totalballs+parseInt(playerNode.childNodes[19].childNodes[0].nodeValue)*6
								var totalruns=playerNode.childNodes[21].childNodes[0].nodeValue;
								var econ="";
								if(totalballs==0)
								{
									econ="-";
								}
								else
								{
									econ=(totalruns/totalballs)*6;
									econ=econ.toFixed(2);
								}
								
								str=str+"<tr height='24px'>"
      							str=str+"<td width='140'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[19].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[20].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[21].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[18].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[16].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+playerNode.childNodes[17].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td width='30' style='text-align:right; color:#fff;'>"+econ+"</td>"
                    			str=str+"</tr>"
								
							}
							
						}
						
					}
					
					str=str+"</table>"
					
					manofthematch=manofthematch.slice(0,-1);
					manofthematch=manofthematch.slice(0,-1);
					
					str=str+"<table width='600' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:15px;'>"
                    str=str+"<tr height='24px'>"
                    str=str+"<td width='535'>&nbsp;</td>"
					str=str+"</tr>"
					str=str+"<tr height='24px'>"
                    str=str+"<td width='535'><b>Player of the match</b>&nbsp;"+manofthematch+"</td>"
					str=str+"</tr>"
					str=str+"<tr height='24px'>"
                    str=str+"<td width='535'>&nbsp;</td>"
					str=str+"</tr>"
					str=str+"<tr height='24px'>"
                    str=str+"<td width='535'><b>Umpires</b>&nbsp;"+matchNode.childNodes[12].childNodes[0].nodeValue+"&nbsp;And&nbsp;"+matchNode.childNodes[13].childNodes[0].nodeValue+"</td>"
					str=str+"</tr>"
					str=str+"<tr height='24px'>"
                    str=str+"<td width='535'><b>Scorer</b>&nbsp;"+matchNode.childNodes[15].childNodes[0].nodeValue+"</td>"
					str=str+"</tr>"
					str=str+"<tr height='24px'>"
                    str=str+"<td width='535'>&nbsp;</td>"
					str=str+"</tr>"
                    str=str+"</table>"
					if(typ==1)
					{
						str=str+"<div style='text-align:right; margin:0 7px 7px 0; font-weight:bold;' ><span style='cursor:pointer' onclick='matchdetailtoschedule()'>Back</span></div>"
					}
					else if(typ==2)
					{
						str=str+"<div style='text-align:right; margin:0 7px 7px 0; font-weight:bold;' ><span style='cursor:pointer' onclick='matchdetailtoscore()'>Back</span></div>"
					}
                    else if(typ==3)
					{
						str=str+"<div style='text-align:right; margin:0 7px 7px 0; font-weight:bold;' ><span style='cursor:pointer' onclick='matchdetailtosingleschedule()'>Back</span></div>"
					}
					
				
					}
					catch(e)
					{
						
						str=str+"<table width='535' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:15px;'>"
						str=str+"<tr height='24px'>"
                    	str=str+"<td width='535'>An error occured while loading the page.</td>"
						str=str+"</tr>"
						str=str+"</table>"
					}
					finally
					{
						//document.getElementById("topindex").style.display="none";
						document.getElementById("toparea2").innerHTML="";
						document.getElementById("toparea3").innerHTML="";
						document.getElementById("toparea3").innerHTML=str;
						$.unblockUI();
						strmatchdetail=str;
					}
					
				}
				
				
			}
		}
		objRequest.send('mid='+matchid+'&tid='+tournamentid);
	}
}

