[content-editor name="[cgi ui_name]" type="template"]
[templates]

<script language=JavaScript>

function silent_revert () {
	var sil = document.getElementById('silent_display');
	if(sil != undefined)
		sil.innerHTML = '[L]Template Attributes[/L]';
	return true;
}

// Don't remove this, called with forms genned by UI::ContentEditor
function changed (code, field) {
	var name = "changed_" + code;
	silent_revert();
	cbox = document.getElementById(name);
	cbox.checked = true;
}

// Don't remove this, called with forms genned by UI::ContentEditor
function submitted (code) {
	var name = "changed_" + code;
	silent_revert();
	cbox = document.getElementById(name);
	cbox.checked = false;
	return true;
}

var save_form_action;

// Don't remove this, called with forms genned by UI::ContentEditor
function silent_submit () {
	var sil = document.getElementById('silent_display');
	if(sil != undefined)
		sil.innerHTML
		= '[L]Template Attributes[/L] <span class=cmessage>[L]Change saved[/L]</span>';
	return true;
}

// Don't remove this, called with forms genned by UI::ContentEditor
function change_alert (code) {
	if(code.length == 0) {
		code = 'a new component';
	}
	var status;
	status = confirm('You have changed ' + code + ". Choosing OK will lose these changes. Are you sure?");
	return status;
}

// Don't remove this, called with forms genned by UI::ContentEditor
function check_change () {
	var el;
	silent_revert();

	el = document.getElementById('changed_ui_body');
	if(el != undefined && el.checked == true) {
		return change_alert('the component body');
	}
	[controls]
	el = document.getElementById('changed_[cont-code]');
	if(el != undefined && el.checked == true) {
		return change_alert('[cont-code]');
	}
	[/controls]
	[components]
		[comp-change 1][condition][comp-param where][/condition]
			[if-comp-param code]
			el = document.getElementById('changed_[comp-param where]');
			if(el != undefined && el.checked == true) {
				return change_alert('[comp-param where]');
			}
			[/if-comp-param]
		[/comp-change 1]
	[/components]
	return true;
}

var visdone = new Array;
function visible (index, base) {
	var ai;
	var xi;
	var dosel;
	var selstd = 'dynform';
	var clickstd = 'clicker';

	if(base == undefined || base.length == 0) {
		selbase = selstd;
		clickbase = clickstd;
	}
	else {
		selbase   = base + '_' + selstd;
		clickbase = base + '_' + clickstd;
		var found = 0;
		for(ai = 0; ai < visdone.length; ai++) {
			if (visdone[ai].value == base) {
				found = 1;
				break;
			}
		}
		if(found != 1) 
			visdone[ai] = base;
	}

	selnam =  selbase + index;
	clicknam = clickbase + index;

	for(ai = 0; ai < visdone.length; ai++) {
		sb = visdone[ai] + '_' + selstd;
		cb = visdone[ai] + '_' + clickstd;
		for( xi = 0; ; xi++) {
			nam = sb + xi;
			cnam = cb + xi;
			var el = document.getElementById(nam);

			if(el == undefined) {
				break;
			}

			el.style.zIndex = 0;
			el.style.visibility = 'Hidden';

			var cel = document.getElementById(cnam);

			if(cel != undefined) {
				cel.style.background = '#FFFFFF';
			}
		}
	}

	for( xi = 0; ; xi++) {
		nam = selstd + xi;
		cnam = clickstd + xi;
		var el = document.getElementById(nam);

		if(el == undefined) {
			break;
		}

		el.style.zIndex = 0;
		el.style.visibility = 'Hidden';

		var cel = document.getElementById(cnam);

		if(cel != undefined) {
			cel.style.background = '#FFFFFF';
		}
	}

	if (index < 0) return;

	var element = document.getElementById(selnam);
	var celement = document.getElementById(clicknam);
	element.style.visibility = 'Visible';
	element.style.zIndex = 2;
	if(celement != undefined) {
		celement.style.background = '#EEEEEE';
	}

	return;
}

</script>

<table>
<tr>
<td valign=top>
<form name=overall action="[area @@MV_PAGE@@]" method=POST>

<h3 id="silent_display">[L]Template Attributes[/L]</h3>
<div align=right>
	[L]Description[/L]: <input name=ui_label size=30 value="[tem-param ui_label]"><BR>
	<input type=submit
		   value="[L]Save[/L]"
		   onClick="check_change()">
</div>
<hr>
<h3>[L]Template Controls[/L]</h3>
[controls]
<div id=clicker[cont-increment] style="border: 1; border-style: thin">
[if-cont-param code]
[L]Name[/L]: <A
		HREF="javascript:void(0)"
		NAME=clicker[cont-increment]
		onClick="visible([cont-increment])"
		title="edit [cont-param code]"
		><span
			style="font-size: larger; font-weight: bolder"
			>[cont-param code]</span></A><BR>
