function aldatu (id){
	ID = document.getElementById (id);
	loturaID = document.getElementById ("lotura" + id);

	if(ID.style.display == ""){
		ID.style.display = "none";
		eraseCookie (id);

		if (loturaID != null)
			loturaID.className = klass_itxita (id);
	}
	else{
		ID.style.display = "";
		createCookie (id, 1);

		if (loturaID != null)
			loturaID.className = klass_irekita (id);
	}
}

function klass_itxita (id){
	switch (id){
		case "m3":
			return ("gehiGrisa");
			break;
		default:
			return ("");
	}
}

function klass_irekita (id){
	switch (id){
		case "m3":
			return ("kenGrisa");
			break;
		default:
			return ("zabalduta");
	}
}

function createCookie (name, value, days) {
	if (days) {
		var date = new Date ();
		date.setTime (date.getTime () + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString ();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie (name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split (';');
	for (var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring (1, c.length);
		if (c.indexOf (nameEQ) == 0) return c.substring (nameEQ.length, c.length);
	}
	return null;
}

function eraseCookie (name) {
	createCookie (name, "", -1);
}

function menuaren_egoera_mantendu (){
	egoera_mantendu ("m1");
	egoera_mantendu ("m2");
	egoera_mantendu ("m3");	
}

function egoera_mantendu (id){
	ID = document.getElementById (id);
	loturaID = document.getElementById ("lotura" + id);

	zabalduta = readCookie (id);
	if (zabalduta == 1){
		ID.style.display = "";

		if (loturaID != null)
			loturaID.className = klass_irekita (id);
	}
	else{
		ID.style.display = "none";

		if (loturaID != null)
			loturaID.className = klass_itxita (id);
	}
}

window.onload = menuaren_egoera_mantendu;
