/*************************************************
* This script was developed by Zaph Webdevelopment
* for Sorprentas SA, and is subject to every kind 
* of copyright imaginable.
* (c) 2007 Zaph www.zaph.nl
**************************************************/
var kaders = true;
var fontPreviewHTML = '';
var basecolors = null;
var WorkspaceWidth = 600;
var displaceX = -50;
var object = null;
var http = null;
var produkt = '';
var maat = '';
var kleur = '';
var zijde = 0;
var sizes = null;
var fontsizes = new Array();
var curfont = 3;
var cursize = 0;
var curfontsize = -1;
var defaultfontsize = -1;
var curontwerp = 0;
var curontwerptab = 0;
var rect = null;
var x1;
var x2;
var y1;
var y2;
var realHeight = 0;
var previewImage = '';
var previewImages = new Array();
var previewImageCount = 0;
var activeRect = -1;
var activeText = null;
var toolbar = null;
var textCount = 0;
var side = 0;
var sides = 0;
var hassides = false;
var fromText = false;
var lastMouseUpX;
var lastMouseUpY;
var lastMouseX;
var lastMouseY;
var Blocks = new Array();
var fontscript = '';
var price = 0.0;
var designprice = 0.0;
var baseprice = 0.0;
var nextdesignprice = 0.0;
var nextlineprice = 0.0;
var elementCount = new Array(0, 0);
var lastQ = '';
var Log = '';
var imageurl = '';
var curkleur = S_DEFAULTKLEUR.toLowerCase();
var curkleurname = S_DEFAULTKLEUR;
var savekleur = '';
var curkleurrgb = 'fe0000';
var savekleurname = '';
var savekleurrgb = '';
var ontwerp = new Array();
var fromdata = false;


function debug(msg) {
return;
	var d = document.getElementById('debug');
	if (d)
		d.innerHTML = msg;
}

function addLog(s) {
	Log += s+'\n';
	if (0)
		alert(Log);
}

function request(q, f) {
//	alert(q);
		var async = false;
		if (async) {
			if (http.readyState) {
				http.abort();
			}
			http.onreadystatechange = function() {
				if (http.readyState == 4) {
					if (http.status == 200) {
						if (q == 'type=fontcolor') {
							fontscript = http.responseText;
//							alert('Fonts: '+fontscript);
							eval(f);
						} else {
//							alert(q+': '+http.responseText);
							eval(http.responseText);
						}
					}
				}
			};
		}
		http.open('GET', 'getdata.php?lang='+language+'&'+q+'&next='+f, async);
		http.send(null);
		if (!async) {
			if (q == 'type=fontcolor') {
				fontscript = http.responseText;
				eval(f);
			} else {
//				alert(q+'\n'+f+': '+http.responseText);
				eval(http.responseText);
			}
		}
	lastQ = q;
}

function getColors() {
	eval(fontscript);
}

function inWarning() {
	var o = document.getElementById('warning');
	if (o.style.display == 'block') {
//		alert('Warning');
		return true;
	}
	return false;
}

function setActiveClass(c) {
	if (!activeText) return;
	if (c == '') {
		document.getElementById('ontwerptable').className = 'ontwerptable_normal';
		c = 'InactiveWindow';
	}
	if (!adminmode) {
		if (activeText.body) activeText.body.className = c;
		if (activeText.obj) activeText.obj.className = c;
	}
}

function getColorSelect(soort) {
	var html = '';
	var s = '';

	getColors();
	var o = document.getElementById('ontwerptab');
	var otab = o.selectedIndex;
	var srt = Math.pow(2, soort);
	var rgb = '';
	var def = '';
	var defkleur = '';
	var rgbkleur = '';
	for (var c = 0; c < basecolors.length; c++) {
		if (srt & basecolors[c][4]) {
			if (srt == 1 || basecolors[c][5].indexOf('['+otab+']') > -1) {
				if (def == '') {
					def = basecolors[c][1];
					defkleur = basecolors[c][0];
				}
				if (soort == 0) {
					if (rgb == '' && basecolors[c][1] == activeText.fontcolor) {
						rgb = basecolors[c][0];
					}
				} else if (basecolors[c][2] == activeText.imagekleur) {
					rgb = basecolors[c][1];
					rgbkleur = basecolors[c][0];
				}	
			}
		}
	}
	if (rgb == '') {
		rgb = def;
		rgbkleur = defkleur;
	}
	if (soort == 1) {
//		activeText.imagekleur = rgbkleur;
	}
//	curkleurrgb = rgb;
//	curkleur = rgbkleur;

	var extrastyle = '';

	// soort == 1: graphic
	if (soort == 1) {
		if (ontwerp[curontwerptab][0][10] != '1') {
			// one-color graphic, no color select
			extrastyle = ';display:none';
		}
	}
	html = '<span style=\'background-color: '+curkleurrgb+extrastyle+'\' id=\'colorbutton\'><a href=\'#\' onclick=\'showColorPreview('+soort+', false);\'>';
	html += '<img title=\''+S_KIESKLEUR+'\' border=\'0\'src=\'images/edit_kleurtekst.gif\' /></a>';
	html += '</span>';
	return html;
}

function showColorPreview(soort, hide) {
	var html = '';
	var p = document.getElementById('colors');
	if (soort == 1 && ontwerp[curontwerptab][0][10] == '0') {
		p.style.display = 'none';
		return; //geen full-colour.
	}
	if (p && hide) {
		oldkleur = curkleur;
		curkleur = savekleur;
		curkleurrgb = savekleurrgb;
		p.style.display = 'none';
		displayOntwerp();
		if (activeText) {
			if (activeText.soort == 1)
				activeText.image = activeText.image.replace(oldkleur, curkleur);
			updatePreview();
		}
		return;
	}
	var o = document.getElementById('ontwerptab');
	var otab = o.selectedIndex;
	var srt = Math.pow(2, soort);
	savekleur = curkleur;
	savekleurrgb = curkleurrgb;
	var count = 0;
	for (var c = 0; c < basecolors.length; c++) {
		if (srt & basecolors[c][4])
			if (srt == 1 || basecolors[c][5].indexOf('['+otab+']') > -1) {
				count++;
			}
	}
	var cols = (count/2 - 1);
	if (count % 2 == 1)
		cols++;
	html = '<table bgcolor=\'#ffffff\' border=0 cellpadding=\'0\' cellspacing=\'5\'><tr>';
	html += '<tr><td colspan=\''+cols+'\'>'+S_KIESKLEUR+'</td><td align=\'right\'><a href=\'#\' onclick=\'savekleur=curkleur;savekleurrgb=curkleurrgb;showColorPreview('+soort+', true);\'><img border=\'0\'src=\'images/edit_ok.jpg\' /></a></td></tr>';
	var br = false;
	var teller = 0;
	for (var c = 0; c < basecolors.length; c++) {
		if (srt & basecolors[c][4]) {
			if (srt == 1 || basecolors[c][5].indexOf('['+otab+']') > -1) {
				if (teller >= count / 2 && !br) {
					html += '</tr><tr>';
					br = true;
				}
				var cl='';
				if (basecolors[c][1] == 'ffffff')
					cl = 'class=\'whitecolor\' ';
				var colorimage = '&nbsp;';
				var bgcolor = basecolors[c][1];
				if (basecolors[c][3] != '') {
					colorimage = '<img src=\'/images/kleuren/'+basecolors[c][3]+'.gif\' />';
//					bgcolor = '#ffffff';
				}
				html += '<td '+cl+'onclick=\'setColor(this, true);\' title=\''+basecolors[c][2]+'\' onmousemove=\'setColor(this, false);\' style=\'cursor: pointer; background-color: '+bgcolor+'\' width=\'20px\' >'+colorimage+'</td>';
//				if (c+1 != basecolors.length / 2 && c != basecolors.length-1)
//					html += '<td width=\'5px\'>&nbsp;</td>';
				teller++;
			}
		}
	}
	html += '</tr></table>';
	var p = document.getElementById('colors');
	p.style.width = (count/2) * 25 - 5;
	p.innerHTML = html;
	p.style.left = activeText.x;
	if (activeText.soort == 0) {
		p.style.top = activeText.y - 140;
	} else {
		p.style.top = activeText.y - 110;
	}
	p.style.display = 'block';
}

function getFontSelect() {
	var html = '';
	var s = '';

	html = '<span><a href=\'#\' onclick=\'showFontPreview();\'><img border=\'0\' height=\'20px\' id=\'fontimage\' src=\'fonts/'+fontnames[curfont]+'.png\' />';
	html += '<img title=\''+S_KIESFONT+'\' border=\'0\' src=\'images/arrow_down.png\' /></a>';
	html += '</span>';
	return html;
}

function selectFont(f) {
	curfont = f;
	var p = document.getElementById('fontpreviews');
	p.style.display = 'none';
	var p = document.getElementById('fontimage');
	p.src = 'fonts/'+fontnames[curfont]+'.png';
	activeText.font = fontnames[curfont];
	updatePreview();
}

function showFontPreview() {
	fontPreviewHTML = '<table bgcolor=\'#ffffff\' border=0 cellpadding=\'0\' cellspacing=\'0\'>';
	fontPreviewHTML += '<tr><td colspan=\'2\'>'+S_KIESFONT+'</td><td align=\'right\'><a href=\'#\' onclick=\'selectFont('+curfont+');\'><img border=\'0\'src=\'images/edit_ok.jpg\' /></a></td></tr>';
	for (var i = 0; i < fontnames.length; i++) {
		if ((i % 3) == 0) {
			if (i > 0)
				fontPreviewHTML += '</tr>';
			fontPreviewHTML += '<tr>';
		}
		s = '';
		if (i == curfont)
			s = '_select';
		fontPreviewHTML += '<td class=\'fontpreview'+s+'\'><a href=\'#\' onclick=\'selectFont('+i+');\'><img border=\'0\'id=\'fontimage'+i+'\' src=\'fonts/'+fontnames[i]+'.png\' /></a></td>';
	}
	fontPreviewHTML += '</tr></table>';
	var p = document.getElementById('fontpreviews');
	p.innerHTML = fontPreviewHTML;
	var off = $('#w_toolbar').offset();
	p.style.left = (off.left - 60) + 'px';
	p.style.top = (off.top + 25) + 'px';
	p.style.display = 'block';
}

