function ajx(obsluha, url, content, obj) {
	$.ajax({
	   type: "POST",
	   url: url,
	   data: "val="+content,
	   success: obsluha
	 });
}
/****************/
var http_request = false; 
var ajaxInfoDiv  = false;
function ajaxInfo(stav){
	if(!ajaxInfoDiv){
		ajaxInfoDiv = document.createElement("div");
		ajaxInfoDiv.id = "ajaxInfoDiv";
		ajaxInfoDiv.innerHTML = "<img src='images/loading.gif' />Prosím čekejte...";
		document.body.appendChild(ajaxInfoDiv);
	}
	if(stav==0){
			ajaxInfoDiv.style.visibility="hidden";
	}else{
			ajaxInfoDiv.style.visibility="visible";
	}
}
function ajax(url,data,xml){
	/*if(data)
		alert(data);*/
	url = "/"+url;
	//if(xml)
		//window.open(url+"&val="+data,"_blank");
	if (window.XMLHttpRequest) { // Mozilla, Safari,... 
		http_request = new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { // IE 
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var x;
	ajaxInfo(1);
	http_request.open("POST", url, false); 
	http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http_request.send("val="+data);
	ajaxInfo(0);
	//if (http_request.readyState == 4)
	if(xml==1){
		return http_request.responseXML;
	}else{
		return http_request.responseText;	
	}
	
}
function getXML(xml,nazev){
	var val;
	val = xml.getElementsByTagName(nazev)[0].firstChild.data;
	return val;
}
function delPref(id){
	if(!confirm("Opravdu smazat?"))return false;
	ajx(false,"/upravy.php?akce=del-vip&id="+id);
	odstran("vip",id);
	return true;
	
}
function odstran(typ,id){
	var tr = document.getElementById(typ+"-"+id);
	document.getElementById(typ).removeChild(tr);
}
/***********/
function rozbalKat(id,typ){
	var xml,ul,li;
	if(document.getElementById("kat"+typ+"-"+id).getElementsByTagName("ul").length>0){
		document.getElementById("kat"+typ+"-"+id).innerHTML = "";
		return;
	}
	xml = ajax("xml.php?akce=kategorie&id="+id,false,true);
	ul = document.createElement("ul");
	ul.id = "kats"+typ;
	document.getElementById("kat"+typ+"-"+id).appendChild(ul);
	var userNodes = xml.getElementsByTagName('kat');
		//alert(userNodes.length);
		for(i=0; i<userNodes.length; i++) {
				var nazev = userNodes[i].firstChild.data;
				var id2 = userNodes[i].getAttribute('id');
				li = document.createElement("li");
				ul.appendChild(li);
				li.innerHTML = "<input type='checkbox' name='kategorie"+typ+"[]' value='"+id2+"' id='subkat"+typ+"-"+id2+"'> <label for='subkat"+typ+"-"+id2+"'>"+nazev+"</label>";
		}
}
function rozbalKat2(id,typ){
	var xml,ul,li;
	if(document.getElementById("kat"+typ+"-"+id).getElementsByTagName("ul").length>0){
		document.getElementById("kat"+typ+"-"+id).innerHTML = "";
		return;
	}
	xml = ajax("xml.php?akce=kategorie2&id="+id+"&typ="+typ,false,true);
	ul = document.createElement("ul");
	ul.id = "kats"+typ;
	document.getElementById("kat"+typ+"-"+id).appendChild(ul);
	var userNodes = xml.getElementsByTagName('kat');
		//alert(userNodes.length);
		for(i=0; i<userNodes.length; i++) {
				var nazev = userNodes[i].firstChild.data;
				var id2 = userNodes[i].getAttribute('id');
				var on = userNodes[i].getAttribute('on');
				li = document.createElement("li");
				ul.appendChild(li);
				if(on>0)
					li.innerHTML = "<input type='checkbox' onclick='ulozKat(this,"+typ+");' name='kategorie"+typ+"[]' value='"+id2+"' id='subkat"+typ+"-"+id2+"' checked='checked' /> <label for='subkat"+typ+"-"+id2+"'>"+nazev+"</label>";
				else
					li.innerHTML = "<input type='checkbox' onclick='ulozKat(this,"+typ+");'  name='kategorie"+typ+"[]' value='"+id2+"' id='subkat"+typ+"-"+id2+"'  /> <label for='subkat"+typ+"-"+id2+"'>"+nazev+"</label>";
		}
}
function vip_link(id){
	ajx(false,"/upravy.php?akce=vip_link&id="+id);
	alert("Web byl přidán na seznam preferovaných webů.");
}