var battingXmlHttp = false;
var bowlingXmlHttp = false;

function battingXmlRequest() {
	batXmlHttpRequest();
	battingXmlHttp.onreadystatechange=function(){
		createBatting();
	}
	battingXmlHttp.open("GET", "aptechRecord.xml", true);
	battingXmlHttp.send(null);	
}

function batXmlHttpRequest() {
	if (window.ActiveXObject) {
		battingXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		battingXmlHttp = new XMLHttpRequest();
	}
}

function createBatting() {
	if ((battingXmlHttp.readyState == 4) && (battingXmlHttp.status==200)) {
		createBatTable();
	}
}

function createBatTable() {
	var response = battingXmlHttp.responseXML.documentElement;
	header1 = '<div id="tab" style="width:395px;"><ul id="tabmenu"><li><a href="#" rel="tcontent1" onclick="battingXmlRequest();">Batting</a></li><li><a href="#" rel="tcontent1" onclick="bowlingXmlRequest();">Bowling</a></li></ul><div id="tcontent1" style="display: block;"></div></div>';
	txt = header1 + '<table border="1px" solid>';
	x = response.getElementsByTagName("DATA_RECORD");
	header='<tr id="row1"><th>Batsman</th><th>Matches</th><th>Innings</th><th>Not Out</th><th>Runs</th><th>Highest</th><th>Average</th></tr>'
	txt=txt+header;
	for (i=0;i<x.length;i++) {
		txt=txt + "<tr>";
    	xx=x[i].getElementsByTagName("Batsmen");
	    txt=txt + '<td style="font: bold 10px Verdana, Arial, Helvetica, sans-serif;">' + xx[0].firstChild.data + "</td>";
    	xx=x[i].getElementsByTagName("Match");
        txt=txt + "<td>" + xx[0].firstChild.data + "</td>";
    	xx=x[i].getElementsByTagName("Innings");
        txt=txt + "<td>" + xx[0].firstChild.data + "</td>";
    	xx=x[i].getElementsByTagName("NotOut");
        txt=txt + "<td>" + xx[0].firstChild.data + "</td>";
    	xx=x[i].getElementsByTagName("Runs");
        txt=txt + "<td>" + xx[0].firstChild.data + "</td>";
    	xx=x[i].getElementsByTagName("HS");
        txt=txt + "<td>" + xx[0].firstChild.data + "</td>";
    	xx=x[i].getElementsByTagName("Ave");
        txt=txt + "<td>" + xx[0].firstChild.data + "</td>";      
		txt=txt + "</tr>"
      }
  txt=txt + "</table>";
//  document.getElementById('tcontent1').innerHTML=txt
  document.getElementById('railContent').innerHTML=txt
}


function bowlingXmlRequest() {
	bowlXmlHttpRequest();
	bowlingXmlHttp.onreadystatechange=function(){
		createBowling();
	}
	bowlingXmlHttp.open("GET", "BowlingStats.xml", true);
	bowlingXmlHttp.send(null);	
}

function bowlXmlHttpRequest() {
	if (window.ActiveXObject) {
		bowlingXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		bowlingXmlHttp = new XMLHttpRequest();
	}
}

function createBowling() {
	if ((bowlingXmlHttp.readyState == 4) && (bowlingXmlHttp.status==200)) {
		createBowlTable();
	}
}

function createBowlTable() {
	var bresponse = bowlingXmlHttp.responseXML.documentElement;
	header1 = '<div id="tab" style="width:390px;"><ul id="tabmenu"><li><a href="#" rel="tcontent1" onclick="battingXmlRequest();">Batting</a></li><li><a href="#" rel="tcontent1" onclick="bowlingXmlRequest();">Bowling</a></li></ul>	<div id="tcontent1" style="display: block;"></div></div>';
	btxt= header1 + '<table border=1" id="statsTable">';
	x = bresponse.getElementsByTagName("DATA_RECORD");
	header='<tr id="row1"><th>Bowler</th><th>Matches</th><th>Overs</th><th>Runs</th><th>Wkts</th><th>Avg</th><th>Econ</th><th>3 Wkts</th></tr>'
	btxt=btxt+header;
	for (i=0;i<x.length;i++) {
		btxt=btxt + "<tr>";
    	xx=x[i].getElementsByTagName("Bowler");
	    btxt=btxt + '<td style="font: bold 10px Verdana, Arial, Helvetica, sans-serif;">' + xx[0].firstChild.data + "</td>";
       	xx=x[i].getElementsByTagName("Match");
        btxt=btxt + "<td>" + xx[0].firstChild.data + "</td>";
       	xx=x[i].getElementsByTagName("Overs");
        btxt=btxt + "<td>" + xx[0].firstChild.data + "</td>";
       	xx=x[i].getElementsByTagName("Runs");
        btxt=btxt + "<td>" + xx[0].firstChild.data + "</td>";
       	xx=x[i].getElementsByTagName("Wickets");
        btxt=btxt + "<td>" + xx[0].firstChild.data + "</td>";
       	xx=x[i].getElementsByTagName("Average");
        btxt=btxt + "<td>" + xx[0].firstChild.data + "</td>";
       	xx=x[i].getElementsByTagName("Economy");
        btxt=btxt + "<td>" + xx[0].firstChild.data + "</td>";
       	xx=x[i].getElementsByTagName("Three_Wickets");
        btxt=btxt + "<td>" + xx[0].firstChild.data + "</td>";
		btxt=btxt + "</tr>";
      }
  btxt=btxt + "</table>";
//  document.getElementById('tcontent1').innerHTML=btxt;
  document.getElementById('railContent').innerHTML=btxt;
}

function info() {
	alert("Information" + document.getElementById("tcontent1").getAttribute("style"));
	document.getElementById("tcontent1").setAttribute("style","display: block");
}

