	var GLOBAL_DCAL_ACTIVE_INPUT;
	var GLOBAL_DCAL_CURRENT_YEAR_MONTH;
	var D_CAL_MONTHS = new Array('Januari','Februari','Mars','April','Maj','Juni','Juli','Augusti','September','Oktober','November','December');

	function dCalInit() {
		// dCalCreateContainer();
		var SEL_OBJ = document.forms["dCalForm"]["dCalMontsSel"];
		var BASE_DATE = dCalBaseDate();
		// populate select
		for (i=0; i < 12; i++) {
			addOption(SEL_OBJ, BASE_DATE.getFullYear()+"-"+dCalDateFriendlyDigits(BASE_DATE.getMonth()+1), D_CAL_MONTHS[BASE_DATE.getMonth()]+" "+BASE_DATE.getFullYear());
			BASE_DATE.setMonth(BASE_DATE.getMonth()+1);
		}
	}

	function dCalOpen(inputObj) {
		// position the shit!
		var dCalObj = getDocObjectById("dCal");
		dCalObj.style.left = (getObjectLeftPos(null, inputObj)+getObjectWidth(null, inputObj))+"px";
		dCalObj.style.top = getObjectTopPos(null, inputObj)+"px";

		displayDiv("dCal", true);
		GLOBAL_DCAL_ACTIVE_INPUT = inputObj;
		dCalPopulate(inputObj.value);
		var SEL_OBJ = document.forms["dCalForm"]["dCalMontsSel"];
		if (inputObj.value && inputObj.value.length == 10) {
			var selectValue = inputObj.value.substr(0,4)+inputObj.value.substr(4,3);
			for (var i=0; i < SEL_OBJ.options.length; i++) {
				if (SEL_OBJ.options[i].value == selectValue) {
					SEL_OBJ.selectedIndex = i;
					break;
				}
			}
		} else
			SEL_OBJ.selectedIndex = 0;
		SEL_OBJ.focus();
	}

	function dCalSelect(dateSelected) {
		if (GLOBAL_DCAL_ACTIVE_INPUT) {
			GLOBAL_DCAL_ACTIVE_INPUT.value = dateSelected;
			displayDiv("dCal", false);
		}
	}

	function dCalCheckReturnDate(startObj, endObj) {
		if (!startObj || !startObj.value || !endObj)
			return;
		else if (!endObj.value)
			endObj.value = startObj.value;
		else {
			var startDate = new Date();
			startDate.setFullYear(startObj.value.substr(0,4));
			startDate.setMonth(startObj.value.substr(5,2).substr(0,1) == "0" ? startObj.value.substr(6,1) : startObj.value.substr(5,2));
			startDate.setDate(startObj.value.substr(8,2).substr(0,1) == "0" ? startObj.value.substr(9,1) : startObj.value.substr(8,2));
			var endDate = new Date();
			endDate.setFullYear(endObj.value.substr(0,4));
			endDate.setMonth(endObj.value.substr(5,2).substr(0,1) == "0" ? endObj.value.substr(6,1) : endObj.value.substr(5,2));
			endDate.setDate(endObj.value.substr(8,2).substr(0,1) == "0" ? endObj.value.substr(9,1) : endObj.value.substr(8,2));
			if (startDate > endDate)
				endObj.value = startObj.value;
		}
	}

	function dCalPopulate(preDefined) {
		var i, j;
		var BASE_DATE = dCalBaseDate(preDefined);
		GLOBAL_DCAL_CURRENT_YEAR_MONTH = BASE_DATE.getFullYear()+"-"+dCalDateFriendlyDigits(BASE_DATE.getMonth()+1)+"-";
		// populate calendar
		var startDay = (BASE_DATE.getDay() == 0 ? 7 : BASE_DATE.getDay());
		var endDay = dCalDaysInMonth(BASE_DATE.getMonth(), BASE_DATE.getFullYear());
		//alert(startDay + "#" + endDay + "#" + BASE_DATE)
		// calculate start week...
		BASE_DATE.setDate(1);
		var calIdx = 0;
		var dayCounter = 1;
		var divWeekObj, divWeekRowObj, divObj;
		for (i=1; i < 7; i++) {
			for (j=1; j < 8; j++) {

				if (j == 1) {
					divWeekObj = getDocObjectById("dCalWeek"+i);
					divWeekObj.innerHTML = BASE_DATE.getWeek();
					divWeekObj.onclick = function() { void(0); };
					BASE_DATE.setDate(BASE_DATE.getDate()+7);

					divWeekRowObj = getDocObjectById("dCalWeekRow"+i);
					divWeekRowObj.style.display = ((endDay+startDay) < calIdx+2) ? "none" : "block";
				}

				calIdx++;
				divObj = getDocObjectById("dCalDays"+calIdx);
				if (startDay > calIdx || (endDay+startDay-1) < calIdx) {
					divObj.innerHTML = "&nbsp;";
					divObj.className = "dCalDayInactive";
					divObj.onclick = function() { void(0); };
				} else {
					divObj.innerHTML = dayCounter++;
					divObj.className = "dCalDay";
					divObj.onclick = function() {
						dCalSelect(GLOBAL_DCAL_CURRENT_YEAR_MONTH+dCalDateFriendlyDigits(this.innerHTML));
					};
				}
			}
		}
	}

	function dCalBaseDate(preDefined) {
		var DATE = new Date();
		DATE.setDate(1);
		if (preDefined) {
			DATE.setFullYear( parseInt(preDefined.substr(0,4)) );
			DATE.setMonth( parseInt((preDefined.substr(5,2).substr(0,1) == "0" ? preDefined.substr(6,1) : preDefined.substr(5,2)))-1 );
		}
		return DATE;
	}

	/// "help" functions
	Date.prototype.getWeek = function () {
		var year = this.getFullYear();
		var month = this.getMonth()+1;
		var day = this.getDate();
		var a = Math.floor((14-(month))/12);
		var y = year+4800-a;
		var m = (month)+(12*a)-3;
		var jd = day + Math.floor(((153*m)+2)/5) + (365*y) + Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400) - 32045;
		var d4 = (jd+31741-(jd%7))%146097%36524%1461;
		var L = Math.floor(d4/1460);
		var d1 = ((d4-L)%365)+L;
		return Math.floor(d1/7) + 1;
	};
	function dCalDaysInMonth(iMonth, iYear) { return 32 - new Date(iYear, iMonth, 32).getDate(); };
	function dCalDateFriendlyDigits(val) { return (val < 10 ? "0" : "")+val; };
	

	document.write('<div id="dCal">');
	document.write('  <iframe style="position: absolute; top: 0; left: 0; height: 100%; width:100%; border: 0; z-index: -1;"></iframe>');
	document.write('	<form action="" name="dCalForm" style="margin:0;padding:0;" onsubmit="return false;">');
	document.write('	<div id="dCalClose"><a href="javascript:displayDiv(\'dCal\', false)">Stäng</a></div>');
	document.write('	<div id="dCalSelection">Välj månad: <select name="dCalMontsSel" onchange="dCalPopulate(this.options[this.selectedIndex].value)"></select></div>');
	document.write('	<div id="dCalDaysHead">');
	document.write('		<div class="dCalRow">');
	document.write('			<div class="dCalWeek">Vecka</div>');
	document.write('			<div class="dCalDay">Mån</div>');
	document.write('			<div class="dCalDay">Tis</div>');
	document.write('			<div class="dCalDay">Ons</div>');
	document.write('			<div class="dCalDay">Tor</div>');
	document.write('			<div class="dCalDay">Fre</div>');
	document.write('			<div class="dCalDay">Lör</div>');
	document.write('			<div class="dCalDay">Sön</div>');
	document.write('			<div class="clearer"></div>');
	document.write('		</div>');
	document.write('	</div>');
	document.write('	<div id="dCalDays">');
	document.write('		<div id="dCalWeekRow1" class="dCalRow"><div id="dCalWeek1" class="dCalWeek"></div><div id="dCalDays1" class="dCalDay"></div><div id="dCalDays2" class="dCalDay"></div><div id="dCalDays3" class="dCalDay"></div><div id="dCalDays4" class="dCalDay"></div><div id="dCalDays5" class="dCalDay"></div><div id="dCalDays6" class="dCalDay"></div><div id="dCalDays7" class="dCalDay"></div><div class="clearer"></div></div>');
	document.write('		<div id="dCalWeekRow2" class="dCalRow"><div id="dCalWeek2" class="dCalWeek"></div><div id="dCalDays8" class="dCalDay"></div><div id="dCalDays9" class="dCalDay"></div><div id="dCalDays10" class="dCalDay"></div><div id="dCalDays11" class="dCalDay"></div><div id="dCalDays12" class="dCalDay"></div><div id="dCalDays13" class="dCalDay"></div><div id="dCalDays14" class="dCalDay"></div><div class="clearer"></div></div>');
	document.write('		<div id="dCalWeekRow3" class="dCalRow"><div id="dCalWeek3" class="dCalWeek"></div><div id="dCalDays15" class="dCalDay"></div><div id="dCalDays16" class="dCalDay"></div><div id="dCalDays17" class="dCalDay"></div><div id="dCalDays18" class="dCalDay"></div><div id="dCalDays19" class="dCalDay"></div><div id="dCalDays20" class="dCalDay"></div><div id="dCalDays21" class="dCalDay"></div><div class="clearer"></div></div>');
	document.write('		<div id="dCalWeekRow4" class="dCalRow"><div id="dCalWeek4" class="dCalWeek"></div><div id="dCalDays22" class="dCalDay"></div><div id="dCalDays23" class="dCalDay"></div><div id="dCalDays24" class="dCalDay"></div><div id="dCalDays25" class="dCalDay"></div><div id="dCalDays26" class="dCalDay"></div><div id="dCalDays27" class="dCalDay"></div><div id="dCalDays28" class="dCalDay"></div><div class="clearer"></div></div>');
	document.write('		<div id="dCalWeekRow5" class="dCalRow"><div id="dCalWeek5" class="dCalWeek"></div><div id="dCalDays29" class="dCalDay"></div><div id="dCalDays30" class="dCalDay"></div><div id="dCalDays31" class="dCalDay"></div><div id="dCalDays32" class="dCalDay"></div><div id="dCalDays33" class="dCalDay"></div><div id="dCalDays34" class="dCalDay"></div><div id="dCalDays35" class="dCalDay"></div><div class="clearer"></div></div>');
	document.write('		<div id="dCalWeekRow6" class="dCalRow"><div id="dCalWeek6" class="dCalWeek"></div><div id="dCalDays36" class="dCalDay"></div><div id="dCalDays37" class="dCalDay"></div><div id="dCalDays38" class="dCalDay"></div><div id="dCalDays39" class="dCalDay"></div><div id="dCalDays40" class="dCalDay"></div><div id="dCalDays41" class="dCalDay"></div><div id="dCalDays42" class="dCalDay"></div><div class="clearer"></div></div>');
	document.write('	</div>');
	document.write('	</form>');
	document.write('</div>');
	setTimeout("dCalInit()", 200);
