
// declare a global  XMLHTTP Request object
var XmlHttpObj;

// create an instance of XMLHTTPRequest Object, varies with browser type, try for IE first then Mozilla
function CreateXmlHttpObj()
{
	// try creating for IE (note: we don't know the user's browser type here, just attempting IE first.)
	try
	{
		XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpObj = null;
		}
	}
	// if unable to create using IE specific code then try creating for Mozilla (FireFox) 
	if(!XmlHttpObj && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttpObj = new XMLHttpRequest();
	}
}

function PopulateCity(searchstring) 
{
    
    var requestUrl;
    requestUrl = "../search-page/xml_data_provider.php?searchstring=" + searchstring;
	CreateXmlHttpObj();
	
	if (XmlHttpObj.readyState == 4 || XmlHttpObj.readyState == 0) 
	{
		XmlHttpObj.open("GET",requestUrl, true);
		XmlHttpObj.onreadystatechange = function () 
		{
		   if (XmlHttpObj.readyState == 4)
		   {
				var cityList = document.getElementById('searchcity');
			
				var cityNode = XmlHttpObj.responseXML.documentElement;
				var cityNodes = cityNode.getElementsByTagName('selection');
				var textValue; 
				var optionItem;
				
				cityList[cityList.selectedIndex].text="All Cities";
				// populate the dropdown list with data from the xml doc
				for (var count = 0; count < cityNodes.length; count++)
				{
			   		textValue = GetInnerText(cityNodes[count]);
					optionItem = new Option( textValue, textValue,  false, false);
					cityList.options[cityList.length] = optionItem;
				}
		   }
		}
		XmlHttpObj.send(null);
	}
}

// returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}


function PopulateList() 
{
	document.getElementById('pane300').innerHTML = '<p class="search_tool"><img src="../search-page/ajax_loader.gif" border="0" /></p><p class="search_tool">Loading MMA gyms... please be patient</p>';
    var requestUrl;
    var args=PopulateList.arguments;
    requestUrl = "../search-page/search_data.php";
    if (args.length>0)
    {
		for (var count = 0; count < args.length; count++)
		{
			if (count==0) requestUrl = requestUrl + "?searchstring=" + args[count];
			else if (count==1) requestUrl = requestUrl + "&searchcity=" + args[count];
		}
    }
    CreateXmlHttpObj();
	if (XmlHttpObj.readyState == 4 || XmlHttpObj.readyState == 0) 
	{
		XmlHttpObj.open("GET",requestUrl, true);
		XmlHttpObj.onreadystatechange = function () 
		{
		   if (XmlHttpObj.readyState == 4)
		   {
				var rr = XmlHttpObj.responseText;
				document.getElementById('pane300').innerHTML = rr;
		   }
		}
		XmlHttpObj.send(null);
	}
}