err_color = '#FFDDDD';
useSilentCheck = true;

var printWindow = document.location.href;
printWindow = printWindow.replace('?', '?t_loc=p&');
if (printWindow.indexOf('t_loc=p') == -1) printWindow = printWindow + '?t_loc=p&';

_ncache = {};
_nto = null;
_sto = null;

function checkValidation(land, fields) {
	if (land.selectedIndex == 0) {
		for (var i = 0, l = fields.length; i < l; i++) {
			if (!$(fields[i]).getAttribute('fc_pattern')) $(fields[i]).setAttribute('fc_pattern', $(fields[i]).getAttribute('x_fc_pattern'));
		}
	} else {
		for (var i = 0, l = fields.length; i < l; i++) {
			if ($(fields[i]).getAttribute('fc_pattern')) {
				$(fields[i]).setAttribute('x_fc_pattern', $(fields[i]).getAttribute('fc_pattern'));
				$(fields[i]).setAttribute('fc_pattern', '');
			}
		}
	}
}

function pingPopupnav() {
	if (_hto) clearTimeout(_hto);
}

function showPopupnav(el, x, waited) {
	x = x.split('|');
	var kontext = x[0];
	var id = x[1];
	x = x.join('|');
	
	if (_hto) clearTimeout(_hto);
	
	if ($('popupnav').style.display != 'none' && !waited) {
		if (_sto) clearTimeout(_sto);
		_sto = setTimeout(function() {
			showPopupnav(el, x, true);
		}, 100);
		
		return;
	} else if (!waited) {
		if (_sto) clearTimeout(_sto);
		_sto = setTimeout(function() {
			showPopupnav(el, x, true);
		}, 100);
		
		return;
	}
	
	if (_nto) clearTimeout(_nto);
	
	if (!_ncache[x]) {
		var url = '/hidden/dynkatalog/index.html?t_Kontext=' + kontext + '&t_ParentID=' + id;
		var xmlhttp;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		try {
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
		} catch (e) {
			try {
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
			} catch (E) {
				xmlhttp=false
			}
		}
		@else
			xmlhttp=false
		@end @*/
		
		if (!xmlhttp) {
			try {
				xmlhttp = new XMLHttpRequest();
			} catch (e) {
				if (window.ActiveXObject) { // IE
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} else {
					xmlhttp=false;
				}
			}
		}
		
		if (xmlhttp) {
			xmlhttp.open('GET', url, true);
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4) _ncache[x] = xmlhttp.responseText;
			}
			xmlhttp.setRequestHeader('Accept', 'message/x-formresult');
			xmlhttp.send(null);
		}
	}
	
	_nto = setTimeout(function() {
		reallyShowPopupnav(el, x);
	}, 300);
}

_rto = null;
function reallyShowPopupnav(el, x) {
	if (_ncache[x]) {
		var popupnav = $('popupnav');
		popupnav.innerHTML = _ncache[x];
		if (_ncache[x].split('float: right;').length > 1) {
			popupnav.style.width = '366px';
		} else {
			popupnav.style.width = '';
		}
		showObj(popupnav);
		var t = getY(el) - $('nf_content').scrollTop - $('left').scrollTop;
		popupnav.style.top = t + 'px';
		if (msie < 7) {
			if ($('nf_fixed').parentNode.offsetWidth < $('nf_fixed').parentNode.scrollWidth) {
				if (t + popupnav.offsetHeight > $('nf_fixed').offsetHeight - 16) {
					popupnav.style.top = $('nf_fixed').offsetHeight - popupnav.offsetHeight - 16 + 'px';
				}
			} else {
				if (t + popupnav.offsetHeight > $('nf_fixed').offsetHeight) {
					popupnav.style.top = $('nf_fixed').offsetHeight - popupnav.offsetHeight + 'px';
				}
			}
		} else {
			if (t + popupnav.offsetHeight > $('nf_fixed').offsetHeight) {
				popupnav.style.top = $('nf_fixed').offsetHeight - popupnav.offsetHeight + 'px';
			}
		}
	} else {
		setTimeout(function() {
			reallyShowPopupnav(el, x);
		}, 50);
	}
}

