//   Copyright(c) 2003-2005 New Media Guru Ltd
//   email:alex@newmediaguru.com
//   window.onerror = null;

//get option value
function get_select_id(SelectField){

	//SelectField.options[SelectField.selectedIndex].value>0
	if(SelectField.selectedIndex<0)return false;
	if(SelectField.options[SelectField.selectedIndex]){
		return SelectField.options[SelectField.selectedIndex].value;
	}
	return false;
}

//active option
function select_field(SelectField,value){
	SelectField.options[value].selected=true;
	return true;
}

///find field in the select box
function find_field(SValue,SelectField){
	for(i=0;i<SelectField.length;i++){
		if(SelectField.options[i].value==SValue){
			return i;
		}
	}
	return false;
}//find field


function clear_select(sf){
	limit=0;
	if(arguments[1])limit=arguments[1];
	for(i=sf.options.length;i>=limit;i--){
		sf.remove(i);
	}
}

function fill_select(sf,array){
	for(i=0;i<array.length;i++){
		sf[sf.length]=new Option(array[i][0],array[i][1],array[i][2]);
	}
}

/*
find field in the select box
search_start
search_string
SValue - what to search
SelectField - select field
*/
var search_start=0;
var search_string='';

function search_option(SValue,SelectField){
	if((SelectField.length>0)&&(SValue.length>0)){
		if(search_string==SValue){
			search_start++;
		}else{
			search_start=0;
			search_string='';
		}
		for(i=search_start;i<SelectField.length;i++){
			if(SelectField.options[i].text.substr(0,SValue.length)==SValue){
				search_string=SValue;
				search_start=i;
				SelectField.options[i].selected=true;
				SelectField.focus();
				return true;
			};
		}
		if(search_string==SValue){
			search_start=0;
			search_string='';
			search_option(SValue,SelectField);
		}
		return false;
	}

}
