var frameWidth = 780;
var frameHeight = 507;
var orgWidth = 780;
var orgHeight = 507;
var orgLeft = 10;
var orgTop = 10;
var edit_mode = "stand";
var selected_color = '#FD0101';
var nr_selected = 0;

function SwitchMode(mode) {
	if (mode != "stand") {
		if (mode == "zones") {
			edit_mode = "zones";
			window.frames['iFrame1'].document.getElementById("stand").style.visibility = 'hidden';
			window.frames['iFrame1'].document.getElementById("zones").style.visibility = '';
			window.frames['iFrame1'].document.getElementById("product").style.visibility = 'hidden';
			window.frames['iFrame1'].document.getElementById("sector").style.visibility = 'hidden';
			parent.document.getElementById("stands_legenda").style.display = 'none';
			parent.document.getElementById("zones_legenda").style.display = '';
			parent.document.getElementById("sector_legenda").style.display = 'none';
			parent.document.getElementById("productgroup_legenda").style.display = 'none';
		}
		if (mode == "product") {
			edit_mode = "product";
			window.frames['iFrame1'].document.getElementById("stand").style.visibility = 'hidden';
			window.frames['iFrame1'].document.getElementById("zones").style.visibility = 'hidden';
			window.frames['iFrame1'].document.getElementById("product").style.visibility = '';
			window.frames['iFrame1'].document.getElementById("sector").style.visibility = 'hidden';
			parent.document.getElementById("stands_legenda").style.display = 'none';
			parent.document.getElementById("zones_legenda").style.display = 'none';
			parent.document.getElementById("sector_legenda").style.display = 'none';
			parent.document.getElementById("productgroup_legenda").style.display = '';
		}
		if (mode == "sector") {
			edit_mode = "sector";
			window.frames['iFrame1'].document.getElementById("stand").style.visibility = 'hidden';
			window.frames['iFrame1'].document.getElementById("zones").style.visibility = 'hidden';
			window.frames['iFrame1'].document.getElementById("product").style.visibility = 'hidden';
			window.frames['iFrame1'].document.getElementById("sector").style.visibility = '';
			parent.document.getElementById("stands_legenda").style.display = 'none';
			parent.document.getElementById("zones_legenda").style.display = 'none';
			parent.document.getElementById("sector_legenda").style.display = '';
			parent.document.getElementById("productgroup_legenda").style.display = 'none';
		}
	} else if (edit_mode != "stand" && mode == "stand") {
		edit_mode = 'stand';
		window.frames['iFrame1'].document.getElementById("stand").style.visibility = '';
		window.frames['iFrame1'].document.getElementById("zones").style.visibility = 'hidden';
		window.frames['iFrame1'].document.getElementById("product").style.visibility = 'hidden';
		window.frames['iFrame1'].document.getElementById("sector").style.visibility = 'hidden';
		parent.document.getElementById("stands_legenda").style.display = '';
		parent.document.getElementById("zones_legenda").style.display = 'none';
		parent.document.getElementById("sector_legenda").style.display = 'none';
		parent.document.getElementById("productgroup_legenda").style.display = 'none';
	}
	WorkAround();
}

function ShowHideLayer(layer_code) {
	layer = window.frames['iFrame1'].document.getElementById("layer_" + layer_code);
	if (layer.style.display == 'none') {
		layer.style.display = 'inline';
		if(layer_code == 'VH') {
			layer = window.frames['iFrame1'].document.getElementById("layer_VHNL");
			if(layer != null) {
				layer.style.display = 'inline';
			}
			layer = window.frames['iFrame1'].document.getElementById("layer_VHEN");
			if(layer != null) {
				layer.style.display = 'inline';
			}
		}
	} else {
		layer.style.display = 'none';
		if(layer_code == 'VH') {
			layer = window.frames['iFrame1'].document.getElementById("layer_VHNL");
			if(layer != null) {
				layer.style.display = 'none';
			}
			layer = window.frames['iFrame1'].document.getElementById("layer_VHEN");
			if(layer != null) {
				layer.style.display = 'none';
			}
		}
	}
	WorkAround();
}

function WorkAround() {	//Functie WorkAround vanwege bug in iexplorer-vml bij uitzoomen
	var shape = window.frames['iFrame1'].document.getElementById('plattegrond');
	var oldWidth = shape.style.pixelWidth;
	var oldHeight = shape.style.pixelHeight;
	var oldLeft = shape.style.pixelLeft;
	var oldTop = shape.style.pixelTop;
	shape.style.width = Math.round(oldWidth * 1.001) + "px";
	shape.style.height = Math.round(oldHeight * 1.001) + "px";
	shape.style.left = oldLeft + "px";
	shape.style.top = oldTop + "px";
}

function zp_reset(elementid) {
	var shape = window.frames['iFrame1'].document.getElementById(elementid);
	shape.style.width = orgWidth + "px";
	shape.style.height = orgHeight + "px";	
	shape.style.left = orgLeft + "px";
	shape.style.top = orgTop + "px";	
}

function zoom(elementid, zoomfactor) {
	var shape = window.frames['iFrame1'].document.getElementById(elementid);
	var oldWidth = shape.style.pixelWidth;
	var oldHeight = shape.style.pixelHeight;
	var oldLeft = shape.style.pixelLeft;
	var oldTop = shape.style.pixelTop;
	shape.style.width = Math.round(oldWidth * zoomfactor) + "px";
	shape.style.height = Math.round(oldHeight * zoomfactor) + "px";
	shape.style.left = Math.round((frameWidth/2) - (((frameWidth/2) - oldLeft) * zoomfactor));
	shape.style.top = Math.round((frameHeight/2) - (((frameHeight/2) - oldTop) * zoomfactor));	
}

function pan(elementid, moveX, moveY) {
	var shape = window.frames['iFrame1'].document.getElementById(elementid);
	var oldLeft = shape.style.pixelLeft;
	var oldTop = shape.style.pixelTop;
	var newLeft = oldLeft + moveX;
	var newTop = oldTop + moveY;
	shape.style.left = newLeft + "px";
	shape.style.top = newTop + "px";
}


