//place these scripts within BODY tag if you are using IE 4.0 or below.
//****************************************************************************
// PopCalendar 3.50, Emailware(please mail&commend me if u like it)
// Originally coded by Liming(Victor) Weng, email: victorwon@netease.com
// Release date: 2000.3.13
// Anyone may modify it to satify his needs, but please leave this comment ahead.
//****************************************************************************
<!-- Begin
var gdCtrl = new Object();
var goSelectTag = new Array();
var gcGray = "#808080";
var gcToggle = "#FFFF00";
var gcBG = "#D7D7D7";
var gcBG2 = "#000000";

var gdCurDate = new Date();
var giYear = gdCurDate.getFullYear();
var giMonth = gdCurDate.getMonth()+1;
var giDay = gdCurDate.getDate();

//****************************************************************************
// Param:	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){
  event.cancelBubble=true;
  gdCtrl = dateCtrl;
  fSetYearMon(giYear, giMonth);
  var point = fGetXY(popCtrl);
  with (VicPopCal.style) {
  	left = point.x;
	top  = point.y+popCtrl.offsetHeight+1;
	width = VicPopCal.offsetWidth;
	height = VicPopCal.offsetHeight;
	fToggleTags(point);
	visibility = 'visible';
  }
  VicPopCal.focus();
}

function fSetDate(iYear, iMonth, iDay){
  if(iDay<10) iDay = "0"+iDay;
  if(iMonth<10) iMonth = "0"+iMonth;
  
  gdCtrl.value = iDay+"-"+iMonth+"-"+iYear; //Here, you could modify the locale as you need !!!!
  try{
    gdCtrl.onchange();
  }catch(e){
  };
  fHideCalendar();
}

function fClearDate(){
  gdCtrl.value = "";
  try{
    gdCtrl.onchange();
  }catch(e){
  };

  fHideCalendar();
}



function fSetFutureDate(){
	var AddDays = 1;  //  How many days ahead of the current date
	TDate = new Date();
	TDay = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	TMonth = new Array('1','2','3','4','5','6','7','8','9','10','11','12');
	MonthDays = new Array('31','28','31','30','31','30','31','31','30','31','30','31');

	function isLeapYear(Year)
		{
		if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0))
			{
			return true;
			}
		else
			{
			return false;
			}
		}
	
	CurYear = TDate.getYear();
	
	if (CurYear < 2000)       // Y2K Fix, Isaac Powell
		CurYear = CurYear + 1900; // http://onyx.idbsu.edu/~ipowell
		CurMonth = TDate.getMonth();
		CurDayOw = TDate.getDay();
		CurDay = TDate.getDate();
		month = TMonth[CurMonth];
	
	if (month == 'February'){
		if (((CurYear % 4)==0) && ((CurYear % 100)!=0) || ((CurYear % 400)==0))
		{
		MonthDays[1] = 29;
		}
		else
		{
		MonthDays[1] = 28;
		}
	}
	
	days = MonthDays[CurMonth];
	CurDay += AddDays;
	if (CurDay > days)
		{
		if (CurMonth == 11)
			{
			CurMonth = 0;
			month = TMonth[CurMonth];
			CurYear = CurYear + 1
			}
		else
			{
			month = TMonth[CurMonth+1];
			}
		CurDay = CurDay - days;
		}
	
	CurDayOw += AddDays;
	
	function adjustDay(cday)
		{
		if (cday > 6)
			{
			cday -= 6;
			CurDayOw = TDay[cday-1];
			adjustDay(cday-1);
			}
		else
			{
			CurDayOw = TDay[cday];
			return true;
			}
		}
	
	adjustDay(CurDayOw);
  //#Code Opdateret af MHN 17-03-2004. Genbruger fSetDate til at indsætte selve datoen. 
  //#Code fSetDate ændrer 1-3-2005 til 02-03-2005 og gør det simplere at validere at det er en dato..
	if (CurYear<100) CurYear="19" + CurYear;
  fSetDate(CurYear, month , CurDay);
}



