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: '#000000', 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+"<div class='back'><span onclick='getprofiletoshowplayers()'>&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:5px; margin-bottom:7px'><tr height='25' style='background:url(images/heading_grey.gif);font-weight:bold;color:#d7fe01'><td>&nbsp;&nbsp;"+fromsession+" - "+tosession+" > "+document.getElementById("txttournament").value+" > "+document.getElementById("txtgroup").value+" > "+clubname+"</td></tr>";
					
				
					str=str+"</div>";
					
					str=str+"<tr><td><table width='100%' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:5px; text-align:center; background:url(images/heading_blue.gif);color:#FFFFFF; font-size:13px; font-weight:bold' class='sortable'>"
					str=str+"<tr height='30'>"
					str=str+"<td>Batting Statistics</td>"					
					str=str+"</tr>"
					str=str+"</table>"
					
					str=str+"<table align='center' width='100%' border='0' cellspacing='0' cellpadding='5' style='border:1px solid #596166;border-bottom:none;text-align:center;margin-top:2px'>"
     				str=str+"<tr height='25' style='background:url(images/heading_grey.gif)'>"
					str=str+"<th width='260' class='style3' style='border-right:1px solid #000000'>Name</th>";
					str=str+"<th width='30' class='style3' style='border-right:1px solid #000000'>M</th>";
					str=str+"<th width='30' class='style3' style='border-right:1px solid #000000'>I</th>";
					str=str+"<th width='30' class='style3' style='border-right:1px solid #000000'>NO</th>";
					str=str+"<th width='35' class='style3' style='border-right:1px solid #000000'>R</th>";
					str=str+"<th width='35' class='style3' style='border-right:1px solid #000000'>HS</th>";
					str=str+"<th width='35' class='style3' style='border-right:1px solid #000000'>BF</th>";
					str=str+"<th width='45' class='style3' style='border-right:1px solid #000000'>Avg</th>";
					str=str+"<th width='35' class='style3' style='border-right:1px solid #000000'>100</th>";
					str=str+"<th width='30' class='style3' style='border-right:1px solid #000000'>50</th>";
					str=str+"<th width='45' class='style3' style='border-right:1px solid #000000'>S/R</th>";
					str=str+"<th width='30' class='style3' style='border-right:1px solid #000000'>Ct</th>";
					str=str+"<th width='30' class='style3'>St</th>";
					str=str+"</tr>";
					
					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 #596166; font-weight:bold'>"+pname+"</td>";
								
								str=str+"<td style='border-bottom:1px solid #596166;'>"+totmatches+"</td>";
								
								if(totinnings>0)
								{
									str=str+"<td style='border-bottom:1px solid #596166;'>"+totinnings+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+battingNode.childNodes[j+2].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+battingNode.childNodes[j+3].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+battingNode.childNodes[j+4].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+battingNode.childNodes[j+5].childNodes[0].nodeValue+"</td>";
									if(battingNode.childNodes[j+6].childNodes.length>0)
									{
										str=str+"<td style='border-bottom:1px solid #596166;'>"+parseFloat(battingNode.childNodes[j+6].childNodes[0].nodeValue).toFixed(2)+"</td>";
									}
									else
									{
										str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";	
									}
									
									str=str+"<td style='border-bottom:1px solid #596166;'>"+battingNode.childNodes[j+7].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+battingNode.childNodes[j+8].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+parseFloat(battingNode.childNodes[j+9].childNodes[0].nodeValue).toFixed(2)+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+battingNode.childNodes[j+10].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+battingNode.childNodes[j+11].childNodes[0].nodeValue+"</td>";
								}
								else
								{
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";								
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</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 #596166;'>"+pname+"</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"</tr>";
							
						}
						
					}
					str=str+"</tbody>";
					str=str+"</table><br/>";
					
					
					
					str=str+"<tr><td><table width='100%' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:5px; text-align:center; background:url(images/heading_blue.gif);color:#FFFFFF; font-size:13px; font-weight:bold' class='sortable'>"
					str=str+"<tr height='30'>"
					str=str+"<td>Bowling Statistics</td>"					
					str=str+"</tr>"
					str=str+"</table>"
					
					str=str+"<table align='center' width='100%' border='0' cellspacing='0' cellpadding='5' style='border:1px solid #596166;border-bottom:none;text-align:center;margin-top:2px'>"
     				str=str+"<tr height='25' style='background:url(images/heading_grey.gif)'>"
					str=str+"<th width='265' class='style3' style='border-right:1px solid #000000'>Name</th>";
					str=str+"<th width='20' class='style3' style='border-right:1px solid #000000'>M</th>";
					str=str+"<th width='20' class='style3' style='border-right:1px solid #000000'>I</th>";
					str=str+"<th width='35' class='style3' style='border-right:1px solid #000000'>O</th>";
					str=str+"<th width='35' class='style3' style='border-right:1px solid #000000'>R</th>";
					str=str+"<th width='30' class='style3' style='border-right:1px solid #000000'>Wkt</th>";
					str=str+"<th width='20' class='style3' style='border-right:1px solid #000000'>M</th>";
					str=str+"<th width='50' class='style3' style='border-right:1px solid #000000'>BB</th>";
					str=str+"<th width='45' class='style3' style='border-right:1px solid #000000'>Avg</th>";
					str=str+"<th width='45' class='style1' style='border-right:1px solid #000000'>Econ</th>";
					str=str+"<th width='45' class='style3' style='border-right:1px solid #000000'>S/R</th>";
					str=str+"<th width='30' class='style3' style='border-right:1px solid #000000'>3W</th>";
					str=str+"<th width='30' class='style3'>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 #596166;font-weight:bold'>"+pname+"</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>"+bowlingNode.childNodes[j].childNodes[0].nodeValue+"</td>";
								if(totinnings>0)
								{
									
									str=str+"<td style='border-bottom:1px solid #596166;'>"+totinnings+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+convertBallsToOvers(bowlingNode.childNodes[j+2].childNodes[0].nodeValue)+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+bowlingNode.childNodes[j+3].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+bowlingNode.childNodes[j+4].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+bowlingNode.childNodes[j+5].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+bowlingNode.childNodes[j+6].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+parseFloat(bowlingNode.childNodes[j+7].childNodes[0].nodeValue).toFixed(2)+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+parseFloat(bowlingNode.childNodes[j+8].childNodes[0].nodeValue).toFixed(2)+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+parseFloat(bowlingNode.childNodes[j+9].childNodes[0].nodeValue).toFixed(2)+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+bowlingNode.childNodes[j+10].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>"+bowlingNode.childNodes[j+11].childNodes[0].nodeValue+"</td>";
								}
								else
								{
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
									str=str+"<td style='border-bottom:1px solid #596166;'>-</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 #596166;'>"+pname+"</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"<td style='border-bottom:1px solid #596166;'>-</td>";
								str=str+"</tr>";
						}
						
					}
					 str=str+"</tbody>";
					 str=str+"</table>";
					 
					 str=str+"<div class='back'><span onclick='getprofiletoshowplayers()'>&laquo; Back</span></div>"
					 
					 var strtitle="";
					
					 
					 strtitle=strtitle+"&nbsp;<font color='#ffffff'><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;
					str=str+"</td></tr></table>"
				}
			}
		}
		objRequest.send('cid='+cid+'&tid='+tid);
	}
}

