/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var loadedobjects="";
var rootdomain="http://"+window.location.hostname;
var ajax_check_login;
var ajax_url_content = '';


//sluzi na zaskrtnutie setkych chboxov formulara
function mark_all(t)
{
    var parent = t.form.elements;
    var len = parent.length;
    for (i = 0; i <= len-1; i++)
    {
        if (parent[i].type == "checkbox")
            parent[i].checked = t.checked;
    }
}


// new AJAX
function container_load(data)
{
    var container = document.createElement("div");
        container.innerHTML = data;
    var nlist = container.childNodes;
    if (nlist == undefined)
        return false;
    var len = nlist.length-1;
    var i = 0;
    while (i <= len && nlist[i].nodeType != 1) i++;
    if (nlist[i] == undefined)
        return false;
    else
        return nlist[i];
}

function create_ajax(url, params, ifunc, containerid, func)
{
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject)
    { // if IE
        try
        {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e)
        {
            try
            {
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e){}
        }
    } else
        return false
    if (this.progress_bar != undefined)
    {
        this.progress_bar(true);
    }

    page_request.onreadystatechange=function()
    {
        load_my_page(page_request, this.progress_bar, ifunc, containerid, func)
    }

    page_request.open('POST', url, true)
    page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    page_request.setRequestHeader("Content-length", params.length);
    page_request.setRequestHeader("Connection", "close");
    page_request.send(params)
}

function load_my_page(page_request, progress_bar, ifunc, containerid, func)
{
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    {
        if (containerid != undefined && ifunc != 1)
            document.getElementById(containerid).innerHTML=page_request.responseText
        if (func != undefined && ifunc != 2)
            if (containerid != undefined)
                func(page_request.responseText, containerid);
        if (progress_bar != undefined)
            progress_bar(false);
    }

        if (containerid == 'uniodetail')
        {
            document.getElementById('uniodetail').style.visibility='';
        };
}

function ajax_class(progres_bar)
{
    this.load = create_ajax;
    this.progress = progres_bar;
}
// end new AJAX


// AJAX - get defined page - stiahne stranku a ulozi ju do premennej

function ajaxGetPage(containerid, url)
{
    var xmlHttp;
	var ajaxreturn = 0;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 && xmlHttp.status == 200)
		{
			document.getElementById(containerid).innerHTML = xmlHttp.responseText;
		}
	}

	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


function check_agreement(box_id, button_id)
{
  if(document.getElementById(box_id).checked == true)
  {
    document.getElementById(button_id).disabled = false;
  }
  else
  {
    document.getElementById(button_id).disabled = true;
  }
} 

function numbersonly(myfield, e, dec)
{
  var key;
  var keychar;
  
  if (window.event) key = window.event.keyCode;
  else if(e) key = e.which;
  else return true;
  keychar = String.fromCharCode(key);
  
  // control keys
  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
   return true;
  // numbers
  else if((("0123456789,.-%").indexOf(keychar) > -1)) return true;
  // decimal point jump
  else if (dec && (keychar == "."))
   {
     myfield.form.elements[dec].focus();
     return false;
   }
  else return false;
}

function cislo(myfield, pocet_des_miest)
{
  myfield.value = myfield.value.replace(/,/ , ".");
  var myfield_cislo = myfield.value * 1;
  if(isNaN(myfield_cislo))
  {
    alert("Chyba, zadajte číslo!");
    myfield_cislo = 0;
  }
  myfield.value = myfield_cislo.toFixed(pocet_des_miest);
}

function lenCisla(myfield, e)  // vracia len cisla bez ',' a bez '.'
{
  var key;
  var keychar;
  
  if (window.event) key = window.event.keyCode;
  else if(e) key = e.which;
  else return true;
  keychar = String.fromCharCode(key);
  // control keys
  if((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)) return true;
  // numbers
  else if((("0123456789").indexOf(keychar) > -1)) return true;
  else return false;
}

function tickCheckBox(id)
{
    if(document.getElementById(id).checked == true)
      document.getElementById(id).checked = false;
    else
      document.getElementById(id).checked = true;
}

function copyFormValue(src, target)
{
    src_sel = document.getElementById(src);
    var i;
    for(i = src_sel.length - 1; i >= 0; i--)
    {
        if(src_sel.options[i].selected)
          value = src_sel.options[i].text;
    }
    document.getElementById(target).value = value;
    
}

function copyFormText(src, target)
{
    document.getElementById(target).value = document.getElementById(src).value;
}

