//zapíše datum do inputu
function zapisDen(den)
{
var year=parseInt(document.getElementById("year").value);
var month=parseInt(document.getElementById("month").value);
	
document.getElementById("datum").value=den+". "+month+". "+year;	
	
}

//zobrazí kalendář
function showCalendar()
{
      	if (window.ActiveXObject)
       		{
       		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
       		}
       	else
       		{
       		httpRequest = new XMLHttpRequest();
       		}
    	httpRequest.open("GET", "ajax/ajax_kalendar.php");
       	httpRequest.onreadystatechange= function () {processRequest("kalendar"); };
       	httpRequest.send(null);
}

//ajax změna měsíce kalendáře
//směr - 1= příští měsíc, 0=předchozí měsíc
function nextMonth(smer)
{
//načtu si hodnoty ze skrytých inputů
var year=parseInt(document.getElementById("year").value);
var month=parseInt(document.getElementById("month").value);

//přechod přes roky
      if (month == 12)
            {
            odkaz_dalsi_month=1;
            odkaz_dalsi_year=year+1;
            odkaz_zpet_month=month-1;
            odkaz_zpet_year=year;
            }
        else if (month == 1)
            {
            odkaz_dalsi_month=month+1;
            odkaz_dalsi_year=year;
            odkaz_zpet_month=12;
            odkaz_zpet_year=year-1;
            }
        else
            {
            odkaz_dalsi_month=month+1;
            odkaz_dalsi_year=year;
            odkaz_zpet_month=month-1;
            odkaz_zpet_year=year;
            }
//směr posunu
	if (smer==1)
		{
		document.getElementById("year").value=odkaz_dalsi_year;
		document.getElementById("month").value=odkaz_dalsi_month;
		year=odkaz_dalsi_year;
		month=odkaz_dalsi_month;
		}
	else
		{
		document.getElementById("year").value=odkaz_zpet_year;
		document.getElementById("month").value=odkaz_zpet_month;
		year=odkaz_zpet_year;
		month=odkaz_zpet_month;
		}

//	alert(month);
//	alert(year);

       	if (window.ActiveXObject)
       		{
       		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
       		}
       	else
       		{
       		httpRequest = new XMLHttpRequest();
       		}
    	httpRequest.open("GET", "ajax/ajax_kalendar.php?mesic="+month+"&rok="+year);
       	httpRequest.onreadystatechange= function () {processRequest("kalendar"); };
       	httpRequest.send(null);

}


//ajax pro ověření datumu z db - volá soubor ajax/ajax_check_datum.php
function checkDatum()
{
    var datum_hodnota = document.getElementById("datum").value;
//    if (datum_hodnota != 0)
//		{
        	if (window.ActiveXObject)
        		{
          		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        		}
        	else
        		{
          		httpRequest = new XMLHttpRequest();
        		}
	    	httpRequest.open("GET", "ajax/ajax_check_datum.php?datum="+datum_hodnota);
        	httpRequest.onreadystatechange= function () {processRequest("overeni_vypis"); };
        	httpRequest.send(null);
//	    }
//	else
//      	{
//    	document.getElementById("overeni_vypis").innerHTML = "";
//      	}	
}

//------------------------------------------------------------------------------------------------------------------------
function processRequest(element)
{
//alert(uroven);
  if (httpRequest.readyState == 4)
  {
    if(httpRequest.status == 200)
    {
      var sel = document.getElementById(element);
      sel.innerHTML = httpRequest.responseText;
    }
    else
    {
        alert("Chyba při načítání stránky"+ httpRequest.status +":"+ httpRequest.statusText);
    }
  }
}

