Index: D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/core/src/com/icesoft/faces/context/DOMContext.java
===================================================================
--- D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/core/src/com/icesoft/faces/context/DOMContext.java	(revision 16406)
+++ D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/core/src/com/icesoft/faces/context/DOMContext.java	(working copy)
@@ -36,9 +36,17 @@
  */
 package com.icesoft.faces.context;
 
-import com.icesoft.faces.util.HalterDump;
-import com.icesoft.faces.webapp.http.common.Configuration;
-import com.icesoft.faces.webapp.http.common.ConfigurationException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -47,15 +55,10 @@
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Text;
 
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import com.icesoft.faces.renderkit.dom_html_basic.HTML;
+import com.icesoft.faces.util.HalterDump;
+import com.icesoft.faces.webapp.http.common.Configuration;
+import com.icesoft.faces.webapp.http.common.ConfigurationException;
 
 /**
  * <p><strong>DOMContext</strong> provides a component specific interface to the
@@ -408,8 +411,27 @@
         }
         return foundItems;
     }
-
-
+    
+    public static boolean hasChildWithName(Element root, String name, String tagName){
+    	NodeList list = root.getElementsByTagName(tagName);
+    	for( int i = 0 ; i < list.getLength() ; i++ ){
+    		if(((Element)list.item(i)).getAttribute("name").equalsIgnoreCase(name))
+    			return true;
+    	}
+    	return false;
+    }
+    
+    public Element createHiddenField(Element parent, String name){
+    	Element hiddenField = this.createElement(HTML.INPUT_ELEM);
+		hiddenField
+				.setAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN);
+		hiddenField.setAttribute(HTML.NAME_ATTR, name);
+		parent.appendChild(hiddenField);
+		return hiddenField;
+    }
+    
+    
+   
     private HashMap halterDumps = new HashMap();
 
     /**
Index: D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/core/src/com/icesoft/faces/renderkit/dom_html_basic/FormRenderer.java
===================================================================
--- D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/core/src/com/icesoft/faces/renderkit/dom_html_basic/FormRenderer.java	(revision 16406)
+++ D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/core/src/com/icesoft/faces/renderkit/dom_html_basic/FormRenderer.java	(working copy)
@@ -33,22 +33,25 @@
 
 package com.icesoft.faces.renderkit.dom_html_basic;
 
-import com.icesoft.faces.context.DOMContext;
-import com.icesoft.faces.context.effects.CurrentStyle;
-import com.icesoft.util.SeamUtilities;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Element;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 import javax.faces.FacesException;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIForm;
 import javax.faces.context.FacesContext;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Element;
+
+import com.icesoft.faces.context.DOMContext;
+import com.icesoft.faces.context.effects.CurrentStyle;
+import com.icesoft.util.SeamUtilities;
+
 public class FormRenderer extends DomBasicRenderer {
 
     public static final String COMMAND_LINK_HIDDEN_FIELD =
@@ -278,15 +281,19 @@
             FacesContext facesContext, Map map) {
         DOMContext domContext =
                 DOMContext.getDOMContext(facesContext, uiComponent);
+        
         Element root = (Element) domContext.getRootNode();
         Iterator commandLinkFields = map.entrySet().iterator();
         while (commandLinkFields.hasNext()) {
             Map.Entry nextField = (Map.Entry) commandLinkFields.next();
             if (COMMAND_LINK_HIDDEN_FIELD.equals(nextField.getValue())) {
-                Element next = domContext.createElement("input");
-                next.setAttribute("type", "hidden");
-                next.setAttribute("name", nextField.getKey().toString());
-                root.appendChild(next);
+            	if( !DOMContext.hasChildWithName(root, nextField.getKey().toString(), "input") ){
+            		Element next = domContext.createElement("input");
+                    next.setAttribute("type", "hidden");
+                    next.setAttribute("name", nextField.getKey().toString());
+                    root.appendChild(next);
+            	}
+                
             }
         }
     }
Index: D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/tree/TreeRenderer.java
===================================================================
--- D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/tree/TreeRenderer.java	(revision 16406)
+++ D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/tree/TreeRenderer.java	(working copy)
@@ -152,22 +152,7 @@
             return;
         }
 
-        // set up form fields
-        FormRenderer.addHiddenField(facesContext,
-                                    CustomComponentUtils.getHiddenTreeExpandFieldName(
-                                            uiComponent.getClientId(
-                                                    facesContext),
-                                            CustomComponentUtils.getFormName(
-                                                    uiComponent,
-                                                    facesContext)));
-        FormRenderer.addHiddenField(facesContext,
-                                    CustomComponentUtils.getHiddenTreeActionFieldName(
-                                            uiComponent.getClientId(
-                                                    facesContext),
-                                            CustomComponentUtils.getFormName(
-                                                    uiComponent,
-                                                    facesContext)));
-
+       
         // encode the root DIV
         if (!domContext.isInitialized()) {
             Element rootDOMNode = domContext.createRootElement(HTML.DIV_ELEM);
@@ -176,7 +161,7 @@
         }
         // get the root node
         Element rootDomNode = (Element) domContext.getRootNode();
-
+        
         // Apply  default styleClass and style to the root node.
         rootDomNode
                 .setAttribute(HTML.CLASS_ATTR, treeComponent.getStyleClass());
@@ -188,7 +173,25 @@
 
         // clean up, and remove nodes
         DOMContext.removeChildren(rootDomNode);
+        
+     // set up form fields
+        domContext.createHiddenField(rootDomNode, CustomComponentUtils.getHiddenTreeExpandFieldName(
+                uiComponent.getClientId(
+                        facesContext),
+                CustomComponentUtils.getFormName(
+                        uiComponent,
+                        facesContext)));
+        
+        domContext.createHiddenField(rootDomNode, 
+                CustomComponentUtils.getHiddenTreeActionFieldName(
+                        uiComponent.getClientId(
+                                facesContext),
+                        CustomComponentUtils.getFormName(
+                                uiComponent,
+                                facesContext)));
 
+        
+
         if (PassThruAttributeRenderer.passThruAttributeExists(uiComponent)) {
             PassThruAttributeRenderer
                     .renderAttributes(facesContext, uiComponent, null);
Index: D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/panelcollapsible/PanelCollapsibleRenderer.java
===================================================================
--- D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/panelcollapsible/PanelCollapsibleRenderer.java	(revision 16406)
+++ D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/panelcollapsible/PanelCollapsibleRenderer.java	(working copy)
@@ -55,7 +55,7 @@
         //add click handler if not disabled and toggleOnClick is set to true
         if (panelCollapsible.isToggleOnClick() && 
         		!panelCollapsible.isDisabled()) {
-            FormRenderer.addHiddenField(facesContext, uiComponent.getClientId(facesContext)+ "Expanded");
+            domContext.createHiddenField(root, uiComponent.getClientId(facesContext)+ "Expanded");
             UIComponent form = findForm(uiComponent);
             if(form == null) {
                 throw new FacesException("PanelCollapsible must be contained within a form");                
Index: D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/panelcollapsible/PanelCollapsible.java
===================================================================
--- D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/panelcollapsible/PanelCollapsible.java	(revision 16406)
+++ D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/panelcollapsible/PanelCollapsible.java	(working copy)
@@ -220,8 +220,9 @@
          if(headerFacet != null){
          	headerFacet.processDecodes(context);
          }
+         decode(context);
   	   }
-  	   decode(context);
+  	   
      }
 
      /* (non-Javadoc)
Index: D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/selectinputdate/SelectInputDateRenderer.java
===================================================================
--- D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/selectinputdate/SelectInputDateRenderer.java	(revision 16406)
+++ D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/selectinputdate/SelectInputDateRenderer.java	(working copy)
@@ -87,1246 +87,1250 @@
 import java.util.regex.Pattern;
 
 /**
- * <p> The SelectInputDateRenderer class is an ICEfaces D2D renderer for the
+ * <p>
+ * The SelectInputDateRenderer class is an ICEfaces D2D renderer for the
  * SelectInputDate component. Note: This class originally was derived from the
- * MyFaces Calendar.</p>
+ * MyFaces Calendar.
+ * </p>
  */