/*
function prepocitaj_ceny(index)
{
    mnozstvo            = document.getElementById('mnozstvo' + index);
    cena_predaj         = document.getElementById('cena_predaj' + index);
    cena_predaj_celkom  = document.getElementById('cena_predaj_celkom' + index);
    cena_dph            = document.getElementById('cena_dph' + index);
    dph                 = document.getElementById('dph' + index);
    max_mnozstvo        = document.getElementById('max_mnozstvo' + index);
    marza               = document.getElementById('marza' + index);
    in_n                = document.getElementById('in_n' + index);
    cena_nakup          = document.getElementById('cena_nakup' + index);
    
    // ---- odstranenie ciarok -------------------------------------------------
      cena_predaj.value = cena_predaj.value.replace(/,/ , ".");
      mnozstvo.value = mnozstvo.value.replace(/,/ , ".");
    // ---- end odstranenie ciarok ---------------------------------------------
    // ---- pretypovanie -------------------------------------------------------
      var mnozstvo_cislo            = mnozstvo.value * 1;
      var cena_predaj_cislo         = cena_predaj.value * 1;
      var cena_predaj_celkom_cislo  = cena_predaj_celkom.value * 1;
      var cena_dph_cislo            = cena_dph.value * 1;
      var dph_cislo                 = dph.value * 1;
      var max_mnozstvo_cislo        = max_mnozstvo.value * 1;
      var cena_nakup_cislo          = cena_nakup.value * 1;
      var in_n_cislo                = in_n.value * 1;
    // ---- end pretypovanie ---------------------------------------------------
    // ---- zaokruhlenie -------------------------------------------------------
      mnozstvo_cislo            = Math.round(mnozstvo_cislo * 1000) / 1000;
      cena_predaj_cislo         = Math.round(cena_predaj_cislo * 100) / 100;
      cena_predaj_celkom_cislo  = Math.round(cena_predaj_celkom_cislo * 100) / 100;
      cena_dph_cislo            = Math.round(cena_dph_cislo * 100) / 100;
      dph_cislo                 = Math.round(dph_cislo * 100) / 100;
      max_mnozstvo_cislo        = Math.round(max_mnozstvo_cislo * 1000) / 1000;
      cena_nakup_cislo          = Math.round(cena_nakup_cislo * 100) / 100;
    // ---- end zaokruhlenie ---------------------------------------------------
    // ---- zistenie ci su ciselne hodnoty -------------------------------------
      if(isNaN(mnozstvo_cislo) || (mnozstvo_cislo > max_mnozstvo_cislo))
      {
        alert("Chyba, množstvo musí byť číslo menšie alebo rovné " + max_mnozstvo_cislo + " !");
        mnozstvo_cislo = max_mnozstvo_cislo;
      }
      
      if(isNaN(cena_predaj_cislo))
      {
        alert("Chyba, 'Cena/mj' musí byť číslo!");
        cena_predaj_cislo = 0;
      }
      
      if(isNaN(cena_nakup_cislo))
      {
        alert("Chyba, 'Cena nakup' musí byť číslo!");
        cena_nakup_cislo = 0;
      }
    // ---- end zistenie ci su ciselne hodnoty ---------------------------------
    // ---- vypocty ------------------------------------------------------------
      cena_predaj_celkom_cislo = mnozstvo_cislo * cena_predaj_cislo;
      cena_dph_cislo = cena_predaj_celkom_cislo * (1 + (dph_cislo / 100));
      marza_cislo = mnozstvo_cislo * (cena_predaj_cislo - cena_nakup_cislo) - in_n_cislo;
    // ---- end vypocty --------------------------------------------------------

    mnozstvo.value            = mnozstvo_cislo.toFixed(3);
    cena_predaj.value         = cena_predaj_cislo.toFixed(2);
    cena_predaj_celkom.value  = cena_predaj_celkom_cislo.toFixed(2);
    cena_dph.value            = cena_dph_cislo.toFixed(2);
    max_mnozstvo.value        = max_mnozstvo_cislo.toFixed(3);
    marza.value               = marza_cislo.toFixed(2);

    prepocitaj_podiel_s(index);
}

function interny_naklad_zoznam(index)
{
    cena_nakladu        = document.getElementById('id_cena_nakladu_' + index);
    cena_za_mj          = document.getElementById('id_cena_za_mj_' + index);
    cena_fakturacie     = document.getElementById('id_cena_fakturacie_' + index);
    mnozstvo            = document.getElementById('id_mnozstvo_' + index);
    max_mnozstvo        = document.getElementById('id_max_mnozstvo_' + index);
    // ---- odstranenie ciarok -------------------------------------------------
      cena_fakturacie.value = cena_fakturacie.value.replace(/,/ , ".");
      mnozstvo.value        = mnozstvo.value.replace(/,/ , ".");
      cena_za_mj.value      = cena_za_mj.value.replace(/,/ , ".");
    // ---- end odstranenie ciarok ---------------------------------------------
    // ---- pretypovanie -------------------------------------------------------
      var cena_nakladu_cislo      = cena_nakladu.value * 1;
      var cena_fakturacie_cislo   = cena_fakturacie.value * 1;
      var cena_za_mj_cislo        = cena_za_mj.value * 1;
      var mnozstvo_cislo          = mnozstvo.value * 1;
      var max_mnozstvo_cislo      = max_mnozstvo.value * 1;
    // ---- end pretypovanie ---------------------------------------------------
    // ---- zistenie ci su ciselne hodnoty -------------------------------------
      if(isNaN(cena_za_mj_cislo))
      {
        alert("Chyba, 'Cena / MJ' musí byť číslo!");
        cena_za_mj_cislo = 0;
      }
      if(isNaN(cena_fakturacie_cislo))
      {
        alert("Chyba, 'Cena fakturácie' musí byť číslo!");
        cena_fakturacie_cislo = 0;
      }
      if(isNaN(mnozstvo_cislo) || (mnozstvo_cislo > max_mnozstvo_cislo))
      {
        alert("Chyba, množstvo musí byť číslo menšie alebo rovné " + max_mnozstvo_cislo +"!");
        mnozstvo_cislo = max_mnozstvo_cislo;
      }
    // ---- end zistenie ci su ciselne hodnoty ---------------------------------
    // ---- vypocty ------------------------------------------------------------
      cena_nakladu_cislo = mnozstvo_cislo * cena_za_mj_cislo;
    // ---- end vypocty --------------------------------------------------------
    // ---- zaokruhlenie -------------------------------------------------------
      cena_nakladu_cislo        = Math.round(cena_nakladu_cislo * 100) / 100;
      cena_fakturacie_cislo     = Math.round(cena_fakturacie_cislo * 100) / 100;
      mnozstvo_cislo            = Math.round(mnozstvo_cislo * 1000) / 1000;
      cena_za_mj_cislo          = Math.round(cena_za_mj_cislo * 1000) / 1000;
    // ---- end zaokruhlenie ---------------------------------------------------
    mnozstvo.value            = mnozstvo_cislo.toFixed(3);
    cena_nakladu.value        = cena_nakladu_cislo.toFixed(2);
    cena_fakturacie.value     = cena_fakturacie_cislo.toFixed(2);
    cena_za_mj.value          = cena_za_mj_cislo.toFixed(2);
}

function prepocitaj_podiel_p(index)
{
  percenta            = document.getElementById('podiel_percenta' + index);
  suma                = document.getElementById('podiel_suma' + index);
  max_suma            = document.getElementById('marza' + index);
  
  percenta.value = percenta.value.replace(/,/ , ".");
  suma.value = suma.value.replace(/,/ , ".");
  max_suma.value = max_suma.value.replace(/,/ , ".");
  // kvoli pretypovaniu
  var percenta_cislo  = percenta.value * 1;
  var suma_cislo      = suma.value * 1;
  var max_suma_cislo  = max_suma.value * 1;
  // ---- zaokruhlenie
  percenta_cislo = Math.round(percenta_cislo * 100) / 100;
  if(!(percenta_cislo >= 0 && percenta_cislo <= 100))
  {
    alert("Chyba, číslo musí byť v rozsahu <0; 100>!");
    percenta_cislo = 0;
  }

  suma_cislo = Math.round((max_suma_cislo * (percenta_cislo / 100))*100)/100;
  suma.value = suma_cislo.toFixed(2);
  percenta.value = percenta_cislo.toFixed(2);
}

function prepocitaj_podiel_s(index)
{
  percenta            = document.getElementById('podiel_percenta' + index);
  suma                = document.getElementById('podiel_suma' + index);
  max_suma            = document.getElementById('marza' + index);

  percenta.value = percenta.value.replace(/,/ , ".");
  suma.value = suma.value.replace(/,/ , ".");
  max_suma.value = max_suma.value.replace(/,/ , ".");
  // kvoli pretypovaniu
  var percenta_cislo  = percenta.value * 1;
  var suma_cislo      = suma.value * 1;
  var max_suma_cislo  = max_suma.value * 1;
  // ---- zaokruhlenie
  suma_cislo = Math.round(suma_cislo * 100) / 100;
  max_suma_cislo = Math.round(max_suma_cislo * 100) / 100;
  if(!(suma_cislo >= 0 && suma_cislo <= max_suma_cislo))
  {
    alert("Chyba, pole 'Podiel suma' musí mať hodnotu v rozsahu <0; " + max_suma_cislo + ">!");
    suma_cislo = 0;
  }

  if(max_suma_cislo > 0)
  {
    percenta_cislo = Math.round((suma_cislo / max_suma_cislo) * 10000) / 100;
  }
  else
  {
    percenta_cislo = 0;
    suma_cislo = 0;
  }
  suma.value = suma_cislo.toFixed(2);
  percenta.value = percenta_cislo.toFixed(2);
}

function datum_dodania_change()
{
    datum_dodania = document.getElementById('vf_datum_dodania');
    datum_vystavenia = document.getElementById('vf_datum_vystavenia');
    datum_danovej_povinnosti = document.getElementById('vf_datum_danovej_povinnosti');
    datum_splatnosti = document.getElementById('vf_datum_splatnosti');

    splatnost_dni = document.getElementById('splatnost_dni');
    
    datum_vystavenia.value = datum_dodania.value;
    datum_danovej_povinnosti.value = datum_dodania.value;
    dokoncit_datum_vystavenia_change();
    //alert(new Date());
}

function sklad_upravitpolozku_prepocitat_ceny()
{
    mnozstvo            = document.getElementById('ps_mnozstvo');
    cena_nakup          = document.getElementById('ps_cena_nakup_kus');
    cena_nakup_celkom   = document.getElementById('ps_cena_nakup');
    cena_dph            = document.getElementById('ps_cena_nakup_s_dph');
    cena_predaj         = document.getElementById('ps_cena_predaj1');
    perc_nav            = document.getElementById('ps_perc_nav');

    //dph                 = document.getElementById('dph' + index);

    src_sel = document.getElementById('ps_dph');
    var dph_value;
    var i;
    for(i = src_sel.length - 1; i >= 0; i--)
    {
        if(src_sel.options[i].selected)
        {
            dph_value = src_sel.options[i].value;
        }
    }

    mnozstvo.value = mnozstvo.value.replace(/,/ , ".");
    cena_nakup.value = cena_nakup.value.replace(/,/ , ".");
    cena_nakup_celkom.value = cena_nakup_celkom.value.replace(/,/ , ".");
    cena_dph.value = cena_dph.value.replace(/,/ , ".");
    cena_predaj.value = cena_predaj.value.replace(/,/ , ".");

    var cnc = mnozstvo.value * cena_nakup.value;
    cena_nakup_celkom.value = cnc.toFixed(2);
     
    var cd = cena_nakup.value * (1 + (dph_value / 100));
    cena_dph.value = cd.toFixed(2);

    cp = cena_nakup.value * (1 + (perc_nav.value / 100));
    cena_predaj.value = cp.toFixed(2);
}

function sklad_upravitpolozku_cena_predaj()
{
    cena_nakup          = document.getElementById('ps_cena_nakup_kus');
    cena_predaj         = document.getElementById('ps_cena_predaj1');
    perc_nav            = document.getElementById('ps_perc_nav');
    
    cp = cena_nakup.value * (1 + (perc_nav.value / 100));
    cena_predaj.value = cp.toFixed(2);
}

function sklad_vyroby_pridat()
{
  max_mnozstvo        = document.getElementById('max_mnozstvo');
  cena_predaj         = document.getElementById('cena_predaj');
    
  // ---- odstranenie ciarok ---------------------------------------------------
    max_mnozstvo.value      = max_mnozstvo.value.replace(/,/ , ".");
    cena_predaj.value       = cena_predaj.value.replace(/,/ , ".");
  // ---- end odstranenie ciarok -----------------------------------------------
  // ---- kvoli pretypovaniu ---------------------------------------------------
    var max_mnozstvo_cislo      = max_mnozstvo.value * 1;
    var cena_predaj_cislo       = cena_predaj.value * 1;
  // ---- end kvoli pretypovaniu -----------------------------------------------
  // ---- zaokruhlenie ---------------------------------------------------------
    max_mnozstvo_cislo      = Math.round(max_mnozstvo_cislo * 1000) / 1000;
    cena_predaj_cislo       = Math.round(cena_predaj_cislo * 100) / 100;
  // ---- end zaokruhlenie -----------------------------------------------------    
  // ---- vypisy ---------------------------------------------------------------
    max_mnozstvo.value      = max_mnozstvo_cislo.toFixed(3);
    cena_predaj.value       = cena_predaj_cislo.toFixed(2);
  // ---- end vypisy -----------------------------------------------------------  
}

function prijfak_prepocitaj_ceny_perc_nav(index)
{
  cena_nakup          = document.getElementById('id_cena_nakup_kus' + index);
  cena_predaj         = document.getElementById('id_cena_predaj' + index);
  perc_nav            = document.getElementById('id_perc_nav' + index);
  
  // ---- odstranenie ciarok ---------------------------------------------------
    cena_nakup.value        = cena_nakup.value.replace(/,/ , ".");
    perc_nav.value          = perc_nav.value.replace(/,/ , ".");
    cena_predaj.value       = cena_predaj.value.replace(/,/ , ".");
  // ---- end odstranenie ciarok -----------------------------------------------
  // ---- kvoli pretypovaniu ---------------------------------------------------
    var cena_nakup_cislo        = cena_nakup.value * 1;
    var perc_nav_cislo          = perc_nav.value * 1;
    var cena_predaj_cislo       = cena_predaj.value * 1;
  // ---- end kvoli pretypovaniu -----------------------------------------------
  // ---- zaokruhlenie ---------------------------------------------------------
    cena_nakup_cislo        = Math.round(cena_nakup_cislo * 100) / 100;
    perc_nav_cislo          = Math.round(perc_nav_cislo * 100) / 100;
    cena_predaj_cislo       = Math.round(cena_predaj_cislo * 100) / 100;
  // ---- end zaokruhlenie -----------------------------------------------------  
    cp = cena_nakup_cislo * (1 + (perc_nav_cislo / 100));
    cena_predaj.value = cp.toFixed(2);
}

function prijfak_prepocitaj_ceny(index)
{
  mnozstvo            = document.getElementById('id_mnozstvo' + index);
  cena_nakup          = document.getElementById('id_cena_nakup_kus' + index);
  cena_nakup_celkom   = document.getElementById('id_cena_nakup' + index);
  cena_dph            = document.getElementById('id_cena_s_dph' + index);
  perc_nav            = document.getElementById('id_perc_nav' + index);
  cena_predaj         = document.getElementById('id_cena_predaj' + index);
  
  src_sel = document.getElementById('id_dph' + index);
  var dph_value;
  var i;
  for(i = src_sel.length - 1; i >= 0; i--)
  {
    if(src_sel.options[i].selected)
    {
      dph_value = src_sel.options[i].text;
    }
  }
  // ---- odstranenie ciarok ---------------------------------------------------
    mnozstvo.value          = mnozstvo.value.replace(/,/ , ".");
    cena_nakup.value        = cena_nakup.value.replace(/,/ , ".");
    cena_nakup_celkom.value = cena_nakup_celkom.value.replace(/,/ , ".");
    cena_dph.value          = cena_dph.value.replace(/,/ , ".");
    perc_nav.value          = perc_nav.value.replace(/,/ , ".");
    cena_predaj.value       = cena_predaj.value.replace(/,/ , ".");
  // ---- end odstranenie ciarok -----------------------------------------------
  // ---- kvoli pretypovaniu ---------------------------------------------------
    var mnozstvo_cislo          = mnozstvo.value * 1;
    var cena_nakup_cislo        = cena_nakup.value * 1;
    var cena_nakup_celkom_cislo = cena_nakup_celkom.value * 1;
    var cena_dph_cislo          = cena_dph.value * 1;
    var perc_nav_cislo          = perc_nav.value * 1;
    var cena_predaj_cislo       = cena_predaj.value * 1;
    var dph_cislo               = dph_value * 1;
  // ---- end kvoli pretypovaniu -----------------------------------------------
  // ---- zaokruhlenie ---------------------------------------------------------
    mnozstvo_cislo          = Math.round(mnozstvo_cislo * 1000) / 1000;
    cena_nakup_cislo        = Math.round(cena_nakup_cislo * 100) / 100;
    cena_nakup_celkom_cislo = Math.round(cena_nakup_celkom_cislo * 100) / 100;
    cena_dph_cislo          = Math.round(cena_dph_cislo * 100) / 100;
    perc_nav_cislo          = Math.round(perc_nav_cislo * 100) / 100;
    cena_predaj_cislo       = Math.round(cena_predaj_cislo * 100) / 100;
    dph_cislo               = Math.round(dph_cislo);
  // ---- end zaokruhlenie -----------------------------------------------------
  // ---- vypocty --------------------------------------------------------------
    cena_nakup_celkom_cislo = mnozstvo_cislo * cena_nakup_cislo;
    cena_dph_cislo          = cena_nakup_cislo * (1 + (dph_cislo / 100));
    //cena_predaj_cislo       = cena_nakup_cislo * (1 + (perc_nav_cislo / 100));
  // ---- end vypocty ----------------------------------------------------------
  // ---- vypisy ---------------------------------------------------------------
    mnozstvo.value          = mnozstvo_cislo.toFixed(3);
    cena_nakup.value        = cena_nakup_cislo.toFixed(2);
    cena_nakup_celkom.value = cena_nakup_celkom_cislo.toFixed(2);
    cena_dph.value          = cena_dph_cislo.toFixed(2);
    perc_nav.value          = perc_nav_cislo.toFixed(2);
    cena_predaj.value       = cena_predaj_cislo.toFixed(2);
  // ---- end vypisy -----------------------------------------------------------
} 

function prijfak_prepocitaj_perc_nav(index)
{
  cena_nakup          = document.getElementById('id_cena_nakup_kus' + index);
  perc_nav            = document.getElementById('id_perc_nav' + index);
  cena_predaj         = document.getElementById('id_cena_predaj' + index);
  // ---- odstranenie ciarok ---------------------------------------------------
    perc_nav.value          = perc_nav.value.replace(/,/ , ".");
  // ---- end odstranenie ciarok -----------------------------------------------
  // ---- kvoli pretypovaniu ---------------------------------------------------
    var perc_nav_cislo          = perc_nav.value * 1;
    var cena_nakup_cislo        = cena_nakup.value * 1;
    var cena_predaj_cislo       = cena_predaj.value * 1;
  // ---- end kvoli pretypovaniu -----------------------------------------------
  // ---- zaokruhlenie ---------------------------------------------------------
    perc_nav_cislo          = Math.round(perc_nav_cislo * 100) / 100;
  // ---- end zaokruhlenie -----------------------------------------------------
  // ---- vypocty --------------------------------------------------------------
    cena_predaj_cislo       = cena_nakup_cislo * (1 + (perc_nav_cislo / 100));
  // ---- end vypocty ----------------------------------------------------------
  // ---- vypisy ---------------------------------------------------------------
    cena_predaj.value       = cena_predaj_cislo.toFixed(2);
    perc_nav.value          = perc_nav_cislo.toFixed(2);
  // ---- end vypisy -----------------------------------------------------------
} 
   
// ---- id=faktury&cmd=vystavena_dokoncit --------------------------------------
*/
function pridaj_nuly(retazec, pocet_znakov_spolu) //prida k retazcu nuly na zaciatok
{
  while(retazec.length < pocet_znakov_spolu)
  {
    retazec = "0" + retazec;
  }
  return retazec;
}
/*
function dokoncit_datum_vystavenia_change()
{
  dat_vystavenia     = document.getElementById('vf_datum_vystavenia');
  dat_splatnosti     = document.getElementById('vf_datum_splatnosti');
  pocet_dni          = document.getElementById('vf_splatnost_dni');
  
  pocet_dni_cislo = parseInt(pocet_dni.value, 10);
  
  dat_vyst_den             = parseInt(dat_vystavenia.value.substr(0, 2), 10);
  dat_vyst_mesiac          = parseInt(dat_vystavenia.value.substr(3, 2), 10);
  dat_vyst_rok             = parseInt(dat_vystavenia.value.substr(6, 4), 10);
  
  datum_splatnosti = new Date();
  datum_splatnosti.setFullYear(dat_vyst_rok);
  datum_splatnosti.setMonth(dat_vyst_mesiac - 1);
  datum_splatnosti.setDate(dat_vyst_den);
  datum_splatnosti.setHours(0);
  datum_splatnosti.setMinutes(0);
  datum_splatnosti.setSeconds(0);
  datum_splatnosti.setTime(datum_splatnosti.getTime() + pocet_dni_cislo *24*60*60*1000);
  dat_splatnosti.value = pridaj_nuly(datum_splatnosti.getDate().toString(), 2) + '.' + pridaj_nuly(((datum_splatnosti.getMonth() + 1).toString()), 2) + '.' + pridaj_nuly(datum_splatnosti.getFullYear().toString(), 4);
}

function dokoncit_datum_splatnosti_change()
{
  dat_vystavenia     = document.getElementById('vf_datum_vystavenia');
  dat_splatnosti     = document.getElementById('vf_datum_splatnosti');
  pocet_dni          = document.getElementById('vf_splatnost_dni');
  
  dat_vyst_den             = parseInt(dat_vystavenia.value.substr(0, 2), 10);
  dat_vyst_mesiac          = parseInt(dat_vystavenia.value.substr(3, 2), 10);
  dat_vyst_rok             = parseInt(dat_vystavenia.value.substr(6, 4), 10);
  
  datum_vystavenia = new Date();
  datum_vystavenia.setFullYear(dat_vyst_rok);
  datum_vystavenia.setMonth(dat_vyst_mesiac - 1);
  datum_vystavenia.setDate(dat_vyst_den);
  datum_vystavenia.setHours(0);
  datum_vystavenia.setMinutes(0);
  datum_vystavenia.setSeconds(0);
  
  dat_splat_den             = parseInt(dat_splatnosti.value.substr(0, 2), 10);
  dat_splat_mesiac          = parseInt(dat_splatnosti.value.substr(3, 2), 10);
  dat_splat_rok             = parseInt(dat_splatnosti.value.substr(6, 4), 10);
  
  datum_splatnosti = new Date();  
  datum_splatnosti.setFullYear(dat_splat_rok);
  datum_splatnosti.setMonth(dat_splat_mesiac - 1);
  datum_splatnosti.setDate(dat_splat_den);
  datum_splatnosti.setHours(0);
  datum_splatnosti.setMinutes(0);
  datum_splatnosti.setSeconds(0);  

  
  pocet_dni_cislo = (datum_splatnosti.getTime() - datum_vystavenia.getTime())/(24*60*60*1000);
  pocet_dni.value = Math.round(pocet_dni_cislo);
}

function dokoncit_pocet_dni_blur()
{
  dat_vystavenia     = document.getElementById('vf_datum_vystavenia');
  dat_splatnosti     = document.getElementById('vf_datum_splatnosti');
  pocet_dni          = document.getElementById('vf_splatnost_dni');
  
  pocet_dni_cislo = parseInt(pocet_dni.value, 10);
  
  dat_vyst_den             = parseInt(dat_vystavenia.value.substr(0, 2), 10);
  dat_vyst_mesiac          = parseInt(dat_vystavenia.value.substr(3, 2), 10);
  dat_vyst_rok             = parseInt(dat_vystavenia.value.substr(6, 4), 10);
  
  datum_splatnosti = new Date();
  datum_splatnosti.setFullYear(dat_vyst_rok);
  datum_splatnosti.setMonth(dat_vyst_mesiac - 1);
  datum_splatnosti.setDate(dat_vyst_den);
  datum_splatnosti.setHours(0);
  datum_splatnosti.setMinutes(0);
  datum_splatnosti.setSeconds(0);    
  
  
  datum_splatnosti.setTime(datum_splatnosti.getTime() + pocet_dni_cislo *24*60*60*1000);
  
  dat_splatnosti.value = pridaj_nuly(datum_splatnosti.getDate().toString(), 2) + '.' + pridaj_nuly(((datum_splatnosti.getMonth() + 1).toString()), 2) + '.' + pridaj_nuly(datum_splatnosti.getFullYear().toString(), 4);
  pocet_dni.value = Math.round(pocet_dni_cislo);
}
// ---- end id=faktury&cmd=vystavena_dokoncit ----------------------------------
// ---- vymazavanie faktur -----------------------------------------------------
function vymaz_vyst_fakturu(index)
{
  if(confirm("Naozaj chcete vymazať faktúru s ID " + index + "?"))
	{
  	window.location=("index.php?id=faktury&cmd=vystavena_zmazat&id_vf=" + index);
	}
}

function vymaz_prij_fakturu(index)
{
  if(confirm("Naozaj chcete vymazať faktúru s ID " + index + "?"))
	{
  	window.location=("index.php?id=faktury&cmd=prijata_zmazat&id_pf=" + index);
	}
}

function vymaz_zamestnanca(index)
{
  if(confirm("Naozaj chcete vymazať zamestnanca s ID " + index + "?"))
	{
  	window.location=("index.php?id=user&cmd=zamestnanci_del&userid=" + index);
	}
}

function vymaz_zak_kartu(index)
{
  if(confirm("Naozaj chcete vymazať zákaznícku kartu s ID " + index + "?"))
	{
  	window.location=("index.php?id=zakaznickakarta&cmd=del_proc&kartaid=" + index);
	}
}
// ---- end vymazavanie faktur -------------------------------------------------
function interny_naklad_add_all()
{
  cena_nakladu        = document.getElementById('cena_nakladu');
  cena_za_mj          = document.getElementById('cena_za_mj');
  cena_fakturacie     = document.getElementById('cena_fakturacie');
  mnozstvo            = document.getElementById('mnozstvo');
  
  // ---- odstranenie ciarok -------------------------------------------------
    mnozstvo.value        = mnozstvo.value.replace(/,/ , ".");
    cena_za_mj.value      = cena_za_mj.value.replace(/,/ , ".");
  // ---- end odstranenie ciarok ---------------------------------------------
  // ---- pretypovanie -------------------------------------------------------
    var cena_za_mj_cislo        = cena_za_mj.value * 1;
    var mnozstvo_cislo          = mnozstvo.value * 1;
  // ---- end pretypovanie ---------------------------------------------------
  // ---- zistenie ci su ciselne hodnoty -------------------------------------
    if(isNaN(cena_za_mj_cislo))
    {
      alert("Chyba, 'Cena / MJ' musí byť číslo!");
      cena_za_mj_cislo = 0;
    }
    if(isNaN(mnozstvo_cislo) ||(mnozstvo_cislo <= 0))
    {
      alert("Chyba, 'MnoĹľstvo' musí byť číslo väčšie ako nula!");
      mnozstvo_cislo = 1;   
    }
  // ---- end zistenie ci su ciselne hodnoty ---------------------------------
  // ---- vypocty ------------------------------------------------------------
    cena_nakladu_cislo = mnozstvo_cislo * cena_za_mj_cislo;
  // ---- end vypocty --------------------------------------------------------
  // ---- zaokruhlenie -------------------------------------------------------
    cena_nakladu_cislo        = Math.round(cena_nakladu_cislo * 100) / 100;
    mnozstvo_cislo            = Math.round(mnozstvo_cislo * 1000) / 1000;
    cena_za_mj_cislo          = Math.round(cena_za_mj_cislo * 100) / 100;
  // ---- end zaokruhlenie ---------------------------------------------------
  mnozstvo.value            = mnozstvo_cislo.toFixed(3);
  cena_nakladu.value        = cena_nakladu_cislo.toFixed(2);
  cena_fakturacie.value     = cena_nakladu_cislo.toFixed(2);
  cena_za_mj.value          = cena_za_mj_cislo.toFixed(2);
}

function interny_naklad_add_cena_fakturacie()
{
  cena_fakturacie     = document.getElementById('cena_fakturacie');
  // ---- odstranenie ciarok -------------------------------------------------
    cena_fakturacie.value = cena_fakturacie.value.replace(/,/ , ".");
  // ---- end odstranenie ciarok ---------------------------------------------
  // ---- pretypovanie -------------------------------------------------------
    var cena_fakturacie_cislo   = cena_fakturacie.value * 1;
  // ---- end pretypovanie ---------------------------------------------------
  // ---- zistenie ci su ciselne hodnoty -------------------------------------
    if(isNaN(cena_fakturacie_cislo))
    {
      alert("Chyba, 'Cena fakturácie' musí byť číslo!");
      cena_fakturacie_cislo = 0;
    }
  // ---- end zistenie ci su ciselne hodnoty ---------------------------------
  // ---- zaokruhlenie -------------------------------------------------------
    cena_fakturacie_cislo     = Math.round(cena_fakturacie_cislo * 100) / 100;
  // ---- end zaokruhlenie ---------------------------------------------------
  cena_fakturacie.value     = cena_fakturacie_cislo.toFixed(2);
}

function skladvyroby_pridat_s_in_spocitat_naklady(pocet_nakladov)
{
  var cena_fakturacie_spolu = 0;
  for(var i = 1; i <= pocet_nakladov; i++)
  {
    cena_fakturacie          = document.getElementById('hid_cena_fakturacie' + i);
    checkbox_id              = document.getElementById('hid_checkbox_id' + i);
    checkbox                 = document.getElementById(checkbox_id.value);
    if(checkbox.checked)
    {
      cena_fakturacie           = document.getElementById('hid_cena_fakturacie' + i);
      var cena_fakturacie_cislo = cena_fakturacie.value * 1;
      if(isNaN(cena_fakturacie_cislo))
      {
        alert("Chyba, 'Cena fakturácie' musí byť číslo!");
        cena_fakturacie_cislo = 0;
      }
      cena_fakturacie_spolu = cena_fakturacie_spolu + cena_fakturacie_cislo;
    }
  }
  cena_predaj = document.getElementById('cena_predaj');
  cena_predaj.value = cena_fakturacie_spolu.toFixed(2);
}

function skladvyroby_pridat_s_in_spocitat_mnozstvo(pocet_nakladov)
{
  var mnozstvo_spolu = 0;
  for(var i = 1; i <= pocet_nakladov; i++)
  {
    mnozstvo                 = document.getElementById('hid_mnozstvo' + i);
    checkbox_id              = document.getElementById('hid_checkbox_id' + i);
    checkbox                 = document.getElementById(checkbox_id.value);
    if(checkbox.checked)
    {
      mnozstvo           = document.getElementById('hid_mnozstvo' + i);
      var mnozstvo_cislo = mnozstvo.value * 1;
      if(isNaN(mnozstvo_cislo))
      {
        alert("Chyba, 'Mnozstvo' musí byť číslo!");
        mnozstvo_cislo = 0;
      }
      mnozstvo_spolu = mnozstvo_spolu + mnozstvo_cislo;
    }
  }
  max_mnozstvo = document.getElementById('max_mnozstvo');
  max_mnozstvo.value = mnozstvo_spolu.toFixed(3);
}

function skladvyroby_pridat_s_in_row_onclick(id)
{
  if(document.getElementById(id).checked == true)
    document.getElementById(id).checked = false;
  else
    document.getElementById(id).checked = true;
}

function c_fond_zoznam_percento(index, typ)
{
  percento          = document.getElementById('percento' + index);
  suma              = document.getElementById('suma' + index);
  pocitane_zo_sumy  = document.getElementById('pocitane_zo_sumy' + index);
  suma_spolu        = document.getElementById('suma_spolu' + index);
  // ---- odstranenie ciarok -------------------------------------------------
    percento.value = percento.value.replace(/,/ , ".");
    suma.value = suma.value.replace(/,/ , ".");
    pocitane_zo_sumy.value = pocitane_zo_sumy.value.replace(/,/ , ".");
    suma_spolu.value = suma_spolu.value.replace(/,/ , ".");
  // ---- end odstranenie ciarok ---------------------------------------------
  // ---- pretypovanie -------------------------------------------------------
    var percento_cislo            = percento.value * 1;
    var suma_cislo                = suma.value * 1;
    var pocitane_zo_sumy_cislo    = pocitane_zo_sumy.value * 1;
    var suma_spolu_cislo          = suma_spolu.value * 1;
  // ---- end pretypovanie ---------------------------------------------------
  // ---- zistenie ci su ciselne hodnoty -------------------------------------
    if(isNaN(percento_cislo))
    {
      alert("Chyba, 'Percento' musí byť číslo!");
      percento_cislo = 0;
    }
    if(isNaN(suma_cislo))
    {
      alert("Chyba, 'Suma' musí byť číslo!");
      suma_cislo = 0;
    }
  // ---- end zistenie ci su ciselne hodnoty ---------------------------------
  // ---- zaokruhlenie -------------------------------------------------------
    percento_cislo = Math.round(percento_cislo * 10000) / 10000;
    suma_cislo     = Math.round(suma_cislo * 100) / 100;
  // ---- end zaokruhlenie ---------------------------------------------------
  suma_cislo = pocitane_zo_sumy_cislo * (percento_cislo/100);
  if(typ == 0)
    suma_spolu_cislo = pocitane_zo_sumy_cislo - suma_cislo;
  else
    suma_spolu_cislo = pocitane_zo_sumy_cislo + suma_cislo;
  
  suma.value         = suma_cislo.toFixed(2);
  percento.value     = percento_cislo.toFixed(4);
  suma_spolu.value   = suma_spolu_cislo.toFixed(2);
}

function c_fond_zoznam_suma(index, typ)
{
  percento          = document.getElementById('percento' + index);
  suma              = document.getElementById('suma' + index);
  pocitane_zo_sumy  = document.getElementById('pocitane_zo_sumy' + index);
  suma_spolu        = document.getElementById('suma_spolu' + index);
  // ---- odstranenie ciarok -------------------------------------------------
    percento.value = percento.value.replace(/,/ , ".");
    suma.value = suma.value.replace(/,/ , ".");
    pocitane_zo_sumy.value = pocitane_zo_sumy.value.replace(/,/ , ".");
    suma_spolu.value = suma_spolu.value.replace(/,/ , ".");
  // ---- end odstranenie ciarok ---------------------------------------------
  // ---- pretypovanie -------------------------------------------------------
    var percento_cislo            = percento.value * 1;
    var suma_cislo                = suma.value * 1;
    var pocitane_zo_sumy_cislo    = pocitane_zo_sumy.value * 1;
    var suma_spolu_cislo          = suma_spolu.value * 1;
  // ---- end pretypovanie ---------------------------------------------------
  // ---- zistenie ci su ciselne hodnoty -------------------------------------
    if(isNaN(percento_cislo))
    {
      alert("Chyba, 'Percento' musí byť číslo!");
      percento_cislo = 0;
    }
    if(isNaN(suma_cislo))
    {
      alert("Chyba, 'Suma' musí byť číslo!");
      suma_cislo = 0;
    }
  // ---- end zistenie ci su ciselne hodnoty ---------------------------------
  // ---- zaokruhlenie -------------------------------------------------------
    percento_cislo = Math.round(percento_cislo * 10000) / 10000;
    suma_cislo     = Math.round(suma_cislo * 100) / 100;
  // ---- end zaokruhlenie ---------------------------------------------------
  if(pocitane_zo_sumy_cislo != 0)
    percento_cislo = (suma_cislo / pocitane_zo_sumy_cislo) * 100;
  else
    percento_cislo = 0;
    
  if(typ == 0)
    suma_spolu_cislo = pocitane_zo_sumy_cislo - suma_cislo;
  else
    suma_spolu_cislo = pocitane_zo_sumy_cislo + suma_cislo;
    
  suma.value         = suma_cislo.toFixed(2);
  percento.value     = percento_cislo.toFixed(4);
  suma_spolu.value   = suma_spolu_cislo.toFixed(2);
}

function praca_zoznam_pocet_hodin()
{
  pocet_hodin = document.getElementById('pocet_hodin');
  pocet_hodin.value = pocet_hodin.value.replace(/,/ , ".");
  var pocet_hodin_cislo = pocet_hodin.value * 1;
  if(isNaN(pocet_hodin_cislo))
  {
    alert("Chyba, 'Počet hodín' musí byť číslo!");
    pocet_hodin_cislo = 0;
  }
  pocet_hodin_cislo = Math.round(pocet_hodin_cislo * 100) / 100;
  pocet_hodin.value = pocet_hodin_cislo.toFixed(2);
}

function a_uloha_zoznam_button_go(task_id)
{
	span = "a_" + task_id;
	document.getElementById(span).innerHTML = '...';
	ajaxGetPage(span, 'ajax.php?id=project&cmd=a_uloha_zoznam_button_go&task_id=' + task_id);
}

function a_praca_zoznam_status(span_id, edit_id, praca_id)
{
  edit           = document.getElementById(edit_id);
  edit.value     = edit.value.replace(/,/ , ".");
  var edit_cislo = edit.value * 1;
  if(isNaN(edit_cislo))
  {
    alert("Chyba, 'Počet hodín' musí byť číslo!");
    edit_cislo = 0;
    edit_cislo = Math.round(edit_cislo * 100) / 100;
    edit.value = edit_cislo.toFixed(2);
  }
  else
  {
    edit_cislo = Math.round(edit_cislo * 100) / 100;
    edit.value = edit_cislo.toFixed(2);
  	document.getElementById(span_id).innerHTML = '...';
  	ajaxGetPage(span_id, 'ajax.php?id=project&cmd=a_praca_zoznam_schvalene_go&praca_id=' + praca_id + '&pocet_schv_hodin=' + edit_cislo);
  }
}

function praca_zoznam_schvalene_hodiny(edit_id)
{
  pocet_hodin = document.getElementById(edit_id);
  pocet_hodin.value = pocet_hodin.value.replace(/,/ , ".");
  var pocet_hodin_cislo = pocet_hodin.value * 1;
  if(isNaN(pocet_hodin_cislo))
  {
    alert("Chyba, 'Počet hodín' musí byť číslo!");
    pocet_hodin_cislo = 0;
  }
  pocet_hodin_cislo = Math.round(pocet_hodin_cislo * 100) / 100;
  pocet_hodin.value = pocet_hodin_cislo.toFixed(2);
}
*/
function ajax(span, address)
{
	document.getElementById(span).innerHTML = '...';
	ajaxGetPage(span, address);
}

