var path = "ajax/treffpunkt_reload.php";
var selectsource = 0;
var selecttype = null;
var response = null;

function loadChildClasses(field, classId, type, source){
	
	what = 'loadchildclasses';
	var params ='classId='+classId+'&type='+type+'&what='+what;
	selecttype = type;
	selectsource = ++source;

	jQuery.ajax({
			type: 'POST',
			url: path,
			data: params,
			dataType: 'json',
			error: function(response) { },
			success: function(response){
				if (response[0] == what) {
					response.splice(0,1);
					fillChildSelect(response);
				}
			}
		});
	
}

function fillChildSelect(response){
	var option;
	var txt;
	var selectOther;

	var select = document.getElementById(selecttype+selectsource);

    if (selecttype == 'search_animal_race') {
        countSelects = 5;
    }
    else {
        countSelects = 4;
    }
    
	for(var k = selectsource; k <= countSelects; k++){
		selectOther = document.getElementById(selecttype+k);
        selectOtherLength = selectOther.length;

		for(var j = 0; j < selectOtherLength; j++){
			//selectOther.remove(0);
			selectOther.options[0] = null;
		}
		selectOther.style.display = 'none';
	}

	if(response.length > 1){
		select.style.display = 'block';

		var classesLength = response.length;
		var id;
		var name;
		var selectLength;

		/*for(var i = 0; i < classesLength - 2; i++){*/
		for(var i = 0; i < classesLength; i++){
			id = response[i][0];
			name = response[i][1];

			option = document.createElement("option");
        	option.setAttribute("value", id);
           	txt = document.createTextNode(name);
           	option.appendChild(txt);
			select.appendChild(option);
		}

		option = document.createElement("option");
		option.setAttribute("value", 0);
		txt = document.createTextNode("Suche weiter einschränken ?");
		option.appendChild(txt);
		select.appendChild(option);
		select.selectedIndex = select.length - 1;
	}
}