_hto = null;
function hidePopupnav(el) {
	if (_rto) clearTimeout(_rto);
	if (_nto) clearTimeout(_nto);
	if (_sto) clearTimeout(_sto);
	_hto = setTimeout(function() {
		reallyHidePopupnav(el);
	}, 500);
}

function reallyHidePopupnav(el) {
	if (_hto) clearTimeout(_hto);
	if (_nto) clearTimeout(_hto);
	if (_sto) clearTimeout(_hto);
	if (_rto) clearTimeout(_hto);
	hideObj('popupnav');
}

if (!haendler) {
	resetNavHeight = function() {
		try {
			var menuContainer = $('left');
			if (document.all) {
				if (msie < 7) {
					if ($('nf_fixed').parentNode.offsetWidth < $('nf_fixed').parentNode.scrollWidth) {
						menuContainer.style.height = document.documentElement.offsetHeight - 190 + 'px';
					} else {
						menuContainer.style.height = document.documentElement.offsetHeight - 175 + 'px';
					}
				} else {
					if (msie > 7) {
						if ($('nf_fixed').parentNode.offsetWidth < $('nf_fixed').offsetWidth) {
							menuContainer.style.height = document.documentElement.offsetHeight - 190 + 'px';
						} else {
							menuContainer.style.height = document.documentElement.offsetHeight - 175 + 'px';
						}
						$('nf_content').onscroll();
					} else {
						menuContainer.style.height = document.documentElement.offsetHeight - 170 + 'px';
					}
				}
			} else {
				menuContainer.style.height = $('nf_height').offsetHeight + 'px';
			}
		} catch(e) {}
		
		return true;
	}
} else {
	resetNavHeight = function() {
		var menuContainer = $('left');
		if (document.all) {
			if (msie < 7) {
				if ($('nf_fixed').parentNode.offsetWidth < $('nf_fixed').parentNode.scrollWidth) {
					menuContainer.style.height = document.documentElement.offsetHeight - 80 + 'px';
				} else {
					menuContainer.style.height = document.documentElement.offsetHeight - 65 + 'px';
				}
			} else {
				if (msie > 7) {
					if ($('nf_fixed').parentNode.offsetWidth < $('nf_fixed').offsetWidth) {
						menuContainer.style.height = document.documentElement.offsetHeight - 80 + 'px';
					} else {
						menuContainer.style.height = document.documentElement.offsetHeight - 65 + 'px';
					}
				} else {
					menuContainer.style.height = document.documentElement.offsetHeight - 60 + 'px';
				}
			}
		} else {
			menuContainer.style.height = $('nf_height').offsetHeight + 'px';
		}
		
		return true;
	}
}

var msie = 0;
var scrollto = null;

function initPage() {
	setFocus();
	
	var d_nf_content = $('nf_content');
	var d_se_parent = $('schnellerfassungbox').parentNode;
	var d_left = $('left');
	var d_right = $('right');
	
	if (navigator.userAgent.toLowerCase().match(/msie (\d+)/)) {
		msie = parseInt(navigator.userAgent.toLowerCase().match(/msie (\d+)/)[1]);
	}
	
	if (!document.all || msie > 7) {
		d_nf_content.onscroll = function() {
			if (scrollto) clearTimeout(scrollto);
			scrollto = setTimeout(function() {
				d_left.style.top = d_right.style.top = d_nf_content.scrollTop + 'px';
			}, 200);
		}
	} else {
		if (msie < 7) {
			$('nf_content').style.overflowY = 'auto';
			$('nf_content').style.overflowX = 'hidden';
			$('nf_fixed').style.display = 'none';
			$('nf_fixed').style.display = 'block';
			resetNavHeight();
		}
	}
	
	d_se_parent.appendChild($('schnellerfassungbox'));
	if ($('staffelung')) d_se_parent.appendChild($('staffelung'));
	if ($('WKAdded')) d_se_parent.appendChild($('WKAdded'));
	if ($('searchbox')) d_se_parent.appendChild($('searchbox'));
	if ($('csvexport')) d_se_parent.appendChild($('csvexport'));
	if ($('staffelung')) d_se_parent.appendChild($('staffelung'));
	if ($('csvexport2')) d_se_parent.appendChild($('csvexport2'));
	if ($('Empfehlen')) d_se_parent.appendChild($('Empfehlen'));
	if (haendler) {
		$('schnellerfassungbox').style.top = $('searchboxheader').style.display == 'none' ? '169px' : '191px';
		if ($('searchbox')) $('searchbox').style.top = '93px';
	} else {
		$('schnellerfassungbox').style.top = $('searchboxheader').style.display == 'none' ? '203px' : '226px';
		if ($('searchbox')) $('searchbox').style.top = '203px';
	}
	
	resetNavHeight();
}

