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: '#000000', 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="";
					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 class='back'><span onclick='matchdetailtoschedule()'>&laquo; Back</span></div>"
					}
					else if(typ==2)
					{
						str=str+"<div class='back'><span onclick='matchdetailtoscore()'>&laquo; Back</span></div>"
					}
					else if(typ==3)
					{
						str=str+"<div class='back'><span onclick='matchdetailtosingleschedule()'>&laquo; Back</span></div>"
					}

								
					
					str=str+"<table align='center' width='99%' border='0' cellspacing='0' cellpadding='5' style='color:#ffffff; border:1px solid #596166; margin-top:7px; margin-bottom:7px; text-align:left; font-family:Arial, Helvetica, sans-serif'>"
					str=str+"<tr height='25' style='background:url(images/heading_grey.gif);font-weight:bold;color:#d7fe01'>"
                    str=str+"<td>"+document.getElementById("txttournament").value+"</td>"  //- 4th match       
                    str=str+"<td align='right'>"+fromsession+" - "+tosession+" Season</td>"
                    str=str+"</tr>"
					str=str+"<tr height='40'>"
					str=str+"<td colspan='2' style='text-align:center; font-size:15px;background-color:#323232; border:1px solid #000000'>"        
                    str=str+"<b style='color:#fcff00'>"+club1name+"</b>&nbsp;&nbsp; vs.&nbsp;&nbsp;<b style='color:#fcff00'>"+club2name+"</b>"  
					str=str+"</td>"
					str=str+"</tr>"
					
					str=str+"<tr>"
					str=str+"<td colspan='2' style='background-color:#323232; border:1px solid #000000'>"
					
						str=str+"<table width='100%' border='0' cellspacing='0' cellpadding='5' style='font-family:Arial, Helvetica, sans-serif'>"
						str=str+"<tr>"
						str=str+"<td width='15%' style='border-bottom:1px solid #000000;font-weight:bold;color:#51ccff'>Played At</td>"
						str=str+"<td width='2%' style='border-bottom:1px solid #000000;font-weight:bold'>:</td>"
						str=str+"<td width='83%' style='border-bottom:1px solid #000000'>"+groundName+", on "+dateval+" "+timeval+"</td>"
						str=str+"</tr>"
						str=str+"<tr>"
						str=str+"<td style='border-bottom:1px solid #000000;font-weight:bold;color:#51ccff'>Toss</td>"
						str=str+"<td width='2%' style='border-bottom:1px solid #000000;font-weight:bold'>:</td>"
						str=str+"<td style='border-bottom:1px solid #000000'>"+tosswonby+" won the toss and decided to "+decision+"</td>"
						str=str+"</tr>"
						str=str+"<tr>"
						str=str+"<td style='font-weight:bold;color:#51ccff'>Result</td>"
						str=str+"<td width='2%'><strong>:</strong></td>"
						str=str+"<td>"+result+"</td>"
						str=str+"</tr>"
						str=str+"</table>"
						
					str=str+"</td>"
					str=str+"</tr>"
					
					//================== INNINGS 1 BATTING ==============================
					str=str+"<tr>"
					str=str+"<td colspan='2'>"
					
						str=str+"<table align='center' width='99%' border='0' cellspacing='0' cellpadding='5' style='color:#ffffff; border:1px solid #596166; margin-top:15px; margin-bottom:7px'>"
                    str=str+"<tr height='25' style='background:url(images/heading_grey.gif);font-weight:bold;color:#d7fe01'>"
                    str=str+"<td width='440' colspan='2'>"+club1name+" - Innings</td>"                    
                    str=str+"<td width='50' style='text-align:right;border-right:1px solid #000000'>R</td>"
                    str=str+"<td width='50' style='text-align:right;border-right:1px solid #000000'>B</td>"
                    str=str+"<td width='40' style='text-align:right;border-right:1px solid #000000'>4s</td>"
                    str=str+"<td width='40' style='text-align:right;border-right:1px solid #000000'>6s</td>"
                    str=str+"<td width='50' style='text-align:right'>SR</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 "Double Hit":
										outstring="double hit";
										break;
									case "Unknown":
										outstring="unknown";
										break;
								}
								var id=playerNode.childNodes[0].childNodes[0].nodeValue;
								
								str=str+"<tr height='30'>"
								
								if(id==captain1id)
								{
									
									if(id==wk1id)
									{
										if(outmode=="Not Out")
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>"+playerNode.childNodes[1].childNodes[0].nodeValue+" * &dagger;</td>"
										else
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>"+playerNode.childNodes[1].childNodes[0].nodeValue+" * &dagger;</td>"
										
									}
									else
									{
										if(outmode=="Not Out")
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>"+playerNode.childNodes[1].childNodes[0].nodeValue+" *</td>"
										else
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>"+playerNode.childNodes[1].childNodes[0].nodeValue+" *</td>"
									}
									
								}
								else
								{
									if(id==wk1id)
									{
										if(outmode=="Not Out")
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>"+playerNode.childNodes[1].childNodes[0].nodeValue+" &dagger;</td>"
										else
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>"+playerNode.childNodes[1].childNodes[0].nodeValue+" &dagger;</td>"
									}
									else
									{
										if(outmode=="Not Out")
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>"+playerNode.childNodes[1].childNodes[0].nodeValue+"</td>"
										else
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>"+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='430' style='border-bottom:1px solid #596166;'>"+outstring+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'><b>"+runsscored+"</b></td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+ballsfaced+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+playerNode.childNodes[13].childNodes[0].nodeValue+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+playerNode.childNodes[15].childNodes[0].nodeValue+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+strikerate.toFixed(2)+"</td>"
								}
								else
								{
									str=str+"<td width='430' style='border-bottom:1px solid #596166;'>"+outstring+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'><b>"+runsscored+"</b></td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+ballsfaced+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+playerNode.childNodes[13].childNodes[0].nodeValue+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+playerNode.childNodes[15].childNodes[0].nodeValue+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+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='10' >"
					str=str+"<td colspan='7' class='style2'>&nbsp;</td>"
					str=str+"</tr>"				
					
			        str=str+"<tr height='30'>"
                   
					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 style='text-align:left;color:#51ccff'><strong>Extras :</strong></td>"
                    str=str+"<td style='text-align:left'>(b "+b+", lb "+lb+", w "+w+", nb "+nb+")"
					str=str+"</td>"
                    str=str+"<td style='text-align:right; border-bottom:1px solid #596166;'><strong>"+(parseInt(b)+parseInt(lb)+parseInt(w)+parseInt(nb))+"</strong></td>"
                    str=str+"<td style='text-align:right; border-bottom:1px solid #596166;'></td>"
                    str=str+"<td style='text-align:right; border-bottom:1px solid #596166;'></td>"
                    str=str+"<td style='text-align:right; border-bottom:1px solid #596166;'></td>"
                    str=str+"<td style='text-align:right; border-bottom:1px solid #596166;'></td>"
                    str=str+"</tr>"
                    str=str+"<tr height='30'>"
                    str=str+"<td width='430' style='text-align:left;color:#51ccff'><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 style='text-align:left'>("+matchNode.childNodes[16].childNodes[3].childNodes[0].nodeValue+" wickets; "+convertBallsToOvers(totalballs)+" overs)</td>"
                    str=str+"<td style='text-align:right'><b>"+matchNode.childNodes[16].childNodes[2].childNodes[0].nodeValue+"</b></td>"
                    str=str+"<td colspan='4' style='text-align:center'>("+(parseFloat(matchNode.childNodes[16].childNodes[2].childNodes[0].nodeValue)*6/totalballs).toFixed(2)+" runs per over)</td>"
                    str=str+"</tr>"
					
					if(didnotbatname!="")
					{
						str=str+"<tr height='10'>"
						str=str+"<td colspan='7' style='text-align:left;'><font style='color:#51ccff'><b>Did not bat : </b></font> "+didnotbatname+"</td>"
						str=str+"</tr>"
					}
					
                    str=str+"</table>"
						
					str=str+"</td>"
					str=str+"</tr>"
					
					//================== INNINGS 1 BOWLING ==============================
					str=str+"<tr>"
					str=str+"<td colspan='2'>"
					
						str=str+"<table align='center' width='80%' border='0' cellspacing='0' cellpadding='5' style='color:#ffffff; border:1px solid #42494d; border-bottom:none; margin-bottom:7px'>"
                    str=str+"<tr height='25' style='background:url(images/heading_grey_1.gif);font-weight:bold;color:#8afffe'>"
     				str=str+"<td width='290'>Bowling</td>"
                    str=str+"<td width='40' style='text-align:right;border-right:1px solid #000000'>O</td>"
                    str=str+"<td width='40' style='text-align:right;border-right:1px solid #000000'>M</td>"
                    str=str+"<td width='40' style='text-align:right;border-right:1px solid #000000'>R</td>"
                    str=str+"<td width='40' style='text-align:right;border-right:1px solid #000000'>W</td>"
                    str=str+"<td width='40' style='text-align:right;border-right:1px solid #000000'>NB</td>"
                    str=str+"<td width='40' style='text-align:right;border-right:1px solid #000000'>WB</td>"
                    str=str+"<td width='40' style='text-align:right'>Econ</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='30'>"
      							str=str+"<td style='border-bottom:1px solid #42494d;font-weight:bold'>"+playerNode.childNodes[1].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+playerNode.childNodes[19].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+playerNode.childNodes[20].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+playerNode.childNodes[21].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+playerNode.childNodes[18].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+playerNode.childNodes[16].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+playerNode.childNodes[17].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+econ+"</td>"
                    			str=str+"</tr>"								
								
							}
							
						}
						
					}		
    				
  					str=str+"</table>"
						
					str=str+"</td>"
					str=str+"</tr>"					
					
					//================== INNINGS 2 BATTING ==============================
					str=str+"<tr>"
					str=str+"<td colspan='2'>"
					
						str=str+"<table align='center' width='99%' border='0' cellspacing='0' cellpadding='5' style='color:#ffffff; border:1px solid #596166; margin-top:15px; margin-bottom:7px'>"
                    str=str+"<tr height='25' style='background:url(images/heading_grey.gif);font-weight:bold;color:#d7fe01'>"
                    str=str+"<td width='430' colspan='2'>"+club2name+" - Innings</td>"                    
                    str=str+"<td width='50' style='text-align:right;border-right:1px solid #000000'>R</td>"
                    str=str+"<td width='50' style='text-align:right;border-right:1px solid #000000'>B</td>"
                    str=str+"<td width='40' style='text-align:right;border-right:1px solid #000000'>4s</td>"
                    str=str+"<td width='40' style='text-align:right;border-right:1px solid #000000'>6s</td>"
                    str=str+"<td width='60' style='text-align:right'>SR</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 "Double Hit":
										outstring="double hit";
										break;
									case "Unknown":
										outstring="unknown";
										break;
								}
								
								var id=playerNode.childNodes[0].childNodes[0].nodeValue;
								
								str=str+"<tr height='30'>"
								if(id==captain2id)
								{
									
									if(id==wk2id)
									{
										if(outmode=="Not Out")
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" * &dagger;</td>"
										else
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" * &dagger;</td>"
									}
									else
									{
										if(outmode=="Not Out")
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" *</td>"
										else
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" *</td>"
									}
									
								}
								else
								{
									if(id==wk2id)
									{
										if(outmode=="Not Out")
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" &dagger;</td>"
										else
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+" &dagger;</td>"
									}
									else
									{
										if(outmode=="Not Out")
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>&nbsp;"+playerNode.childNodes[1].childNodes[0].nodeValue+"</td>"
										else
											str=str+"<td width='430' style='border-bottom:1px solid #596166;font-weight:bold'>&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='430'  style='border-bottom:1px solid #596166;'>"+outstring+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'><b>"+runsscored+"</b></td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+ballsfaced+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+playerNode.childNodes[13].childNodes[0].nodeValue+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+playerNode.childNodes[15].childNodes[0].nodeValue+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+strikerate.toFixed(2)+"</td>"
								}
								else
								{
									str=str+"<td width='430'  style='border-bottom:1px solid #596166;'>"+outstring+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'><b>"+runsscored+"</b></td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+ballsfaced+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+playerNode.childNodes[13].childNodes[0].nodeValue+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+playerNode.childNodes[15].childNodes[0].nodeValue+"</td>"
									str=str+"<td style='border-bottom:1px solid #596166;text-align:right'>"+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='10' >"
					str=str+"<td colspan='7' class='style2'>&nbsp;</td>"
					str=str+"</tr>"
					
					str=str+"<tr height='30'>"
                    
					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 style='text-align:left;color:#51ccff'><strong>Extras :</strong></td>"
                    str=str+"<td style='text-align:left'>(b "+b+", lb "+lb+", w "+w+", nb "+nb+")"
					str=str+"</td>"
                    str=str+"<td style='text-align:right; border-bottom:1px solid #596166;'><strong>"+(parseInt(b)+parseInt(lb)+parseInt(w)+parseInt(nb))+"</strong></td>"
                    str=str+"<td style='text-align:right; border-bottom:1px solid #596166;'></td>"
                    str=str+"<td style='text-align:right; border-bottom:1px solid #596166;'></td>"
                    str=str+"<td style='text-align:right; border-bottom:1px solid #596166;'></td>"
                    str=str+"<td style='text-align:right; border-bottom:1px solid #596166;'></td>"
                    str=str+"</tr>"
                    str=str+"<tr height='30'>"
                    str=str+"<td width='430' style='text-align:left;color:#51ccff'><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 style='text-align:left'>("+matchNode.childNodes[16].childNodes[9].childNodes[0].nodeValue+" wickets; "+convertBallsToOvers(totalballs)+" overs)</td>"
                    str=str+"<td style='text-align:right'><b>"+matchNode.childNodes[16].childNodes[7].childNodes[0].nodeValue+"</b></td>"
                    str=str+"<td colspan='4' style='text-align:center'>("+(parseFloat(matchNode.childNodes[16].childNodes[7].childNodes[0].nodeValue)*6/totalballs).toFixed(2)+" runs per over)</td>"
                    str=str+"</tr>"
					
					if(didnotbatname!="")
					{
						str=str+"<tr height='10'>"
						str=str+"<td colspan='7' style='text-align:left;'><font style='color:#51ccff'><b>Did not bat : </b></font> "+didnotbatname+"</td>"
						str=str+"</tr>"
					}

					
					str=str+"</table>"
						
					str=str+"</td>"
					str=str+"</tr>"
					
					//================== INNINGS 2 BOWLING ==============================
					str=str+"<tr>"
					str=str+"<td colspan='2'>"
					
						str=str+"<table width='80%' border='0' cellspacing='0' cellpadding='5' align='center' style='color:#ffffff; border:1px solid #42494d; border-bottom:none; margin-bottom:7px'>"
                    str=str+"<tr height='25' style='background:url(images/heading_grey_1.gif);font-weight:bold;color:#8afffe'>"
     				str=str+"<td width='290' style='text-align:left'>Bowling</td>"
                    str=str+"<td width='40' style='border-right:1px solid #000000;text-align:right'>O</td>"
                    str=str+"<td width='40' style='border-right:1px solid #000000;text-align:right'>M</td>"
                    str=str+"<td width='40' style='border-right:1px solid #000000;text-align:right'>R</td>"
                    str=str+"<td width='40' style='border-right:1px solid #000000;text-align:right'>W</td>"
                    str=str+"<td width='40' style='border-right:1px solid #000000;text-align:right'>NB</td>"
                    str=str+"<td width='40' style='border-right:1px solid #000000;text-align:right'>WB</td>"
                    str=str+"<td width='40' style='text-align:right'>Econ</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='30'>"
      							str=str+"<td style='border-bottom:1px solid #42494d;font-weight:bold'>"+playerNode.childNodes[1].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+playerNode.childNodes[19].childNodes[0].nodeValue+"</td>"
								
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+playerNode.childNodes[20].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+playerNode.childNodes[21].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+playerNode.childNodes[18].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+playerNode.childNodes[16].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+playerNode.childNodes[17].childNodes[0].nodeValue+"</td>"
                    			str=str+"<td style='border-bottom:1px solid #42494d;text-align:right'>"+econ+"</td>"
                    			str=str+"</tr>"
								
							}
							
						}
						
					}
					
					str=str+"</table>"
					
					str=str+"</td>"
					str=str+"</tr>"
						
						
					
					
					
					manofthematch=manofthematch.slice(0,-1);
					manofthematch=manofthematch.slice(0,-1);
					
					//================== PLAYER OF THE MATCH, UMPIRE & SCORER ============
					str=str+"<tr>"
					str=str+"<td colspan='2' style='background-color:#323232; border:1px solid #000000; text-align:left; font-family:Arial, Helvetica, sans-serif'>"
					
					str=str+"<table width='100%' border='0' cellspacing='0' cellpadding='5' align='center'>"
					
					str=str+"<tr height='30'>"
                    str=str+"<td width='25%' style='font-weight:bold;border-bottom:1px solid #000000;color:#51ccff'>Player of the match</td>"
					str=str+"<td width='2%' style='font-weight:bold;border-bottom:1px solid #000000'>:</td>"
					str=str+"<td width='73%' style='border-bottom:1px solid #000000'>"+manofthematch+"</td>"
					str=str+"</tr>"
					str=str+"<tr height='30'>"
                    str=str+"<td style='font-weight:bold;border-bottom:1px solid #000000;color:#51ccff'>Umpires</td>"
					str=str+"<td style='font-weight:bold;border-bottom:1px solid #000000'>:</td>"
					str=str+"<td style='border-bottom:1px solid #000000'>"+matchNode.childNodes[12].childNodes[0].nodeValue+"&nbsp;And&nbsp;"+matchNode.childNodes[13].childNodes[0].nodeValue+"</td>"
					str=str+"</tr>"
					str=str+"<tr height='30'>"
                    str=str+"<td style='font-weight:bold;color:#51ccff'>Scorer</td>"
					str=str+"<td style='font-weight:bold'>:</td>"
					str=str+"<td>"+matchNode.childNodes[15].childNodes[0].nodeValue+"</td>"
					str=str+"</tr>"
                    str=str+"</table>"
					
					str=str+"</td>"
					str=str+"</tr>"
					str=str+"</table>"
					
					if(typ==1)
					{
						str=str+"<div class='back'><span onclick='matchdetailtoschedule()'>&laquo; Back</span></div>"
					}
					else if(typ==2)
					{
						str=str+"<div class='back'><span onclick='matchdetailtoscore()'>&laquo; Back</span></div>"
					}
                    else if(typ==3)
					{
						str=str+"<div class='back'><span onclick='matchdetailtosingleschedule()'>&laquo; Back</span></div>"
					}
					
				
					}
					catch(e)
					{
						
						str=str+"<table width='670' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:15px;'>"
						str=str+"<tr height='30'>"
                    	str=str+"<td class='style2'>An error occured while loading the page.</td>"
						str=str+"</tr>"
						str=str+"</table>"
					}
					finally
					{
						document.getElementById("toparea2").style.display="none";
						document.getElementById("toparea2").innerHTML="";
						document.getElementById("toparea3").innerHTML="";
						document.getElementById("toparea4").innerHTML=str;
					
						$.unblockUI();
						strmatchdetail=str;
						
					}
					
				}
				
				
			}
		}
		objRequest.send('mid='+matchid+'&tid='+tournamentid);
	}
}