function Toolbar(s, t) {	
	if (fromdata) return;
	if (!s) {
		if (inWarning())
			return;
		if (activeText) {
			setActiveClass('');
			if (activeText.soort == 0 && activeText.text == '') {
				dodeleteText();
				displayPrice();
			}
			activeText = null;
		}
		for (var i = 0; i < rect.length; i++) {
			o = document.getElementById('w_PDIV'+i);
			if (o)
				o.style.zIndex = 1;
		}
		toolbar.Hide();
		var p = document.getElementById('fontpreviews');
		p.style.display = 'none';
		var p = document.getElementById('colors');
		p.style.display = 'none';
	} else {
		var html = '';
		var subject='';
		var x = 0;
		if (adminmode) {
			activeText = document.getElementById('w_PDIV'+activeRect);
			activeText.x = 0;
			activeText.y = 0;
			html = '<table cellpadding=0 cellspacing=0 class="toolbar">';
			html += '<a href="#" onclick="deleteRect(); return false;"><img alt="'+S_VERWIJDEREN+'" border=0 src="images/edit_stop.jpg" /></a>';
			html += '<a href="#" onclick="Toolbar(false); return false;"><img id="klaarbutton" alt="'+S_KLAAR+'" border=0 src="images/edit_ok.jpg" /></a>';
			html += '</td></tr></table>';
		} else {
			x = activeText.x;
			switch (t) {
				case 0:
					var fb1 = '';
					var fb2 = '';
					if (curfontsize <= 0)
						fb1 = '_disable';
					if (curfontsize >= fontsizes.length)
						fb2 = '_disable';
					html = '<table border=0 cellpadding=0 cellspacing=0 class="toolbar">';
					html += '<tr><td valign="top"><a href="#" onclick="changeFontsize(this, -1); return false;"><img id="fb1" title="'+S_FONTKLEINER+'" border=0 src="images/edit_min'+fb1+'.jpg" /></a>';
					html += '<a href="#" onclick="changeFontsize(this, 1); return false;"><img border=0 id="fb2" title="'+S_FONTGROTER+'" src="images/edit_plus'+fb2+'.jpg" /></a>';
					html += '<a href="#" onclick="changeAngle(); return false;"><img title="'+S_FONTROTEREN+'" border=0 src="images/edit_turn.jpg" /></a>';
	
					if (true) {
						html += getFontSelect();
						html += getColorSelect(0);
					} else {
						html += '<select onchange="javascript:updatePreview();" id="fontname">';
						html +=	'<option value="airstream.ttf">Airstream</option>';
						html +=	'<option value="allstar.ttf">Allstar</option>';
						html +=	'<option value="amazone.ttf">Amazone</option>';
						html +=	'<option value="americantypewriter.ttf">American Typewriter</option>';
						html +=	'<option value="chiller.ttf">Chiller</option>';
						html +=	'<option value="comic.ttf">Comic</option>';
						html +=	'<option value="comicbd.ttf">Comic Bold</option>';
						html +=	'<option value="curlz.ttf">Curlz</option>';
						html +=	'<option value="dolores.ttf">Dolores</option>';
						html +=	'<option value="entrez.ttf">Entrez</option>';
						html +=	'<option value="frosty.ttf">Frosty</option>';
						html +=	'<option value="funstuff.ttf">Funstuff</option>';
						html +=	'<option value="gigi.ttf">Gigi</option>';
						html +=	'<option value="goudysto.ttf">Goudy Stout</option>';
						html +=	'<option value="impact.ttf">Impact</option>';
						html +=	'<option value="lemonade.ttf">Lemonade</option>';
						html +=	'<option value="loveletters.ttf">Love Letters</option>';
						html +=	'<option value="mangatemple.ttf">Manga Temple</option>';
						html +=	'<option value="marydale.ttf">Marydale</option>';
						html +=	'<option value="minnie.ttf">Minnie</option>';
						html +=	'<option value="oldengl.ttf">Old English</option>';
						html +=	'<option value="poornut.ttf">Poornut</option>';
						html +=	'<option value="porkys.ttf">Porky\'s</option>';
						html +=	'<option value="vagrounded.ttf">VAG Rounded</option>';
						html +=	'</select>';
					}
	
//					html += '<select onchange="javascript:updatePreview();" id="fontcolor">';
//					html +=	'</select>';
	
					html += '<a href="#" onclick="deleteText(); return false;"><img title="'+S_VERWIJDEREN+'" border=0 src="images/edit_stop.jpg" /></a>';
					html += '</td><td><a href="#" onclick="Toolbar(false); return false;"><img id="klaarbutton" title="'+S_KLAAR+'" border=0 src="images/edit_ok.jpg" /></a>';
					html += '</td></tr><tr><td><input id="tekst" type="text" size="20" value="'+activeText.text+'" /></td>';
					html += '<td align=\'right\'><a href=\'#\' onclick=\'showInfo();\'><img title=\''+S_MEERINFO+'\' border=0 src=\'images/tooltip.png\' /></a></td>';
					html += '</tr></table>';
	
					subject = S_DETEKST;
					toolbar.height = 50;
					if (x > 380) x = 380;
					break;
				case 1:
					var fb1 = '';
					var fb2 = '';
					if (cursize <= 0)
						fb1 = '_disable';
					if (cursize >= sizes.length-1)
						fb2 = '_disable';
	
					html = '<table cellpadding=0 cellspacing=0 class="toolbar">';
					html += '<tr><td><a href="#" onclick="changeFontsize(this, -1); return false;"><img id="fb1" title="'+S_ONTWERPKLEINER+'" border=0 src="images/edit_min'+fb1+'.jpg" /></a>';
					html += '<a href="#" onclick="changeFontsize(this, 1); return false;"><img border=0 id="fb2" title="'+S_ONTWERPGROTER+'" src="images/edit_plus'+fb2+'.jpg" /></a>';
					html += getColorSelect(1);
					
					html += '<select style=\'position: relative; top: -5px \' id=\'des\' name=\'des\' onchange=\'setOntwerptab(this.options[this.selectedIndex].value);\'>';
					for (c = 0; c < ontwerp.length; c++) {
						try {
						var s = (curontwerptab == ontwerp[c][0][7] ? 'selected ' : '');
						if ((produkt != '11' && ontwerp[c][0][7] != '2') || (produkt == '11'))
							html += '<option '+s+'value=\''+ontwerp[c][0][7]+'\'>'+ontwerp[c][0][9]+'</option>';
						} catch(e) {
							//alert(c);
						}
					}
					html += '</select>';
					
					html += '<a href="javascript:scrollOntwerp(-1);"><img border="0" title="'+S_VORIGONTWERP+'" src="images/pijl-left-small.jpg" /></a>';
	            			html += '<a href="javascript:scrollOntwerp(1);"><img border="0" title="'+S_VOLGENDONTWERP+'" src="images/pijl-right-small.jpg" /></a>';
					
					html += '<a href="#" onclick="deleteText(); return false;"><img title="'+S_VERWIJDEREN+'" border=0 src="images/edit_stop.jpg" /></a>';
					html += '<a href="#" onclick="Toolbar(false); return false;"><img id="klaarbutton" title="'+S_KLAAR+'" border=0 src="images/edit_ok.jpg" /></a>';
					html += '<a href=\'#\' onclick=\'showInfo();\'><img title=\''+S_MEERINFO+'\' border=0 src=\'images/tooltip.png\' /></a>';
					html += '</td></tr></table>';
	
					subject = S_HETONTWERP;
					toolbar.height = 20;
					if (x > 340) x = 340;
					break;
				default:
					//alert('Unkown: '+t);
					return;
			}
		}
		toolbar.body.innerHTML = html;
		toolbar.Move(x, activeText.y - toolbar.height - 5);
		toolbar.Show();
		if (!adminmode)
			setSelect('fontname', activeText.font);
		for (var i = 0; i < rect.length; i++) {
			o = document.getElementById('w_PDIV'+i);
			if (o)
				o.style.zIndex = -0;
		}
		if (!adminmode) {
			if (t == 0) {
				getColors();
				setSelect('fontcolor', activeText.fontcolor);
				document.getElementById('tekst').focus();
			} else {
				setOntwerptab(-1);
			}
		}
	}
}

function showInfo() {
	var o = document.getElementById('info');
//	o.style.left = 0;//toolbar.x;
//	o.style.top = 0;//toolbar.y + 100;
	o.style.display = 'block';
}

function hideInfo() {
	var o = document.getElementById('info');
	o.style.display = 'none';
}

var initialized = false;
function Init() {
	if (initialized)
		return;
	var l = document.location.toString();
	var p = l.indexOf('fromdata=1');
	if (p > 0) fromdata = true;
	DetectBrowser();
	var o = document.getElementById('editpreview');
	if(window.location.href.indexOf('connaxis-development')!=-1){
//	$('.Workspace').css('height','420px');
		if(!isIE)	var workspaceHeight2=350;
		else var workspaceHeight2=380;
	}
	else{
		var workspaceHeight2=350;
	}
	Workspace.Initialize(o, 0, 0, WorkspaceWidth, workspaceHeight2);
	Workspace.body.style.backgroundRepeat = 'no-repeat';
	Workspace.body.style.position = 'relative';
	Workspace.body.style.top = '25px';
//	Workspace.body.onClick = 'alert(1);selectRect(null);if (activeText) {setActiveClass("");activeText = null;}';
	var t = Workspace.AddTab("Preview");
	Workspace.ActivateTab("Preview");
	toolbar = Workspace.AddWindow('toolbar');
	toolbar.obj.style.zIndex = 100;
	toolbar.body.style.zIndex = 100;
	toolbar.height = 20;
	try {
		http = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e1) { 
		try { 
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e2) {
			http = typeof XMLHttpRequest != "undefined" ? new XMLHttpRequest() : null;
		}
	}
	request('type=produkt', 'Init2();');
	jQuery("#loading-studio").hide();
}

function Init2() {
	if (initialized)
		return;
	request('type=fontcolor', 'Init3();');
}

function Init3() {
	if (initialized)
		return;
	var o = document.getElementById('produkt');
	var url = '0';
	produkt = 4;
	for (i = 1; i < o.options.length; i++) {
		if (o.options[i].value == 4) 
			url = i;
	}
	url = "var o = document.getElementById('produkt');o.selectedIndex = "+url+"; getKleuren(4);";
	var u = document.location.toString();
	var p = u.indexOf('?');
	if (p>-1) {
		u = u.substring(p+1);
		var a = u.split('&');
		for (var i = 0; i < a.length; i++) {
			var b = a[i].split('=');
			if (b[0] == 'produkt' || b[0] == 'cat') {
				setSelect('produkt', b[1], false);
				var o = document.getElementById('produkt');
				produkt = o.options[o.selectedIndex].value;
				url = 'getKleuren('+produkt+'); displaySide(0);';
			}
		}
		
	}
	getMaten(produkt, url);
	window.init3Completed=true;
}

function Init4() {
	if (initialized)
		return;
	var u = document.location.toString();
	var p = u.indexOf('?');
	if (p>-1) {
		u = u.substring(p+1);
		var a = u.split('&');
		for (var i = 0; i < a.length; i++) {
			var b = a[i].split('=');
			if (b[0] == 'product') {
				setSelect('maat', b[1], false);
				var o = document.getElementById('maat');
				m = b[1];//o.options[o.selectedIndex].value;
//alert('produkt: '+m+', '+o.selectedIndex);
			}
		}
		
	}
	request('type=ontwerp', 'scrollOntwerp(0);');
	if (!fromdata) {
		for (var i = 0; i < 3; i+= 2) {
			var op = 30;
			var o = document.getElementById('ont'+i).style;
			o.opacity = (op / 100);
			o.MozOpacity = (op / 100);
			o.KhtmlOpacity = (op / 100);
			o.filter = "alpha(opacity="+op+")";
		}
	}
	initialized = true;
	setOntwerptab(0);
	var l = document.location.toString();
	var p = l.indexOf('fromdata=1');
	if (p > 0) {
		l = l.substring(p+11);
		addFromData(l);
	}
}