-public class SelectInputDateRenderer
-        extends DomBasicInputRenderer {
-    //	add a static log member
-    private static final Log log =
-            LogFactory.getLog(SelectInputDateRenderer.class);
+public class SelectInputDateRenderer extends DomBasicInputRenderer {
+	// add a static log member
+	private static final Log log = LogFactory
+			.getLog(SelectInputDateRenderer.class);
 
-    private static final String CALENDAR_TABLE = "_calendarTable";
-    private static final String CALENDAR_BUTTON = "_calendarButton";
-    private static final String CALENDAR_POPUP = "_calendarPopup";
-    private static final String HIDDEN_FIELD_NAME = "showPopup";
-    private static final String DATE_SELECTED = "dateSelected";
+	private static final String CALENDAR_TABLE = "_calendarTable";
+	private static final String CALENDAR_BUTTON = "_calendarButton";
+	private static final String CALENDAR_POPUP = "_calendarPopup";
+	private static final String HIDDEN_FIELD_NAME = "showPopup";
+	private static final String DATE_SELECTED = "dateSelected";
 
-    // constants for navigation link ids
-    private static final String PREV_MONTH = "_prevmo";
-    private static final String NEXT_MONTH = "_nextmo";
-    private static final String PREV_YEAR = "_prevyr";
-    private static final String NEXT_YEAR = "_nextyr";
+	// constants for navigation link ids
+	private static final String PREV_MONTH = "_prevmo";
+	private static final String NEXT_MONTH = "_nextmo";
+	private static final String PREV_YEAR = "_prevyr";
+	private static final String NEXT_YEAR = "_nextyr";
 
-    // constant for selectinputdate links
-    private static final String CALENDAR = "_calendar";
-    
-    private static final String INPUT_TEXT_TITLE =
-        "com.icesoft.faces.component.selectinputdate.INPUT_TEXT_TITLE";
-    private static final String CALENDAR_TITLE =
-        "com.icesoft.faces.component.selectinputdate.CALENDAR_TITLE";
-    private static final String CALENDAR_SUMMARY =
-        "com.icesoft.faces.component.selectinputdate.CALENDAR_SUMMARY";
-    private static final String POPUP_CALENDAR_TITLE =
-        "com.icesoft.faces.component.selectinputdate.POPUP_CALENDAR_TITLE";
-    private static final String POPUP_CALENDAR_SUMMARY =
-        "com.icesoft.faces.component.selectinputdate.POPUP_CALENDAR_SUMMARY";
-    private static final String YEAR_MONTH_SUMMARY =
-        "com.icesoft.faces.component.selectinputdate.YEAR_MONTH_SUMMARY";
-    private static final String OPEN_POPUP_ALT =
-        "com.icesoft.faces.component.selectinputdate.OPEN_POPUP_ALT";
-    private static final String OPEN_POPUP_TITLE =
-        "com.icesoft.faces.component.selectinputdate.OPEN_POPUP_TITLE";
-    private static final String CLOSE_POPUP_ALT =
-        "com.icesoft.faces.component.selectinputdate.CLOSE_POPUP_ALT";
-    private static final String CLOSE_POPUP_TITLE =
-        "com.icesoft.faces.component.selectinputdate.CLOSE_POPUP_TITLE";
-    private static final String PREV_YEAR_ALT =
-        "com.icesoft.faces.component.selectinputdate.PREV_YEAR_ALT";
-    private static final String PREV_YEAR_TITLE =
-        "com.icesoft.faces.component.selectinputdate.PREV_YEAR_TITLE";
-    private static final String NEXT_YEAR_ALT =
-        "com.icesoft.faces.component.selectinputdate.NEXT_YEAR_ALT";
-    private static final String NEXT_YEAR_TITLE =
-        "com.icesoft.faces.component.selectinputdate.NEXT_YEAR_TITLE";
-    private static final String PREV_MONTH_ALT =
-        "com.icesoft.faces.component.selectinputdate.PREV_MONTH_ALT";
-    private static final String PREV_MONTH_TITLE =
-        "com.icesoft.faces.component.selectinputdate.PREV_MONTH_TITLE";
-    private static final String NEXT_MONTH_ALT =
-        "com.icesoft.faces.component.selectinputdate.NEXT_MONTH_ALT";
-    private static final String NEXT_MONTH_TITLE =
-        "com.icesoft.faces.component.selectinputdate.NEXT_MONTH_TITLE";
+	// constant for selectinputdate links
+	private static final String CALENDAR = "_calendar";
 
-    /* (non-Javadoc)
-    * @see javax.faces.render.Renderer#getRendersChildren()
-    */
-    public boolean getRendersChildren() {
+	private static final String INPUT_TEXT_TITLE = "com.icesoft.faces.component.selectinputdate.INPUT_TEXT_TITLE";
+	private static final String CALENDAR_TITLE = "com.icesoft.faces.component.selectinputdate.CALENDAR_TITLE";
+	private static final String CALENDAR_SUMMARY = "com.icesoft.faces.component.selectinputdate.CALENDAR_SUMMARY";
+	private static final String POPUP_CALENDAR_TITLE = "com.icesoft.faces.component.selectinputdate.POPUP_CALENDAR_TITLE";
+	private static final String POPUP_CALENDAR_SUMMARY = "com.icesoft.faces.component.selectinputdate.POPUP_CALENDAR_SUMMARY";
+	private static final String YEAR_MONTH_SUMMARY = "com.icesoft.faces.component.selectinputdate.YEAR_MONTH_SUMMARY";
+	private static final String OPEN_POPUP_ALT = "com.icesoft.faces.component.selectinputdate.OPEN_POPUP_ALT";
+	private static final String OPEN_POPUP_TITLE = "com.icesoft.faces.component.selectinputdate.OPEN_POPUP_TITLE";
+	private static final String CLOSE_POPUP_ALT = "com.icesoft.faces.component.selectinputdate.CLOSE_POPUP_ALT";
+	private static final String CLOSE_POPUP_TITLE = "com.icesoft.faces.component.selectinputdate.CLOSE_POPUP_TITLE";
+	private static final String PREV_YEAR_ALT = "com.icesoft.faces.component.selectinputdate.PREV_YEAR_ALT";
+	private static final String PREV_YEAR_TITLE = "com.icesoft.faces.component.selectinputdate.PREV_YEAR_TITLE";
+	private static final String NEXT_YEAR_ALT = "com.icesoft.faces.component.selectinputdate.NEXT_YEAR_ALT";
+	private static final String NEXT_YEAR_TITLE = "com.icesoft.faces.component.selectinputdate.NEXT_YEAR_TITLE";
+	private static final String PREV_MONTH_ALT = "com.icesoft.faces.component.selectinputdate.PREV_MONTH_ALT";
+	private static final String PREV_MONTH_TITLE = "com.icesoft.faces.component.selectinputdate.PREV_MONTH_TITLE";
+	private static final String NEXT_MONTH_ALT = "com.icesoft.faces.component.selectinputdate.NEXT_MONTH_ALT";
+	private static final String NEXT_MONTH_TITLE = "com.icesoft.faces.component.selectinputdate.NEXT_MONTH_TITLE";
 
-        return true;
-    }
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.faces.render.Renderer#getRendersChildren()
+	 */
+	public boolean getRendersChildren() {
 
-    /* (non-Javadoc)
-     * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
-     */
-    public void encodeChildren(FacesContext facesContext,
-                               UIComponent uiComponent) {
+		return true;
+	}
 
-    }
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext,
+	 *      javax.faces.component.UIComponent)
+	 */
+	public void encodeChildren(FacesContext facesContext,
+			UIComponent uiComponent) {
 
-    private String getHiddenFieldName(FacesContext facesContext,
-                                      UIComponent uiComponent) {
-        UIComponent form = findForm(uiComponent);
-        String formId = form.getClientId(facesContext);
-        String clientId = uiComponent.getClientId(facesContext);
-        String hiddenFieldName = formId
-                                 + NamingContainer.SEPARATOR_CHAR
-                                 + UIViewRoot.UNIQUE_ID_PREFIX
-                                 + clientId
-                                 + HIDDEN_FIELD_NAME;
-        return hiddenFieldName;
-    }
+	}
 
-    /* (non-Javadoc)
-     * @see com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
-     */
-    public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
-            throws IOException {
-        validateParameters(facesContext, uiComponent, SelectInputDate.class);
-        DOMContext domContext =
-                DOMContext.attachDOMContext(facesContext, uiComponent);
-        SelectInputDate selectInputDate = (SelectInputDate) uiComponent;
+	private String getHiddenFieldName(FacesContext facesContext,
+			UIComponent uiComponent) {
+		UIComponent form = findForm(uiComponent);
+		String formId = form.getClientId(facesContext);
+		String clientId = uiComponent.getClientId(facesContext);
+		String hiddenFieldName = formId + NamingContainer.SEPARATOR_CHAR
+				+ UIViewRoot.UNIQUE_ID_PREFIX + clientId + HIDDEN_FIELD_NAME;
+		return hiddenFieldName;
+	}
 
-        // get the parentForm
-        UIComponent parentForm = findForm(selectInputDate);
-        // if there is no parent form - ERROR
-        if (parentForm == null) {
-            log.error("SelectInputDate::must be in a FORM");
-            return;
-        }
-        String clientId;
-        if (!domContext.isInitialized()) {
-            Element root = domContext.createRootElement(HTML.DIV_ELEM);
-            boolean popupState = selectInputDate.isShowPopup();
-            
-            setRootElementId(facesContext, root, uiComponent);
-            clientId = uiComponent.getClientId(facesContext);
-            if (selectInputDate.isRenderAsPopup()) {
-                if (log.isTraceEnabled()) {
-                    log.trace("Render as popup");
-                }
-                // ICE-2492
-                root.setAttribute(HTML.CLASS_ATTR,
-                        Util.getQualifiedStyleClass(uiComponent, CSS_DEFAULT.DEFAULT_CALENDARPOPUP_CLASS, false));
-                Element dateText = domContext.createElement(HTML.INPUT_ELEM);
-//System.out.println("value: " + selectInputDate.getValue());
-                
-                dateText.setAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_TEXT); // ICE-2302
-                dateText.setAttribute(HTML.VALUE_ATTR,
-                                      selectInputDate.getTextToRender());
-                dateText.setAttribute(HTML.ID_ATTR,
-                                      clientId + SelectInputDate.CALENDAR_INPUTTEXT);
-                dateText.setAttribute(HTML.NAME_ATTR,
-                                      clientId + SelectInputDate.CALENDAR_INPUTTEXT);
-                dateText.setAttribute(HTML.CLASS_ATTR,
-                                      selectInputDate.getCalendarInputClass());
-                dateText.setAttribute(HTML.ONFOCUS_ATTR, "setFocus('');");
-                dateText.setAttribute("onkeypress", this.ICESUBMIT);
-                dateText.setAttribute(HTML.ONBLUR_ATTR, "setFocus('');"+ this.ICESUBMITPARTIAL);
-                if (selectInputDate.getAutocomplete() != null) {
-                    dateText.setAttribute("autocomplete",
-                                          selectInputDate.getAutocomplete());
-                }
-                String tooltip = null;
-                tooltip = selectInputDate.getTitle();
-                if(tooltip == null || tooltip.length() == 0) {
-                    // extract the popupdate format and use it as a tooltip
-                    tooltip = getMessageWithParamFromResource(
-                        facesContext, INPUT_TEXT_TITLE,
-                        selectInputDate.getSpecifiedPopupDateFormat());
-                }
-                if(tooltip != null && tooltip.length() > 0) {
-                    dateText.setAttribute(HTML.TITLE_ATTR, tooltip);
-                }
-                if (selectInputDate.isDisabled()) {
-                    dateText.setAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR);
-                }
-                root.appendChild(dateText);
-                Element calendarButton =
-                        domContext.createElement(HTML.INPUT_ELEM);
-                calendarButton
-                        .setAttribute(HTML.ID_ATTR, clientId + CALENDAR_BUTTON);
-                calendarButton.setAttribute(HTML.NAME_ATTR,
-                                            clientId + CALENDAR_BUTTON);
-                calendarButton.setAttribute(HTML.TYPE_ATTR, "image");
-                calendarButton.setAttribute(HTML.ONFOCUS_ATTR, "setFocus('');");
-                // render onclick to set value of hidden field to true
-                String onClick = "document.forms['" +
-                                 parentForm.getClientId(facesContext) + "']['" +
-                                 this.getLinkId(facesContext, uiComponent) +
-                                 "'].value='" + clientId + CALENDAR_BUTTON +
-                                 "';"
-                                 + "document.forms['" +
-                                 parentForm.getClientId(facesContext) + "']['" +
-                                 getHiddenFieldName(facesContext, uiComponent) +
-                                 "'].value='toggle';"
-                                 + "iceSubmitPartial( document.forms['" +
-                                 parentForm.getClientId(facesContext) +
-                                 "'], this,event); return false;";
-                calendarButton.setAttribute(HTML.ONCLICK_ATTR, onClick);
-                if (selectInputDate.isDisabled()) {
-                    calendarButton.setAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR);
-                }
-                root.appendChild(calendarButton);
-                // render a hidden field to manage the popup state; visible || hidden
-                FormRenderer.addHiddenField(facesContext, getHiddenFieldName(
-                        facesContext, uiComponent));
-                String resolvedSrc;
-                if (popupState) {
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer#encodeEnd(javax.faces.context.FacesContext,
+	 *      javax.faces.component.UIComponent)
+	 */
+	public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
+			throws IOException {
+		validateParameters(facesContext, uiComponent, SelectInputDate.class);
+		DOMContext domContext = DOMContext.attachDOMContext(facesContext,
+				uiComponent);
+		SelectInputDate selectInputDate = (SelectInputDate) uiComponent;
 
-                    if (selectInputDate.isImageDirSet()) {
-                        resolvedSrc = CoreUtils.resolveResourceURL(facesContext,
-                                selectInputDate.getImageDir() + selectInputDate.getClosePopupImage());
-                    } else {
-                        // ICE-2127: allow override of button images via CSS
-                        calendarButton.setAttribute(HTML.CLASS_ATTR, selectInputDate.getClosePopupClass());
-                        // without this Firefox would display a default text on top of the image
-                        resolvedSrc = CoreUtils.resolveResourceURL(facesContext,
-                                selectInputDate.getImageDir() + "spacer.gif");
-                    }
-                    calendarButton.setAttribute(HTML.SRC_ATTR, resolvedSrc );
-                    addAttributeToElementFromResource(facesContext,
-                        CLOSE_POPUP_ALT, calendarButton, HTML.ALT_ATTR);
-                    addAttributeToElementFromResource(facesContext,
-                        CLOSE_POPUP_TITLE, calendarButton, HTML.TITLE_ATTR);
-                } else {
-                    if (selectInputDate.isImageDirSet()) {
-                        resolvedSrc = CoreUtils.resolveResourceURL(facesContext,
-                                selectInputDate.getImageDir() + selectInputDate.getOpenPopupImage());
-                    } else {
-                        // ICE-2127: allow override of button images via CSS
-                        calendarButton.setAttribute(HTML.CLASS_ATTR, selectInputDate.getOpenPopupClass());
-                        // without this Firefox would display a default text on top of the image
-                        resolvedSrc = CoreUtils.resolveResourceURL(facesContext,
-                                selectInputDate.getImageDir() + "spacer.gif");
-                    }
-                    calendarButton.setAttribute(HTML.SRC_ATTR, resolvedSrc );
-                    addAttributeToElementFromResource(facesContext,
-                        OPEN_POPUP_ALT, calendarButton, HTML.ALT_ATTR);
-                    addAttributeToElementFromResource(facesContext,
-                        OPEN_POPUP_TITLE, calendarButton, HTML.TITLE_ATTR);
-                    FormRenderer.addHiddenField(
-                        facesContext,
-                        parentForm.getClientId(facesContext)+ ":_idcl");
-                    PassThruAttributeRenderer.renderAttributes(
-                        facesContext, uiComponent, new String[] {"title"});
-                    domContext.stepOver();
-                    return ;
-                }
-                
-                if (!domContext.isStreamWriting()) {
-                    Text br = domContext.createTextNode("<br/>");
-                    root.appendChild(br);
-                }
-                
-                Element calendarDiv = domContext.createElement(HTML.DIV_ELEM);
-                calendarDiv
-                        .setAttribute(HTML.ID_ATTR, clientId + CALENDAR_POPUP);
-                calendarDiv.setAttribute(HTML.NAME_ATTR,
-                                         clientId + CALENDAR_POPUP);
-                calendarDiv.setAttribute(HTML.STYLE_ELEM,
-                          "position:absolute;z-index:10;");
-                addAttributeToElementFromResource(facesContext,
-                    POPUP_CALENDAR_TITLE, calendarDiv, HTML.TITLE_ATTR);
-                Element table = domContext.createElement(HTML.TABLE_ELEM);
-                table.setAttribute(HTML.ID_ATTR, clientId + CALENDAR_TABLE);
-                table.setAttribute(HTML.NAME_ATTR, clientId + CALENDAR_TABLE);
-                table.setAttribute(HTML.CLASS_ATTR,
-                                   selectInputDate.getStyleClass());
-                table.setAttribute(HTML.STYLE_ATTR, "position:absolute;");                 
-                table.setAttribute(HTML.CELLPADDING_ATTR, "0");
-                table.setAttribute(HTML.CELLSPACING_ATTR, "0");
-                // set mouse events on table bug 372
-                String mouseOver = selectInputDate.getOnmouseover();
-                table.setAttribute(HTML.ONMOUSEOVER_ATTR, mouseOver);
-                String mouseOut = selectInputDate.getOnmouseout();
-                table.setAttribute(HTML.ONMOUSEOUT_ATTR, mouseOut);
-                String mouseMove = selectInputDate.getOnmousemove();
-                table.setAttribute(HTML.ONMOUSEMOVE_ATTR, mouseMove);
-                addAttributeToElementFromResource(facesContext,
-                    POPUP_CALENDAR_SUMMARY, table, HTML.SUMMARY_ATTR);
-                calendarDiv.appendChild(table);
-                Text iframe = domContext.createTextNode("<!--[if lte IE"+
-                        " 6.5]><iframe src='"+ CoreUtils.resolveResourceURL
-                        (FacesContext.getCurrentInstance(),"/xmlhttp/blank")+ 
-                        "' class=\"iceSelInpDateIFrameFix\"></iframe><![endif]-->");
-                calendarDiv.appendChild(iframe);                 
-                root.appendChild(calendarDiv);
+		// get the parentForm
+		UIComponent parentForm = findForm(selectInputDate);
+		// if there is no parent form - ERROR
+		if (parentForm == null) {
+			log.error("SelectInputDate::must be in a FORM");
+			return;
+		}
+		String clientId;
+		if (!domContext.isInitialized()) {
+			Element root = domContext.createRootElement(HTML.DIV_ELEM);
+			boolean popupState = selectInputDate.isShowPopup();
 
-            } else {
-                if (log.isTraceEnabled()) {
-                    log.trace("Select input Date Normal");
-                }
-                Element table = domContext.createElement(HTML.TABLE_ELEM);
-                table.setAttribute(HTML.ID_ATTR, clientId + CALENDAR_TABLE);
-                table.setAttribute(HTML.NAME_ATTR, clientId + CALENDAR_TABLE);
-                table.setAttribute(HTML.CLASS_ATTR,
-                                   selectInputDate.getStyleClass());
-                addAttributeToElementFromResource(facesContext,
-                    CALENDAR_TITLE, table, HTML.TITLE_ATTR);
-                table.setAttribute(HTML.CELLPADDING_ATTR, "0");
-                table.setAttribute(HTML.CELLSPACING_ATTR, "0");
-                // set mouse events on table bug 372
-                String mouseOver = selectInputDate.getOnmouseover();
-                table.setAttribute(HTML.ONMOUSEOVER_ATTR, mouseOver);
-                String mouseOut = selectInputDate.getOnmouseout();
-                table.setAttribute(HTML.ONMOUSEOUT_ATTR, mouseOut);
-                String mouseMove = selectInputDate.getOnmousemove();
-                table.setAttribute(HTML.ONMOUSEMOVE_ATTR, mouseMove);
-                addAttributeToElementFromResource(facesContext,
-                    CALENDAR_SUMMARY, table, HTML.SUMMARY_ATTR);
-                root.appendChild(table);
-            }
-        }
-        clientId = uiComponent.getClientId(facesContext);
+			setRootElementId(facesContext, root, uiComponent);
+			clientId = uiComponent.getClientId(facesContext);
+			if (selectInputDate.isRenderAsPopup()) {
+				if (log.isTraceEnabled()) {
+					log.trace("Render as popup");
+				}
+				// ICE-2492
+				root.setAttribute(HTML.CLASS_ATTR, Util.getQualifiedStyleClass(
+						uiComponent, CSS_DEFAULT.DEFAULT_CALENDARPOPUP_CLASS,
+						false));
+				Element dateText = domContext.createElement(HTML.INPUT_ELEM);
+				// System.out.println("value: " + selectInputDate.getValue());
 
-        Date value;
+				dateText.setAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_TEXT); // ICE-2302
+				dateText.setAttribute(HTML.VALUE_ATTR, selectInputDate
+						.getTextToRender());
+				dateText.setAttribute(HTML.ID_ATTR, clientId
+						+ SelectInputDate.CALENDAR_INPUTTEXT);
+				dateText.setAttribute(HTML.NAME_ATTR, clientId
+						+ SelectInputDate.CALENDAR_INPUTTEXT);
+				dateText.setAttribute(HTML.CLASS_ATTR, selectInputDate
+						.getCalendarInputClass());
+				dateText.setAttribute(HTML.ONFOCUS_ATTR, "setFocus('');");
+				dateText.setAttribute("onkeypress", this.ICESUBMIT);
+				dateText.setAttribute(HTML.ONBLUR_ATTR, "setFocus('');"
+						+ this.ICESUBMITPARTIAL);
+				if (selectInputDate.getAutocomplete() != null) {
+					dateText.setAttribute("autocomplete", selectInputDate
+							.getAutocomplete());
+				}
+				String tooltip = null;
+				tooltip = selectInputDate.getTitle();
+				if (tooltip == null || tooltip.length() == 0) {
+					// extract the popupdate format and use it as a tooltip
+					tooltip = getMessageWithParamFromResource(facesContext,
+							INPUT_TEXT_TITLE, selectInputDate
+									.getSpecifiedPopupDateFormat());
+				}
+				if (tooltip != null && tooltip.length() > 0) {
+					dateText.setAttribute(HTML.TITLE_ATTR, tooltip);
+				}
+				if (selectInputDate.isDisabled()) {
+					dateText.setAttribute(HTML.DISABLED_ATTR,
+							HTML.DISABLED_ATTR);
+				}
+				root.appendChild(dateText);
+				Element calendarButton = domContext
+						.createElement(HTML.INPUT_ELEM);
+				calendarButton.setAttribute(HTML.ID_ATTR, clientId
+						+ CALENDAR_BUTTON);
+				calendarButton.setAttribute(HTML.NAME_ATTR, clientId
+						+ CALENDAR_BUTTON);
+				calendarButton.setAttribute(HTML.TYPE_ATTR, "image");
+				calendarButton.setAttribute(HTML.ONFOCUS_ATTR, "setFocus('');");
+				// render onclick to set value of hidden field to true
+				String onClick = "document.forms['"
+						+ parentForm.getClientId(facesContext) + "']['"
+						+ this.getLinkId(facesContext, uiComponent)
+						+ "'].value='" + clientId + CALENDAR_BUTTON + "';"
+						+ "document.forms['"
+						+ parentForm.getClientId(facesContext) + "']['"
+						+ getHiddenFieldName(facesContext, uiComponent)
+						+ "'].value='toggle';"
+						+ "iceSubmitPartial( document.forms['"
+						+ parentForm.getClientId(facesContext)
+						+ "'], this,event); return false;";
+				calendarButton.setAttribute(HTML.ONCLICK_ATTR, onClick);
+				if (selectInputDate.isDisabled()) {
+					calendarButton.setAttribute(HTML.DISABLED_ATTR,
+							HTML.DISABLED_ATTR);
+				}
+				root.appendChild(calendarButton);
+				// render a hidden field to manage the popup state; visible ||
+				// hidden
+				domContext.createHiddenField(root, getHiddenFieldName(
+						facesContext, uiComponent));
+				
+				String resolvedSrc;
+				if (popupState) {
 
-        if (selectInputDate.isNavEvent()) {
-            if (log.isTraceEnabled()) {
-                log.trace("Rendering Nav Event");
-            }
-            value = selectInputDate.getNavDate();
-//System.out.println("navDate: " + value);
-        } else {
-            if (log.isTraceEnabled()) {
-                log.trace("Logging non nav event");
-            }
-            value = CustomComponentUtils.getDateValue(selectInputDate);
-//System.out.println("CustomComponentUtils.getDateValue: " + value);
-        }
-        
-        TimeZone tz = selectInputDate.resolveTimeZone(facesContext);
-        Locale currentLocale = selectInputDate.resolveLocale(facesContext);
-        
-        Calendar timeKeeper = Calendar.getInstance(tz, currentLocale);
-        timeKeeper.setTime(value != null ? value : new Date());
+					if (selectInputDate.isImageDirSet()) {
+						resolvedSrc = CoreUtils.resolveResourceURL(
+								facesContext, selectInputDate.getImageDir()
+										+ selectInputDate.getClosePopupImage());
+					} else {
+						// ICE-2127: allow override of button images via CSS
+						calendarButton.setAttribute(HTML.CLASS_ATTR,
+								selectInputDate.getClosePopupClass());
+						// without this Firefox would display a default text on
+						// top of the image
+						resolvedSrc = CoreUtils.resolveResourceURL(
+								facesContext, selectInputDate.getImageDir()
+										+ "spacer.gif");
+					}
+					calendarButton.setAttribute(HTML.SRC_ATTR, resolvedSrc);
+					addAttributeToElementFromResource(facesContext,
+							CLOSE_POPUP_ALT, calendarButton, HTML.ALT_ATTR);
+					addAttributeToElementFromResource(facesContext,
+							CLOSE_POPUP_TITLE, calendarButton, HTML.TITLE_ATTR);
+				} else {
+					if (selectInputDate.isImageDirSet()) {
+						resolvedSrc = CoreUtils.resolveResourceURL(
+								facesContext, selectInputDate.getImageDir()
+										+ selectInputDate.getOpenPopupImage());
+					} else {
+						// ICE-2127: allow override of button images via CSS
+						calendarButton.setAttribute(HTML.CLASS_ATTR,
+								selectInputDate.getOpenPopupClass());
+						// without this Firefox would display a default text on
+						// top of the image
+						resolvedSrc = CoreUtils.resolveResourceURL(
+								facesContext, selectInputDate.getImageDir()
+										+ "spacer.gif");
+					}
+					calendarButton.setAttribute(HTML.SRC_ATTR, resolvedSrc);
+					addAttributeToElementFromResource(facesContext,
+							OPEN_POPUP_ALT, calendarButton, HTML.ALT_ATTR);
+					addAttributeToElementFromResource(facesContext,
+							OPEN_POPUP_TITLE, calendarButton, HTML.TITLE_ATTR);
+					FormRenderer.addHiddenField(facesContext, parentForm
+							.getClientId(facesContext)
+							+ ":_idcl");
+					PassThruAttributeRenderer.renderAttributes(facesContext,
+							uiComponent, new String[] { "title" });
+					domContext.stepOver();
+					return;
+				}
 
