var bV=parseInt(navigator.appVersion);
var NS4=(document.layers) ? true : false;
var IE4=((document.all)&&(bV>=4)) ? true : false;
var DOM=(!document.layers && !document.all && bV>=4) ? true : false;
var std_navi_bg = '#9933CC';
// A hack to guess if the browser supports the DOM
var capable = (NS4 || IE4 || DOM) ? true : false;

function initIt(){
	if(DOM){
		tempColl = document.getElementsByTagName("a");
		for (i=0;i<tempColl.length; i++) {
			tempColl[i].addEventListener("mouseover", mousePos, true);
		}
	} else if(IE4){
		document.onmousemove = mousePos;
	} else if(NS4){
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = mousePos;
	}
}

function mousePos(Ereignis){
	if(DOM){
		MouseX = Ereignis.pageX;
		MouseY = Ereignis.pageY;
	} else if(IE4){
		MouseX = window.event.clientX;
		MouseY = window.event.clientY;
	} else if(NS4){
		Ev = Ereignis;
		MouseX = Ev.pageX;
		MouseY = Ev.pageY;
	}
}

var active;

function startclose(){
     active = window.setTimeout("closeAll()",600);
}
function stopclose(){
     if(active){
		window.clearTimeout(active);
	}
}
function expandIt(el, OffsX, OffsY) {
	// closeAll();
	//return;
    // document.getElementById(el).className='current';

		whichEl = document.getElementById(el+'Child');
		whichEl.style.display = "block";
}

function closeAll(){
  
  closeAllByName("submenu");
  
  tempColl = document.getElementsByTagName("LI");
    for (i=0; i<tempColl.length; i++) {
        whichEl = tempColl[i];
        //if (whichEl.className == 'current')  { whichEl.className = 'normal'; }
    }
}

function closeAllByName(name){
	stopclose();

    tempColl = document.getElementsByTagName("DIV");
    for (i=0; i<tempColl.length; i++) {
        whichEl = tempColl[i];
        if (whichEl.className == name) whichEl.style.display = "none";
    }
}
/*
* Added: L. Albrzykowski
* Function to hide submenus in product section. Tu use it the inner <li> elemenys inside the menu shoul have declared clas as "normal first-submenu".
*/
function hideSubMenus()
{
	var value = getParamValue('sourceId');
	var vType = typeof(value);
	if(vType == "undefined")
	{
		value = "";
	}
	if(value!="" && value.length>'3' && value.substring(0,3)!='175')
	{
		value = value.substring(0,3);
	}
        else if(value.substring(0,3)!='175') {
                value = value.substring(0,4);
        }
	var lis = document.getElementsByTagName("li");
	for(var i=0;i<lis.length;i++)
	{
		if(navigator.userAgent.indexOf("MSIE")!=-1)
		{ 
			if(lis[i].className=="normal first-submenu" || lis[i].className=="current first-submenu"
            ||
            lis[i].className=="normal first-submenu padding1" || lis[i].className=="current first-submenu padding1"
        )
			{
				if(lis[i].id.indexOf(value)!=-1 && value!="" && value != undefined)
				{
					lis[i].style.display = "block";
				}
				else
				{
					lis[i].style.display = "none";
				}
			}
		}
		else
		{
			if(lis[i].getAttribute('class')=="normal first-submenu" || lis[i].getAttribute('class')=="current first-submenu"
            || lis[i].getAttribute('class')=="normal first-submenu padding1" || lis[i].getAttribute('class')=="current first-submenu padding1"
    )
			{
				if(lis[i].getAttribute('id').indexOf(value)!=-1 && value!="")
				{
					lis[i].setAttribute('style','display: block');
				}
				else
				{
					lis[i].setAttribute('style','display: none');
				}
			}
		}
	}
}
/*
* Added: L. Albrzykowski
* Function to hide or show the submenus in the menu (second tree) . In smarty automaticly generate the ids for the elements like: smid{smartySectionIncementedElement).
*/
function displaySubMenu(smid)
{
	var subMenu = document.getElementById('smid'+smid);
	if(navigator.userAgent.indexOf("MSIE")!=-1)
	{
		if(subMenu.style.display=="none")
		{
			subMenu.style.display="block";
		}
		else
		{
			subMenu.style.display="none";
		}
	}
	else
	{
		if(subMenu.getAttribute('style')=="display: none;" || subMenu.getAttribute('style')=="display: none")
		{
			subMenu.setAttribute('style','display: block');
		}
		else
		{
			subMenu.setAttribute('style','display: none');
		}
	}
}

/*
* Added: L. Albrzykowski
* Function initialize function hideSubMenus - using modern DOM methods.
*/
function initSubMenus(){
	if(window.addEventListener)
	{
		window.addEventListener('load',hideSubMenus,false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent('onload',hideSubMenus);
	}
}
initSubMenus();
/*
* Added: L. Albrzykowski
* Function to unset the underline at right menu.
*/
function unsetActiveLink()
{
	var i =0;
	var menu = document.getElementById('r-menu')
	var menuChilds = menu.childNodes;
	while(menu.hasChildNodes && i<menuChilds.length)
	{
		var child = document.getElementById("submenu_"+i);
		if(child){
			if(child.getAttribute('class')=="normal upper")
			child.setAttribute('style','text-decoration: none');
		}
		if(menuChilds[i].tagName =="LI" && menuChilds[i].getAttribute('class')=="normal upper" ){
			menuChilds[i].setAttribute('style','text-decoration: none');
		}
		i++;
	}
}
/*
* Added: L. Albrzykowski
* Function to set underline on the clicked link on  first level  right menus.
*/
function setActiveLink(link)
{
	unsetActiveLink();
	link.setAttribute('style','text-decoration: underline');
}

function changeClass(obj, oldClass, newClass){
        obj.className = obj.className.replace(oldClass, newClass);
}