function ajax_1p(p1_id, p1_type, span_id, address) //1 parameter (id editboxu)
{
  p1 = document.getElementById(p1_id);
  ok = 0;
  if(p1_type == 'txt')
  {
    ok = 1;
  }
  else if(p1_type == 'num')
  {
    p1.value     = p1.value.replace(/,/ , ".");
    var p1_cislo = p1.value * 1;
    if(isNaN(p1_cislo))
    {
      alert("Chyba, parameter musí byť číslo!");
      p1.value = '0';
    }
    else
    {
      ok = 1;
    }
  }
  else if(p1_type == 'num0')
  {
    p1.value     = p1.value.replace(/,/ , ".");
    var p1_cislo = p1.value * 1;
    if(isNaN(p1_cislo))
    {
      alert("Chyba, parameter musí byť číslo!");
      p1.value = '0';
    }
    else
    {
      p1_cislo = Math.round(p1_cislo * 1) / 1;
      p1.value = p1_cislo.toFixed(0);
      ok = 1;
    }
  }
  else if(p1_type == 'num1')
  {
    p1.value     = p1.value.replace(/,/ , ".");
    var p1_cislo = p1.value * 1;
    if(isNaN(p1_cislo))
    {
      alert("Chyba, parameter musí byť číslo!");
      p1.value = '0.0';
    }
    else
    {
      p1_cislo = Math.round(p1_cislo * 10) / 10;
      p1.value = p1_cislo.toFixed(1);
      ok = 1;
    }
  }
  else if(p1_type == 'num2')
  {
    p1.value     = p1.value.replace(/,/ , ".");
    var p1_cislo = p1.value * 1;
    if(isNaN(p1_cislo))
    {
      alert("Chyba, parameter musí byť číslo!");
      p1.value = '0.00';
    }
    else
    {
      p1_cislo = Math.round(p1_cislo * 100) / 100;
      p1.value = p1_cislo.toFixed(2);
      ok = 1;
    }
  }
  else if(p1_type == 'num3')
  {
    p1.value     = p1.value.replace(/,/ , ".");
    var p1_cislo = p1.value * 1;
    if(isNaN(p1_cislo))
    {
      alert("Chyba, parameter musí byť číslo!");
      p1.value = '0.000';
    }
    else
    {
      p1_cislo = Math.round(p1_cislo * 1000) / 1000;
      p1.value = p1_cislo.toFixed(3);
      ok = 1;
    }
  }
  
  if(ok == 1)
  {
    document.getElementById(span_id).innerHTML = '...';
    ajaxGetPage(span_id, address + '&p1=' + p1.value);
  }
}