-        DateFormatSymbols symbols = new DateFormatSymbols(currentLocale);
+				if (!domContext.isStreamWriting()) {
+					Text br = domContext.createTextNode("<br/>");
+					root.appendChild(br);
+				}
 
-        String[] weekdays = mapWeekdays(symbols);
-        String[] weekdaysLong = mapWeekdaysLong(symbols);
-        String[] months = mapMonths(symbols);
+				Element calendarDiv = domContext.createElement(HTML.DIV_ELEM);
+				calendarDiv.setAttribute(HTML.ID_ATTR, clientId
+						+ CALENDAR_POPUP);
+				calendarDiv.setAttribute(HTML.NAME_ATTR, clientId
+						+ CALENDAR_POPUP);
+				calendarDiv.setAttribute(HTML.STYLE_ELEM,
+						"position:absolute;z-index:10;");
+				addAttributeToElementFromResource(facesContext,
+						POPUP_CALENDAR_TITLE, calendarDiv, HTML.TITLE_ATTR);
+				Element table = domContext.createElement(HTML.TABLE_ELEM);
+				table.setAttribute(HTML.ID_ATTR, clientId + CALENDAR_TABLE);
+				table.setAttribute(HTML.NAME_ATTR, clientId + CALENDAR_TABLE);
+				table.setAttribute(HTML.CLASS_ATTR, selectInputDate
+						.getStyleClass());
+				table.setAttribute(HTML.STYLE_ATTR, "position:absolute;");
+				table.setAttribute(HTML.CELLPADDING_ATTR, "0");
+				table.setAttribute(HTML.CELLSPACING_ATTR, "0");
+				// set mouse events on table bug 372
+				String mouseOver = selectInputDate.getOnmouseover();
+				table.setAttribute(HTML.ONMOUSEOVER_ATTR, mouseOver);
+				String mouseOut = selectInputDate.getOnmouseout();
+				table.setAttribute(HTML.ONMOUSEOUT_ATTR, mouseOut);
+				String mouseMove = selectInputDate.getOnmousemove();
+				table.setAttribute(HTML.ONMOUSEMOVE_ATTR, mouseMove);
+				addAttributeToElementFromResource(facesContext,
+						POPUP_CALENDAR_SUMMARY, table, HTML.SUMMARY_ATTR);
+				calendarDiv.appendChild(table);
+				Text iframe = domContext
+						.createTextNode("<!--[if lte IE"
+								+ " 6.5]><iframe src='"
+								+ CoreUtils
+										.resolveResourceURL(FacesContext
+												.getCurrentInstance(),
+												"/xmlhttp/blank")
+								+ "' class=\"iceSelInpDateIFrameFix\"></iframe><![endif]-->");
+				calendarDiv.appendChild(iframe);
+				root.appendChild(calendarDiv);
 
-        // use the currentDay to set focus - do not set
-        int lastDayInMonth = timeKeeper.getActualMaximum(Calendar.DAY_OF_MONTH);
-        int currentDay = timeKeeper.get(Calendar.DAY_OF_MONTH); // starts at 1
+			} else {
+				if (log.isTraceEnabled()) {
+					log.trace("Select input Date Normal");
+				}
+				Element table = domContext.createElement(HTML.TABLE_ELEM);
+				table.setAttribute(HTML.ID_ATTR, clientId + CALENDAR_TABLE);
+				table.setAttribute(HTML.NAME_ATTR, clientId + CALENDAR_TABLE);
+				table.setAttribute(HTML.CLASS_ATTR, selectInputDate
+						.getStyleClass());
+				addAttributeToElementFromResource(facesContext, CALENDAR_TITLE,
+						table, HTML.TITLE_ATTR);
+				table.setAttribute(HTML.CELLPADDING_ATTR, "0");
+				table.setAttribute(HTML.CELLSPACING_ATTR, "0");
+				// set mouse events on table bug 372
+				String mouseOver = selectInputDate.getOnmouseover();
+				table.setAttribute(HTML.ONMOUSEOVER_ATTR, mouseOver);
+				String mouseOut = selectInputDate.getOnmouseout();
+				table.setAttribute(HTML.ONMOUSEOUT_ATTR, mouseOut);
+				String mouseMove = selectInputDate.getOnmousemove();
+				table.setAttribute(HTML.ONMOUSEMOVE_ATTR, mouseMove);
+				addAttributeToElementFromResource(facesContext,
+						CALENDAR_SUMMARY, table, HTML.SUMMARY_ATTR);
+				root.appendChild(table);
+			}
+		}
+		clientId = uiComponent.getClientId(facesContext);
 
-        if (currentDay > lastDayInMonth) {
-            currentDay = lastDayInMonth;
-        }
+		Date value;
 
-        timeKeeper.set(Calendar.DAY_OF_MONTH, 1);
+		if (selectInputDate.isNavEvent()) {
+			if (log.isTraceEnabled()) {
+				log.trace("Rendering Nav Event");
+			}
+			value = selectInputDate.getNavDate();
+			// System.out.println("navDate: " + value);
+		} else {
+			if (log.isTraceEnabled()) {
+				log.trace("Logging non nav event");
+			}
+			value = CustomComponentUtils.getDateValue(selectInputDate);
+			// System.out.println("CustomComponentUtils.getDateValue: " +
+			// value);
+		}
 
-        int weekDayOfFirstDayOfMonth =
-                mapCalendarDayToCommonDay(timeKeeper.get(Calendar.DAY_OF_WEEK));
+		TimeZone tz = selectInputDate.resolveTimeZone(facesContext);
+		Locale currentLocale = selectInputDate.resolveLocale(facesContext);
 
-        int weekStartsAtDayIndex =
-                mapCalendarDayToCommonDay(timeKeeper.getFirstDayOfWeek());
+		Calendar timeKeeper = Calendar.getInstance(tz, currentLocale);
+		timeKeeper.setTime(value != null ? value : new Date());
 
-        // do not require a writer - clean out all methods that reference a writer
-        ResponseWriter writer = facesContext.getResponseWriter();
+		DateFormatSymbols symbols = new DateFormatSymbols(currentLocale);
 
-        Element root = (Element) domContext.getRootNode();
+		String[] weekdays = mapWeekdays(symbols);
+		String[] weekdaysLong = mapWeekdaysLong(symbols);
+		String[] months = mapMonths(symbols);
 
-      
-        if (selectInputDate.isRenderAsPopup()) {
-            if (log.isTraceEnabled()) {
-                log.trace("SelectInputDate as Popup");
-            }
+		// use the currentDay to set focus - do not set
+		int lastDayInMonth = timeKeeper.getActualMaximum(Calendar.DAY_OF_MONTH);
+		int currentDay = timeKeeper.get(Calendar.DAY_OF_MONTH); // starts at 1
 
-            // assumption input text is first child
-            Element dateText = (Element) root.getFirstChild();
-//System.out.println("dateText  currentValue: " + currentValue);
-            dateText.setAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_TEXT); // ICE-2302
-            dateText.setAttribute(
-                HTML.VALUE_ATTR,
-                selectInputDate.getTextToRender());
-    
-            // get tables , our table is the first and only one
-            NodeList tables = root.getElementsByTagName(HTML.TABLE_ELEM);
-            // assumption we want the first table in tables. there should only be one
-            Element table = (Element) tables.item(0);
+		if (currentDay > lastDayInMonth) {
+			currentDay = lastDayInMonth;
+		}
 
-            PassThruAttributeRenderer.renderAttributes(
-                facesContext, uiComponent, new String[] {"title"});
+		timeKeeper.set(Calendar.DAY_OF_MONTH, 1);
 
-            Element tr1 = domContext.createElement(HTML.TR_ELEM);
+		int weekDayOfFirstDayOfMonth = mapCalendarDayToCommonDay(timeKeeper
+				.get(Calendar.DAY_OF_WEEK));
 
