function hideElementById(id){
  document.getElementById(id).className = 'hidden';
}

function showElementById(id, className){
  document.getElementById(id).className = className;
}

function setVisibilityElementRelatedToCheckbox(elementId, checkboxId, showIfChecked){
  if(document.getElementById(checkboxId).checked){
    if(showIfChecked){
      showElementById(elementId, '');
    }else{
      hideElementById(elementId);
    }
  }else{
   if(showIfChecked){
     hideElementById(elementId);
    }else{
     showElementById(elementId, '');
    }
  }
}

function findElementInArray(arr, element) {
  var index = 0;
  while (index < arr.length) {
    if (arr[index] == element) return true;
    index++
  }
  return false;
}

function goToNextInput(currentInput, nextInputId, e) {
  var funcKeys = [0,8,9,16,17,18,37,38,39,40,46];
  if (e.keyCode && !findElementInArray(funcKeys, e.keyCode))
    if (currentInput.value.length >= currentInput.getAttribute('maxlength'))
      document.getElementById(nextInputId).focus();
}

function disableElementRelatedToInput(elementId, inputId, messageId, isError){
  var elementClass = '';
  if (isError) {
    elementClass = 'red3';
  }
  if (document.getElementById(inputId).value == '') {
    document.getElementById(elementId).disabled = 'disabled';
    showElementById(messageId, elementClass);
  } else {
    document.getElementById(elementId).disabled = '';
    hideElementById(messageId);
  }
}

function disableElement(elementId){
  document.getElementById(elementId).disabled='disabled';
}

function selectValue(selectId, setValue){
  select = document.getElementById(selectId);
  for(var i=0; i<select.options.length; i++){
    if(select.options[i].value == setValue){
      select.selectedIndex = i;
    }
  }
}

function sendEvent(eventName) {
  element = document.getElementById('eventId');
  element.value = eventName;
  element.form.submit();
}

// Array.push and Array.unshift are required for proper IE5 and DWR cooperation :)
// Array.push() - Add an element to the end of an array, return the new length
if (typeof Array.prototype.push === 'undefined') {
  Array.prototype.push = function() {
    for (var i = 0, b = this.length, a = arguments, l = a.length; i<l; i++) {
      this[b+i] = a[i];
    }
    return this.length;
  };
}

// Array.unshift() - Add an element to the beginning of an array
if (typeof Array.prototype.unshift === 'undefined') {
  Array.prototype.unshift = function() {
    this.reverse();
    var a = arguments, i = a.length;
    while(i--) { this.push(a[i]); }
    this.reverse();
    return this.length;
  };
}


