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+"<div id='header' style='background-color:#000000; height:30px;width:528px;margin: 20px 0px 0px 12px;padding-bottom:5px;' >";
					//str=str+"<div class='caption1'>"+document.getElementById("txttournament").value+" > "+document.getElementById("txtgroup").value+" > "+clubname+"</div>";
					//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='600' border='0' cellspacing='0' cellpadding='0' align='center' style='text-align:center; margin-bottom:20px;' class='sortable'>";
					str=str+"<thead>";
					str=str+"<tr><td colspan='13' height='24' align='left' style='color:#000000;background-image:url(image/group-header-bg.png); border:1px solid #000000; text-align:center;'><b>Batting Statistics</b></td></tr>";
					str=str+"<tr height='35' style='color: #FFCC00; font-weight:bold; background-color:#000;'>";
					str=str+"<th width='200' style='text-align:left; border:1px solid #000;'>Name</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>M</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>I</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>NO</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>R</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>HS</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>BF</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>Avg</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>100</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>50</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>S/R</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>Ct</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>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 totinnings=battingNode.childNodes[j+1].childNodes[0].nodeValue;
								
								
								str=str+"<tr height='20'>";
								str=str+"<td style='text-align:left; border:1px solid #000; color:#CCCCCC; font-weight:bold'>"+pname+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j].childNodes[0].nodeValue+"</td>";
								if(totinnings>0)
								{
									str=str+"<td style='border:1px solid #000;'>"+totinnings+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+2].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+3].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+4].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+5].childNodes[0].nodeValue+"</td>";
									if(battingNode.childNodes[j+6].childNodes.length>0)
									{
										str=str+"<td style='border:1px solid #000;'>"+parseFloat(battingNode.childNodes[j+6].childNodes[0].nodeValue).toFixed(2)+"</td>";
									}
									else
									{
										str=str+"<td style='border:1px solid #000;'>-</td>";	
									}
									
									str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+7].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+8].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+parseFloat(battingNode.childNodes[j+9].childNodes[0].nodeValue).toFixed(2)+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+10].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+11].childNodes[0].nodeValue+"</td>";
								}
								else
								{
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";								
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</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='20'>";
								str=str+"<td style='text-align:left; border:1px solid #000; color:#CCCCCC; font-weight:bold'>"+pname+"</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"</tr>";
							
						}
						
					}
					str=str+"</tbody>";
					str=str+"</table>";
					
					str=str+"<table width='600' border='0' cellspacing='0' cellpadding='0' align='center' style='text-align:center; margin-bottom:10px;' class='sortable'>";
					str=str+"<thead>";
					str=str+"<tr><td colspan='13' height='24' align='left' style='color:#000000;background-image:url(image/group-header-bg.png); border:1px solid #000000; text-align:center;'><b>Bowling Statistics</b></td></tr>";
					str=str+"<tr height='35' style='color: #FFCC00; font-weight:bold; background-color:#000;'>";
					str=str+"<th width='200' style='text-align:left;border:1px solid #000;'>Name</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>M</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>I</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>O</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>R</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>Wkt</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>M</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>BB</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>Avg</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>Econ</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>S/R</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>3W</th>";
					str=str+"<th width='33' style='border:1px solid #000;'>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='20'>";
								str=str+"<td style='text-align:left; border:1px solid #000; color:#CCCCCC; font-weight:bold'>"+pname+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j].childNodes[0].nodeValue+"</td>";
								if(totinnings>0)
								{
									
									str=str+"<td style='border:1px solid #000;'>"+totinnings+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+convertBallsToOvers(bowlingNode.childNodes[j+2].childNodes[0].nodeValue)+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+3].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+4].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+5].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+6].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+parseFloat(bowlingNode.childNodes[j+7].childNodes[0].nodeValue).toFixed(2)+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+parseFloat(bowlingNode.childNodes[j+8].childNodes[0].nodeValue).toFixed(2)+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+parseFloat(bowlingNode.childNodes[j+9].childNodes[0].nodeValue).toFixed(2)+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+10].childNodes[0].nodeValue+"</td>";
									str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+11].childNodes[0].nodeValue+"</td>";
								}
								else
								{
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</td>";
									str=str+"<td style='border:1px solid #000;'>-</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='20'>";
								str=str+"<td style='text-align:left; border:1px solid #000; color:#CCCCCC; font-weight:bold'>"+pname+"</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</td>";
								str=str+"<td style='border:1px solid #000;'>-</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+"<table width='600' border='0' cellspacing='0' cellpadding='0' style='text-align:left;'><tr height='14'>";
					 strtitle=strtitle+"<td width='15' bgcolor='#69c6c7'>&nbsp;</td>";
					 strtitle=strtitle+"<td width='125' align='center'><strong>Team Statistics</strong></td>";
					 strtitle=strtitle+"<td width='460' background='image/line.jpg'>&nbsp;</td>";
					 strtitle=strtitle+"</tr></table>";
					 //document.getElementById("topindex").style.display="none";
					 document.getElementById("toparea1").innerHTML=strtitle;
					 document.getElementById("toparea3").innerHTML=str;
					 standardistaTableSortingInit();
					 $.unblockUI();
					//strgetprofilelabel=strtitle;
					//strgetprofile=str;
				}
			}
		}
		objRequest.send('cid='+cid+'&tid='+tid);
	}
}

