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 getScores(id)
{	
	
	$.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","scores.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 scheduleNode=doc.documentElement;
				if(scheduleNode)
				{
					var str="<br/><br/>";
					//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+"</div>";
					//str=str+"</div><br/>";
					
					var FNNode=scheduleNode.getElementsByTagName("FINAL");
					if(FNNode[0].childNodes.length>0) // If Final has been created 
					{
						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;border:1px solid #d6d6d6;background-image:url(image/group-header-bg.png);'>FINALS</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' bgcolor='#333944' style='color: #FFCC66; font-weight:bold;'>"
      					str=str+"<td width='40' >Cup</td>"
      					str=str+"<td width='160' >Teams</td>"
						str=str+"<td width='80' >Date</td>"
      					str=str+"<td width='80' >Timing (Hrs.)</td>"
      					str=str+"<td width='80' >Venue</td>"
      					str=str+"<td width='160' >Result</td>"
     					str=str+"</tr>"
						for(var m=0;m<FNNode[0].childNodes.length;m=m+11)
						{
							str=str+"<tr height='65'>"
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+FNNode[0].childNodes[m].childNodes[0].nodeValue+"</td>"
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+FNNode[0].childNodes[m+4].childNodes[0].nodeValue+"<br /> vs. <br />"+FNNode[0].childNodes[m+5].childNodes[0].nodeValue+"</td>"
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+FNNode[0].childNodes[m+1].childNodes[0].nodeValue+"</td>"
							
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+FNNode[0].childNodes[m+2].childNodes[0].nodeValue+"<br /> to <br />"+FNNode[0].childNodes[m+3].childNodes[0].nodeValue+"</td>"
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+FNNode[0].childNodes[m+9].childNodes[0].nodeValue+"</td>"
							matchid=FNNode[0].childNodes[m+10].childNodes[0].nodeValue
							tournamentid=id;
							if(FNNode[0].childNodes[m+6].childNodes.length>0) // if result is not null
							{
																
								if(FNNode[0].childNodes[m+6].childNodes[0].nodeValue=="R") // if result is win
								{
									if(FNNode[0].childNodes[m+7].childNodes.length>0 && FNNode[0].childNodes[m+8].childNodes.length) // if description & won clubname is available
									{
										
										if(FNNode[0].childNodes[m+7].childNodes[0].nodeValue.toUpperCase().indexOf("WALK OVER")>=0)
										{
											str=str+"<td style='border:1px solid #000;color:#ffffff;' >"+FNNode[0].childNodes[m+8].childNodes[0].nodeValue+"<br /> won by "+FNNode[0].childNodes[m+7].childNodes[0].nodeValue+"</td>"
										}
										else
										{
											str=str+"<td style='border:1px solid #000;color:#ffffff;cursor:pointer;text-decoration:underline' onclick='showMatchDetail("+matchid+","+tournamentid+",1);'>"+FNNode[0].childNodes[m+8].childNodes[0].nodeValue+"<br /> won by "+FNNode[0].childNodes[m+7].childNodes[0].nodeValue+"</td>"
										}
										
									}
									else // if description is not available
									{
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;</td>"
									}
								}
								else // if result is draw or no result
								{
									if(FNNode[0].childNodes[m+7].childNodes.length>0) // if description is available
									{
										str=str+"<td style='border:1px solid #000;color:#ffffff;cursor:pointer;text-decoration:underline' onclick='showMatchDetail("+matchid+","+tournamentid+",1);'>&nbsp;"+FNNode[0].childNodes[m+7].childNodes[0].nodeValue+"</td>"
									}
									else // if description is not available
									{
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;</td>"
									}
								}
							}
							else // if match is not played yet
							{
								str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;</td>"
							}
							
						}
						str=str+"</table><br/>";
						
					}
					
					var SFNode=scheduleNode.getElementsByTagName("SF");
					if(SFNode[0].childNodes.length>0) // If Semi-Final has been created 
					{
						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;border:1px solid #d6d6d6;background-image:url(image/group-header-bg.png);'>SEMI FINALS</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' bgcolor='#333944' style='color: #FFCC66; font-weight:bold;'>"
      					str=str+"<td width='40' >Cup</td>"
      					str=str+"<td width='160' >Teams</td>"
						str=str+"<td width='80' >Date</td>"
      					str=str+"<td width='80' >Timing (Hrs.)</td>"
      					str=str+"<td width='80' >Venue</td>"
      					str=str+"<td width='160' >Result</td>"
     					str=str+"</tr>"
						for(var m=0;m<SFNode[0].childNodes.length;m=m+11)
						{
							str=str+"<tr height='65'>"
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+SFNode[0].childNodes[m].childNodes[0].nodeValue+"</td>"
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+SFNode[0].childNodes[m+4].childNodes[0].nodeValue+"<br /> vs. <br />"+SFNode[0].childNodes[m+5].childNodes[0].nodeValue+"</td>"
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+SFNode[0].childNodes[m+1].childNodes[0].nodeValue+"</td>"
							
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+SFNode[0].childNodes[m+2].childNodes[0].nodeValue+"<br /> to <br />"+SFNode[0].childNodes[m+3].childNodes[0].nodeValue+"</td>"
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+SFNode[0].childNodes[m+9].childNodes[0].nodeValue+"</td>"
							matchid=SFNode[0].childNodes[m+10].childNodes[0].nodeValue
							tournamentid=id;
							if(SFNode[0].childNodes[m+6].childNodes.length>0) // if result is not null
							{
																
								if(SFNode[0].childNodes[m+6].childNodes[0].nodeValue=="R") // if result is win
								{
									if(SFNode[0].childNodes[m+7].childNodes.length>0 && SFNode[0].childNodes[m+8].childNodes.length) // if description & won clubname is available
									{
										
										if(SFNode[0].childNodes[m+7].childNodes[0].nodeValue.toUpperCase().indexOf("WALK OVER")>=0)
										{
											str=str+"<td style='border:1px solid #000;color:#ffffff;' >"+SFNode[0].childNodes[m+8].childNodes[0].nodeValue+"<br /> won by "+SFNode[0].childNodes[m+7].childNodes[0].nodeValue+"</td>"
										}
										else
										{
											str=str+"<td style='border:1px solid #000;color:#ffffff;cursor:pointer;text-decoration:underline' onclick='showMatchDetail("+matchid+","+tournamentid+",1);'>"+SFNode[0].childNodes[m+8].childNodes[0].nodeValue+"<br /> won by "+SFNode[0].childNodes[m+7].childNodes[0].nodeValue+"</td>"
										}
										
									}
									else // if description is not available
									{
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;</td>"
									}
								}
								else // if result is draw or no result
								{
									if(SFNode[0].childNodes[m+7].childNodes.length>0) // if description is available
									{
										str=str+"<td style='border:1px solid #000;color:#ffffff;cursor:pointer;text-decoration:underline' onclick='showMatchDetail("+matchid+","+tournamentid+",1);'>&nbsp;"+SFNode[0].childNodes[m+7].childNodes[0].nodeValue+"</td>"
									}
									else // if description is not available
									{
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;</td>"
									}
								}
							}
							else // if match is not played yet
							{
								str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;</td>"
							}
							
						}
						str=str+"</table><br/>";
						
					}
					
					var QFNode=scheduleNode.getElementsByTagName("QF");
					if(QFNode[0].childNodes.length>0) // If Quarter-Final has been created 
					{
						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;border:1px solid #d6d6d6;background-image:url(image/group-header-bg.png);'>QUARTER FINALS</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' bgcolor='#333944' style='color: #FFCC66; font-weight:bold;'>"
      					str=str+"<td width='40' >Cup</td>"
      					str=str+"<td width='160' >Teams</td>"
						str=str+"<td width='80' >Date</td>"
      					str=str+"<td width='80' >Timing (Hrs.)</td>"
      					str=str+"<td width='80' >Venue</td>"
      					str=str+"<td width='160' >Result</td>"
     					str=str+"</tr>"
						for(var m=0;m<QFNode[0].childNodes.length;m=m+11)
						{
							str=str+"<tr height='65'>"
							if(QFNode[0].childNodes[m].childNodes[0].nodeValue=="Gold")
							{
								str=str+"<td style='border:1px solid #000;'><img src='image/gold.jpg' alt='Gold' border='0'/></td>"
							}
							else if(QFNode[0].childNodes[m].childNodes[0].nodeValue=="Silver")
							{
								str=str+"<td style='border:1px solid #000;'><img src='image/silver.jpg' alt='Silver'  border='0'/></td>"
							}
							else
							{
								str=str+"<td style='border:1px solid #000;'><img src='image/bronze.jpg' alt='Bronze'  border='0'/></td>"
							}
							
							
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+QFNode[0].childNodes[m+4].childNodes[0].nodeValue+"<br /> vs. <br />"+QFNode[0].childNodes[m+5].childNodes[0].nodeValue+"</td>"
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+QFNode[0].childNodes[m+1].childNodes[0].nodeValue+"</td>"
							
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+QFNode[0].childNodes[m+2].childNodes[0].nodeValue+"<br /> to <br />"+QFNode[0].childNodes[m+3].childNodes[0].nodeValue+"</td>"
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+QFNode[0].childNodes[m+9].childNodes[0].nodeValue+"</td>"
							matchid=QFNode[0].childNodes[m+10].childNodes[0].nodeValue
							tournamentid=id;
							if(QFNode[0].childNodes[m+6].childNodes.length>0) // if result is not null
							{
																
								if(QFNode[0].childNodes[m+6].childNodes[0].nodeValue=="R") // if result is win
								{
									if(QFNode[0].childNodes[m+7].childNodes.length>0 && QFNode[0].childNodes[m+8].childNodes.length) // if description & won clubname is available
									{
										
										if(QFNode[0].childNodes[m+7].childNodes[0].nodeValue.toUpperCase().indexOf("WALK OVER")>=0)
										{
											str=str+"<td style='border:1px solid #000;color:#ffffff;' >"+QFNode[0].childNodes[m+8].childNodes[0].nodeValue+"<br /> won by "+QFNode[0].childNodes[m+7].childNodes[0].nodeValue+"</td>"
										}
										else
										{
											str=str+"<td style='border:1px solid #000;color:#ffffff;cursor:pointer;text-decoration:underline' onclick='showMatchDetail("+matchid+","+tournamentid+",1);'>"+QFNode[0].childNodes[m+8].childNodes[0].nodeValue+"<br /> won by "+QFNode[0].childNodes[m+7].childNodes[0].nodeValue+"</td>"
										}
										
									}
									else // if description is not available
									{
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;</td>"
									}
								}
								else // if result is draw or no result
								{
									if(QFNode[0].childNodes[m+7].childNodes.length>0) // if description is available
									{
										str=str+"<td style='border:1px solid #000;color:#ffffff;cursor:pointer;text-decoration:underline' onclick='showMatchDetail("+matchid+","+tournamentid+",1);'>&nbsp;"+QFNode[0].childNodes[m+7].childNodes[0].nodeValue+"</td>"
									}
									else // if description is not available
									{
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;</td>"
									}
								}
							}
							else // if match is not played yet
							{
								str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;</td>"
							}
							
						}
						str=str+"</table><br/>";
						
					}
					
					
					
					var dateNode=scheduleNode.getElementsByTagName("dates");
					var p=0;
					for(var i=0;i<dateNode.length;i++)
					{	
			
						var idNode=dateNode[i].firstChild;
						str=str+"<table width='600' border='0' cellspacing='0' cellpadding='0' align='center' style='text-align:Center;'>"
                        str=str+"<tr height='24'>"
						if(dateNode[i].childNodes.length>0)
						{
							str=str+"<td colspan='6' style='color:#000000;font-weight:bold;border:1px solid #d6d6d6;background-image:url(image/group-header-bg.png);'>"+dateNode[i].childNodes[0].nodeValue+"</td>"
						}
                        else
						{
							str=str+"<td colspan='6' style='color:#000000;font-weight:bold;border:1px solid #d6d6d6;background-image:url(image/group-header-bg.png);'>Detail scores will be available once the tournament starts</td>"
						}
                        str=str+"</tr>"
                        str=str+"</table>"
						
						if(dateNode[i].childNodes.length>0)
						{
							str=str+"<table width='600' border='0' cellspacing='0' cellpadding='0' align='center' style='text-align:Center;' bgcolor='#333944'>"						
						str=str+"<tr height='30' bgcolor='#333944' style='color: #FFCC66; font-weight:bold;'>"
						str=str+"<td width=60>Sl. No.</td>"
                        str=str+"<td width=60>Group</td>"
                        str=str+"<td width=160>Teams</td>"
                        
                        str=str+"<td width=120>Venue</td>"
						str=str+"<td width=200>&nbsp;</td>"
                        str=str+"</tr>"
						
						var isOddRow=true
						var matchesNode=dateNode[i].getElementsByTagName("matches")
						
						for(var j=0;j<matchesNode.length;j++)
						{
							
							p=p+1;
							var color=""
							if(isOddRow)
							{
								color="style='background-color:#000000;'"
							}
							str=str+"<tr height='35'>"
							str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+p+"</td>"
                        	str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+matchesNode[j].childNodes[4].childNodes[0].nodeValue+"</td>"
                        	str=str+"<td style='border:1px solid #000;color:#ffffff;' >&nbsp;"+matchesNode[j].childNodes[1].childNodes[0].nodeValue+"<br/> vs. <br/>"+matchesNode[j].childNodes[2].childNodes[0].nodeValue+"</td>"
                        	                        	
                        	//str=str+"<td style='border:1px solid #000;'>&nbsp;"+matchesNode[j].childNodes[5].childNodes[0].nodeValue+"<br/> to <br/>"+matchesNode[j].childNodes[6].childNodes[0].nodeValue+"</td>"
                        	str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;"+matchesNode[j].childNodes[8].childNodes[0].nodeValue+"</td>"
							matchid=matchesNode[j].childNodes[0].childNodes[0].nodeValue
							
							tournamentid=matchesNode[j].childNodes[12].childNodes[0].nodeValue
							if(matchesNode[j].childNodes[9].childNodes.length>0) // if result is not null
							{
																
								if(matchesNode[j].childNodes[9].childNodes[0].nodeValue=="R") // if result is win
								{
									if(matchesNode[j].childNodes[10].childNodes.length>0 && matchesNode[j].childNodes[11].childNodes.length) // if description & won clubname is available
									{
										
										if(matchesNode[j].childNodes[10].childNodes[0].nodeValue.toUpperCase().indexOf("WALK OVER")>=0)
										{
											
											str=str+"<td style='border:1px solid #000;color:#ffffff;'>"+matchesNode[j].childNodes[11].childNodes[0].nodeValue+" <br/>won by "+matchesNode[j].childNodes[10].childNodes[0].nodeValue+"</td>"
										}
										else
										{
											
											str=str+"<td style='border:1px solid #000;color:#ffffff;cursor:pointer;text-decoration:underline' onclick='showMatchDetail("+matchid+","+tournamentid+",2);'>"+matchesNode[j].childNodes[11].childNodes[0].nodeValue+" <br/>won by "+matchesNode[j].childNodes[10].childNodes[0].nodeValue+"</td>"
										}
										
									}
									else // if description is not available
									{
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;</td>"
									}
								}
								else // if result is draw or no result
								{
									if(matchesNode[j].childNodes[10].childNodes.length>0) // if description is available
									{
										
										str=str+"<td style='border:1px solid #000;color:#ffffff;cursor:pointer;text-decoration:underline' onclick='showMatchDetail("+clubid+","+tournamentid+",2);'>&nbsp;"+matchesNode[j].childNodes[10].childNodes[0].nodeValue+"</td>"
									}
									else // if description is not available
									{
										str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;</td>"
									}
								}
							}
							else // if match is not played yet
							{
								str=str+"<td style='border:1px solid #000;color:#ffffff;'>&nbsp;</td>"
							}
							
							str=str+"</tr>"
							isOddRow=!isOddRow
						}
						str=str+"</table><br/>";
						}
						
						
						
						
					}
				}
				
				//document.getElementById("topindex").style.display="none";
				document.getElementById("toparea3").innerHTML=str;
				$.unblockUI();
				strscore=str;
				
			}
		}
		objRequest.send('tid='+id);
	}
}


