<% 
  String enc = request.getParameter("enc");
  if ((enc == null) || "".equals(enc))
    response.setContentType("text/html");
  else
    response.setContentType("text/html;charset=" + enc);
%>
<%@ page import='java.util.Date'%>
<%@ page import='java.util.SimpleTimeZone'%>
<%@ page import='oracle.bali.share.nls.LocaleUtils'%>
<%@ page import='oracle.cabo.share.config.Configuration'%>
<%@ page import='oracle.cabo.share.nls.LocaleContext'%>
<%@ page import='oracle.cabo.ui.ServletRenderingContext'%>
<%@ page import='oracle.cabo.ui.TextNode'%>
<%@ page import='oracle.cabo.ui.UIConstants'%>
<%@ page import='oracle.cabo.ui.beans.BodyBean'%>
<%@ page import='oracle.cabo.ui.beans.HeadBean'%>
<%@ page import='oracle.cabo.ui.beans.MarlinBean'%>
<%@ page import='oracle.cabo.ui.beans.ScriptBean'%>
<%@ page import='oracle.cabo.ui.beans.form.FormBean'%>
<%@ page import='oracle.cabo.ui.beans.layout.TableLayoutBean'%>
<%@ page import='oracle.cabo.ui.beans.layout.RowLayoutBean'%>
<%@ page import='oracle.cabo.ui.beans.layout.SpacerBean'%>
<%@ page import='oracle.cabo.ui.beans.nav.ButtonBean'%>
<%@ page import='oracle.cabo.ui.laf.base.BaseLafRenderer'%>
<%//567890123456789012345678901234567890123456789012345678901234567890123456789
  String localeName = request.getParameter("loc");
  
  final LocaleContext localeContext = new LocaleContext(
    LocaleUtils.getLocaleForIANAString(localeName));

  ServletRenderingContext rContext = new ServletRenderingContext(pageContext)
  {
    public LocaleContext getLocaleContext()
    {
      return localeContext;
    }
  };

  //
  // set the correct configuration
  //
  rContext.setConfiguration((String)request.getParameter("configName"));
  
  //
  // Configure the time zone if its offset is different than our current
  // offset
  //
  String zoneOffset = (String)request.getParameter("tzOffset");
    
  if (zoneOffset != null)
  {
    int tzOffset = Integer.parseInt(zoneOffset);
    
    if (tzOffset != new Date().getTimezoneOffset())
    {        
      // create the new time zone with the offset in milliseconds
      rContext.getLocaleContext().setTimeZone(
                                new SimpleTimeZone(tzOffset * -60 * 1000, ""));
    }
  }

  // Set the context URI and path if they are specified
  String contextURI = (String)request.getParameter("contextURI");
  if (contextURI != null)
  {
    rContext.setProperty(UIConstants.MARLIN_NAMESPACE,
                         rContext.CONTEXT_URI_PROPERTY,
                         contextURI);
  }

  String contextPath = (String)request.getParameter("contextPath");
  if (contextPath != null)
  {
    rContext.setProperty(UIConstants.MARLIN_NAMESPACE,
                         rContext.CONTEXT_PATH_PROPERTY,
                         contextPath);
  }

%><jsp:useBean id="root"
             scope="request"
             class="oracle.cabo.ui.beans.DocumentBean"><%
  
  TableLayoutBean layout = new TableLayoutBean();

  //
  // Create the calendar row
  //
  RowLayoutBean calendarRow = new RowLayoutBean();
  calendarRow.setHAlign("end");
  
  MarlinBean calendar = new MarlinBean(UIConstants.CALENDAR_NAME);

  calendar.setAttributeValue(UIConstants.DESTINATION_ATTR,
                             "calendarDialog.jsp");

  Object minTimeObject = request.getParameter(
    UIConstants.MIN_VALUE_ATTR.getAttributeName());

  if (minTimeObject != null)
  {
    calendar.setAttributeValue(UIConstants.MIN_VALUE_ATTR,
                               Long.valueOf((String)minTimeObject));
  }
  
  Object maxTimeObject = request.getParameter(
    UIConstants.MAX_VALUE_ATTR.getAttributeName());

  if (maxTimeObject != null)
  {
    calendar.setAttributeValue(UIConstants.MAX_VALUE_ATTR,
                               Long.valueOf((String)maxTimeObject));
  }

  Object selectedTimeObject = request.getParameter(
    UIConstants.VALUE_ATTR.getAttributeName());
  
  if (selectedTimeObject != null)
  {
    calendar.setAttributeValue(UIConstants.VALUE_ATTR,
                               Long.valueOf((String)selectedTimeObject));
  }

  Object displayTimeObject = request.getParameter(
    UIConstants.SCROLLED_VALUE_ATTR.getAttributeName());

  if (displayTimeObject != null)
  {
    calendar.setAttributeValue(UIConstants.SCROLLED_VALUE_ATTR,
                               Long.valueOf((String)displayTimeObject));
  }

  calendarRow.addIndexedChild(calendar);
  
  //
  // Create a spacer row
  //
  RowLayoutBean spacerRow = new RowLayoutBean();
  spacerRow.addIndexedChild(new SpacerBean(1, 8));
  
  //
  // Create the button row
  //
  RowLayoutBean buttonRow = new RowLayoutBean();
  buttonRow.setHAlign("end");
  
  String cancelLabel = BaseLafRenderer.getTranslatedString(
                                                        rContext,
                                                        "CANCEL_BUTTON_LABEL");
  
  ButtonBean cancelButton = new ButtonBean(cancelLabel, "");
  cancelButton.setOnClick("return doCancel()");
  
  buttonRow.addIndexedChild(cancelButton);
  
  //
  // Add the rows to the stacker
  //
  layout.addIndexedChild(calendarRow);
  layout.addIndexedChild(spacerRow);
  layout.addIndexedChild(buttonRow);

  // create a form bean with a dummy name
  FormBean form = new FormBean("a");
  form.addIndexedChild(layout);
  
  BodyBean body = new BodyBean();
  
  body.addIndexedChild(form);
  root.addIndexedChild(body);

  HeadBean head = new HeadBean();
  head.setTitle(BaseLafRenderer.getTranslatedString(rContext,
                                                    "CALENDAR_DIALOG_TITLE"));

  ScriptBean scripts = new ScriptBean();
  scripts.addIndexedChild(new TextNode(
  "function doCancel()" + 
  "{" +
   "top.returnValue = (void 0);" +
   "top.close();" +
   "return false;" +
  "}" +
  
  "function selectDate(dateTime)" +
  "{" +
    // fix up for daylight savings time hose
    "var dstDate = new Date(dateTime);" +
    "var hours = dstDate.getHours();" +
    
    "if (hours >= 12)" +
    "{" +
      "hours = 24;" +
    "}" +
    
    "dstDate.setHours(hours);" +
          
    "top.returnValue = dstDate.getTime();" +
    "top.close();" +
    
    "return false;" +
  "}"));

  head.addIndexedChild(scripts);

  root.setMetaContainer(head);
%></jsp:useBean><%
  root.render(rContext);
%>