function fHideCalendar(){
 
  VicPopCal.style.visibility = "hidden";
 
  //for (i in goSelectTag){
  var i;
  for (i=0; i < goSelectTag.length; i++) {
  	goSelectTag[i].style.visibility = "visible";
  }
  goSelectTag.length = 0;
  
}

function fSetSelected(aCell){
  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, iDateTextSize) {
  var WeekDay = new Array("Su","Mo","Tu","We","Th","Fr","Sa");
  var styleTD = " bgcolor='"+gcBG+"' bordercolor='"+gcBG+"' valign='middle' align='center' height='"+iCellHeight+"' style='font:bold "+iDateTextSize+" Verdana,Arial,Helvetica;";

  with (document) {
	write("<tr>");
	for(i=0; i<7; i++)
		write("<td bgcolor='black' "+styleTD+"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='Liming Weng'></font>");
			write("</td>")
		}
		write("</tr>");
	}
  }
}



function fUpdateCal(iYear, iMonth) {
  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){
  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 iMon = tbSelMonth.value;
  var iYear = tbSelYear.value;

  if (--iMon<1) {
	  iMon = 12;
	  iYear--;
  }

  fSetYearMon(iYear, iMon);
}

function fNextMonth(){
  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 ((item(i).Victor!="Won")&&fTagInBound(item(i))){
 			item(i).style.visibility = "hidden";
 			goSelectTag[goSelectTag.length] = item(i);
 		}
  }
}

function fTagInBound(aTag){
  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 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;
}

//var gMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var gMonths = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

with (document) {
write("<Div id='VicPopCal' onclick='event.cancelBubble=true' style='POSITION:absolute;visibility:hidden;border:2px ridge;width:10;z-index:100;'>");
	write("<table border='0' bgcolor='#FFFFE2'>");
	write("<tr>");
	write("<tr>");
	write("<td align='center' nowrap>");
//	write("<input type='button' style='font-weight: bold;width:100%' onclick='fSetDate(giYear,giMonth,giDay)' value='Today:&nbsp;"+giDay+"&nbsp;"+gMonths[giMonth-1]+"&nbsp;"+giYear+"'>");
	write("<input type='button' style='font-weight: bold;width:49%' onclick='fSetDate(giYear,giMonth,giDay)' value='I dag'>&nbsp;");
	write("<input type='button' style='font-weight: bold;width:49%' onclick='fSetFutureDate()' value='I morgen'>");
  write("<br><input type='button' style='font-weight: bold;width:49%' onclick='fClearDate()' value='Slet dato'>");
  
	write("</td>");
	write("</tr>");
	write("<td valign='middle' align='center'>");
	write("<input type='button' name='PrevMonth' value='<' style='height:20;width:20;FONT:16 Fixedsys' onClick='fPrevMonth()'>");
	write("&nbsp;&nbsp;");
	write("<select name='tbSelMonth' onChange='fUpdateCal(tbSelYear.value, tbSelMonth.value)' Victor='Won'>");
	for (i=0; i<12; i++)
		write("<option value='"+(i+1)+"'>"+gMonths[i]+"</option>");
	write("</select>");
	write("&nbsp;&nbsp;")
	write("<select name='tbSelYear' onChange='fUpdateCal(tbSelYear.value, tbSelMonth.value)' Victor='Won'>");
	for(i=1930;i<=2010;i++)
		write("<option value='"+i+"'>&nbsp;"+i+"&nbsp;</option>");
	write("</select>");
	write("&nbsp;&nbsp;");
	write("<input type='button' name='PrevMonth' value='>' style='height:20;width:20;FONT:16 Fixedsys' onclick='fNextMonth()'>");
	write("</td>");
	write("</tr>");
	write("<tr>");
	write("<td align='center'>");
		write("<div style='background-color:teal;'>");
			write("<table width='100%' border='2' cellpadding='2'>");
				fDrawCal(giYear, giMonth, 10, 10);
			write("</table>");
		write("</div>");
	write("</td>");
	write("</tr>");
	write("</td>");
	write("</tr>");
	write("</table>");
write("</div>");
write("<SCRIPT event=onclick() for=document>fHideCalendar();</SCRIPT>");
}
// End --  -->