var selectedTop = 2;
var selectedChild = 8;

function appendOptionLast(obj, _titel, _value) {

	var elOptNew = document.createElement('option');
	elOptNew.text = _titel;
	elOptNew.value = _value;
	
	try {
	  obj.add(elOptNew, null); // standards compliant; doesn't work in IE
	}
	catch(ex) {
	  obj.add(elOptNew); // IE only
	}
}

function populateParent(selectedId) {
	var selected = 0;
	
	
	var selBox = document.getElementById('parent');
	var i=0;
	
	for (i=0; i<cats.length; i++) {
		
		if ( cats[i].parent ==  0 ) {
			
			appendOptionLast(selBox,cats[i].titel,cats[i].id);
			
			if (cats[i].id==selectedId) {
				selected = selBox.length-1;
				
			}
		}
	}
	/*alert(selectedId);
	
	alert(selBox.selectedIndex);*/
	
	selBox.selectedIndex=selected;	
/*document.getElementById('kategori[]').value=this.options[selBoxP.selectedIndex].value*/

	
}


function populateChild(parent, selectedId) {
	var selected = 0;
	var selBox = document.getElementById('child');
	
	
	var i=0;
	for (i=0; i<cats.length; i++) {
		
		if ( cats[i].parent ==  parent ) {
			appendOptionLast(selBox,cats[i].titel,cats[i].id);
			
			
			if (cats[i].id == selectedId) {
				selected = selBox.length-1;
								
			}
		}
	}		
	
	selBox.selectedIndex=selected;
document.getElementById('kategori[]').value=selBox.options[selBox.selectedIndex].value;
/*alert(selBox.options[selBox.selectedIndex].value);*/
}

function clearChild() {

	var selBox = document.getElementById('child');
	var selBoxP = document.getElementById('parent');

	while (selBox.length!=0) {
		selBox.remove(0);
	}
}

//used top copy the child selectboxe's valye to a category selectbox valye on change
function copyChildToCatIt() {
	
	childSel = document.getElementById('child');
	document.getElementById('catId').value=childSel.options[childSel.selectedIndex].value;
	
	
}
