
if (!isAdmin){ if (top != self){ top.location.replace(document.location); } }
window.loaded = false;
window.finished = false;
var assigningSub = false;
var deleteMe = false;


function fetchStockInfo(fetchStockInfoId){
	//only numbers or complete table?
	elFetchStockInfo = MM_findObj('limitsalesbystock'+fetchStockInfoId+'sub');
	if (elFetchStockInfo!= null){
		strClassName = elFetchStockInfo.className;
	}
	elFetchStockInfo = MM_findObj('limitsalesbystock'+fetchStockInfoId+'main');
	if (elFetchStockInfo!= null){
		strClassName = elFetchStockInfo.className;
	}
	maketable = 0;
	if (parseInt(strClassName) > 1){ maketable = 1; }
	multiplechoiceid = parseInt(strClassName.substr(strClassName.indexOf(',')+1));
	ajaxRun('plugins/fetchStockInfo.asp',displayStockInfo,'POST','id='+fetchStockInfoId+'&maketable='+maketable+'&multiplechoiceid='+multiplechoiceid,false,true)
}
function closeStockInfo(closeStockInfoId,forceClosure){
	elCloseStockInfo = null;
	if (MM_findObj('stockTable'+closeStockInfoId+'main')){
		//MM_findObj('stockTable'+closeStockInfoId).parentNode.removeChild(MM_findObj('stockTable'+closeStockInfoId));
		elCloseStockInfo = MM_findObj('stockTable'+closeStockInfoId+'main');
	}else if (MM_findObj('stockTable'+closeStockInfoId+'sub')){
		//MM_findObj('stockTable'+closeStockInfoId+'sub').parentNode.removeChild(MM_findObj('stockTable'+closeStockInfoId+'sub'));
		elCloseStockInfo = MM_findObj('stockTable'+closeStockInfoId+'sub');
	}
	if (elCloseStockInfo){
		if (elCloseStockInfo.childNodes.length > 0){
			if (forceClosure || elCloseStockInfo.childNodes[0].title == 'autoClose=true'){
				elCloseStockInfo.parentNode.removeChild(elCloseStockInfo);
			}
		}
	}
}
function displayStockInfo(xmlObj){
	if (xmlObj && xmlObj.readyState == 4){
		//if(xmlObj.status == 200){
		var txt = xmlObj.responseText;
		//alert(txt);//.substr(2000));
		var id = parseInt(txt.replace('<id>',''));
		txt = txt.replace('<id>'+id+'</id>','');
		//alert(id+'\n'+txt);
		var elStock = null;
		var stockTableId = id;
		if (MM_findObj('limitsalesbystock'+id+'main')){
			elStock = MM_findObj('limitsalesbystock'+id+'main');
		}else if (MM_findObj('limitsalesbystock'+id+'sub')){
			elStock = MM_findObj('limitsalesbystock'+id+'sub');
			stockTableId = stockTableId + 'sub';
		}
		if (elStock != null){
			maketable = false;
			if (parseInt(elStock.className) > 1){ maketable = true; }
			if (maketable){
				stockTable = document.createElement('DIV');
				stockTable.id = 'stockTable'+stockTableId;
				stockTable.style.position = 'absolute';
				stockTable.innerHTML = txt;
				//elStock.parentNode.appendChild(stockTable); <- this causes shifting of the page in IE
				document.body.appendChild(stockTable);
				//alert(findPosY(elStock)+'\n'+parseInt(stockTable.childNodes[0].offsetHeight))
				positionLayer(stockTable,findPosX(elStock),findPosY(elStock)+22-parseInt(stockTable.childNodes[0].offsetHeight),1,true);
			}else{
				if (parseInt(elStock.className) == 0){ //aangeven in eigen stock dingetje
					elStock.innerHTML = txt.replace('[split],','');
				}else{ //aangeven bij multiple property
					multiplechoiceid = parseInt(elStock.className.substr(strClassName.indexOf(',')+1));
					//qty-id,qty-id, etc.
					arrUpdate = txt.split(',');
					for (iUpdate = 0;iUpdate < arrUpdate.length - 1;iUpdate++){
						arrUpdate2 = arrUpdate[iUpdate].split('[split]');
						elDisplayQty = MM_findObj('multiplechoice'+id+'-'+multiplechoiceid+'-'+arrUpdate2[1]+'sub');
						if (elDisplayQty != null){
							elDisplayQty.innerHTML = arrUpdate2[0];
						}
						elDisplayQty = MM_findObj('multiplechoice'+id+'-'+multiplechoiceid+'-'+arrUpdate2[1]+'main');
						if (elDisplayQty != null){
							elDisplayQty.innerHTML = arrUpdate2[0];
						}
					}
					elStock.innerHTML = '';
				}
			}
		}
		//}
	}
	return;
}