function getHex(d) {
	var hex = '0123456789abcdef';
	var hi = parseInt(d/16);
	var lo = d % 16;
	var h = hex.substring(hi-1, 1)+hex.substring(lo-1, 1)+' ';
	hi = hex.substring(hi, hi+1);
	lo = hex.substring(lo, lo+1);
	h = hi+lo;
	return h;
}

function rgb(r, g, b) {
	return '#'+getHex(r)+getHex(g)+getHex(b);
}

function setColor(c, final) {
	var oldkleur = curkleur;
	c = c.style.backgroundColor;
	if (!isIE)
		c = eval(c);
	for (var i = 0; i < basecolors.length; i++) {
		if ('#'+basecolors[i][1] == c) {
			curkleur = basecolors[i][0].toLowerCase();
			curkleurname = basecolors[i][2];
			curkleurrgb = c;
		}
	}
	if (activeText) {
		if (activeText.soort == 1) {
			activeText.image = activeText.image.replace(oldkleur, curkleur);
			activeText.imagekleur = curkleurname;
//			alert('1. activeText.imagekleur = '+curkleurname);
			displayOntwerp();
		}
		updatePreview();
	}
	if (final) {
		var o = document.getElementById('colors');
		o.style.display = 'none';
		o = document.getElementById('colorbutton');
		o.style.backgroundColor = c;
	}
}

function setOntwerptab(t) {
	if (fromdata) return;
	var ont = 0;
	if (t == -1) {
		var i = activeText.ontwerptab;
//		for (i = 0; i < 3; i++)
			for (j = 0; j < ontwerp[i].length; j++)
				if (ontwerp[i][j][1] == activeText.image) {
					t = i;
					ont = j;
				}
	}
	var o = document.getElementById('ontwerptab'+curontwerptab);
	if (o) {
		o.className = 'ontwerptab';
		o = document.getElementById('ontwerpimgleft'+curontwerptab);
		o.src = 'images/tab_geel_links.gif';
		o = document.getElementById('ontwerpimgright'+curontwerptab);
		o.src = 'images/tab_geel_rechts.gif';
	}
	curontwerptab = t;
	o = document.getElementById('ontwerptab'+curontwerptab);
	if (o) {
		o.className = 'ontwerptab_active';
		o = document.getElementById('ontwerpimgleft'+curontwerptab);
		o.src = 'images/tab_oranje_links.gif';
		o = document.getElementById('ontwerpimgright'+curontwerptab);
		o.src = 'images/tab_oranje_rechts.gif';
	}
	o = document.getElementById('ontwerptab');
	o.selectedIndex = curontwerptab;
	o.onchange();
	o = document.getElementById('ont0');
	o.style.display = (t == 2 ? 'none' : '');
	o = document.getElementById('ont2');
	o.style.display = (t == 2 ? 'none' : '');
	o = document.getElementById('ont1');
	o.style.width = (t == 2 ? '225px' : '75px');
	o = document.getElementById('colorbutton');
	if (o) {
		var mustrefresh = false;
		if (o.style.display == '')
			mustrefresh = true;
		o.style.display = (ontwerp[t][0][10] != '1' ? 'none' : '');
		if (mustrefresh) {
			o = document.getElementById('colors');
			if (o.style.display == 'block')
				showColorPreview(1, false);
		}
	}
	getColors();
	o = document.getElementById('ontwerptab');
	var otab = o.selectedIndex;
	var srt = 2;
	var rgb = '';
	var def = '';
	var defkleur = '';
	var defkleurname = '';
	var rgbkleur = '';
	var rgbkleurname = '';
	var msg = '';
	for (var c = 0; c < basecolors.length; c++) {
		if (2 & basecolors[c][4]) {
			if (basecolors[c][5].indexOf('['+otab+']') > -1) {
				if (def == '') {
					def = basecolors[c][1];
					defkleur = basecolors[c][0];
					defkleurname = basecolors[c][2];
				}
msg += basecolors[c][2]+': ';
				if (activeText && basecolors[c][2] == activeText.imagekleur) {
					rgb = basecolors[c][1];
					rgbkleur = basecolors[c][0];
					rgbkleurname = basecolors[c][2];
msg += 'True, ';
				}
else msg += 'False, ';
			}
		}
	}
//alert('img: '+activeText.imagekleur+' -> def: '+defkleur+', rgb: '+rgbkleur+'\n'+msg);
	if (rgb == '') {
		rgb = def;
		rgbkleur = defkleur;
		rgbkleurname = defkleurname;
	}
	curkleur = rgbkleur.toLowerCase();
	curkleurrgb = rgb;
	if (activeText) {
		activeText.imagekleur = rgbkleurname;
//		alert('2. activeText.imagekleur = '+rgbkleurname);
		o = document.getElementById('colorbutton');
		if (o) {
			o.style.backgroundColor = rgb;
		}
	}
	curontwerp = ont;
	var s = document.getElementById('des');
	o = document.getElementById('ontwerphelp');
	o.innerHTML = '&nbsp;&#8226;&nbsp;'+ontwerp[curontwerptab][0][11];
	scrollOntwerp(0);
	
}

var previewVisible = false;
function showOntwerpPreview() {
	previewVisible = true;
	var o = document.getElementById('ont1');
	var s = o.src;
	if (curontwerptab == 0) {
		s = s.replace('klein_', 'groot_');
		s = s.replace('.jpg', '.png');
	} else if (curontwerptab == 1) {
		s = s.replace('klein/klein_', 'preview/groot_');
	} else {
		s = s.replace('lak_', 'groot_lak_');
	}
	s = o.src.replace('/klein/', '/preview/');
	o = document.getElementById('ontwerppreviewimage');
	o.src = s;
}

function displayOntwerp() {
	var j;
	if (fromdata) return;
	for (var i = 0; i < 3; i++ ) {
		j = curontwerp-1+i;
		if (j >= ontwerp[curontwerptab].length)
			j -= ontwerp[curontwerptab].length;
		if (j < 0)
			j = ontwerp[curontwerptab].length-1;
		document.getElementById('ont'+i).alt = ontwerp[curontwerptab][j][0];
		if (curontwerptab == 0) {
			document.getElementById('ont'+i).src = 'images/ontwerpen/'+ontwerp[curontwerptab][j][1]+'.jpg';
		} else if (curontwerptab == 1) {
			document.getElementById('ont'+i).src = 'images/ontwerpen/monochroom/klein/'+ontwerp[curontwerptab][j][1]+'_'+curkleur+'.jpg';
		} else if (curontwerptab == 2) {
			document.getElementById('ont'+i).src = 'images/ontwerpen/laken/'+ontwerp[curontwerptab][j][1]+'.gif';
		} else {
			document.getElementById('ont'+i).src = 'images/ontwerpen/glitter/'+ontwerp[curontwerptab][j][1]+'.gif';
		}
		var multi = '';
		if (design_multi[curontwerptab] == 1)
			multi = '_'+curkleur;
		document.getElementById('ont'+i).src = 'images/ontwerpen/'+ontwerp[curontwerptab][j][8]+'/klein/'+ontwerp[curontwerptab][j][1]+multi+'.jpg';
	}
}

function scrollOntwerp(d) {
	if (fromdata) return;
	curontwerp += d;
	if (curontwerp >= ontwerp[curontwerptab].length)
		curontwerp -= ontwerp[curontwerptab].length;
	if (curontwerp < 0)
		curontwerp = ontwerp[curontwerptab].length-1;
	displayOntwerp();
	updateSizes(curontwerp);
	if (activeText)
		if (activeText.soort == 1) {
			activeText.ontwerp = curontwerp;
			activeText.ontwerptab = curontwerptab;
			activeText.image = ontwerp[curontwerptab][curontwerp][1];
			changeFontsize(null, 0);
		}
}

function initKleur(cur) {
	if (cur == 'undefined' || cur == 0) {
		cur = S_DEFAULTKLEUR;
	}
	var lcur = cur.toLowerCase();
	var k = document.getElementById('kleur');
	if (fromdata) {
		k.disabled = true;
		return;
	}
	for (var i =  0; i < k.options.length; i++) {
		if (k.options[i].value.toLowerCase() == lcur) {
			kleur = cur;
			k.selectedIndex = i;
			return;
		}
	}
}

function getKleuren(p, m) {
	if (inWarning()) {
		var o = document.getElementById('warning');
		o.style.display = 'none';
		Toolbar(false);
	}
	produkt = p;
	var tmp = 0;
	var o = document.getElementById('maat');
	tmp = o.selectedIndex;
	if (m == undefined) {
		m = o.options[o.selectedIndex].value;
	}
	o = document.getElementById('kleur');
	var curk = o.options[o.selectedIndex].value;
	o = document.getElementById('ontwerphier');
	if (o)
		o.innerHTML = S_ONTWERPHIER;
//		o.innerHTML = (tmp == 0 ? S_ONTWERPHIERMAAT : S_ONTWERPHIER);
	request('type=kleur&maat='+m+'&produkt='+produkt, 'initKleur("'+curk+'"); checkKleur(document.getElementById(\'kleur\')); updateSize(); updatePreview();');
return;
	deleteAllText();
	displaySide(0);
	var o = document.getElementById('ontwerpcontainer2');
	var t = 0;
	if (p == '11') {
		o.style.display = '';
		t = 2;
	} else {
		o.style.display = 'none';
	}
	setOntwerptab(t);
}

function destroyRectangles(n) {
	if (rect) {
//		alert('Remove '+rect.length+' rectangles');
		for (var i = 0; i < rect.length; i++) {
//			alert('Remove PDIV'+i);
			Workspace.DeleteWindow('PDIV'+i);
		}
		rect = new Array();
	}
	activeRect = -1;
}

function setSelect(s, v, h) {
	v = v.toString();
	var o = document.getElementById(s);
	if (o) {
		for (var i = 0; i < o.options.length; i++) {
			if ((!h && o.options[i].value == v) || (h && o.options[i].innerHTML.toLowerCase() == v)) {
				o.selectedIndex = i;
				return i;
			}
		}
	}
	return -1;
}

function selectText(t, skipbar) {
	if (inWarning())
		return;
	if (t.className == 'Workspace')
		return;
	if (t.obj) {
//		return;
	}
	if (t != null) {
		if (activeText) {
			cursize = activeText.fontsize;
			Toolbar(false);
		}
		if (activeRect!=t.rect) {
			fromText = true;
//			alert('w_PDIV'+t.rect);
			selectRect(document.getElementById('w_PDIV'+t.rect));
		}
		activeText = t;
		if (!skipbar) {
			Toolbar(true, activeText.soort);
		}
		if (activeText.body) activeText.body.style.cursor = 'move';
		if (!fromdata) setActiveClass('designRect');
		if (activeText.soort == 1) {
			updateSizes(activeText.ontwerp);
			document.getElementById('ontwerptable').className = 'ontwerptable_selected';
		}
//		alert('text: '+activeText.text+', angle: '+activeText.angle+', size: '+activeText.fontsize+', skip: '+skipbar);
	}
}

