var xmlHttp;
var iModelID;

function createXMLHttpRequest()
{
	if (window.ActiveXObject)
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest)
	{
		xmlHttp = new XMLHttpRequest();
	}
}

function startRequest(typenr)
{
	createXMLHttpRequest();
	
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("GET", "xmltypes.php?zoek="+typenr, true);
	xmlHttp.send(null);
}

function handleStateChange()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			var sel = document.getElementById('typeselect');
			var xmlDoc = xmlHttp.responseXML;
							
			clearTypes(sel);

			var types = xmlDoc.getElementsByTagName('type');

			for (var i = 0; i < types.length; i++)
			{
				type = types[i];
				
				naam = type.getElementsByTagName('name')[0].firstChild.nodeValue; 
				ID = type.getElementsByTagName('ID')[0].firstChild.nodeValue; 
				
				addOption(sel, ID, naam);
			}
		}
	}
}

function addOption(sel, ID, naam)
{
	var option = document.createElement('option');
	option.text = naam;
	option.value = naam;
	
	if (ID == iModelID)
	{
		option.selected = true;
	}
	
	  try {
	    sel.add(option, null); // standards compliant; doesn't work in IE
	  }
	  catch(ex) {
	    sel.add(option); // IE only
	  }
}

function clearTypes(sel)
{
	var a = sel.childNodes;
	
	while (sel.hasChildNodes())
	{
		sel.removeChild(a[0]);
	}				
}
