

/**
* Select Hierarchy class
*/
	function SelectHierarchy() {
	
		this.depends = new Array();
		this.arrayval = new Array();
		
	}
	
	SelectHierarchy.prototype.getValueArray = function () {
		return this.arrayval;
	}
	
	SelectHierarchy.prototype.addDepends = function (child, parent) {
		
		this.depends[child] = parent;
		this.arrayval[child] = new Array();
		
	}
	
	SelectHierarchy.prototype.addKeyFilterValue = function (parent, key, filter, value) {
		
		var tempA = new Array(filter, value);
		this.arrayval[parent][key] = tempA;
		
	}

	SelectHierarchy.prototype.changeChildren = function (parent) {
		
		var box = document.getElementById(parent);
		
		if(box) {
			
			var child;
			for(child in this.depends) {
				if(this.depends[child] == parent) {
					
					if(box.selectedIndex>=0) {
						var val = box.options[box.selectedIndex].value;
						
						this.removeOptions(child);
						this.addOptions(child, val)
						
						this.changeChildren(child);
					}else{
						this.removeOptions(child);
						this.changeChildren(child);
					}
					
				}
			}
		}
		
	}
	
	SelectHierarchy.prototype.removeOptions = function (child) {
		
		var box = document.getElementById(child);
		var len = box.options.length;
		while(len>0) {
			len--;
			box.remove(len);
		}
		
	}
	
	SelectHierarchy.prototype.addOptions = function (child, val) {
		
		var box = document.getElementById(child);
		var i = 0;
		
		for(obj in this.arrayval) {
			if(obj==child) {
			 
				for(key in this.arrayval[obj]) {
					if(this.arrayval[obj][key][0]==val) {
					 	//alert(key.substring(val.length+1,key.length));
					 	var newkey = key;// key.substring(val.length+1);
					 	box.options[i] = new Option(this.arrayval[obj][key][1],newkey);
					 	i++
					}
					
				}			 
			 
			}
			
		}
		
	}
	
	function changeChildren(objname, parent) {
		eval("x='"+parent+"';"+objname+".changeChildren(x);");
	}
	
