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 getGroups(id)
{
	
	//document.getElementById("tcaption").innerHTML=document.getElementById("txttournament").value+"<br/> As on 10.03.2009";
	$.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","group.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 groupsNode=doc.documentElement;
				if(groupsNode)
				{
					var str="";
					str="<br/><br/>"
					var groupNode=groupsNode.getElementsByTagName("group");
					
					/*str=str+"<div id='header' style='background-color:#000000; height:50px;width:528px;margin: 20px 0px 0px 12px;padding-bottom:5px;'>";
					str=str+"<div class='caption1'>"+document.getElementById("txttournament").value+" <br/> As on 16.03.2009</div>";
					str=str+"</div><br/>";*/
					
					var trophynameNode=groupsNode.getElementsByTagName("trophyname");
					for(var p=0;p<trophynameNode.length;p++)
					{
						//if(trophynameNode[p].childNodes[0].nodeValue=="Gold") 
						//{
							if(trophynameNode[p].childNodes.length>1) //if QF or SF or Final is defined
							{
								
								str=str+"<table width='600' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:0px; text-align:center;'>"
								str=str+"<tr height='24'>"
								str=str+"<td colspan='5' style='color:#000000;font-weight:bold;background-image:url(image/group-header-bg.png);'>"+trophynameNode[p].childNodes[0].nodeValue+" Cup Lineup</td>"
								//str=str+"<td width='40' style='color:#000000;background-image:url(image/group-header-bg.png);'><img src='image/gold.jpg' height='24' border='0' />&nbsp;</td>"
								//str=str+"<td width='480' colspan='4' style='color:#000000;font-weight:bold;background-image:url(image/group-header-bg.png);'>"+trophynameNode[p].childNodes[0].nodeValue+" Cup Lineup</td>"
								str=str+"</tr>"
								str=str+"</table>"
								
								str=str+"<table width='600' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:0px; text-align:center;' bgcolor='#333944'>"
								str=str+"<tr height='30' style='color: #FFCC66; font-weight:bold;'>"
								str=str+"<td width='40' >Sl. No.</td>"
								str=str+"<td width='100' >Groups</td>"
								str=str+"<td width='460' colspan='3' align='center' >Teams</td>"
								str=str+"</tr>"
								if(trophynameNode[p].getElementsByTagName("QF").length>0) // If QF is defined
								{

									for(var q=0;q<trophynameNode[p].getElementsByTagName("QF").length;q++)
									{
										var qfNode=trophynameNode[p].getElementsByTagName("QF")[q];
										str=str+"<tr height='24'>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+qfNode.childNodes[0].childNodes[0].nodeValue+"</td>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+qfNode.childNodes[1].childNodes[0].nodeValue+" Vs. "+qfNode.childNodes[2].childNodes[0].nodeValue+"</td>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;width:200px'>&nbsp;"+qfNode.childNodes[3].childNodes[0].nodeValue+"</td>"
										//str=str+"<td style='border:1px solid #000;color:#ffffff;width:200px'>&nbsp;</td>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;width:60px'>&nbsp;Vs.</td>"
										//str=str+"<td style='border:1px solid #000;color:#ffffff;width:60px'>&nbsp;</td>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;width:200px'>&nbsp;"+qfNode.childNodes[4].childNodes[0].nodeValue+"</td>"
										//str=str+"<td style='border:1px solid #000;width:200px'>&nbsp;</td>"
										str=str+"</tr>"
									}
									if(trophynameNode[p].getElementsByTagName("SF").length==0) // if SF is not defined then end the table
									{
										str=str+"</table><br />"
									}
									
								}
								if(trophynameNode[p].getElementsByTagName("SF").length>0) // If SF is defined
								{
									
									
									for(var q=0;q<trophynameNode[p].getElementsByTagName("SF").length;q++)
									{
										var sfNode=trophynameNode[p].getElementsByTagName("SF")[q];
										str=str+"<tr height='24'>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+sfNode.childNodes[0].childNodes[0].nodeValue+"</td>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+sfNode.childNodes[1].childNodes[0].nodeValue+" Vs. "+sfNode.childNodes[2].childNodes[0].nodeValue+"</td>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;width:200px'>&nbsp;"+sfNode.childNodes[3].childNodes[0].nodeValue+"</td>"
										//str=str+"<td style='border:1px solid #000;color:#ffffff;width:200px'>&nbsp;</td>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;width:60px'>&nbsp;Vs.</td>"
										//str=str+"<td style='border:1px solid #000;color:#ffffff;width:60px'>&nbsp;</td>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;width:200px'>&nbsp;"+sfNode.childNodes[4].childNodes[0].nodeValue+"</td>"
										//str=str+"<td style='border:1px solid #000;width:200px'>&nbsp;</td>"
										str=str+"</tr>"
									}
									if(trophynameNode[p].getElementsByTagName("FINAL").length==0)
									{
										str=str+"</table><br />" // If FINAL is not defined then end the table
									}
									
								
								}
								if(trophynameNode[p].getElementsByTagName("FINAL").length>0) // If Final is defined
								{
									
									
									for(var q=0;q<trophynameNode[p].getElementsByTagName("FINAL").length;q++)
									{
										var fNode=trophynameNode[p].getElementsByTagName("FINAL")[q];
										str=str+"<tr height='24'>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+fNode.childNodes[0].childNodes[0].nodeValue+"</td>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+fNode.childNodes[1].childNodes[0].nodeValue+" Vs. "+fNode.childNodes[2].childNodes[0].nodeValue+"</td>"
										
										str=str+"<td style='border:1px solid #000;color:#ffffff;width:200px'>&nbsp;"+fNode.childNodes[3].childNodes[0].nodeValue+"</td>"
										//str=str+"<td style='border:1px solid #000;color:#ffffff;width:200px'>&nbsp;</td>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;width:60px'>&nbsp;Vs.</td>"
										//str=str+"<td style='border:1px solid #000;color:#ffffff;width:60px'>&nbsp;</td>"
										str=str+"<td style='border:1px solid #000;color:#ffffff;width:200px'>&nbsp;"+fNode.childNodes[4].childNodes[0].nodeValue+"</td>"
										//str=str+"<td style='border:1px solid #000;color:#ffffff;width:200px'>&nbsp;</td>"
										str=str+"</tr>"
									}
									str=str+"</table><br />"
								
								}
								
							}
							
						str=str+"<br />";
					}
					str=str+"<div style='background-color:#002443; height:18px;width:600px;margin: 0px 0px 0px 0px;padding-bottom:3px;'>";
					str=str+"<div class='caption1' style='color:#ffffff;'> LEAGUE STAGE</div>";
					str=str+"</div><br/>"
					
					for(var i=0;i<groupNode.length;i++)
					{
						var idNode=groupNode[i].firstChild;
						var gid=idNode.childNodes[0].nodeValue;
						
						var groupnameNode=idNode.nextSibling;
						var groupname=groupnameNode.childNodes[0].nodeValue;
						var clubNode=groupnameNode.childNodes[0].nextSibling;
						var tournamentidnode=groupnameNode.nextSibling;
						var tournamentid=tournamentidnode.childNodes[0].nodeValue;
						
						var cnt=clubNode.childNodes.length;
						var clubidNode;
						var clubid;
						var clubnameNode;
						var clubname;
						var matchplayedNode;
						var matchplayed;
						var matchwonNode;
						var matchwon;
						var matchlostNode;
						var matchlost;
						var matchdrawnNode;
						var matchdrawn;
						var matchnoresultNode;
						var matchnoresult;
						var matchpointNode;
						var matchpoint;
						
						//var arr=new Array();
						
						
						
						str=str+"<table width='600px' border='0' cellspacing='0' cellpadding='0' align='center' style='text-align:Center;'>"
                        str=str+"<tr id='"+gid+"' onclick='setValue(\"Group "+groupname+"\",2);showClub(this.id);' style='cursor:pointer'>"
                        str=str+"<td class='group-header'><div class='arrow' id='div"+gid+"'></div>Group "+groupname+"</td>"
                        str=str+"</tr>"
                        str=str+"</table><br>"
						str=str+"<table width='600px' id='table"+gid+"' border='0' cellspacing='0' cellpadding='0' align='center' style='text-align:Center;' bgcolor='#333944'>"
						if(cnt>0)
						{
							str=str+"<tr height='24'>"
							str=str+"<td style='color: #ffcc66; width:300px;'>Team Name</td>"
                        	str=str+"<td style='width:50px;color: #ffcc66;'>M</td>"
                        	str=str+"<td style='width:50px;color: #ffcc66;'>W</td>"
                        	str=str+"<td style='width:50px;color: #ffcc66;'>L</td>"
                        	//str=str+"<td style='width:50px;color: #ffcc66;'>D</td>"
                        	str=str+"<td style='width:50px;color: #ffcc66;'>N/R</td>"
                        	str=str+"<td style='width:50px;color: #ffcc66;'>P</td>"
							str=str+"<td style='width:50px;color: #ffcc66;'>R/R</td>"
							str=str+"</tr>"
							var isOddRow=true
							
							for(var j=0;j<clubNode.childNodes.length;j=j+9)
							{						
								var color=""							
								clubidNode=clubNode.childNodes[j];
								clubid=clubidNode.childNodes[0].nodeValue;
								clubnameNode=clubidNode.nextSibling
								clubname=clubnameNode.childNodes[0].nodeValue;
								matchplayedNode=clubnameNode.nextSibling;
								matchplayed=matchplayedNode.childNodes[0].nodeValue;
								matchwonNode=matchplayedNode.nextSibling;
								matchwon=matchwonNode.childNodes[0].nodeValue;
								matchlostNode=matchwonNode.nextSibling;
								matchlost=matchlostNode.childNodes[0].nodeValue;
								matchdrawnNode=matchlostNode.nextSibling;
								matchdrawn=matchdrawnNode.childNodes[0].nodeValue;
								matchnoresultNode=matchdrawnNode.nextSibling;
								matchnoresult=matchnoresultNode.childNodes[0].nodeValue;

								matchpointNode=matchnoresultNode.nextSibling;
								matchpoint=matchpointNode.childNodes[0].nodeValue;
								netrunrateNode=matchpointNode.nextSibling;
								netrunrate=netrunrateNode.childNodes[0].nodeValue;
								
								if(matchplayed>0)
								{
									if(isOddRow)
									{
										color="style='background-color:#000000;'"
									}
									str=str+"<tr height='24' "+color+">"
									str=str+"<td style='font-weight: bold;color:#ffffff;'><span style='text-decoration:underline;cursor:pointer' onclick='showSingleSchedule("+clubid+","+tournamentid+")'>"+clubname+"</span></td>"
									str=str+"<td style='width:50px;color:#ffffff;'>"+matchplayed+"</td>"
	                        		str=str+"<td style='width:50px;color:#ffffff;'>"+matchwon+"</td>"
	                        		str=str+"<td style='width:50px;color:#ffffff;'>"+matchlost+"</td>"
	                        		//str=str+"<td style='width:50px;'>"+matchdrawn+"</td>"
	                        		str=str+"<td style='width:50px;color:#ffffff;'>"+matchnoresult+"</td>"
	                        		str=str+"<td style='width:50px;color:#ffffff;'>"+matchpoint+"</td>"
									str=str+"<td style='width:50px;color:#ffffff;'>"+netrunrate+"</td>"
									str=str+"</tr>"
									
									isOddRow=!isOddRow
								}
								
							}
							
							
							for(var j=0;j<clubNode.childNodes.length;j=j+9)
							{						
								var color=""							
								clubidNode=clubNode.childNodes[j];
								clubid=clubidNode.childNodes[0].nodeValue;
								clubnameNode=clubidNode.nextSibling
								clubname=clubnameNode.childNodes[0].nodeValue;
								matchplayedNode=clubnameNode.nextSibling;
								matchplayed=matchplayedNode.childNodes[0].nodeValue;
								matchwonNode=matchplayedNode.nextSibling;
								matchwon=matchwonNode.childNodes[0].nodeValue;
								matchlostNode=matchwonNode.nextSibling;
								matchlost=matchlostNode.childNodes[0].nodeValue;
								matchdrawnNode=matchlostNode.nextSibling;
								matchdrawn=matchdrawnNode.childNodes[0].nodeValue;
								matchnoresultNode=matchdrawnNode.nextSibling;
								matchnoresult=matchnoresultNode.childNodes[0].nodeValue;
								matchpointNode=matchnoresultNode.nextSibling;
								matchpoint=matchpointNode.childNodes[0].nodeValue;
								netrunrateNode=matchpointNode.nextSibling;
								netrunrate=netrunrateNode.childNodes[0].nodeValue;
								
								if(matchplayed==0)
								{
									if(isOddRow)
									{
										color="style='background-color:#000000;'"
									}
									str=str+"<tr height='24' "+color+">"
									
									str=str+"<td style='font-weight: bold;color:#ffffff;'><span style='text-decoration:underline;cursor:pointer' onclick='showSingleSchedule("+clubid+","+tournamentid+")'>"+clubname+"</span></td>"
									str=str+"<td style='width:50px;color:#ffffff;'>"+matchplayed+"</td>"
	                        		str=str+"<td style='width:50px;color:#ffffff;'>"+matchwon+"</td>"
	                        		str=str+"<td style='width:50px;color:#ffffff;'>"+matchlost+"</td>"
	                        		//str=str+"<td style='width:50px;'>"+matchdrawn+"</td>"
	                        		str=str+"<td style='width:50px;color:#ffffff;'>"+matchnoresult+"</td>"
	                        		str=str+"<td style='width:50px;color:#ffffff;'>"+matchpoint+"</td>"
									str=str+"<td style='width:50px;color:#ffffff;'>"+netrunrate+"</td>"
									str=str+"</tr>"
									
									isOddRow=!isOddRow
								}
								
							}
														
						}

						else
						{
							str=str+"<tr height='24'>"
							str=str+"<td style='font-weight: bold;' colspan='8'>There is no club in this group. </td>"
                        	str=str+"</tr>"
						}
						
                        
						str=str+"</table><br />"					
					}
					//document.getElementById("topindex").style.display="none";
					document.getElementById("toparea3").innerHTML=str;
					
					$.unblockUI();
					strgroups=str;
				}
			}
		}
		objRequest.send('tid='+id);
	}
}
