var globIdx = null;
var bMenuActive = false;
var globInfoLayer = null;

function getField(frm, fieldName) {
	/*if (typeof(frm) == "string") frm = eval("document." + frm);
	if (b.alias == "Opera") return document.getElementById(fieldName)
	else if (document.all) return eval("frm.elements('" + fieldName + "')")
	else if (document.getElementById) return document.getElementById(fieldName)
	else return eval("frm.elements['" + fieldName + "']"); */
	if (typeof(frm) == "string") {
		frm = eval("document." + frm);
	}
	if (b.alias == "Opera") {
		return document.getElementById(fieldName);
	} else if (document.all) {
		return eval("frm.elements('" + fieldName + "')");
	} else if (document.getElementById) {		
		if (document.getElementById(fieldName) == null) {						
			return eval('frm.' + fieldName);
		} else {
			return document.getElementById(fieldName);
		}
	} else {		
		return eval("frm.elements['" + fieldName + "']"); 
	}
}

function saveSettings(frm, flag) {
	mediaEl = getField(frm, '4');
	mediaStr = mediaEl.options[mediaEl.selectedIndex].value;
	fontEl = getField(frm, '1');
	fontStr = fontEl.options[fontEl.selectedIndex].value;
	familyEl = getField(frm, '2');
	familyStr = familyEl.options[familyEl.selectedIndex].value;
	lineEl = getField(frm, '3');
	lineStr = lineEl.options[lineEl.selectedIndex].value;

	if (flag == 'change') {
		url = replaceQuery('setmedia', mediaStr);
		setCookie('MEDIA', mediaStr);
		setCookie('FONT', fontStr);
		if (familyStr == 'Standard') deleteCookie('FAMILY')
		else setCookie('FAMILY', familyStr);
		setCookie('LINEHEIGHT', lineStr);
		window.location.href = url;
	}
	else if (flag == 'default') {
		url = replaceQuery('setmedia', 'WEBBROWSER_ALL');
	//	setCookie('MEDIA', 'WEBBROWSER_ALL');
	//	setCookie('FONT', '80%');
	//	setCookie('FAMILY', 'Verdana');
	//	setCookie('LINEHEIGHT', '120%');
		deleteCookie('MEDIA');
		deleteCookie('FONT');
		deleteCookie('FAMILY');
		deleteCookie('LINEHEIGHT');
		window.location.href = url;
	}
	else {
		setCookie('MEDIA', mediaStr);
		setCookie('FONT', fontStr);
		if (familyStr == 'Standard') deleteCookie('FAMILY')
		else setCookie('FAMILY', familyStr);
		setCookie('LINEHEIGHT', lineStr);
		window.location.href = '/?page=1&setmedia=' + mediaStr;
	}
}

function submitSearchSmall(frm, rootUrl) {
	naviEl = getField(frm, 'navipath');
	navipath = naviEl.value;
	countEl = getField(frm, 'count');
	count = countEl.value;
	indexEl = getField(frm, 'indexids');
	indexIds = indexEl.value;
	searchEl = getField(frm, 'searchSmall');
	searchStr = searchEl.value;
	setCookie('search', searchStr);
	url = rootUrl + '/default.aspx?page=34&indexids=' + indexIds + '&count=' + count + '&search=' + searchStr + ' AND navipath:' + navipath;
	window.location.href = url;
	return false;
}

function writeBrowser() {
	var s = "<style>";

	fontSize = getCookie('FONT');
	fontFamily = getCookie('FAMILY');
	lineHeight = getCookie('LINEHEIGHT');
	if (fontSize != null) s += "td {font-size: " + fontSize + ";}";
	if (fontFamily != null) s += "td, SELECT, TEXTAREA, INPUT {font-family: " + fontFamily + ";}";
//	if (lineHeight != null) s += "#tdPage, #tdPage td {line-height: " + lineHeight + ";}";
	if (lineHeight != null) s += "td {line-height: " + lineHeight + ";}";
	if ((b.alias == "IE" && b.version >= 4)) {
	//	s += "TEXTAREA {border: 1px solid #0099CC;}";
	//	s += "INPUT.inputField {border: 1px solid #0099CC; height: 19px;}";
	//	s += "INPUT.inputButton {border: 1px solid #0099CC; background: white;}";
	//	s += "#search {padding-left: 2px; width: 100px; border: 1px solid #999999; color: white; background: #222222;}";
		s += ".navItem {padding: 0px;}";
		s += ".navItem A {padding: 5px; padding-left: 13px; width: 166px;}";
		s += ".navItemSel {padding: 0px;}";
		s += ".navItemSel A {padding: 5px; padding-left: 13px; width: 166px;}";
		s += ".navItemCat {padding: 0px;}";
		s += ".navItemCat A {padding: 5px; padding-left: 14px; width: 185px; height: 25px;}";
		s += ".navItemCat .navLink {padding: 0px;}";
	}
	else if ((b.alias == "NS") && (b.version >= 5)) {
	}
	else if ((b.alias == "NS") && (b.version >= 4)) {
	}
	else if ((b.alias == "Opera") && (b.version >= 5)) {
	}

	s += "</style>";
	document.writeln(s);
}

