function clearModel() {
	if(typeof modelField_id == 'undefined') {
		return;
	}
	var el = document.getElementById(modelField_id);
	if(el) {
		el.options.length = 0;
		var option = document.createElement('option');
		option.value = '';
		option.appendChild(document.createTextNode('Kies eerst een merk'));
		el.appendChild(option);

		clearVariant('merk');
	}
}

function clearVariant(type) {
	if(typeof variantField_id == 'undefined') {
		return;
	}
	var el = document.getElementById(variantField_id);
	if(el) {
		el.options.length = 0;
		var option = document.createElement('option');
		option.value = '';

		if(type == null) {
			type = 'model';
		}

		option.appendChild(document.createTextNode('Kies eerst een '+ type));
		el.appendChild(option);

		clearSerie(type);
	}
}

function clearSerie(type) {
	if(typeof serieField_id == 'undefined') {
		return;
	}
	var el = document.getElementById(serieField_id);
	if(el) {
		el.options.length = 0;
		var option = document.createElement('option');
		option.value = '';

		if(type == null) {
			type = 'variant';
		}

		option.appendChild(document.createTextNode('Kies eerst een '+ type));
		el.appendChild(option);

		clearType(type);
	}
	if(setup == 'beheer_kortingen') {
		whf_setRequired(typeField_id, false);
	}
}

function clearType(type) {
	if(typeof typeField_id == 'undefined') {
		return;
	}
	var el = document.getElementById(typeField_id);
	if(el) {
		el.options.length = 0;
		var option = document.createElement('option');
		option.value = '';

		if(type == null) {
			type = 'serie';
		}

		option.appendChild(document.createTextNode('Kies eerst een '+ type));
		el.appendChild(option);
	}
}

function merkChanged(value) {
	if(value != '') {
		clearVariant();
		var el = document.getElementById(modelField_id);
		el.disabled=true;
		el.options.length = 0;
		var option = document.createElement('option');
		option.value = '';
		option.innerHTML = 'Selecteer...';
		el.appendChild(option);
		var j = 0;

		for(i in modellen[value]) {
			var option = document.createElement('option');
			option.value = i;
			option.innerHTML = modellen[value][i];
			el.appendChild(option);
			j++;
		}
		el.disabled=false;
		if(j == 1 && setup != 'beheer_kortingen' && setup != 'beheer_afleverpakketten' && setup != 'home' && typeof variantField_id != 'undefined') {
			el.value = i;
			modelChanged(i);
		}
		
	} else {
		clearModel();
	}
}

function modelChanged(value) {
	var make = document.getElementById(makeField_id);
	var el = document.getElementById(variantField_id);

	if(value != '') {
		clearSerie();
		el.disabled = true;
		var script = document.createElement('script');
		script.type = 'text/javascript';
		if(setup == 'dealers_aanbiedingen') {
			script.src = '/js/'+ make.value +'/'+ value +'/all/types.js';
		} else {
			script.src = '/js/'+ make.value +'/'+ value +'/types.js';
		}
		document.getElementsByTagName('head')[0].appendChild(script);
	} else {
		clearVariant();
	}
}

function updateVarianten(make_id, model_id) {
	var el = document.getElementById(variantField_id);
	el.options.length = 0;
	var option = document.createElement('option');
	option.value = '';
	option.innerHTML = 'Selecteer...';
	el.appendChild(option);
	var j = 0;
	for(i in varianten[make_id][model_id]) {
		var option = document.createElement('option');
		option.value = i;
		option.innerHTML = varianten[make_id][model_id][i];
		el.appendChild(option);
		j++;
	}
	if(j == 1 && setup != 'beheer_kortingen' && setup != 'beheer_afleverpakketten') {
		el.value = i;
		variantChanged(i);
	}
	el.disabled = false;
}

function variantChanged(value) {
	if(value != '') {
		clearType();
		var el = document.getElementById(serieField_id);
		el.options.length = 0;
		var option = document.createElement('option');
		var make_id = document.getElementById(makeField_id).value;
		var model_id = document.getElementById(modelField_id).value;
		var variant_id = document.getElementById(variantField_id).value;
		option.value = '';
		option.innerHTML = 'Selecteer...';
		el.appendChild(option);
		var j = 0;
		for(i in series[make_id][model_id][variant_id]) {
			var option = document.createElement('option');
			option.value = i;
			option.innerHTML = series[make_id][model_id][variant_id][i];
			el.appendChild(option);
			j++;
		}
		if(j == 1 && setup != 'beheer_kortingen') {
			el.value = i;
			serieChanged(i);
		}
	} else {
		clearSerie();
	}
}

function serieChanged(value) {
	if(value != '') {
		var el = document.getElementById(typeField_id);
		el.options.length = 0;
		var option = document.createElement('option');
		var make_id = document.getElementById(makeField_id).value;
		var model_id = document.getElementById(modelField_id).value;
		var variant_id = document.getElementById(variantField_id).value;
		var serie_id = document.getElementById(serieField_id).value;
		option.value = '';
		option.innerHTML = 'Selecteer...';
		el.appendChild(option);
		for(i in types[make_id][model_id][variant_id][serie_id]) {
			var option = document.createElement('option');
			option.value = i;
			option.innerHTML = types[make_id][model_id][variant_id][serie_id][i];
			el.appendChild(option);
		}
		if(setup == 'beheer_kortingen') {
			whf_setRequired(typeField_id, true);
		}
	} else {
		clearType();
	}
}

function load_photo(photo) {
	el = document.getElementById('photo_');
	el.src = photo;
}


function sendtoautotaxatie(id) {
	
var el = document.getElementById('');
	el.value = 'sendtoatn';
	

}


function setwaitform(frm,tp) {
	
	if(whf_checkForm(frm) != false) {
		document.getElementById('momentaub').className='momentaub_overlay';
		
		document.getElementById('momentaub').style.top = tp + 'px';
		
		
	}
	

}


function dropoffer(el,id) {
	var c = confirm('Wilt u deze offerte verwijderen ?');
	if(c == true) {
		window.location=location.href + '&drop='+id;
	}
	return false;

}

function meldaf(id) {
	window.location=location.href + '&bevestig=1';
}