function selectRect(t) {
	if (fromdata) return;
	if (inWarning())
		return;
	if (activeRect > -1) {
		var o = document.getElementById('w_PDIV'+activeRect);
//		o.className = 'previewrect_none';
	}
	if (activeText) {
		Toolbar(false);
		activeText = null;
	}
	if (t == null) {
		if (adminmode) {
			addRectangle();
		}
		return;
	}
	var n = t.id;
	activeRect = n.substring(6);
	if (!adminmode) {
		for (i = 0; i < rect.length; i++) {
			if (rect[activeRect][7] == rect[i][7]) {
				var o = document.getElementById('w_PDIV'+i);
				o.innerHTML = '';
				o.onmouseover = function() {
					tooltip(true, 'kaderhover', S_KADERHOVERTOOLTIP);
				}
				o.onmousemove = function() {
					moveTooltip();
				}
				o.onmouseout = function() {
					tooltip(false, '', '');
				}
			}
		}
	}
	if (!fromText) {
		if (!adminmode) {
			showPopupMenu();
		}
	}
	setKaders(true);
	fromText = false;
}

function showPopupMenu() {
	if (fromdata) return;
	if (inWarning())
		return;
	var m = document.getElementById('menutip');
	m.style.display =  (produkt == '11' ? 'block' : 'none');
	m = document.getElementById('popupmenu');
	m.style.left = lastMouseUpX-25;
	m.style.top = lastMouseUpY-25;
	m.style.display = 'block';

}

var tooltipTimer = null;

function hideTooltip() {
	var o = document.getElementById('tooltip');
	o.style.display = 'none';
	tooltipTimer = null;
}

function showTooltip() {
	var o = document.getElementById('tooltip');
	o.style.zindex = 100;
	o.style.left = lastMouseX - 3;
	o.style.top = lastMouseY + 20;
	o.style.display = 'block';
	tooltipTimer = setTimeout('hideTooltip();', 3000);
}

function moveTooltip() {
	var o = document.getElementById('tooltip');
	o.style.left = lastMouseX - 3;
	o.style.top = lastMouseY + 20;
}

function tooltip(display, classname, html) {
	if (fromdata) return;
	if (tooltipTimer) {
		clearTimeout(tooltipTimer);
	}
	if (display) {
		var o = document.getElementById('tooltip');
		if(o!=null){
			o.className = classname;
			o.innerHTML = html;
		}
		tooltipTimer = setTimeout('showTooltip();', 5);
	} else {
		var o = document.getElementById('tooltip');
		o.style.display = 'none';
	}
}

function createRectangles(n) {
	sides = 0;
	var p = document.getElementById('editpreview');
	var minx = 1000;
	var maxx = 0;
	for (var i = 0; i < n; i++)  {
		xFact = 1;//Workspace.width / rect[i][5];
		yFact = 1;//Workspace.height / rect[i][6];
		rect[i][0] = rect[i][0] * xFact;
		rect[i][1] = rect[i][1] * xFact;
		rect[i][2] = rect[i][2] * yFact;
		rect[i][3] = rect[i][3] * yFact;
		if (rect[i][0] < minx)
			minx = rect[i][0];
		if (rect[i][1] > maxx)
			maxx = rect[i][0];
	}
	var w = 600;//rect[0][5];
	x = (WorkspaceWidth-w) / 2;
	Workspace.obj.style.left = x+displaceX;
	Workspace.obj.style.width = w;//+300;
	var o = document.getElementById('sides');
	//o.style.left = 200 + WorkspaceWidth - ((WorkspaceWidth / 2) - x) - x/2;
//	x = (WorkspaceWidth / 2) - x;
	for (var i = 0; i < n; i++)  {
		if (rect[i][0]+rect[i][1]+rect[i][2]+rect[i][3]>0) {
			createRectangle(i);
		}
		if (rect[i][7] > sides)
			sides = rect[i][7];
	}
	for (var i = 0; i <= 5; i++) {
		var d = document.getElementById('side'+i);
		if (d)
			d.style.display = 'none';
	}
	var d = document.getElementById('kaders');
	if (d) d.style.display = 'block';
	if (sides != 0)
		hassides = true;
		
		if(typeof(hijackKaders) != 'undefined') hijackKaders();
}

function createRectangle(i) {

			var d = Workspace.AddWindow('PDIV'+i);
//			var d = document.createElement('DIV');
//			d.obj.id = 'PDIV'+i;
			if (adminmode)
				d.body.className = 'Handle';//'previewrect_none';
			d.obj.onclick = function () {
				selectRect(this);
				Toolbar(adminmode);
				return false;
			}
			x1 = rect[i][0];// + x;
			x2 = rect[i][1];// + x;
			y1 = rect[i][2];
			y2 = rect[i][3];
//alert('Add rectangle '+i+': '+x1+', '+y1+' - '+x2+', '+y2+' = '+d);

			d.width = (x2-x1);
			d.height = (y2-y1);
			d.y = y1;
			d.x = x1;

			d.body.style.width = (x2-x1) + 'px';
			d.body.style.height = (y2-y1) + 'px';
			d.body.style.top = y1 + 'px';
			d.body.style.left = x1;//(x1+displaceX) + 'px';

			d.obj.style.position = 'absolute';
			if (!fromdata) d.obj.style.cursor = 'pointer';
			d.obj.style.width = (x2-x1) + 'px';
			d.obj.style.height = (y2-y1) + 'px';
			d.obj.style.top = y1 + 'px';
			d.obj.style.left = x1;//(x1+displaceX) + 'px';
			d.obj.style.zIndex = 10;
			d.obj.style.display = 'block';//'none';
			d.body.onmouseover = function() {
				tooltip(true, 'kaderhover', S_KADERHOVERTOOLTIP);
			}
			d.body.onmouseout = function() {
				tooltip(false, '', '');
			}
			if (!adminmode)
				if (!fromdata) {
					var s = S_ONTWERPHIER;//MAAT;
					s = '<table><tr><td align=\'center\' bgcolor=\'#eeeeee\'><font size=\'2\' color=\'#CC0066\'>&nbsp;<span id=\'ontwerphier\' class="ontwerphier">'+s+'</span>&nbsp;</font></td></tr></table>';
					d.body.innerHTML = '<table border=0 width=\'100%\' height=\'100%\'><tr><td align=\'center\' height=\'100%\' width=\'100%\'>'+s+'</td></tr></table>';
				}
			p = d;
			if (adminmode) {
				d = p.resize;//document.createElement('DIV');
				d.className = 'Resize';
				d.style.position = 'relative';
				d.style.top = (y1 + (y2-y1) - 25) + 'px';
				d.style.left = (x1 + (x2-x1) - 25) + 'px';
				d.style.width = 25;
				d.style.height = 25;
				d.innerHTML = '?';
				p.resize = d;
				p.body.appendChild(d);
			}
			hassides = false;
			p.Move(p.x, p.y);

			if(typeof(hijackKaders)!='undefined') hijackKaders();			
}

function setKaders(display) {
	for (var i = 0; i < rect.length; i++) {
		var o = document.getElementById('w_PDIV'+i);
		o.className = (display ? 'Window' : '');
	}
	if (fromdata) return;
	var o = document.getElementById('kaders');
	var s = (display ? S_AAN : S_UIT);
	var r = (display ? S_UIT : S_AAN);
	o.innerHTML = o.innerHTML.replace(s, r);
	kaders = display;
}

function toggleKaders() {
	setKaders(!kaders);
}

function addRectangle() {
	i = rect.length;
	rect[i] = new Array();
	rect[i][0] = 0;
	rect[i][1] = 50;
	rect[i][2] = 0;
	rect[i][3] = 50;
	rect[i][7] = side;
	rect[i][9] = -i;
	rect[i][10] = 1;
	createRectangle(i);
}

function deleteRect() {
	rect[activeRect][10] = 0;
	var o = document.getElementById('w_PDIV'+activeRect);
	o.style.display = 'none';
	Toolbar(false);
	activeRect = -1;
}

function displaySide(s) {
	g=window.location.search;
	g+=window.location.hash;
	/*
	if(typeof(g)!='undefined'){//TODO:remove this latches once everyting is complete
		if(g.indexOf('connaxis')>0){
			if(typeof(window.dobj)!='undefined'){
				initKleur(window.dobj.kleur.toLowerCase());
			}
		}
	}
	*/
	var d;
	var o;

	if (inWarning())
		return;
	d = document.getElementById('side0');
	if (hassides) {
		var src = '';
		var newsrc = '';
		for (var i = 0; i <= sides; i++) {
			d = document.getElementById('side'+i);
			d.style.display = '';
			if (i != s) {
				newsrc=d.src.replace('_aan', '_uit');
			} else {
				newsrc=d.src.replace('_uit', '_aan');
			}
			src=newsrc.replace('_uit', '_aan');
			d.over = src;
			d.out = newsrc;
			d.onmouseover = function() {this.src=this.over;}
			d.onmouseout = function() {this.src=this.out;}
			d.src = newsrc;
		}
	} else {
		d.src='images/voorzijde_uit.jpg';
		d = document.getElementById('side1');
		d.src='images/achterzijde_uit.jpg';
	}

	activeText = null;
	activeRect = 0;
	Toolbar(false);
	side = s;

	previewImage = previewImages[side].replace('$kleur$', kleur.toLowerCase());
	
	var w = 0;//rect[side][5];
	var altw = 0;
	for (var i = 0; i < rect.length; i++) {
		o = document.getElementById('w_PDIV'+i);
		if (o) { 
			var b = (rect[i][7] == s && rect[i][10] == 1);
			o.style.display = (b ? 'block' : 'none');
			if (b) {
				if (rect[i][5] > w) 
					w = rect[i][5];
			} else if (rect[i][5] > altw) 
					altw = rect[i][5];
		}
	}
	if(w == 0) w = altw;
	w = 600;
	var x = (WorkspaceWidth-w) / 2;
	Workspace.obj.style.left = x;//50;
	Workspace.obj.style.width = w;//+300;

	for (i = 0; i < Blocks.length; i ++ ) {
		if (Blocks[i][1])
			Blocks[i][0].obj.style.display = (Blocks[i][0].side == side ? 'block' : 'none');
	}
	updatePreview();
}

function displayPrice() {
	if (fromdata) return;
	var p = price;
	for (var r = 0; r < rect.length; r++) {
		var first = true;
		for (var b = 0; b<Blocks.length; b++) {
			if (Blocks[b][1])
				if (Blocks[b][2] == r) {
					if (first) {
//debug('ontwerp['+Blocks[b][0].ontwerptab+']['+Blocks[b][0].ontwerp+'] - Block = '+b);
						p += baseprice;
						if (Blocks[b][3] == 1)
							p -= ontwerp[Blocks[b][0].ontwerptab][Blocks[b][0].ontwerp][2];
						first = false;
					} else {
						if (Blocks[b][3] == 0) {
							p += nextlineprice;
						} else {
							p += nextdesignprice;
							p -= ontwerp[Blocks[b][0].ontwerptab][Blocks[b][0].ontwerp][3];
						}
					}
				}
		}
	}
	totalprice = p - price;
	var d = p.toString();
	d = d.substring(0, d.length-2)+','+d.substring(d.length-2);
	var o = document.getElementById('prijs');
	o.innerHTML = S_PRIJS+': &euro; '+d;
}