-            table.appendChild(tr1);
-	            writeMonthYearHeader(domContext, facesContext, writer,
-	                                 selectInputDate, timeKeeper,
-	                                 currentDay, tr1,
-	                                 selectInputDate.getMonthYearRowClass(),
-                                     currentLocale, months, weekdays, weekdaysLong);
-	
-	            Element tr2 = domContext.createElement(HTML.TR_ELEM);
-	            table.appendChild(tr2);
-	
-	            writeWeekDayNameHeader(domContext, weekStartsAtDayIndex, weekdays,
-	                                   facesContext, writer, selectInputDate, tr2,
-	                                   selectInputDate.getWeekRowClass(),
-                                       timeKeeper, months, weekdaysLong);
-	
-	            writeDays(domContext, facesContext, writer, selectInputDate,
-	                      timeKeeper,
-	                      currentDay, weekStartsAtDayIndex,
-	                      weekDayOfFirstDayOfMonth,
-	                      lastDayInMonth, table,
-                          months, weekdays, weekdaysLong);
+		int weekStartsAtDayIndex = mapCalendarDayToCommonDay(timeKeeper
+				.getFirstDayOfWeek());
 
+		// do not require a writer - clean out all methods that reference a
+		// writer
+		ResponseWriter writer = facesContext.getResponseWriter();
 
-        } else {
-            if (log.isTraceEnabled()) {
-                log.trace("renderNormal::endcodeEnd");
-            }
-            // assume table is the first child
-            Element table = (Element) root.getFirstChild();
+		Element root = (Element) domContext.getRootNode();
 
-            PassThruAttributeRenderer.renderAttributes(
-                facesContext, uiComponent, new String[] {"title"});
+		if (selectInputDate.isRenderAsPopup()) {
+			if (log.isTraceEnabled()) {
+				log.trace("SelectInputDate as Popup");
+			}
 
-            Element tr1 = domContext.createElement(HTML.TR_ELEM);
-            table.appendChild(tr1);
+			// assumption input text is first child
+			Element dateText = (Element) root.getFirstChild();
+			// System.out.println("dateText currentValue: " + currentValue);
+			dateText.setAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_TEXT); // ICE-2302
+			dateText.setAttribute(HTML.VALUE_ATTR, selectInputDate
+					.getTextToRender());
 
-            writeMonthYearHeader(domContext, facesContext, writer,
-                                 selectInputDate, timeKeeper,
-                                 currentDay, tr1,
-                                 selectInputDate.getMonthYearRowClass(),
-                                 currentLocale, months, weekdays, weekdaysLong);
+			// get tables , our table is the first and only one
+			NodeList tables = root.getElementsByTagName(HTML.TABLE_ELEM);
+			// assumption we want the first table in tables. there should only
+			// be one
+			Element table = (Element) tables.item(0);
 
-            Element tr2 = domContext.createElement(HTML.TR_ELEM);
+			PassThruAttributeRenderer.renderAttributes(facesContext,
+					uiComponent, new String[] { "title" });
 
-            writeWeekDayNameHeader(domContext, weekStartsAtDayIndex, weekdays,
-                                   facesContext, writer, selectInputDate, tr2,
-                                   selectInputDate.getWeekRowClass(),
-                                   timeKeeper, months, weekdaysLong);
+			Element tr1 = domContext.createElement(HTML.TR_ELEM);
 
-            table.appendChild(tr2);
+			table.appendChild(tr1);
+			writeMonthYearHeader(domContext, facesContext, writer,
+					selectInputDate, timeKeeper, currentDay, tr1,
+					selectInputDate.getMonthYearRowClass(), currentLocale,
+					months, weekdays, weekdaysLong);
 
-            writeDays(domContext, facesContext, writer, selectInputDate,
-                      timeKeeper,
-                      currentDay, weekStartsAtDayIndex,
-                      weekDayOfFirstDayOfMonth,
-                      lastDayInMonth, table,
-                      months, weekdays, weekdaysLong);
+			Element tr2 = domContext.createElement(HTML.TR_ELEM);
+			table.appendChild(tr2);
 
-        }
+			writeWeekDayNameHeader(domContext, weekStartsAtDayIndex, weekdays,
+					facesContext, writer, selectInputDate, tr2, selectInputDate
+							.getWeekRowClass(), timeKeeper, months,
+					weekdaysLong);
 
-        // purge child components as they have been encoded no need to keep them around
-        selectInputDate.getChildren().removeAll(selectInputDate.getChildren());
+			writeDays(domContext, facesContext, writer, selectInputDate,
+					timeKeeper, currentDay, weekStartsAtDayIndex,
+					weekDayOfFirstDayOfMonth, lastDayInMonth, table, months,
+					weekdays, weekdaysLong);
 
-        // steps to the position where the next sibling should be rendered
-        domContext.stepOver();
-        domContext.streamWrite(facesContext, uiComponent);
-    }
+		} else {
+			if (log.isTraceEnabled()) {
+				log.trace("renderNormal::endcodeEnd");
+			}
+			// assume table is the first child
+			Element table = (Element) root.getFirstChild();
 
-    private void writeMonthYearHeader(DOMContext domContext,
-                                      FacesContext facesContext,
-                                      ResponseWriter writer,
-                                      SelectInputDate inputComponent,
-                                      Calendar timeKeeper,
-                                      int currentDay, Element headerTr,
-                                      String styleClass, Locale currentLocale,
-                                      String[] months, String[] weekdays, String[] weekdaysLong)
-            throws IOException {
+			PassThruAttributeRenderer.renderAttributes(facesContext,
+					uiComponent, new String[] { "title" });
 
-        Element table = domContext.createElement(HTML.TABLE_ELEM);
-        table.setAttribute(HTML.CELLPADDING_ATTR, "0");
-        table.setAttribute(HTML.CELLSPACING_ATTR, "0");
-        table.setAttribute(HTML.WIDTH_ATTR, "100%");
-        addAttributeToElementFromResource(facesContext,
-            YEAR_MONTH_SUMMARY, table, HTML.SUMMARY_ATTR);
+			Element tr1 = domContext.createElement(HTML.TR_ELEM);
+			table.appendChild(tr1);
 
-        Element tr = domContext.createElement(HTML.TR_ELEM);
+			writeMonthYearHeader(domContext, facesContext, writer,
+					selectInputDate, timeKeeper, currentDay, tr1,
+					selectInputDate.getMonthYearRowClass(), currentLocale,
+					months, weekdays, weekdaysLong);
 
-        Element headertd = domContext.createElement(HTML.TD_ELEM);
-        table.appendChild(tr);
-        headertd.appendChild(table);
-        headerTr.appendChild(headertd);
+			Element tr2 = domContext.createElement(HTML.TR_ELEM);
 
-        headertd.setAttribute(HTML.COLSPAN_ATTR, "7"); // weekdays.length = 7
+			writeWeekDayNameHeader(domContext, weekStartsAtDayIndex, weekdays,
+					facesContext, writer, selectInputDate, tr2, selectInputDate
+							.getWeekRowClass(), timeKeeper, months,
+					weekdaysLong);
 
-        // first render month with navigation back and forward
-        Calendar cal = shiftMonth(facesContext, timeKeeper, currentDay, -1);
-        writeCell(domContext, facesContext, writer, inputComponent,
-                  "<", cal.getTime(), styleClass, tr,
-                  inputComponent.getImageDir() +
-                  inputComponent.getMovePreviousImage(), -1,
-                  timeKeeper, months, weekdaysLong);
+			table.appendChild(tr2);
 
-        Element td = domContext.createElement(HTML.TD_ELEM);
-        td.setAttribute(HTML.CLASS_ATTR, styleClass);
-        td.setAttribute(HTML.WIDTH_ATTR, "40%");
-        Text text = domContext
-                .createTextNode(months[timeKeeper.get(Calendar.MONTH)] + "");
-        td.appendChild(text);
+			writeDays(domContext, facesContext, writer, selectInputDate,
+					timeKeeper, currentDay, weekStartsAtDayIndex,
+					weekDayOfFirstDayOfMonth, lastDayInMonth, table, months,
+					weekdays, weekdaysLong);
 
-        tr.appendChild(td);
+		}
 
-        cal = shiftMonth(facesContext, timeKeeper, currentDay, 1);
-        int calYear = cal.get(Calendar.YEAR);
+		Element hiddenField = domContext.createElement(HTML.INPUT_ELEM);
+		hiddenField.setAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN);
+		hiddenField.setAttribute(HTML.NAME_ATTR, uiComponent
+				.getClientId(facesContext));
+		root.appendChild(hiddenField);
 
-        if (inputComponent.getHightlightRules().containsKey(Calendar.YEAR+"$"+calYear)) {
-            inputComponent.setHighlightYearClass(inputComponent.getHightlightRules().get(Calendar.YEAR+"$"+calYear) + " ");
-        } else {
-            inputComponent.setHighlightYearClass("");
-        }
-              
-        int calMonth = cal.get(Calendar.MONTH);
-        if (inputComponent.getHightlightRules().containsKey(Calendar.MONTH+"$"+calMonth)) {
-            inputComponent.setHighlightMonthClass(inputComponent.getHightlightRules().get(Calendar.MONTH+"$"+calMonth) + " ");
-        } else {
-            inputComponent.setHighlightMonthClass("");
-        }  
-        writeCell(domContext, facesContext, writer, inputComponent,
-                  ">", cal.getTime(), styleClass, tr,
-                  inputComponent.getImageDir() +
-                  inputComponent.getMoveNextImage(), -1,
-                  timeKeeper, months, weekdaysLong);
+		// purge child components as they have been encoded no need to keep them
+		// around
+		selectInputDate.getChildren().removeAll(selectInputDate.getChildren());
 
-        // second add an empty td
-        Element emptytd = domContext.createElement(HTML.TD_ELEM);
-        emptytd.setAttribute(HTML.CLASS_ATTR, styleClass);
-        Text emptytext = domContext.createTextNode("");
-        emptytd.appendChild(emptytext);
+		// steps to the position where the next sibling should be rendered
+		domContext.stepOver();
+		domContext.streamWrite(facesContext, uiComponent);
+	}
 
-        tr.appendChild(emptytd);
+	private void writeMonthYearHeader(DOMContext domContext,
+			FacesContext facesContext, ResponseWriter writer,
+			SelectInputDate inputComponent, Calendar timeKeeper,
+			int currentDay, Element headerTr, String styleClass,
+			Locale currentLocale, String[] months, String[] weekdays,
+			String[] weekdaysLong) throws IOException {
 
-        // third render year with navigation back and forward
-        cal = shiftYear(facesContext, timeKeeper, currentDay, -1);
+		Element table = domContext.createElement(HTML.TABLE_ELEM);
+		table.setAttribute(HTML.CELLPADDING_ATTR, "0");
+		table.setAttribute(HTML.CELLSPACING_ATTR, "0");
+		table.setAttribute(HTML.WIDTH_ATTR, "100%");
+		addAttributeToElementFromResource(facesContext, YEAR_MONTH_SUMMARY,
+				table, HTML.SUMMARY_ATTR);
 
-        writeCell(domContext, facesContext, writer, inputComponent,
-                  "<<", cal.getTime(), styleClass, tr,
-                  inputComponent.getImageDir() +
-                  inputComponent.getMovePreviousImage(), -1,
-                  timeKeeper, months, weekdaysLong);
+		Element tr = domContext.createElement(HTML.TR_ELEM);
 
-        Element yeartd = domContext.createElement(HTML.TD_ELEM);
-        yeartd.setAttribute(HTML.CLASS_ATTR, styleClass);
-        Text yeartext =
-                domContext.createTextNode("" + timeKeeper.get(Calendar.YEAR));
-        yeartd.appendChild(yeartext);
+		Element headertd = domContext.createElement(HTML.TD_ELEM);
+		table.appendChild(tr);
+		headertd.appendChild(table);
+		headerTr.appendChild(headertd);
 
-        tr.appendChild(yeartd);
+		headertd.setAttribute(HTML.COLSPAN_ATTR, "7"); // weekdays.length = 7
 
-        cal = shiftYear(facesContext, timeKeeper, currentDay, 1);
+		// first render month with navigation back and forward
+		Calendar cal = shiftMonth(facesContext, timeKeeper, currentDay, -1);
+		writeCell(domContext, facesContext, writer, inputComponent, "<", cal
+				.getTime(), styleClass, tr, inputComponent.getImageDir()
+				+ inputComponent.getMovePreviousImage(), -1, timeKeeper,
+				months, weekdaysLong);
 
-        writeCell(domContext, facesContext, writer, inputComponent,
-                  ">>", cal.getTime(), styleClass, tr,
-                  inputComponent.getImageDir() +
-                  inputComponent.getMoveNextImage(), -1,
-                  timeKeeper, months, weekdaysLong);
+		Element td = domContext.createElement(HTML.TD_ELEM);
+		td.setAttribute(HTML.CLASS_ATTR, styleClass);
+		td.setAttribute(HTML.WIDTH_ATTR, "40%");
+		Text text = domContext.createTextNode(months[timeKeeper
+				.get(Calendar.MONTH)]
+				+ "");
+		td.appendChild(text);
 
-    }
+		tr.appendChild(td);
 
-    private Calendar shiftMonth(FacesContext facesContext,
-                                Calendar timeKeeper, int currentDay,
-                                int shift) {
-        Calendar cal = copyCalendar(facesContext, timeKeeper);
+		cal = shiftMonth(facesContext, timeKeeper, currentDay, 1);
+		int calYear = cal.get(Calendar.YEAR);
 
-        cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + shift);
+		if (inputComponent.getHightlightRules().containsKey(
+				Calendar.YEAR + "$" + calYear)) {
+			inputComponent.setHighlightYearClass(inputComponent
+					.getHightlightRules().get(Calendar.YEAR + "$" + calYear)
+					+ " ");
+		} else {
+			inputComponent.setHighlightYearClass("");
+		}
 
-        if (currentDay > cal.getActualMaximum(Calendar.DAY_OF_MONTH)) {
-            currentDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
-        }
+		int calMonth = cal.get(Calendar.MONTH);
+		if (inputComponent.getHightlightRules().containsKey(
+				Calendar.MONTH + "$" + calMonth)) {
+			inputComponent.setHighlightMonthClass(inputComponent
+					.getHightlightRules().get(Calendar.MONTH + "$" + calMonth)
+					+ " ");
+		} else {
+			inputComponent.setHighlightMonthClass("");
+		}
+		writeCell(domContext, facesContext, writer, inputComponent, ">", cal
+				.getTime(), styleClass, tr, inputComponent.getImageDir()
+				+ inputComponent.getMoveNextImage(), -1, timeKeeper, months,
+				weekdaysLong);
 
