// JavaScript Document

// Selections
function select_emptyList(field) {
  while (field.options.length) field.options[0] = null;
}

function select_fillList(field, arr) {
  // arr[0] --> text
  // arr[1] --> values
  for (i=0;i<arr[0].length;i++ ) {
	option = new Option(arr[0][i],arr[1][i] );
	field.options[field.length] = option;
  }
  field.selectedIndex=0;
}

function select_changeList(field, arr) {
  select_emptyList(field);
  select_fillList(field, arr);
}

function select_create(fieldName, arr, parentElem, afterElement, style, text) {
  if (text) {var span = document.createElement("span");}
  var selectBox = document.createElement("select");
  selectBox.setAttribute("name", fieldName);
  if (style) {selectBox.setAttribute("name", style);}
  select_fillList(selectBox, arr);
  if (text) {
	  span.appendChild(document.createTextNode(text));
	  span.appendChild(selectBox);		
	  parentElem.insertBefore(span,afterElement);
  }
  else {
      parentElem.insertBefore(selectBox,afterElement);
  }
}