﻿//====
//use the DateComboBox variable in your script.
//====
function _DateComboBoxCls_() {}
//----
_DateComboBoxCls_.prototype.getTag = function(tagID) {
	if (typeof(tagID) != "string") return null;
	else {
		if (document.getElementById) return document.getElementById(tagID);
		if (document.all) return document.all[tagID];
		if (document.layers) return document.layers[tagID];
	}
}
//----
_DateComboBoxCls_.prototype.isLeapYear = function(year) {
  if (year % 400 == 0) return true;
  else {
    if (year % 100 == 0) return false;
    else return (year % 4 == 0) ? true : false;
  }
}
//----
_DateComboBoxCls_.prototype.isValueValid = function(tagID) {
  try {
    var s = this.getTag(tagID + "Year").value;
    var yr = parseInt(s, 10);
    s = this.getTag(tagID + "Month").value;
    var mn = parseInt(s, 10);
    s = this.getTag(tagID + "Day").value;
    var dy = parseInt(s, 10);
    var r = false;
    switch (mn) {
      case  2 : r = (this.isLeapYear(yr) == true) ? (dy <= 29) : (dy <= 28); break;
      case  4 : r = (dy <= 30); break;
      case  6 : r = (dy <= 30); break;
      case  9 : r = (dy <= 30); break;
      case 11 : r = (dy <= 30); break;
      default : r = true; break;
    }
    return r;
  }
  catch (e) {
    return false;
  }
}
//----
_DateComboBoxCls_.prototype.getValue = function(tagID) {
  return this.getTag(tagID + "Year").value + this.getTag(tagID + "Month").value +
         this.getTag(tagID + "Day").value;
}
//----
_DateComboBoxCls_.prototype.parseYYYYMMDD = function(yyyyMMdd)	{
  var tagType = typeof(yyyyMMdd);
  if (tagType != "string") return null;
  else {
    if (yyyyMMdd.length < 6) return null;
    else {
      var x = new Date();
      x.setFullYear(parseInt(yyyyMMdd.substr(0, 4), 10));
      x.setMonth(parseInt(yyyyMMdd.substr(4, 2), 10) - 1);
      var dy = (yyyyMMdd.length < 8) ? 1 : parseInt(yyyyMMdd.substr(6, 2), 10);
      x.setDate(dy);
      x.setHours(0);
      x.setMinutes(0);
      x.setSeconds(0);
      return x;
    }
  }
}
//----
var DateComboBox = new _DateComboBoxCls_();

