function createRequestObject()
{
	var ro;
	var browser = navigator.appName;

	if(browser == "Microsoft Internet Explorer") 
	{
		// on IE, we have to use ActiveX
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		// on every other browser, we can directly create a new XMLHttpRequest object
		ro = new XMLHttpRequest();
	}
	return ro;
}

var http = createRequestObject();

// this function should be called for user input
// it opens up a php page with a querystring of 'action'
// this function could probably be adapted to POST

//Function call with <select name="club_name" tabindex="3" id="club_name" onChange=" sndReq('ajax.php?request_type=club_member&id='+this.value);"><option value="0" selected="selected">-select club-</option>
function showUser(sid,cntid)
{
	var url="county.php?stateId="+sid+"&cntId="+cntid;
	http.open("get", url);
	http.onreadystatechange = handleResponse;
	http.send(null);
}

// the response in this case is formatted as follows:
// object|text
// where object is the id of the HTML element we are going to update
// and text is what it will be updated to
// this could obviously work a lot better with some XML

function handleResponse()
{
	if(http.readyState == 4) 
	{
		var arrCounty = http.responseText.split(":");
		var arrCountyList = arrCounty[1].split("|~~|");
		removeAllOptions(document.getElementById("county"));
		for(i=0;i<arrCountyList.length;i++)
		{
			var arrCountyDetail = arrCountyList[i].split("~");
			if(arrCountyDetail[0])
			{	
				if(arrCountyList.length == i+1)
					str = arrCountyDetail[1].substr(0,arrCountyDetail[2]);
				else
					str = arrCountyDetail[1];
				addOption(document.getElementById("county"),arrCountyDetail[0],str);
				if(arrCounty[0]==arrCountyDetail[0])
				{
					document.getElementById("county").value = arrCounty[0];
				}
			}
		}
	}
	
	function addOption(selectbox,value,text)   
	{ 
		
		var objDropdown = document.getElementById('county');
		var objOption = new Option(text,value);
		objDropdown.options[objDropdown.length] = objOption;
	} 
}

function removeAllOptions(selectbox)  
{  
	var i;  
	for(i=selectbox.options.length;i>=0;i--)  
	{  
		selectbox.remove(i);  
	}  
}  

	