function checkbox_change(id)
{
  if(document.getElementById(id).checked == true)
    document.getElementById(id).checked = false;
  else
    document.getElementById(id).checked = true;
}
/*
function project_prac_kalendar(cislo_tyzdna, prvy_den)
{
  for (j=0;j<=6;j++)
  {
    var tyz = pridaj_nuly(cislo_tyzdna, 2);
    if(document.getElementById('den_' + tyz + '_' + j))
      document.getElementById('den_' + tyz + '_' + j).value = document.getElementById('sablona_' + j).value;
  }
}

function project_prac_kalendar_all(cislo_tyzdna_zac, cislo_tyzdna_kon, prvy_den)
{
  for (i=0;i<=54;i++)
    for (j=0;j<=6;j++)
    {
      str_i = '' + i;
      var tyz = pridaj_nuly(str_i, 2);
      if(document.getElementById('den_' + tyz + '_' + j))
        document.getElementById('den_' + tyz + '_' + j).value = document.getElementById('sablona_' + j).value;
    }
}
*/
// ---- vlastne ----------------------------------------------------------------

function selectPackage(num, package_name)
{
    var pack = 'pack' + num;
    var x = document.getElementsByTagName('td');
	
	// uprav vsetky stlpce na normal
    for (var i=0;i<x.length; i++)
	{
	   var clases = x[i].className;
		if (clases.search(/pack/) > 0)
		{
            x[i].style.fontWeight = 'normal';	
        }
	}

    // uprav vybrany stlpec na font: bold
    for (var i=0;i<x.length; i++)
	{
	   var clases = x[i].className;
		if (clases.search(pack) > 0)
		{
            x[i].style.fontWeight = 'bold';	
        }
	}

    //  zablokuj vsetky input boxy	
    for (var i=1; i<5; i++)
    {
	   var sled_ico = 'sled_ico' + i;
	   document.getElementById(sled_ico).disabled = true; 
	   var uziv_ucty = 'uziv_ucty' + i;
	   document.getElementById(uziv_ucty).disabled = true; 
    }

    var sled_ico = 'sled_ico' + num;
    document.getElementById(sled_ico).disabled = false;
    var uziv_ucty = 'uziv_ucty' + num;
    document.getElementById(uziv_ucty).disabled = false;
    
    // zmen nazov balika v zmluve
    document.getElementById('typ_balika1').innerHTML = package_name;
    document.getElementById('typ_balika2').innerHTML = package_name;
    document.getElementById('typ_balika3').innerHTML = package_name;
    document.getElementById('typ_balika4').innerHTML = package_name;
    document.getElementById('typ_balika5').innerHTML = package_name;
}

