var NS4 = (document.layers) ? true : false;
var IE4 = (document.all) ? true : false;

function _struct(child, childcaption, parent) {
    this.child = child;
    this.childcaption = childcaption;
    this.parent = parent;
}
function _addobject(child, childcaption, parent) {
    var obj = new _struct();
    obj.child = child;
    obj.childcaption = childcaption;
    obj.parent = parent;
    return (obj);
}
function insertEntry(child, childcaption, parent) {
    if (child.length > 0) {
        for (var i = 0; i < this.length; i++)
            if (this.items[i].child == child)
            return;
        this.items[this.length++] = _addobject(child, childcaption, parent);
    }
}

function OptionCollection() {
    this.length = 0;
    this.items = new Object();
    this.Add = insertEntry
}
function clearSelect(oSelect) {
    var iCount = 0;
    if (!oSelect) return;
    iCount = oSelect.options.length;
    for (var i = 0; i < iCount; i++) {
        if (IE4)
            oSelect.options.remove(0);
        else if (NS4)
            oSelect.options[0] = null;
    }
}

function addOptions(oSelect,olist,parent){
	var elOption;
	var idxSelect=0;	

	//check arguments.
	if((!olist) || (!oSelect))return;		
	if(parent.length <=	0) 	return;
					
	//now looop through all the list items only entering relevant options.
	clearSelect(oSelect);	
	
	for(var i=0;i<olist.length;i++){		
		//only the child entries of the parent
				
		if(olist.items[i].parent == parent){
		    //elOption = new Option();
		    elOption = document.createElement('option');
			//now IE and NS have a different way to handle object creation.
			if(NS4){						
				elOption.value = olist.items[i].child
				elOption.text = olist.items[i].childcaption
				oSelect.options[idxSelect] = elOption				
			}else if(IE4){				
				elOption.value = olist.items[i].child
				elOption.text = olist.items[i].childcaption
				oSelect.options.add(elOption,idxSelect)					
			}						
			idxSelect++;
			delete(elOption);
		}			
	}	
}

function UpdateSelect(szSelect,szForm,szParent,olist){

addOptions(document.getElementById(szSelect),olist,szParent);

}
