// Auswahlliste - Text aus TF ermitteln; passenden index selectbox anspringen

//representation of selectbox-values 
//in correct order
var arr=[];
	
/**
* init - build array containing all labels of select-box
*/
function init() {
	
	document.quickmenu.ip1.style.color = "#000000";
	document.quickmenu.enterButton.disabled=true;

	var i=0;
	while(document.quickmenu.id.options[i]){
		arr.push(document.quickmenu.id.options[i].text);
		i++;
	}
	
	document.quickmenu.ip1.focus();
};


/**
* try to select item in select-box (called TF.onKeyUp) 
*/
function selectItem(str) {
	
	var value=-1;
	if(str)
		value = getCurrentIndex(str);
	else
		value = getCurrentIndex(document.quickmenu.ip1.value);
 	
 	if(value>-1){
 		document.quickmenu.id.selectedIndex=value;
		document.quickmenu.ip1.style.color = "#000000";
		document.quickmenu.enterButton.disabled=false;


	}
 	else{
 		document.quickmenu.id.selectedIndex=0;//NEW
 		document.quickmenu.ip1.style.color = "#ff0000";
		document.quickmenu.enterButton.disabled=true;

 	}
};

/**
* compare passed string with indezes of array and return index
*/
function getCurrentIndex(str) {
	
	str=trim(str);
	for(var j=0; j<arr.length;j++){
		if( (arr[j].substring(0, str.length)).toLowerCase()==(str.substring(0, str.length)).toLowerCase() )
			return j;
	}
	return -1;
};

/**
* js-trim (r+l)
*/
function trim (str) {
	return str.replace (/^\s+/, '').replace (/\s+$/, '');
};

/** 
* only submit form, if a value in box was chosen
*/
function handleSubmit() {
	
	if(document.quickmenu.id.selectedIndex>0){
		return true;
	}
	
	return false;
};