function getOffsetFromTop(){ // get current y for all browsers
	if (document.layers){ //netscape vier heeft een bugje als je naar boven scrollt, er gebeurt dan niets meer
		return (window.pageYOffset > 0)?window.pageYOffset:0;
	}else{
		return window.scrollY || document.body.scrollTop || 0;
	}
}
function isSubFromTop(idToTest){ //checks whether supplied menuDivId is directly under top menu, for it displays differently when mPosition == 0
	if (MM_findObj('menuItem'+idToTest)){
		FromTopMenuItemDiv = MM_findObj('menuItem'+idToTest);
		while (FromTopMenuItemDiv.parentNode){
			FromTopMenuItemDiv = FromTopMenuItemDiv.parentNode;
			if (FromTopMenuItemDiv.id){
				if (FromTopMenuItemDiv.id.substr(0,7) == 'menuDiv'){
					return parseInt(FromTopMenuItemDiv.id.replace('menuDiv','')) == 0;
				}
			}
		}
	}
	return false;
}
function count(countinstring,stringtocount){
	counthiero = 0; counterin = 0;
	while (countinstring.indexOf(stringtocount) != -1) {
		counthiero = countinstring.indexOf(stringtocount)+1;
		countinstring = countinstring.substr(counthiero);
		counterin++;
	}
	countinstring="";
	return counterin;
}

