﻿function DateTimePicker(baseId)
{
 this.baseId = baseId;
 this.calendarId = this.baseId + "_Calendar";
 this.captionId = this.baseId + "_Caption";
 this.contentId = this.baseId + "_Content";
 this.lblTodayId = this.baseId + "_lblToday";
 this.selectMonthId = this.baseId + "_selectMonth";
 this.selectYearId = this.baseId + "_selectYear";
 this.spanLeftId = this.baseId + "_spanLeft";
 this.spanRightId = this.baseId + "_spanRight";
 this.spanMonthId = this.baseId + "_spanMonth";
 this.spanYearId = this.baseId + "_spanYear";

 this.iframeId = this.baseId + "_iframe";

 this.zIndex = "+999";

 this.fixedX = -1;   // x position (-1 if to appear below control)
 this.fixedY = -1;   // y position (-1 if to appear below control)
 this.startAt = 0;   // 0 - sunday ; 1 - monday
 this.showWeekNumber = 1; // 0 - don't show; 1 - show
 this.showToday = 1;  // 0 - don't show; 1 - show
 this.allowDragCalendar = 1;
 
   this.titleColor = 'black';
   this.titleBackcolor = '#cccccc';
   this.titleBorderColor = '#f0f0f0';
   this.titleBorderColorH = 'white';
   this.selectBackColor = 'white';
   this.selectBackColorH = '#f0f0f0';
   this.holidayBackColor = '#FFDDDD';
   this.staticFilter = '';
   this.moveFilter = 'alpha(opacity=85)';

 this.gotoString = "转到当月";
 this.todayString = "今天：";
 this.weekString = "周";
 this.scrollLeftMessage = "上个月";
 this.scrollRightMessage = "下个月";
 this.selectMonthMessage = "选择月";
 this.selectYearMessage = "选择年";
 this.selectDateMessage = "选择日期 [date] "; // do not replace [date], it will be replaced by date.
 this.clearString = "清除";
 this.closeString = "关闭";

 this.bPageLoaded=false;

 this.ie = false;

 this.ns4=document.layers;
 this.today = new Date()
 this.dateNow  = this.today.getDate()
 this.monthNow = this.today.getMonth()
 this.yearNow  = this.today.getYear()

 this.bShow = false;

 if((navigator.userAgent.toLowerCase().indexOf("opera") == -1) && (navigator.userAgent.toLowerCase().indexOf("msie") != -1))
 {
    this.ie = true;
 }

 function HolidayRec(d, m, y, desc)
 {
  this.d = d
  this.m = m
  this.y = y
  this.desc = desc
 }

 this.HolidaysCounter = 0
 this.Holidays = new Array()

 this.addHoliday=function(d, m, y, desc)
 {
  this.Holidays[this.HolidaysCounter++] = new HolidayRec ( d, m, y, desc )
 }

  document.write ("<div onselectstart='return false' onclick='dateTimePicker.bShow=true' id='" + this.calendarId + "' style='z-index:" + this.zIndex + ";position:absolute;visibility:hidden;filter:" + this.staticFilter + "'><table width="+((this.showWeekNumber==1)?250:220)+" style='font-family:arial;font-size:11px;border-width:1px;border-style:solid;border-color:#a0a0a0;font-family:arial; font-size:11px;' bgcolor='white'><tr bgcolor='" + this.titleBackcolor + "'><td><table width='100%'><tr><td style='padding:2px;font-family:arial; font-size:11px;" + (this.allowDragCalendar == 1 ? "cursor:move" : "") + "'><B style='color:" + this.titleColor + "'><span id='" + this.captionId + "'></span></B></font></td><td align='right' style='font-size:12px;" + (this.allowDragCalendar == 1 ? "cursor:move" : "") + "'><a href='javascript:dateTimePicker.clearCalendar()' style='font-family:Webdings;font-size:12px;color:" + this.titleColor + ";text-decoration:none;' onmousemove='window.status=\"" + this.clearString + "\"' onmouseout='window.status=\"\"' title='" + this.clearString + "'>x</a>&nbsp;<a href='javascript:dateTimePicker.hideCalendar()' style='font-family:Webdings;font-size:12px;color:" + this.titleColor + ";text-decoration:none;' onmousemove='window.status=\"" + this.closeString + "\"' onmouseout='window.status=\"\"' title='" + this.closeString + "'>r</a></td></tr></table></td></tr><tr><td style='padding:5px' bgcolor=white><span id='" + this.contentId + "'></span></td></tr>")

  if (this.showToday==1)
  {
   document.write ("<tr bgcolor=#f0f0f0><td style='padding:5px' align=center><span id='" + this.lblTodayId + "' style='font-size:10px; font-family:verdana;'></span></td></tr>")
  }

  document.write ("</table><iframe src='' id='" + this.iframeId + "' style='z-index:-1;position:absolute;left:0px;top:0px;'></iframe></div><div id='" + this.selectMonthId + "' style='z-index:" + this.zIndex + ";position:absolute;visibility:hidden;'></div><div id='" + this.selectYearId + "' style='z-index:" + this.zIndex + ";position:absolute;visibility:hidden;'></div>");

  this.calendar = document.getElementById(this.calendarId);

 this.monthName = new Array("01","02","03","04","05","06","07","08","09","10","11","12")
 this.monthName2 = new Array("01","02","03","04","05","06","07","08","09","10","11","12")
 if (this.startAt==0)
 {
  dayName = new Array ("日","一","二","三","四","五","六")
 }
 else
 {
  dayName = new Array ("一","二","三","四","五","六","日")
 }
 this.styleAnchor="text-decoration:none;color:black;"
 this.styleLightBorder="border:solid 1px #a0a0a0;"

 this.init = function()
 {
  if (!this.ns4)
  {
   if (!this.ie)
   {
    this.yearNow += 1900
   }

   this.crossobj=document.getElementById(this.calendarId).style

   this.hideCalendar()

   this.crossMonthObj=document.getElementById(this.selectMonthId).style

   this.crossYearObj=document.getElementById(this.selectYearId).style

   this.monthConstructed=false;
   this.yearConstructed=false;

   if (this.showToday==1)
   {
    document.getElementById(this.lblTodayId).innerHTML = this.todayString + " <a onmousemove='window.status=\""+this.gotoString+"\"' onmouseout='window.status=\"\"' title='"+this.gotoString+"' style='"+this.styleAnchor+"' href='javascript:dateTimePicker.monthSelected=dateTimePicker.monthNow;dateTimePicker.yearSelected=dateTimePicker.yearNow;dateTimePicker.constructCalendar();'>星期"+dayName[(this.today.getDay()-this.startAt==-1)?6:(this.today.getDay()-this.startAt)]+" " + this.yearNow + "年" + this.monthName[this.monthNow].substring(0,3) + "月" + this.dateNow + "日</a>"
   }

   sHTML1="<span id='" + this.spanLeftId + "' style='border-style:solid;border-width:1px;border-color:" + this.titleBorderColor + ";cursor:pointer;font-family:webdings;font-size:9px;color:" + this.titleColor + ";padding-left:1px;padding-right:1px;' onmouseover='this.style.borderColor=\"" + this.titleBorderColorH + "\";window.status=\""+this.scrollLeftMessage+"\"' onclick='dateTimePicker.decMonth()' onmouseout='clearInterval(dateTimePicker.intervalID1);this.style.borderColor=\"" + this.titleBorderColor + "\";window.status=\"\"' onmousedown='clearTimeout(dateTimePicker.timeoutID1);dateTimePicker.timeoutID1=setTimeout(\"dateTimePicker.StartDecMonth()\",500)' onmouseup='clearTimeout(dateTimePicker.timeoutID1);clearInterval(dateTimePicker.intervalID1)' title='" + this.scrollLeftMessage + "'>3</span>&nbsp;"
   sHTML1+="<span id='" + this.spanRightId + "' style='border-style:solid;border-width:1px;border-color:" + this.titleBorderColor + ";cursor:pointer;font-family:webdings;font-size:9px;color:" + this.titleColor + ";padding-left:1px;padding-right:1px;' onmouseover='this.style.borderColor=\"" + this.titleBorderColorH + "\";window.status=\""+this.scrollRightMessage+"\"' onmouseout='clearInterval(dateTimePicker.intervalID1);this.style.borderColor=\"" + this.titleBorderColor + "\";window.status=\"\"' onclick='dateTimePicker.incMonth()' onmousedown='clearTimeout(dateTimePicker.timeoutID1);dateTimePicker.timeoutID1=setTimeout(\"dateTimePicker.StartIncMonth()\",500)' onmouseup='clearTimeout(dateTimePicker.timeoutID1);clearInterval(dateTimePicker.intervalID1)' title='" + this.scrollRightMessage + "'>4</span>&nbsp"
   sHTML1+="<span id='" + this.spanMonthId + "' style='border-style:solid;border-width:1px;border-color:" + this.titleBorderColor + ";cursor:pointer' onmouseover='this.style.borderColor=\"" + this.titleBorderColorH + "\";window.status=\""+this.selectMonthMessage+"\"' onmouseout='this.style.borderColor=\"" + this.titleBorderColor + "\";window.status=\"\"' onclick='dateTimePicker.popUpMonth()' title='" + this.selectMonthMessage + "'></span>&nbsp;"
   sHTML1+="<span id='" + this.spanYearId + "' style='border-style:solid;border-width:1px;border-color:" + this.titleBorderColor + ";cursor:pointer' onmouseover='this.style.borderColor=\"" + this.titleBorderColorH + "\";window.status=\""+this.selectYearMessage+"\"' onmouseout='this.style.borderColor=\"" + this.titleBorderColor + "\";window.status=\"\"' onclick='dateTimePicker.popUpYear()' title='" + this.selectYearMessage + "'></span>&nbsp;"

   document.getElementById(this.captionId).innerHTML  = sHTML1

   this.bPageLoaded=true
  }
 }

 this.hideCalendar=function()
 {
  if (this.crossobj.visibility != "hidden")
  {
    this.crossobj.visibility="hidden"
    if (this.crossMonthObj != null)
    {
     this.crossMonthObj.visibility="hidden"
    }
    if (this.crossYearObj != null)
    {
     this.crossYearObj.visibility="hidden"
    }

    if (this.ctlToPlaceValue != null)
      this.ctlToPlaceValue.focus();
  }
 }

 function padBlank(num)
 {
  return (num < 10)? '&nbsp;' + num : num ;
 }

 function padZero(num)
 {
  return (num < 10)? '0' + num : num ;
 }

 this.constructDate=function(d,m,y)
 {
  sTmp = this.dateFormat
  sTmp = sTmp.replace ("dd","<e>")
  sTmp = sTmp.replace ("d","<d>")
  sTmp = sTmp.replace ("<e>",padZero(d))
  sTmp = sTmp.replace ("<d>",d)
  sTmp = sTmp.replace ("mmmm","<p>")
  sTmp = sTmp.replace ("mmm","<o>")
  sTmp = sTmp.replace ("mm","<n>")
  sTmp = sTmp.replace ("m","<m>")
  sTmp = sTmp.replace ("<m>",m+1)
  sTmp = sTmp.replace ("<n>",padZero(m+1))
  sTmp = sTmp.replace ("<o>",this.monthName[m])
  sTmp = sTmp.replace ("<p>",this.monthName2[m])
  sTmp = sTmp.replace ("yyyy",y)
  return sTmp.replace ("yy",padZero(y%100))
 }

 this.closeCalendar=function()
 {
  var sTmp

  this.hideCalendar();
  this.ctlToPlaceValue.value = this.constructDate(this.dateSelected,this.monthSelected,this.yearSelected)
 }

 this.clearCalendar=function()
 {
   this.hideCalendar()
   this.ctlToPlaceValue.value = ""
 }

 /*** Month Pulldown ***/

this.StartDecMonth = function()
 {
  this.intervalID1=setInterval("dateTimePicker.decMonth()",80)
 }

 this.StartIncMonth =function()
 {
  this.intervalID1=setInterval("dateTimePicker.incMonth()",80)
 }

 this.incMonth=function()
 {
  this.monthSelected++
  if (this.monthSelected>11)
  {
   this.monthSelected=0
   this.yearSelected++
  }
  this.constructCalendar()
 }

 this.decMonth =function()
 {
  this.monthSelected--
  if (this.monthSelected<0)
  {
   this.monthSelected=11
   this.yearSelected--
  }
  this.constructCalendar()
 }

 this.upMonth=function()
 {
  if(this.nStartingMonth > 0)
  {
   this.nStartingMonth --;
   var newMonth;
   var txtMonth;
   for (i=0; i<6; i++)
   {
    newMonth = (i + this.nStartingMonth);
    if (newMonth == this.monthSelected)
     txtMonth = "&nbsp;<B>" + this.monthName[newMonth] + "</B>&nbsp;";
    else
     txtMonth = "&nbsp;" + this.monthName[newMonth] + "&nbsp;";
    document.getElementById(this.baseId + "_m" + i).innerHTML = txtMonth;
   }
  }
  this.bShow=true
 }

 this.downMonth =function()
 {
  if(this.nStartingMonth < 6)
  {
   this.nStartingMonth ++;
   var newMonth;
   var txtMonth;
   for (i=0; i<6; i++)
   {
    newMonth = (i + this.nStartingMonth);
    if (newMonth == this.monthSelected)
     txtMonth = "&nbsp;<B>" + this.monthName[newMonth] + "</B>&nbsp;";
    else
     txtMonth = "&nbsp;" + this.monthName[newMonth] + "&nbsp;";
    document.getElementById(this.baseId + "_m" + i).innerHTML = txtMonth;
   }
  }
  this.bShow=true
 }

 this.selectMonth =function(nMonth)
 {
  this.monthSelected=parseInt(nMonth+this.nStartingMonth);
  this.monthConstructed=false;
  this.constructCalendar();
  this.popDownMonth();
 }

this.constructMonth= function()
 {
  this.popDownYear()
  if (!this.monthConstructed)
  {

   sHTML = "<tr><td align='center' onmouseover='this.style.backgroundColor=\"" + this.selectBackColorH + "\"' onmouseout='clearInterval(dateTimePicker.intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(dateTimePicker.intervalID1);dateTimePicker.intervalID1=setInterval(\"dateTimePicker.upMonth()\",30)' onmouseup='clearInterval(dateTimePicker.intervalID1)'>-</td></tr>"

   j=0;
   i=(this.monthSelected-3);
   if(i < 0)
    i=0;
   if(i > 6)
    i=6;
   this.nStartingMonth = i;
   for (ii=0; ii<6; ii++, i++, j++)
   {
    sName = this.monthName[i];
    if (i==this.monthSelected)
    {
     sName = "<B>" + sName + "</B>"
    }
    sHTML += "<tr><td id='" + this.baseId + "_m" + j + "' onmouseover='this.style.backgroundColor=\"" + this.selectBackColorH + "\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='dateTimePicker.selectMonth(" + j + ");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
   }

   sHTML += "<tr><td align='center' onmouseover='this.style.backgroundColor=\"" + this.selectBackColorH + "\"' onmouseout='clearInterval(dateTimePicker.intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(dateTimePicker.intervalID2);dateTimePicker.intervalID2=setInterval(\"dateTimePicker.downMonth()\",30)' onmouseup='clearInterval(dateTimePicker.intervalID2)'>+</td></tr>"

   document.getElementById(this.selectMonthId).innerHTML = "<table width=32 style='font-family:arial; font-size:11px; border-width:1px; border-style:solid; border-color:#a0a0a0;' bgcolor='" + this.selectBackColor + "' cellspacing=0 onmouseover='clearTimeout(dateTimePicker.timeoutID1)' onmouseout='clearTimeout(dateTimePicker.timeoutID1);dateTimePicker.timeoutID1=setTimeout(\"dateTimePicker.popDownMonth()\",100);event.cancelBubble=true'>" + sHTML + "</table>"

   this.monthConstructed=true
  }
 }
 this.popUpMonth=function()
 {
  this.constructMonth()
  this.crossMonthObj.visibility = (this.ie)? "visible" : "show"
  leftOffset = parseInt(this.crossobj.left) + document.getElementById(this.spanMonthId).offsetLeft
  if (this.ie)
  {
   leftOffset += 6
  }
  this.crossMonthObj.left = leftOffset
  this.crossMonthObj.top = parseInt(this.crossobj.top) + 26
 }

 this.popDownMonth=function()
 {
  this.crossMonthObj.visibility= "hidden"
 }

 /*** Year Pulldown ***/

 this.incYear=function()
 {
  for (i=0; i<6; i++)
  {
   newYear = (i+this.nStartingYear)+1
   if (newYear==this.yearSelected)
   {
    txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;"
   }
   else
   {
    txtYear = "&nbsp;" + newYear + "&nbsp;"
   }
   document.getElementById(this.baseId + "_y" + i).innerHTML = txtYear
  }
  this.nStartingYear ++;
  this.bShow=true
 }

 this.decYear=function()
 {
  for (i=0; i<6; i++)
  {
   newYear = (i+this.nStartingYear)-1
   if (newYear==this.yearSelected)
   {
    txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;"
   }
   else
   {
    txtYear = "&nbsp;" + newYear + "&nbsp;"
   }
   document.getElementById(this.baseId + "_y" + i).innerHTML = txtYear
  }
  this.nStartingYear --;
  this.bShow=true
 }

 this.selectYear=function(nYear)
 {
  this.yearSelected=parseInt(nYear+this.nStartingYear);
  this.yearConstructed=false;
  this.constructCalendar();
  this.popDownYear();
 }

 this.constructYear=function()
 {
  this.popDownMonth()
  sHTML = ""
  if (!this.yearConstructed)
  {

   sHTML = "<tr><td align='center' onmouseover='this.style.backgroundColor=\"" + this.selectBackColorH + "\"' onmouseout='clearInterval(dateTimePicker.intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(dateTimePicker.intervalID1);dateTimePicker.intervalID1=setInterval(\"dateTimePicker.decYear()\",30)' onmouseup='clearInterval(dateTimePicker.intervalID1)'>-</td></tr>"

   j = 0
   this.nStartingYear = this.yearSelected-3
   for (i=(this.yearSelected-3); i<(this.yearSelected+3); i++)
   {
    sName = i;
    if (i==this.yearSelected)
    {
     sName = "<B>" + sName + "</B>"
    }

    sHTML += "<tr><td id='" + this.baseId + "_y" + j + "' onmouseover='this.style.backgroundColor=\"" + this.selectBackColorH + "\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='dateTimePicker.selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
    j ++;
   }

   sHTML += "<tr><td align='center' onmouseover='this.style.backgroundColor=\"" + this.selectBackColorH + "\"' onmouseout='clearInterval(dateTimePicker.intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(dateTimePicker.intervalID2);dateTimePicker.intervalID2=setInterval(\"dateTimePicker.incYear()\",30)' onmouseup='clearInterval(dateTimePicker.intervalID2)'>+</td></tr>"

   document.getElementById(this.selectYearId).innerHTML = "<table width=44 style='font-family:arial; font-size:11px; border-width:1px; border-style:solid; border-color:#a0a0a0;' bgcolor='" + this.selectBackColor + "' onmouseover='clearTimeout(dateTimePicker.timeoutID2)' onmouseout='clearTimeout(dateTimePicker.timeoutID2);dateTimePicker.timeoutID2=setTimeout(\"dateTimePicker.popDownYear()\",100)' cellspacing=0>" + sHTML + "</table>"

   this.yearConstructed = true
  }
 }

 this.popDownYear=function()
 {
  clearInterval(this.intervalID1)
  clearTimeout(this.timeoutID1)
  clearInterval(this.intervalID2)
  clearTimeout(this.timeoutID2)
  this.crossYearObj.visibility= "hidden"
 }

 this.popUpYear=function()
 {
  var leftOffset

  this.constructYear()
  this.crossYearObj.visibility = (this.ie)? "visible" : "show"
  leftOffset = parseInt(this.crossobj.left) + document.getElementById(this.spanYearId).offsetLeft
  if (this.ie)
  {
   leftOffset += 6
  }
  this.crossYearObj.left = leftOffset
  this.crossYearObj.top = parseInt(this.crossobj.top) + 26
 }

 /*** calendar ***/
   this.WeekNbr=function(n)
   {
      // Algorithm used:
      // From Klaus Tondering's Calendar document (The Authority/Guru)
      // http://www.tondering.dk/claus/calendar.html
      // a = (14-month) / 12
      // y = year + 4800 - a
      // m = month + 12a - 3
      // J = day + (153m + 2) / 5 + 365y + y / 4 - y / 100 + y / 400 - 32045
      // d4 = (J + 31741 - (J mod 7)) mod 146097 mod 36524 mod 1461
      // L = d4 / 1460
      // d1 = ((d4 - L) mod 365) + L
      // WeekNumber = d1 / 7 + 1

      year = n.getFullYear();
      month = n.getMonth() + 1;
      if (this.startAt == 0)
      {
        day = n.getDate() + 1;
      }
      else
      {
        day = n.getDate();
      }

      a = Math.floor((14-month) / 12);
      y = year + 4800 - a;
      m = month + 12 * a - 3;
      b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
      J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
      d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
      L = Math.floor(d4 / 1460);
      d1 = ((d4 - L) % 365) + L;
      week = Math.floor(d1/7) + 1;

      return week;
   }

 this.constructCalendar=function()
 {
  var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31)

  var dateMessage
  var startDate = new Date (this.yearSelected,this.monthSelected,1)
  var endDate

  if (this.monthSelected==1)
  {
   endDate = new Date (this.yearSelected,this.monthSelected+1,1);
   endDate = new Date (endDate - (24*60*60*1000));
   numDaysInMonth = endDate.getDate()
  }
  else
  {
   numDaysInMonth = aNumDays[this.monthSelected];
  }

  datePointer = 0
  dayPointer = startDate.getDay() - this.startAt

  if (dayPointer<0)
  {
   dayPointer = 6
  }

  sHTML = "<table border=0 style='font-family:verdana;font-size:10px;table-layout:fixed;'><tr>"

  if (this.showWeekNumber==1)
  {
   sHTML += "<td width=27 align='center'><b>" + this.weekString + "</b></td><td width=1 rowspan=7 bgcolor='#d0d0d0' style='padding:0px'></td>"
  }

  for (i=0; i<7; i++)
  {
   sHTML += "<td width='27' align='center'><b>"+ dayName[i]+"</b></td>"
  }
  sHTML +="</tr><tr>"

  if (this.showWeekNumber==1)
  {
   sHTML += "<td align=right>" + this.WeekNbr(startDate) + "&nbsp;</td>"
  }

  for ( var i=1; i<=dayPointer;i++ )
  {
   sHTML += "<td>&nbsp;</td>"
  }

  for ( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
  {
   dayPointer++;
   sHTML += "<td align=right>"
   sStyle=this.styleAnchor
   if ((datePointer==this.othis_dateSelected) && (this.monthSelected==this.othis_monthSelected) && (this.yearSelected==this.othis_yearSelected))
   { sStyle+=this.styleLightBorder }

   sHint = ""
   for (k=0;k<this.HolidaysCounter;k++)
   {
    if ((parseInt(this.Holidays[k].d)==datePointer)&&(parseInt(this.Holidays[k].m)==(this.monthSelected+1)))
    {
     if ((parseInt(this.Holidays[k].y)==0)||((parseInt(this.Holidays[k].y)==this.yearSelected)&&(parseInt(this.Holidays[k].y)!=0)))
     {
      sStyle+="background-color:" + this.holidayBackColor + ";"
      sHint+=sHint==""?this.Holidays[k].desc:"\n"+this.Holidays[k].desc
     }
    }
   }

   var regexp= /\"/g
   sHint=sHint.replace(regexp,"&quot;")

   dateMessage = "onmousemove='window.status=\""+this.selectDateMessage.replace("[date]",this.constructDate(datePointer,this.monthSelected,this.yearSelected))+"\";if (style.border==\"\") { style.borderBackup=style.border; style.border=\"dotted 1px gray\"; }' onmouseout='window.status=\"\";if (style.borderBackup != null) { style.border=style.borderBackup; style.borderBackup=null; }' "

   if ((datePointer==this.dateNow)&&(this.monthSelected==this.monthNow)&&(this.yearSelected==this.yearNow))
   {
    sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateTimePicker.dateSelected="+datePointer+";dateTimePicker.closeCalendar();'><b style='color:red'>&nbsp;" + padBlank(datePointer) + "</b>&nbsp;</a>"
   }
   else if (dayPointer % 7 == (this.startAt * -1)+1)
   {
    sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateTimePicker.dateSelected="+datePointer+ ";dateTimePicker.closeCalendar();'>&nbsp;<font color=#909090>" + padBlank(datePointer) + "</font>&nbsp;</a>"
   }
   else
   {
    sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateTimePicker.dateSelected="+datePointer + ";dateTimePicker.closeCalendar();'>&nbsp;" + padBlank(datePointer) + "&nbsp;</a>"
   }

   sHTML += ""
   if ((dayPointer+this.startAt) % 7 == this.startAt)
   {
    sHTML += "</tr><tr>"
    if ((this.showWeekNumber==1)&&(datePointer<numDaysInMonth))
    {
     sHTML += "<td align=right>" + (this.WeekNbr(new Date(this.yearSelected,this.monthSelected,datePointer+1))) + "&nbsp;</td>"
    }
   }
  }

  document.getElementById(this.contentId).innerHTML   = sHTML
  document.getElementById(this.spanMonthId).innerHTML = "&nbsp;" + this.monthName[this.monthSelected] + "&nbsp;<span style='font-family:webdings;font-size:9px;color:" + this.titleColor + ";'>6</span>"
  document.getElementById(this.spanYearId).innerHTML = "&nbsp;" + this.yearSelected + "&nbsp;<span style='font-family:webdings;font-size:9px;color:" + this.titleColor + ";'>6</span>"

  document.getElementById(this.iframeId).width = document.getElementById(this.calendarId).offsetWidth;
  document.getElementById(this.iframeId).height = document.getElementById(this.calendarId).offsetHeight;
 }

 this.popUpCalendar=function(ctl, ctl2, format)
 {
  var leftpos=0
  var toppos=0
  if (this.bPageLoaded)
  {
   if ( this.crossobj.visibility == "hidden" )
   {
    this.ctlToPlaceValue = ctl2
    this.dateFormat=format;

    formatChar = " "
    aFormat = this.dateFormat.split(formatChar)
    if (aFormat.length<3)
    {
     formatChar = "/"
     aFormat = this.dateFormat.split(formatChar)
     if (aFormat.length<3)
     {
      formatChar = "."
      aFormat = this.dateFormat.split(formatChar)
      if (aFormat.length<3)
      {
       formatChar = "-"
       aFormat = this.dateFormat.split(formatChar)
       if (aFormat.length<3)
       {
        // invalid date format
        formatChar=""
       }
      }
     }
    }

    tokensChanged = 0
    if ( formatChar != "" )
    {
     // use user's date
     aData = ctl2.value.split(formatChar)

     for (i=0;i<3;i++)
     {
      if ((aFormat[i]=="d") || (aFormat[i]=="dd"))
      {
       this.dateSelected = parseInt(aData[i], 10)
       tokensChanged ++
      }
      else if ((aFormat[i]=="m") || (aFormat[i]=="mm"))
      {
       this.monthSelected = parseInt(aData[i], 10) - 1
       tokensChanged ++
      }
      else if (aFormat[i]=="yyyy")
      {
       this.yearSelected = parseInt(aData[i], 10)
       tokensChanged ++
      }
      else if (aFormat[i]=="mmm")
      {
       for (j=0; j<12; j++)
       {
        if (aData[i]==this.monthName[j])
        {
         this.monthSelected=j
         tokensChanged ++
        }
       }
      }
      else if (aFormat[i]=="mmmm")
      {
       for (j=0; j<12; j++)
       {
        if (aData[i]==this.monthName2[j])
        {
         this.monthSelected=j
         tokensChanged ++
        }
       }
      }
     }
    }

    if ((tokensChanged!=3)||isNaN(this.dateSelected)||isNaN(this.monthSelected)||isNaN(this.yearSelected))
    {
     this.dateSelected = this.dateNow
     this.monthSelected = this.monthNow
     this.yearSelected = this.yearNow
    }

    this.othis_dateSelected=this.dateSelected
    this.othis_monthSelected=this.monthSelected
    this.othis_yearSelected=this.yearSelected

    aTag = ctl.offsetParent;
    while(aTag != null && aTag.tagName.toUpperCase()!="BODY")
    {
     leftpos += aTag.offsetLeft - aTag.scrollLeft;
     toppos += aTag.offsetTop - aTag.scrollTop;
     aTag = aTag.offsetParent;
    }

    this.crossobj.left = this.fixedX==-1 ? ctl.offsetLeft - ctl.scrollLeft + leftpos : this.fixedX
    this.crossobj.top = this.fixedY==-1 ? ctl.offsetTop - ctl.scrollTop + toppos/* + ctl.offsetHeight + 2*/ : this.fixedY
    this.constructCalendar (1, this.monthSelected, this.yearSelected);
    this.crossobj.visibility=(this.ie)? "visible" : "show";

    this.bShow = true;

    // position plus
    if (this.crossobj.pixelLeft + this.calendar.clientWidth > document.body.clientWidth + document.body.scrollLeft)
    {
        this.crossobj.pixelLeft = document.body.scrollLeft + document.body.clientWidth - this.calendar.clientWidth;
        if (this.crossobj.pixelLeft < document.body.scrollLeft)
            this.crossobj.pixelLeft = document.body.scrollLeft;
    }
    if (this.crossobj.pixelTop + this.calendar.clientHeight > document.body.clientHeight + document.body.scrollTop)
    {
        this.crossobj.pixelTop = document.body.scrollTop + document.body.clientHeight - this.calendar.clientHeight;
        if (this.crossobj.pixelTop < document.body.scrollTop)
            this.crossobj.pixelTop = document.body.scrollTop;
    }

    this.calendar.focus()
   }
   else
   {
    this.hideCalendar()
    if (this.ctlNow!=ctl) {this.popUpCalendar(ctl, ctl2, format)}
   }
   this.ctlNow = ctl
  }
 }
this.hidecal1=function()
	{
  if (event.keyCode==27)
  {
   dateTimePicker.hideCalendar()
  }
	}
this.hidecal2 = function()
 {
  if (!dateTimePicker.bShow)
  {
   dateTimePicker.hideCalendar()
  }
  dateTimePicker.bShow = false
 }

 if(this.ie)
 {
  this.init()
 }
 else
 {
  window.onload=this.init
 }

//拖拽过程中相关变量
var calendarDraging = false; //是否处于拖拽中
var calendarDragOffsetX = 0;     //X方向左右偏移量
var calendarDragOffsetY = 0;     //Y方向上下偏移量

//准备拖拽
this.BeforeDragCalendar=function()
{
    if (event.button != 1 || event.srcElement.style.cursor.toLowerCase() != "move")
    {
        return;
    }
    dateTimePicker.popDownMonth();
    dateTimePicker.popDownYear();
    dateTimePicker.calendarDragOffsetX = document.body.scrollLeft + event.clientX-dateTimePicker.calendar.style.pixelLeft;
    dateTimePicker.calendarDragOffsetY = document.body.scrollTop + event.clientY-dateTimePicker.calendar.style.pixelTop;
    dateTimePicker.calendar.style.filter = dateTimePicker.moveFilter;
    dateTimePicker.calendarDraging = true;
}

//拖拽中
this.OnDragCalendar=function()
{
    if(!dateTimePicker.calendarDraging)
    {
        return;
    }
    //更新位置
    dateTimePicker.calendar.style.pixelLeft = document.body.scrollLeft + event.clientX-dateTimePicker.calendarDragOffsetX;
    dateTimePicker.calendar.style.pixelTop = document.body.scrollTop + event.clientY-dateTimePicker.calendarDragOffsetY;
}

//结束拖拽
this.EndDragCalendar=function()
{
    if (event.button != 1)
    {
        return;
    }
    dateTimePicker.calendarDraging = false;
    dateTimePicker.calendar.style.filter = dateTimePicker.staticFilter;
}

if (this.allowDragCalendar == 1)
{
    this.calendar.onmousedown = this.BeforeDragCalendar;
    document.onmousemove = this.OnDragCalendar;
    this.calendar.onmouseup = this.EndDragCalendar;
}

this.addHoliday(1, 1, 0, '元旦')
this.addHoliday(1, 5, 0, '劳动节')
this.addHoliday(1, 10, 0, '国庆节')
}

var dateTimePicker = new DateTimePicker("dateTimePicker");
document.onkeypress = dateTimePicker.hidecal1
document.onclick = dateTimePicker.hidecal2

// <INPUT id="Text1" name="Text1" type="text" onclick='dateTimePicker.popUpCalendar(this, this, "yyyy-m-d")' readOnly />
