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 searchplayer()
{
	psearch=document.getElementById("txtsearch").value
	
	if(jQuery.trim(psearch)=="" || jQuery.trim(psearch)==$('input#txtsearch').attr('title'))
	{
		alert('Please enter the player\'s name you want to search.')
		return false;
	}
	
	createXMLHttp();
	$.blockUI({ message: '<img src=image/loader.gif></img>',css: { backgroundColor: '#000000', color: '#fff', width: '100', height: '100', border: '0px solid #f00', left: '50%', top: '50%'} });
	if(objRequest)
	{
		objRequest.open("POST","search.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 clubNode=doc.documentElement;
				if(clubNode)
				{
					var str="";
					
					
					//for(var i=0;i<clubnameNode.length;i++)
					//{
						var idNode=clubNode.childNodes[0];
						var cid=idNode.childNodes[0].nodeValue;	
								
						var clubnameNode=idNode.nextSibling;
						var clubName=clubnameNode.childNodes[0].nodeValue;
						
						var cpersonNode=clubnameNode.nextSibling;
						var addressNode=cpersonNode.nextSibling;
						var phoneNode=addressNode.nextSibling;
						var mobileNode=phoneNode.nextSibling;												
						var playersNode=mobileNode.nextSibling;
						var cnt=playersNode.childNodes.length;
						
						str=str+"<div id='pdetail'>"
											
						if(cnt>0)
						{
							str=str+"<table width='99%' border='0' cellspacing='0' cellpadding='0' style='margin:10px 0 10px 10px;padding:10px'>"
							
							str=str+"<tr>"
							str=str+"<td colspan='3' align='left' valign='middle' style='padding-top:10px; padding-bottom:7px;'><strong>"+parseInt(cnt)/9+"</strong> Record(s) found for you search for <strong>\""+psearch+"\"</strong></td>"
							str=str+"<tr>"
							
							
							var r=0;
							for(var j=0;j<playersNode.childNodes.length;j=j+9)
							{
								//alert(playersNode.childNodes[j].firstChild.nodeValue)
								var playerIdNode=playersNode.childNodes[j];
								var playerId=playerIdNode.childNodes[0].nodeValue;
								var playerNameNode=playerIdNode.nextSibling;
								var playerName=playerNameNode.childNodes[0].nodeValue;
								var ageNode=playerNameNode.nextSibling;
								var categoryNode=ageNode.nextSibling;
								var battingNode=categoryNode.nextSibling;
								var bowlingNode=battingNode.nextSibling;
								var otherNode=bowlingNode.nextSibling;
								var addressNode=otherNode.nextSibling;
								var imageNode=addressNode.nextSibling;
								
								if(r%3==0)
								{
									str=str+"<tr>"
								}
								
								str=str+"<td width='33%' align='center' valign='middle' style='padding-top:10px; padding-bottom:7px;'>"
								var strbody="<table width=100% cellspacing=2 cellpadding=0>"
								
								if(categoryNode.childNodes.length>0)
								{
									strbody=strbody+"<tr><td valign=top align=left><b>Category :</b></td> <td valign=top align=left>&nbsp;&nbsp;"+categoryNode.childNodes[0].nodeValue+"</td></tr>";

								}
								
								if(battingNode.childNodes.length>0)
								{
									strbody=strbody+"<tr><td valign=top align=left><b>Bats :</b></td> <td valign=top align=left>&nbsp;&nbsp;"+battingNode.childNodes[0].nodeValue+"</td></tr>";

								}
								
								if(bowlingNode.childNodes.length>0)
								{
									strbody=strbody+"<tr><td valign=top align=left><b>Bowls :</b></td> <td valign=top align=left>&nbsp;&nbsp;"+bowlingNode.childNodes[0].nodeValue+"</td></tr>";

								}
								
								if(otherNode.childNodes.length>0)
								{
									strbody=strbody+"<tr><td valign=top align=left><b>Others : </b></td> <td valign=top align=left>&nbsp;&nbsp;"+otherNode.childNodes[0].nodeValue+"</td></tr>";
								}
								
								if(addressNode.childNodes.length>0)
								{
									strbody=strbody+"<tr><td valign=top align=left><b>Address : </b></td> <td valign=top align=left>&nbsp;&nbsp;"+addressNode.childNodes[0].nodeValue+"</td></tr>";
								}
								
								strbody=strbody+"</table>"
								
								if(imageNode.childNodes.length>0)
								{
									str=str+"<img src='pimage/"+imageNode.childNodes[0].nodeValue+"' style='cursor:pointer; border:1px solid #666666; padding:2px' onClick='getProfile("+playerId+")' title='header=[<span align=left><b>"+playerName+"</b></span>] fade=[on] cssbody=[dvbdy] cssheader=[dvhdr] body=["+strbody+"]'/>"
								}
								else
								{
									str=str+"<img src='pimage/noimage.gif' border='0'  style='cursor:pointer; border:1px solid #666666; padding:2px' onClick='getProfile("+playerId+")' title='header=[<span align=left><b>"+playerName+"</b></span>] fade=[on] cssbody=[dvbdy] cssheader=[dvhdr] body=["+strbody+"]'/>"
								}
								str=str+"<br /><br />"
								//str=str+"Name: "+playerNameNode.childNodes[0].nodeValue+"<br />"
								str=str+playerNameNode.childNodes[0].nodeValue+"<br />"
								if(ageNode.childNodes.length>0)
								{
									str=str+"Age: "+ageNode.childNodes[0].nodeValue
								}
								str=str+"</td>"
								
								if(r%3==2)
								{
									str=str+"</tr>"
									
								}
								
								r=r+1;
							}
							
							str=str+"</table>"
							str=str+"</td></tr></table>"
						}
						else
						{
							str=str+"<table width='100%' border='0' cellspacing='0' cellpadding='0' style='margin:10px 0 10px 10px;padding:10px'>"
							
							str=str+"<tr>"
							str=str+"<td colspan='3' align='left' valign='middle' style='padding-top:10px; padding-bottom:7px;'><strong>0</strong> Record(s) found for you search for <strong>\""+psearch+"\"</strong></td>"
							str=str+"<tr></table>"
						}
						
						str=str+"</div>"
					
					
					
						 var strtitle="";
						 strtitle=strtitle+"&nbsp;<font color='#fff000'><em>&nbsp;Players Search&nbsp;</em></font>&nbsp;";
						 
						
					 
						document.getElementById("toparea2").style.display="none";
						document.getElementById("toparea2").innerHTML="";
						document.getElementById("toparea3").innerHTML="";
						document.getElementById("toparea1").innerHTML=strtitle;
						document.getElementById("toparea4").innerHTML=str;
						
						$.unblockUI();
						strshowplayerslabel=strtitle;
						strshowplayers=str;
						str=str+"</div>"
						str=str+"</td></tr></table>"
						
				}
			}
		}
		objRequest.send('psearch='+psearch);
	}
}