-        cal.set(Calendar.DAY_OF_MONTH, currentDay);
-        return cal;
-    }
+		// second add an empty td
+		Element emptytd = domContext.createElement(HTML.TD_ELEM);
+		emptytd.setAttribute(HTML.CLASS_ATTR, styleClass);
+		Text emptytext = domContext.createTextNode("");
+		emptytd.appendChild(emptytext);
 
-    private Calendar shiftYear(FacesContext facesContext,
-                               Calendar timeKeeper, int currentDay, int shift) {
-        Calendar cal = copyCalendar(facesContext, timeKeeper);
-        
-        cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + shift);
+		tr.appendChild(emptytd);
 
-        if (currentDay > cal.getActualMaximum(Calendar.DAY_OF_MONTH)) {
-            currentDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
-        }
+		// third render year with navigation back and forward
+		cal = shiftYear(facesContext, timeKeeper, currentDay, -1);
 
-        cal.set(Calendar.DAY_OF_MONTH, currentDay);
-        return cal;
-    }
+		writeCell(domContext, facesContext, writer, inputComponent, "<<", cal
+				.getTime(), styleClass, tr, inputComponent.getImageDir()
+				+ inputComponent.getMovePreviousImage(), -1, timeKeeper,
+				months, weekdaysLong);
 
-    private Calendar copyCalendar(FacesContext facesContext,
-                                  Calendar timeKeeper) {
-        Calendar cal = (Calendar) timeKeeper.clone();
-        return cal;
-    }
+		Element yeartd = domContext.createElement(HTML.TD_ELEM);
+		yeartd.setAttribute(HTML.CLASS_ATTR, styleClass);
+		Text yeartext = domContext.createTextNode(""
+				+ timeKeeper.get(Calendar.YEAR));
+		yeartd.appendChild(yeartext);
 
-    private void writeWeekDayNameHeader(DOMContext domContext,
-                                        int weekStartsAtDayIndex,
-                                        String[] weekdays,
-                                        FacesContext facesContext,
-                                        ResponseWriter writer,
-                                        SelectInputDate inputComponent, Element tr,
-                                        String styleClass,
-                                        Calendar timeKeeper,
-                                        String[] months, String[] weekdaysLong)
-            throws IOException {
-        // the week can start with Sunday (index 0) or Monday (index 1)
-        for (int i = weekStartsAtDayIndex; i < weekdays.length; i++) {
-            writeCell(domContext, facesContext,
-                      writer, inputComponent, weekdays[i], null, styleClass, tr,
-                      null, i,
-                      timeKeeper, months, weekdaysLong);
-        }
+		tr.appendChild(yeartd);
 
-        // if week start on Sunday this block is not executed
-        // if week start on Monday this block will run once adding Sunday to End of week.
-        for (int i = 0; i < weekStartsAtDayIndex; i++) {
-            writeCell(domContext, facesContext, writer,
-                      inputComponent, weekdays[i], null, styleClass, tr, null, i,
-                      timeKeeper, months, weekdaysLong);
-        }
-    }
+		cal = shiftYear(facesContext, timeKeeper, currentDay, 1);
 
-    private void writeDays(DOMContext domContext, FacesContext facesContext,
-                           ResponseWriter writer,
-                           SelectInputDate inputComponent, Calendar timeKeeper,
-                           int currentDay, int weekStartsAtDayIndex,
-                           int weekDayOfFirstDayOfMonth, int lastDayInMonth,
-                           Element table, String[] months,
-                           String[] weekdays, String[] weekdaysLong)
-            throws IOException {
-        Calendar cal;
+		writeCell(domContext, facesContext, writer, inputComponent, ">>", cal
+				.getTime(), styleClass, tr, inputComponent.getImageDir()
+				+ inputComponent.getMoveNextImage(), -1, timeKeeper, months,
+				weekdaysLong);
 
-        int space = (weekStartsAtDayIndex < weekDayOfFirstDayOfMonth) ?
-                    (weekDayOfFirstDayOfMonth - weekStartsAtDayIndex)
-                    : (weekdays.length - weekStartsAtDayIndex +
-                       weekDayOfFirstDayOfMonth);
+	}
 
-        if (space == weekdays.length) {
-            space = 0;
-        }
+	private Calendar shiftMonth(FacesContext facesContext, Calendar timeKeeper,
+			int currentDay, int shift) {
+		Calendar cal = copyCalendar(facesContext, timeKeeper);
 
-        int columnIndexCounter = 0;
+		cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + shift);
 
-        Element tr1 = null;
-        for (int i = 0; i < space; i++) {
-            if (columnIndexCounter == 0) {
-                tr1 = domContext.createElement(HTML.TR_ELEM);
-                table.appendChild(tr1);
-            }
-            
-            writeCell(domContext, facesContext, writer, inputComponent, "&nbsp;",
-                      null, inputComponent.getDayCellClass(), tr1, null,
-                      (weekStartsAtDayIndex + i) % 7,
-                      timeKeeper, months, weekdaysLong);
-            columnIndexCounter++;
-        }
+		if (currentDay > cal.getActualMaximum(Calendar.DAY_OF_MONTH)) {
+			currentDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
+		}
 
-        Element tr2 = null;
-        for (int i = 0; i < lastDayInMonth; i++) {
-            if (columnIndexCounter == 0) {
-                // don't create a new row until we have finished the last
-                tr2 = domContext.createElement(HTML.TR_ELEM);
-                table.appendChild(tr2);
-            }
+		cal.set(Calendar.DAY_OF_MONTH, currentDay);
+		return cal;
+	}
 
-            cal = copyCalendar(facesContext, timeKeeper);
-            cal.set(Calendar.DAY_OF_MONTH,
-                    i + 1); // i starts at 0 DAY_OF_MONTH start at 1
+	private Calendar shiftYear(FacesContext facesContext, Calendar timeKeeper,
+			int currentDay, int shift) {
+		Calendar cal = copyCalendar(facesContext, timeKeeper);
 
-            // get day, month and year
-            // use these to check if the currentDayCell style class should be used
-            int day = 0;
-            int month = 0;
-            int year = 0;
-            try {
-                Date currentDate = (Date) inputComponent.getValue();
-                Calendar current = copyCalendar(facesContext, timeKeeper);
-                current.setTime(currentDate);
-                
-                day = current.get(Calendar.DAY_OF_MONTH); // starts with 1
-                month = current.get(Calendar.MONTH); // starts with 0
-                year = current.get(Calendar.YEAR);
-            } catch (Exception e) {
-                // hmmm this should never happen
-            }
-            
-           
-            if (inputComponent.getHightlightRules().size()>0) {
-                int weekOfYear = cal.get(Calendar.WEEK_OF_YEAR);
-                int weekOfMonth = cal.get(Calendar.WEEK_OF_MONTH);
-                int date =cal.get(Calendar.DATE);
-                int dayOfYear = cal.get(Calendar.DAY_OF_YEAR);
-                int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
-                int dayOfWeekInMonth = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
-                
-                if (inputComponent.getHightlightRules().containsKey(Calendar.WEEK_OF_YEAR+"$"+weekOfYear)) {
-                    inputComponent.addHighlightWeekClass(String.valueOf(inputComponent.getHightlightRules().get(Calendar.WEEK_OF_YEAR+"$"+weekOfYear)));
-                }
-                if (inputComponent.getHightlightRules().containsKey(Calendar.WEEK_OF_MONTH+"$"+weekOfMonth)) {
-                    inputComponent.addHighlightWeekClass(String.valueOf(inputComponent.getHightlightRules().get(Calendar.WEEK_OF_MONTH+"$"+weekOfMonth)));
-                }
-                if (inputComponent.getHightlightRules().containsKey(Calendar.DATE+"$"+date)) {
-                    inputComponent.addHighlightDayClass(String.valueOf(inputComponent.getHightlightRules().get(Calendar.DATE+"$"+date)));
-                }  
-                if (inputComponent.getHightlightRules().containsKey(Calendar.DAY_OF_YEAR+"$"+dayOfYear)) {
-                    inputComponent.addHighlightDayClass(String.valueOf(inputComponent.getHightlightRules().get(Calendar.DAY_OF_YEAR+"$"+dayOfYear)));
-                } 
-                if (inputComponent.getHightlightRules().containsKey(Calendar.DAY_OF_WEEK+"$"+dayOfWeek)) {
-                    inputComponent.addHighlightDayClass(String.valueOf(inputComponent.getHightlightRules().get(Calendar.DAY_OF_WEEK+"$"+dayOfWeek)));
-                } 
-                if (inputComponent.getHightlightRules().containsKey(Calendar.DAY_OF_WEEK_IN_MONTH+"$"+dayOfWeekInMonth)) {
-                    inputComponent.addHighlightDayClass(String.valueOf(inputComponent.getHightlightRules().get(Calendar.DAY_OF_WEEK_IN_MONTH+"$"+dayOfWeekInMonth)));
-                }                
-            }
-            
-            String cellStyle = inputComponent.getDayCellClass() + " " + inputComponent.getHighlightDayCellClass();            
-            
-            
-            if ((cal.get(Calendar.DAY_OF_MONTH) == day) &&
-                    (cal.get(Calendar.MONTH) == month) &&
-                    (cal.get(Calendar.YEAR) == year)) {
-                    cellStyle = inputComponent.getCurrentDayCellClass();
-                }
-             
-            
-            // do not automatically select date when navigating by month
-            if ((cal.get(Calendar.DAY_OF_MONTH) == day) &&
-                (cal.get(Calendar.MONTH) == month) &&
-                (cal.get(Calendar.YEAR) == year)) {
-                cellStyle = inputComponent.getCurrentDayCellClass();
-            }
+		cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + shift);
 
-            if (tr2 == null) {
-                // finish the first row
-                writeCell(domContext, facesContext, writer,
-                          inputComponent, String.valueOf(i + 1), cal.getTime(),
-                          cellStyle, tr1, null, i,
-                          timeKeeper, months, weekdaysLong);
-            } else {
-                // write to new row
-                writeCell(domContext, facesContext, writer,
-                          inputComponent, String.valueOf(i + 1), cal.getTime(),
-                          cellStyle, tr2, null, i,
-                          timeKeeper, months, weekdaysLong);
-            }
+		if (currentDay > cal.getActualMaximum(Calendar.DAY_OF_MONTH)) {
+			currentDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
+		}
 
-            columnIndexCounter++;
+		cal.set(Calendar.DAY_OF_MONTH, currentDay);
+		return cal;
+	}
 
-            if (columnIndexCounter == weekdays.length) {
-                columnIndexCounter = 0;
-            }
-            inputComponent.resetHighlightClasses(Calendar.WEEK_OF_YEAR);
-        }
+	private Calendar copyCalendar(FacesContext facesContext, Calendar timeKeeper) {
+		Calendar cal = (Calendar) timeKeeper.clone();
+		return cal;
+	}
 
-        if ((columnIndexCounter != 0) && (tr2 != null)) {
-            for (int i = columnIndexCounter; i < weekdays.length; i++) {
-                writeCell(domContext, facesContext, writer,
-                          inputComponent, "&nbsp;", null,
-                          inputComponent.getDayCellClass(), tr2, null,
-                          (weekStartsAtDayIndex + i) % 7,
-                          timeKeeper, months, weekdaysLong);
-             }
-        }
+	private void writeWeekDayNameHeader(DOMContext domContext,
+			int weekStartsAtDayIndex, String[] weekdays,
+			FacesContext facesContext, ResponseWriter writer,
+			SelectInputDate inputComponent, Element tr, String styleClass,
+			Calendar timeKeeper, String[] months, String[] weekdaysLong)
+			throws IOException {
+		// the week can start with Sunday (index 0) or Monday (index 1)
+		for (int i = weekStartsAtDayIndex; i < weekdays.length; i++) {
+			writeCell(domContext, facesContext, writer, inputComponent,
+					weekdays[i], null, styleClass, tr, null, i, timeKeeper,
+					months, weekdaysLong);
+		}
 
-    }
+		// if week start on Sunday this block is not executed
+		// if week start on Monday this block will run once adding Sunday to End
+		// of week.
+		for (int i = 0; i < weekStartsAtDayIndex; i++) {
+			writeCell(domContext, facesContext, writer, inputComponent,
+					weekdays[i], null, styleClass, tr, null, i, timeKeeper,
+					months, weekdaysLong);
+		}
+	}
 
