

    function makeDropDownRequest(url,id,selectedValue) {
        var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
		if(id == "")
			http_request.onreadystatechange = function() { alertContents(http_request); };
		else
			http_request.onreadystatechange = function() { insertContents(http_request,id,selectedValue); };
        http_request.open('GET', url, true);
        http_request.send(null);
    }

    function alertContents(http_request) {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                alert(http_request.responseText);
            } else {
                alert('There was a problem with the request.');
            }
        }
    }
    function insertContents(http_request,id,selectedValue) {

		
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                //alert(http_request.responseText);
              //  document.getElementById(id).innerHTML = http_request.responseText;
                //document.getElementById(id).innerHTML
                var stateList = document.getElementById(id);
				//Clears the state combo box contents.
				for (var count = stateList.options.length-1; count >-1; count--)
				{
					stateList.options[count] = null;
				}

				var stateNodes = http_request.responseText.split(";");
				//window.alert(stateNodes) 
				var textValue; 
				var text
				var optionItem;
				//alert(stateNodes.length);
				//Add new states list to the state combo box.
				for (var count = 0; count < stateNodes.length; count= count+2)
				{
					textValue = (stateNodes[count]);
					text = (stateNodes[count+1]);
					optionItem = new Option( text, textValue,  false, false);
					//window.alert(textValue); 
					//stateList.appendChild(textValue); 
					stateList.options[stateList.length] = optionItem;
					/*
					if(selectedValue != "")
					{
							alert(encodeURIComponent(textValue) + " " + encodeURIComponent(selectedValue));
					}
					*/
					if(encodeURIComponent(textValue) == encodeURIComponent(selectedValue) && selectedValue != "")
						stateList.options[stateList.length-1].selected = true;
				}
				stateList.options[stateList.length-1] = null;
				
			} else {
	              // alert('There was a problem with the request.');
			}							
        }        
    }
    function LoadCounties(id,url,selectedValue)
	{
		var requestUrl = url + "?County=true"; 
		
		var areaList = document.getElementById("Search_AreasDropDownList");
		var selectedArea = areaList.options[areaList.selectedIndex].value;
		
		//var countyList = document.getElementById("Search_CountiesDropDownList");
		//var selectedCounty = countyList.options[countyList.selectedIndex].value;
		
		if(selectedArea != "")
			requestUrl += "&selectedArea=" + selectedArea;						         
        makeDropDownRequest(requestUrl,id,selectedValue);
                
	}
    
	function LoadCities(id,url,selectedValue)
	{
		var requestUrl = url + "?City=true"; 
		
		var areaList = document.getElementById("Search_AreasDropDownList");
		var selectedArea = areaList.options[areaList.selectedIndex].value;
		if(selectedArea != "")
			requestUrl += "&selectedArea=" + selectedArea;
		
		var countyList = document.getElementById("Search_CountiesDropDownList");
		var selectedCounty = countyList.options[countyList.selectedIndex].value;
		
		if(selectedCounty != "")
			requestUrl += "&SelectedCounty=" + selectedCounty;						         
        makeDropDownRequest(requestUrl,id,selectedValue);
                
	}
	function LoadClients(id,url,selectedValue,selectedCity)
	{
		
		var requestUrl = url + "?Client=true"; 
		
		var areaList = document.getElementById("Search_AreasDropDownList");
		var selectedArea = areaList.options[areaList.selectedIndex].value;
		if(selectedArea != "")
			requestUrl += "&selectedArea=" + selectedArea;
		
		var countyList = document.getElementById("Search_CountiesDropDownList");
		var selectedCounty = countyList.options[countyList.selectedIndex].value;		
		if(selectedCounty != "")
			requestUrl += "&SelectedCounty=" + selectedCounty;
		
		
		
		if(selectedCity == "")
		{
			var cityList = document.getElementById("Search_SearchCity");
			selectedCity = cityList.options[cityList.selectedIndex].value;
		}
        if(selectedCity != "")
			requestUrl += "&SelectedCity=" + encodeURIComponent(selectedCity);
         
        //alert("LoadClient " + selectedCity + " " + selectedCounty + " self: " + selectedValue);           
        makeDropDownRequest(requestUrl,id,selectedValue);
        
       // document.getElementById("Search_SearchClient").options[document.getElementById("Search_SearchClient").selectedIndex].selected = false;
        //document.getElementById("Search_SearchClient").options[0].selected = true;
	}
	function LoadCourses(id,url,selectedValue,selectedCity,selectedClient)
	{
			
		var requestUrl = url + "?Course=true"; 
		
		var areaList = document.getElementById("Search_AreasDropDownList");
		var selectedArea = areaList.options[areaList.selectedIndex].value;
		if(selectedArea != "")
			requestUrl += "&selectedArea=" + selectedArea;
		
		var countyList = document.getElementById("Search_CountiesDropDownList");
		var selectedCounty = countyList.options[countyList.selectedIndex].value;		
		if(selectedCounty != "")
			requestUrl += "&SelectedCounty=" + selectedCounty;
		
		if(selectedCity == "")
		{
			var cityList = document.getElementById("Search_SearchCity");
			selectedCity = cityList.options[cityList.selectedIndex].value;
		}
		if(selectedClient == "")
		{
			var clientList = document.getElementById("Search_SearchClient");
			selectedClient = clientList.options[clientList.selectedIndex].value;
		}
	
        if(selectedCity != "")
			requestUrl += "&SelectedCity=" + encodeURIComponent(selectedCity);
		if(selectedClient != "")
			requestUrl += "&SelectedClient=" +  encodeURIComponent(selectedClient);
		
		//alert("LoadCourse " + selectedCity + " " + selectedCounty + " " + selectedClient + " self: " + selectedValue);
		
        makeDropDownRequest(requestUrl,id,selectedValue);
	}
	
	
function ClearListAndDisplayLoading(course,client,city)
{
	var optionItem = new Option( "Laddar...", "",  false, false);
	var stateList;
	if(course)
	{
		stateList = document.getElementById("Search_SearchCourse");
			 
		for(var count = stateList.options.length-1; count >-1; count--)
				{
					stateList.options[count] = null;
				}
		stateList.options[0] = optionItem;
	
		optionItem = new Option( "Laddar...", "",  false, false);
	}
	if(client)
	{
		stateList = document.getElementById("Search_SearchClient");			 				
		for (var count = stateList.options.length-1; count >-1; count--)
			{
				stateList.options[count] = null;
			}
		stateList.options[0] = optionItem;
			//document.getElementById("Search_SearchClient").options[document.getElementById("Search_SearchClient").selectedIndex] = optionItem;
		
		optionItem = new Option( "Laddar...", "",  false, false);
	}
	if(city)
	{
		stateList = document.getElementById("Search_SearchCity");			 				
		for (var count = stateList.options.length-1; count >-1; count--)
					{
						stateList.options[count] = null;
					}
		stateList.options[0] = optionItem;
	}
}


	

	
	
