function focusForm(field_id)
{
	if(document.getElementById(field_id))
		document.getElementById(field_id).focus();
}

function processForm(f,cid)
{
	d_cid = document.getElementById(cid);
	if(d_cid)
	{
		d_orig = d_cid.innerHTML;
		showFormProcessing(cid);
		qstr = createQStringFromForm(f)+"&a="+cid;
		new Ajax.Request("/", 
		{
			method: f.method,
			postBody: qstr,
			onSuccess: function(transport) {
				d_cid.innerHTML = transport.responseText;
			},
			onFailure: function() {
				alert("Unable to save Form");
			}
		});
	} else {
		alert(cid+" content_id does not exist... cannot process request for "+f.name)
	}
}

function createQStringFromForm(f)
{
	var q_params = new Array();
	for(var i=0; i<f.length; i++)
	{
		 e = f.elements[i];
		 q_params.push(encodeURIComponent(e.name)+'='+encodeURIComponent(e.value));
	}
	return(q_params.join('&'));
}

function showFormProcessing(cid)
{	
	d_cid = document.getElementById(cid);
	if(d_cid)
	{
		d_cid.innerHTML = "Processing Form... Please wait";
	}
}

function processLink(a,qstr,cid)
{
	d_cid = document.getElementById(cid);
	if(d_cid)
	{
		d_orig = d_cid.innerHTML;
		if(qstr.toString().length) qstr += "&";
		qstr += "a="+a+"&cid="+cid;
		new Ajax.Request("/?"+qstr, 
		{
			method: 'GET',
			onSuccess: function(transport) {
				alert(transport.responseText)
				eval(transport.responseText);
			},
			onFailure: function() {
				alert("Unable to process request");
			}
		});
	} else {
		alert(cid+" content_id does not exist... cannot process request for "+f.name)
	}	
}

function deleteEntity(a,p,id)
{
	if(confirm("Are you sure you want to delete this entry?  All records will be lost if you delete it."))
		document.location = "?a="+a+"&p="+p+"&id="+id;
}


tinyMCE.init({
	// General options
	mode : "specific_textareas",
	editor_deselector : "noMCE",
	theme : "advanced",
	plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager",

	// Theme options
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,formatselect,fontselect,fontsizeselect,|,forecolor,backcolor,|,sub,sup",
	theme_advanced_buttons2 : "bullist,numlist,|,justifyleft,justifycenter,justifyright,justifyfull,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,|,iespell,advhr,|,pasteword,pastetext,selectall",
	theme_advanced_buttons3 : "tablecontrols,|,spellchecker,preview,insertfile,insertimage,|,insertdate,inserttime,|,code",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : true,
	
	spellchecker_languages : "+English=en",
	
	relative_urls : false,
	remove_script_host : false,
	forced_root_block : false,


	// Drop lists for link/image/media/template dialogs
	template_external_list_url : "js/template_list.js",
	external_link_list_url : "js/link_list.js",
	external_image_list_url : "js/image_list.js",
	media_external_list_url : "js/media_list.js"
});
