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 getProfile(pid)
{
	
	
	$.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","profile.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 playerNode=doc.documentElement;
				
				if(playerNode)
				{
					var idNode=playerNode.childNodes[0];
					var pid=idNode.childNodes[0].nodeValue;	
					var pnameNode=idNode.nextSibling;
					var pname=pnameNode.childNodes[0].nodeValue;
					var pimageNode=pnameNode.nextSibling;
					if(pimageNode.childNodes.length>0)
					{
					    var pimage=pimageNode.childNodes[0].nodeValue;
					}
					else
					{
						var pimage="noimage.gif";
					}
					var dobNode=pimageNode.nextSibling;
					var dob=dobNode.childNodes[0].nodeValue;
					if(dob=="0")
					{
						dob="";
					}
					
					var ageNode=dobNode.nextSibling;
					var age=ageNode.childNodes[0].nodeValue;
					if(age=="0")
					{
						age="";
					}
					var debutNode=ageNode.nextSibling;
					var debut=debutNode.childNodes[0].nodeValue;
					if(debut=="0")
					{
						debut="Not yet played";
					}
					var battingNode=debutNode.nextSibling;
					var batting=battingNode.childNodes[0].nodeValue;
					var bowlingNode=battingNode.nextSibling;
					var bowling=bowlingNode.childNodes[0].nodeValue;
					var momNode=bowlingNode.nextSibling;
					var mom=momNode.childNodes[0].nodeValue;
					var battingNode=momNode.nextSibling;
					var bowlingNode=battingNode.nextSibling;
					var battingGraphNode=bowlingNode.nextSibling;
					var bowlingGraphNode=battingGraphNode.nextSibling;
					
					
					var str="";
					
					str=str+"<table width='670' border='0' cellspacing='0' cellpadding='0' align='center' style='text-align:center;margin-bottom:20px;'>";
                    str=str+"<tr><td style=' background-color:#000000; padding:10px; border:1px #baff00 solid'>";
                    str=str+"<img src='pimage/"+pimage+"'/></td>";
					str=str+"<td valign='top'>";
					
					
                    str=str+"<table width='490' border='0' cellspacing='0' cellpadding='0'  style='text-align:left; font-weight:bold;' align='right'>";
                    str=str+"<tr height='25'><td width='120' style='border-bottom:1px dotted #999; color: #000;'>&nbsp;Full Name</td>";
                    str=str+"<td width='10' style='border-bottom:1px dotted #999;'>:</td>";
                    str=str+"<td width='200' style='border-bottom:1px dotted #999; color: #999999;'>&nbsp;"+pname+"</td>";
                    str=str+"</tr><tr height='22'><td style='border-bottom:1px dotted #999; color: #000;'>&nbsp;Born</td>";
                    str=str+"<td width='10' style='border-bottom:1px dotted #999;'>:</td>";
                    str=str+"<td style='border-bottom:1px dotted #999; color: #999999;'>&nbsp;"+dob+"</td>";
                    str=str+"</tr><tr height='22'><td style='border-bottom:1px dotted #999; color: #000;'>&nbsp;Age</td>";
                    str=str+"<td width='10' style='border-bottom:1px dotted #999;'>:</td>";
                    str=str+"<td style='border-bottom:1px dotted #999; color: #999999;'>&nbsp;"+age+"</td></tr>";
                    str=str+"<tr height='22'><td style='border-bottom:1px dotted #999; color: #000;'>&nbsp;Debut</td>";
                    str=str+"<td width='10' style='border-bottom:1px dotted #999;'>:</td>";
                    str=str+"<td style='border-bottom:1px dotted #999; color: #999999;'>&nbsp;"+debut+"</td></tr>"; 
                    str=str+"<tr height='22'><td style='border-bottom:1px dotted #999; color: #000;'>&nbsp;Batting Style</td>";
					str=str+"<td width='10' style='border-bottom:1px dotted #999;'>:</td>";
                    str=str+"<td style='border-bottom:1px dotted #999; color: #999999;'>&nbsp;"+batting+"</td></tr>";
                    str=str+"<tr height='22'><td style='border-bottom:1px dotted #999; color: #000;'>&nbsp;Bowling Style</td>";
                    str=str+"<td width='10' style='border-bottom:1px dotted #999;'>:</td>";
                    str=str+"<td style='border-bottom:1px dotted #999; color: #999999;'>&nbsp;"+bowling+"</td></tr>";
                    str=str+"<tr height='22'><td style='border-bottom:1px dotted #999; color: #000;'>&nbsp;Man of the Match</td>";
                    str=str+"<td width='10' style='border-bottom:1px dotted #999;'>:</td>";
                    str=str+"<td style='border-bottom:1px dotted #999; color: #999999;'>&nbsp;"+mom+"</td></tr>";
                    str=str+"</table>      </td></tr></table>";
                    str=str+"<div style='text-align:right; margin:0 7px 7px 0; font-weight:bold;' ><span style='cursor:pointer' onclick='getprofiletoshowplayers()'>Back</span></div>"
					if(debut!="Not yet played")
					{
						str=str+"<table width='520' border='0' cellspacing='0' cellpadding='0' align='center' style='text-align:center; margin-bottom:20px;'>";
						str=str+"<tr><td colspan='13' height='24' align='left' style='color:#000000;background-image:url(image/group-header-bg.png); border:1px solid #000000; text-align:center;'><b>Batting Statistics</b></td></tr>";
						str=str+"<tr height='35' style='color: #FFCC00; font-weight:bold; background-color:#000;'>";
						str=str+"<td width='166' style='text-align:left; border:1px solid #000;'>&nbsp;Tournaments</td>";
						str=str+"<td width='27' style='border:1px solid #000;'>M</td>";
						str=str+"<td width='26' style='border:1px solid #000;'>I</td>";
						str=str+"<td width='30' style='border:1px solid #000;'>NO</td>";
						str=str+"<td width='33' style='border:1px solid #000;'>R</td>";
						str=str+"<td width='34' style='border:1px solid #000;'>HS</td>";
						str=str+"<td width='35' style='border:1px solid #000;'>BF</td>";
						str=str+"<td width='42' style='border:1px solid #000;'>Avg</td>";
						str=str+"<td width='36' style='border:1px solid #000;'>100</td>";
						str=str+"<td width='28' style='border:1px solid #000;'>50</td>";
						str=str+"<td width='43' style='border:1px solid #000;'>S/R</td>";
						str=str+"<td width='30' style='border:1px solid #000;'>Ct</td>";
						str=str+"<td width='30' style='border:1px solid #000;'>St</td>";
						str=str+"</tr>";
						
						for(j=0;j<battingNode.childNodes.length;j=j+13)
						{
							var innings=battingNode.childNodes[j+2].childNodes[0].nodeValue
							str=str+"<tr height='40'>";
							str=str+"<td style='text-align:left; border:1px solid #000; color:#CCCCCC;'>&nbsp;<b>"+battingNode.childNodes[j].childNodes[0].nodeValue+"</b></td>";
							str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+1].childNodes[0].nodeValue+"</td>";
							if(innings>0)
							{
								str=str+"<td style='border:1px solid #000;'>"+innings+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+3].childNodes[0].nodeValue+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+4].childNodes[0].nodeValue+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+5].childNodes[0].nodeValue+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+6].childNodes[0].nodeValue+"</td>";
								if(battingNode.childNodes[j+7].childNodes.length>0)
								{
									str=str+"<td style='border:1px solid #000;'>"+parseFloat(battingNode.childNodes[j+7].childNodes[0].nodeValue).toFixed(2)+"</td>";
								}
								else
								{
									str=str+"<td style='border:1px solid #000;'> - </td>";	
								}
								
								str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+8].childNodes[0].nodeValue+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+9].childNodes[0].nodeValue+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+parseFloat(battingNode.childNodes[j+10].childNodes[0].nodeValue).toFixed(2)+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+11].childNodes[0].nodeValue+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+battingNode.childNodes[j+12].childNodes[0].nodeValue+"</td>";
							}
							else
							{
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
							}
							
							
							str=str+"</tr>";
							//zeros=parseInt(battingNode.childNodes[j+12].childNodes[0]);
							//str=str+battingNode.childNodes[j+12].childNodes[0].nodeValue;
							
						}
						
						str=str+"</table>"; 
					}
					  
                    str=str+"<div align='center'>";
					str=str+battingGraphNode.childNodes[0].nodeValue;
					str=str+"</div><br />";
					

					if(debut!="Not yet played")
					{
						str=str+"<table width='520' border='0' cellspacing='0' cellpadding='0' align='center' style='text-align:center; margin-bottom:10px;'>";
						str=str+"<tr><td colspan='13' height='24' align='left' style='color:#000000;background-image:url(image/group-header-bg.png); border:1px solid #000000; text-align:center;'><b>Bowling Statistics</b></td></tr>";
						str=str+"<tr height='35' style='color: #FFCC00; font-weight:bold; background-color:#000;'>";
						str=str+"<td width='154' style='text-align:left;border:1px solid #000;'>&nbsp;<b>Tournaments</b></td>";
						str=str+"<td width='22' style='border:1px solid #000;'>M</td>";
						str=str+"<td width='22' style='border:1px solid #000;'>I</td>";
						str=str+"<td width='37' style='border:1px solid #000;'>O</td>";
						str=str+"<td width='36' style='border:1px solid #000;'>R</td>";
						str=str+"<td width='32' style='border:1px solid #000;'>Wkt</td>";
						str=str+"<td width='20' style='border:1px solid #000;'>M</td>";
						str=str+"<td width='40' style='border:1px solid #000;'>BB</td>";
						str=str+"<td width='38' style='border:1px solid #000;'>Avg</td>";
						str=str+"<td width='39' style='border:1px solid #000;'>Econ</td>";
						str=str+"<td width='36' style='border:1px solid #000;'>S/R</td>";
						str=str+"<td width='30' style='border:1px solid #000;'>3W</td>";
						str=str+"<td width='46' style='border:1px solid #000;'>5W</td>";
						str=str+"</tr>";
						
						for(j=0;j<bowlingNode.childNodes.length;j=j+13)
						{
							var innings=bowlingNode.childNodes[j+2].childNodes[0].nodeValue;
							
							str=str+"<tr height='40'>";
							str=str+"<td style='text-align:left; border:1px solid #000; color:#CCCCCC;'>&nbsp;<b>"+bowlingNode.childNodes[j].childNodes[0].nodeValue+"</b></td>";
							str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+1].childNodes[0].nodeValue+"</td>";
							
							if(innings==0)
							{
								
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
								str=str+"<td style='border:1px solid #000;'> - </td>";
							}
							else
							{
								
								str=str+"<td style='border:1px solid #000;'>"+innings+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+convertBallsToOvers(bowlingNode.childNodes[j+3].childNodes[0].nodeValue)+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+4].childNodes[0].nodeValue+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+5].childNodes[0].nodeValue+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+6].childNodes[0].nodeValue+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+7].childNodes[0].nodeValue+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+parseFloat(bowlingNode.childNodes[j+8].childNodes[0].nodeValue).toFixed(2)+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+parseFloat(bowlingNode.childNodes[j+9].childNodes[0].nodeValue).toFixed(2)+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+parseFloat(bowlingNode.childNodes[j+10].childNodes[0].nodeValue).toFixed(2)+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+11].childNodes[0].nodeValue+"</td>";
								str=str+"<td style='border:1px solid #000;'>"+bowlingNode.childNodes[j+12].childNodes[0].nodeValue+"</td>";
							}
							
							
							str=str+"</tr>";
							
						}
						
						str=str+"</table>";
					}
                    
					
					//str=str+"<div align='center'>";
					//str=str+battingGraphNode.childNodes[0].nodeValue;
					//str=str+"</div>";
					str=str+"<div align='center'>";
					str=str+bowlingGraphNode.childNodes[0].nodeValue;
					str=str+"</div>";
					str=str+"<div style='text-align:right; margin:0 7px 7px 0; font-weight:bold;' ><span style='cursor:pointer' onclick='getprofiletoshowplayers()'>Back</span></div>"
					 var strtitle="";
					/* strtitle=strtitle+"<table width='0' border='0' cellspacing='0'><tr height='14'>";
					 strtitle=strtitle+"<td style='color:#c9ff00; font-size:10pt; font-weight:bold;'>&nbsp;Profile&nbsp;</td>";
					 strtitle=strtitle+"</tr></table>";*/
					 
					strtitle=strtitle+"&nbsp;<font color='#990000'><em>Profile</em></font>&nbsp;";	
					
					
					
					
					document.getElementById("toparea1").innerHTML=strtitle;
					document.getElementById("toparea2").style.display="none";
					document.getElementById("toparea2").innerHTML="";
					document.getElementById("toparea3").innerHTML="";
					document.getElementById("toparea4").innerHTML=str;
					
					
					$.unblockUI();
					strgetprofilelabel=strtitle;
					strgetprofile=str;
				}
			}
		}
		
		objRequest.send('pid='+pid);
	}
}