-    private void writeCell(DOMContext domContext, FacesContext facesContext,
-                           ResponseWriter writer, SelectInputDate component,
-                           String content,
-                           Date valueForLink, String styleClass, Element tr,
-                           String imgSrc, int weekDayIndex,
-                           Calendar timeKeeper,
-                           String[] months, String[] weekdaysLong)
-            throws IOException {
-        Element td = domContext.createElement(HTML.TD_ELEM);
-        tr.appendChild(td);
+	private void writeDays(DOMContext domContext, FacesContext facesContext,
+			ResponseWriter writer, SelectInputDate inputComponent,
+			Calendar timeKeeper, int currentDay, int weekStartsAtDayIndex,
+			int weekDayOfFirstDayOfMonth, int lastDayInMonth, Element table,
+			String[] months, String[] weekdays, String[] weekdaysLong)
+			throws IOException {
+		Calendar cal;
 
-        if (styleClass != null) {
-            td.setAttribute(HTML.CLASS_ATTR, styleClass);
-        }
+		int space = (weekStartsAtDayIndex < weekDayOfFirstDayOfMonth) ? (weekDayOfFirstDayOfMonth - weekStartsAtDayIndex)
+				: (weekdays.length - weekStartsAtDayIndex + weekDayOfFirstDayOfMonth);
 
-        if (valueForLink == null) {
-            if(content != null && content.length() > 0) {
-                Text text = domContext.createTextNode(content);
-                td.setAttribute(HTML.TITLE_ATTR,weekdaysLong[weekDayIndex]);
-                td.appendChild(text);
-            }
-        } else {
-            // set cursor to render into the td
-            domContext.setCursorParent(td);
-            domContext.streamWrite(facesContext, component,
-                                   domContext.getRootNode(), td);
-            writeLink(content, component, facesContext, valueForLink,
-                      styleClass, imgSrc, td, timeKeeper,
-                      months, weekdaysLong);
-            // steps to the position where the next sibling should be rendered
-            domContext.stepOver();
-        }
+		if (space == weekdays.length) {
+			space = 0;
+		}
 
-    }
+		int columnIndexCounter = 0;
 
-    private void writeLink(String content,
-                           SelectInputDate component,
-                           FacesContext facesContext,
-                           Date valueForLink,
-                           String styleClass,
-                           String imgSrc,
-                           Element td,
-                           Calendar timeKeeper,
-                           String[] months, String[] weekdaysLong)
-            throws IOException {
+		Element tr1 = null;
+		for (int i = 0; i < space; i++) {
+			if (columnIndexCounter == 0) {
+				tr1 = domContext.createElement(HTML.TR_ELEM);
+				table.appendChild(tr1);
+			}
 
-        Converter converter = component.resolveDateTimeConverter(facesContext);
-        HtmlCommandLink link = new HtmlCommandLink();
-        Calendar cal = copyCalendar(facesContext, timeKeeper);
-        cal.setTime(valueForLink);
-        String month = months[cal.get(Calendar.MONTH)];
-        String year = String.valueOf(cal.get(Calendar.YEAR));
-        int dayInt = cal.get(Calendar.DAY_OF_WEEK);
-        dayInt = mapCalendarDayToCommonDay(dayInt);
-        String day = weekdaysLong[dayInt];
-        String altText = null;
-        String titleText = null;
-        // assign special ids for navigation links
-        if (content.equals("<")) {
-            link.setId(component.getId() + this.PREV_MONTH);
-            altText = getMessageWithParamFromResource(
-                facesContext, PREV_MONTH_ALT, month);
-            titleText = getMessageWithParamFromResource(
-                facesContext, PREV_MONTH_TITLE, month);
-        } else if (content.equals(">")) {
-            link.setId(component.getId() + this.NEXT_MONTH);
-            altText = getMessageWithParamFromResource(
-                facesContext, NEXT_MONTH_ALT, month);
-            titleText = getMessageWithParamFromResource(
-                facesContext, NEXT_MONTH_TITLE, month);
-        } else if (content.equals(">>")) {
-            link.setId(component.getId() + this.NEXT_YEAR);
-            altText = getMessageWithParamFromResource(
-                facesContext, NEXT_YEAR_ALT, year);
-            titleText = getMessageWithParamFromResource(
-                facesContext, NEXT_YEAR_TITLE, year);
-        } else if (content.equals("<<")) {
-            link.setId(component.getId() + this.PREV_YEAR);
-            altText = getMessageWithParamFromResource(
-                facesContext, PREV_YEAR_ALT, year);
-            titleText = getMessageWithParamFromResource(
-                facesContext, PREV_YEAR_TITLE, year);
-        } else {
-            link.setId(component.getId() + "_" + content.hashCode() + this
-                    .CALENDAR);
-            if (log.isDebugEnabled()) {
-                log.debug("linkId=" + component.getId() + "_" +
-                          content.hashCode() + this.CALENDAR);
-            }
-        }
+			writeCell(domContext, facesContext, writer, inputComponent,
+					"&nbsp;", null, inputComponent.getDayCellClass(), tr1,
+					null, (weekStartsAtDayIndex + i) % 7, timeKeeper, months,
+					weekdaysLong);
+			columnIndexCounter++;
+		}
 
-        link.setPartialSubmit(true);
-        link.setTransient(true);
-        link.setImmediate(component.isImmediate());
-        link.setDisabled(((SelectInputDate) component).isDisabled());
+		Element tr2 = null;
+		for (int i = 0; i < lastDayInMonth; i++) {
+			if (columnIndexCounter == 0) {
+				// don't create a new row until we have finished the last
+				tr2 = domContext.createElement(HTML.TR_ELEM);
+				table.appendChild(tr2);
+			}
 
-        if (imgSrc != null) {
-            HtmlGraphicImage img = new HtmlGraphicImage();
-            if (component.isImageDirSet()) {
-                img.setUrl(imgSrc);
-            } else {
-                // ICE-2127: allow override of button images via CSS
-                // getImageDir() returns default
-                // without a dummy image Firefox would show the alt text
-                img.setUrl(component.getImageDir() + "spacer.gif");
-                if (content.equals("<") || content.equals("<<")) {
-                    img.setStyleClass(component.getMovePrevClass());
-                } else if (content.equals(">") || content.equals(">>")) {
-                    img.setStyleClass(component.getMoveNextClass());
-                }
-            }
-            img.setHeight("16");
-            img.setWidth("17");
-            img.setStyle("border:none;");
-            if(altText != null)
-                img.setAlt(altText);
-            if(titleText != null)
-                img.setTitle(titleText);
-            img.setId(component.getId() + "_" + content.hashCode() + "_img");
-            img.setTransient(true);
-            link.getChildren().add(img);
-        } else {            
-            HtmlOutputText text = new HtmlOutputText();
-            text.setValue(content);
-            text.setId(component.getId() + "_" + content.hashCode() + "_text");
-            text.setTransient(true);
-            text.setTitle(day);
-            link.getChildren().add(text);
-        }
-        // links are focus aware       
-        UIParameter parameter = new UIParameter();
-        parameter.setId(
-                component.getId() + "_" + valueForLink.getTime() + "_param");
-        parameter.setTransient(true);
-        parameter.setName(component.getClientId(facesContext));
-        parameter.setValue(
-                converter.getAsString(facesContext, component, valueForLink));
+			cal = copyCalendar(facesContext, timeKeeper);
+			cal.set(Calendar.DAY_OF_MONTH, i + 1); // i starts at 0
+			// DAY_OF_MONTH start at 1
 
-        component.getChildren().add(link);
-        link.getChildren().add(parameter);
+			// get day, month and year
+			// use these to check if the currentDayCell style class should be
+			// used
+			int day = 0;
+			int month = 0;
+			int year = 0;
+			try {
+				Date currentDate = (Date) inputComponent.getValue();
+				Calendar current = copyCalendar(facesContext, timeKeeper);
+				current.setTime(currentDate);
 
-        //don't add this parameter for next and previouse button/link        
-        if (!content.equals("<") && !content.equals(">") &&
-            !content.equals(">>") && !content.equals("<<")) {
-            //this parameter would be use to close the popup selectinputdate after date selection.
-            parameter = new UIParameter();
-            parameter.setId(component.getId() + "_" + valueForLink.getTime() +
-                            "_" + DATE_SELECTED);
-            parameter.setName(getHiddenFieldName(facesContext, component));
-            parameter.setValue("false");
-            link.getChildren().add(parameter);
-        }
-        link.encodeBegin(facesContext);
-        link.encodeChildren(facesContext);
-        link.encodeEnd(facesContext);
-        td.setAttribute(HTML.ID_ATTR, link.getClientId(facesContext) + "td");
-        try {
-            Integer.parseInt(content);
-            ((SelectInputDate) component).getLinkMap()
-                    .put(link.getClientId(facesContext), td);
-            if (styleClass.equals(CSS_DEFAULT.DEFAULT_CALENDAR + CSS_DEFAULT
-                    .DEFAULT_CURRENTDAYCELL_CLASS)) {
-                ((SelectInputDate) component)
-                        .setSelectedDayLink(link.getClientId(facesContext));
-            }
-        } catch (NumberFormatException e) {
+				day = current.get(Calendar.DAY_OF_MONTH); // starts with 1
+				month = current.get(Calendar.MONTH); // starts with 0
+				year = current.get(Calendar.YEAR);
+			} catch (Exception e) {
+				// hmmm this should never happen
+			}
 
-        }
+			if (inputComponent.getHightlightRules().size() > 0) {
+				int weekOfYear = cal.get(Calendar.WEEK_OF_YEAR);
+				int weekOfMonth = cal.get(Calendar.WEEK_OF_MONTH);
+				int date = cal.get(Calendar.DATE);
+				int dayOfYear = cal.get(Calendar.DAY_OF_YEAR);
+				int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
+				int dayOfWeekInMonth = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
 
+				if (inputComponent.getHightlightRules().containsKey(
+						Calendar.WEEK_OF_YEAR + "$" + weekOfYear)) {
+					inputComponent.addHighlightWeekClass(String
+							.valueOf(inputComponent.getHightlightRules().get(
+									Calendar.WEEK_OF_YEAR + "$" + weekOfYear)));
+				}
+				if (inputComponent.getHightlightRules().containsKey(
+						Calendar.WEEK_OF_MONTH + "$" + weekOfMonth)) {
+					inputComponent
+							.addHighlightWeekClass(String
+									.valueOf(inputComponent
+											.getHightlightRules()
+											.get(
+													Calendar.WEEK_OF_MONTH
+															+ "$" + weekOfMonth)));
+				}
+				if (inputComponent.getHightlightRules().containsKey(
+						Calendar.DATE + "$" + date)) {
+					inputComponent.addHighlightDayClass(String
+							.valueOf(inputComponent.getHightlightRules().get(
+									Calendar.DATE + "$" + date)));
+				}
+				if (inputComponent.getHightlightRules().containsKey(
+						Calendar.DAY_OF_YEAR + "$" + dayOfYear)) {
+					inputComponent.addHighlightDayClass(String
+							.valueOf(inputComponent.getHightlightRules().get(
+									Calendar.DAY_OF_YEAR + "$" + dayOfYear)));
+				}
+				if (inputComponent.getHightlightRules().containsKey(
+						Calendar.DAY_OF_WEEK + "$" + dayOfWeek)) {
+					inputComponent.addHighlightDayClass(String
+							.valueOf(inputComponent.getHightlightRules().get(
+									Calendar.DAY_OF_WEEK + "$" + dayOfWeek)));
+				}
+				if (inputComponent.getHightlightRules().containsKey(
+						Calendar.DAY_OF_WEEK_IN_MONTH + "$" + dayOfWeekInMonth)) {
+					inputComponent.addHighlightDayClass(String
+							.valueOf(inputComponent.getHightlightRules().get(
+									Calendar.DAY_OF_WEEK_IN_MONTH + "$"
+											+ dayOfWeekInMonth)));
+				}
+			}
 
-    }
-    
-    protected void addAttributeToElementFromResource(
-        FacesContext facesContext, String resName, Element elem, String attrib)
-    {
-        String res = MessageUtils.getResource(facesContext, resName);
-        if(res != null && res.length() > 0) {
-            elem.setAttribute(attrib, res);
-        }
-    }
-    
-    protected String getMessageWithParamFromResource(
-        FacesContext facesContext, String resName, String param)
-    {
-        String msg = null;
-        if(param != null && param.length() > 0) {
-            String messagePattern = MessageUtils.getResource(
-                facesContext, resName);
-            if(messagePattern != null && messagePattern.length() > 0) {
-                msg = MessageFormat.format(
-                    messagePattern, new Object[] {param});
-            }
-        }
-        return msg;
-    }
-    
-    private int mapCalendarDayToCommonDay(int day) {
-        switch (day) {
-            case Calendar.TUESDAY:
-                return 1;
-            case Calendar.WEDNESDAY:
-                return 2;
-            case Calendar.THURSDAY:
-                return 3;
-            case Calendar.FRIDAY:
-                return 4;
-            case Calendar.SATURDAY:
-                return 5;
-            case Calendar.SUNDAY:
-                return 6;
-            default:
-                return 0;
-        }
-    }
+			String cellStyle = inputComponent.getDayCellClass() + " "
+					+ inputComponent.getHighlightDayCellClass();
 
-    private static String[] mapWeekdays(DateFormatSymbols symbols) {
-        String[] weekdays = new String[7];
+			if ((cal.get(Calendar.DAY_OF_MONTH) == day)
+					&& (cal.get(Calendar.MONTH) == month)
+					&& (cal.get(Calendar.YEAR) == year)) {
+				cellStyle = inputComponent.getCurrentDayCellClass();
+			}
 
-        String[] localeWeekdays = symbols.getShortWeekdays();
+			// do not automatically select date when navigating by month
+			if ((cal.get(Calendar.DAY_OF_MONTH) == day)
+					&& (cal.get(Calendar.MONTH) == month)
+					&& (cal.get(Calendar.YEAR) == year)) {
+				cellStyle = inputComponent.getCurrentDayCellClass();
+			}
 
-        weekdays[0] = localeWeekdays[Calendar.MONDAY];
-        weekdays[1] = localeWeekdays[Calendar.TUESDAY];
-        weekdays[2] = localeWeekdays[Calendar.WEDNESDAY];
-        weekdays[3] = localeWeekdays[Calendar.THURSDAY];
-        weekdays[4] = localeWeekdays[Calendar.FRIDAY];
-        weekdays[5] = localeWeekdays[Calendar.SATURDAY];
-        weekdays[6] = localeWeekdays[Calendar.SUNDAY];
+			if (tr2 == null) {
+				// finish the first row
+				writeCell(domContext, facesContext, writer, inputComponent,
+						String.valueOf(i + 1), cal.getTime(), cellStyle, tr1,
+						null, i, timeKeeper, months, weekdaysLong);
+			} else {
+				// write to new row
+				writeCell(domContext, facesContext, writer, inputComponent,
+						String.valueOf(i + 1), cal.getTime(), cellStyle, tr2,
+						null, i, timeKeeper, months, weekdaysLong);
+			}
 
-        return weekdays;
-    }
+			columnIndexCounter++;
 
-    private static String[] mapWeekdaysLong(DateFormatSymbols symbols) {
-        String[] weekdays = new String[7];
+			if (columnIndexCounter == weekdays.length) {
+				columnIndexCounter = 0;
+			}
+			inputComponent.resetHighlightClasses(Calendar.WEEK_OF_YEAR);
+		}
 
-        String[] localeWeekdays = symbols.getWeekdays();
+		if ((columnIndexCounter != 0) && (tr2 != null)) {
+			for (int i = columnIndexCounter; i < weekdays.length; i++) {
+				writeCell(domContext, facesContext, writer, inputComponent,
+						"&nbsp;", null, inputComponent.getDayCellClass(), tr2,
+						null, (weekStartsAtDayIndex + i) % 7, timeKeeper,
+						months, weekdaysLong);
+			}
+		}
 
-        weekdays[0] = localeWeekdays[Calendar.MONDAY];
-        weekdays[1] = localeWeekdays[Calendar.TUESDAY];
-        weekdays[2] = localeWeekdays[Calendar.WEDNESDAY];
-        weekdays[3] = localeWeekdays[Calendar.THURSDAY];
-        weekdays[4] = localeWeekdays[Calendar.FRIDAY];
-        weekdays[5] = localeWeekdays[Calendar.SATURDAY];
-        weekdays[6] = localeWeekdays[Calendar.SUNDAY];
+	}
 
-        return weekdays;
-    }
+	private void writeCell(DOMContext domContext, FacesContext facesContext,
+			ResponseWriter writer, SelectInputDate component, String content,
+			Date valueForLink, String styleClass, Element tr, String imgSrc,
+			int weekDayIndex, Calendar timeKeeper, String[] months,
+			String[] weekdaysLong) throws IOException {
+		Element td = domContext.createElement(HTML.TD_ELEM);
+		tr.appendChild(td);
 
-    /**
-     * @param symbols
-     * @return months - String[] containing localized month names
-     */
-    public static String[] mapMonths(DateFormatSymbols symbols) {
-        String[] months = new String[12];
+		if (styleClass != null) {
+			td.setAttribute(HTML.CLASS_ATTR, styleClass);
+		}
 
-        String[] localeMonths = symbols.getMonths();
+		if (valueForLink == null) {
+			if (content != null && content.length() > 0) {
+				Text text = domContext.createTextNode(content);
+				td.setAttribute(HTML.TITLE_ATTR, weekdaysLong[weekDayIndex]);
+				td.appendChild(text);
+			}
+		} else {
+			// set cursor to render into the td
+			domContext.setCursorParent(td);
+			domContext.streamWrite(facesContext, component, domContext
+					.getRootNode(), td);
+			writeLink(content, component, facesContext, valueForLink,
+					styleClass, imgSrc, td, timeKeeper, months, weekdaysLong);
+			// steps to the position where the next sibling should be rendered
+			domContext.stepOver();
+		}
 
-        months[0] = localeMonths[Calendar.JANUARY];
-        months[1] = localeMonths[Calendar.FEBRUARY];
-        months[2] = localeMonths[Calendar.MARCH];
-        months[3] = localeMonths[Calendar.APRIL];
-        months[4] = localeMonths[Calendar.MAY];
-        months[5] = localeMonths[Calendar.JUNE];
-        months[6] = localeMonths[Calendar.JULY];
-        months[7] = localeMonths[Calendar.AUGUST];
-        months[8] = localeMonths[Calendar.SEPTEMBER];
-        months[9] = localeMonths[Calendar.OCTOBER];
-        months[10] = localeMonths[Calendar.NOVEMBER];
-        months[11] = localeMonths[Calendar.DECEMBER];
+	}
 
-        return months;
-    }
+	private void writeLink(String content, SelectInputDate component,
+			FacesContext facesContext, Date valueForLink, String styleClass,
+			String imgSrc, Element td, Calendar timeKeeper, String[] months,
+			String[] weekdaysLong) throws IOException {
 
-    /**
-     * @param facesContext
-     * @param uiComponent
-     * @return id - used for the commandlink hidden field in the form
-     */
-    public String getLinkId(FacesContext facesContext,
-                            UIComponent uiComponent) {
-        //this is a fix for bug 340
-        UIComponent form = findForm(uiComponent);
-        String formId = form.getClientId(facesContext);
-        return formId + ":_idcl";
-    }
+		Converter converter = component.resolveDateTimeConverter(facesContext);
+		HtmlCommandLink link = new HtmlCommandLink();
+		Calendar cal = copyCalendar(facesContext, timeKeeper);
+		cal.setTime(valueForLink);
+		String month = months[cal.get(Calendar.MONTH)];
+		String year = String.valueOf(cal.get(Calendar.YEAR));
+		int dayInt = cal.get(Calendar.DAY_OF_WEEK);
+		dayInt = mapCalendarDayToCommonDay(dayInt);
+		String day = weekdaysLong[dayInt];
+		String altText = null;
+		String titleText = null;
+		// assign special ids for navigation links
+		if (content.equals("<")) {
+			link.setId(component.getId() + this.PREV_MONTH);
+			altText = getMessageWithParamFromResource(facesContext,
+					PREV_MONTH_ALT, month);
+			titleText = getMessageWithParamFromResource(facesContext,
+					PREV_MONTH_TITLE, month);
+		} else if (content.equals(">")) {
+			link.setId(component.getId() + this.NEXT_MONTH);
+			altText = getMessageWithParamFromResource(facesContext,
+					NEXT_MONTH_ALT, month);
+			titleText = getMessageWithParamFromResource(facesContext,
+					NEXT_MONTH_TITLE, month);
+		} else if (content.equals(">>")) {
+			link.setId(component.getId() + this.NEXT_YEAR);
+			altText = getMessageWithParamFromResource(facesContext,
+					NEXT_YEAR_ALT, year);
+			titleText = getMessageWithParamFromResource(facesContext,
+					NEXT_YEAR_TITLE, year);
+		} else if (content.equals("<<")) {
+			link.setId(component.getId() + this.PREV_YEAR);
+			altText = getMessageWithParamFromResource(facesContext,
+					PREV_YEAR_ALT, year);
+			titleText = getMessageWithParamFromResource(facesContext,
+					PREV_YEAR_TITLE, year);
+		} else {
+			link.setId(component.getId() + "_" + content.hashCode()
+					+ this.CALENDAR);
+			if (log.isDebugEnabled()) {
+				log.debug("linkId=" + component.getId() + "_"
+						+ content.hashCode() + this.CALENDAR);
+			}
+		}
 
-    private boolean checkLink(String clickedLink, String clientId) {
-        if (clickedLink == null) {
-            return false;
-        }
-        boolean found = false;
-        String REGEX = clientId;
-        String INPUT = clickedLink;
-        Pattern pattern;
-        Matcher matcher;
+		link.setPartialSubmit(true);
+		link.setTransient(true);
+		link.setImmediate(component.isImmediate());
+		link.setDisabled(((SelectInputDate) component).isDisabled());
 
-        pattern = Pattern.compile(REGEX);
-        matcher = pattern.matcher(INPUT);
+		if (imgSrc != null) {
+			HtmlGraphicImage img = new HtmlGraphicImage();
+			if (component.isImageDirSet()) {
+				img.setUrl(imgSrc);
+			} else {
+				// ICE-2127: allow override of button images via CSS
+				// getImageDir() returns default
+				// without a dummy image Firefox would show the alt text
+				img.setUrl(component.getImageDir() + "spacer.gif");
+				if (content.equals("<") || content.equals("<<")) {
+					img.setStyleClass(component.getMovePrevClass());
+				} else if (content.equals(">") || content.equals(">>")) {
+					img.setStyleClass(component.getMoveNextClass());
+				}
+			}
+			img.setHeight("16");
+			img.setWidth("17");
+			img.setStyle("border:none;");
+			if (altText != null)
+				img.setAlt(altText);
+			if (titleText != null)
+				img.setTitle(titleText);
+			img.setId(component.getId() + "_" + content.hashCode() + "_img");
+			img.setTransient(true);
+			link.getChildren().add(img);
+		} else {
+			HtmlOutputText text = new HtmlOutputText();
+			text.setValue(content);
+			text.setId(component.getId() + "_" + content.hashCode() + "_text");
+			text.setTransient(true);
+			text.setTitle(day);
+			link.getChildren().add(text);
+		}
+		// links are focus aware
+		UIParameter parameter = new UIParameter();
+		parameter.setId(component.getId() + "_" + valueForLink.getTime()
+				+ "_param");
+		parameter.setTransient(true);
+		parameter.setName(component.getClientId(facesContext));
+		parameter.setValue(converter.getAsString(facesContext, component,
+				valueForLink));
 
-        while (matcher.find()) {
-            found = true;
-        }
+		component.getChildren().add(link);
+		link.getChildren().add(parameter);
 
-        return found;
-    }
+		// don't add this parameter for next and previouse button/link
+		if (!content.equals("<") && !content.equals(">")
+				&& !content.equals(">>") && !content.equals("<<")) {
+			// this parameter would be use to close the popup selectinputdate
+			// after date selection.
+			parameter = new UIParameter();
+			parameter.setId(component.getId() + "_" + valueForLink.getTime()
+					+ "_" + DATE_SELECTED);
+			parameter.setName(getHiddenFieldName(facesContext, component));
+			parameter.setValue("false");
+			link.getChildren().add(parameter);
+		}
+		link.encodeBegin(facesContext);
+		link.encodeChildren(facesContext);
+		link.encodeEnd(facesContext);
+		td.setAttribute(HTML.ID_ATTR, link.getClientId(facesContext) + "td");
+		try {
+			Integer.parseInt(content);
+			((SelectInputDate) component).getLinkMap().put(
+					link.getClientId(facesContext), td);
+			if (styleClass.equals(CSS_DEFAULT.DEFAULT_CALENDAR
+					+ CSS_DEFAULT.DEFAULT_CURRENTDAYCELL_CLASS)) {
+				((SelectInputDate) component).setSelectedDayLink(link
+						.getClientId(facesContext));
+			}
+		} catch (NumberFormatException e) {
 
-    /* (non-Javadoc)
-    * @see com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer#decode(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
-    */
-    public void decode(FacesContext facesContext, UIComponent component) {
-        validateParameters(facesContext, component, SelectInputDate.class);
-        Map requestParameterMap =
-                facesContext.getExternalContext().getRequestParameterMap();
-        Object linkId = getLinkId(facesContext, component);
-        Object clickedLink = requestParameterMap.get(linkId);
-        String clientId = component.getClientId(facesContext);
+		}
 
-        if (clickedLink != null) {
-            if (log.isDebugEnabled()) {
-                log.debug("linkId::" + linkId + "  clickedLink::" +
-                          clickedLink + "  clientId::" + clientId);
-            }
-            
-            String sclickedLink = (String) clickedLink;
-            if (checkLink(sclickedLink, clientId)) {
-                if (log.isDebugEnabled()) {
-                    log.debug("---------------------------------");
-                    log.debug("----------START::DECODE----------");
-                    log.debug("---------------------------------");
-                    log.debug("decode::linkId::" + linkId + "=" + clickedLink +
-                              " clientId::" + clientId);
-                }
+	}
 
-                if (sclickedLink.endsWith(this.PREV_MONTH) ||
-                    sclickedLink.endsWith(this.NEXT_MONTH) ||
-                    sclickedLink.endsWith(this.PREV_YEAR) ||
-                    sclickedLink.endsWith(this.NEXT_YEAR)) {
-                    if (log.isDebugEnabled()) {
-                        log.debug("-------------Navigation Event-------------");
-                    }
-                    decodeNavigation(facesContext, component);
-                } else if (sclickedLink.endsWith(this.CALENDAR)) {
-                    if (log.isDebugEnabled()) {
-                        log.debug(
-                                "-------------Select Date Event-------------");
-                    }
-                    decodeSelectDate(facesContext, component);
-                } else if (sclickedLink.endsWith(this.CALENDAR_BUTTON)) {
-                    if (log.isDebugEnabled()) {
-                        log.debug(
-                                "-------------Popup Event-------------------");
-                    }
-                    decodePopup(facesContext, component);
-                }
-            } else {
-                if (log.isDebugEnabled()) {
-                    log.debug("-------------InputText enterkey Event ??----");
-                }
-                decodeInputText(facesContext, component);
-            }
+	protected void addAttributeToElementFromResource(FacesContext facesContext,
+			String resName, Element elem, String attrib) {
+		String res = MessageUtils.getResource(facesContext, resName);
+		if (res != null && res.length() > 0) {
+			elem.setAttribute(attrib, res);
+		}
+	}
 
-        }
-    }
+	protected String getMessageWithParamFromResource(FacesContext facesContext,
+			String resName, String param) {
+		String msg = null;
+		if (param != null && param.length() > 0) {
+			String messagePattern = MessageUtils.getResource(facesContext,
+					resName);
+			if (messagePattern != null && messagePattern.length() > 0) {
+				msg = MessageFormat.format(messagePattern,
+						new Object[] { param });
+			}
+		}
+		return msg;
+	}
 