function onHTMLload(){
	window.status = 'Starting up menu...';
	startMenu();
	window.status = 'Menu started';
	window.finished = true;
}
h = 0;
w = 0;
tableWidth = tableWidthDefault;
mFromLeft = mFromLeftDefault;
listOfSelectLists = new Array(); //filled by onBodyLoad with appropriate objects
function hideSelectListsWhenNecessary(floatingObject,x,y){ //called from positionLayer
	for (iHideSelectListsWhenNecessary = 0;iHideSelectListsWhenNecessary < listOfSelectLists.length;iHideSelectListsWhenNecessary++){
		currentSelectList = listOfSelectLists[iHideSelectListsWhenNecessary][0];
		blockingObjects = listOfSelectLists[iHideSelectListsWhenNecessary][1];
		// NOTE: blockingObjects is a copy actually, changing it doesn't affect the original in listOfSelectLists!!
		if ((findPosX(currentSelectList)<x+floatingObject.offsetWidth && x<findPosX(currentSelectList)+currentSelectList.offsetWidth) && (findPosY(currentSelectList)<y+floatingObject.offsetHeight && y<findPosY(currentSelectList)+currentSelectList.offsetHeight)){
			currentSelectList.style.visibility = 'hidden';
			blockingObjects[blockingObjects.length] = floatingObject.id;
		}else{ //the object is not shown, unhide select lists that were hidden by it and not anymore by any other object
			arrTempHideSelectLists = new Array();
			for (counter6 = 0;counter6 < blockingObjects.length;counter6++){
				if (blockingObjects[counter6] != floatingObject.id){
					if (MM_findObj(blockingObjects[counter6])){ // bloking layer might be gone without signing off!
						arrTempHideSelectLists[arrTempHideSelectLists.length] = blockingObjects[counter6];
					}
				}
			}
			listOfSelectLists[iHideSelectListsWhenNecessary][1] = arrTempHideSelectLists;
			if (listOfSelectLists[iHideSelectListsWhenNecessary][1].length == 0){
				currentSelectList.style.visibility = 'visible';
			}
		}
	}
}
function onBodyLoad(){
	try{ init(); }catch(e){ }//initialise copy-pasted script in protect.js to prevent images from being copied
	if (isAdmin){
		checkchanges('init');
	}
	if (parseInt(idFound) > 0){
		if (document.getElementById('idFound'+idFound)){
			idFoundElement = MM_findObj('idFound'+idFound);
			if (MM_findObj('menuOnPageImg'+idFound)){
				MM_findObj('menuOnPageImg'+idFound).style.border = 'solid 2px #CC99FF';
				//MM_findObj('menuOnPageImg'+idFound).style.margin = '2px';
			}else{
				idFoundElement.style.backgroundColor = '#CC99FF';
			}
		}else if (parseInt(id) != parseInt(idFound) && !isAdmin){
			docsrc = document.location.search;
			if (docsrc != ''){
				docsrc = docsrc.replace('?','&');
				docsrc = docsrc.replace('&pn='+parseInt(currentpage),'')
			}
			document.location.replace(document.location.pathname+'?pn='+(parseInt(currentpage)+1)+docsrc+'#'+idFound);
		}
	}
	h = document.body.clientHeight || window.innerHeight || document.body.offsetHeight;
	w = document.body.clientWidth || window.innerWidth || document.body.offsetWidth;
	if (tableWidthDefault == 0){ tableWidth = w - margin; }
	mFromLeft = parseInt((w - tableWidth) / 2) + mFromLeftDefault;
	m(0);
	positionLayer('lyrMenuPath',(tableWidth == 0)?margin:(w / 2 - tableWidth / 2) + mPathFromLeft,mPathFromTop);
	positionLayer('lyrZoekForm',(tableWidth == 0)?margin:(w / 2 - tableWidth / 2) + zoekFormFromLeft,zoekFormFromTop);
	positionLayer('menuItem0HomeLogo',(tableWidth == 0)?0:(w / 2 - tableWidth / 2),1);
	if (MM_findObj('lyrLanguages')){
		positionLayer('lyrLanguages',(tableWidth == 0)?margin:(w / 2 - tableWidth / 2) + languagesFromLeft,languagesFromTop,150)
	}
	cleancounter = 0;
	for (i1 = 0;i1 < document.forms.length;i1++){
		for (i2 = 0;i2 < document.forms[i1].elements.length;i2++){
			if (document.forms[i1].elements[i2].type.substr(0,6) == 'select'){
				listOfSelectLists[cleancounter] = new Array();
				listOfSelectLists[cleancounter][0] = document.forms[i1].elements[i2];
				listOfSelectLists[cleancounter][1] = new Array(); //this will hold objects that block this selectlist
				cleancounter++;
			}
		}
	}
	window.loaded = true;
	setInterval('hideSelectListsWhenNecessary(document.body.childNodes[0]);',1500);
	setTimeout('fadeSiteWarning();',1000); //function in page.js
	//go fetch stock information where needed
	for (iFetchStockInfo = 0; iFetchStockInfo < arrLimitsalesbystock.length;iFetchStockInfo++){
		fetchStockInfo(parseInt(arrLimitsalesbystock[iFetchStockInfo]));
		setTimeout('closeStockInfo('+parseInt(arrLimitsalesbystock[iFetchStockInfo])+');',3000);
	}
	if (deleteMe){
		ajaxRun('deleteMe.asp',nocb,'POST','page='+deleteMe,false,true)
	}
}
function nocb(xmlObj){
	if (xmlObj && xmlObj.readyState == 4){
		//if(xmlObj.status == 200){
		var txt = xmlObj.responseText;
		window.status = txt;
		setTimeout('window.status = window.defaultStatus;',2000);
		//}
	}
	return;
}
function onBodyResize(){
	if (document.layers){ document.location.reload(); }
	h = window.innerHeight || document.body.clientHeight || document.body.offsetHeight;
	w = document.body.clientWidth || window.innerWidth || document.body.offsetWidth;
	if (tableWidthDefault == 0){ tableWidth = w - margin; }
	mFromLeft = parseInt((w - tableWidth) / 2) + mFromLeftDefault;
	startMenu();
	m(0);
	setTimeout('afterBodyResize();',400);
}
function afterBodyResize(){
	//close all stockinfo screens for they are not repositioned
	for (iCloseStockInfo = 0; iCloseStockInfo < arrLimitsalesbystock.length; iCloseStockInfo++){
		closeStockInfo(parseInt(arrLimitsalesbystock[iCloseStockInfo]),true);
	}
	positionLayer('lyrMenuPath',(tableWidth == 0)?margin:(w / 2 - tableWidth / 2) + mPathFromLeft,mPathFromTop)
	positionLayer('lyrZoekForm',(tableWidth == 0)?margin:(w / 2 - tableWidth / 2) + zoekFormFromLeft,zoekFormFromTop)
	positionLayer('menuItem0HomeLogo',(tableWidth == 0)?0:(w / 2 - tableWidth / 2),1)
	if (MM_findObj('lyrLanguages')){
		positionLayer('lyrLanguages',(tableWidth == 0)?margin:(w / 2 - tableWidth / 2) + languagesFromLeft,languagesFromTop,150)
	}
}
function onBodyUnload(){
	if (dateassistwindow){
		if (!dateassistwindow.closed){ dateassistwindow.close(); }
	}
	if (isAdmin){ return saveChanges(); }else{ return true; }
}

