function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function delete_cookie ( cookie_name ){
	var cookie_date = new Date ( );  // current date & time
	cookie_date.setTime ( cookie_date.getTime() - 1 );
	document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

var pre = "_menu_";
var ctrl = "Ctrl";

function AutoShow(id, obj){
	var target = document.getElementById(id);
	var ctrlObj   = document.getElementById(id + ctrl);
	var cookie_date = new Date();
	cookie_date.setTime( cookie_date.getTime() - 1);
	if(target){
		if(target.style.display == "none"){
			target.style.display = "block";
			if(ctrlObj) ctrlObj.innerHTML = "-";
		}else{
			target.style.display = "none";
			if(ctrlObj) ctrlObj.innerHTML = "+";
		}
		setCookie(pre + id, target.style.display, 365);
		//alert(id + ", " + target.style.display);
	}
}

function AutoShowObject(id){
	var target = document.getElementById(id);
	if(target){
		if(target.style.display == "none"){
			target.style.display = "block";
		}else{
			target.style.display = "none";
		}
	}
}

function MenuInit(){
	var menuIds = new Array(
		"OpeningImages",
		"SavingAnImage",
		"Tools",
		"Filters",
		"Hierarchy",
		"Selections"
	);

	for(var i=0;i<menuIds.length;i++){
		var target  = document.getElementById(menuIds[i]);
		var ctrlObj = document.getElementById(menuIds[i] + ctrl);

		if(target){
			var value  = getCookie(pre + menuIds[i]);

			if(value == "none"){
				target.style.display = "none";
				if(ctrlObj) ctrlObj.innerHTML = "+";
			}else{
				target.style.display = "block";
				if(ctrlObj) ctrlObj.innerHTML = "-";
			}
		}
	}
}