function check_amount(obj, num)
{
    if(obj.value < num && obj.value != 0)
        obj.value = num;
}

function vypocitajCenu()
{
    // prejdi vsetky radio buttony a zisti, ktory je vybraty
    for(var i=1; i<5; i++)
    {
        radio_but = document.getElementById('r_pack' + i);
        if(radio_but.checked == true)
            package = i;
    }

    // zrataj hodnoty ostatnych udajov
    sled_ico = 'sled_ico' + package;
    uziv_ucty = 'uziv_ucty' + package;

    sled_ico_pocet = document.getElementById(sled_ico).value;
    uziv_ucty_pocet = document.getElementById(uziv_ucty).value;
    
    switch(package)
    {
        case 1:
            var cena_rok = 200;
            var cena_uu = 400;
            var cena_si = 40;
            break;
            
        case 2:
            var cena_rok = 800;
            var cena_uu = 200;
            var cena_si = 10;
            break;
            
        case 3:
            var cena_rok = 2500;
            var cena_uu = 150;
            var cena_si = 7;
            break;
            
        case 4:
            var cena_rok = 5000;
            var cena_uu = 80;
            var cena_si = 6;
            break;
    }

    cena_uziv_ucty = uziv_ucty_pocet * cena_uu;
    cena_sled_ico = sled_ico_pocet * cena_si;

    celkova_cena = (cena_rok + cena_uziv_ucty + cena_sled_ico);

    document.getElementById('celkova_cena').innerHTML = celkova_cena;
}