mFromTop = mFromTopDefault;

function positionLayer(lyr,x,y,z,limitX,limitY){ //document.zoekForm.q.value=lyr;
	if (!z){ z = 1; }
	if (typeof lyr == 'string'){ lyr = MM_findObj(lyr); }
	if (limitX){
		if (x + lyr.offsetWidth > w){
			xSubtract = x + lyr.offsetWidth - w;
			x = x - xSubtract;
		}
	}
	if (limitY){
		if (y + lyr.offsetHeight > h + getOffsetFromTop()){
			ySubtract = y + lyr.offsetHeight - (h + getOffsetFromTop());
			y = y - ySubtract;
		}
	}
	hideSelectListsWhenNecessary(lyr,x,y);
	lyr.style.left = x;
	lyr.style.top = y;
	lyr.style.zIndex = z;
}

function startMenu(){
	from = document.getElementsByTagName('span') || document.all.tags('span');
	for (cleanCounter = 0;cleanCounter < from.length;cleanCounter++){
		startMenuDiv = from[cleanCounter];
		if (startMenuDiv.id.substr(0,7) == 'menuDiv'){
			startMenuDivId = parseInt(startMenuDiv.id.replace('menuDiv',''));
			if (startMenuDivId == 0 && mPosition == 0){ //top menu which is horizontal
				startMenuDiv.style.width = (tableWidth == 0)?w - 2 * margin:tableWidthDefault;
				//set width and class (skin) of all sub menu's
				for (counter2=0;counter2<startMenuDiv.childNodes.length;counter2++){
					tempDiv = startMenuDiv.childNodes[counter2];
					if (tempDiv.id){ //apparently also "text objects" are childNodes of startMenuDiv, no idea which ones though
						tempDivId = parseInt(tempDiv.id.replace('menuItem',''));
						mImgSwap(tempDivId);
						arrHovered[tempDivId] = false;
						tempDiv.className = 'm'+mSkins[tempDivId];
						tempDiv.style.display = 'inline';
						//also set the links themselves
						tempDiv.childNodes[0].className = 'm'+mSkins[tempDivId]+'a';
						tempDiv.childNodes[0].style.display = 'inline';
						//add selected image when this menu item has one
						if (mImgSelected[tempDivId]){
							if (MM_findObj('menuImg'+tempDivId)){ //TODO BUG how come this can be false???
								MM_findObj('menuImg'+tempDivId).src = 'upload/'+mImgSelected[tempDivId];
							}
						}
					} //only menu div's
				}
			}else{ //submenu's or vertical topmenu
				largestWidth = mItemWidthDiv;
				if (startMenuDivId > 0){ //loop through items to see which is widest and adjust menu accordingly
					largestWidth = largestWidth + 2 * mIndent;
					for (counter2=0;counter2<startMenuDiv.childNodes.length;counter2++){
						if (startMenuDiv.childNodes[counter2].offsetWidth > largestWidth){
							largestWidth = startMenuDiv.childNodes[counter2].offsetWidth;
						}	
					}
					//largestWidth = largestWidth + 2 * mIndent;
				}
				//set width and class (skin) of all sub menu's
				for (counter2=0;counter2<startMenuDiv.childNodes.length;counter2++){
					tempDiv = startMenuDiv.childNodes[counter2];
					if (tempDiv.id){ //apparently also "text objects" are childNodes of startMenuDiv, no idea which ones though
						tempDivId = parseInt(tempDiv.id.replace('menuItem',''));
						mImgSwap(tempDivId);
						arrHovered[tempDivId] = false;
						tempDiv.style.width=largestWidth;
						tempDiv.className = 'm'+mSkins[tempDivId];
						tempDiv.style.display = 'block';
						//also set the links themselves
						tempDiv.childNodes[0].style.width=largestWidth;
						tempDiv.childNodes[0].className = 'm'+mSkins[tempDivId]+'a';
						tempDiv.childNodes[0].style.display = 'block';
						//add selected image when this menu item has one
						if (mImgSelected[tempDivId]){
							MM_findObj('menuImg'+tempDivId).src = 'upload/'+mImgSelected[tempDivId];
						}
					} //only menu div's
				}
				largestWidth+=mFromLeftDefault;
				startMenuDiv.style.width=largestWidth;
				startMenuDiv.style.height = ''; //reset height to default for window might have become bigger
			}
			if (startMenuDivId > 0){
				positionLayer(startMenuDiv,-2000,-2000);
			}
			//if (arrHovered[startMenuDivId]){
			//	positionLayer(startMenuDiv,-2000,-2000);
				//startMenuDiv.style.left = -2000;
				//startMenuDiv.style.top = -2000;
			//}
		}
	}
	from = ''; //don't take up unnecessary memory space
	if (MM_findObj("mTools")){ displayMenuTools(0,true); } //hide
}
function isInPath(idToTest,idEndOfPath){
	while (idEndOfPath != idToTest && idEndOfPath > 0){
		idEndOfPath = parseInt(MM_findObj('menuItem'+idEndOfPath).parentNode.id.replace('menuDiv',''));
	}
	return idEndOfPath > 0;
}
var arrHovered = new Array();
function mUnHover(whichUnHover){
	if (whichUnHover.id){
		for (counter3 = 0;counter3 < arrHovered.length;counter3++){
			if (arrHovered[counter3]){
				mUnHoverMenuId = parseInt(whichUnHover.id.replace('menuItem',''));
				if (!isInPath(counter3,mUnHoverMenuId)){
					MM_findObj('menuItem'+counter3).className = 'm'+mSkins[counter3];
					MM_findObj('menuItem'+counter3).style.zIndex = 100;
					if (MM_findObj('menuDiv'+counter3)){
						positionLayer('menuDiv'+counter3,-2000,-2000);
					}
					mImgSwap(counter3);
					arrHovered[counter3] = false;
				}
			}
		}
	}
}
function mImgSwap(mImgSwapId){
	if (arrHovered[mImgSwapId]){
		if (document.getElementById('menuImg'+mImgSwapId)){
			if (document.getElementById('menuImg'+mImgSwapId).alt){
				mTempStr = document.getElementById('menuImg'+mImgSwapId).src;
				document.getElementById('menuImg'+mImgSwapId).src = document.getElementById('menuImg'+mImgSwapId).alt;
				document.getElementById('menuImg'+mImgSwapId).alt = mTempStr;
			}
		}
	}
}

