function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function SelectAll(id) {
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

function toggle(theDiv){
	var elem = document.getElementById(theDiv);
	elem.style.display = (elem.style.display == "none") ? "" : "none";
}

function showstuff (boxid) { 
   document.getElementById(boxid).style.display = ""; 
} 

function hidestuff (boxid) { 
   document.getElementById(boxid).style.display = "none"; 
}
function toggleCells (el) {
	rCells = document.getElementsByTagName('td');
	for (i = 0; i < rCells.length; i++)
		if (rCells[i].style.backgroundColor == 'white')
			rCells[i].style.backgroundColor = 'ECEAD1'
		el.style.backgroundColor = 'white'
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function popUp(url) {
	popupWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,width=570,height=450');
	self.name = "mainWin";
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function dropdownmenuload() {

// determine active root category in drop down menu
	var s_location = String(window.location).toLowerCase().replace(/\#.*$/, '');
	var e_menu = document.getElementById('dropdownmenu');
	var a_links = e_menu.getElementsByTagName('A');
	var e_navLink, e_currentElement;

	// determine active root and second level categories in tree menu
	e_menu = document.getElementById('leftNav');
	if (e_menu) {
		a_links = e_menu.getElementsByTagName('A');
		e_currentElement = null;
		var e_rootItem;

		for (var i = 0; i < a_links.length; i++) {
			if (String(a_links[i].href).toLowerCase() == s_location) {
				e_currentElement = a_links[i];
				// highlight current link
				e_currentElement.style.fontWeight = 'bold';
				var e_prevNode = e_currentElement;
				while (e_currentElement = e_currentElement.parentNode) {
					if (String(e_currentElement.className).indexOf('rootSectionLeft') != -1) {
						e_rootItem = e_currentElement;
						if (e_prevNode)
							e_prevNode.id = 'activeCategoryLeft';
						break;
					}
					e_prevNode = e_currentElement;
				}
			}
		}
	}
	
	var submenu;
	var anchor;
	var oldAnchor;
	var showInterval;
	var hideInterval;
	var inDropDown;
	
	var ddm = document.getElementById('dropdownmenu');
	ddm.onmouseover = function() {
		inDropDown = true;
		clearInterval(hideInterval);
	}
	ddm.onmouseout = function() {
		inDropDown = false;
		anchor = null;
		hideInterval = setTimeout(function(){hideSubmenu();},250);
	}
	var items = document.getElementsByName('toplevelmenuitem');
	
	var len = items.length;
	for(var i = 0; i < len; i++) {
		items[i].onmouseover = function() {
			anchor = this;
			var tmpAnchor = anchor;
			this.style.backgroundColor = "#ffffff";
			if(submenu != undefined) {
				hideSubmenu();
			}
			if(hasActiveCategory() && (this != document.getElementById("activeCategory"))) {
				document.getElementById('activeCategory').style.backgroundColor = '#cccccc';
			}
			var childlen = this.parentNode.childNodes;

			for(var k = 0; k < childlen.length; k++) {
				if(childlen[k].nodeName == "TABLE") {
					submenu = childlen[k];
					submenu.onmouseover = function() {
						
						inDropDown = true;
						anchor = tmpAnchor;
						clearInterval(hideInterval);
						anchor.style.backgroundColor = "#ffffff";
						if(hasActiveCategory()) {
							if(anchor != document.getElementById("activeCategory")) {
								document.getElementById('activeCategory').style.backgroundColor = '#cccccc';
							}
						}
					}
					submenu.onmouseout = function() {
						if (window.event && window.event.fromElement && window.event.fromElement.tagName != 'TABLE')
							return;
						
						inDropDown = false;
						hideInterval = setTimeout(function(){hideSubmenu();}, 250);
						anchor.style.backgroundColor = "#cccccc";
						if (hasActiveCategory()) {
							document.getElementById('activeCategory').style.backgroundColor = "#ffffff";
						}
					}
					showInterval = setTimeout(function(){showSubmenu(submenu);}, 250);
				}
			}
		}
		items[i].onmouseout = function() {
			oldAnchor = this;
			this.style.backgroundColor = "#cccccc";
			if (hasActiveCategory()) {
				document.getElementById('activeCategory').style.backgroundColor = '#ffffff';
			}
			clearInterval(showInterval);
			hideInterval = setTimeout(function(){hideSubmenu();},250);
		}
	}

	function showSubmenu(node) {
		
		var e_root = getElement('rootLevel');
		if (!e_root) return;

		var n_left = f_getPosition(e_root, 'Left');
		var n_top  = f_getPosition(e_root, 'Top');

		var s_location = String(window.location).toLowerCase().replace(/\#.*$/, '');


		if (b_ie7 && (s_location.indexOf('screen=') != -1)) {
			n_left += 1;
			n_top  += 1;
		}
	
		node.style.left = (n_left + (node.className == 'submenuright'
			? e_root.offsetWidth - node.offsetWidth - 8
			: + 2)) + 'px'
		
		node.style.top  = (n_top  + e_root.offsetHeight + 2) + 'px';
		node.style.visibility = 'visible';
		if (document.all) {
			var sf = document.getElementById("selectfix");
			sf.style.display = "block";
			sf.width = node.offsetWidth;
			sf.height = node.offsetHeight;
			sf.style.top = node.offsetTop;
			sf.style.left = node.offsetLeft;
		}
		var e_shade = document.getElementById('menuShade');
		if (!e_shade) return;
		f_customShade(e_shade, node.offsetWidth - 1, node.offsetHeight - 1, node.offsetLeft + 1, node.offsetTop + 1);
		e_shade.style.visibility = 'visible';
	}
	function hideSubmenu() {
		if(anchor == oldAnchor) return;
		if(inDropDown) return;
		document.getElementById("selectfix").style.display = "none";
		
		var e_shade = document.getElementById('menuShade');
		if (e_shade)
			e_shade.style.visibility = 'hidden';
		if(submenu)
			submenu.style.visibility = 'hidden';
	}
	function hasActiveCategory() {
		return (document.getElementById("activeCategory") != undefined);
	}
}

getElement = document.all ?
	function (s_id) { return document.all[s_id] } :
	function (s_id) { return document.getElementById(s_id) };

var s_userAgent = navigator.userAgent.toLowerCase();
var b_mac = s_userAgent.indexOf('mac') != -1,
	b_ie5    = s_userAgent.indexOf('msie 5') != -1,
	b_ie6    = s_userAgent.indexOf('msie 6') != -1 && s_userAgent.indexOf('opera') == -1,
	b_ie7    = s_userAgent.indexOf('msie 7') != -1,
	b_ie8    = s_userAgent.indexOf('msie 8') != -1,
	b_ieMac  = b_mac && b_ie5,
	b_safari = b_mac && s_userAgent.indexOf('safari') != -1;

function f_getPosition (e_elemRef, s_coord) {

	var n_pos = 0, n_offset,
		e_elem = e_elemRef;

	while (e_elem) {
		n_offset = e_elem["offset" + s_coord];
		n_pos += n_offset;
		e_elem = e_elem.offsetParent;
	}

	// margin correction in some browsers
	if (b_ieMac)
		n_pos += parseInt(document.body[s_coord.toLowerCase() + 'Margin']);
	else if (b_safari)
		n_pos -= n_offset;
	
	e_elem = e_elemRef;
	while (e_elem != document.body) {
		n_offset = e_elem["scroll" + s_coord];
		if (n_offset && e_elem.style.overflow == 'scroll')
			n_pos -= n_offset;
		e_elem = e_elem.parentNode;
	}
	return n_pos;
}
function f_customShade (e_container, n_width, n_height, n_left, n_top) {
	if (!e_container) return;
	if (n_width != null) e_container.style.width = (n_width + 8) + 'px';
	if (n_left != null) e_container.style.left = (n_left - 1) + 'px';
	e_container.style.top = (n_top - 1) + 'px';
	if (b_ie5 || b_ie6)
		e_container.innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td rowspan="2" colspan="2" width="6"><img src="/images/pixel.gif"></td><td width="7" height="7" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/shade_tr.png\', sizingMethod=\'scale\');"><img src="/images/pixel.gif"></td></tr><tr><td height="' + (n_height - 7) + '" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/shade_mr.png\', sizingMethod=\'scale\');"><img src="/images/pixel.gif"></td></tr><tr><td width="7" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/shade_bl.png\', sizingMethod=\'scale\');"><img src="/images/pixel.gif"></td><td style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/shade_bm.png\', sizingMethod=\'scale\');" height="7" align="left"><img src="/images/pixel.gif"></td><td style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/shade_br.png\', sizingMethod=\'scale\');"><img src="/images/pixel.gif"></td></tr></table>';
	else
		e_container.innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td rowspan="2" width="6"><img src="/images/pixel.gif"></td><td rowspan="2"><img src="/images/pixel.gif" width="' + (n_width - 6) + '" height="1"></td><td width="7" height="7"><img src="/images/shade_tr.png"></td></tr><tr><td background="/images/shade_mr.png" height="' + (n_height - 7) + '"><img src="/images/pixel.gif"></td></tr><tr><td><img src="/images/shade_bl.png"></td><td background="/images/shade_bm.png" height="7" align="left"><img src="/images/pixel.gif"></td><td><img src="/images/shade_br.png"></td></tr></table>';
}


function f_cartPopup() {
	
	// get position of anchor
	var e_cartLink = document.getElementById('cart-link');
	var e_cartPopup = document.getElementById('cart-popup');
	var e_cartPopupShade = document.getElementById('cart-popup-shade');
	if (!e_cartLink || !e_cartPopup || !e_cartPopupShade) return;

	// position 
	var n_left = f_getPosition(e_cartLink, 'Left');
	var n_top  = f_getPosition(e_cartLink, 'Top');
	
	e_cartPopup.style.left = (n_left + e_cartLink.offsetWidth + 2 - e_cartPopup.offsetWidth) + 'px';
	e_cartPopup.style.top = (n_top - 8) + 'px';
	e_cartPopup.style.visibility = 'visible';

	f_customShade(e_cartPopupShade, e_cartPopup.offsetWidth - 1, e_cartPopup.offsetHeight - 5, e_cartPopup.offsetLeft + 1, e_cartPopup.offsetTop + 5);
	e_cartPopupShade.style.visibility = 'visible';

}
function f_cartClose() {
	var e_cartPopup = document.getElementById('cart-popup');
	var e_cartPopupShade = document.getElementById('cart-popup-shade');
	if (!e_cartPopup || !e_cartPopupShade) return;
	e_cartPopup.style.visibility = 'hidden';
	e_cartPopupShade.style.visibility = 'hidden';
}


// assign mouseover event	
if (document.addEventListener)
	window.addEventListener('load', dropdownmenuload, false);
if (window.attachEvent)
	window.attachEvent('onload', dropdownmenuload);
else
	window.onload = dropdownmenuload;
