//author:Tracy
//2007.7.13
var cpdCalendar = {};
cpdCalendar.Calendar = function () {
};
cpdCalendar.Calendar.prototype = {months:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], bDay:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31], sDay:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30], lFebruary:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], february:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28], init:function (year, month, day, wy, wm, wd) {

	DWRUtil.removeAllOptions(day);
	DWRUtil.removeAllOptions(month);
	DWRUtil.addOptions(month, this.months);
	if (wy !== "" && wy!== undefined) {//å›žæ˜¾
    //is leap or not
		var leap = (wy % 4 === 0 && (wy % 100 !== 0 || wy % 400 === 0));	
		if (wm == 4 || wm == 6 || wm == 9 || wm == 11) {
			DWRUtil.addOptions(day, this.sDay);
		} else {
			if (wm == 2) {
				if (leap) {
					DWRUtil.addOptions(day, this.lFebruary);
				} else {
					DWRUtil.addOptions(day, this.february);
				}
			} else {
				DWRUtil.addOptions(day, this.bDay);
			}
		}
		$(year).value = wy;
		$(month).value = parseInt(wm);
		$(day).value = parseInt(wd);
	} else {//åˆå§‹
		DWRUtil.addOptions(day, this.bDay);
		$(month).value = 1;
		$(day).value = 1;
	}
}, showDay:function (year, month, day) {
	if (!(new RegExp("^[123456789]{1}\\d{3}$", "g").test($(year).value))) {
		this.init('',month, day,'','','');
		return false;
	}
	var isLeap = ($(year).value % 4 === 0 && ($(year).value % 100 !== 0 || $(year).value % 400 === 0));
	var whichMonth = $(month).value;
	if (whichMonth == 4 || whichMonth == 6 || whichMonth == 9 || whichMonth == 11) {
		DWRUtil.removeAllOptions(day);
		DWRUtil.addOptions(day, this.sDay);
	} else {
		if (whichMonth == 2) {
			if (isLeap) {
				DWRUtil.removeAllOptions(day);
				DWRUtil.addOptions(day, this.lFebruary);
			} else {
				DWRUtil.removeAllOptions(day);
				DWRUtil.addOptions(day, this.february);
			}
		} else {
			DWRUtil.removeAllOptions(day);
			DWRUtil.addOptions(day, this.bDay);
		}
	}
}, checkDay:function (year, day) {
	if (!(new RegExp("^[123456789]{1}\\d{3}$", "g").test($(year).value))) {
		$(day).value = 1;
		return false;
	}
}};

/**
 * add by frank
 * 2008.1.15
 * function:西方日期格初始化
 * 
 */
var nowDate = new Date();
var westCalendar ={};
westCalendar.Calendar=function(){};
westCalendar.Calendar.prototype = {months:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
aMonthDays:[31,28,31,30,31,30,31,31,30,31,30,31],
 days:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],
init:function (month,day,year, vM, vD, vY) {
 /* 创建下拉列表并初始化*/
  DWRUtil.removeAllOptions(month);
  DWRUtil.addOptions(month, this.months);
  DWRUtil.removeAllOptions(day);
  DWRUtil.addOptions(day, this.days);
  if(!isEmpty(vM)){
		$(month).value = parseInt(vM);
	 }
  if(!isEmpty(vD)){
		$(day).value = parseInt(vD);  
	 }
  if(!isEmpty(vY)){	
		$(year).value = vY;
	 }
  },checkYearInput:function (year) {
	if (!(new RegExp("^[123456789]{1}\\d{3}$", "g").test(alltrim($(year).value)))) {
	    $(year).value="";
		return false;
	}else{
	    return true;
	}
},validateDate:function (monthId,dayId,yearId){
   var result = true;
 /* 是否是闰年 */
   var isLeap = ($(yearId) && $(yearId).value % 4 == 0 && ($(yearId).value % 100 != 0 || $(yearId).value % 400 == 0));
   if(isLeap){
      this.aMonthDays[1] = 29;
   }else{
      this.aMonthDays[1] = 28;
   }
   if(this.aMonthDays[($(monthId).value-1)]< $(dayId).value){
     result = false;
     $(dayId).value = parseInt(this.aMonthDays[($(monthId).value-1)]);
   }
   /** 判断是否大于当前日期 ***/
   var yn = result && $(yearId) && (new Date($(yearId).value,($(monthId).value-1),$(dayId).value)).getTime() >= (nowDate.getTime()-24*60*60*1000);
   if(yn){
      $(yearId).value = nowDate.getYear();
      result = false;
    }
    
    return result;
 }
};
var westCalendar = new westCalendar.Calendar();
var calendar = new cpdCalendar.Calendar();

