protected override void OnPreRender(EventArgs e)
        {
            Page.RegisterRequiresPostBack(this);

            if (string.IsNullOrEmpty(SelectedTab) && _Tabs.Count > 0)
            {
                SelectedTab = _Tabs[0].TabPageClientId;
            }

            // Persist our selection into a hidden var since it's all client side
            // Script updates this var
            ClientScriptProxy.RegisterHiddenField(this, HIDDEN_FORMVAR_PREFIX + ClientID, SelectedTab);

            string script =
                @"
function ActivateTab(tabId, num)
{
    var _Tabs = eval(tabId);
    if (_Tabs.onActivate && _Tabs.onActivate(num))
        return; 
   
    if (typeof(num)=='string') {
        for(var x=0; x< _Tabs.length; x++) {
            if (_Tabs[x].pageId == num)
            { num = x; break;}
        }
    }
    if (typeof(num)=='string') num=0;
    var Tab = _Tabs[num];
    for(var i=0; i<_Tabs.length; i++) {
        var t = _Tabs[i];
        document.getElementById(t.tabId).className = (t.enabled ? '" + TabCssClass + "' : '" + DisabledTabCssClass + @"');
        if (t.pageId)
            document.getElementById(t.pageId).style.display = 'none';
    }
    document.getElementById(Tab.tabId).className = '" + SelectedTabCssClass + @"';
    document.getElementById(Tab.pageId).style.display = '';
    document.getElementById('" + HIDDEN_FORMVAR_PREFIX + ClientID + @"').value=Tab.pageId;
}
";

            // Register only once per page
            ClientScriptProxy.RegisterClientScriptBlock(this, typeof(WebResources), "ActivateTab", script, true);


            StringBuilder sb = new StringBuilder(2048);

            sb.AppendFormat("var {0} = [];\r\n", ClientID);
            for (int i = 0; i < TabPages.Count; i++)
            {
                string  iStr = i.ToString();
                TabPage tab  = TabPages[i];
                sb.Append(ClientID + "[" + iStr + "] = { id: " + iStr + "," +
                          "tabId: '" + ClientID + "_" + iStr + "'," +
                          "pageId: '" + tab.TabPageClientId + "'," +
                          "enabled: " + tab.Enabled.ToString().ToLower() + "};\r\n");
            }

            ClientScriptProxy.RegisterClientScriptBlock(this, typeof(WebResources), "TabInit_" + ClientID, sb.ToString(), true);


            // Force the page to show the Selected Tab
            if (SelectedTab != "")
            {
                script = "ActivateTab('" + ClientID + "','" + SelectedTab + "');\r\n";
                ClientScriptProxy.RegisterStartupScript(this, typeof(WebResources), "TabStartup_" + ClientID, script, true);
            }

            base.OnPreRender(e);
        }
        /// <summary>
        /// Most of the work happens here for generating the hook up script code
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            // MS AJAX aware script management
            ClientScriptProxy scriptProxy = ClientScriptProxy.Current;

            // Register resources
            RegisterResources(scriptProxy);

            string dateFormat = DateFormat;

            if (string.IsNullOrEmpty(dateFormat) || dateFormat == "Auto")
            {
                // Try to create a data format string from culture settings
                // this code will fail if culture can't be mapped on server hence the empty try/catch
                try
                {
                    dateFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
                }
                catch { }
            }

            dateFormat = dateFormat.ToLower().Replace("yyyy", "yy");

            // Capture and map the various option parameters
            StringBuilder sbOptions = new StringBuilder(512);

            sbOptions.Append("{");

            string onSelect = OnClientSelect;

            if (DisplayMode == DatePickerDisplayModes.Button)
            {
                sbOptions.Append("showOn: 'button',");
            }
            else if (DisplayMode == DatePickerDisplayModes.ImageButton)
            {
                string img = ButtonImage;
                if (img == "WebResource")
                {
                    img = scriptProxy.GetWebResourceUrl(this, typeof(WebResources), WebResources.CALENDAR_ICON_RESOURCE);
                }
                else
                {
                    img = ResolveUrl(ButtonImage);
                }

                sbOptions.Append("showOn: 'button', buttonImageOnly: true, buttonImage: '" + img + "',buttonText: 'Select date',");
            }
            else if (DisplayMode == DatePickerDisplayModes.Inline)
            {
                // need to store selection in the page somehow for inline since it's
                // not tied to a textbox
                scriptProxy.RegisterHiddenField(this, ClientID, Text);
                onSelect = ClientID + "OnSelect";
            }

            if (!string.IsNullOrEmpty(onSelect))
            {
                sbOptions.Append("onSelect: " + onSelect + ",");
            }

            if (DisplayMode != DatePickerDisplayModes.Inline)
            {
                if (!string.IsNullOrEmpty(OnClientBeforeShow))
                {
                    sbOptions.Append("beforeShow: function(y,z) { $('#ui-datepicker-div').maxZIndex(); " +
                                     OnClientBeforeShow + "(y,z); },");
                }
                else
                {
                    sbOptions.Append("beforeShow: function() { $('#ui-datepicker-div').maxZIndex(); },");
                }
            }

            if (MaxDate.HasValue)
            {
                sbOptions.Append("maxDate: " + WebUtils.EncodeJsDate(MaxDate.Value) + ",");
            }

            if (MinDate.HasValue)
            {
                sbOptions.Append("minDate: " + WebUtils.EncodeJsDate(MinDate.Value) + ",");
            }

            if (ShowButtonPanel)
            {
                sbOptions.Append("showButtonPanel: true,");
            }

            sbOptions.Append("dateFormat: '" + dateFormat + "'}");


            // Write out initilization code for calendar
            StringBuilder sbStartupScript = new StringBuilder(400);

            sbStartupScript.AppendLine("$( function() {");


            if (DisplayMode != DatePickerDisplayModes.Inline)
            {
                scriptProxy.RegisterClientScriptBlock(Page,
                                                      typeof(WebResources),
                                                      "__attachDatePickerInputKeys",
                                                      AttachDatePickerKeysScript, true);

                sbStartupScript.AppendFormat("var cal = jQuery('#{0}').datepicker({1}).attachDatepickerInputKeys();\r\n",
                                             ClientID, sbOptions);
            }
            else
            {
                sbStartupScript.AppendLine("var cal = jQuery('#" + ClientID + "Div').datepicker(" + sbOptions.ToString() + ")");

                if (SelectedDate.HasValue && SelectedDate.Value > new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc))
                {
                    WestwindJsonSerializer ser = new WestwindJsonSerializer();
                    ser.DateSerializationMode = JsonDateEncodingModes.NewDateExpression;
                    string jsDate = ser.Serialize(SelectedDate);

                    sbStartupScript.AppendLine("cal.datepicker('setDate'," + jsDate + ");");
                }
                else
                {
                    sbStartupScript.AppendLine("cal.datepicker('setDate',new Date());");
                }

                // Assign value to hidden form var on selection
                scriptProxy.RegisterStartupScript(this, typeof(WebResources), UniqueID + "OnSelect",
                                                  "function  " + ClientID + "OnSelect(dateStr) {\r\n" +
                                                  ((!string.IsNullOrEmpty(OnClientSelect)) ? OnClientSelect + "(dateStr);\r\n" : "") +
                                                  "jQuery('#" + ClientID + "')[0].value = dateStr;\r\n}\r\n", true);
            }

            sbStartupScript.AppendLine("} );");
            scriptProxy.RegisterStartupScript(Page, typeof(WebResources), "_cal" + UniqueID,
                                              sbStartupScript.ToString(), true);
        }