-    private void decodeNavigation(FacesContext facesContext,
-                                  UIComponent component) {
-        Map requestParameterMap =
-                facesContext.getExternalContext().getRequestParameterMap();
-        SelectInputDate dateSelect = (SelectInputDate) component;
+	private int mapCalendarDayToCommonDay(int day) {
+		switch (day) {
+		case Calendar.TUESDAY:
+			return 1;
+		case Calendar.WEDNESDAY:
+			return 2;
+		case Calendar.THURSDAY:
+			return 3;
+		case Calendar.FRIDAY:
+			return 4;
+		case Calendar.SATURDAY:
+			return 5;
+		case Calendar.SUNDAY:
+			return 6;
+		default:
+			return 0;
+		}
+	}
 
-        // set the navDate on the Calendar
-        if (log.isDebugEnabled()) {
-            log.debug("setNavDate::");
-            log.debug("#################################");
-        }
-        dateSelect.setNavEvent(true);
-        dateSelect.setNavDate(
-            (Date) getConvertedValue(
-                facesContext, dateSelect, requestParameterMap.get(
-                    dateSelect.getClientId(facesContext))));
-    }
+	private static String[] mapWeekdays(DateFormatSymbols symbols) {
+		String[] weekdays = new String[7];
 
-    private void decodePopup(FacesContext facesContext, UIComponent component) {
-        Map requestParameterMap =
-                facesContext.getExternalContext().getRequestParameterMap();
-        String popupState = getHiddenFieldName(facesContext, component);
-        String showPopup = (String) requestParameterMap.get(popupState);
-        SelectInputDate dateSelect = (SelectInputDate) component;
+		String[] localeWeekdays = symbols.getShortWeekdays();
 
-        if (log.isDebugEnabled()) {
-            log.debug("decodePopup::" + showPopup);
-            log.debug("#################################");
-        }
-        // check showPopup
-        if (showPopup != null) {
+		weekdays[0] = localeWeekdays[Calendar.MONDAY];
+		weekdays[1] = localeWeekdays[Calendar.TUESDAY];
+		weekdays[2] = localeWeekdays[Calendar.WEDNESDAY];
+		weekdays[3] = localeWeekdays[Calendar.THURSDAY];
+		weekdays[4] = localeWeekdays[Calendar.FRIDAY];
+		weekdays[5] = localeWeekdays[Calendar.SATURDAY];
+		weekdays[6] = localeWeekdays[Calendar.SUNDAY];
 
-            dateSelect.setShowPopup(!dateSelect.isShowPopup());
-        }
-        // not a nav event
-        dateSelect.setNavEvent(false);
-    }
+		return weekdays;
+	}
 
