/* Global Varriables */
var pop_win_params = 'directories=no,location=no,menubars=no,menubar=no,resizable=yes,scrollbars=yes,statusbars=yes,status=no,titlebar=yes,toolbar=no,fullscreen=no'; 
var pop_win_calendar_params = 'directories=no,location=no,menubars=no,menubar=no,resizable=no,scrollbars=no,statusbars=yes,status=no,titlebar=yes,toolbar=no,fullscreen=no'; 
var pop_win_time_params = 'directories=no,location=no,menubars=no,menubar=no,resizable=no,scrollbars=no,statusbars=no,status=no,titlebar=yes,toolbar=no,fullscreen=no'; 
var active_color_row = '#000084';
// pagecode - nazev vytvoreneho popup okna
var pagecode = "new window";
var str_div_invisible = "none";
var str_div_visible   = "inline";
var last_layer_name = "";

/* Funkce pro otevreni ciselniku projektu */
function ShowCodeProjects(URL) {
  if (URL != null) {
    ShowTable(URL, 500, 300);
  }
}

/* Funkce pro otevreni ciselniku zakazek */
function ShowCodeProjGroups(URL) {
  if (URL != null) {
    ShowTable(URL, 300, 300);
  }
}

/* Funkce pro otevreni ciselniku stredisek */
function ShowCodeDepartments(URL) {
  if (URL != null) {
    ShowTable(URL, 200, 300);
  }
}

/* Funkce pro otevreni ciselniku dotazniku */
function ShowCodeProjQuests(URL) {
  if (URL != null) {
    ShowTable(URL, 200, 300);
  }
}

/* Funkce pro otevreni ciselniku cinnosti dotazniku */
function ShowCodeQuestActivities(URL) {
  if (URL != null) {
    ShowTable(URL, 200, 300);
  }
}

/* Funkce pro otevreni ciselniku zamestnancu */
function ShowCodeEmployees(URL) {
  if (URL != null) {
    ShowTable(URL, 300, 300);
  }
}

/* Funkce pro otevreni ciselniku kodu banky */
function ShowCodeBankCode(URL) {
  if (URL != null) {
    ShowTable(URL, 300, 300);
  }
}

/* Funkce pro otevreni ciselniku kontaktnich osob dane firmy */
function ShowCodeContacts(URL) {
  if (URL != null) {
    ShowTable(URL, 400, 300);
  }
}

/* Funkce pro otevreni ciselniku firem */
function ShowCodeCompanies(URL) {
  if (URL != null) {
    ShowTable(URL, 500, 400);
  }
}

/* Funkce pro zobrazeni ciselniku pro vyber datumu 
   -----------------------------------------------
   Vstup: URL - nazev stranky pro window.open, vcetne parametru 'field_id' - jmeno prvku, 
                do ktereho se musi naplnit hodnota z kalendare.
          Priklad URL: calendar.htm?field_id=datum
                  Otevre stranku kalendare a do pole 'datum' naplni vybranne datum.
*/
function ShowCodeDate(URL) {
  if (URL != null) {
    ShowTable(URL, 350, 196, pop_win_calendar_params);
  }
}

/* Funkce pro zobrazeni ciselniku pro cas */
function ShowCodeTime(URL) {
  if (URL != null) {
    //ShowTable(URL, 200, 100, pop_win_time_params);
    okno = popWin(URL, 200, 100, 'pagecode', 'pagecode_window', pop_win_time_params);
    okno.focus();
  }
}

/* Funkce pro otevření okna detailu pro kontakty (modul contacts) - firmy, osoby */
function ShowContactsDetail(URL) {
  if (URL != null) {
    okno = popWin(URL, 400, 300, 'detail', 'contact_detail', pop_win_params);
    okno.focus();
  }
}

/* Funkce pro otevření okna detailu zamestnancu (modul employees) */
function ShowEmployeesDetail(URL) {
  if (URL != null) {
    okno = popWin(URL, 400, 300, 'detail', 'employee_detail', pop_win_params);
    okno.focus();
  }
}

/* Funkce pro otevření okna detailu stredisek (modul departments) */
function ShowDepartmentDetail(URL) {
  if (URL != null) {
    okno = popWin(URL, 400, 300, 'detail', 'department_detail', pop_win_params);
    okno.focus();
  }
}

/* Funkce pro otevření okna detailu historie kontaktů (modul contacts) */
function ShowHistoryContactsDetail(URL, i_move_x, i_move_y) {
  if (URL != null) {
    okno = popWin(URL, 640, 440, 'detail', 'contact_history_detail', pop_win_params, i_move_x, i_move_y);
    okno.focus();
  }
}

