var tdNode=document.getElementById("fun");
var node = document.getElementById("root");

if(node != null) { 
	node.onclick=selectIt;
	var data = obj.root.cat;
	node.options[node.options.length] = new Option("Select one",-1);
	for(i=0;i<data.length;i++) {
		var d = data[i];
		node.options[node.options.length] = new Option(d.title,d.id);
	} 
}

function selectIt() {
	var selNode=document.getElementById("s1");
	if(selNode!=null){
		tdNode.removeChild(selNode);
  }
  var id=this.options[this.options.selectedIndex].value;
  var o = obj.cat[id];
  if(o!=null && o.hasChild()){
		var sel= document.createElement("SELECT");
		sel.id="s1";
		sel.name="cat1";
		tdNode.appendChild(sel);
		if(this.options.selectedIndex>0) {
			nextData(this.options[this.options.selectedIndex].value,"s1");
		}
	}
	
}

function nextData(id,index) {
	var o;
	if(id==0) {
		o=obj.root; 
	} else {
		o = obj.cat[id];
	}
	if(o!=null &&o.hasChild()) {
		var n = document.getElementById(index);
		//alert(n);
		if(n != null) {
			n.options[n.options.length] = new Option("Select one",-1);
			var data = o.cat;
			if(index=="s1"){
					n.onclick=selectIt2;
		  }
		  
	    //alert(data.length);
			for(i=0;i<data.length;i++) {
					var d = data[i];
					if(d.hasChild()){
						n.options[n.options.length] = new Option(d.title,d.id);
					}
					else{
						n.options[n.options.length] = new Option(d.title,d.id);
					}
			}
			
		} 
	} 
}

function selectIt2() {
	var selNode=document.getElementById("s2");
	if(selNode!=null){
		tdNode.removeChild(selNode);
  }  	
}