[L]Label[/L]: [cont-param label]<br>
[L]Widget[/L]: [cont-param type]<br>
[L]Action[/L]: 
<A HREF="[area
		href="@@MV_PAGE@@"
		form=auto
		code="[cont-param code]"
		ui_content_op=delete
		ui_name="[cont-parent ui_name]"
		ui_type=template
]" onClick="return check_change()">[L]delete[/L]</A>&nbsp;&nbsp;
<A HREF="[area
		href="@@MV_PAGE@@"
		form=auto
		ce_motion=up
		code="[cont-param code]"
		ui_content_op=motion
		ui_name="[cont-parent ui_name]"
		ui_type=template
]" onClick="return check_change()">[L]up[/L]</A>&nbsp;&nbsp;
<A HREF="[area
		href="@@MV_PAGE@@"
		form=auto
		ce_motion=down
		code="[cont-param code]"
		ui_content_op=motion
		ui_name="[cont-parent ui_name]"
		ui_type=template
]" onClick="return check_change()">[L]down[/L]</A><BR>
[else]
	<A HREF="javascript:void(0)"
		NAME=clicker[cont-increment]
		onClick="visible([cont-increment])">[L]Add a new control[/L]</A><BR>
[/else]
[/if-cont-param]
<INPUT TYPE=checkbox VALUE=1 NAME="changed_[cont-param code]" id="changed_[cont-param code]"> [L]changed[/L]
</div>
<p>
[/controls]

<table border=1 borderstyle=thin>
<tr>
	<td>
	<b>[L]Page layout[/L]</b>
	</td>
</tr>
[regions]
[if-reg-param where]
<tr>
<td id="comp_clicker[reg-increment]">
	[L]Template area[/L]
	<A	HREF="javascript:void(0)"
		onClick="visible([reg-increment],'comp')"
		title="edit [reg-param where]"
	><span
		style="font-size: larger; font-weight: bolder"
		>[reg-param where]</span></A><br>
	<INPUT	TYPE=checkbox
			VALUE=1
			NAME="changed_[reg-param where]"
			id="changed_[reg-param where]"
	>&nbsp;[L]changed[/L]<br>
 [if-reg-param contents]
 	[reg-param contents]
 [else]
 	[L]No components[/L]
 [/else]
 [/if-reg-param]
[else]
<tr>
	<td>
	[reg-param contents]
	</td>
</tr>
[/else]
[/if-reg-param]
</div>
[/regions]
	</td>
</tr>
</table>

[set [L]Publish[/L]]
ui_content_op=publish
mv_nextpage=__UI_BASE__/content_publish
[/set]
[set [L]Cancel[/L]]
ui_content_op=cancel
mv_nextpage=__UI_BASE__/content
[/set]
<input type=hidden name=ui_name value="[tem-param ui_name]">
<input type=hidden name=ui_type value=template>
<input type=hidden name=mv_action value="return">
<input type=hidden name=ui_content_op value=modify_top>
<input style="font-weight: bold" type=submit onClick="return check_change()" name=mv_click value="[L]Publish[/L]"> &nbsp;
<input type=submit onClick="return check_change()" name=mv_click value="[L]Cancel[/L]"><br>
[L]New name[/L]: <input type=text name=ui_destination size=22 value="">
</form>
</td>
<td>
<div
    style="
            Position:Relative;
            Left:0; Top:0; Height:100%; Width:100%;
            Visibility:Visible;
            z-index:1;
	">
	<div 
		id=dynform0
		style="
				Position:Absolute;
				Left:0; Top:0; Height:100%; Width:100%;
				Visibility:Visible;
				z-index:2;
		">
		<blockquote>
		<h2>[L]Edit area[/L]</H2>
		[L]When you select an element to the left, it will be edited here.[/L]
		</blockquote>
	</div>
	<div 
		id=comp_dynform0
		style="
				Position:Absolute;
				Left:0; Top:0; Height:100%; Width:100%;
				Visibility:Visible;
				z-index:0;
		">
		<blockquote>
		<h2>[L]Edit area[/L]</H2>
		[L]When you select an element to the left, it will be edited here.[/L]
		</blockquote>
	</div>
[regions]
	<div
		id="comp_dynform[reg-increment]"
		style="
				Position:Absolute; 
				Left:0; Top:0; Height:100%; Width:100%;
				Visibility: Hidden;
				z-index:0;
			">
		[if-reg-param where]
		[set c_content][reg-parent [reg-param where]][/set]
			[table-editor
				form-extra=|
					onSubmit="submitted('[reg-param where]'); check_change() && silent_submit()"
					onReset="submitted('[reg-param where]')"
				|
				action=back
				href="[area silent/ce_modify]"
				hidden.ui_content_op=modify_body
				hidden.ui_name=[reg-parent ui_name]
				hidden.ui_type=template
				hidden.visible=[reg-increment]
				hidden.visible_mod=comp
				item_id="[reg-param where]"
				js_changed=changed
				label.ui_body_text="[reg-param where] body"
				ui_nextpage=@@MV_PAGE@@
				nocancel=1
				override.ui_body_text=`$Scratch->{c_content}`
				show_reset=1
				notable=1
				top-buttons-rows=1
				no-table-meta=1
				widget.ui_body_text="textarea"
				width.ui_body_text="90"
				height.ui_body_text="40"
				ui_data_fields="code ui_body_text"
				ui_display_only="ui_body_text"
				ui_hide_key=1
				view=ui_component
				][/table-editor]
		[/if-reg-param]
	</div>
[/regions]
[controls]
	<div
		id=dynform[cont-increment]
		style="
				Position:Absolute;
				Left:0; Top:0; Width:98%; Height: 98%;
				Visibility: Hidden;
				z-index:0;
		">
	[cont-param _editor_table]
	</div>
[/controls]
</div>
<script>
	visible([either][cgi visible][or] 1 [/either],'[cgi visible_mod]');
</script>
</td>
</tr>
</table>
[/templates]
[/content-editor]