/* Spolecna funkce pro zobrazeni popup menu, vola popWin */
function ShowTable(URL, i_width, i_height, s_params, i_move_x, i_move_y) {
  if (i_height == null) {
    i_height = 200;
  }
  if (i_width == null) {
    i_width = 300;
  }
  if (s_params == null) {
    s_params = '';
  }
  if ( (i_move_x == null) ) {
    i_move_x = 0;
  }
  if ( (i_move_y == null) ) {
    i_move_y = 0;
  }
  if (URL != null) {
    okno = popWin(URL, i_width, i_height, 'pagecode', 'pagecode_window', s_params, i_move_x, i_move_y);
  }
}

/* Funkce vytvori popup okno se jmenem 'page' + s_title, pro ciselniky 'pagecode'
   Funkce dostane URL a je mozne take predat funkci sirku a vysku okna, pointer na okno, nazev okna, parametry okna. */
function popWin( URL, i_width, i_height, s_title, s_name, s_params, i_move_x, i_move_y) {
  i_height += 16;
  var s_win_params = '';
  if (parseInt(navigator.appVersion) >= 4) { winl = 100, wint = 100; }
  var winl = (screen.width - i_width) / 2;
  var wint = (screen.height - i_height) / 2;
  if ( (i_move_x != null) && (typeof(i_move_x) == "number") ) {
    winl = winl + i_move_x;
  }
  if ( (i_move_y != null) && (typeof(i_move_y) == "number") ) {
    wint = wint + i_move_y;
  }
  day = new Date();
  if ( (s_params != null) && (s_params.length > 0) )
    s_win_params = s_params;
  else 
    s_win_params = pop_win_params;
    
  eval (s_title + " = window.open('" + URL + "','" + s_name + "','" + s_win_params + ",width="+i_width+",height="+i_height+",left="+winl+",top="+wint+"');");
  eval (s_title + ".focus();");     // pagecode - nazev okna
  return eval(s_title);
}

/* Funkce slouzi k dynamickemu odliseni aktivniho radku tabulky */
function colorIt( xpointer,  xstate, xcolor, without_change_cursor ) {
  var default_color = active_color_row;  // definice nahore
  var change_cursor = true;
  if ( (xcolor != null) && (typeof(xcolor) == "string") ) {
    default_color = xcolor;
  }
  if ( (without_change_cursor != null) && (typeof(without_change_cursor) == "boolean") && (without_change_cursor == true) ) {
    change_cursor = false;
  }
  // menit odliseni radku
  if (xstate) {
    xpointer.style.background = default_color;
    if (change_cursor) {
      xpointer.style.cursor = 'hand';
    }
  } else {
    if ( (xcolor != null) && (typeof(xcolor) == "string") && (xcolor != active_color_row) ) {
      xpointer.style.background = xcolor;
    } else {
      xpointer.style.background = "transparent";
    }
    xpointer.style.cursor='default';
  }
  return true;
}

/* Funkce plni hodnoty v parent okne 
   Parametry:
   id - jmeno polozky, do ktere se bude ukladat hodnota 2.parametru value
   value - uklada se do id prvku formulare
   desc - posila popis (napr. strediska, zakazky), existuje-li prvek <id>_display naplni se hodnotou desc
   fill_title - pokud nastavime 'A' - provede se plneni vlastnosti title textboxu.
*/
function Fill(id, value, desc, fill_title){
  if (window.opener && window.opener.open && !window.opener.closed &&
      window.opener.document.getElementById(id)) {
    window.opener.document.getElementById(id).value = value;
    if ( (desc != null) && (desc.length > 0) ) {
      if ( (fill_title != null) && (fill_title == 'A' || fill_title == '1') ) {
        window.opener.document.getElementById(id).title = '"' + desc + '"';
      }
      if ( window.opener.document.getElementById(id + '_display') ) {
        window.opener.document.getElementById(id + '_display').value = desc;
      }
    }
  }
  self.close();
}

/* Funkce na schování Layeru */
function HideLayer(layer_name) {
  _layer = document.getElementById(layer_name);
  if (_layer) {
    _layer.style.display = str_div_invisible;
  }
}

/* Funkce k zobrazeni Layeru */
function ShowLayer(layer_name) {
  _layer = document.getElementById(layer_name);
  if (_layer) {
    _layer.style.display = str_div_visible;
  }
}

