/**
 * Will show label for selected checkbox as bold text. Other labels with 
 * same prefix in ID will be turned to normal text.
 */
function changeOnlySelected(radio_button, show, hide, prefix) {
 
 if (radio_button.checked) {
   if (show != null) {
      Element.show(show);
      var label = prefix + '_'  + show + '_label';
      $(label).style.fontWeight = 'bold';
   } else {
      var label = prefix + '_none_label';
      $(label).style.fontWeight = 'bold';
   }
   
   if (hide instanceof Array) {
     hide.each(function(element) {
       if (element != 'none') Element.hide(element);
       var label = prefix + '_'  + element + '_label';
       $(label).style.fontWeight = 'normal';
     });
   } else {
     Element.hide(hide);
     var label = prefix + '_'  + hide + '_label';
     $(label).style.fontWeight = 'normal';
   }
   
 }
} //changeOnlySelected()

/**
 * Insert item from select box to textarea to selected position
 */
function insertItem(textarea, selectA) {
  
  // make sure it's object
  if (textarea instanceof String) {
    textarea = $(textarea);
  }
  
  var option = selectA.options[selectA.selectedIndex];
  var item = option.value;
  
  //IE support
  if (document.selection) {
    var temp;
    textarea.focus();
    sel = document.selection.createRange();
    temp = sel.text.lenght;
    sel.text = item;
    if (item.length == 0) {
      sel.moveStart('character', item.length);
      sel.moveEnd('character', item.length);
    } else {
      sel.moveStart('character', -item.length + temp);
    }
    sel.select();
  }
  //MOZILLA/NETSCAPE support
  else if (textarea.selectionStart || textarea.selectionStart == '0') {
    var startPos = textarea.selectionStart;
    var endPos = textarea.selectionEnd;
    textarea.value = textarea.value.substring(0, startPos) + item + textarea.value.substring(endPos, textarea.value.length);
    textarea.focus();
    textarea.selectionStart = startPos + item.length;
    textarea.selectionEnd = startPos + item.length;
  } else {
    textarea.value += item;
  }
  
} //insertItem()

function checkConditions(selectA) {
  
  var option = selectA.options[selectA.selectedIndex];
  
  switch (option.value) {
    case (option.value = 'BINARY_CONDITIONS'):
      Element.show('params');
      Element.show('binary_items');
      Element.show('binary_items_name');
      Element.hide('param_values');
      Element.hide('param_values_name');
    break
    case (option.value = 'CAR_INSIDE'):
    case (option.value = 'CAR_OUTSIDE'):
    case (option.value = 'CAR_LEFT'):
    case (option.value = 'CAR_ENTER'):
      Element.hide('params');
    break
    default:
    case (option.value = 'MAX_SPEED'):
    case (option.value = 'MIN_SPEED'):
      Element.show('params');
      Element.show('param_values');
      Element.show('param_values_name');
      Element.hide('binary_items');
      Element.hide('binary_items_name');
    break
  }
  
} //checkConditions()

function loadScript(scriptpath){
    var oXML = getXMLHttpObj();
    oXML.open('GET', scriptpath, false);
    oXML.send('');
    eval(oXML.responseText);
}
