/// <summary>
		/// Called by the framework so the component can
		/// render its content
		/// </summary>
		public override void Render()
		{
			base.Render();
			JavascriptHelper javascript = new JavascriptHelper(Context, EngineContext,"LinkSubmitButtonComponent");
			javascript.IncludeStandardScripts("Ajax");

			RenderText(LinkToRender());
			CancelView();
		}
        /// <summary>
        /// Called by the framework so the component can
        /// render its content
        /// </summary>
        public override void Render()
        {
            base.Render();

            if (Text.Length <= MaxLength)
            {
                RenderText(Text);
            }
            else
            {
                int inx = Text.LastIndexOf(' ', MaxLength);
                RenderText(Text.Substring(0, inx));

				JavascriptHelper helper = new JavascriptHelper(Context, EngineContext, "MoreLessComponent");
				if (helper.PreferredLibrary == "jquery")
				{
					helper.IncludeStandardScripts("jquery");
					helper.IncludeScriptText("function moreless(key) {jQuery('#extraText:'+key).toggle();jQuery('#more:'+key);}");
				}
				else
				{
					helper.IncludeStandardScripts("Ajax");
					helper.IncludeScriptText("function moreless(key) {Element.toggle('extraText:'+key);Element.toggle('more:'+key);}");
				}
                string key = base.MakeUniqueId("");
                RenderTextFormat(@"&nbsp;<span id=""extraText:{0}"">", key);
                RenderText(Text.Substring(inx));
                RenderTextFormat(@"<a onclick=""moreless('{0}');"">{1}</a></span>" +
                                                @"<span id=""more:{0}"" style=""display:none""><a onclick=""moreless('{0}');"">{2}</a></span>"+
                                                @"<script type=""text/javascript"">moreless('{0}');</script>",
                                                key, LessText, MoreText);
            }
            CancelView();
        }
        /// <summary>
        /// Called by the framework once the component instance
        /// is initialized
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

			helper = new JavascriptHelper(this.Context, this.EngineContext, "DummyInsertJavascript");
            string std = Context.ComponentParameters["Std"] as string ?? string.Empty;
            helper.IncludeStandardScripts(std);
        }
        /// <summary>
        /// Called by the framework once the component instance
        /// is initialized
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();
            id = Context.ComponentParameters["id"] as string;

            if (id == null)
            {
                if (sectionsUsed.Count > 0)
                {
                    throw new ViewComponentException("JavascriptComponent: 'id' parameter must be specified if subsections are used.");
                }
                id = GetHashCode().ToString("x");
            }
			helper = new JavascriptHelper(this.Context, this.EngineContext, id);
            string std = Context.ComponentParameters["std"] as string ?? string.Empty;
            helper.IncludeStandardScripts(std);

            string file = Context.ComponentParameters["file"] as string;
            if (!string.IsNullOrEmpty(file))
                helper.IncludeScriptFile(file);
        }
        void AddScript()
        {
            JavascriptHelper helper = new JavascriptHelper(this.Context, this.EngineContext, "CollapsiblePanelComponent");
            jsLibrary = jsLibrary ?? helper.PreferredLibrary;
            ResourceManager rm = new ResourceManager("Castle.MonoRail.ViewComponents.CollapsiblePanelScripts", Assembly.GetExecutingAssembly());
                string script = rm.GetString(jsLibrary);

            if (script == null)
                throw new ViewComponentException("unsupported JSLibrary option");

            helper.IncludeScriptText(script);
            helper.IncludeStandardScripts(jsLibrary);
			if (jsLibrary.StartsWith("proto"))
				helper.IncludeStandardScripts("effects");
            helper.IncludeScriptText("\nvar CollapseComponentDefaults = {effect: 'blind', effectDuration:0.3,expandLinkText: 'Show', collapseLinkText: 'Hide'};");
        }
        private void RenderJavascript()
        {
            JavascriptHelper helper = new JavascriptHelper(Context, EngineContext, "MenuComponent");
            string jslibrary = this.ComponentParams["JSLibrary"] as string ?? helper.PreferredLibrary ?? "prototype";
            ResourceManager rm = new ResourceManager("Castle.MonoRail.ViewComponents.Menu", 
                            Assembly.GetExecutingAssembly());

            switch (jslibrary.ToLowerInvariant())
            {
                case "jquery":
                    helper.IncludeScriptText(rm.GetString(jslibrary));
                    helper.IncludeStandardScripts("jquery");
                    break;

                case "prototype":
                    helper.IncludeScriptText(rm.GetString(jslibrary));
                    helper.IncludeStandardScripts("effects2");
                    break;

                case "none":
                    break;

                default:
                throw new ViewComponentException("Unsupported JavaScript library requested.  Must be 'prototype' or 'jquery'");
            }
        }
        private void BuildScript()
        {
			JavascriptHelper helper = new JavascriptHelper(Context, EngineContext, "DualList");
			helper.IncludeStandardScripts("Ajax");
			helper.IncludeScriptText(
                @"function moveItem(sourceControl, targetControl) 
{
    var source = $(sourceControl);
    var target = $(targetControl);
    if ((source != null) && (target != null)) 
    {
        while ( source.options.selectedIndex >= 0 ) 
        {
            var newOption = new Option();		          // Create a new instance of ListItem
            newOption.text = source.options[source.options.selectedIndex].text;
            newOption.value = source.options[source.options.selectedIndex].value;
            target.options[target.length] = newOption;	  //Append the item in target
            source.remove(source.options.selectedIndex);  //Remove the item from Source
        }
    }
}

// moveOptionsUp
//
// move the selected options up one location in the select list
//
function moveOptionsUp(sourceControl)
{
    var selectList = $(sourceControl);
    var selectOptions = selectList.getElementsByTagName('option');
    for (var i = 1; i < selectOptions.length; i++)
    {
        var opt = selectOptions[i];
        if (opt.selected)
        {
            selectList.removeChild(opt);
            selectList.insertBefore(opt, selectOptions[i - 1]);
        }
     }
}

// moveOptionsDown
//
// move the selected options down one location in the select list
//

function moveOptionsDown(sourceControl)
{
    var selectList = $(sourceControl);
    var selectOptions = selectList.getElementsByTagName('option');
    for (var i = selectOptions.length - 2; i >= 0; i--)
    { 
        var opt = selectOptions[i];
        if (opt.selected)
        {
            var nextOpt = selectOptions[i + 1];   
            opt = selectList.removeChild(opt); 
            nextOpt = selectList.replaceChild(opt, nextOpt); 
            selectList.insertBefore(nextOpt, opt);
         } 
     }
}
");
        }