-    private void decodeSelectDate(FacesContext facesContext,
-                                  UIComponent component) {
+	private static String[] mapWeekdaysLong(DateFormatSymbols symbols) {
+		String[] weekdays = new String[7];
 
-        Map requestParameterMap =
-                facesContext.getExternalContext().getRequestParameterMap();
-        String popupState = getHiddenFieldName(facesContext, component);
-        String showPopup = (String) requestParameterMap.get(popupState);
-        SelectInputDate dateSelect = (SelectInputDate) component;
+		String[] localeWeekdays = symbols.getWeekdays();
 
-        if (log.isDebugEnabled()) {
-            log.debug("selectDate::showPopup" + showPopup);
-            log.debug("#################################");
-        }
-        if (showPopup != null) {
-            if (showPopup.equalsIgnoreCase("true")) {
-                dateSelect.setShowPopup(true);
-            } else {
-                dateSelect.setShowPopup(false);
-            }
-        }
-        if (log.isDebugEnabled()) {
-            log.debug("decodeUIInput::");
-            log.debug("#################################");
-        }
-        String inputDateTextId = component.getClientId(facesContext) +
-            SelectInputDate.CALENDAR_INPUTTEXT;
-        if (requestParameterMap.containsKey(inputDateTextId)) {
-            String inputDateButtonId = component.getClientId(facesContext) +
-                CALENDAR_BUTTON;
-            ((BridgeFacesContext)facesContext).setFocusId(inputDateButtonId);
-        }
-        CustomComponentUtils.decodeUIInput(facesContext, component);
-        // not a navigation event
-        dateSelect.setNavEvent(false);
-    }
+		weekdays[0] = localeWeekdays[Calendar.MONDAY];
+		weekdays[1] = localeWeekdays[Calendar.TUESDAY];
+		weekdays[2] = localeWeekdays[Calendar.WEDNESDAY];
+		weekdays[3] = localeWeekdays[Calendar.THURSDAY];
+		weekdays[4] = localeWeekdays[Calendar.FRIDAY];
+		weekdays[5] = localeWeekdays[Calendar.SATURDAY];
+		weekdays[6] = localeWeekdays[Calendar.SUNDAY];
 
-    private void decodeInputText(FacesContext facesContext,
-                                 UIComponent component) {
-        Map requestParameterMap =
-                facesContext.getExternalContext().getRequestParameterMap();
-        String popupState = getHiddenFieldName(facesContext, component);
-        String showPopup = (String) requestParameterMap.get(popupState);
-        SelectInputDate dateSelect = (SelectInputDate) component;
-        String clientId = dateSelect.getClientId(facesContext);
-        Object linkId = getLinkId(facesContext, component);
-        Object clickedLink = requestParameterMap.get(linkId);
+		return weekdays;
+	}
 
-        String inputTextDateId = component.getClientId(facesContext) +
-        SelectInputDate.CALENDAR_INPUTTEXT;
-        Object inputTextDate = requestParameterMap.get(inputTextDateId);
+	/**
+	 * @param symbols
+	 * @return months - String[] containing localized month names
+	 */
+	public static String[] mapMonths(DateFormatSymbols symbols) {
+		String[] months = new String[12];
 
-        // inputtext is only available in popup mode 
-        if (requestParameterMap.containsKey(inputTextDateId) &&
-            dateSelect.isRenderAsPopup()) {
-            if (log.isDebugEnabled()) {
-                log.debug("decoding InputText EnterKey::");
-                log.debug("###################################");
-            }
-            if (showPopup != null) {
- 
-                
-                if (checkLink((String) clickedLink, clientId)) {
-                    if (showPopup.equalsIgnoreCase("true")) {
-                        dateSelect.setShowPopup(true);
-                    } else {
-                        dateSelect.setShowPopup(false);
-                    }
-                }
-                if (inputTextDate == null) {
-                    dateSelect.setSubmittedValue(null);
-                }
-                else if (String.valueOf(inputTextDate).trim().length() == 0) {
-                    dateSelect.setSubmittedValue("");
-                }
-                else {
-                    dateSelect.setSubmittedValue(inputTextDate);
-                }
-            }
-        }
-    }
+		String[] localeMonths = symbols.getMonths();
 
-    /* (non-Javadoc)
-     * @see com.icesoft.faces.renderkit.dom_html_basic.DomBasicInputRenderer#getConvertedValue(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
-     */
-    public Object getConvertedValue(FacesContext facesContext,
-                                    UIComponent uiComponent,
-                                    Object submittedValue)
-            throws ConverterException {
-        validateParameters(facesContext, uiComponent, SelectInputDate.class);
-        
-        Converter converter = ((SelectInputDate)uiComponent).resolveDateTimeConverter(facesContext);
+		months[0] = localeMonths[Calendar.JANUARY];
+		months[1] = localeMonths[Calendar.FEBRUARY];
+		months[2] = localeMonths[Calendar.MARCH];
+		months[3] = localeMonths[Calendar.APRIL];
+		months[4] = localeMonths[Calendar.MAY];
+		months[5] = localeMonths[Calendar.JUNE];
+		months[6] = localeMonths[Calendar.JULY];
+		months[7] = localeMonths[Calendar.AUGUST];
+		months[8] = localeMonths[Calendar.SEPTEMBER];
+		months[9] = localeMonths[Calendar.OCTOBER];
+		months[10] = localeMonths[Calendar.NOVEMBER];
+		months[11] = localeMonths[Calendar.DECEMBER];
 
-        if (!(submittedValue == null || submittedValue instanceof String)) {
-            throw new IllegalArgumentException(
-                    "Submitted value of type String expected");
-        }
-        Object o = converter.getAsObject(facesContext, uiComponent,
-                (String) submittedValue);
-        
-        return o;
-    }
+		return months;
+	}
+
+	/**
+	 * @param facesContext
+	 * @param uiComponent
+	 * @return id - used for the commandlink hidden field in the form
+	 */
+	public String getLinkId(FacesContext facesContext, UIComponent uiComponent) {
+		// this is a fix for bug 340
+		UIComponent form = findForm(uiComponent);
+		String formId = form.getClientId(facesContext);
+		return formId + ":_idcl";
+	}
+
+	private boolean checkLink(String clickedLink, String clientId) {
+		if (clickedLink == null) {
+			return false;
+		}
+		boolean found = false;
+		String REGEX = clientId;
+		String INPUT = clickedLink;
+		Pattern pattern;
+		Matcher matcher;
+
+		pattern = Pattern.compile(REGEX);
+		matcher = pattern.matcher(INPUT);
+
+		while (matcher.find()) {
+			found = true;
+		}
+
+		return found;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer#decode(javax.faces.context.FacesContext,
+	 *      javax.faces.component.UIComponent)
+	 */
+	public void decode(FacesContext facesContext, UIComponent component) {
+		validateParameters(facesContext, component, SelectInputDate.class);
+		Map requestParameterMap = facesContext.getExternalContext()
+				.getRequestParameterMap();
+		Object linkId = getLinkId(facesContext, component);
+		Object clickedLink = requestParameterMap.get(linkId);
+		String clientId = component.getClientId(facesContext);
+
+		if (clickedLink != null) {
+			if (log.isDebugEnabled()) {
+				log.debug("linkId::" + linkId + "  clickedLink::" + clickedLink
+						+ "  clientId::" + clientId);
+			}
+
+			String sclickedLink = (String) clickedLink;
+			if (checkLink(sclickedLink, clientId)) {
+				if (log.isDebugEnabled()) {
+					log.debug("---------------------------------");
+					log.debug("----------START::DECODE----------");
+					log.debug("---------------------------------");
+					log.debug("decode::linkId::" + linkId + "=" + clickedLink
+							+ " clientId::" + clientId);
+				}
+
+				if (sclickedLink.endsWith(this.PREV_MONTH)
+						|| sclickedLink.endsWith(this.NEXT_MONTH)
+						|| sclickedLink.endsWith(this.PREV_YEAR)
+						|| sclickedLink.endsWith(this.NEXT_YEAR)) {
+					if (log.isDebugEnabled()) {
+						log.debug("-------------Navigation Event-------------");
+					}
+					decodeNavigation(facesContext, component);
+				} else if (sclickedLink.endsWith(this.CALENDAR)) {
+					if (log.isDebugEnabled()) {
+						log
+								.debug("-------------Select Date Event-------------");
+					}
+					decodeSelectDate(facesContext, component);
+				} else if (sclickedLink.endsWith(this.CALENDAR_BUTTON)) {
+					if (log.isDebugEnabled()) {
+						log
+								.debug("-------------Popup Event-------------------");
+					}
+					decodePopup(facesContext, component);
+				}
+			} else {
+				if (log.isDebugEnabled()) {
+					log.debug("-------------InputText enterkey Event ??----");
+				}
+				decodeInputText(facesContext, component);
+			}
+
+		}
+	}
+
+	private void decodeNavigation(FacesContext facesContext,
+			UIComponent component) {
+		Map requestParameterMap = facesContext.getExternalContext()
+				.getRequestParameterMap();
+		SelectInputDate dateSelect = (SelectInputDate) component;
+
+		// set the navDate on the Calendar
+		if (log.isDebugEnabled()) {
+			log.debug("setNavDate::");
+			log.debug("#################################");
+		}
+		dateSelect.setNavEvent(true);
+		dateSelect.setNavDate((Date) getConvertedValue(facesContext,
+				dateSelect, requestParameterMap.get(dateSelect
+						.getClientId(facesContext))));
+	}
+
+	private void decodePopup(FacesContext facesContext, UIComponent component) {
+		Map requestParameterMap = facesContext.getExternalContext()
+				.getRequestParameterMap();
+		String popupState = getHiddenFieldName(facesContext, component);
+		String showPopup = (String) requestParameterMap.get(popupState);
+		SelectInputDate dateSelect = (SelectInputDate) component;
+
+		if (log.isDebugEnabled()) {
+			log.debug("decodePopup::" + showPopup);
+			log.debug("#################################");
+		}
+		// check showPopup
+		if (showPopup != null) {
+
+			dateSelect.setShowPopup(!dateSelect.isShowPopup());
+		}
+		// not a nav event
+		dateSelect.setNavEvent(false);
+	}
+
+	private void decodeSelectDate(FacesContext facesContext,
+			UIComponent component) {
+
+		Map requestParameterMap = facesContext.getExternalContext()
+				.getRequestParameterMap();
+		String popupState = getHiddenFieldName(facesContext, component);
+		String showPopup = (String) requestParameterMap.get(popupState);
+		SelectInputDate dateSelect = (SelectInputDate) component;
+
+		if (log.isDebugEnabled()) {
+			log.debug("selectDate::showPopup" + showPopup);
+			log.debug("#################################");
+		}
+		if (showPopup != null) {
+			if (showPopup.equalsIgnoreCase("true")) {
+				dateSelect.setShowPopup(true);
+			} else {
+				dateSelect.setShowPopup(false);
+			}
+		}
+		if (log.isDebugEnabled()) {
+			log.debug("decodeUIInput::");
+			log.debug("#################################");
+		}
+		String inputDateTextId = component.getClientId(facesContext)
+				+ SelectInputDate.CALENDAR_INPUTTEXT;
+		if (requestParameterMap.containsKey(inputDateTextId)) {
+			String inputDateButtonId = component.getClientId(facesContext)
+					+ CALENDAR_BUTTON;
+			((BridgeFacesContext) facesContext).setFocusId(inputDateButtonId);
+		}
+		CustomComponentUtils.decodeUIInput(facesContext, component);
+		// not a navigation event
+		dateSelect.setNavEvent(false);
+	}
+
+	private void decodeInputText(FacesContext facesContext,
+			UIComponent component) {
+		Map requestParameterMap = facesContext.getExternalContext()
+				.getRequestParameterMap();
+		String popupState = getHiddenFieldName(facesContext, component);
+		String showPopup = (String) requestParameterMap.get(popupState);
+		SelectInputDate dateSelect = (SelectInputDate) component;
+		String clientId = dateSelect.getClientId(facesContext);
+		Object linkId = getLinkId(facesContext, component);
+		Object clickedLink = requestParameterMap.get(linkId);
+
+		String inputTextDateId = component.getClientId(facesContext)
+				+ SelectInputDate.CALENDAR_INPUTTEXT;
+		Object inputTextDate = requestParameterMap.get(inputTextDateId);
+
+		// inputtext is only available in popup mode
+		if (requestParameterMap.containsKey(inputTextDateId)
+				&& dateSelect.isRenderAsPopup()) {
+			if (log.isDebugEnabled()) {
+				log.debug("decoding InputText EnterKey::");
+				log.debug("###################################");
+			}
+			if (showPopup != null) {
+
+				if (checkLink((String) clickedLink, clientId)) {
+					if (showPopup.equalsIgnoreCase("true")) {
+						dateSelect.setShowPopup(true);
+					} else {
+						dateSelect.setShowPopup(false);
+					}
+				}
+				if (inputTextDate == null) {
+					dateSelect.setSubmittedValue(null);
+				} else if (String.valueOf(inputTextDate).trim().length() == 0) {
+					dateSelect.setSubmittedValue("");
+				} else {
+					dateSelect.setSubmittedValue(inputTextDate);
+				}
+			}
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see com.icesoft.faces.renderkit.dom_html_basic.DomBasicInputRenderer#getConvertedValue(javax.faces.context.FacesContext,
+	 *      javax.faces.component.UIComponent, java.lang.Object)
+	 */
+	public Object getConvertedValue(FacesContext facesContext,
+			UIComponent uiComponent, Object submittedValue)
+			throws ConverterException {
+		validateParameters(facesContext, uiComponent, SelectInputDate.class);
+
+		Converter converter = ((SelectInputDate) uiComponent)
+				.resolveDateTimeConverter(facesContext);
+
+		if (!(submittedValue == null || submittedValue instanceof String)) {
+			throw new IllegalArgumentException(
+					"Submitted value of type String expected");
+		}
+		Object o = converter.getAsObject(facesContext, uiComponent,
+				(String) submittedValue);
+
+		return o;
+	}
 }
Index: D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/paneltabset/PanelTabSetRenderer.java
===================================================================
--- D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/paneltabset/PanelTabSetRenderer.java	(revision 16406)
+++ D:/Documents and Settings/pbreau/workspace/icefaces-trunk-ossrepo/component/src/com/icesoft/faces/component/paneltabset/PanelTabSetRenderer.java	(working copy)
@@ -612,7 +612,7 @@
             String nextKey;
             while (parameterKeys.hasNext()) {
                 nextKey = (String) parameterKeys.next();
-                FormRenderer.addHiddenField(facesContext, nextKey);
+                domContext.createHiddenField(tr, nextKey);               
             }
 
         }
