// JavaScript Document
 function velky2(x,y,orient){
	var posun = document.documentElement.scrollTop;
	 document.getElementById('nahlad').style.display="block";
	document.getElementById('nahlad').innerHTML="<img src='./obr/upload/"+x+"' alt='"+y+"' onclick='zavr()' style='cursor:pointer;' /><br /><a href='javascript:zavr()'>Zatvor náhľad</a>";
}
 function zatvor(id){
	document.getElementById(id).style.display="none";
}
 function zavr(){
	document.getElementById("nahlad").style.display="none";
}

function sendmail() {
	document.getElementById("sendmail").style.display = "block";	
}

function zmena() {
	if(document.getElementById("ajobr").checked)
		document.getElementById('obrazok').style.display="block"
	else {
		document.getElementById('obrazok').style.display="none"
	}		
}

function confirmDelete() {
	return confirm("Určite chceš zmazať to na čo si klikla?");	
}
// NEZAKOMENTOVAVAT!!!!!!!!!!!! POTREBNE!!!!!!!!!! NA FUNGOVANIE ZMENY KATEGORIIIII!!!!!! URCITE!!!!TREBA!!!!
// AJAX na zmenu podkategorii
var subhlbka = 1;
var selCat = 0;

/* NEPOUZIVA SA, POVODNA HLUPA VERZIA
function kucharkaGetSubCat_orig(catid, hlbka) {
	if(catid==0)
		return;
	if(hlbka < subhlbka) {
		selCat = catid;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
  // ak zvolim novu kategoriu, ktora nie je uplne najhlbsie, tak tymto sa odstrania vsetky jej podselecty zobrazene, aby sme mohli zobrazit novy select
	var nodeRef = document.getElementById("subcat");
	for (var i = 0; i < nodeRef.childNodes.length; i++) {
		if (nodeRef.childNodes[i].id.indexOf('dsubcat_')==0) {
			//alert("nasiel som node "+nodeRef.childNodes[i].id);
			var cislo = nodeRef.childNodes[i].id.substr(8);
			//alert(cislo);
			if(cislo > hlbka) {
				//alert("cislo "+cislo+" > "+(hlbka));
				nodeRef.removeChild(nodeRef.childNodes[i--]);
			}
		}
	}
	subhlbka = hlbka + 1;
	var url="ajax.php?method=getsubcat&catid="+catid;
	xmlHttp.onreadystatechange=subCatStateChanged; // funkcia ktora urci, ze co sa ma robit s vysledkom vratenym
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function subCatStateChanged_orig() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		var novyDiv = document.createElement("div");
		novyDiv.id = "dsubcat_"+subhlbka;
		subhlbka++;
		document.getElementById("subcat").appendChild(novyDiv);
		novyDiv.innerHTML = xmlHttp.responseText;
	} 
}
// */

// rovno sa vypise cela skupina selectov az po zvoleny select s predvolenymi nadradenymi kategoriami, aby sme usetrili mazanie a hlavne potom pri editacie komplikovane vytvaranie cez settimeout
function kucharkaGetSubCat(catid) {
	if(catid==0)
		return;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="ajax.php?method=getsubcat&catid="+catid;
	xmlHttp.onreadystatechange=subCatStateChanged; // funkcia ktora urci, ze co sa ma robit s vysledkom vratenym
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function subCatStateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		var categorySelect = document.getElementById("categorySelect");
		categorySelect.innerHTML = xmlHttp.responseText;
	} 
}

function GetXmlHttpObject(handler) { 
	var objXMLHttp=null;
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

var receptid = "";
function showPresun(recid, reccat, e) {
	document.getElementById('presun').style.Top = e.clientY + "px";
	document.getElementById('presun').style.Left = (e.clientX + 20) + "px";
	document.getElementById('presun').style.display = 'block';
	receptid = recid;
}


function presunRecept(recid) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="ajax.php?method=presun&catid="+selCat+"&recid="+receptid;
	xmlHttp.onreadystatechange=presunStateChanged; // funkcia ktora urci, ze co sa ma robit s vysledkom vratenym
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function presunStateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById("presun").style.display="none";
		//document.getElementById("presun").innerHTML = xmlHttp.responseText;
		document.location.reload(true);
		//document.location.href='?rec='+xmlHttp.responseText;
	} 
}


/*

function poslimailom(nazov){
	var Okno = window.open('kucharka/mailrec.php?nazov='+nazov, 'DynDok','height=200px ,width=300px');
}
function vytlac(nazov) {
	if(document.getElementById("ajobr").checked)
		var Okno = window.open('kucharka/printrec.php?ajobr=1&id='+nazov, 'DynDok','height=500px ,width=450px');
	else var Okno = window.open('kucharka/printrec.php?ajobr=0&id='+nazov, 'DynDok','height=500px ,width=450px');
}

var otvorene = "";
function otvor(to) {
	document.getElementById("recepty").style.display="none";
	if(otvorene=="sub_"+to.id) {
		document.getElementById(otvorene).style.display = "none";
		otvorene = "";
	}
	else {
		if(otvorene!="")
			document.getElementById(otvorene).style.display = "none";
		document.getElementById("sub_"+to.id).style.display = "block";
		otvorene = "sub_"+to.id;
	}
}

function zobrazrecept(x,zv) {
	if(!zv) zv = x;
	document.location.href = 'index.php?recepty='+x+'&zvyr='+zv;
}

function zobrazobsah(x) {
	document.location.href = 'index.php?obsah='+x;
}

var korenina1="k1";
var korenina2="l1";
function korenie(x,y){
  	document.getElementById(korenina1).style.display="none";
	document.getElementById(korenina2).style.fontWeight="normal";                      
	document.getElementById(x).style.display="block";
 	document.getElementById(y).style.fontWeight="bold";                      
   	korenina1 = x; 
   	korenina2 = y;
}

function checkkateg() {
	if(document.getElementById('sel_kategoria').value=="0") {
		document.getElementById('sel_kategoria').focus();
		alert("Zvoľ si aspoň kategóriu");
		return false;
	} else
	if(!document.getElementById('nazovr').value) {
		document.getElementById('nazovr').focus();
		alert("Vyplň názov receptu");
		return false;
	} else
	if(!document.getElementById('surovr').value) {
		document.getElementById('surovr').focus();
		alert("Vyplň suroviny potrebné na prípravu");
		return false;
	} else return true;
}
var zobrazene_sel="";
function show_sel(){
var x = document.getElementById('sel_kategoria').value;
if(zobrazene_sel!="") {
	document.getElementById("sel_"+zobrazene_sel).style.display = "none";
	document.getElementById("sel_"+zobrazene_sel).selectedIndex = 0;
}
if(document.getElementById("sel_"+x)) {
	document.getElementById("sel_"+x).style.display = "block";
	zobrazene_sel = x;

	}
}

var zvyraznene = 0;
function zvyrazni(to) {
	if(zvyraznene) {
		zvyraznene.style.fontWeight = "normal";
	}
	to.style.fontWeight = "bold";
	zvyraznene= to;
}
*/
