function deleting(id){
	window.location="./dzest.php?id="+id;
}

function addSibiling(type, root){
	var i=0;
	if(document.getElementsByName("leve1[]")) i=document.getElementsByName("leve1[]").length;
	var s=document.getElementById("tree").appendChild(document.createElement("li"));
	var text="";
	if (type==1) text+="<form name='banner' action='bannermenu-update.php?switch=5' method='post'><input name='root' type='hidden' value='"+root+"' />";
	text+="<input id='lev"+i+"' name='leve1[]' type='text' />";
	if (type==1) text+="<input id='"+i+"labot' name='"+i+"labot' type='submit' value='Labot'>";
	text+="<input id='child"+i+"' name='child' type='button' value='Izveidot apakšsarakstu' onclick=\"addChild('"+i+"', "+type+", "+root+")\" /><input id='fin"+i+"' name='fin' type='button' value='URL jeb Links' onclick=\"addLink('"+i+"',"+type+", "+root+" )\" /><ul id='subtree"+i+"'></ul><div id='lnk"+i+"'></div>";
	if (type==1) text+="</form>";
	s.innerHTML=text;
}

function addChild(sub, type, root){
	if(document.getElementsByName("'lev"+sub+"[]")) i=document.getElementsByName("lev"+sub+"[]").length;
	var s=document.getElementById("subtree"+sub).appendChild(document.createElement("li"));
	var text="";
	if (type==1) text+="<form name='banner' action='bannermenu-update.php?switch=5' method='post'><input name='root' type='hidden' value='"+root+"' /><input name='hid' type='hidden' value='"+sub+"' />";
	text+="<input id='lev"+sub+i+"' name='lev"+sub+"[]' type='text' />";
	if (type==1) text+="<input id='"+i+"labot' name='"+i+"labot' type='submit' value='Labot'>";
	text+="<input id='child"+sub+i+"' name='child' type='button' value='Izveidot apakšsarakstu' onclick=\"addChild('"+sub+i+"', "+type+", "+root+")\" /><input id='fin"+sub+i+"' name='fin' type='button' value='URL jeb Links' onclick=\"addLink('"+sub+i+"', "+type+", "+root+")\" /><ul id='subtree"+sub+i+"'></ul><div id='lnk"+sub+i+"'></div>";
	if (type==1) text+="</form>";
	s.innerHTML=text;
	document.getElementById("fin"+sub).style.display="none";
}

function addLink(sub, type, root){
	var text="";
	if (type==1) text+="<form name='banner' action='bannermenu-update.php?switch=4' method='post'><input id='hid' name='hid' type='hidden' value='"+sub+"' /><input name='root' type='hidden' value='"+root+"' />";
	text+="Links: <input id='links"+sub+"' name='links"+sub+"' type='text' />";
	if (type==1) text+="<input id='"+sub+"labot' name='"+sub+"labot' type='submit' onclick='' value='Labot'>";
	document.getElementById("lnk"+sub).innerHTML=text;
	document.getElementById("child"+sub).style.display="none";
	document.getElementById("fin"+sub).style.display="none";
	if (type==1) text+="</form>";
}

function createnew(){
	try{// Firefox, Opera 8.0+, Safari
		return new XMLHttpRequest();
	}
	catch (e){// Internet Explorer
		try{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				return new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Sim pārlūkam nav AJAX atbalsta!");
				return false;
			}
		}
	}
}
var flag=0;
function getsub(parent){
	var xmlHttp=createnew();

	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){ // Get the data from the server's response    
			var i=0;			
			var nam=document.getElementById("a"+parent).getAttribute("name");
			while (document.getElementsByTagName('ul')[i]){
				if (document.getElementsByTagName('ul')[i].getAttribute("name")==nam){
					document.getElementsByTagName('ul')[i].innerHTML="";
					document.getElementsByTagName('ul')[i].style.visibility="hidden";
					if (document.getElementById("a"+parent).getAttribute("name")!="menu"){
						document.getElementsByTagName('ul')[i].parentNode.getElementsByTagName("div")[0].style.backgroundColor="#172627";
					}
				}
				document.getElementById("a"+parent).style.visibility="visible";
				document.getElementById("a"+parent).innerHTML=xmlHttp.responseText;	
				if (document.getElementById("a"+parent).getAttribute("name")!="menu"){
					document.getElementById("a"+parent).parentNode.getElementsByTagName("div")[0].style.backgroundColor="#305467";
				}
				i++;
			}
		}
	}
	var url="./getsubmenu.php?parent="+parent;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function closing(parent){
	if (parent){
		if (!flag){
			document.getElementById("a"+parent).style.visibility="hidden";
			document.getElementById("a"+parent).innerHTML="";
			flag=0;
		}
	}
	else{
		var i=0;
		while (document.getElementsByTagName('ul')[i]){
			if(document.getElementsByTagName('ul')[i].getAttribute("name")=="menu"){
				document.getElementsByTagName('ul')[i].style.visibility="hidden";
				document.getElementsByTagName('ul')[i].innerHTML="";
				flag=0;
			}
			i++;
		}
	}
}