/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
*    The level - OPTIONAL
* Returns  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*/
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
 for(var item in arr) {
  var value = arr[item];
 
  if(typeof(value) == 'object') { //If it is an array,
   dumped_text += level_padding + "'" + item + "' ...\n";
   dumped_text += dump(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  }
 }
} else { //Stings/Chars/Numbers etc.
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
} 

function kopiruj_ico(ico)
{
  // prejdi vsetky radio buttony a zisti, ktory je vybraty
  ra1 = document.getElementById('ra1');
  ra2 = document.getElementById('ra2');
  txt1 = document.getElementById('txt1');
  txt2 = document.getElementById('txt2');
  
  if(ra1.checked == true)
  {
    txt1.value = ico;
  }
  else if(ra2.checked == true)
  {
    txt2.value = ico;
  }
  else
  {
    alert('chyba, nie je vybraný cieľ');
  }  
}

function getStatistiky()
{
    var select=document.getElementById('sklad_id');
	var sklad=select.options[select.selectedIndex].value;
    document.getElementById('stat_div').innerHTML = document.getElementById('ajax_progress').innerHTML;
	//var page = 'ajax.php?id=search&cmd=search';
	var page = 'ajax.php?id=statistiky&cmd=sumar&sklad_id=' + sklad;
    ajaxGetPage('stat_div', page);
}

