function changeStyle(element, property, value){
  //alert("change "+ element+"-"+property+" to "+value)
  if(property.indexOf("-") != -1){
    var propArr = property.split("-");
    property = propArr[0]+propArr[1].substr(0,1).toUpperCase()+propArr[1].substr(1);
  }
  if(document.getElementById){
    if(document.getElementById(element)){
      document.getElementById(element).style[property] = value;
    }
  }
  else if(document.all){
    if(document.all[element]){
      document.all[element].style[property] = value;
    }
  }
}

function openWindow(url, t, width, height, properties){
  //fullsize options
  var widthStr = ""+width+"";
  var heightStr = ""+height+"";
  if(widthStr.indexOf("%") != -1){
    width = screen.availWidth * parseInt(width) / 100;
  }
  if(heightStr.indexOf("%") != -1){
    height = screen.availHeight * parseInt(height) / 100;
  }
  var left = screen.width/2 - width/2;
  var top = screen.height/2 - height/2;
  var props = "left="+left+", top="+top+", width="+width+", height="+height+", "+properties;
  win = window.open(url, t, props);
}

function confirmLink(link, text){
  if(confirm(text)){
    self.location.href = link;
  }
}

function submitForm(action, method){
  document.forms[0].method = method;
  document.forms[0].action = action;
  document.forms[0].submit();
}

function commaKiller(elem){
  var re = /,/g
  var newVal = f.elements[elem].value;
  newVal = newVal.replace(re, ".");
  newVal = parseFloat(newVal);
  f.elements[elem].value = newVal;
  return newVal;
}

function calendarChooseDay(date, value, dateField, valueField){
  if(document.getElementById(dateField)){
    document.getElementById(dateField).value = date;
  }
  if(document.getElementById(valueField)){
    document.getElementById(valueField).value = value;
  }
}

function moveOption(f,bDir,sName){
  var el = f.elements[sName];
  var idx = el.selectedIndex;
  if(idx==-1){
    alert("keine auswahl");
  }
  else{
    if(bDir == "top"){
      for(i=0;i<idx;i++){
        moveOption(f,'up', sName);
      }
      var nxidx = 0;
      idx = 0;
    }
    if(bDir == "bottom"){
      var distance = (el.length-1) - idx;
      for(i=0;i<distance;i++){
        moveOption(f,'down', sName);
      }
      var nxidx = el.length-1;
      idx = nxidx;
    }

    if(bDir == "up"){
      nxidx = (idx - 1);
    }
    if(bDir == "down"){
      nxidx = (idx + 1);
    }

    if(nxidx<0){
      nxidx = 0;
    }
    if(nxidx>=el.length){
      nxidx = el.length-1;
    }
    var oldVal = el[idx].value;
    var oldText = el[idx].text;
    el[idx].value = el[nxidx].value;
    el[idx].text = el[nxidx].text;
    el[nxidx].value = oldVal;
    el[nxidx].text = oldText;
    el.selectedIndex = nxidx;
  }
}

function hideSelectBoxes(reverse, ignore){
  for(var i=0; i<document.forms.length; i++){
    var f = document.forms[i];
    //loop thru elements
    for(var a = 0; a < f.elements.length; a++){
      var e = f.elements[a];
      var t = e.type.toUpperCase();
      if(t.indexOf("SELECT") != -1 && e.name != ignore && e.name.indexOf("[NEW]") == -1){
        if(reverse){
          e.style.visibility = "visible";
        }
        else{
          e.style.visibility = "hidden";
        }
      }
    }
  }
}