var gMaxBannerSize = 32766;
function editBanner() 
{ 
	var bannerTA = $('bannerTextRW');
	if(bannerTA == null) bannerTA = $('CKbannerTextRW'); // This line should go away once the build is updated

	if(bannerTA != null) {		// This had better not be null at this point
		bannerTA.value = $("bannerText").innerHTML;
		var editor = null;
		if((typeof(tinymce) != "undefined") && (editor = tinymce.EditorManager.get(bannerTA.id)))
			editor.load();
		if((typeof(CKEDITOR) != "undefined") && (editor = CKEDITOR.instances[bannerTA.id]))
			editor.setData(bannerTA.value);

	}
	$("bannerDisplay").hide();
	$("bannerEdit").show();
}

function cancelEditBanner() 
{
  $("bannerEdit").hide();
  $("bannerDisplay").show();
}
function saveBanner(tURL)
{	
	var bannerTA = $('bannerTextRW');
	if(bannerTA == null) bannerTA = $('CKbannerTextRW'); // This line should go away once the build is updated

	if(bannerTA != null) {		// This had better not be null at this point
		bannerTA.value = $("bannerText").innerHTML;
		var editor = null;
		if((typeof(tinymce) != "undefined")  && (editor = tinymce.EditorManager.get(bannerTA.id)))
			editor.save();
		if((typeof(CKEDITOR) != "undefined")  && (editor = CKEDITOR.instances[bannerTA.id]))
			editor.updateElement();

	}

	var tBannerTextSize = parseInt(bannerTA.value.length);   // rgi - why parseInt here??
	
	if(tBannerTextSize > gMaxBannerSize)
	{
		retValue = false;
		alert(' Please restrict input to ' + gMaxBannerSize + 
			' characters!  Current text length is ' + tBannerTextSize + '.');
		return false;
	}
	
	new Ajax.Updater(
		'bannerText',
		tURL,
		{	method : 'post',
			parameters : $('bannerEditForm').serialize(true),
			onSuccess : function(transport) {
                        	$('bannerEdit').hide();
                        	$('bannerDisplay').show();
			},
			onFailure : function(transport) {
				alert("Error code:"+ transport.status + ". " + transport.statusText); 
				transport.responseText = tBannerTextArea;
				$('bannerEdit').show();
				$('bannerDisplay').hide();
			}			
		}
	);
}

/* not banner related, just testing scripts */


document.observe('dom:loaded',function(){ 
  $$('.ebLegend').each(function(x){x.observe('click',function(){this.up().toggleClassName('ebCollapsed')})})
  if($('noteColor')) $('noteColor').observe('change',function(){
    var newcolor = this.value;
    var div = this.up('.ebNoteDetail');
    div.setStyle({'background': ''});
    $A(this.options).each(function(x){div.removeClassName('eb'+x.value.toLowerCase())});
    div.addClassName('eb'+newcolor.toLowerCase());
  });
})

