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('loading...', '', 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(text)
	{
		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, text);
	}
}

if(typeof FillSelectBouwjaar != 'function') { //controleer of functie al bestaat
	function FillSelectBouwjaar(text)
	{
		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, text);
	}
}

if(typeof FillSelectAanduiding != 'function') { //controleer of functie al bestaat
	function FillSelectAanduiding(text)
	{
		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, text);
	}
}

if(typeof FillSelectType != 'function') { //controleer of functie al bestaat
	function FillSelectType(text)
	{
		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, text);
	}
}

if(typeof selectKentekenNr != 'function') { //controleer of functie al bestaat
	function selectKentekenNr(f, so, m, text)
	{
		var selectedKenteken = document.getElementById('auto_kenteken').value;
		if (selectedKenteken.length < 6)
			alert(text);
		else
			location.href = 'voertuig.php?f=' + f + '&so=' + so + '&m=' + m + '&k=' + selectedKenteken;
	}
}

if(typeof selectAutoNr != 'function') { //controleer of functie al bestaat
	function selectAutoNr(f, so, text)
	{
		var selectedId = document.getElementById('auto_type').value;
		if (selectedId.length == 0)
			alert(text);
		else
			location.href = f+'.php?so=' + so + '&an=' + selectedId;
			
		return false;
	}
}

if(typeof getListWiel != 'function') { //controleer of functie al bestaat
	function getListWiel(so, an)
	{
		var params = 'dia=' + document.getElementById('wiel_dia').value;
		
		if (document.getElementById('wiel_model'))
			params += '&model=' + document.getElementById('wiel_model').value
			
		if (document.getElementById('wiel_seizoen'))
			params += '&seizoen=' + document.getElementById('wiel_seizoen').value;

		if (document.getElementById('wiel_br'))	
			params += '&br=' + document.getElementById('wiel_br').value;

		if (document.getElementById('wiel_bg'))	
			params += '&bg=' + document.getElementById('wiel_bg').value;
		
		if (document.getElementById('wiel_st'))
			params += '&st=' + document.getElementById('wiel_st').value;
		
		params = params + '&so=' + so + '&an=' + an;

		FillWithHtmlContent('tabel', 'gethtml/select_wiel.php', params, true);
		
		return false;
	}
}

if(typeof getListBand != 'function') { //controleer of functie al bestaat
	function getListBand(so)
	{
		var params = 'code=' + document.getElementById('band_code').value;
		
		var merken = document.getElementsByName('band_merk');
		for (var i=0; i < merken.length; i++)
			if (merken[i].checked)
				params += '&merk[]=' + merken[i].value;
		
		params = params + '&so=' + so;
		
		FillWithHtmlContent('tabel', 'gethtml/select_band.php', params, true);
		
		return false;
	}
}

if(typeof getListToebehoren != 'function') { //controleer of functie al bestaat
	function getListToebehoren(so)
	{
		var params = 'so=' + so;
		if (document.getElementById('toebehoren_merk'))
			params += '&merk=' + document.getElementById('toebehoren_merk').value;
		if (document.getElementById('toebehoren_draad'))
			params += '&draad=' + document.getElementById('toebehoren_draad').value;
		if (document.getElementById('toebehoren_kopvorm'))
			params += '&kopvorm=' + document.getElementById('toebehoren_kopvorm').value;
		if (document.getElementById('toebehoren_gewicht'))
			params += '&gewicht=' + document.getElementById('toebehoren_gewicht').value;
		
		FillWithHtmlContent('tabel', 'gethtml/select_toebehoren.php', params, true);
	}
}

if(typeof getListAutoWielBandenmaat != 'function') { //controleer of functie al bestaat
	function getListAutoWielBandenmaat(an)
	{
		var params = 'soort=' + document.getElementById('soort').value
			+ '&dia=' + document.getElementById('dia').value
			+ '&seizoen=' + document.getElementById('seizoen').value
			+ '&band=' + document.getElementById('band').value
			+ '&bo1=' + ((document.getElementById('band_omschrijving1').checked)? '1': '0');

		params = params + '&an=' + an;

		FillWithHtmlContent('tabel', 'gethtml/select_auto_wiel_bandenmaat.php', params, true);
		
		return false;
	}
}

if(typeof getListAutoWielBand != 'function') { //controleer of functie al bestaat
	function getListAutoWielBand(awb, s)
	{
		var params = 'awb=' + awb;
		
		var merken = document.getElementsByName('band_merk');
		for (var i=0; i < merken.length; i++)
			if (merken[i].checked)
				params += '&merk[]=' + merken[i].value;
		if (s == -1)
			params += '&seizoen=' + document.getElementById('band_seizoen').value;
		else
			params += '&seizoen=' + s;
		
		FillWithHtmlContent('tabel', 'gethtml/select_auto_wiel_band.php', params, true);
		
		return false;
	}
}

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, false);
	}
}

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;
		}
	}
}

if(typeof FillAddress != 'function') { //controleer of functie al bestaat
	function FillAddress(adresString)
	{
		var name = '';
		var name2 = '';
		var contact = '';
		var address1 = '';
		var address2 = '';
		var country = '';
		
		adresArr = adresString.split(';');
		if (adresArr.length == 6)
		{
			name = adresArr[0];
			name2 = adresArr[1];
			contact = adresArr[2];
			address1 = adresArr[3];
			address2 = adresArr[4];
			country = adresArr[5];
		}
		
		document.getElementById('f_naam').value = name;
		document.getElementById('f_naam2').value = name2;
		document.getElementById('f_contact').value = contact;
		document.getElementById('f_adres1').value = address1;
		document.getElementById('f_adres2').value = address2;
		document.getElementById('f_land').value = country;
	}
}
