if(typeof FillSelect != 'function') { //controleer of functie al bestaat
	function FillSelect(selectId, xmlPage, params, emptyText)
	{
		var thisSelect = document.getElementById(selectId);
		var thisSelected = document.getElementById(selectId).value;
		thisSelect.options.length = 0; // empty select
		thisSelect.options[0] = new Option('gegevens ophalen...', '', false);

		// haal select gegevens op
		var xmlHttp = getXmlHttp();
		xmlHttp.open("POST", xmlPage, true);
		
		// Voor POST request zijn deze headers nodig
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200) // Ok
			{
				var xml = xmlHttp.responseXML;
				var item = xml.getElementsByTagName('item');
				
				thisSelect.options.length = 0; // empty select
				
				if (item.length > 0)
					thisSelect.options[0] = new Option(emptyText, '', false);

				var selectedOption = 0;
					
				for (i = 0; i < item.length; i++)
				{
					if (thisSelected == item[i].getElementsByTagName('id')[0].firstChild.nodeValue)
						selectedOption = i+1;
					thisSelect.options[i+1] = new Option(item[i].getElementsByTagName('text')[0].firstChild.nodeValue, item[i].getElementsByTagName('id')[0].firstChild.nodeValue, selectedOption);
				}
				
				if (item.length == 1)
					selectedOption = 1;

				thisSelect.selectedIndex = selectedOption;
				
				if ( (selectedOption > 0) && (thisSelect.onchange) )
					thisSelect.onchange();
			}
		}
		xmlHttp.send(params);
	}
}

if(typeof FillSelectModel != 'function') { //controleer of functie al bestaat
	function FillSelectModel()
	{
		var selectedId = document.getElementById('auto_fabrikant').value;
		document.getElementById('auto_bouwjaar').length = 0;
		document.getElementById('auto_aanduiding').length = 0;
		document.getElementById('auto_type').length = 0;
		
		FillSelect('auto_model', 'getxml/auto_model.php', 'f=' + selectedId, 'kies model');
	}
}

if(typeof FillSelectBouwjaar != 'function') { //controleer of functie al bestaat
	function FillSelectBouwjaar()
	{
		var selectedId = document.getElementById('auto_model').value;
		document.getElementById('auto_aanduiding').length = 0;
		document.getElementById('auto_type').length = 0;
				
		FillSelect('auto_bouwjaar', 'getxml/auto_bouwjaar.php', 'm=' + selectedId, 'kies bouwjaar');
	}
}

if(typeof FillSelectAanduiding != 'function') { //controleer of functie al bestaat
	function FillSelectAanduiding()
	{
		var selectedId = document.getElementById('auto_model').value;
		var bouwjaar = document.getElementById('auto_bouwjaar').value;
		document.getElementById('auto_type').length = 0;
				
		FillSelect('auto_aanduiding', 'getxml/auto_aanduiding.php', 'm=' + selectedId + '&b=' + bouwjaar, 'kies aanduiding');
	}
}

if(typeof FillSelectType != 'function') { //controleer of functie al bestaat
	function FillSelectType()
	{
		var selectedId = document.getElementById('auto_model').value;
		var bouwjaar = document.getElementById('auto_bouwjaar').value;
		var aanduiding = document.getElementById('auto_aanduiding').value;
				
		FillSelect('auto_type', 'getxml/auto_type.php', 'm=' + selectedId + '&b=' + bouwjaar + '&a=' + aanduiding, 'kies type');
	}
}

if(typeof selectSN != 'function') { //controleer of functie al bestaat
	function selectSN()
	{
		var selectedSN = document.getElementById('zoek_sn').value;
		if (selectedSN.length == 0)
			alert('Vul een serienummer in!');
		else
			location.href = 'serienummer.php?sn=' + selectedSN;
	}
}


if(typeof selectKentekenNr != 'function') { //controleer of functie al bestaat
	function selectKentekenNr()
	{
		var selectedKenteken = document.getElementById('auto_kenteken').value;
		if (selectedKenteken.length < 6)
			alert('Vul een Nederlands kenteken in!');
		else
			location.href = 'kenteken.php?k=' + selectedKenteken;
	}
}

if(typeof selectAutoNr != 'function') { //controleer of functie al bestaat
	function selectAutoNr()
	{
		var selectedId = document.getElementById('auto_type').value;
		if (selectedId.length == 0)
			alert('Selecteer eerst een voertuig!');
		else
			location.href = 'wielen.php?an=' + selectedId;
	}
}

if(typeof getListWheels != 'function') { //controleer of functie al bestaat
	function getListWheels()
	{
		var params = 'model=' + document.getElementById('wiel_model').value
			+ '&materiaal=' + document.getElementById('wiel_materiaal').value
			+ '&dia=' + document.getElementById('wiel_dia').value
			+ '&br=' + document.getElementById('wiel_br').value
			+ '&seizoen=' + document.getElementById('wiel_seizoen').value;
		
		if (document.getElementById('wiel_auto'))
			params = params + '&an=' + document.getElementById('wiel_auto').value;
		
		FillWithHtmlContent('overzicht', 'gethtml/wielen_overzicht.php', params, true);
	}
}

if(typeof getListTires != 'function') { //controleer of functie al bestaat
	function getListTires()
	{
		var params = 'merk=' + document.getElementById('band_merk').value
			+ '&seizoen=' + document.getElementById('band_seizoen').value
			+ '&code=' + document.getElementById('band_code').value;
		
		FillWithHtmlContent('overzicht', 'gethtml/banden_overzicht.php', params, true);
	}
}

if(typeof getListSets != 'function') { //controleer of functie al bestaat
	function getListSets()
	{
		var selectedAWB = document.getElementById('set_awb').value;
		if (selectedAWB.length == 0)
			alert('Selecteer eerst een banden maat!');
		else
		{
			var params = 'awb=' + selectedAWB
				+ '&aw=' + document.getElementById('set_aw').value
				+ '&merk=' + document.getElementById('set_merk').value
				+ '&seizoen=' + document.getElementById('set_seizoen').value;
			
			FillWithHtmlContent('overzicht', 'gethtml/setjes_overzicht.php', params, true);
	}
	}
}

if(typeof changeWW != 'function') { //controleer of functie al bestaat
	function changeWW(id, aantal)
	{
		var params = 'id=' + id	+ '&aantal=' + aantal;
			
		FillWithHtmlContent('winkelwagen', 'gethtml/winkelwagen_aanpassen.php', params, true);
	}
}

if(typeof SelectSelectedOption != 'function') { //controleer of functie al bestaat
	function SelectSelectedOption(selectContainer, optionValue)
	{
		for (var i = 0; i < selectContainer.options.length; i++)
		{
 			if (selectContainer.options[i].value == optionValue)
  				selectContainer.selectedIndex = i;
		}
	}
}