//var _editor_url = '/htmlarea/';var browse_images_popup = null;var browse_docs_popup = null;var main_popup = null;function edit_html( field, listcode ) {	// Open popup for editing this field, passing url	// param so popup knows where to get data and	// css defined by listcode	var css_param = "";	if (listcode) {		css_param = '&css=/ecco/css/edit_' + listcode + '.css';	}	var popup = window.open( '/ecco/edit_html.html?field=' + field + css_param, 'edit_html', 'width=670,height=520,top=10,left=10,resizable=no' );	popup.focus();	main_popup = popup;}function insert_html( w, html ) {	// Insert HTML into the Xinha editor in window w	agt = navigator.userAgent.toLowerCase();	is_ie	= ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));	if (is_ie) {		// Hack for IE to put focus in window, otherwise content is inserted		// into frame outside of editor!		//w.xinha_editors['content']._iframe.contentWindow.focus();	}	// Use first (only) editor instance	var editor_id = 'mce_editor_0';	w.tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, html); }function fill_edit() {	// Called by popup, retrieve data from opener's field	// specified by url param	var field = url_param( 'field' );	var content = window.opener.document.getElementsByName( field )[0].value;	var htmledit = document.getElementsByName('content')[0]	htmledit.value = content;	return content;}function plain_text(html) {	// Return nothing for blanks	if (!html) {		return html;	}		// Remove entities	var re = new RegExp( "&[a-z]+?;", "g" );	html = html.replace(re, "");		// Encode & signs	html = html.replace('&','&amp;');		// Remove tags 	re = new RegExp( "</?[^>]+>", "g" );	html = html.replace(re, " ");	return html;}function save_html() {	// Write changes back to opener	var field = url_param( 'field' );	var content = document.getElementsByName( 'content' )[0].value;	window.opener.document.getElementsByName( field )[0].value = content;		// Any preview to update?	var preview = window.opener.document.getElementById("preview_" + field)	if (preview) {		preview.innerHTML = plain_text(content).substr(0,150);	}		// Close image/doc popup if it's open	if (browse_images_popup) {		browse_images_popup.close();	}	if (browse_docs_popup) {		browse_docs_popup.close();	}}function autosave_html(content) {	// Write changes back to opener	var field = url_param( 'field' );	window.opener.document.getElementsByName( field )[0].value = content;}function url_param(p) {	// Retrieve an url param specified by p=value	var re = new RegExp( p + "=([^&]+)" );	var matches = document.location.href.match(re);	if (matches) {		return matches[1];	}	else {		return '';	}}function list_value(l) {	return l.options[l.selectedIndex].value;}function reset_list(list) {	// Reset the current item to the top one, usually a blank	document.getElementsByName(list)[0].selectedIndex = 0;}function confirm_delete() {	// 1st argument [0] is whether this delete can be undone	var message = 'Are you sure you want to delete this item?';	if (!arguments[0]) {		message += '\n\nThis cannot be undone.';	}	return confirm(message);}function popup_browse_images(folder, mode, set_field) {	// Open the popup image browser, in the folder if specified	// mode="select" causes clicked images to be returned to the	// caller's li_image field.	if (folder===undefined) folder = "";	if (set_field===undefined) set_field = "";	if (mode===undefined) mode = "browse";	var params = "category=" + folder + "&mode=" + mode + "&set_field=" + set_field;	browse_images_popup = window.open( '/do/ecco_edit_images.py/popup?' + params, 'images', 'width=700px,height=600,top=10,left=400,scrollbars=yes,resizable=yes' );	browse_images_popup.focus();}function select_image(img, field) {	// The user has selected this image, so write it back to the caller	window.opener.document.getElementsByName(field)[0].value = img;	var preview = window.opener.document.getElementById("img_" + field);	if (preview) {		// Use the thumbnail channel		var thumb = img.slice(0, img.lastIndexOf(".")) + "@thumb" + img.slice(img.lastIndexOf("."));		preview.src = "/resources/listimg/" + thumb;	}	window.close();}function popup_browse_docs() {	browse_docs_popup = window.open( '/do/ecco_edit_docs.py/popup', 'docs', 'width=700px,height=600,top=10,left=600,scrollbars=yes' );	browse_docs_popup.focus();}function popup_image(img) {	// Open a new window for this image, ensuring that it's	// the right size (same size as the image)		w = window.open('/ecco/popup/popup_image.html?img=' + img, 'popupImage','width=300,height=300,left=650,top=20,scrollbars=yes,resizable=yes');	w.focus();}function popup_image_load() {	// Image popup calls this in onload to load 	// the image and resize the window	// Load the image	i = document.getElementById('imgdiv'); 	// The auto resize causes problems with drag and drop usage, so don't use it	//i.innerHTML = '<img id="mainimg" src="' + url_param('img') + '" onload="popup_image_resize()">';	i.innerHTML = '<img id="mainimg" src="' + url_param('img') + '">';}function popup_image_resize() {	// Now that the image has loaded resize it	i = document.getElementById('mainimg'); 		// Include space for extra stuff under and to right of image?	space_for_title_bar = 30;	space_to_right = 30;			// check that the image isn't too big	if (i.width < 800 && i.height < 600) {		window.resizeTo(i.width + space_to_right, i.height + space_for_title_bar);	}}function check_help_open() {	if (document.cookie.indexOf('ecco_help=closed') == -1) {		open_help();	}}function open_help() {    if (!document.getElementById('help')) return false;	document.getElementById('help').className = '';	set_cookie("ecco_help", "open");}function close_help() {	document.getElementById('help').className = 'closed';	set_cookie("ecco_help", "closed");}function set_cookie(name, value) {	// Add a year for expiry	var next_year = new Date();	next_year.setYear(next_year.getFullYear()+1);	document.cookie = name + "=" + value + "; path=/; expires=" + next_year.toGMTString();	}function autosave_and_close(){	// See if an editor window is open	if(main_popup != null)	{		// If so force a submit by the editor which will execute save_and_close()		var form = main_popup.document.getElementById("editForm");		form.submit();	}}function save_and_close_editor(){	// Write html changes back to openner	save_html();	// Perform an autosave in case user navigates away without saving or discarding	autosave(); 	// Close the editor window	window.close();	// Clear editor popup var	main_popup = null;}// ---------------------------------------------------------------// AUTO SAVE// ---------------------------------------------------------------function start_autosave() {	var autosave_period = 10; //seconds	window.setTimeout( "autosave()", autosave_period * 1000 );}function autosave() {	var form = window.opener.document.getElementById("autosaveForm");	if (form) {		// Post back data to opener		var editor = tinyMCE.getInstanceById( "content" );		autosave_html( editor.getHTML() );		// Tweak the form then submit, causing an autosave		form.target = "autosaveFrame";		form.autosave.value = 1;		form.submit();		// Now restore normal state		form.autosave.value = 0;		form.target = "";		// Start timer for next save		start_autosave();	}	else {		// No autosave on this form	}}// ---------------------------------------------------------------// NAVIGATION// ---------------------------------------------------------------function highlight_nav(id) {	document.getElementById( 'a_' + id ).className = 'sel';}function switch_tab() {     	// Show on and Hide off	document.getElementById('tab_' + arguments[0]).style.display = 'block';	document.getElementById('a_' + arguments[0]).className = 'sel';			for(var i=1;i<arguments.length; i++){	        document.getElementById('tab_' + arguments[i]).style.display = 'none';        document.getElementById('a_' + arguments[i]).className = '';	}}function add_tag(select, tagsinput) {	var ti = document.getElementById(tagsinput);	if (ti.value) {		ti.value += ',';	}	ti.value += list_value(select);}
