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 getteamstat(cid,tid,clubname)
{
	
	$.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","teamstat.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 playerNode=doc.documentElement;
				if(playerNode)
				{
					
					var allPlayersNode=playerNode.getElementsByTagName("id");
					
					var str="";
					
					str=str+" <table width='670' border='0' cellspacing='0' cellpadding='0' style='margin:10px 0 1px 10px; border:1px solid #666666'><tr height='25' bgcolor='#666666'><td style='color:#ffffff; font-weight:bold'>&nbsp;&nbsp;"+fromsession+" - "+tosession+" > "+document.getElementById("txttournament").value+" > "+document.getElementById("txtgroup").value+" > "+clubname+"</td></tr></table>";
					
					
					
					
				
					str=str+"</div><br/>";
					
					str=str+"<div style='text-align:right; margin:0 7px 7px 0; font-weight:bold;' ><span style='cursor:pointer' onclick='getprofiletoshowplayers()'>Back</span></div>"
							
						
					str=str+"<table width='670' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:0px; text-align:center;border:1px solid #B2B3B5;' class='sortable'>";
					str=str+"<thead>";
					str=str+"<tr height='30'><td bgcolor='#7A8289' colspan='13' style='color:#FFFFFF; font-size:14px; font-weight:bold'>Batting Statistics</td></tr>";
					str=str+"<tr height='25' bgcolor='#BDBEC0'>"
					str=str+"<th width='260' class='style3' style='border-bottom:1px solid #333333'>Name</th>";
					str=str+"<th width='30' class='style3' style='border-bottom:1px solid #333333'>M</th>";
					str=str+"<th width='30' class='style3' style='border-bottom:1px solid #333333'>I</th>";
					str=str+"<th width='30' class='style3' style='border-bottom:1px solid #333333'>NO</th>";
					str=str+"<th width='35' class='style3' style='border-bottom:1px solid #333333'>R</th>";
					str=str+"<th width='35' class='style3' style='border-bottom:1px solid #333333'>HS</th>";
					str=str+"<th width='35' class='style3' style='border-bottom:1px solid #333333'>BF</th>";
					str=str+"<th width='45' class='style3' style='border-bottom:1px solid #333333'>Avg</th>";
					str=str+"<th width='35' class='style3' style='border-bottom:1px solid #333333'>100</th>";
					str=str+"<th width='30' class='style3' style='border-bottom:1px solid #333333'>50</th>";
					str=str+"<th width='45' class='style3' style='border-bottom:1px solid #333333'>S/R</th>";
					str=str+"<th width='30' class='style3' style='border-bottom:1px solid #333333'>Ct</th>";
					str=str+"<th width='30' class='style3' style='border-bottom:1px solid #333333'>St</th>";
					str=str+"</tr>";
					str=str+"</thead>";
					
					str=str+"<tbody>";
					for(i=0;i<allPlayersNode.length;i++)
					{
						var pnameNode=allPlayersNode[i].nextSibling;
						var pname=pnameNode.childNodes[0].nodeValue;
						var debutNode=pnameNode.nextSibling;
						var debut=debutNode.childNodes[0].nodeValue;
						if(debut!="0")
						{
							var battingNode=debutNode.nextSibling;
							var bowlingNode=battingNode.nextSibling;
							for(j=0;j<battingNode.childNodes.length;j=j+13)
							{
								var totmatches
								var totinnings
								
								if(battingNode.childNodes[j].childNodes[0])
								{
									totmatches=battingNode.childNodes[j].childNodes[0].nodeValue;
								}
								else
								{
									totmatches="-"
								}
								
								if(battingNode.childNodes[j+1].childNodes[0])
								{
									totinnings=battingNode.childNodes[j+1].childNodes[0].nodeValue;
								}
								else
								{
									totinnings=0;
								}
								
								
								
								str=str+"<tr height='25'>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+pname+"</td>";
								
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+totmatches+"</td>";
								
								if(totinnings>0)
								{
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+totinnings+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+battingNode.childNodes[j+2].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+battingNode.childNodes[j+3].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+battingNode.childNodes[j+4].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+battingNode.childNodes[j+5].childNodes[0].nodeValue+"</td>";
									if(battingNode.childNodes[j+6].childNodes.length>0)
									{
										str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+parseFloat(battingNode.childNodes[j+6].childNodes[0].nodeValue).toFixed(2)+"</td>";
									}
									else
									{
										str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";	
									}
									
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+battingNode.childNodes[j+7].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+battingNode.childNodes[j+8].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+parseFloat(battingNode.childNodes[j+9].childNodes[0].nodeValue).toFixed(2)+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+battingNode.childNodes[j+10].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+battingNode.childNodes[j+11].childNodes[0].nodeValue+"</td>";
								}
								else
								{
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";								
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								}
								
								
								str=str+"</tr>";
							}
							
						}
						
					}
					
					for(i=0;i<allPlayersNode.length;i++)
					{
						var pnameNode=allPlayersNode[i].nextSibling;
						var pname=pnameNode.childNodes[0].nodeValue;
						var debutNode=pnameNode.nextSibling;
						var debut=debutNode.childNodes[0].nodeValue;
						if(debut=="0")
						{
								str=str+"<tr height='25'>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+pname+"</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"</tr>";
							
						}
						
					}
					str=str+"</tbody>";
					str=str+"</table><br/>";
					
					
					
					str=str+"<table width='670' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:0px; text-align:center;border:1px solid #B2B3B5;' class='sortable'>";
					str=str+"<thead>";
					str=str+"<tr height='30'><td bgcolor='#7A8289' colspan='13' style='color:#FFFFFF; font-size:14px; font-weight:bold'>Bowling Statistics</td></tr>";
					str=str+"<tr height='25' bgcolor='#BDBEC0'>"

					str=str+"<th width='265' class='style3' style='border-bottom:1px solid #333333'>Name</th>";
					str=str+"<th width='20' class='style3' style='border-bottom:1px solid #333333'>M</th>";
					str=str+"<th width='20' class='style3' style='border-bottom:1px solid #333333'>I</th>";
					str=str+"<th width='35' class='style3' style='border-bottom:1px solid #333333'>O</th>";
					str=str+"<th width='35' class='style3' style='border-bottom:1px solid #333333'>R</th>";
					str=str+"<th width='30' class='style3' style='border-bottom:1px solid #333333'>Wkt</th>";
					str=str+"<th width='20' class='style3' style='border-bottom:1px solid #333333'>M</th>";
					str=str+"<th width='50' class='style3' style='border-bottom:1px solid #333333'>BB</th>";
					str=str+"<th width='45' class='style3' style='border-bottom:1px solid #333333'>Avg</th>";
					str=str+"<th width='45' class='style1'>Econ</th>";
					str=str+"<th width='45' class='style3' style='border-bottom:1px solid #333333'>S/R</th>";
					str=str+"<th width='30' class='style3' style='border-bottom:1px solid #333333'>3W</th>";
					str=str+"<th width='30' class='style3' style='border-bottom:1px solid #333333'>5W</th>";
					str=str+"</tr>";
					str=str+"</thead>";
					
					str=str+"<tbody>";
					for(i=0;i<allPlayersNode.length;i++)
					{
						var pnameNode=allPlayersNode[i].nextSibling;
						var pname=pnameNode.childNodes[0].nodeValue;
						var debutNode=pnameNode.nextSibling;
						var debut=debutNode.childNodes[0].nodeValue;
						if(debut!="0")
						{
							var battingNode=debutNode.nextSibling;
							var bowlingNode=battingNode.nextSibling;
							for(j=0;j<bowlingNode.childNodes.length;j=j+13)
							{
								var totinnings=bowlingNode.childNodes[j+1].childNodes[0].nodeValue;
								
								str=str+"<tr height='25'>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+pname+"</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+bowlingNode.childNodes[j].childNodes[0].nodeValue+"</td>";
								if(totinnings>0)
								{
									
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+totinnings+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+convertBallsToOvers(bowlingNode.childNodes[j+2].childNodes[0].nodeValue)+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+bowlingNode.childNodes[j+3].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+bowlingNode.childNodes[j+4].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+bowlingNode.childNodes[j+5].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+bowlingNode.childNodes[j+6].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+parseFloat(bowlingNode.childNodes[j+7].childNodes[0].nodeValue).toFixed(2)+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+parseFloat(bowlingNode.childNodes[j+8].childNodes[0].nodeValue).toFixed(2)+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+parseFloat(bowlingNode.childNodes[j+9].childNodes[0].nodeValue).toFixed(2)+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+bowlingNode.childNodes[j+10].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+bowlingNode.childNodes[j+11].childNodes[0].nodeValue+"</td>";
								}
								else
								{
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								}
								
								str=str+"</tr>";
							}
							
						}
						
					}
					for(i=0;i<allPlayersNode.length;i++)
					{
						var pnameNode=allPlayersNode[i].nextSibling;
						var pname=pnameNode.childNodes[0].nodeValue;
						var debutNode=pnameNode.nextSibling;
						var debut=debutNode.childNodes[0].nodeValue;
						if(debut=="0")
						{
							var battingNode=debutNode.nextSibling;
							var bowlingNode=battingNode.nextSibling;
							
								str=str+"<tr height='25'>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+pname+"</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>-</td>";
								str=str+"</tr>";
						}
						
					}
					 str=str+"</tbody>";
					 str=str+"</table>";
					 
					 str=str+"<div style='text-align:right; margin:0 7px 7px 0; font-weight:bold;' ><span style='cursor:pointer' onclick='getprofiletoshowplayers()'>Back</span></div>"
					 
					 var strtitle="";
					
					 
					 strtitle=strtitle+"&nbsp;<font color='#990000'><em>Team Statistics</em></font>&nbsp;";
					 
					 //document.getElementById("topindex").style.display="none";
					 //document.getElementById("toparea1").innerHTML=strtitle;
					 //document.getElementById("toparea3").innerHTML=str;
					
					 document.getElementById("toparea1").innerHTML=strtitle;
					 document.getElementById("toparea2").style.display="none";
					 document.getElementById("toparea2").innerHTML="";
					 document.getElementById("toparea3").innerHTML="";
					 document.getElementById("toparea4").innerHTML=str;
					 
					 standardistaTableSortingInit();
					 $.unblockUI();
					//strgetprofilelabel=strtitle;
					//strgetprofile=str;
				}
			}
		}
		objRequest.send('cid='+cid+'&tid='+tid);
	}
}

