	var todayObj = new Date();
	var currMonth = todayObj.getMonth();
	var currYear = todayObj.getFullYear();
	var currHour = todayObj.getHours();
	var currMin = todayObj.getMinutes();

	var browserIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1;
	var timeoutId

	monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	leapYears = new Array(2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032);
	weekDays = new Array("Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"); // However in Javascript this starts with Sun and ends with Sat

	function buildCalMonth_func(mnth, yr){ // mnth is set as 0-11, yr is a in format yyyy
		// Remove dynamically created from javascript calender elements
		if (document.getElementById('calMain').childNodes[0]){
			childrenObj = document.getElementById('calMain').childNodes[0];
			document.getElementById('calMain').removeChild(childrenObj);
		}

		document.getElementById('calTitle').removeChild(document.getElementById('calTitle').childNodes[0])
		cellData = document.createTextNode(monthNames[mnth]+" "+yr);
		document.getElementById('calTitle').appendChild(cellData)
		// Check if is Leap Year and set Feb as 28 or 29 days
		isleapyear=0
		for(i=0;i<leapYears.length;i++){
			if (yr == leapYears[i]){
				isleapyear=1;
				break;
			}
		}
		if (mnth == 1 && isleapyear==1){
			numDays = 29;
		} else {
			numDays = monthDays[mnth];
		}
		var newEl = document.createElement('TABLE');
		newEl.setAttribute('cellPadding',2);
		newEl.setAttribute('cellSpacing',0);
		if (browserIE){newEl.setAttribute('className','calTab')} else {newEl.setAttribute('class','calTab')}
		newEl.setAttribute('width','100%');
		var body = document.createElement('TBODY'); // IE requires that TBODY be added otherwise table will not work
		newEl.appendChild(body);

		var row = document.createElement('TR');
		row.setAttribute("style","font-size:9px");
		if (browserIE){row.setAttribute('className','monsun')} else {row.setAttribute('class','monsun')}
		weekDaysLen = weekDays.length
		for (i=0;i<weekDaysLen;i++){
			var container = document.createElement('TD');
			container.setAttribute('align','center');
			cellData = document.createTextNode(weekDays[i]);
			container.appendChild(cellData);
			row.appendChild(container);
		}
		body.appendChild(row);
		dateObj = new Date();
		dateObj.setTime(Date.parse(monthNames[mnth]+" 1,"+yr)) // Update DateObj to start of the month
		firstDay = dateObj.getDay();
		if (firstDay == 0){firstDay=7;}
		c=1;
		var row = document.createElement('TR');
		for (i=0;i<weekDaysLen;i++){
			if (i < (firstDay-1)){
				var container = document.createElement('TD');
				container.setAttribute('align','center');
				cellData = document.createTextNode("");
				container.appendChild(cellData);
				row.appendChild(container);
				c++;
			}
		}

		for (d=1;d<=numDays;d++){
			dateObj.setTime(Date.parse(monthNames[mnth]+" "+d+","+yr+" "+currHour+":"+(currMin+1)+":00")) // Add 1 here to make current day clickable
			var container = document.createElement('TD');
			cellData = document.createTextNode(d);
			if (todayObj > dateObj){
				if (browserIE){container.setAttribute('className','calDayOld')} else {container.setAttribute('class','calDayOld')}
			} else {
				if (browserIE){container.setAttribute('className','calDay')} else {container.setAttribute('class','calDay')}
			}
			container.setAttribute('align','center');
			container.setAttribute('id',d+"-"+mnth+"-"+yr);
			container.appendChild(cellData);
			row.appendChild(container);
			if (c >= 7){
				body.appendChild(row);
				var row = document.createElement('TR');
				c=1;
			} else {
				c++;
			}
		}
		body.appendChild(row);
		document.getElementById('calMain').appendChild(newEl);
		initCalTab_func();
	}

	function nextMonth_func(){
		if ((currMonth+1) > 11){ // Beyond December so next year
			currYear++;
			currMonth = 0;
		} else {
			currMonth++;
		}
		buildCalMonth_func(currMonth, currYear);
	}

	function prevMonth_func(){
		if ((currMonth-1) < 0){ // Beyond January so previous year
			currYear--;
			currMonth = 11;
		} else {
			currMonth--;
		}
		buildCalMonth_func(currMonth, currYear);
	}

	function initCalTab_func(){
		caltab = document.getElementById('calMain').childNodes[0];
		tdObjs = caltab.getElementsByTagName("TD")
		l = tdObjs.length;
		for(i=0;i<l;i++){
			if (tdObjs[i].className == "calDay"){
				tdObjs[i].onmouseover = calDayMover_func;
				tdObjs[i].onmouseout = calDayMout_func;
				tdObjs[i].onclick = calDayClick_func;
			}
		}
	}

	function calDayMover_func(){
		setStyle_func(this, 'background', '#E8112D')
	}
	function calDayMout_func(){
		setStyle_func(this, 'background', '');
	}
	function calDayClick_func(){
		d = this.id.split("-")[0];
		m = this.id.split("-")[1];
		y = this.id.split("-")[2];
		document.forms[0][frmDayName].selectedIndex=d-1;
		document.forms[0][frmMnthName].selectedIndex=m;
		document.forms[0][frmYrName].selectedIndex=y-2000;
		hideCal_func();
	}

	function showCal_func(obj){	
		buildCalMonth_func(currMonth, currYear);
		objTop = obj.offsetTop;
		objLeft = obj.offsetLeft+obj.width+2;
		lastobj = obj
		totalLeft=lastobj.offsetLeft;
		totalTop=lastobj.offsetTop;
		for(i=0;i<=50;i++){
			if (lastobj.offsetParent){
				lastobj = lastobj.offsetParent;
				totalLeft+=lastobj.offsetLeft;
				totalTop+=lastobj.offsetTop;				
			} else {
				break;
			}
		}
		
		setStyle_func(document.getElementById('calenderObj'),'visibility','visible');
		setStyle_func(document.getElementById('calenderObj'),'top',totalTop);
		setStyle_func(document.getElementById('calenderObj'),'left',totalLeft+obj.width+2);		
		setStyle_func(document.forms[0].dthour,'visibility','hidden');
		setStyle_func(document.forms[0].dtmin,'visibility','hidden');		
	}

	function hideCal_func(){
		setStyle_func(document.getElementById('calenderObj'),'visibility','hidden');
		setStyle_func(document.forms[0].dthour,'visibility','visible');
		setStyle_func(document.forms[0].dtmin,'visibility','visible');			
	}

	function calendarTimer(){
		timeoutId=setTimeout('hideCal_func();',1000);
	}