function checkForm() {
	return true;
}

function checkEmail(email) {
	if ((email.indexOf('@', 0) == -1) || (email.indexOf('.', 0) == -1)) return false;
	return true;
}

function getRealNS(tempEl, typ, value, n) {
	i = 0;
	while ((tempEl != null) && (tempEl.tagName != "BODY") && (i < n)) {
		if (tempEl.className != null) {
			if ((tempEl.className.indexOf(value) != -1) || (tempEl.id == 'divMenu')) return tempEl;
		}
		tempEl = tempEl.parentNode;
		i++;
	}
	return null;
}

function getRealOffset(el, str) {
	temp = el;
	i = 0;
	while ((temp != null) && (temp.tagName != "BODY")) {
		i += eval("temp." + str);
		temp = temp.offsetParent;
	}
	return i;
}

function handleOver(e) {
	if ((b.alias == "IE") && (b.version >= 4)) {
	}
	else if ((b.alias == "NS") && (b.version >= 5)) {
	}
}

function handleOut() {
}

function handleClick() {
	bMenuActive = false;
	if (typeof(event) != "undefined") {
		toggleInfoLayers(event.srcElement);
	}
//	toggleInfoLayers();
}

function handleScroll() {
}

function handleResize() {
//	hideMenu();
}

function hover(img, flag, layerEl) {
	imgEl = document.images[img];
	if (imgEl != null) {
		if (flag) {
			if ((imgEl.src).indexOf("right") != -1) imgEl.src = imgNavRight.src
			else imgEl.src = imgNavDown.src
		}
		else {
			if ((imgEl.src).indexOf("right") != -1) imgEl.src = imgNavRightOver.src
			else imgEl.src = imgNavDownOver.src
		}
	}
}

function hideMenu() {
	if (globIdx == null) return;
	if (b.alias == "IE" && b.version >= 4) {
		topEl = eval("document.all.divTop" + globIdx);
		dropEl = eval("document.all.divDrop" + globIdx);
		if ((topEl != null) && (dropEl != null)) {
			topEl.style.visibility = "hidden";
			dropEl.style.visibility = "hidden";
			globIdx = null;
		}
	}
	else if (b.alias == "NS" && b.version >= 5) {
		topEl = document.getElementById("divTop" + globIdx);
		dropEl = document.getElementById("divDrop" + globIdx);
		if ((topEl != null) && (dropEl != null)) {
			topEl.style.visibility = "hidden";
			dropEl.style.visibility = "hidden";
			globIdx = null;
		}
	}
}

function ieHideMenu() {
	topEl = getReal((event.toElement), "className", "divDropTop");
	menuEl = getReal((event.toElement), "className", "divDropMenu");
	if ((topEl == null) && (menuEl == null)) {
		hideMenu();
	}
}

function initMenu() {
}