/* Funkce pro schování nebo zobrazení Layeru */
function LayerClick(layer_name) {
  _layer = document.getElementById(layer_name);
  if (_layer.style.display == str_div_invisible) {
    if (document.getElementById(last_layer_name)) {
      //window.alert(last_layer_name)
      HideLayer(last_layer_name);
    }
    ShowLayer(layer_name);
    last_layer_name = layer_name;
  }
  else
    HideLayer(layer_name);
}

/* Rozbalení a Aktivace posledního submenu */
function ActivateLayer(layer_name) {
  _layer = document.getElementById(layer_name);
  if (_layer != null) {
    LayerClick(layer_name);
  }  
}

function ImageFilterMouseOver(picture)
{
  picture.style.filter = 'alpha(opacity=50,enabled=1)';
  return false;
}

function ImageFilterMouseOut(picture)
{
  window.status = "";
  picture.style.filter = 'alpha(enabled=0)';
  return false;
}


/* Funkce skryva blok div s tlacitkem "Zpět" v pripade, ze neni predchozi historie */
function Hide_Back_Button(layer_name) {
  if ( (layer_name != null) && (window.history.length == 0) ) {
    HideLayer(layer_name);
  }
}

/* Testovaci funkce */
function Zmena() {
  formular.polozka.value = formular.department.value;
  //alert(formular.department.value);
}

/* Zobrazí layer */
function Show_Faq() {
  _checkbox = document.getElementById("show_faq");
  if (_checkbox.checked) {
    ShowLayer('faq_layer'); 
  }
  else {
    HideLayer('faq_layer'); 
  }
}

/* FAQ - Kontrola vstupních údajů */
function FaqCheckEntry(form) {
  if ((typeof(form) == 'object') ) {
    if ( (typeof(form.subject) == 'object') && (form.subject.value == "") ) {
      form.subject.focus();
      window.alert("Pro odeslání příspěvku musíte zadat věc příspěvku !");
      return false;
    }
    else if ( (typeof(form.nickname) == 'object') && (form.nickname.value == "") ) {
      form.nickname.focus();
      window.alert("Pro odeslání příspěvku musíte zadat jméno (přezdívku) !");
      return false;
    }
    else 
      return true;
  }
  return false;
}

/* Faq - Odpoved na prispevek ve foru - Reply to */
function FaqReply(form_name, parentid, subject, message) {
  var form_referer = '0';
  ShowLayer("faq_layer");
  if ( form_name != null ) {
    form = document.getElementById(form_name);
    if ( parentid != null ) {
      form_referer = parentid;
    }
    if ( typeof(form) == 'object' ) {
      if ( typeof(form.subject) == 'object' ) {
        form.subject.value = 'Re: ' + subject;
      }
      if ( typeof(form.parentid) == 'object' ) {
        form.parentid.value = form_referer;
      }
      if ( typeof(form.message) == 'object' ) {
        /*form.message.value = "\r\n\r\n>>" + message;*/
        window.scroll(0, 10);
        form.message.focus();
      }
    }
  }
}

/* Otevreni poznamky FAQ */
function ShowNote(URL) {
  if (URL != null) {
    /*ShowLayer("faq_layer"); */
    ShowWindow(URL, 610, 480, pop_win_params);
  }
}

/* Spolecna funkce pro zobrazeni popup menu, vola popWin */
function ShowWindow(URL, i_height, i_width, s_params) {
  if (i_height == null) {
    i_height = 200;
  }
  if (i_width == null) {
    i_width = 300;
  }
  if (s_params == null) {
    s_params = pop_win_params;
  }
  if (URL != null) {
    okno = popWin(URL, i_height, i_width, 'foto', 'foto_window', s_params);
  }
}

/* Funkce vytvori popup okno se jmenem 'page' + s_title, pro ciselniky 'pagecode'
   Funkce dostane URL a je mozne take predat funkci vysku a sirku okna, pointer na okno, nazev okna, parametry okna. */
function popWin( URL, i_height, i_width, s_title, s_name, s_params) {
  i_height += 16;
  var s_win_params = '';
  if (parseInt(navigator.appVersion) >= 4) { winl = 100, wint = 100; }
  var winl = (screen.width - i_height) / 2;
  var wint = (screen.height - i_width) / 2;
  day = new Date();
  if ( (s_params != null) && (s_params.length > 0) )
    s_win_params = s_params;
  else 
    s_win_params = pop_win_params;
    
  eval (s_title + " = window.open('" + URL + "','" + s_name + "','" + s_win_params + ",width="+i_height+",height="+i_width+",left="+winl+",top="+wint+"');");
  eval (s_title + ".focus();");     // pagecode - nazev okna
  return eval(s_title);
} 