function getMaten(p, url){
	hassides = false;
	produkt = p;
	//kleur = k;
	//previewImage = previewImages[0].replace('$kleur$', kleur.toLowerCase());
	request('type=maat&produkt='+produkt, 'Init4();'+url+'; displaySide(0); updatePreview();');
	if (!fromdata ){
		deleteAllText();
		var o = document.getElementById('ontwerpcontainer2');
		var t = 0;
		if (p == '11') {
			o.style.display = '';
			t = 2;
		} else {
			o.style.display = 'none';
		}
		setOntwerptab(t);
	}
}

function updateSize() {
	var minh = 4;
	for (var i=0; i <= 30; i++) {
		fontsizes[i-1] = minh + i*2;
		if (curfontsize == -1 && fontsizes[i-1] >= 12) {
			curfontsize = i;
			defaultfontsize = i;
		}
	}
	switch (side) {
		case 0:
		case 1: 
			realHeight = rect[0][11];
			break;
		case 2:
			realHeight = rect[0][12];
			break;
		default:
			realHeight = rect[0][13];
			break;
	}
//	alert(realHeight+'\n'+rect[0]);
	updatePreview();
	return;
	var o = document.getElementById('maat');
	var s = o.options[o.selectedIndex].value
	var p = s.indexOf('cm');
	if (p == -1)
		return;
	s = s.substring(0, p-1);
	p = s.indexOf(' ');
	while (p > -1) {
		p = s.indexOf(' ');
		s = s.substring(p+1);
	}
	if (s.indexOf('(') > -1)
		s = s.substring(1);
	var h = 0;
	if (s.indexOf('/') > -1) {
		var mi = s.substring(0, s.indexOf('/'));
		var ma = s.substring(s.indexOf('/')+1);
		h = (parseInt(mi)+parseInt(ma))/2;
	} else {
		h = s.substring(s.indexOf('x')+1);
	}
	realHeight = h;
	minh = h / 10;
	if (minh < 4)
		minh = 4;
	for (var i=0; i <= 30; i++) {
		fontsizes[i-1] = minh + i*2;
		if (curfontsize == -1 && fontsizes[i-1] >= 12) {
			curfontsize = i;
			defaultfontsize = i;
		}
	}
	updatePreview();
}

function updateSizes(o) {
	var soort = ontwerp[curontwerptab][0][10];
	if (curontwerptab == 2) {
		eval('sizes = "'+ontwerp[curontwerptab][o][4]+'".split(",");');
	} else if (soort == '0') {
		eval('sizes = "'+ontwerp[curontwerptab][o][4]+'".split(",");');
	} else {
		for (var i = 0; i < 25; i++) {
			sizes[i] = 5 + i;
		}
	}
}

function changeAngle() {
	activeText.angle += 90;
	if (activeText.angle >= 360)
		activeText.angle = 0;
	updatePreview();
}

var factor = 5;

function checkFontsize(s) {
	if (fromdata) return;
	if (activeText) {
		if (activeText.soort == 0) {
			activeText.width = imagewidth;
			activeText.height = imageheight;
		}
		var b = false;
		var h = false;
		var wi = rect[activeRect][1] - rect[activeRect][0];
		var he = rect[activeRect][3] - rect[activeRect][2];

		if (activeText.x+activeText.width > rect[activeRect][1]) {
			if (activeText.width < wi) {
				activeText.x = rect[activeRect][1] - activeText.width-2;
				activeText.obj.style.left = activeText.x;
				toolbar.obj.style.left = activeText.x;
			} else {
				b = true;
			}
		}
		if (activeText.y+activeText.height > rect[activeRect][3]) {
			if (activeText.height < he) {
				activeText.y = rect[activeRect][3] - activeText.height-2;
				activeText.obj.style.top = activeText.y;
				toolbar.obj.style.top = activeText.y - toolbar.height - 5;
			} else {
				h = true;
			}
		}
		var s = activeText.width+' > '+wi+': '+b+', '+activeText.height+' > '+he+': '+h+' - '+inWarning();
//		alert(s);
		if (b || h) {
			var s = '';
			if (activeText.soort == 0) {
				s = S_TEKST;
			} else {
				s = S_ONTWERP;
			}
			s += S_VERKLEINENAUB;
			var o = document.getElementById('warning');
			o.innerHTML = s;
			o.style.left = activeText.x;
			if (activeText.soort == 0) {
				o.style.top = activeText.y - 92;
			} else {
				o.style.top = activeText.y - 62;
			}
			o.style.display = 'block';
		} else {
			var o = document.getElementById('warning');
			o.style.display = 'none';
		}
	}
}

function allowChangeFontsize(s, d) {
	var s = activeText.fontsize;

	var x = parseInt(activeText.obj.style.left.replace('px', ''));
	var y = parseInt(activeText.obj.style.top.replace('px', ''));
	var x2 = rect[activeRect][1];
	var y2 = rect[activeRect][3];
	if (activeText.soort == 0) {
/*		if (x+imagewidth>x2)
			return false;
		if (y+imageheight>y2)
			return false;
*/	} else {
		s += d*25;
		if ((x+s)>=x2)
			return false;
		if ((y+s)>=y2)
			return false;
	}
	return true;
}

function doSizeButtons(s, a) {
	var o = document.getElementById('fb1');
	if (!o)
		return;
	if (s > 0) {
		o.src = 'images/edit_min.jpg';
	} else {
		o.src = 'images/edit_min_disable.jpg';
	}
	var o = document.getElementById('fb2');
	if (s < a.length-1) {
		o.src = 'images/edit_plus.jpg';
	} else {
		o.src = 'images/edit_plus_disable.jpg';
	}
}

function changeFontsize(t, d) {
	if (fromdata) return;
	if (activeText.soort == 0) {
		if (curfontsize == 0 && d < 0)
			return;
		if (curfontsize == fontsizes.length-1 && d > 0)
			return;
		var s = curfontsize+d;
		if (s<0)
			s = 0;
		if (s>=fontsizes.length)
			s = fontsizes.length-1;
		curfontsize = s;
		activeText.fontsize = fontsizes[curfontsize];
		doSizeButtons(curfontsize, fontsizes);
	} else {
		if (cursize == 0 && d < 0)
			return;
		if (cursize == sizes.length-1 && d > 0)
			return;
		var s = cursize+d;
		var f = sizes[s] / sizes[cursize];
		if (s<0)
			s = 0;
		if (s>=sizes.length)
			s = sizes.length-1;
		cursize = s;
		activeText.fontsize = cursize;
		activeText.height = (rect[0][6]*(sizes[cursize]/realHeight));
		activeText.width = activeText.width * f;

//		activeText.width = 0;
		doSizeButtons(cursize, sizes);
		checkFontsize();
	}
	updatePreview();
}

function createText(soort, sleeping) {
	if (inWarning() && !fromdata)
		return;
	if (activeText == null) {	
		var d = document.getElementById('PDIV'+activeRect);
		textCount++;
		activeText = Workspace.AddWindow('TXT'+textCount);
		var l = Blocks.length;
		elementCount[soort]++;
		Blocks[l] = new Array();
		Blocks[l][0] = activeText;
		Blocks[l][1] = true;
		Blocks[l][2] = activeRect;
		Blocks[l][3] = soort;
		activeText.soort = soort;
		activeText.side = side;
		activeText.ontwerp = curontwerp;
		activeText.ontwerptab = curontwerptab;
		if (soort == 1) activeText.image = ontwerp[curontwerptab][curontwerp][1];
		activeText.font = fontnames[curfont];
		if (curontwerptab == 0) {
			if (!fromdata)
				cursize = sizes.length-1;
		} else {
			for (var i = 0; i < sizes.length; i++) {
				if (sizes[i] > realHeight / 4) {
					cursize = i;
					break;
				}
			}
//			alert(realHeight+' -> '+cursize+': '+sizes);
		}
		curfontsize = defaultfontsize;
		if (!sleeping) {
//			updateSize();
			updateSizes(curontwerp);
		}
		if (soort == 0) {
			activeText.fontsize = fontsizes[curfontsize];
		} else {
			activeText.fontsize = cursize;//(rect[0][6]*(sizes[cursize]/realHeight));
			changeFontsize(null, 0);
			if (!fromdata) setActiveClass('designRect');
		}
		activeText.obj.style.zIndex = 20;
		activeText.body.style.zIndex = 20;
		activeText.className = "Handle";
		activeText.imagekleur = curkleurname;
//		alert('3. activeText.imagekleur = '+curkleurname);
		activeText.UnLock();
		x1 = rect[activeRect][0];
		x2 = rect[activeRect][1];
		y1 = rect[activeRect][2];
		y2 = rect[activeRect][3];
		activeText.obj.style.display = 'block';
		activeText.obj.style.left = x1;
		activeText.obj.style.top = y1;
		if (!fromdata) 
			activeText.obj.className = 'designRect';
		else
			activeText.obj.className = '';
		activeText.x = x1;
		activeText.y = y1;
		activeText.obj.onmouseover = function() {
			tooltip(true, 'designhover', S_TOOLTIPSTUDIO);
		}
		activeText.obj.onmousemove = function() {
			moveTooltip();
		}
		activeText.obj.onmouseout = function() {
			tooltip(false, '', '');
		}
		if (!sleeping) {
			Toolbar(true, soort);
			updatePreview();
		}
	}
}

function dodeleteText() {
	for (var i=0; i < Blocks.length; i++ ) {
		if (activeText == Blocks[i][0]) {
			activeText.text = '';
			elementCount[activeText.soort]--;
			var o = document.getElementById('warning');
			if (o.style.display == 'block')
				o.style.display == 'none';
			Blocks[i][1] = false;
			if (activeText && activeText.obj)
				activeText.obj.style.display = 'none';
			if (inWarning()) {
				o = document.getElementById('warning');
				o.style.display = 'none';
			}
		}
	}
}
function deleteText() {
	dodeleteText();
	Toolbar(false);
	activeText = null;
	displayPrice();
}

function deleteAllText() {
	for (var i=0; i < Blocks.length; i++ ) {
		var p = Blocks[i][0].obj.parentNode;
		p.removeChild(Blocks[i][0].obj);
	}
	Blocks = new Array();
	Toolbar(false);
	elementCount[0]=0;
	elementCount[1]=0;
	displayPrice();
}

