/*
Date: 20090604ZK
Purpose: provide functions for selectboxes
*/

var selectFunctions = {
	fill: function(selectId, valueArray, defaulttext){
		var selectbox;
		var optionvalue;
		var optiontext;
		
		selectbox = document.getElementById(selectId);
		
		if(selectbox){
			if (defaulttext){
				selectFunctions.addOption(selectbox,'',defaulttext);
			}
		
			if(valueArray){
				for(i=0;i<valueArray.length;i++){
					optionvalue = valueArray[i][0];
					optiontext = valueArray[i][1];
					selectFunctions.addOption(selectbox,optionvalue,optiontext);
				}
			}
		}
	},
	
	clear: function(selectId){
		var selectbox = document.getElementById(selectId);
		if (selectbox) {
			selectbox.options.length=0;
		}
	},
	
	addOption: function(selectbox,optionvalue,optiontext){
		var option;
		
		if (selectbox) {
			option = document.createElement("OPTION");
			selectbox.options.add(option);
			option.text = optiontext;
			option.value = optionvalue;
		}
	},
	
	value: function(selectId){
		var selectbox;
		var retval = null;
		
		selectbox = document.getElementById(selectId);
		
		if(selectbox){
			retval = selectbox.value;
		}
		
		return retval;
	}
};