function dropMenu(idx, bActive) {
//	if (bClick && bMenuActive) {
//		bMenuActive = false;
//		return false;
//	}
//	else if (bClick) {
//		bMenuActive = true;
//	}
//	if (!bMenuActive) return false;
	if ((b.alias == "IE") && (b.version >= 4)) {
		if (globIdx != null) hideMenu();
		menuEl = eval("document.all.divMenu" + idx);
		topEl = eval("document.all.divTop" + idx);
		dropEl = eval("document.all.divDrop" + idx);
		if ((topEl != null) && (menuEl != null) && (dropEl != null)) {
			oTop = getRealOffset(menuEl, "offsetTop");
			oLeft = getRealOffset(menuEl, "offsetLeft") - 3;
			topEl.style.top = oTop;
			topEl.style.left = oLeft;
			dropEl.style.top = parseInt(topEl.style.top) + topEl.offsetHeight;
			dropEl.style.left = parseInt(topEl.style.left);
			topEl.onmouseout = ieHideMenu;
			dropEl.onmouseout = ieHideMenu;

			toggleSelect();

			topEl.style.visibility = "visible";
			dropEl.style.visibility = "visible";

			globIdx = idx;
		}
	}
	else if ((b.alias == "NS") && (b.version >= 5)) {
		if (globIdx != null) hideMenu();

		menuEl = document.getElementById("divMenu" + idx);
		topEl = document.getElementById("divTop" + idx);
		dropEl = document.getElementById("divDrop" + idx);
		if ((topEl != null) && (menuEl != null) && (dropEl != null)) {
			oTop = menuEl.offsetTop - 3;
			oLeft = menuEl.offsetLeft - 9;

			topEl.style.top = oTop;
			topEl.style.left = oLeft;
			dropEl.style.top = parseInt(topEl.style.top) + topEl.offsetHeight;
			dropEl.style.left = parseInt(topEl.style.left);

			toggleSelect();
	
			topEl.style.visibility = "visible";
			dropEl.style.visibility = "visible";

			globIdx = idx;
		}
	}
}

function getMenu() {
	if (m == null) return false;
	for (j=0; j<m.length; j++) {
		if (m[j].items.length > 0) {
			topId = m[j].id;
			var s = '<div class="divDropTop" id="divTop' + topId + '">';
			s += '<div class="topItem"><nobr><a href="' + m[j].href + '">' + m[j].title + '</a></nobr></div>';
			s += '</div>';
			s += '<div class="divDropMenu" id="divDrop' + topId + '">';
			s += '<img src="images/menu_shadow.gif" width="170" height="5">';
			for (i=0; i<m[j].items.length; i++) {
				s += '<div class="dropItem"><a href="' + m[j].items[i].href + '">' + m[j].items[i].title + '</a></div>';
			}
			s += '</div>';
			document.write(s);
			s = null;
		}
	}
}

function toggleSelect(bHide) {
	var dropCol = document.body.getElementsByTagName("SELECT");
	for (j=0; j<dropCol.length; j++) {
		if (bHide) dropCol[j].style.visibility = "hidden"
		else dropCol[j].style.visibility = "visible";
	}
}

function toggleInfo(id, srcStr, forceSrc) {
	el = document.getElementById(id);
	if (el != null) {
		if (el.style.display != 'block') {
			sTop = '122';
			sLeft = '197';
			if (typeof(event) != "undefined") {
				srcEl = event.srcElement;
				event.cancelBubble = true;
				if (forceSrc != null) {
				    srcEl = document.getElementById(srcStr);
				}
				sTop = getRealOffset(srcEl, 'offsetTop');
				sLeft = getRealOffset(srcEl, 'offsetLeft');
			}
			else {
				srcEl = document.getElementById(srcStr);
				if (srcEl != null) {
					sTop = getRealOffset(srcEl, 'offsetTop');
					sLeft = getRealOffset(srcEl, 'offsetLeft');
				}
			}
			el.style.top = sTop;
			el.style.left = sLeft;
			toggleSelect(true);
			if ((globInfoLayer != null)) globInfoLayer.style.display = 'none';
			el.style.display = 'block';
			globInfoLayer = el;
		}
		else {
			el.style.display = 'none';
			toggleSelect(false);
		}
	}
}

function toggleInfoLayers(srcEl) {
	if ((globInfoLayer != null)) {
		srcEl = getReal(srcEl, "id", globInfoLayer.id);
		if (srcEl == null) {
			toggleSelect(false);
			globInfoLayer.style.display = 'none';
			globInfoLayer == null;
		}
	}
	return;
	for (i=0; i<document.all.length; i++) {
		if ((document.all(i).className == "divInfoLayer") || (document.all(i).className == "divAlertLayer") || (document.all(i).className == "divHelpLayer")) {
			srcEl = getReal(srcEl, "className", "divInfoLayer");
			if (srcEl == null)
				if (document.all(i).style.display == 'block') document.all(i).style.display = 'none';
		}
	}
}

function eopenWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

/*function skapaLead(eventCode) {
 	var leadNumber = Math.round((new Date().getTime() * Math.random()));
            	var uri  = "https://tbl.tradedoubler.com/report?program=42992&event=" + eventCode + "&leadNumber=" + leadNumber;
            	document.getElementById('tb').src = uri; 
}*/

function isDefined(variable) {
    return (typeof(window[variable]) == "undefined")?  false: true;
}
