// *** BUG - DO NOT DELETE THIS LINE ***
var calendar;
var fieldID;
    
function calendarCreate()
{ calendar = new Calendar(0, null, calendarOnSelect, calendarOnClose);
    
  calendar.weekNumbers = false;
  calendar.showsTime = false;
//  calendar.setDateFormat('%Y-%m-%d %H:%M');
  calendar.setDateFormat('%Y-%m-%d');

  calendar.create();

  //calendar.parseDate('sub- date -sub');
}

function calendarSet(date, id)
{ 
  calendar.parseDate(date);
  fieldID = id;
}

function calendarShow(id)
{ if (id) // show at the element provided
  { calendar.showAtElement(document.getElementById(id), 'Bl');
  } else // or show in the center of the browser window
  { var clientWidth, clientHeight, calendarWidth = 200, calendarHeight = 160;
    if (document.all)
    { clientWidth = document.body.clientWidth;
      clientHeight = document.body.clientHeight;
    } else
    { clientWidth = innerWidth;
      clientHeight = innerHeight;
    }
    calendar.showAt(clientWidth/2 - calendarWidth/2, clientHeight/2 - calendarHeight/2 + document.body.scrollTop);
  }
}

function calendarOnSelect(cal, date)
{ 
//  var id = 'shop_frame_date';
  var id = fieldID;
  if (!document.getElementById) return;
  if (cal.dateClicked)
  { document.getElementById(id).value = date;
    cal.callCloseHandler();
  } else
  { var val = document.getElementById(id).value;
    var cdate = val.substring(0, 11);
    var ctime = val.substring(11);
    var stime = date.substring(11);
    if (ctime != stime) document.getElementById(id).value = cdate + stime;
  }
}

function calendarOnClose(cal)
{ cal.hide();
  // or cal.destroy();
}

var orig = window.onload;
window.onload = function()
{ if (typeof orig == 'function') { orig(); } else { eval(orig); }
  calendarCreate();
};