function updatePreview(force) {
	var o = document.getElementById('kleur');
	if (!fromdata && o.selectedIndex>-1) {
		kleur = o.options[o.selectedIndex].value;
	}
	if (produkt == '' || kleur=='') {
		return;
	}
	previewImage = previewImages[side].replace('$kleur$', kleur.toLowerCase());

	Workspace.body.style.backgroundImage = 'url(images/producten/'+previewImage+')';
	var o = document.getElementById('img_ontwerp');
	if (zijde==0) {
		o.style.display = 'none';
	} else {
		var x1 = rect[activeRect][0];
		var x2 = rect[activeRect][1];
		var y1 = rect[activeRect][2];
		var y2 = rect[activeRect][3];
		o.src = ontwerp[curontwerptab][curontwerp][1];
		o.style.display = 'block';
		o.width = x2 - x1;
		o.height = y2 - y1;
		o = o.parentNode;
		o.style.top = y1 + 'px';
		o.style.left = (x1+50) + 'px';
	}
	if (activeRect > -1 && activeText) {
		var alt='';
		if (activeText.soort == 0) {
			var text = '';
			o = document.getElementById('fontname');
			if (o) {
				activeText.font = o.value;
			}
			o = document.getElementById('fontcolor');
			if (o) {
				activeText.fontcolor = o.value;
				activeText.fontcolorname = o.options[o.selectedIndex].innerHTML;
			}
			getColors();
			if (!fromdata) {
				for (i = 0; i < basecolors.length; i++) {
					if (basecolors[i][0].toLowerCase() == curkleur) {
						activeText.fontcolor = basecolors[i][1];
						activeText.fontcolorname = basecolors[i][2];
					}
				}
			}
			o = document.getElementById('tekst');
			if (o) activeText.text = o.value;
			if (activeText.text != '') {
				imageurl = '&line='+activeText.text;
				imageurl += '&angle='+activeText.angle;
				imageurl += '&size='+activeText.fontsize;//fontsizes[curfontsize];

				activeText.rect = activeRect;
				imageurl = 'color='+activeText.fontcolor.replace('#', '')+'&font='+activeText.font+imageurl;
				activeText.body.innerHTML = '<img onmousedown="return false;" class="Handle" '+alt+' src="image.php?'+imageurl+'" />';
				request(imageurl+'&type=coord', 'checkFontsize();');
			}
			activeText.mono = 1;
		} else {
			activeText.rect = activeRect;
			if (!fromdata) {
				var h = (rect[0][6]*(sizes[cursize]/realHeight));
//				activeText.width = activeText.fontsize;
				activeText.height = h;//activeText.fontsize;
				activeText.ontwerpsize = sizes[cursize];
			}
			var img = '';
			if (fromdata)
				img = activeText.imgurl;
			activeText.mono = 0;
			if (curontwerptab == 0) {
				if (!fromdata) img = 'images/ontwerpen/groot_'+activeText.image+'.gif';
				activeText.body.innerHTML = '<img '+alt+'onload="if (activeText) activeText.width=this.width" onmousedown="return false;" height="'+h+'" class="Handle" src="'+img+'" />';
			} else if (curontwerptab == 1) {
				activeText.mono = 1;
				if (!fromdata) img = 'images/ontwerpen/monochroom/studio/'+activeText.image+'_'+curkleur+'.gif';
				activeText.body.innerHTML = '<img '+alt+'onload="if (activeText) activeText.width=this.width" onmousedown="return false;" height="'+h+'" class="Handle" src="'+img+'" />';
			} else {
				var w = rect[activeRect][1] - rect[activeRect][0];
				if (!fromdata) img = 'images/ontwerpen/laken/groot_'+activeText.image+'.gif';
//				activeText.body.innerHTML = '<img '+alt+'onload="if (activeText) activeText.width=this.width" onmousedown="return false;" width="'+w+'" class="Handle" src="'+img+'" />';
				activeText.body.innerHTML = '<img '+alt+'onload="if (activeText) activeText.width=this.width" onmousedown="return false;" height="'+h+'" class="Handle" src="'+img+'" />';
			}
			var multi = '';
			if (ontwerp[curontwerptab][0][10] == 1) {
				if (!curkleur) {
					// EJ, 2009-09-29: check color to fix mantis issue #1647
					curkleur = 'rood';		
				}
				multi = '_'+curkleur;
			}
			activeText.mono = ontwerp[curontwerptab][0][10];
			if (fromdata)
				img = activeText.imgurl;
			else
				img = 'images/ontwerpen/'+ontwerp[activeText.ontwerptab][activeText.ontwerp][8]+'/studio/'+activeText.image+multi+'.gif';
			activeText.body.innerHTML = '<img '+alt+'onload="if (activeText) activeText.width=this.width" onmousedown="return false;" height="'+h+'" class="Handle" src="'+img+'" />';
			activeText.imgurl = img;
			activeText.ontwerpnaam = ontwerp[activeText.ontwerptab][activeText.ontwerp][0];
			if (fromdata) {
				if (isIE) {
					activeText.body.children(0).height = activeText.height;
				} else {
					activeText.body.firstChild.height = activeText.height;
				}
			}
		}
	} 
	if (sizes) {
		for (i = 0; i < Blocks.length; i++) {
			var o = Blocks[i][0].body.firstChild;
			if (o) {
				var h = (rect[0][6]*(Blocks[i][0].ontwerpsize/realHeight));
//				if (o.src.indexOf('_lak') == -1 && o.src.indexOf('image.php') == -1) {
				if (Blocks[i][0].soort == 1) {
					o.height = h;
				}
//alert(i+': '+Blocks[i][0].ontwerpsize+' -> '+rect[0][6]+' * '+Blocks[i][0].ontwerpsize+' / '+realHeight+' = '+h);
//				} else {
//					var w = rect[activeRect][1] - rect[activeRect][0];
//					o.width = w;
//				}
			}
		}
	}
	displayPrice();
}

var isIE;
var isGecko;
var isSafari;
var isOpera;
var objDrag;
var objHandle;

var DictWindow = 1;
var DictTable = 2;
var DictQuery = 3;
var DictTab = 4;
var DictGraph = 5;


function DetectBrowser() {
	var browser = navigator.userAgent.toLowerCase();
	isGecko = ( navigator.product == 'Gecko' );
	isIE = !isGecko && ~browser.indexOf ( "msie" );
	isSafari = !isGecko && !isIE && ~browser.indexOf ( "safari" );
	isOpera = ~browser.indexOf("opera");
	isNetsc71OSX = ~browser.indexOf("macintosh") && ~browser.indexOf("netscape") && ~browser.indexOf("7.1");
}

function getEventWindow(e) {
	var tg;
	var tg = (window.event) ? e.srcElement : e.target;
	if (!tg) return null;
	objHandle = tg;
	if (tg.className != 'Resize' && tg.className != 'Caption' && tg.className != 'Handle' && tg.className != 'Body') return null;
	if (tg.className == 'Body') {
		tg = tg.parentNode;
		if (tg.className == 'Workspace')
			return tg;
		return null;
	}
	if (true) {
		while (tg.tagName != 'DIV') {
			tg = tg.parentNode;
			if (!tg) return null;
		}
		tg = tg.parentNode;
		if (adminmode && tg.className != 'Window')
			tg = tg.parentNode;
		tg = tg.id.substring(2);
		tg = Windows.Get(tg);
	}
	return tg;
}

function updatePreviewText() {
	if (activeText) {
		activeText.text = onkeyup_text;
		updatePreview();
	}
	onkeyup_timer = null;
}

var onkeyup_timer = null;
var onkeyup_text = '';

document.onkeyup = function(e) {
	if (toolbar.obj.style.display == 'none')
		return;
	if (!e) e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (!tg) return;
	if (activeText) {
		if (onkeyup_timer) {
			clearTimeout(onkeyup_timer);
			onkeyup_timer = null;
		}
		onkeyup_text = tg.value;
		onkeyup_timer = setTimeout("updatePreviewText()", 500);
	}
}

document.onmousedown = function(e) {
	if (fromdata) return;
	if (inWarning())
		return false;
	if (!e) e = window.event;
	objDrag = getEventWindow(e);
	if (!objDrag) return;
	objDrag.Dragging = false;
	if (adminmode) {
		if (objDrag.className == 'Workspace')
			selectRect(null);
		else
			selectRect(objDrag.obj);
	} else {
		selectText(objDrag, true);
	}
	if (isIE) {
	  tempX = e.clientX + document.body.scrollLeft
	  tempY = e.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
	  tempX = e.pageX
	  tempY = e.pageY
	}
	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0} 
	objDrag.sx = tempX;
	objDrag.sy = tempY;
	return true;
}

document.onmousemove = function(e) {
	if (!e) e = window.event;
	//alert(1);
	var tempX;
	var tempY;
	if (isIE) {
	  tempX = e.clientX + document.body.scrollLeft
	  tempY = e.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
	  tempX = e.pageX
	  tempY = e.pageY
	}  
	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0} 
	lastMouseX = tempX;
	lastMouseY = tempY;
	if (tooltipTimer)
		moveTooltip();

	if (!objDrag) 
		return true;
	objDrag.dragging = true;
	var resize = (objHandle.className == 'Resize');
	if (!resize && objDrag.obj) {
		objDrag.obj.style.filter  = "alpha(opacity:50)";
		objDrag.obj.style.opacity = 0.5;
		objDrag.obj.style.MozOpacity = 0.5;
	}
	var sx = tempX;
	var sy = tempY;
	tempX = tempX - objDrag.sx;
	tempY = tempY - objDrag.sy;
	objDrag.sx = sx;
	objDrag.sy = sy;
	var nx, ny, l, t;
	if (resize) {
		nx = parseInt(objDrag.width) + parseInt(tempX);
		ny = parseInt(objDrag.height) + parseInt(tempY);
		if (nx<0) return false;
		if (ny<0) return false;
		if (objDrag.x + nx>Workspace.width + Workspace.left) return false;
		if (objDrag.y + ny>Workspace.height + Workspace.top) return false;
		objDrag.Scale(nx, ny);
	} else {
		if (adminmode) {
			l = 0;
			t = 0;
			r = Workspace.width-2;
			b = Workspace.height-2;
		} else {
			l = rect[activeRect][0];
			t = rect[activeRect][2];
			r = rect[activeRect][1];// - rect[activeRect][0]
			b = rect[activeRect][3];// - rect[activeRect][2];
		}
		nx = parseInt(objDrag.x) + parseInt(tempX);// + l;
		ny = parseInt(objDrag.y) + parseInt(tempY);// + t;
		if (false) {
			var s = l+', '+t;
			s += ' : '+r+', '+b;
			s += ' : '+nx+', '+ny+' -> '+(nx+objDrag.width)+', '+(ny+objDrag.height);
			debug(s);//objDrag.width+', '+objDrag.height);
		}
		if (nx<l) return false;
		if (ny<t) return false;
		//objDrag.obj.innerHTML = (nx+objDrag.width)+' - '+(ny+objDrag.height)+' <> '+l+' - '+t;
		//0 - 26 &lt;&gt; 97 - 24 &lt;&gt; 200 
		if (nx+objDrag.width>r) return false;
		if (ny+objDrag.height>b) return false;
		objDrag.x = nx;
		objDrag.y = ny;
		if (objDrag.obj) {
			objDrag.obj.style.left = objDrag.x;
			objDrag.obj.style.top = objDrag.y;
		}
	}
	return false;
}

