function openWindow(url, w, h, l, t, args)
{
	if (!args)
	{
		args = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
	}
	if (w) {
		args += ",width="+w;
	}
	if (h) {
		args += ",height="+h;
	}
	if (l) {
		args += ",left="+l;
	}
	if (t) {
		args+= ",top="+t;
	}
	oWin = window.open(url,'',args);
	if (oWin!=null)
	{
		oWin.focus();
	}
}

function openCart(url, w, h)
{
	args = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
	if (w) {
		args += ",width="+w;
	}
	if (h) {
		args += ",height="+h;
	}
	oWin = window.open(url,'cart',args);
	if (oWin!=null)
	{
		oWin.focus();
	}
}

function popCSS(css,edittype,structure_id,specific)
{
	url = "/onderhoud/css.php?id="+css+"&edittype="+edittype+"&structure_id="+structure_id;
	if (specific)
	{
		url = url + "&specific="+specific;
	}
	w = 600;
	h = 500;
	l = 100;
	t = 100;
	openWindow(url, w, h, l, t);
}

function popCSSmenu(css,edittype,structure_id)
{
	url = "/onderhoud/cssmenu.php?id="+css+"&edittype="+edittype+"&structure_id="+structure_id;
	w = 600;
	h = 500;
	l = 100;
	t = 100;
	openWindow(url, w, h, l, t);
}

function popTextarea(css,structure_id,specific)
{
	url = "/onderhoud/textarea.php?id="+css+"&structure_id="+structure_id;
	if (specific)
	{
		url = url + "&specific="+specific;
	}
	w = 600;
	h = 400;
	l = 100;
	t = 100;
	openWindow(url, w, h, l, t);
}

function popTemplate(structure_id) 
{
	url = "/onderhoud/template.php?structure_id="+structure_id
	w = 1024;
	h = 700;
	l = 0;
	t = 0;
	openWindow(url, w, h, l, t);
}

function popConfig() 
{
	url = "/onderhoud/config.php";
	w = 1024;
	h = 700;
	l = 0;
	t = 0;
	openWindow(url, w, h, l, t);
}

function popContent(page,newpage)
{
	if (page.length == 32) 
	{
		if (newpage)
		{
			url = "/onderhoud/contenttype.php?id="+page;
		}
		else
		{
			url = "/onderhoud/edit.php?structure_id="+page;
		}
		w = 700;
		h = 600;
		l = 50;
		t = 50;
		openWindow(url, w, h, l, t);
	}
}

function popInternalLink()
{
	url = "/onderhoud/internal_link.php";
	w = 700;
	h = 500;
	l = 50;
	t = 50;
	openWindow(url, w, h, l, t);
}

function popOrder()
{
	url = "/onderhoud/order.php";
	w = 700;
	h = 500;
	l = 50;
	t = 50;
	openWindow(url, w, h, l, t);
}

function popHelp()
{
	url = "/help/index.php";
	w = 1024;
	h = 700;
	l = 0;
	t = 50;
	openWindow(url, w, h, l, t);
}

function popImage( url, w, h )
{
	l = 50;
	t = 50;
	openWindow(url, w, h, l, t);
}

function insertPage(structure_id)
{
	popContent(structure_id,true);
}

function deletePage(structure_id)
{
	if (window.confirm("Wilt u deze pagina verwijderen?"))
	{
		window.location.href = "/onderhoud/index.php?delete=true&structure_id="+structure_id+"&t="+new Date().getTime();
	}
}

function cssReset(structure_id)
{
	if (window.confirm("Wijzigingen opmaak ongedaan maken?"))
	{
		window.location.href = "/onderhoud/index.php?resetCss=true&structure_id="+structure_id+"&t="+new Date().getTime();
	}
}

function uitloggen()
{
	if (window.confirm("Wilt u uitloggen?"))
	{
		window.location.href = "/onderhoud/index.php?logout=true";
		//window.opener = null;
		//window.close();
	}
}


function setAdvanced(structure_id, state)
{
	window.location.href = "/onderhoud/index.php?advanced="+state+"&structure_id="+structure_id;
}

function publish()
{
	window.location.href = "/onderhoud/index.php?publish=true";
}

function demo()
{
	alert('in deze demo-versie niet beschikbaar');
}

var structure = new Array();

// omhoog verplaatsen van het geselecteerde item 
// in select-list van een formulier
// o=formulier met options, h = hidden field met alle opties
function moveUp(o,h)
{
	var n = o.selectedIndex;
	if (n>0)
	{
		var t = o.options[n].text;
		var v = o.options[n].value;
		o.options[n].text		= o.options[n-1].text;
		o.options[n].value		= o.options[n-1].value;
		o.options[n-1].text		= t;
		o.options[n-1].value	= v;
		o.selectedIndex = o.selectedIndex-1;
	}
	updateHiddenField(o,h);
}

// omlaag verplaatsen van het geselecteerd item 
// in select-list van een formulier
// o=formulier met options, h = hidden field met alle opties
function moveDown(o,h)
{
	var n = o.selectedIndex;
	if (n<o.options.length && n!=-1)
	{
		var t = o.options[n].text;
		var v = o.options[n].value;
		o.options[n].text		= o.options[n+1].text;
		o.options[n].value		= o.options[n+1].value;
		o.options[n+1].text		= t;
		o.options[n+1].value	= v;
		o.selectedIndex = o.selectedIndex+1;
	}
	updateHiddenField(o,h);
}

function indent2(o,h)
{
	var n = o.selectedIndex;
	if (n>0)
	{
        o.options[n].text = "" + spacer(1) + "" + o.options[n].text;
	}
}

function indent(o,h)
{
	demo();
	/*
	if ((o.selectedIndex>0) && (o[smenu.selectedIndex-1].indent>=o[o.selectedIndex].indent) && ((o[o.selectedIndex-1].breakStorage==false) || (o[o.selectedIndex-1].breakStorage==null)))
	{
		o[o.selectedIndex].indent++
        paintItem(o[o.selectedIndex])
    }
    else
    {
    	alert("You can only indent elements 1 level deeper than the parent.")
    }
	dis.disabled=o[o.selectedIndex].indent==0
	//breakItem.disabled = o[o.selectedIndex].indent==0
	*/
}

function outdent(o,h)
{
	demo();
}

function paintItem(el) {
	var str=""
    for (var i = 0; i < el.indent; i++)
        str+="   "
    el.text = str + el.textStorage
    //buildTable()
}

// wordt aangeroepen door de functie moveUp en moveDown
// o=formulier met options, h = hidden field met alle opties
function updateHiddenField(o,h)
{
	var i = 0;
	var a = new Array();
	for (i=0; i<o.options.length; i++)
	{
		a[a.length] = o.options[i].value;
	}
	h.value = a.join(",");
	//alert(a.toPHP())
}

function drawSelect()
{

}

function spacer(j) {
	var str=""
	for (var i = 0; i < j; i++) {
		str+="--";
	}
	return str
}
