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 getTournaments(typ,fyear,tyear)
{
		
	createXMLHttp();
	$.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","tournament.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 tournamentsNode=doc.documentElement;
				if(tournamentsNode)
				{
					var str="";
					var label="";
					var tournamentNode=tournamentsNode.getElementsByTagName("tournament");
					
					for(var i=0;i<tournamentNode.length;i++)
					{
						var idNode=tournamentNode[i].firstChild;
						var tid=idNode.childNodes[0].nodeValue;
						var tnameNode=idNode.nextSibling;
						var tname=tnameNode.childNodes[0].nodeValue;
						var yrfromNode=tnameNode.nextSibling;
						var yrfrom=yrfromNode.childNodes[0].nodeValue;
						var yrtoNode=yrfromNode.nextSibling;
						var yrto=yrtoNode.childNodes[0].nodeValue;
						fromsession=yrfrom
						tosession=yrto
						
						switch(typ)
						{
							case 1:
							
								str=str+"<table width='685' border='0' cellspacing='0' cellpadding='0' align='center' style='border-bottom:1px solid #ffffff' ><tr height='30' onclick='setValue(\""+tname+"\",1);getGroups("+tid+")'><td style='color:#FFFFFF;cursor:pointer; font-size:14px; font-weight:bold;' background='images/heading-bg.gif'>&nbsp;&nbsp;"+(i+1)+". "+tname +"</td></tr></table>"
								
								label="Points Table";
								break;
							case 2:								
								 str=str+"<table width='685' border='0' cellspacing='0' cellpadding='0' align='center' style='border-bottom:1px solid #ffffff' ><tr height='30' onclick='setValue(\""+tname+"\",1);getSchedule("+tid+")'><td  background='images/heading-bg.gif' style='color:#FFFFFF;cursor:pointer;  font-size:14px; font-weight:bold'>&nbsp;&nbsp;"+(i+1)+". "+tname +"</td></tr></table>"
								label="Schedules";
								break;
							case 3:
								str=str+"<table width='685' border='0' cellspacing='0' cellpadding='0' align='center' style='border-bottom:1px solid #ffffff' ><tr height='30' onclick='setValue(\""+tname+"\",1);getGroupsWithoutDetail("+tid+")'><td  background='images/heading-bg.gif' style='color:#FFFFFF; cursor:pointer; font-size:14px; font-weight:bold'>&nbsp;&nbsp;"+(i+1)+". "+tname +"</td></tr></table>"
								label="Squads";
								break;
							case 4:
								
								str=str+"<table width='685' border='0' cellspacing='0' cellpadding='0' align='center' style='border-bottom:1px solid #ffffff' ><tr height='30' onclick='setValue(\""+tname+"\",1);getScores("+tid+")'><td  background='images/heading-bg.gif' style='color:#FFFFFF;cursor:pointer;  font-size:14px; font-weight:bold'>&nbsp;&nbsp;"+(i+1)+". "+tname +"</td></tr></table>"
								label="Scores";
								break;
							case 5:
								str=str+"<table width='685' border='0' cellspacing='0' cellpadding='0' align='center' style='border-bottom:1px solid #ffffff' ><tr height='30' ><td onclick='setValue(\""+tname+"\",1);getPerformance("+tid+")'  background='images/heading-bg.gif' style='color:#FFFFFF;cursor:pointer;  font-size:14px; font-weight:bold'>&nbsp;&nbsp;"+(i+1)+". "+tname +"</td></tr></table>"
								label="Performances";
								break;
							case 6:
								
								 str=str+"<table width='685' border='0' cellspacing='0' cellpadding='0' align='center' style='border-bottom:1px solid #ffffff' ><tr height='30' ><td background='images/heading-bg.gif' style='color:#FFFFFF;cursor:pointer;  font-size:14px; font-weight:bold'><span onclick='setValue(\""+tname+"\",1);getRule("+tid+")'>&nbsp;&nbsp;"+(i+1)+". "+tname +"</span></td></tr></table>"
								label="Rules &amp; Regulations";
								break;
						}
						
						
					}
					
					 var strtitle="";
					 strtitle=strtitle+"&nbsp;<font color='#990000'><em>"+label+"</em></font>&nbsp;";
					 //strtitle=strtitle+"<table width='0' border='0' cellspacing='0'><tr height='14'>";
					 //strtitle=strtitle+"<td width='26' style='background-color:#d6d6d6;'></td>";
					 //strtitle=strtitle+"<td style='color:#c9ff00; font-size:10pt; font-weight:bold;'>&nbsp;"+label+"&nbsp;</td>";
					 //strtitle=strtitle+"<td width='345' style='background-image:url(image/line.jpg);'></td>";
					//strtitle=strtitle+"</tr></table>";
					 
					 //document.getElementById("topindex").style.display="none";
					 
					 /*document.getElementById("toparea2").innerHTML="";
					 document.getElementById("toparea3").innerHTML="";
					 document.getElementById("toparea1").innerHTML=strtitle;
					 document.getElementById("toparea2").innerHTML=str;*/
					document.getElementById("toparea1").innerHTML=strtitle;
					document.getElementById("toparea2").style.display="none";
					document.getElementById("toparea2").innerHTML="";
					document.getElementById("toparea4").innerHTML="";
					document.getElementById("toparea3").innerHTML=str;
					$.unblockUI();
					
					strtournamentlabel=strtitle;
					strtournament=str;
				}
			}
		}
		
		objRequest.send('fyear='+fyear+'&tyear='+tyear);
	}
	
}
