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 showSingleSchedule(cid,tid)
{
	
	
	$.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","singleschedule.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 detailNode=doc.documentElement;
				if(detailNode)
				{
					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+"</td></tr></table>";
					
					str=str+"<div style='text-align:right; margin:0 7px 7px 0; font-weight:bold;' ><span style='cursor:pointer' onclick='showplayerstogroups()'>Back</span></div>"
					var mainClubNode=detailNode.getElementsByTagName("mainclub");
					
					var mainClubName=mainClubNode[0].childNodes[0].nodeValue;
					
					
						
					str=str+"<table width='670' border='0' cellspacing='0' cellpadding='0' align='center' style='margin-top:0px; text-align:center;'>"
     					str=str+"<tr height='30'>"
								str=str+"<td bgcolor='#7A8289' style='color:#FFFFFF; font-size:14px; font-weight:bold'>"+mainClubName+"</td>"
								str=str+"</tr>"
								str=str+"</table>"
								
					
										
					str=str+"<table width='670' border='0' cellspacing='0' cellpadding='5' style='margin:1px 0 10px 10px; border:1px solid #B2B3B5;text-align:center'>"
     					str=str+"<tr height='25' bgcolor='#BDBEC0'>"
      				str=str+"<td width='170' class='style3' style='border-bottom:1px solid #333333'>Opponent</td>"
					str=str+"<td width='60' class='style3' style='border-bottom:1px solid #333333'>Date</td>"
      				str=str+"<td width='70' class='style3' style='border-bottom:1px solid #333333'>Timing (Hrs.)</td>"
      				str=str+"<td width='130' class='style3' style='border-bottom:1px solid #333333'>Venue</td>"
      				str=str+"<td width='230' class='style3' style='border-bottom:1px solid #333333'>Result</td>"
     				str=str+"</tr>"
					var opponentsNode=detailNode.getElementsByTagName("opponent")
					
					for(var j=0;j<opponentsNode.length;j++)
					{
						str=str+"<tr height='30'>"
						str=str+"<td style='border-bottom:1px solid #B2B3B5;'>&nbsp;"+opponentsNode[j].childNodes[0].childNodes[0].nodeValue+"</td>"
						str=str+"<td style='border-bottom:1px solid #B2B3B5;'>&nbsp;"+opponentsNode[j].childNodes[1].childNodes[0].nodeValue+"</td>"
						str=str+"<td style='border-bottom:1px solid #B2B3B5;'>&nbsp;"+opponentsNode[j].childNodes[2].childNodes[0].nodeValue+"<br /> to <br />"+opponentsNode[j].childNodes[3].childNodes[0].nodeValue+"</td>"
						str=str+"<td style='border-bottom:1px solid #B2B3B5;'>&nbsp;"+opponentsNode[j].childNodes[7].childNodes[0].nodeValue+"</td>"
						var matchid=opponentsNode[j].childNodes[8].childNodes[0].nodeValue
						if(opponentsNode[j].childNodes[4].childNodes.length>0) // if result is not null
							{
																
								if(opponentsNode[j].childNodes[4].childNodes[0].nodeValue=="R") // if result is win
								{
									if(opponentsNode[j].childNodes[5].childNodes.length>0 && opponentsNode[j].childNodes[6].childNodes.length) // if description & won clubname is available
									{
										
										if(opponentsNode[j].childNodes[5].childNodes[0].nodeValue.toUpperCase().indexOf("WALK OVER")>=0 || opponentsNode[j].childNodes[5].childNodes[0].nodeValue.toUpperCase().indexOf("WALKOVER")>=0)
										{
											str=str+"<td style='border-bottom:1px solid #B2B3B5;'>"+opponentsNode[j].childNodes[6].childNodes[0].nodeValue+"<br /> won by "+opponentsNode[j].childNodes[5].childNodes[0].nodeValue+"</td>"
										}
										else
										{
											str=str+"<td style='border-bottom:1px solid #B2B3B5;cursor:pointer;text-decoration:underline' onclick='showMatchDetail("+matchid+","+tid+",3);'>"+opponentsNode[j].childNodes[6].childNodes[0].nodeValue+"<br /> won by "+opponentsNode[j].childNodes[5].childNodes[0].nodeValue+"</td>"
										}
										
									}
									else // if description is not available
									{
										str=str+"<td style='border-bottom:1px solid #B2B3B5;'>&nbsp;</td>"
									}
								}
								else // if result is draw or no result
								{
									if(opponentsNode[j].childNodes[5].childNodes.length>0) // if description is available
									{
										str=str+"<td style='border-bottom:1px solid #B2B3B5;cursor:pointer;text-decoration:underline' onclick='showMatchDetail("+matchid+","+tid+",3);'>&nbsp;"+opponentsNode[j].childNodes[5].childNodes[0].nodeValue+"</td>"
									}
									else // if description is not available
									{
										str=str+"<td style='border-bottom:1px solid #B2B3B5;'>&nbsp;</td>"
									}
								}
							}
							else // if match is not played yet
							{
								str=str+"<td style='border-bottom:1px solid #B2B3B5;'>&nbsp;</td>"
							}
							str=str+"</tr>"
					}
					var notScheduledNode=detailNode.getElementsByTagName("notscheduled")
					if(notScheduledNode[0].childNodes.length>0) // If not scheduled matches exist
					{
						var nsClubNodes=notScheduledNode[0].childNodes;
						for(var k=0;k<nsClubNodes.length;k++)
						{
							str=str+"<tr height='55'>"
							str=str+"<td style='border-bottom:1px solid #B2B3B5;'>&nbsp;"+nsClubNodes[k].childNodes[0].nodeValue+"</td>"
							str=str+"<td style='border-bottom:1px solid #B2B3B5;' colspan='4'>&nbsp; NOT YET SCHEDULED</td>"
							str=str+"</tr>"
						}
					}
					str=str+"</table><br/>";
					str=str+"<div style='text-align:right; margin:0 7px 7px 0; font-weight:bold;' ><span style='cursor:pointer' onclick='showplayerstogroups()'>Back</span></div>"
				}
				
				
				document.getElementById("toparea2").style.display="none";
				document.getElementById("toparea2").innerHTML="";
				document.getElementById("toparea4").innerHTML=str;
				$.unblockUI();
				strsingleschedule=str;
				
			}
		}
		objRequest.send('cid='+cid+'&tid='+tid);
	}
}

