var emptySelect = '---';

function removeCSels(el) {
	var s = $(el.parentNode).getElements('select'), f = false;
	for(var i=0; i<s.length; i++) {
		if(el == s[i]) {
			f = true;
			continue;
		}
		if(f == true) s[i].parentNode.removeChild(s[i]);
	}	
}

function createCSelect(pid, el) {
	removeCSels(el);
	if(pid == 0 || el.options[el.selectedIndex].text == emptySelect) return;
	var o = [], os = new Element('select', {'name': 'category', 'onchange': 'createCSelect(this.options[this.selectedIndex].value, this);'});
	for(var i=0; i<cOptions.length; i++) if(cOptions[i].pid == pid) o.push(cOptions[i].o);
	if(o.length) {
		os.options.add(new Option(emptySelect, pid));
		for(var i=0; i<o.length; i++) os.options.add(o[i]);
		os.inject(el, 'after');
	}
}
