'in then script
'in then code
<script>
//get the language from cookie
function getLanguage()
{
// cookies are separated by semicolons
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
// a name/value pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
if (aCrumb[0] == "TASWEBLANGUAGE")
return aCrumb[1];
}
// a cookie with the requested name does not exist
return "0";
}
function getAllAttributes(object)
{
var strAttributes="";
for(var i=0;i<object.attributes.length;i++)
{
strAttributes=strAttributes+object.attributes(i).name+","
}
alert(strAttributes);
return true;
}
function hideCalendar()
{
HiddenDiv();
return true;
}
function isDate(sDate)
{
var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31];
var iaDate = new Array(3);
var year, month, day;
if (arguments.length != 1) return false;
iaDate = sDate.toString().split("-");
if (iaDate.length != 3) return false;
if (iaDate[1].length > 2 || iaDate[2].length > 2) return false;
if(iaDate[0] == "" || iaDate[1] == "" || iaDate[2] == "")
return false;
if(isNaN(iaDate[0]) || isNaN(iaDate[1]) || isNaN(iaDate[2]))
return false;
year = parseFloat(iaDate[0]);
month = parseFloat(iaDate[1]);
day=parseFloat(iaDate[2]);
if (year < 1900 || year > 2100) return false;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
if (month < 1 || month > 12) return false;
if (day < 1 || day > iaMonthDays[month - 1]) return false;
return true;
}
//如果输入的不是日期型,则修改为当前日期
function checkDateValue(dateCtr)
{
while(dateCtr.value.toString().indexOf("/") > 0)
{
dateCtr.value = dateCtr.value.toString().replace("/","-");
}
if(!isDate(dateCtr.value))
dateCtr.value=getNowDate();
return true;
}
//当前日期
function getNowDate()
{
var nn=new Date();
year1=nn.getYear();
mon1=nn.getMonth()+1;
date1=nn.getDate();
var monstr1;
var datestr1
if(mon1<10)
monstr1="0"+mon1;
else
monstr1=""+mon1;
if(date1<10)
datestr1="0"+date1;
else
datestr1=""+date1;
return year1+"-"+monstr1+"-"+datestr1;
}
//目标日期
function getlastweekDate()
{
var nn=new Date();
year1=nn.getYear();
mon1=nn.getMonth()+1;
date1=nn.getDate();
var mm=new Date(year1,mon1-1,date1);
var tmp1=new Date(2000,1,1);
var tmp2=new Date(2000,1,15);
var ne=tmp2-tmp1;
var mm2=new Date();
mm2.setTime(mm.getTime()-ne);
year2=mm2.getYear();
mon2=mm2.getMonth()+1;
date2=mm2.getDate();
if(mon2<10)
monstr2="0"+mon2;
else
monstr2=""+mon2;
if(date2<10)
datestr2="0"+date2;
else
datestr2=""+date2;
return year2+"-"+monstr2+"-"+datestr2;
}
var gdCtrl = new Object();
var goSelectTag = new Array();
var gcGray = "#808080";
var gcToggle = "#FB8664";
var gcBG = "#e5e6ec";
var gcClose = "#006600";
var wkBgColor= "Gray";
var previousObject = null;
var gdCurDate = new Date();
var giYear = gdCurDate.getFullYear();
var giMonth = gdCurDate.getMonth()+1;
var giDay = gdCurDate.getDate();
function fSetDate(iYear, iMonth, iDay)
{
var VicPopCal= document.getElementById("VicPopCal");
VicPopCal.style.visibility = "hidden";
if ((iYear == 0) && (iMonth == 0) && (iDay == 0))
{
gdCtrl.value = "";
}
else
{
iMonth = iMonth + 100 + "";
iMonth = iMonth.substring(1);
iDay = iDay + 100 + "";
iDay = iDay.substring(1);
if(gdCtrl.tagName == "INPUT")
{
gdCtrl.value = iYear+"-"+iMonth+"-"+iDay;
}
else
{
gdCtrl.innerText = iYear+"-"+iMonth+"-"+iDay;
}
}
for (i in goSelectTag)
goSelectTag[i].style.visibility = "visible";
goSelectTag.length = 0;
window.returnValue=gdCtrl.value;
hidControl();
// window.close();
}
function fSetClose()
{
var VicPopCal= document.getElementById("VicPopCal");
VicPopCal.style.visibility = "hidden";
hidControl();
}
function HiddenDiv()
{
var i;
var VicPopCal= document.getElementById("VicPopCal");
VicPopCal.style.visibility = "hidden";
for (i in goSelectTag)
goSelectTag[i].style.visibility = "visible";
goSelectTag.length = 0;
hidControl();
}
function fSetSelected(aCell)
{
var tbSelMonth = document.getElementById("tbSelMonth");
var tbSelYear = document.getElementById("tbSelYear");
var iOffset = 0;
var iYear = parseInt(tbSelYear.value);
var iMonth = parseInt(tbSelMonth.value);
aCell.bgColor = gcBG;
with (aCell.children["cellText"])
{
var iDay = parseInt(innerText);
if (color==gcGray)
iOffset = (Victor<10)?-1:1;
iMonth += iOffset;
if(iMonth<1)
{
iYear--;
iMonth = 12;
}
else if (iMonth>12)
{
iYear++;
iMonth = 1;
}
}
fSetDate(iYear, iMonth, iDay);
}
function Point(iX, iY)
{
this.x = iX;
this.y = iY;
}
function fBuildCal(iYear, iMonth)
{
var aMonth=new Array();
for(i=1;i<7;i++)
aMonth[i]=new Array(i);
var dCalDate=new Date(iYear, iMonth-1, 1);
var iDayOfFirst=dCalDate.getDay();
var iDaysInMonth=new Date(iYear, iMonth, 0).getDate();
var iOffsetLast=new Date(iYear, iMonth-1, 0).getDate()-iDayOfFirst+1;
var iDate = 1;
var iNext = 1;
for (d = 0; d < 7; d++)
aMonth[1][d] = (d<iDayOfFirst)?-(iOffsetLast+d):iDate++;
for (w = 2; w < 7; w++)
for (d = 0; d < 7; d++)
aMonth[w][d] = (iDate<=iDaysInMonth)?iDate++:-(iNext++);
return aMonth;
}
function fDrawCal(iYear, iMonth, iCellHeight, sDateTextSize)
{
switch(getLanguage())
{
case "0":
var WeekDay = new Array("SU","MO","TU","WE","TH","FR","SA");
break;
case "1":
var WeekDay = new Array("日","一","二","三","四","五","六");
break;
case "2":
var WeekDay = new Array("日","一","二","三","四","五","六");
break;
}
var styleWkTD = " bgcolor='"+wkBgColor+"' bordercolor='"+wkBgColor+"' valign='middle' align='center' height='"+iCellHeight+"' style='font:bold arial "+sDateTextSize+";";
var styleTD = " bgcolor='"+gcBG+"' bordercolor='"+gcBG+"' valign='middle' align='center' height='"+iCellHeight+"' style='font:bold arial "+sDateTextSize+";";
with (document)
{
write("<tr>");
for(i=0; i<7; i++)
{
write("<td "+styleWkTD+"color:white' >"+ WeekDay[i] + "</td>");
}
write("</tr>");
for (w = 1; w < 7; w++)
{
write("<tr>");
for (d = 0; d < 7; d++)
{
write("<td id=calCell "+styleTD+"cursor:hand;' onMouseOver='this.bgColor=gcToggle' onMouseOut='this.bgColor=gcBG' onclick='fSetSelected(this)'>");
write("<font id=cellText Victor='Hcy_Flag'> </font>");
write("</td>")
}
write("</tr>");
}
}
}
function fUpdateCal()
{
var iYear=document.getElementById("tbSelYear").value;
var iMonth=document.getElementById("tbSelMonth").value;
myMonth = fBuildCal(iYear, iMonth);
var i = 0;
for (w = 0; w < 6; w++)
for (d = 0; d < 7; d++)
with (cellText[(7*w)+d])
{
Victor = i++;
if (myMonth[w+1][d]<0)
{
color = gcGray;
innerText = -myMonth[w+1][d];
}
else
{
color = ((d==0)||(d==6))?"red":"black";
innerText = myMonth[w+1][d];
}
}
}
function fSetYearMon(iYear, iMon)
{
var tbSelMonth = document.getElementById("tbSelMonth");
var tbSelYear = document.getElementById("tbSelYear");
tbSelMonth.options[iMon-1].selected = true;
for (i = 0; i < tbSelYear.length; i++)
if (tbSelYear.options[i].value == iYear)
tbSelYear.options[i].selected = true;
fUpdateCal(iYear, iMon);
}
function fPrevMonth()
{
var tbSelMonth = document.getElementById("tbSelMonth");
var tbSelYear = document.getElementById("tbSelYear");
var iMon = tbSelMonth.value;
var iYear = tbSelYear.value;
if (--iMon<1)
{
iMon = 12;
iYear--;
}
fSetYearMon(iYear, iMon);
}
function fNextMonth()
{
var tbSelMonth = document.getElementById("tbSelMonth");
var tbSelYear = document.getElementById("tbSelYear");
var iMon = tbSelMonth.value;
var iYear = tbSelYear.value;
if (++iMon>12)
{
iMon = 1;
iYear++;
}
fSetYearMon(iYear, iMon);
}
function fToggleTags()
{
with (document.all.tags("SELECT"))
{
for (i=0; i<length; i++)
{
if (document.all.tags("SELECT").item(i).Victor==null) return;
if ((item(i).Victor!="Won")&&fTagInBound(item(i)))
{
item(i).style.visibility = "hidden";
goSelectTag[goSelectTag.length] = item(i);
}
}
}
}
function fTagInBound(aTag)
{
var VicPopCal= document.getElementById("VicPopCal");
with (VicPopCal.style)
{
var l = parseInt(left);
var t = parseInt(top);
var r = l+parseInt(width);
var b = t+parseInt(height);
var ptLT = fGetXY(aTag);
return !((ptLT.x>r)||(ptLT.x+aTag.offsetWidth<l)||(ptLT.y>b)||(ptLT.y+aTag.offsetHeight<t));
}
}
function getAbsolutePos(el)
{
var r = { x: el.offsetLeft, y: el.offsetTop };
if (el.offsetParent)
{
var tmp = getAbsolutePos(el.offsetParent);
r.x += tmp.x;
r.y += tmp.y;
}
return r;
}
function hidControl()
{
var tags = new Array("applet", "iframe", "select");
var el= document.getElementById("VicPopCal");
var p = getAbsolutePos(el);
var EX1 = p.x;
var EX2 = el.offsetWidth + EX1;
var EY1 = p.y;
var EY2 = el.offsetHeight + EY1;
for (var k = tags.length; k > 0; )
{
var ar = document.getElementsByTagName(tags[--k]);
var cc = null;
for (var i = ar.length; i > 0;)
{
cc = ar[--i];
p = getAbsolutePos(cc);
var CX1 = p.x;
var CX2 = cc.offsetWidth + CX1;
var CY1 = p.y;
var CY2 = cc.offsetHeight + CY1;
if (el.style.visibility == 'hidden' || (CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1))
{
if(cc.getAttribute("ID") != "tbSelYear" && cc.getAttribute("ID") != "tbSelMonth")
cc.style.visibility = "visible";
} else
{
if(cc.getAttribute("ID") != "tbSelYear" && cc.getAttribute("ID") != "tbSelMonth")
cc.style.visibility = "hidden";
}
}
}
}
// Main: popCtrl is the widget beyond which you want this calendar to appear;
// dateCtrl is the widget into which you want to put the selected date.
// i.e.: <input type="text" name="dc" style="text-align:center" readonly><INPUT type="button" value="V" onclick="fPopCalendar(dc,dc);return false">
function fPopCalendar(popCtrl, dateCtrl,strDate)
{
var ppCtl = popCtrl;//document.getElementById(popCtrl);
var dateCtl = dateCtrl;//document.getElementById(dateCtrl);
var VicPopCal= document.getElementById("VicPopCal");
// getAllAttributes(VicPopCal);
if (ppCtl == previousObject)
{
if (VicPopCal.style.visibility == "visible")
{
HiddenDiv();
return true;
}
}
previousObject = ppCtl;
gdCtrl = dateCtl;
if( strDate == null || strDate.length != 10 )
{
strDate = dateCtl.value;
}
fInitialDate(strDate);
fSetYearMon(giYear, giMonth);
// var point1 = fGetXY(ppCtl);
var point1 = fGetXY(dateCtrl);
with (VicPopCal.style)
{
left = point1.x;
// left = point1.x - parseFloat(dateCtrl.style.width.replace("px","")) - 6;
// top = point1.y+popCtrl.offsetHeight;
top = point1.y+dateCtrl.offsetHeight;
width = VicPopCal.offsetWidth-10;
height = VicPopCal.offsetHeight-60;
fToggleTags(point1);
visibility = 'visible';
}
hidControl();
}
function fGetXY(aTag)
{
var oTmp = aTag;
var pt = new Point(0,0);
do
{
pt.x += oTmp.offsetLeft;
pt.y += oTmp.offsetTop;
oTmp = oTmp.offsetParent;
} while(oTmp.tagName!="BODY");
return pt;
}
// Added by Han Chen
function fInitialDate(strDate)
{
if( strDate == null || strDate.length != 10 )
return false;
var sYear = strDate.substring(0,4);
var sMonth = strDate.substring(5,7);
var sDay = strDate.substring(8,10);
if( sMonth.charAt(0) == '0' ) { sMonth = sMonth.substring(1,2); }
if( sDay.charAt(0) == '0' ) { sDay = sDay.substring(1,2); }
var nYear = parseInt(sYear );
var nMonth = parseInt(sMonth);
var nDay = parseInt(sDay );
if ( isNaN(nYear ) ) return false;
if ( isNaN(nMonth) ) return false;
if ( isNaN(nDay ) ) return false;
var arrMon = new Array(12);
arrMon[ 0] = 31; arrMon[ 1] = nYear % 4 == 0 ? 29:28;
arrMon[ 2] = 31; arrMon[ 3] = 30;
arrMon[ 4] = 31; arrMon[ 5] = 30;
arrMon[ 6] = 31; arrMon[ 7] = 31;
arrMon[ 8] = 30; arrMon[ 9] = 31;
arrMon[10] = 30; arrMon[11] = 31;
if ( nYear < 1900 || nYear > 2100 ) return false;
if ( nMonth < 1 || nMonth > 12 ) return false;
if ( nDay < 1 || nDay > arrMon[nMonth - 1] ) return false;
giYear = nYear;
giMonth = nMonth;
giDay = nDay;
return true;
}
switch(getLanguage())
{
case "0":
var gMonths = new Array("Jan","Feb","Mar.","Apr.","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
break;
case "1":
// var gMonths = new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
var gMonths = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
break;
case "2":
// var gMonths = new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
var gMonths = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
break;
}
with (document)
{
write("<Div id='VicPopCal' style='POSITION:absolute;VISIBILITY:hidden;border:1px ridge;z-index:100;'>");
write("<table border='0' cellSpacing='0' cellPadding='1' bgcolor='#cccccc'>");
write("<TR>");
write("<td valign='middle' align='center'><input type='button' name='PrevMonth' value='<' style='height:20;width:20;FONT:bold' onClick='fPrevMonth()'>");
write(" <SELECT id='tbSelYear' name='tbSelYear' onchange='fUpdateCal()' Victor='Won'>");
for(i=1980;i<=2020;i++)
switch(getLanguage())
{
case "0":
write("<OPTION value='"+i+"'>"+i+" </OPTION>");
break;
case "1":
write("<OPTION value='"+i+"'>"+i+" 年</OPTION>");
break;
case "2":
write("<OPTION value='"+i+"'>"+i+" 年</OPTION>");
break;
}
write("</SELECT>");
write(" <select id='tbSelMonth' name='tbSelMonth' onchange='fUpdateCal()' Victor='Won'>");
for (i=0; i<12; i++)
write("<option value='"+(i+1)+"'>"+gMonths[i]+"</option>");
write("</SELECT>");
write(" <input type='button' name='PrevMonth' value='>' style='height:20;width:20;FONT:bold' onclick='fNextMonth()'>");
write("</td>");
write("</TR><TR>");
write("<td align='center'>");
write("<DIV style='background-color:teal'><table width='100%' border='0'>");
fDrawCal(giYear, giMonth, 17, '12');
write("</table></DIV>");
write("</td>");
write("</TR><TR><TD align='center'>");
// write("<TABLE width='100%'><TR><TD align='center'>");
write("<TABLE width='100%' border='0' cellSpacing='0' cellPadding='0'><TR><TD colspan='2' align='center'>");
switch(getLanguage())
{
case "0":
// write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetDate(0,0,0)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>Clear</B>");
// write("</td><td algin='center'>");
write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>Today<BR/>"+giYear+"-"+giMonth+"-"+giDay+"</B>");
write("</td><td algin='center'>");
write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetClose()' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>Close</B>");
break;
case "1":
// write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetDate(0,0,0)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>清空</B>");
// write("</td><td algin='center'>");
write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>今天<BR/>"+giYear+"-"+giMonth+"-"+giDay+"</B>");
write("</td><td algin='center'>");
write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetClose()' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>关闭</B>");
break;
case "2":
// write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetDate(0,0,0)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>清空</B>");
// write("</td><td algin='center'>");
write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>今天<BR/>"+giYear+"-"+giMonth+"-"+giDay+"</B>");
write("</td><td algin='center'>");
write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetClose()' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>關閉</B>");
break;
}
write("</td></tr></table>");
write("</TD></TR>");
write("</TABLE></Div>");
}
</script>
<table border="0" cellpadding="0" cellspacing="0" style="height: 21px">
<tr valign="top">
<td><asp:TextBox ID="txtDateTime" runat="server" Width="86px" Height="100%" BackColor="White"></asp:TextBox></td>
<td><asp:Button ID="imgSelect" runat="server" style="width: 20px; height: 98%" Text="" /></td>
</tr>
</table>
//get the language from cookie
function getLanguage()
{
// cookies are separated by semicolons
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
// a name/value pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
if (aCrumb[0] == "TASWEBLANGUAGE")
return aCrumb[1];
}
// a cookie with the requested name does not exist
return "0";
}
function getAllAttributes(object)
{
var strAttributes="";
for(var i=0;i<object.attributes.length;i++)
{
strAttributes=strAttributes+object.attributes(i).name+","
}
alert(strAttributes);
return true;
}
function hideCalendar()
{
HiddenDiv();
return true;
}
function isDate(sDate)
{
var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31];
var iaDate = new Array(3);
var year, month, day;
if (arguments.length != 1) return false;
iaDate = sDate.toString().split("-");
if (iaDate.length != 3) return false;
if (iaDate[1].length > 2 || iaDate[2].length > 2) return false;
if(iaDate[0] == "" || iaDate[1] == "" || iaDate[2] == "")
return false;
if(isNaN(iaDate[0]) || isNaN(iaDate[1]) || isNaN(iaDate[2]))
return false;
year = parseFloat(iaDate[0]);
month = parseFloat(iaDate[1]);
day=parseFloat(iaDate[2]);
if (year < 1900 || year > 2100) return false;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
if (month < 1 || month > 12) return false;
if (day < 1 || day > iaMonthDays[month - 1]) return false;
return true;
}
//如果输入的不是日期型,则修改为当前日期
function checkDateValue(dateCtr)
{
while(dateCtr.value.toString().indexOf("/") > 0)
{
dateCtr.value = dateCtr.value.toString().replace("/","-");
}
if(!isDate(dateCtr.value))
dateCtr.value=getNowDate();
return true;
}
//当前日期
function getNowDate()
{
var nn=new Date();
year1=nn.getYear();
mon1=nn.getMonth()+1;
date1=nn.getDate();
var monstr1;
var datestr1
if(mon1<10)
monstr1="0"+mon1;
else
monstr1=""+mon1;
if(date1<10)
datestr1="0"+date1;
else
datestr1=""+date1;
return year1+"-"+monstr1+"-"+datestr1;
}
//目标日期
function getlastweekDate()
{
var nn=new Date();
year1=nn.getYear();
mon1=nn.getMonth()+1;
date1=nn.getDate();
var mm=new Date(year1,mon1-1,date1);
var tmp1=new Date(2000,1,1);
var tmp2=new Date(2000,1,15);
var ne=tmp2-tmp1;
var mm2=new Date();
mm2.setTime(mm.getTime()-ne);
year2=mm2.getYear();
mon2=mm2.getMonth()+1;
date2=mm2.getDate();
if(mon2<10)
monstr2="0"+mon2;
else
monstr2=""+mon2;
if(date2<10)
datestr2="0"+date2;
else
datestr2=""+date2;
return year2+"-"+monstr2+"-"+datestr2;
}
var gdCtrl = new Object();
var goSelectTag = new Array();
var gcGray = "#808080";
var gcToggle = "#FB8664";
var gcBG = "#e5e6ec";
var gcClose = "#006600";
var wkBgColor= "Gray";
var previousObject = null;
var gdCurDate = new Date();
var giYear = gdCurDate.getFullYear();
var giMonth = gdCurDate.getMonth()+1;
var giDay = gdCurDate.getDate();
function fSetDate(iYear, iMonth, iDay)
{
var VicPopCal= document.getElementById("VicPopCal");
VicPopCal.style.visibility = "hidden";
if ((iYear == 0) && (iMonth == 0) && (iDay == 0))
{
gdCtrl.value = "";
}
else
{
iMonth = iMonth + 100 + "";
iMonth = iMonth.substring(1);
iDay = iDay + 100 + "";
iDay = iDay.substring(1);
if(gdCtrl.tagName == "INPUT")
{
gdCtrl.value = iYear+"-"+iMonth+"-"+iDay;
}
else
{
gdCtrl.innerText = iYear+"-"+iMonth+"-"+iDay;
}
}
for (i in goSelectTag)
goSelectTag[i].style.visibility = "visible";
goSelectTag.length = 0;
window.returnValue=gdCtrl.value;
hidControl();
// window.close();
}
function fSetClose()
{
var VicPopCal= document.getElementById("VicPopCal");
VicPopCal.style.visibility = "hidden";
hidControl();
}
function HiddenDiv()
{
var i;
var VicPopCal= document.getElementById("VicPopCal");
VicPopCal.style.visibility = "hidden";
for (i in goSelectTag)
goSelectTag[i].style.visibility = "visible";
goSelectTag.length = 0;
hidControl();
}
function fSetSelected(aCell)
{
var tbSelMonth = document.getElementById("tbSelMonth");
var tbSelYear = document.getElementById("tbSelYear");
var iOffset = 0;
var iYear = parseInt(tbSelYear.value);
var iMonth = parseInt(tbSelMonth.value);
aCell.bgColor = gcBG;
with (aCell.children["cellText"])
{
var iDay = parseInt(innerText);
if (color==gcGray)
iOffset = (Victor<10)?-1:1;
iMonth += iOffset;
if(iMonth<1)
{
iYear--;
iMonth = 12;
}
else if (iMonth>12)
{
iYear++;
iMonth = 1;
}
}
fSetDate(iYear, iMonth, iDay);
}
function Point(iX, iY)
{
this.x = iX;
this.y = iY;
}
function fBuildCal(iYear, iMonth)
{
var aMonth=new Array();
for(i=1;i<7;i++)
aMonth[i]=new Array(i);
var dCalDate=new Date(iYear, iMonth-1, 1);
var iDayOfFirst=dCalDate.getDay();
var iDaysInMonth=new Date(iYear, iMonth, 0).getDate();
var iOffsetLast=new Date(iYear, iMonth-1, 0).getDate()-iDayOfFirst+1;
var iDate = 1;
var iNext = 1;
for (d = 0; d < 7; d++)
aMonth[1][d] = (d<iDayOfFirst)?-(iOffsetLast+d):iDate++;
for (w = 2; w < 7; w++)
for (d = 0; d < 7; d++)
aMonth[w][d] = (iDate<=iDaysInMonth)?iDate++:-(iNext++);
return aMonth;
}
function fDrawCal(iYear, iMonth, iCellHeight, sDateTextSize)
{
switch(getLanguage())
{
case "0":
var WeekDay = new Array("SU","MO","TU","WE","TH","FR","SA");
break;
case "1":
var WeekDay = new Array("日","一","二","三","四","五","六");
break;
case "2":
var WeekDay = new Array("日","一","二","三","四","五","六");
break;
}
var styleWkTD = " bgcolor='"+wkBgColor+"' bordercolor='"+wkBgColor+"' valign='middle' align='center' height='"+iCellHeight+"' style='font:bold arial "+sDateTextSize+";";
var styleTD = " bgcolor='"+gcBG+"' bordercolor='"+gcBG+"' valign='middle' align='center' height='"+iCellHeight+"' style='font:bold arial "+sDateTextSize+";";
with (document)
{
write("<tr>");
for(i=0; i<7; i++)
{
write("<td "+styleWkTD+"color:white' >"+ WeekDay[i] + "</td>");
}
write("</tr>");
for (w = 1; w < 7; w++)
{
write("<tr>");
for (d = 0; d < 7; d++)
{
write("<td id=calCell "+styleTD+"cursor:hand;' onMouseOver='this.bgColor=gcToggle' onMouseOut='this.bgColor=gcBG' onclick='fSetSelected(this)'>");
write("<font id=cellText Victor='Hcy_Flag'> </font>");
write("</td>")
}
write("</tr>");
}
}
}
function fUpdateCal()
{
var iYear=document.getElementById("tbSelYear").value;
var iMonth=document.getElementById("tbSelMonth").value;
myMonth = fBuildCal(iYear, iMonth);
var i = 0;
for (w = 0; w < 6; w++)
for (d = 0; d < 7; d++)
with (cellText[(7*w)+d])
{
Victor = i++;
if (myMonth[w+1][d]<0)
{
color = gcGray;
innerText = -myMonth[w+1][d];
}
else
{
color = ((d==0)||(d==6))?"red":"black";
innerText = myMonth[w+1][d];
}
}
}
function fSetYearMon(iYear, iMon)
{
var tbSelMonth = document.getElementById("tbSelMonth");
var tbSelYear = document.getElementById("tbSelYear");
tbSelMonth.options[iMon-1].selected = true;
for (i = 0; i < tbSelYear.length; i++)
if (tbSelYear.options[i].value == iYear)
tbSelYear.options[i].selected = true;
fUpdateCal(iYear, iMon);
}
function fPrevMonth()
{
var tbSelMonth = document.getElementById("tbSelMonth");
var tbSelYear = document.getElementById("tbSelYear");
var iMon = tbSelMonth.value;
var iYear = tbSelYear.value;
if (--iMon<1)
{
iMon = 12;
iYear--;
}
fSetYearMon(iYear, iMon);
}
function fNextMonth()
{
var tbSelMonth = document.getElementById("tbSelMonth");
var tbSelYear = document.getElementById("tbSelYear");
var iMon = tbSelMonth.value;
var iYear = tbSelYear.value;
if (++iMon>12)
{
iMon = 1;
iYear++;
}
fSetYearMon(iYear, iMon);
}
function fToggleTags()
{
with (document.all.tags("SELECT"))
{
for (i=0; i<length; i++)
{
if (document.all.tags("SELECT").item(i).Victor==null) return;
if ((item(i).Victor!="Won")&&fTagInBound(item(i)))
{
item(i).style.visibility = "hidden";
goSelectTag[goSelectTag.length] = item(i);
}
}
}
}
function fTagInBound(aTag)
{
var VicPopCal= document.getElementById("VicPopCal");
with (VicPopCal.style)
{
var l = parseInt(left);
var t = parseInt(top);
var r = l+parseInt(width);
var b = t+parseInt(height);
var ptLT = fGetXY(aTag);
return !((ptLT.x>r)||(ptLT.x+aTag.offsetWidth<l)||(ptLT.y>b)||(ptLT.y+aTag.offsetHeight<t));
}
}
function getAbsolutePos(el)
{
var r = { x: el.offsetLeft, y: el.offsetTop };
if (el.offsetParent)
{
var tmp = getAbsolutePos(el.offsetParent);
r.x += tmp.x;
r.y += tmp.y;
}
return r;
}
function hidControl()
{
var tags = new Array("applet", "iframe", "select");
var el= document.getElementById("VicPopCal");
var p = getAbsolutePos(el);
var EX1 = p.x;
var EX2 = el.offsetWidth + EX1;
var EY1 = p.y;
var EY2 = el.offsetHeight + EY1;
for (var k = tags.length; k > 0; )
{
var ar = document.getElementsByTagName(tags[--k]);
var cc = null;
for (var i = ar.length; i > 0;)
{
cc = ar[--i];
p = getAbsolutePos(cc);
var CX1 = p.x;
var CX2 = cc.offsetWidth + CX1;
var CY1 = p.y;
var CY2 = cc.offsetHeight + CY1;
if (el.style.visibility == 'hidden' || (CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1))
{
if(cc.getAttribute("ID") != "tbSelYear" && cc.getAttribute("ID") != "tbSelMonth")
cc.style.visibility = "visible";
} else
{
if(cc.getAttribute("ID") != "tbSelYear" && cc.getAttribute("ID") != "tbSelMonth")
cc.style.visibility = "hidden";
}
}
}
}
// Main: popCtrl is the widget beyond which you want this calendar to appear;
// dateCtrl is the widget into which you want to put the selected date.
// i.e.: <input type="text" name="dc" style="text-align:center" readonly><INPUT type="button" value="V" onclick="fPopCalendar(dc,dc);return false">
function fPopCalendar(popCtrl, dateCtrl,strDate)
{
var ppCtl = popCtrl;//document.getElementById(popCtrl);
var dateCtl = dateCtrl;//document.getElementById(dateCtrl);
var VicPopCal= document.getElementById("VicPopCal");
// getAllAttributes(VicPopCal);
if (ppCtl == previousObject)
{
if (VicPopCal.style.visibility == "visible")
{
HiddenDiv();
return true;
}
}
previousObject = ppCtl;
gdCtrl = dateCtl;
if( strDate == null || strDate.length != 10 )
{
strDate = dateCtl.value;
}
fInitialDate(strDate);
fSetYearMon(giYear, giMonth);
// var point1 = fGetXY(ppCtl);
var point1 = fGetXY(dateCtrl);
with (VicPopCal.style)
{
left = point1.x;
// left = point1.x - parseFloat(dateCtrl.style.width.replace("px","")) - 6;
// top = point1.y+popCtrl.offsetHeight;
top = point1.y+dateCtrl.offsetHeight;
width = VicPopCal.offsetWidth-10;
height = VicPopCal.offsetHeight-60;
fToggleTags(point1);
visibility = 'visible';
}
hidControl();
}
function fGetXY(aTag)
{
var oTmp = aTag;
var pt = new Point(0,0);
do
{
pt.x += oTmp.offsetLeft;
pt.y += oTmp.offsetTop;
oTmp = oTmp.offsetParent;
} while(oTmp.tagName!="BODY");
return pt;
}
// Added by Han Chen
function fInitialDate(strDate)
{
if( strDate == null || strDate.length != 10 )
return false;
var sYear = strDate.substring(0,4);
var sMonth = strDate.substring(5,7);
var sDay = strDate.substring(8,10);
if( sMonth.charAt(0) == '0' ) { sMonth = sMonth.substring(1,2); }
if( sDay.charAt(0) == '0' ) { sDay = sDay.substring(1,2); }
var nYear = parseInt(sYear );
var nMonth = parseInt(sMonth);
var nDay = parseInt(sDay );
if ( isNaN(nYear ) ) return false;
if ( isNaN(nMonth) ) return false;
if ( isNaN(nDay ) ) return false;
var arrMon = new Array(12);
arrMon[ 0] = 31; arrMon[ 1] = nYear % 4 == 0 ? 29:28;
arrMon[ 2] = 31; arrMon[ 3] = 30;
arrMon[ 4] = 31; arrMon[ 5] = 30;
arrMon[ 6] = 31; arrMon[ 7] = 31;
arrMon[ 8] = 30; arrMon[ 9] = 31;
arrMon[10] = 30; arrMon[11] = 31;
if ( nYear < 1900 || nYear > 2100 ) return false;
if ( nMonth < 1 || nMonth > 12 ) return false;
if ( nDay < 1 || nDay > arrMon[nMonth - 1] ) return false;
giYear = nYear;
giMonth = nMonth;
giDay = nDay;
return true;
}
switch(getLanguage())
{
case "0":
var gMonths = new Array("Jan","Feb","Mar.","Apr.","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
break;
case "1":
// var gMonths = new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
var gMonths = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
break;
case "2":
// var gMonths = new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
var gMonths = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
break;
}
with (document)
{
write("<Div id='VicPopCal' style='POSITION:absolute;VISIBILITY:hidden;border:1px ridge;z-index:100;'>");
write("<table border='0' cellSpacing='0' cellPadding='1' bgcolor='#cccccc'>");
write("<TR>");
write("<td valign='middle' align='center'><input type='button' name='PrevMonth' value='<' style='height:20;width:20;FONT:bold' onClick='fPrevMonth()'>");
write(" <SELECT id='tbSelYear' name='tbSelYear' onchange='fUpdateCal()' Victor='Won'>");
for(i=1980;i<=2020;i++)
switch(getLanguage())
{
case "0":
write("<OPTION value='"+i+"'>"+i+" </OPTION>");
break;
case "1":
write("<OPTION value='"+i+"'>"+i+" 年</OPTION>");
break;
case "2":
write("<OPTION value='"+i+"'>"+i+" 年</OPTION>");
break;
}
write("</SELECT>");
write(" <select id='tbSelMonth' name='tbSelMonth' onchange='fUpdateCal()' Victor='Won'>");
for (i=0; i<12; i++)
write("<option value='"+(i+1)+"'>"+gMonths[i]+"</option>");
write("</SELECT>");
write(" <input type='button' name='PrevMonth' value='>' style='height:20;width:20;FONT:bold' onclick='fNextMonth()'>");
write("</td>");
write("</TR><TR>");
write("<td align='center'>");
write("<DIV style='background-color:teal'><table width='100%' border='0'>");
fDrawCal(giYear, giMonth, 17, '12');
write("</table></DIV>");
write("</td>");
write("</TR><TR><TD align='center'>");
// write("<TABLE width='100%'><TR><TD align='center'>");
write("<TABLE width='100%' border='0' cellSpacing='0' cellPadding='0'><TR><TD colspan='2' align='center'>");
switch(getLanguage())
{
case "0":
// write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetDate(0,0,0)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>Clear</B>");
// write("</td><td algin='center'>");
write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>Today<BR/>"+giYear+"-"+giMonth+"-"+giDay+"</B>");
write("</td><td algin='center'>");
write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetClose()' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>Close</B>");
break;
case "1":
// write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetDate(0,0,0)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>清空</B>");
// write("</td><td algin='center'>");
write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>今天<BR/>"+giYear+"-"+giMonth+"-"+giDay+"</B>");
write("</td><td algin='center'>");
write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetClose()' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>关闭</B>");
break;
case "2":
// write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetDate(0,0,0)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>清空</B>");
// write("</td><td algin='center'>");
write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>今天<BR/>"+giYear+"-"+giMonth+"-"+giDay+"</B>");
write("</td><td algin='center'>");
write("<B style='cursor:hand;color:"+gcClose+"' onclick='fSetClose()' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>關閉</B>");
break;
}
write("</td></tr></table>");
write("</TD></TR>");
write("</TABLE></Div>");
}
</script>
<table border="0" cellpadding="0" cellspacing="0" style="height: 21px">
<tr valign="top">
<td><asp:TextBox ID="txtDateTime" runat="server" Width="86px" Height="100%" BackColor="White"></asp:TextBox></td>
<td><asp:Button ID="imgSelect" runat="server" style="width: 20px; height: 98%" Text="" /></td>
</tr>
</table>
'in then code
Partial Class SelectDateTime
Inherits System.Web.UI.UserControl
Public Property DateTime() As String
Get
Return Me.txtDateTime.Text.Trim
End Get
Set(ByVal value As String)
Me.txtDateTime.Text = value
DisplayProperty()
End Set
End Property
Public Property DateTextWith() As String
Get
Return Me.txtDateTime.Width.ToString
End Get
Set(ByVal value As String)
Dim Str As String
If Right(value, 1) = "x" Then
Str = Left(value, Len(value) - 2)
Me.txtDateTime.Width = Unit.Pixel(Str)
ElseIf Right(value, 1) = "%" Then
Str = Left(value, Len(value) - 1)
Me.txtDateTime.Width = Unit.Percentage(Str)
Else
Me.txtDateTime.Width = value
End If
End Set
End Property
Public Property DateEnabled() As String
Get
Return Me.txtDateTime.Text.Trim
End Get
Set(ByVal value As String)
Me.txtDateTime.Enabled = value
Me.imgSelect.Enabled = value
End Set
End Property
Protected Sub DisplayPrEnabled()
ViewState("DateTextWith") = Me.txtDateTime.Enabled
End Sub
Protected Sub DisplayProWith()
ViewState("DateTextWith") = Me.txtDateTime.Width
End Sub
Protected Sub DisplayProperty()
ViewState("DateTime") = Me.txtDateTime.Text
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Me.Page.IsPostBack = False Then
Dim script As String = "fPopCalendar(" + Me.imgSelect.ClientID + "," + Me.txtDateTime.ClientID + ");return false"
Me.imgSelect.Attributes.Add("onclick", script)
Me.txtDateTime.Attributes.Add("onfocusout", "checkDateValue(" & Me.txtDateTime.ClientID & ")")
End If
End Sub
End Class
Inherits System.Web.UI.UserControl
Public Property DateTime() As String
Get
Return Me.txtDateTime.Text.Trim
End Get
Set(ByVal value As String)
Me.txtDateTime.Text = value
DisplayProperty()
End Set
End Property
Public Property DateTextWith() As String
Get
Return Me.txtDateTime.Width.ToString
End Get
Set(ByVal value As String)
Dim Str As String
If Right(value, 1) = "x" Then
Str = Left(value, Len(value) - 2)
Me.txtDateTime.Width = Unit.Pixel(Str)
ElseIf Right(value, 1) = "%" Then
Str = Left(value, Len(value) - 1)
Me.txtDateTime.Width = Unit.Percentage(Str)
Else
Me.txtDateTime.Width = value
End If
End Set
End Property
Public Property DateEnabled() As String
Get
Return Me.txtDateTime.Text.Trim
End Get
Set(ByVal value As String)
Me.txtDateTime.Enabled = value
Me.imgSelect.Enabled = value
End Set
End Property
Protected Sub DisplayPrEnabled()
ViewState("DateTextWith") = Me.txtDateTime.Enabled
End Sub
Protected Sub DisplayProWith()
ViewState("DateTextWith") = Me.txtDateTime.Width
End Sub
Protected Sub DisplayProperty()
ViewState("DateTime") = Me.txtDateTime.Text
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Me.Page.IsPostBack = False Then
Dim script As String = "fPopCalendar(" + Me.imgSelect.ClientID + "," + Me.txtDateTime.ClientID + ");return false"
Me.imgSelect.Attributes.Add("onclick", script)
Me.txtDateTime.Attributes.Add("onfocusout", "checkDateValue(" & Me.txtDateTime.ClientID & ")")
End If
End Sub
End Class