// js Handlers - bY kEk 11-10-05

//.......................
//...COMMON FUNCTIONS....
//.......................

String.prototype.trim=function(){
     return this.replace(/^\s+|\s+$/gm,'');
}

function addEvent(elm, evType, fn, useCapture){
	if (elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;		
	}else if(elm.attachEvent){
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}else {
		elm['on' + evType] = fn;	
	}
}


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 cleanCookies(){
	setchildActive('');
	setparentActive('');
	setitemActive('');
}


//.......................
//.....END COMMON........
//.......................

//.......................
//.....NAVIGATION........
//.......................

var childClick;

function setparentActive(value){
	createCookie("parentActive",value);
	if (!childClick){
		setchildActive(value);
	}
	setitemActive('');
}
function setchildActive(value){
	createCookie("childActive",value);
	childClick = true;
	setitemActive('');
}

function getparentActive(){
	if (readCookie("parentActive")==null){
		return '';
	}
	return readCookie("parentActive");
}
function getchildActive(){
	if (readCookie("childActive")==null){
		return '';
	}
	return readCookie("childActive");
}


//Header Menu Display
function showmenuNav(){
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
addEvent(window,'load',showmenuNav,false);


//Header Menu Active Handler
function activemenuNav(){
	if (document.all&&document.getElementById) {
		ulNav = document.getElementById("nav");
		addfunctionActive(ulNav,true);
	}
}

function addfunctionActive(ul,firstparent){
	if (ul != null){
		var i = 0;
		for (i=0; i<ul.childNodes.length; i++) {
			li = ul.childNodes[i];
				if (li.nodeName=="LI"){
					if (firstparent){
						li.onclick=function(){
							setparentActive(this.children[0].innerText);
						}
						if (li.children[0].innerText.trim()==getparentActive().trim()) {
							li.children[0].className+="-active";
						}
					}else{
						li.onclick=function(){
							setchildActive(this.children[0].innerText);
						}
					}
					if (li.children[1]!=null && li.children[1].nodeName=="UL"){
						addfunctionActive(li.children[1].childNodes[0],false);
					}
				}	
		}
	}
}

addEvent(window,'load',activemenuNav,false);

//SideMenu Active Handler
function activesideMenu(){
	if (document.all&&document.getElementById) {
		sideMenu = document.getElementById("sidemenu");
		if (sideMenu != null){
			for (i=0; i<sideMenu.childNodes.length; i++) {
				ulsideMenu = sideMenu.childNodes[i];
				if (ulsideMenu.nodeName=="UL") {
					for (i=0; i<ulsideMenu.childNodes.length; i++){
						liActive = ulsideMenu.childNodes[i];
						if (liActive.nodeName=="LI"){
							if (liActive.innerText.trim()==getchildActive().trim()){
								liActive.className+="-active";
							}
							liActive.onclick=function(){
								setchildActive(this.innerText);
							}
						}			
					}	
				}
			}
		}
	}
}
addEvent(window,'load',activesideMenu,false);


function init(){
	if (document.all&&document.getElementById) {
		var logo = document.getElementById("logo");
		if (logo!=null){
			logo.children[0].onclick=function(){
				cleanCookies();
			}	
		}
	}
}
addEvent(window,'load',init,false);

//.......................
//....END NAVIGATION.....
//.......................


//.......................
//......EXTRA MENUES......
//.......................

function setitemActive(value){
	createCookie("itemActive", value);
}

function getitemActive(){
	if (readCookie("itemActive")==null){
		return '';
	}
	return readCookie("itemActive");
}


//Mark MenuList as Active
function activemenuList(){
	if (document.all&&document.getElementById) {
		menuList = document.getElementById("menu-list");
		if (menuList != null) {
			for (i=0; i<menuList.childNodes.length; i++) {
				ulmenuList = menuList.childNodes[i];
				if (ulmenuList.nodeName=="UL") {
					for (i=0; i<ulmenuList.childNodes.length; i++){
						liActive = ulmenuList.childNodes[i];
						if (liActive.nodeName=="LI"){
							if (liActive.innerText.trim()==getitemActive().trim()){
								liActive.className="activelist";						
							}
							liActive.onclick=function(){
								setitemActive(this.innerText);
							}
						}			
					}	
				}
			}
		}
	}
}
addEvent(window,'load',activemenuList,false);

//..........................
//.....END EXTRA MENUES.....
//..........................