document.onmouseup = function(e) {
	if (fromdata) return;
	if (objDrag) {
		if (!objDrag.dragging) {
			if (!adminmode) {
				selectText(objDrag, false);
			}
		} else {
			setActiveClass('');
			activeText = null;
			objDrag.dragging = false;
			var resize = (objHandle.className == 'Resize');
			if (resize) {
			} else {
				objDrag.obj.style.filter  = null; //"alpha(opacity:100)";
				objDrag.obj.style.opacity = 1;
				objDrag.obj.style.MozOpacity = 1;
				objDrag.dragging = false;
//				objDrag.Move(objDrag.x, objDrag.y);
				checkFontsize();
			}
		}
		objDrag = null;
	}

	if (!e) e = window.event;
	if (isIE) {
	  lastMouseUpX = e.clientX + document.body.scrollLeft
	  lastMouseUpY = e.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
	  lastMouseUpX = e.pageX
	  lastMouseUpY = e.pageY
	}  
	if (lastMouseUpX < 0){lastMouseUpX = 0}
	if (lastMouseUpY < 0){lastMouseUpY = 0} 
	var s = document.getElementById('lu');
	return true;
}

var Class = {
  create: function() {
    return function() { 
      this.initialize.apply(this, arguments);
    }
  }
}

DElement = Class.create();
DElement.prototype = {
	obj: null,
	name: 'leeg',
	type: 0,
	initialize: function(Obj, Name, Type){
		this.obj = Obj;
		this.name = Name;
		this.type = Type;
	}
}


Window = Class.create();
Window.prototype = {
	x: 0,
	y: 0,
	sx: 0,
	sy: 0,
	dragx: 0,
	dragy: 0,
	state: '',
	name: '',
	width: 0,
	height: 0,
	realwidth: 0,
	realheight: 0,
	caption: '',
	obj: null,
	handle: null,
	body: null,
	resize: null,
	parent: null,
	slide: false,
	slidestep: 0,
	slidesteps: 10,
	slider: null,
	nextslide: '',
	nextfade: '',
	fader: null,
	opacity: 100,
	dragging: false,
	resize: null,
	zIndex: 0,
	candrag: false,
	angle: 0,
	text: '',
	fontsize: 0,
	fontcolor: '#fe0000',
	rect: -1,
	image: '',
	ontwerp: -1,
	soort: 0,
	side: -1,
	initialize: function(name, obj, par) {
		this.name = name;
		this.caption = name;
		this.obj = document.createElement('DIV');
		this.obj.id = 'w_'+name;
		this.obj.style.display = 'none';
		this.obj.style.overflow = 'hidden';
		this.obj.className = 'Window';
		if (false) {
			if (this.x > window.screen.width) this.x = 0
			if (this.x < 0) this.x = 0
			if (this.y > window.screen.height) this.y = 0
			if (this.y <0) this.y = 0
			this.x = parseInt(this.x);
			this.y = parseInt(this.y);
		}

		this.body = document.createElement('DIV');
		this.body.className = 'Body';

		this.resize = document.createElement('DIV');
		this.resize.style.position = 'absolute';
		this.resize.style.width = 20;
		this.resize.style.height = 20;
		this.resize.style.left = this.width-20;
		this.resize.style.top = this.height-40;
		this.resize.innerHTML = '***';
		this.resize.className = 'Resize';

		this.obj.appendChild(this.body);
		if (adminmode)
			this.obj.appendChild(this.resize);

		if (par && par != 'undefined') {
			this.parent = par.body;
			this.obj.style.position = 'absolute';//relative';
			if (obj) {
				obj.appendChild(this.obj);
			} else {
				par.body.appendChild(this.obj);
			}
		} else {
			this.parent = document.body;
				this.obj.style.position = 'absolute';
			document.body.appendChild(this.obj);
		}
		//this.parent.appendChild(this.obj);
		this.obj.style.zIndex = 1;
		if (this.state == '+') this.Collapse();
		//this.Scale(400, 100);
		this.obj.style.left = this.x;
		this.obj.style.top = this.y;
		//this.Move(this.x, this.y);
	},
	Lock: function() {
		this.candrag = false;
	},
	UnLock: function() {
		this.candrag = true;
	},
	Show: function() {
		this.obj.style.display = 'block';
	},
	Hide: function() {
		this.obj.style.display = 'none';
	},
	Slide: function (X, Y) {
		if (this.slider) {
			if (this.nextslide == '')
				this.nextslide = 'this.Slide('+X+', '+Y+')';
			return;
		}
		this.slidestep = this.slidesteps;
		this.sx = this.x;
		this.sy = this.y;
		this.slider = setInterval('moveDIV(\''+this.name+'\', '+X+', '+Y+')', 5);
	},
	EndSlide: function() {
		this.slider = null;
		if (this.nextslide != '') {
			eval(this.nextslide);
			this.nextslide = '';
		}
	},
	EndFade: function() {
		this.fader = null;
		this.obj.style.filter = null;
		if (this.nextfade != '') {
			eval(this.nextfade);
			this.nextfade = '';
		}
	},
	Move: function(X, Y) {
		this.x = X;
		this.y = Y;
		this.obj.style.left = X;
		this.obj.style.top = Y;
		this.resize.style.left = this.width-20;
		this.resize.style.top = this.height-20;
		//this.body.innerHTML += this.handle.style.left;
	},
	Scale: function(Width, Height) {
		this.realwidth = Width;
		this.realheight = Height;
		this.width = Width;
		this.height = Height;
		this.obj.style.width = Width;
		this.obj.style.height = this.height;
		this.body.style.height = this.realheight;
		this.resize.style.left = this.width-20;
		this.resize.style.top = this.height-20;
	},
	FadeOut: function() {
		if (this.fader) {
			if (this.nextfade == '')
				this.nextfade = 'this.FadeOut()';
			return;
		}
		this.obj.style.zoom = 1;
		this.opacity = 100;
		this.fader = setInterval('fadeDIV(\''+this.name+'\', -'+20+')', 10);
	},
	FadeIn: function() {
		if (this.fader) {
			if (this.nextfade == '')
				this.nextfade = 'this.FadeIn()';
			return;
		}
		this.obj.style.zoom = 1;
		this.opacity = 0;
		this.fader = setInterval('fadeDIV(\''+this.name+'\', '+20+')', 10);
	},
	Collapse: function() {
		this.state = '+';
		this.height = 25;
		this.obj.style.height = this.height;
		this.body.style.display = 'none';
		this.resize.style.display = 'none';
	},
	Expand: function() {
		this.state = '-';
		this.height = this.realheight;
		this.obj.style.height = this.height;
		this.body.style.display = '';
		this.resize.style.display = '';
	},
	SetBody: function(html) {
		this.body.innerHTML = html;
	}
}

Tab = Class.create();
Tab.prototype = {
	caption: '',
	body: null,
	active: false,
	windows: null,
	lastwindow: null,
	first: true,
	initialize: function(c) {
		this.caption = c;
		this.body = document.createElement('SPAN');
		this.body.className = 'Inactive';
		this.body.innerHTML = '<span onClick="Workspace.ActivateTab(\''+this.caption+'\');">'+this.caption+'</span>';
		this.windows = new Array();
	},
	Activate: function() {
		if (this.active) return;
		if (this.first) {
			Workspace.Arrange();
			this.first = false;
		}
		this.active = true;
		this.body.className = 'Active';
		for (var i=0; i < this.windows.length; i++ ) {
			this.windows[i].FadeIn();
		}
	},
	Deactivate: function(c) {
		if (this.caption==c) return;
		if (!this.active) return;
		this.active = false;
		this.body.className = 'Inactive';
		for (var i=0; i < this.windows.length; i++ )
			this.windows[i].FadeOut();
	},
	Notify: function(m) {
		eval(m);
	},
	AddWindow: function(w) {
		if (w.y < Workspace.top + 25)
			w.Move(w.x, Workspace.top + 25);
		this.windows[this.windows.length] = w;
		this.lastwindow = w;
		return w;
	}
}

var Dictionary = {
	children: new Array(),
	Add: function(Obj, Name, Type) {
		var o = this.Get(Name, Type);
		if (!o) {
			var n = this.children.length;
			this.children[n] = new DElement(Obj, Name, Type);
			o = this.children[n];
		}
		return o;
	},
	Delete: function(Name, Type) {
		for (var i = 0; i < this.children.length; i++ ) {
			if (this.children[i].name == Name && this.children[i].type == Type) {
				o = this.children[i].obj;
				for (j = i; j < this.children.length-1; j++)
					this.children[j] = this.children[j+1];
				this.children.length--;
				return o;
			}
		}
		return null;
	},
	Get: function(Name, Type) {
		for (var i = 0; i < this.children.length; i++ ) {
			if (this.children[i].name == Name && this.children[i].type == Type) {
				return this.children[i].obj;
			}
		}
		return null;
	},
	Dump: function(c) {
		var s=c+'\n';
		for (var i = 0; i < this.children.length; i++ ) {
			s = s+this.children[i].name+': '+this.children[i].type+'\n';
		}
		alert(s);
		return null;
	},
	Notify: function(Type, q) {
		for (var i = 0; i < this.children.length; i++ ) {
			if (this.children[i].type == Type) {
				this.children[i].obj.Notify(q);
			}
		}
	}
}

var Windows = {
	Create: function(name, obj, par) {
		var w = Dictionary.Get(name, DictWindow);
		if (!w) {
			w = new Window(name, obj, par);
			Dictionary.Add(w, name, DictWindow);
		}
		return w;
	},
	Delete: function(name) {
		return Dictionary.Delete(name, DictWindow);
	},
	Get: function(name) {
		return Dictionary.Get(name, DictWindow);
	}
}

