var threshold = 20;	// level to switch text to white - range 0 -> 27
function endoption(ref){
  var select = document.getElementById('sel-' + ref);		// the SELECT statement
  for ( var i = 0; i < select.options.length; i++)
    {
    var thisoption = select.options[i];
    var bits = thisoption.text.match(/(.*)(#\w{6})(.*)/);	// have we a #rrggbb
    if ( bits != null )
      {
      var rgbs = bits[2].match(/(\d).(\d).(\d)./);		// get most sig. rgb digits
      if (rgbs != null) 
        {
        if ( ((rgbs[1] - 0) + (rgbs[2] - 0) + (rgbs[3] - 0)) <= threshold ) thisoption.style.color = 'white';
        } 
      thisoption.text = bits[1] + bits[3];			// remove the #rrggbb code
      thisoption.style.backgroundColor = bits[2];
      }
    }
}