function getMarzaForProdukt()
{
    var box = document.getElementById('akciova_cena');
    var cena = box.value;
    var select=document.getElementById('selectbox_product');
	var produkt=select.options[select.selectedIndex].value;
    
    percento = 'nie';
    if (cena.charAt(cena.length - 1) == '%')
    {
        percento = 'ano';
        cena = parseFloat(cena.substring(0,cena.length - 1));
    } 
    var page = 'ajax.php?id=akcieg&cmd=marza&produkt=' + produkt + '&cena=' + cena + '&percento=' + percento;
    document.getElementById('marza_produkt').innerHTML = '&nbsp;&nbsp;&nbsp;Prebieha výpočet...';
    ajaxGetPage('marza_produkt', page);
}

function getMarzaForKategoria()
{
    var box = document.getElementById('cat_zlava');
    var cena = box.value;
    var select=document.getElementById('fk_kategoria_id');
	
	if (select.selectedIndex == -1)
	{
	   alert('Musíte vybrať kategóriu.');
	}
	else
	{
        var kategoria=select.options[select.selectedIndex].value;
        
        percento = 'ano';
        if (cena.charAt(cena.length - 1) == '%')
        {
            percento = 'ano';
            cena = cena.substring(0,cena.length - 1);
        } 
        var page = 'ajax.php?id=akcieg&cmd=marza&kategoria=' + kategoria + '&cena=' + cena + '&percento=ano';
        document.getElementById('marza_kategoria').innerHTML = '&nbsp;&nbsp;&nbsp;Prebieha výpočet...';
        ajaxGetPage('marza_kategoria', page);
    }
}