var Workspace = {
	obj: null,
	body: null,
	menu: null,
	curtab: null,
	top: 100,
	left: 100,
	width: 0,
	height: 0,
	debug: false,
	Initialize: function(Parent, Left, Top, Width, Height) {
		this.obj = document.createElement('DIV');
		this.obj.className = 'Workspace';

		this.windows = new Array();
		this.left = Left;
		this.top = Top;
		this.obj.style.position = 'absolute';
		this.obj.style.left = this.left;
		this.obj.style.top = this.top;
		this.width = Width;//document.body.clientWidth - this.left;
		this.height = Height;//document.body.clientHeight - this.top;
		this.obj.style.width = this.width;
		this.obj.style.height = this.height;
		if (typeof UserAgent != 'undefined' && UserAgent.isIE8) {
			// fix z-index for IE 8 (issue #1645)
			this.obj.style.zIndex = 100;
		}

		this.body = document.createElement('DIV');
		this.body.className = 'Body';
		this.body.style.left = this.left;
		this.body.style.top = this.top+25;
		//this.body.style.width = this.obj.style.width;
		this.body.style.height = this.height - 25;
		this.body.onclick = function() {Workspace.Arrange();}

		this.obj.appendChild(this.body);
		Parent.appendChild(this.obj);
	},
	AddWindow: function(name, obj) {
		var w = Windows.Create(name, obj, this);
		if (this.curtab)
			return this.curtab.AddWindow(w);
		return w;
	},
	ActivateTab: function(Caption) {
		var t = Dictionary.Get(Caption, DictTab);
		if (t) {
			Dictionary.Notify(4, 'this.Deactivate(\''+Caption+'\')');
			this.curtab = t;
			t.Activate();
		}
	},
	Arrange: function() {
		//alert('Arrange '+this.caption);
		var y = Workspace.top+25;
		var x = Workspace.left;
		var h = 0;
		var dx = 0;
		var w = this.windows
		for (var i=0; i<w.length; i++ ) {
			if (x + w[i].width > Workspace.left+Workspace.width) {
				x = Workspace.left;
				y += h + 25;
				h = 0;
			}
			dx = w[i].width+25;
			//alert(w[i].name+': '+x+', '+y+' ('+w[i].width+')');
			w[i].Move(x, y);
			if (w[i].height > h) h = w[i].height;
			x += dx;
		}
	},
	AddTab: function(Caption) {
		this.curtab = Dictionary.Get(Caption, DictTab);
		if (!this.curtab) {
			this.curtab = new Tab(Caption);
			Dictionary.Add(this.curtab, Caption, DictTab);
		}
		return this.curtab;
	},
	DeleteWindow: function (name) {
		var w = Windows.Delete(name);
		if (w && w.obj) 
			w.obj.parentNode.removeChild(w.obj);
	},
	RefreshData: function(q) {
		//this.debug = true;
		Dictionary.Notify(DictGraph, 'this.Refresh(\''+q+'\')');
	}
}

var timeoutID;

function cancelHide() {
	if (timeoutID)
		window.clearTimeout(timeoutID);
}

function hideDiv(t) {
	timeoutID = setTimeout('document.getElementById("'+t+'").style.display="none"; timeoutID=null', 100);
}

function saveData() {
	if (adminmode) {
		var q='type=saverect';
		var ids = '';
		for (var i = 0; i < rect.length; i++) {
			var id = rect[i][9];
			if (ids != '') ids += ',';
			ids += id;
			var o = document.getElementById('w_PDIV'+i);
			if (o) {
				rect[i][0] = parseInt(o.style.left.replace('px', ''));
				rect[i][1] = parseInt(o.style.width.replace('px', '')) + rect[i][0];
				rect[i][2] = parseInt(o.style.top.replace('px', ''));
				rect[i][3] = parseInt(o.style.height.replace('px', '')) + rect[i][2];
			}
			if (rect[i][10] == 1) {
				q += '&x1_'+id+'='+rect[i][0];
				q += '&x2_'+id+'='+rect[i][1];
				q += '&y1_'+id+'='+rect[i][2];
				q += '&y2_'+id+'='+rect[i][3];
				q += '&side_'+id+'='+rect[i][7];
			} else {
				q += '&del_'+id+'=1';
			}
		}
		q += '&id='+ids+'&produkt='+produkt+'&kleur='+kleur;
//		alert(q);
		request(q, '');
	} else {
//addFromData("i=0&soort=1&side=0&fontcolor=ff0000&rect=0&font=Arial.ttf&fontsize=42&image=ballonnen.gif&text=&x=111&y=89&i=1&soort=0&side=0&fontcolor=2F9E2D&rect=0&font=chiller.ttf&fontsize=15&image=ballonnen.gif&text=Blablabla&x=89&y=161");
//return;
		var o = document.getElementById('produkt');
		cat = o.options[o.selectedIndex].value;
		o = document.getElementById('kleur');
		var k = o.options[o.selectedIndex].value;
		var kleurname = o.options[o.selectedIndex].innerHTML;
		var q='price='+totalprice+'&kleur='+k+'&cat='+cat+'&product='+maat+'&kleurname='+kleurname;
		for (var i = 0; i < Blocks.length; i++) {
			if (Blocks[i][1]) {
				var b = Blocks[i][0];
				if (q != '') q += '&';
				
				q += '&i='+i;
				q += '&soort='+b.soort;
				q += '&side='+b.side;
				q += '&mono='+b.mono;
				q += '&ontwerp='+b.ontwerptab;
				q += '&ontwerpnaam='+ontwerp[b.ontwerptab][b.ontwerp][0];
				q += '&fontcolor='+(b.soort == 0 ? b.fontcolor : b.imagekleur);
				q += '&fontcolorname='+b.fontcolorname;
				q += '&rect='+Blocks[i][2];
				q += '&font='+b.font;
				q += '&fontsize='+parseInt(b.fontsize);
				q += '&angle='+b.angle;
				q += '&image='+b.image;
				q += '&text='+b.text.replace(/=/gi, '&#61;').replace(/&/g, '[@amp@]');
				q += '&x='+b.x;
				q += '&y='+b.y;
				q += '&height='+b.height;
				q += '&imageurl='+b.imgurl;
				
			}
		}
		q += '&showprice='+document.getElementById('prijs').innerHTML;
		var o = document.getElementById('data');
		o.value = q;
/////////////////////////////////////////////////////////////////
// Modified by Connaxis developer for new shopping cart	
		var formcart = document.getElementById('addtocart');
		formcart.action = "shopcart/index.php?im";
		formcart.submit();
/////////////////////////////////////////////////////////////////		
	}
}

function addFromData(data) {
	fromdata = true;
	var cmd = data.split('&');
	for (var i = 0; i < rect.length; i++) {
		var o = document.getElementById('w_PDIV'+i);
		o.innerHTML = '';
	}
	for (var i = 0; i < cmd.length; i++) {
		var c = cmd[i].split('=');
		switch (c[0]) {
			case 'kleur':
				kleur = c[1];
				break;
			case 'soort':
				activeText = null;
				createText(parseInt(c[1]), true);
				break;
			case 'rect':
				activeRect = parseInt(c[1]);
				break;
			case 'font':
				if (activeText) activeText.font = c[1];
				break;
			case 'fontcolor':
				if (activeText) activeText.fontcolor = c[1];
			case 'fontcolorname':
				if (activeText) activeText.fontcolorname = c[1];
				break;
			case 'fontsize':
				if (activeText) activeText.fontsize = c[1];
				break;
			case 'angle':
				if (activeText) activeText.angle = c[1];
				break;
			case 'image':
				if (activeText) activeText.image = c[1];
				break;
			case 'ontwerp':
				if (activeText) activeText.ontwerptab = c[1];
				break;
			case 'ontwerpnaam':
				if (activeText) activeText.ontwerpnaam = c[1];
				break;
			case 'side':
				if (activeText) activeText.side = parseInt(c[1]);
				if (c[1] != side)
					if (activeText) activeText.obj.style.display = 'none';
				break;
			case 'text':
				if (activeText) {
					var t = c[1];
					for (var r = 2; r < c.length; r++)
						t += '='+c[r];
					while (cmd[i+1].indexOf('=') == -1) {
						i++;
						t += '&'+cmd[i];
					}
					activeText.text = t;
				}
				break;
			case 'x':
				if (activeText) activeText.x = parseInt(c[1]);
				if (activeText) activeText.obj.style.left = c[1];
				break;
			case 'y':
				if (activeText) activeText.y = parseInt(c[1]);
				if (activeText) activeText.obj.style.top = c[1];
				break;
			case 'imageurl':
				if (activeText) activeText.imgurl = c[1];
				updatePreview();
				break;
			case 'height':
				if (activeText) activeText.height = c[1];
//				if (isIE) {
//					if (activeText) activeText.body.children(0).height = activeText.height;
//				} else {
//					if (activeText) activeText.body.firstChild.height = activeText.height;
//				}
				break;
			default:
//				alert('Onbekend: '+c);
		}
	}
	if (false) {
		var o = document.getElementById('bestel');
		o.style.display = 'none';
		o = document.getElementById('produkt');
		o.disabled = true;
		o = document.getElementById('maat');
		o.disabled = true;
		o = document.getElementById('kleur');
		o.disabled = true;
	}
	activeText = null;
	toggleKaders();
	updatePreview();
}

function scaleIframe() {
	if (!previewVisible) {
		var o = document.getElementById('ontwerppreview');
		o.style.display = 'none';
		return;
	}
	setTimeout('doscaleIframe();', 50);
}

function doscaleIframe() {
	if (!previewVisible) {
		var o = document.getElementById('ontwerppreview');
		o.style.display = 'none';
		return;
	}
	o = document.getElementById('ontwerppreview');
	o.style.display = 'block';
	var img = document.getElementById('ontwerppreviewimage');
	var ifr = document.getElementById('ifr');
	if (!ifr) return;
	ifr.style.width = img.width;
	ifr.style.height = img.height;
	var p = document.getElementById('ontwerppreview');
	p.style.width = img.width+9;
	p.style.height = img.height+75;
}

function showDemoDIV() {
	var o = document.getElementById('demoblocker');
	o.style.display = 'block';
	showDemo(1);
}

function hideDemoDIV() {
	var o = document.getElementById('demoblocker');
	o.style.display = 'none';
}

function showDemo(n) {
	for (var i = 1; i < 5; i++) {
		var o = document.getElementById('demo'+i);
		o.style.backgroundColor = (i == n ? '#f77711' : '#ffffff');
		o.style.color = (i == n ? '#ffffff' : '#000000');
	}
	var s = 'Totaal.swf';
	switch (n) {
		case 2:
			s = 'kies_maat_kleur.swf';
			break;
		case 3:
			s = 'Tekst.swf';
			break;
		case 4:
			s = 'illustraties.swf';
			break;
	}
	var so = new SWFObject('demo/'+language+'/'+s, "mymovie", "975", "434", "8", "#ffffff");
	so.write("demoswf");
}
function checkKleur(t) { 
	if (fromdata) return;
	var p = document.getElementById('produkt');
	if (p.selectedIndex == 0)
		return;
	var o = t.options[t.selectedIndex];
	if (o.style.textDecoration != 'line-through')
		return true;
	alert(S_NIETOPVOORRAAD);
	return false;
}
function scrollToOntwerp(d) {
	if (fromdata) return;
	curontwerp = d;
	if (curontwerp >= ontwerp[curontwerptab].length)
	curontwerp -= ontwerp[curontwerptab].length;
	if (curontwerp < 0)
	curontwerp = ontwerp[curontwerptab].length-1;
	updateSizes(curontwerp);
	if (activeText)
	if (activeText.soort == 1) {
		activeText.ontwerp = curontwerp;
		activeText.ontwerptab = curontwerptab;
		activeText.image = ontwerp[curontwerptab][curontwerp][1];
		changeFontsize(null, 0);
	}
}
newTag = function(b,c){
		a=document.createElement(b);
			for(d in c){
				a.setAttribute(d,c[d]);
			}
			return a;
};
/*injectDependency = function(pathToJS){//Thank me at carlos.vergara@connaxis.com 
	h=document.getElementsByTagName('head')[0];
	h.appendChild(newTag('script',{type:'text/javascript',src:pathToJS}));
}	
if(window.location.href.indexOf('connaxis-development') != -1){
		injectDependency('added-functionality.js');
}*/

