function createRequestObject()
{
   var req;

   if(window.XMLHttpRequest)
   {
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   }
   else if(window.ActiveXObject)
   {
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
      if(! req)
      {
      		req = new ActiveXObject("Msxml2.XMLHTTP")
      }

   }
   else
   {
      // There is an error creating the object,
      // just as an old browser is being used.
      alert('Problem creating the XMLHttpRequest object');
   }

   return req;
}

// Make the XMLHttpRequest object
var http = createRequestObject();
var http2 = createRequestObject();

function sendRequest(network)
{
	// Open PHP script for requests
   //http.abort; took this out because it caused function to fail in IE
   http.open('get', 'get_drops.php?network='+network);
   http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   http.onreadystatechange = handleResponse;
   http.send(null);

}

function handleResponse()
{
	try
	{
		  if(http.readyState == 4)
		  {
		  	  if(http.status == 200)
		  	  {
		  	  	  // Text returned FROM the PHP script
			      var response = http.responseText;

			      if(response != null)
			      {
			      	if (response.indexOf('invalid') == -1)
			      	{
				      // Split the comma delimited response into an array
				      response = response.split(",");
			      	}

			      createOpts(response);

			      }
		  	   }
		  	   else
		  	   {
		  	    	alert("Error: A problem occurred during communication with the server."+http.status);
		  	   }
		  }

	}
	catch(err)
	{
		alert("Error2: "+err.message + " " + http.readyState);
	}
}

function createOpts(obj)
{
	var _div = document.getElementById("provider");
	var el;

	//first remove all existing options
	while(_div.hasChildNodes())
	{
		for(var i=0; i < _div.childNodes.length; i++)
		{
			_div.removeChild(_div.firstChild);
		}
	}
	if(obj != '')
	{
		//create the first element in the drop-down
		//format is Option(display text, value)
		_div.options[_div.length] = new Option("- Select One -","");

		for(q=0;q<obj.length;q++)
		{
		   //add each option to the drop-down
		   //format is Option(display text, value)
		   _div.options[_div.length] = new Option(obj[q+1],obj[q]);
		   //add one extra to the q value so that the next option will begin at the
		   //value for the next option
		   q=q+1;
		}
	}
	else
	{
		//create the first element in the drop-down
		//format is Option(display text, value)
		_div.options[_div.length] = new Option("* - Select Network First -","");
	}
}