function m(menuId,menutoolstbd,menutoolstbi){
	if (window.finished){
		clearTimeout(tomHideAll);
		localIsSubFromTop = isSubFromTop(menuId);
		var mX;
		var mY;
		thisMenuItem = MM_findObj('menuItem'+menuId);
		if (menuId == 0){
			mX = mFromLeft;//(tableWidth == 0)?margin:(w / 2 - tableWidth / 2) + mFromLeft;
			if (mPosition == 1){
				mX = (tableWidth == 0)?w - mItemWidthDiv:(w / 2 + tableWidthDefault / 2) - mItemWidthDiv;
			}
			mY = mFromTop;// + getOffsetFromTop();
			mUnHover(0);
			if (mPosition != 0){
				MM_findObj('menuDiv'+menuId).style.width = mItemWidthDiv+mFromLeftDefault;
			}
		}else{
			mUnHover(thisMenuItem);
			thisMenuItem.className = 'm'+mSkins[menuId]+'Hovered';
			thisMenuItem.style.zIndex = 101;
			if (!arrHovered[menuId]){
				if (document.getElementById('menuImg'+menuId)){
					if (document.getElementById('menuImg'+menuId).alt){
						mTempStr = document.getElementById('menuImg'+menuId).src;
						document.getElementById('menuImg'+menuId).src = document.getElementById('menuImg'+menuId).alt;
						document.getElementById('menuImg'+menuId).alt = mTempStr;
					}
				}
			}
			arrHovered[menuId] = true;
			mX = findPosX(thisMenuItem);
			mY = findPosY(thisMenuItem);
			if (!assigningSub && isAdmin){
				menutoolstbi++; //the original loopi is 0 based, the changeseq script expects 1 based.
				displayMenuTools(menuId,false,menutoolstbd,menutoolstbi,mX,mY);
			}
			//prepare mX and mY for displaying of submenu
			if ((mPosition == 0) && localIsSubFromTop){
				//mY = mY + thisMenuItem.offsetHeight; //not for kookwinkel
				mY = 118; //for kookwinkel
			}else{
				mX = mX + parseInt(thisMenuItem.style.width) - mItemWidth;
			}
		}
		if (MM_findObj('menuDiv'+menuId)){
			menuDivToPosition = MM_findObj('menuDiv'+menuId);
//menuDivToPosition.style.backgroundColor='#990000';
			if (!(menuId == 0 && mPin)){ //don't vertically position the main menu when pinned
				if (menuId == 0){
					//mY = mFromTop + getOffsetFromTop();
					mY = (getOffsetFromTop() > mFromTop + mFromTopMin)?getOffsetFromTop() + mFromTopMin:mFromTop;
				}
//if (menuId == 0){ alert(menuDivToPosition.offsetHeight+'\n'+mY+'\n'+h+'\n'+getOffsetFromTop()); }
				if (menuDivToPosition.offsetHeight + mY > h + getOffsetFromTop()){
					mY = h - mFromBottom - menuDivToPosition.offsetHeight + getOffsetFromTop();
				}
				if (mY < mFromTopMin + getOffsetFromTop()){
					mY = mFromTopMin + getOffsetFromTop();
					if ((mPosition == 0) && localIsSubFromTop){
						//nothing to do I believe
					}else{
						menuDivToPosition.style.width = parseInt(menuDivToPosition.childNodes[0].style.width) + (document.all?15:17) + mFromLeftDefault;
					}
					if (menuId != 0){ menuDivToPosition.style.height = h - mFromTopMin - mFromBottom; }
				}
			}
			if (menuId == 0 && mPosition == 0){
				menuDivToPosition.style.width = w - mFromLeft;
			}else{
				if (mX + parseInt(menuDivToPosition.style.width) > w){
					if (localIsSubFromTop){
						mX = w - parseInt(menuDivToPosition.style.width);
					}else{
//alert(findPosX(thisMenuItem)+' + '+mItemWidth+' - '+parseInt(menuDivToPosition.style.width)+' = '+(findPosX(thisMenuItem) + mItemWidth - parseInt(menuDivToPosition.style.width)));
						mX = findPosX(thisMenuItem) + mItemWidth - parseInt(menuDivToPosition.style.width);
					}
				}
			}
			if (mX < 0){ mX = 0; }
			positionLayer(menuDivToPosition,mX,mY,100);
		} 
	}
}

var rememberY = 0;
var isConstantY = true; //only trigger repositioning once after scrolling stopped...
function positionEntireMenu(){
	if (window.finished && !mPin){
		if (rememberY == getOffsetFromTop()){
			if (!isConstantY){
				setTimeout('m(0)',mDefaultScrollTime);
				counter5 = 0;
				for (counter4 = 0;counter4 < arrHovered.length;counter4++){
					if (arrHovered[counter4]){
						setTimeout('m('+counter4+');',counter5 * mDefaultScrollTime + mDefaultScrollTime);
						counter5++;
					}
				}
				isConstantY = true;
			}
		}else{
			isConstantY = false;
			rememberY = getOffsetFromTop();
		}
	}
}
tomScrollMenu = setInterval('positionEntireMenu();',mDefaultScrollTime);

tomHideAll = setTimeout('startMenu();',5000);
clearTimeout(tomHideAll);

function mOut(mOutId){
	if (window.finished){
		tomHideAll = setTimeout('startMenu();',mHideAfter);
	}
}