function getOrder(idcl)
{
    var kateg = document.getElementById('selkategoria');
    var kat_id = kateg.options[kateg.selectedIndex].value;
    ajaxGetPage('order',"text.php?id=noviny&cmd=getOrder&kategoria="+kat_id+"&clanok="+idcl);
}

function clearHelpdeskTable(pocet)
{
    var tr = document.getElementsByTagName('TR');
    
    for (i=1; i<=pocet+1; i++)
    {
        tr[i].style.background = '';
    }

}

function getHelpdeskDetail(id)
{
    document.getElementById('helpdesk_detail').innerHTML = '<div style="width: 100%; background-color: #A0FF9F"><b>Nahrávam dáta...</b></div>';
    ajaxGetPage('helpdesk_detail','ajax.php?id=ulohy_out&cmd=podrobnosti&id_poziadavka='+id);
    var riadok = document.getElementById('helpdesk_tr'+id);
    riadok.style.background = 'yellow';
}

function setTermin(uloha)
{
    var termin = document.getElementById('termin_inp').value; 
    ajax('termin_return', 'ajax.php?id=ulohy_out&cmd=zmen_termin&id_polozka=' + uloha + '&termin=' + termin);
}

var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var ajax_check_login;
var ajax_url_content = '';

// AJAX - get defined page - stiahne stranku a ulozi ju do premennej
function ajaxGetPage(containerid, url)
{
	var xmlHttp;
	var ajaxreturn = 0;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 && xmlHttp.status == 200)
		{
			document.getElementById(containerid).innerHTML = xmlHttp.responseText;
		}
	}

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function tipB(tipText){
    Tip(tipText, BALLOON, true, ABOVE, true, OFFSETX, -17, FADEIN, 200, FADEOUT, 200, PADDING, 8);
}

function getEditbox(uloha)
{
    var url = '/ajax.php?id=ulohy_out&cmd=edituj_ulohu&id_polozka=' + uloha;
    //alert(url);
    ajax('helpdesk_detail', url);
}


     function add_to_xinha(data)
    {
         var editor = xinha_editors.text;
         //var txt = document.createTextNode("ahoj");
         editor.insertHTML(data);//insertNodeAtSelection(txt);
    }
    
    function add_to_xinha2(data,kam)
    {
         var editor = eval("xinha_editors."+kam);
         //var txt = document.createTextNode("ahoj");
         editor.insertHTML(data);//insertNodeAtSelection(txt);
    }
    
    function popUpWindow(varname, URL, title_window, popW,popH)
    {
        var w = 480, h = 340;

        if (document.all || document.layers)
        {
            w = self.screen.availWidth;
            h = self.screen.availHeight;
        }

        var topPos = (h-popH)-(4*h/100), leftPos = (w-popW)-(1*w/100);
        eval(varname+" =window.open(URL, title_window,'resizable=no, toolbar=no, location=no, status=no, scrollbars=no, menubar=no, titlebar=no, width=' + popW + ',height=' + popH + ',left=' + leftPos + ',top=' + topPos + ',screenX=' + leftPos + ',screenY=' + topPos);");
    }
    
    function load_nahlad(data, container)
    {
       var wnd = window.open("about:blank","nahlad","resizable=yes, toolbar=no, location=no, status=no, scrollbars=yes, menubar=no, titlebar=no, width=1000, heigth=600", true);
       //wnd.document.write("ahoj");
       var head = document.getElementsByTagName("head").item(0);
       wnd.document.write("\<\!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"\>\<html lang\=\"sk\" xmlns\=\"http://www.w3.org/1999/xhtml\" xml\:lang=\"en\"\>\<head\>"+head.innerHTML+"\</head\>");
       wnd.document.write("\<body\>"+data+"\</body\>\</html\>");
       //alert(data);
       //wnd.document.body.innerHTML = data;
       wnd.focus();
    }
    
    function nahlad_clanku()
    {
        var text_clanku = document.getElementById('XinhaIFrame_text').contentDocument.body.innerHTML;
        var nadpis_clanku = document.getElementById('nadpis').value;
        var perex_clanku  = document.getElementById('perex').value;
        text_clanku  = encodeURIComponent(text_clanku);
        perex_clanku = encodeURIComponent(perex_clanku);
        var send_data = "perex="+perex_clanku;
            send_data += "&text="+text_clanku;
            send_data += "&nadpis="+nadpis_clanku;
        ajax_obj.load(url+"ajax.php?id=web_clanky&cmd=zobraz&nahlad_btn=true", send_data, 1, "container", load_nahlad);
    }
    
    function reload_media_element(id)
    {
        ajaxGetPage("media_box_"+id, "/includes/boxes/clanky_edit_box/class.php?refresh_media="+id);
    }
    
    function test_window(id)
    {
        if (media_box[id] != null && media_box[id].closed)
        {
            window.clearInterval(test_window_timer_handle[id]);
            media_box[id] = null;
            reload_media_element(id);
        }
    }
    
    function show_admin_media(id)
    {
        media_box[id] = window.open(url+"index2.php?id=player&cmd=default","admin_media","resizable=yes, toolbar=no, location=no, status=no, scrollbars=yes, menubar=no, titlebar=no, height=600", true);
        test_window_timer_handle[id] = window.setInterval("test_window("+id+");",10);
    }
    
    function nahlad_media(id)
    {
        window.open(url+"index2.php?id=player&cmd=review&autoplay=true&idcko="+id, "mediapreview","resizable=yes, toolbar=no, location=no, status=no, scrollbars=yes, menubar=no, titlebar=no, width=800, height=600", true);
    }

    function show_admin_galeries(id)
    {
        media_box[id] = window.open(url+"index2.php?id=gallery&cmd=gallery_create","admin_galerie","resizable=yes, toolbar=no, location=no, status=no, scrollbars=yes, menubar=no, titlebar=no, height=600", true);
        test_window_timer_handle[id] = window.setInterval("test_window("+id+");",10);
    }
    
    function show_admin_anketa(id)
    {
        media_box[id] = window.open(url+"index2.php?id=dotaznik","admin_dotaznik","resizable=yes, toolbar=no, location=no, status=no, scrollbars=yes, menubar=no, titlebar=no, height=600", true);
        test_window_timer_handle[id] = window.setInterval("test_window("+id+");",10);
    }

    function odstranit_prispevok(id)
    {
        return confirm ("Naozaj chcete odstranit prispevok "+id+"?");
    }


