function cxlObject(){
  this.getForm =
    function()
    {
      return document.forms[this.formName];
    };

  this.imageSelect =
    function()
    {
      window.open(cxlPage.imageSelection + '?dispatch=images&id=' + cxlPage.id, 'image', 'width=750, height=400, screenX=300, screenY=100, top=100,left=300, resizable=yes');
    };
  this.addCalendar =
    function(fieldId, buttonId, sOptions)
    {
      if (!this.calendars)
        this.calendars = new Array();
      this.calendars[fieldId] = {field:fieldId, button:buttonId, options:sOptions};
      if (sOptions=='startdate')
        this.startCalendar = fieldId;
      if (sOptions=='enddate')
        this.endCalendar = fieldId;
    };

  //utility functions for the calendars
  this.invalidDate =
    function(d)
    {
      startDateElement = document.getElementById(cxlPage.startCalendar);
      startDate = Date.parseDate(startDateElement.value, "m/%d/%Y");
      return (d < startDate);
    };

  //utility functions for the calendars
  this.blockRange =
    function(d)
    {
      ret = true;
      out = '';
      if (cxlPage.blockedDates)
      {
        if (d.getDay()==0) // block all sundays
          ret = true;
        else
        {
          blockedDates = cxlPage.blockedDates;
          ret = false;
          for (i=0;i<blockedDates.length;i++)
          {
            startDate = new Date(blockedDates[i].start);
            endDate = new Date(blockedDates[i].end);
            options = blockedDates[i].options;
            if (options=='yearly')
              d.setYear(startDate.getFullYear());
            if (d>=startDate && d<=endDate)
              ret = true;
          }
        }
        return ret;
      }
    };

  this.setEndDate =
    function setEndDate(cal)
    {
      startDateElement = document.getElementById(cxlPage.startCalendar);
      endDateElement = document.getElementById(cxlPage.endCalendar);

      if (startDateElement.value != '' && endDateElement.value == '')
        endDateElement.value = startDateElement.value;
    }

  this.initCalendars =
    function() {
      for (i in cxlPage.calendars)
      {
        var calendar = cxlPage.calendars[i];
        if (document.getElementById(calendar.field))
        {
          switch(calendar.options)
          {
            case 'startdate':
              cxlPage.calendars[i].object =
                Calendar.setup({inputField:calendar.field, button:calendar.button, ifFormat:"%m/%d/%Y", step:1, showsTime:false, onUpdate:cxlPage.setEndDate});
              break;
            case 'enddate':
              cxlPage.calendars[i].object =
                Calendar.setup({inputField:calendar.field, button:calendar.button, ifFormat:"%m/%d/%Y", step:1, showsTime:false, disableFunc:cxlPage.invalidDate});
              break;
            default:
              cxlPage.calendars[i].object =
                Calendar.setup({inputField:calendar.field, button:calendar.button, ifFormat:"%m/%d/%Y", step:1, showsTime:false, disableFunc:cxlPage.blockRange});
              break;
          }
        }

      }
    }

}

// utility functions for the form
// need to become part of cxlobject
function set(target) {
  cxlPage.getForm().dispatch.value = target;
}

function submitForm(target) {
  set(target);
  cxlPage.getForm().submit();
}

function initNeverExpires() {
  frm = cxlPage.getForm();
  frm.neverExpire.checked = (frm.expirationDate.value == '');
}

function checkFeatured() {
  frm = cxlPage.getForm();
  frm.pressRelease.checked = false;
}

function checkPressRelease() {
  frm = cxlPage.getForm();
  frm.featured.checked = false;
}

function deleteImage(image) {
  frm = cxlPage.getForm();
  if (confirm(cxlPage.confirmDelete)) {
    var theLink = cxlPage.imageSelection + '?dispatch=delete&id=' + image;
    window.location.href = theLink;
  }
}

