function getPlayers(lgid,srchStr,year,team_id,toElem)

{

	var url='ajax_player_load.php';

	var params='league_id='+lgid+'&srchStr='+srchStr;



	if (srchStr.length<2)

	{

		toElem.innerHTML="";

		toElem.options[toElem.options.length]=new Option("Search to add players",-1);

		toElem.options[0].disabled=true;

		toElem.style.color="#999999";

		toElem.style.fontStyle="italic";

		return;

	}



	if (year!='') {params+='&year='+year;}

	if (team_id!='') {params+='&team_id='+team_id;}



      	// Initiate Request

	if (window.XMLHttpRequest) {                  // code for IE7+, Firefox, Chrome, Opera, Safari

	      	xmlhttpgetPlayers=new XMLHttpRequest();

      	}

	else {                                        // code for IE6, IE5

      		xmlhttpgetPlayers=new ActiveXObject("Microsoft.XMLHTTP");

      	}



      	xmlhttpgetPlayers.open("POST",url,true);



      	xmlhttpgetPlayers.onreadystatechange=function() {



		if ((xmlhttpgetPlayers.readyState==4) && (xmlhttpgetPlayers.status==200)) {

      			xmlDoc=xmlhttpgetPlayers.responseXML;



			var i,x,xx,pid,name,pos,key,value,years,tabbr;



			toElem.innerHTML="";



			try {x=xmlhttpgetPlayers.responseXML.getElementsByTagName("PLAYER");}

			catch (er) {x='';}



			for (i=0;i<x.length;i++)

			{

				xx=x[i].getElementsByTagName("PID");

      				try {pid=xx[0].firstChild.nodeValue;}

      				catch (er) {pid='';}

				if (pid=='') {continue;}



				xx=x[i].getElementsByTagName("NAME");

      				try {name=xx[0].firstChild.nodeValue;}

      				catch (er) {name='';}

				if (name=='') {continue;}

				name=entityToHtml(name);



				xx=x[i].getElementsByTagName("POS");

      				try {pos=xx[0].firstChild.nodeValue;}

      				catch (er) {pos='';}



				if ((year=='all')||(year==''))

				{

					xx=x[i].getElementsByTagName("YEARS");

					try {years=xx[0].firstChild.nodeValue;}

					catch (er) {years='';}

	

					value=pos + " " + name + " (" + years + ")";

				}

				else

				{

					xx=x[i].getElementsByTagName("TABBR");

					try {tabbr=xx[0].firstChild.nodeValue;}

					catch (er) {tabbr='';}

	

					value=pos + " " + name + " (" + tabbr + ")";

				}



				key = pid + "," + value;



				toElem.options[toElem.options.length] = new Option(value,key);

			}



			//Restore default

			if ((toElem.options.length==0)||(x.length==0))

			{

				toElem.options[toElem.options.length] = new Option("No players found",-1);

				toElem.options[0].disabled=true;

				toElem.style.color="#999999";

				toElem.style.fontStyle="italic";

			}

			else

			{

				toElem.style.color="#000000";

				toElem.style.fontStyle="normal";

			}

		}

      	} // End state change function



      	xmlhttpgetPlayers.setRequestHeader('Content-type','application/x-www-form-urlencoded');

      	xmlhttpgetPlayers.send(params);

}



