// Script to show and hide the menu-items

//Needed to show and hover the active menus
function fktReactivateMenu(){
	fktHideSub();
	fktMenuUnHover();
	
	main_id = getCookie('active_main_menu_id');
	sub_id = getCookie('active_sub_menu_id');
	
	//Check if the page is ssph_home
	//If it is, don't reload active cookie
	var url = window.location.toString();
	if(url.indexOf("page=ssph_home") != -1){
		main_id = 0;
		sub_id = 0;
	}
	
	if(document.getElementById("menu_main_item"+main_id) != null)
		document.getElementById("menu_main_item"+main_id).style.backgroundPosition = "0px -34px";
		
	if(document.getElementById("menu_sub"+main_id) != null)
		document.getElementById("menu_sub"+main_id).style.visibility = "visible";
	if(document.getElementById("menu_sub_item"+main_id+''+sub_id) != null)
		document.getElementById("menu_sub_item"+main_id+''+sub_id).style.color = "#529a9f";
}


function fktChangeActiveMain(id){
	setCookie('active_main_menu_id',id,1);
	setCookie('active_sub_menu_id',0,1);
}
function fktChangeActiveSub(id_main,id_sub){
	setCookie('active_main_menu_id',id_main,1);
	setCookie('active_sub_menu_id',id_sub,1);
}


//clicked_item contains reference to the clicked bouton or item
//menu_id contains a string with the menu to show
function fktMenuShow(clicked_item,menu_id) {
	fktHideSub();
	fktMenuHover(clicked_item);
	if(document.getElementById(menu_id) != null)
		document.getElementById(menu_id).style.visibility = "visible";
}


//Function to hide all the menu_sub's
function fktHideSub() {
  	//Hide all menu_sub's
  	//Works only for upto 9 menu_sub's
	for (var i=1;i<10;i++){
		if(document.getElementById("menu_sub"+i) != null)
			document.getElementById("menu_sub"+i).style.visibility = "hidden";
	}
}

function fktMenuHover(citem) {
	//First: unhover all elements
	fktMenuUnHover();
	
	//Second: hover the clicked bouton
	//citem.className = "menu_main_item_active";
	citem.style.backgroundPosition = "0px -34px";
}

function fktMenuUnHover(){
	menu_main_items = document.getElementById("menu_main_container").getElementsByTagName("a");
	for (var i=0;i<menu_main_items.length;i++)
		menu_main_items[i].style.backgroundPosition = "0px 0px";
}



function setCookie(name,value,days) {
	//Need to delete cookie first, otherwise
	//IE 6 didn't overwrite the cookie on changement
	eraseCookie(name);
	
	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 getCookie(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) {
	var date = new Date();
	date.setTime(date.getTime()+(-1*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+expires+"; path=/";
}
