function flipMenu(el){
	if (el)
	{
		var id = el.id.replace('item_','');
		var open = (el.className == 'ws_menuitem_open');
		el.className = (open ? 'ws_menuitem_close' : 'ws_menuitem_open');
		ul = document.getElementById('ul_'+id);
		if(ul != null){
			ul.style.display = (open ? 'none' : 'block');
		}
		 
	
	}
}

function firstFlipMenu(el, index)
{		
	if (el)
	{
		document.getElementById('ul_'+el.id.substr(5)).style.display = "block";
		el.className = "ws_menuitem_open";
		var parent = el;
		while(parent.id.substr(0, 3) != "ul_")
		{
			parent = parent.parentNode;
		}
		
		var item = document.getElementById('item_' + parent.id.substr(3));
		
		if (parent.id != "ul_0")
		{
			flipMenu(item);
			firstFlipMenu(item);
		}
	}
	else
	{
		firstFlipSubMenu(index);
	}
}

function firstFlipSubMenu(index)
{
	el = document.getElementById('a_' + index);
	var parent = el;
	while(parent.id.substr(0, 3) != "ul_")
	{
		parent = parent.parentNode;
	}
	var item = document.getElementById('item_' + parent.id.substr(3));
	firstFlipMenu(item);
}


function init_menu(id){
	
}

// [Cookie] Clears a cookie
clearCookie = function() {
	var now = new Date();
	var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
	this.setCookie('co'+this.obj, 'cookieValue', yesterday);
	this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
};

// [Cookie] Sets value in a cookie
setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
};

// [Cookie] Gets a value from a cookie
getCookie = function(cookieName) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
};

// [Cookie] Returns ids of open nodes as a string
updateCookie = function() {
	var str = '';
	for (var n=0; n<this.aNodes.length; n++) {
		if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {
			if (str) str += '.';
			str += this.aNodes[n].id;
		}
	}
	this.setCookie('co' + this.obj, str);
};

// [Cookie] Checks if a node id is in a cookie
isOpen = function(id) {
	var aOpen = this.getCookie('co' + this.obj).split('.');
	for (var n=0; n<aOpen.length; n++)
		if (aOpen[n] == id) return true;
	return false;
};


function doXhttp(page,query)
{	
	var xmlhttp;
	if (window.ActiveXObject)	{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else{
				xmlhttp=new XMLHttpRequest();
	}
	
	if (xmlhttp) {
		var date		= new Date();
		var random		= date.getTime();
		xmlhttp.open("GET",page+'?'+query+"&"+random,true);
		xmlhttp.onreadystatechange=function() {  
		if (xmlhttp.readyState==4)
		{
			try{
				eval(xmlhttp.responseText);
			}
			catch (e){
				alert("xhttp error:\n"+e+"\n\n"+xmlhttp.responseText);
			};
	   }
	 }
	 
	 xmlhttp.send(null)
	}
}

function delArtikel(id){
	doXhttp('ws_xhttp.php', 'act=del&id='+id);
}

function updateValue(field,value,id){
	doXhttp('ws_xhttp.php', 'act=update&id='+id+'&value='+value+'&field='+field);
}

