var fldFocus;

function SetFocus() {
  if (!fldFocus) {
    return;
  }
  switch (fldFocus.type) {
    case "select-multiple":
    case "select": 
      fldFocus.focus();
      break;
    case "text":
    case "textarea":
    case "password":
      fldFocus.focus();
      fldFocus.select();
      break; 
    default:
      break; 
  }  
}

function ConfirmCommand(txt,ctx) {
  if (typeof(ctx) != 'undefined') {
    if (ctx != '') { 
      return (confirm(ctx+'\n\nWollen Sie das Kommando "'+txt+'" wirklich ausführen?'))
    } else {
      return (confirm('Wollen Sie das Kommando "'+txt+'" wirklich ausführen?'))
    }  
  } else {
    return (confirm('Wollen Sie das Kommando "'+txt+'" wirklich ausführen?'))
  }
}

function ExecuteCommand(fld, win) {
  if (fld.options[fld.selectedIndex].value != '') {
    if (fld.options[fld.selectedIndex].value.charAt(0) == "@") {
      if (confirm('Wollen Sie das Kommando "'+fld.options[fld.selectedIndex].text+'" wirklich ausführen?')) {
        win.location.href = fld.options[fld.selectedIndex].value.slice(1)
      }
    } else {
      win.location.href = fld.options[fld.selectedIndex].value
    }  
  }
}

function GotoURL(fld, win) {
  if (fld.options[fld.selectedIndex].value != '') {
    win.location.href = fld.options[fld.selectedIndex].value
  }
}

function CheckNumber(fld, decpoint, minval, maxval, fldname)
{
  var checkOK = "0123456789-";
  var checkStr = fld.value;
  var allValid = true;
  var allNum = "";
  
  if (decpoint) {
    checkOK += ".,";
  }
  
  for (i=0; i<checkStr.length; i++) {
    ch = checkStr.charAt(i);
    for (j=0; j<checkOK.length; j++)
      if (ch==checkOK.charAt(j))
        break;
    if (j==checkOK.length) {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid) {
    if (!decpoint)
      alert("Geben Sie nur ganze Zahlen in das Feld '"+fldname+"' ein.");
    else 
      alert("Geben Sie nur Zahlen mit oder ohne Dezimalpunkt in das Feld '"+fldname+"' ein.");
    return (false);
  }
  
  var chkVal = allNum;
  if (chkVal != "") {
    var prsVal = parseFloat(allNum);
    if (minval != "") {
      var prsMin = parseFloat(minval)
      if (prsVal < prsMin) {
        alert("Geben Sie einen Wert größer oder gleich "+minval+" in das Feld '"+fldname+"' ein.");
        return (false);
      }	
    }
    if (maxval != "") {
      var prsMax = parseFloat(maxval)
      if (prsVal > prsMax) {
        alert("Geben Sie einen Wert kleiner oder gleich "+maxval+" in das Feld '"+fldname+"' ein.");
        return (false);
      }	
    }
  }

  return (true);
}

function CheckLength(fld, minval, maxval, fldname)
{
  var checkStr = fld.value;
  if (minval != "") {
    var prsMin = parseFloat(minval)
    if ((checkStr.length == 0) & (prsMin > 0)) {
      alert("Geben Sie einen Wert in das Feld '"+fldname+"' ein.");
      return (false);
    }
    if (checkStr.length < prsMin) {
      alert("Geben Sie einen Wert der länger oder gleich "+minval+" Zeichen lang ist in das Feld '"+fldname+"' ein.");
      return (false);
    }	
  }
  if (maxval != "") {
    var prsMax = parseFloat(maxval)
    if (checkStr.length > prsMax) {
      alert("Geben Sie einen Wert der kürzer oder gleich "+maxval+" Zeichen lang ist in das Feld '"+fldname+"' ein.");
      return (false);
    }	
  }

  return (true);
}