window.onresize = resetNavHeight;

function getMenuData() {
	if (parent.menu2) {
		return [parent.menu1,parent.menu2,parent.menu3];
	}
}

function showSelects() {
	var sel = document.getElementsByTagName('select');
	for (var i = 0; i < sel.length; i++) {
		sel[i].style.visibility = 'visible';
	}
}

function hideSelects(id) {
	var sel = document.getElementsByTagName('select');
	var div = $(id);
	var d_l = getX(div);
	var d_t = getY(div);
	var d_r = d_l + div.offsetWidth;
	var d_b = d_t + div.offsetHeight;
	
	for (var i = 0; i < sel.length; i++) {
		var found = false;
		var pnode = sel[i];
		while (pnode.parentNode) {
			if (pnode.parentNode.id && pnode.parentNode.id == id) {
				found = true;
				break;
			}
			pnode = pnode.parentNode;
		}
		
		if (found) {
			continue;
		}
		
		var l = getX(sel[i]);
		var t = getY(sel[i]);
		var r = l + sel[i].offsetWidth;
		var b = t + sel[i].offsetHeight;
		
		if ((l >= d_l && l <= d_r) || (r >= d_l && r <= d_r) || (l <= d_l && r >= d_r)) {
			if ((t >= d_t && t <= d_b) || (b >= d_t && b <= d_b) || (t <= d_t && b >= d_b)) {
				sel[i].style.visibility = 'hidden';
			}
		}
	}
}

function toggleDiv(id) {
	if ($(id).style.display == 'none') {
		showSelects();
		if ($('searchbox') && $('searchboxheader')) {
			hideObj('searchbox');
			hideObj('searchboxheaderout');
			showObj('searchboxheader');
		}
		
		hideObj('schnellerfassungbox');
		hideObj('schnellerfassungboxheaderout');
		showObj('schnellerfassungboxheader');
		
		setTimeout(function() {
			showObj(id);
			showObj(id + 'headerout');
			hideObj(id + 'header');
			hideSelects(id);
		}, 200);
	} else {
		hideObj(id);
		hideObj(id + 'headerout');
		showObj(id + 'header');
		showSelects();
	}
}

function releaseUserInfo() {
	var url = '/hidden/xmlproduktevergleich/index.html?i2cms_i2connect=i2c_benutzer.i2connect(Method,releaseUserInfo,)';
	var xmlhttp;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try {
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	} catch (e) {
		try {
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		} catch (E) {
			xmlhttp=false
		}
	}
	@else
		xmlhttp=false
	@end @*/
	
	if (!xmlhttp) {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			if (window.ActiveXObject) { // IE
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} else {
				xmlhttp=false;
			}
		}
	}
	
	if (xmlhttp) {
		xmlhttp.open('GET', url, true);
		xmlhttp.setRequestHeader('Accept', 'message/x-formresult');
		xmlhttp.send(null);
	} 
}

function updatePos(mengefeld ) {
	if (mengefeld.value.length < 1 || mengefeld.value == '0' ) mengefeld.value = '1';
}
	
function showStaffeln(artNr) {
	el = $('staffelungContent');
	al = $('staffelungHeader');
	var staffeln = getStaffel(artNr);
	el.innerHTML = staffeln;
	al.innerHTML = al.innerHTML + " " + artNr;
	
	showObj('staffelung');
}	

function showStaffelnMitHeader(artNr, windowTitle) {
	el = $('staffelungContent');
	al = $('staffelungHeader');
	var staffeln = getStaffel(artNr);
	el.innerHTML = staffeln;
	al.innerHTML = windowTitle + " - " + artNr;
	
	showObj('staffelung');
}