﻿var calendar = null;

// This function gets called when an end-user clicks on some date
function selected(cal, date) {
  //alert(cal.sel.id);
  cal.sel.value = date; // just update the value of the input field  
  if (cal.sel.id.substring(0,2)=="XX")  //這是明暇自己做的特殊處理，如果為XX打頭的日期ID,要另外作驗証
  	//displayFormInfo();  
  	displayNext();  //add by mhhsu為了點選完日期，還要做跨月的驗證，要顯示下一步
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
  cal.hide();			// hide the calendar
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id) {
  var el = document.getElementById(id);

  if (calendar != null) {
    // we already have one created, so just update it.
    calendar.hide();		// hide the existing calendar
    calendar.parseDate(el.value); // set it to a new date    
  } else {
    // first-time call, create the calendar
   var cal = new Calendar(true, null, selected, closeHandler);

    calendar = cal;		// remember the calendar in the global
    cal.setRange(1900, 2100);	// min/max year allowed
    // uncomment the following to hide the week numbers
    // calendar.weekNumbers = false;
    calendar.create();		// create a popup calendar
  }
  calendar.sel = el;		// inform it about the input field in use
  calendar.showAtElement(el);	// show the calendar next to the input field
  return false;
}
function showCalendars(id,index) {
  //var el = document.getElementById(id);
  var el = document.getElementsByName(id);
  if (calendar != null) {
    // we already have one created, so just update it.
    calendar.hide();		// hide the existing calendar
    calendar.parseDate(el[index].value); // set it to a new date
  } else {
    // first-time call, create the calendar
    var cal = new Calendar(true, null, selected, closeHandler);
    calendar = cal;		// remember the calendar in the global
    cal.setRange(1900, 2100);	// min/max year allowed
    // uncomment the following to hide the week numbers
    // calendar.weekNumbers = false;
    calendar.create();		// create a popup calendar
  }
  calendar.sel = el[index];		// inform it about the input field in use
  calendar.showAtElement(el[index]);	// show the calendar next to the input field
  return false;
}