// JavaScript Document

$(document).ready(function() {
	if(document.getElementById('location')){
		getDealers('location');
	}
})

//id van selectbox waarin items geplaatst moeten worden
function getDealers(mode){
	//haal (optioneel) geselecteerde city op
	var q = '';
	q = '?country=' + $('#country').val();
	if(mode=='dealer'){q += '&city=' + $('#location').val()}
	//haal xml op en plaats deze in selectbox
	$.ajax({
		type: "GET",
		url: PROJECT_URL + 'wkactie/xml/dealers.xml.asp' + q,
		dataType: "xml",
		success: function(xml){
			if(mode=='dealer'){
				FillDealers(xml)
			}else{
				FillCity(xml);
			}
		}
	});
}

function FillCity(xml) {
	var selectbox=document.getElementById("location");
	selectbox.options.length=1;
	$(xml).find("item").each(function() {
		selectbox.options[selectbox.options.length]=new Option($(this).find("city").text(),$(this).find("city").text());
	});
	var selectboxdealer=document.getElementById("dealer");
	selectboxdealer.options.length=1;
}

function FillDealers(xml) {
	var selectbox=document.getElementById("dealer");
	selectbox.options.length=1;
	$(xml).find("item").each(function() {
		selectbox.options[selectbox.options.length]=new Option($(this).find("name").text(),$(this).attr("id"));
	});
}

function goto(e, nr){
	if($('#code'+nr).val().length == 3) {
		if(nr<4){ $('#code'+(nr+1)).focus(); }
	}
}