// Javascript Calendar Popup for Date Setting

function calendar(fieldName, onclick)
{
  // Assign Methods
  this.popup = popup;

  // Save the field names
  this.fieldName = fieldName;
  this.yearField = fieldName + 'YY';
  this.monthField = fieldName + 'MM';
  this.dayField = fieldName + 'DD';
  this.onClick = onclick;
}

// Generate the popup
function popup()
{
  this.date = document.getElementById(this.yearField).value + '-' + document.getElementById(this.monthField).value + '-' + document.getElementById(this.dayField).value;

  if (this.date == '--')
  {
    today = new Date;
    this.date =  today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
  }

  if (this.onClick)
    var onclick = '&onclick=true';

  var calWindow = window.open('/calendar/?field=' + this.fieldName + '&current=' + this.date + onclick,
                              'Calendar', 'width=200,height=150,status=no,resizable=no,top=250,left=250,dependant=yes,alwaysraised=yes');
  calWindow.opener = window;
  calWindow.focus();
}