function SwitchMenu(obj) {
  if (document.getElementById) {
    var el = document.getElementById(obj);
    var ar = document.getElementById("masterdiv").getElementsByTagName("span");
    if (el.style.display != "block") {
      for (var i = 0; i < ar.length; i++) {
        if (ar[i].className == "submenu")
        ar[i].style.display = "none";
      } //for
      el.style.display = "block";
    } //if
    else {
      el.style.display = "none";
    } //else
  } //if
} //function SwitchMenu;

/**
 * Sprawdza poprawnosc rozszerzenia wybranych plikow przy pomocy <input type="file" .. />
 *
 * Pomocnicza funkcja LimitAttach:
 * @param  object  formularz
 * @param  string  wartosc <input type="file" ... />
 *
 * @return boolean jezeli rozszerzenie wybranego pliku zgodne z podanym w tablicy extArray zwraca false
 *
 * Funkcja SprawdzRozszerzenie:
 * @param  object  formularz
 * @param  string  nazwa elementu <input name="nazwa1">
 * @param  integer ilosc elementow <input> o nazwach "nazwa1 - nazwa+ilosc" (parametr moze byc pusty)
 *
 * @return boolean jezeli wszystkie rozszerzenia sa dobre zwraca true
 */
extArray = new Array(".jpg", ".bmp", ".png", ".gif", ".jpeg");

function LimitAttach(form, file) {
  allowSubmit = false;
  if (!file) return;

  while (file.indexOf("\\") != -1)
    file = file.slice(file.indexOf("\\") + 1);
  ext = file.slice(file.indexOf(".")).toLowerCase();
  for (var i = 0; i < extArray.length; i++) {
    if (extArray[i] == ext) { allowSubmit = true; break; }
  } //for
  
  if (allowSubmit)
    return false;
  else
    return true;
} //function LimitAttach

function SprawdzRozszerzenie(form, nazwa, ilosc) {
  WszystkoOK = true;
  if (!ilosc) ilosc = 1;

  for (var i = 1; i <= ilosc; i++) {
    if (ilosc == 1) nazwa_obj = nazwa;
    else nazwa_obj = nazwa+i;
    
    if (form[nazwa_obj]) {
      if (LimitAttach(form, form[nazwa_obj].value)) { WszystkoOK = false; };
    } //if
  }//for
  
  if (WszystkoOK)
    return true;
  else
    return false;
} //function SprawdzRozszerzenie

/**
 * Displays an error message if an element of a form hasn't been completed and
 * should be
 *
 * @param   object   the form
 * @param   string   the name of the form field to put the focus on
 *
 * @return  boolean  whether the form field is empty or not
 */
function emptyFormElements(theForm, theFieldName, Komunikat)
{
    var isEmpty  = 1;
    var theField = theForm.elements[theFieldName];
    // Whether the replace function (js1.2) is supported or not
    var isRegExp = (typeof(theField.value.replace) != 'undefined');

    if (!isRegExp) {
        isEmpty      = (theField.value == '') ? 1 : 0;
    } else {
        var space_re = new RegExp('\\s+');
        isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
    }
    if (isEmpty) {
        // theForm.reset();
        theField.select();
        alert(Komunikat);
        theField.focus();
        return false;
    }

    return true;
} // end of the 'emptyFormElements()' function
