function getCalendar(htmlID, year, month, day, oldDates, yearDivID, monthDivID, dayDivID, divChoosenDateDivID)
{
	var todayColor, clickedColor, backgroundColor, textColor, dayColor, nextOrBeforeColor;

	if(!oldDates)
	{
		oldDates = 0;
	}

	//todayColorImg = "";
	clickedColor = "#000";
	backgroundColor = "#f3f4f4";
	textColor = "#54636e";
	dayColor = "#f3f4f4";
	nextOrBeforeColor = "#cdc9c4";
	
 var temp = 1;
 var j = 1;
	
	
	var monthArray = new Array();
	monthArray[1] = "Januari";
	monthArray[2] = "Februari";
	monthArray[3] = "Mars";
	monthArray[4] = "April";
	monthArray[5] = "Maj";
	monthArray[6] = "Juni";
	monthArray[7] = "Juli";
	monthArray[8] = "Augusti";
	monthArray[9] = "September";
	monthArray[10] = "Oktober";
	monthArray[11] = "November";
	monthArray[12] = "December";


	
	var date = new Date();
	
	// Used to only make todays date and forward clickable, se line 373 and forward
	var tempDate = date;
	tempDate.setDate(tempDate.getDate()-1);
	
	// Ifall datum inte är satt, sätt till dagens
	if(year == "")
	{
		year = date.getFullYear();
	}

	if(month === "")
	{
		month = date.getMonth();
	}
	
	if(day == "")
	{
		day = date.getDate();
	}

	var userDate = new Date(year, month, day);
	startDate = new Date(userDate.getFullYear(), userDate.getMonth(), 1);
	var lastDateInMonth = new Date(userDate.getFullYear(), userDate.getMonth() + 1, 0);
	var endDate = new Date(userDate.getFullYear(), userDate.getMonth() + 1, 0);
	var nextMonth = new Date(userDate.getFullYear(), userDate.getMonth(), 1);
	var previousMonth = new Date(userDate.getFullYear(), userDate.getMonth(), 1);
	
	var todayDate = new Date();
	
	// Set nextMonth
	nextMonth.setMonth(nextMonth.getMonth() + 1);

	// Set previous month
	previousMonth.setMonth(previousMonth.getMonth() - 1);

	// Get startdate, always a monday
	while(startDate.getDay() !== 1)
	{
		startDate.setDate(startDate.getDate() - 1);
	}
	
	// Get enddate, always a sunday
	while(endDate.getDay() !== 0)
	{
		endDate.setDate(endDate.getDate() + 1);
	}

	var curTempDivID = "dayDivm"+userDate.getMonth() + 1+"d"+1;
	
	// Table var, that are returned later on
	table = "<table height='160' width='148' border='0' style='color :" +textColor +"; border: solid 1px #000; background-color: " + backgroundColor+"' cellspacing='0' cellpadding='0' >";
	table += "<tr> <td style='height: 22px; border-bottom: solid 1px;'><a style='margin-left:5px; cursor: pointer;' onclick = \"setDate('"+curTempDivID+"', '"+previousMonth.getFullYear()+"', '"+previousMonth.getMonth()+"', '"+1+"', '"+yearDivID+"', '"+monthDivID+"', '"+dayDivID+"', '"+divChoosenDateDivID+"', '"+htmlID+"' ) \">&laquo;&laquo;</<a></td><td style = 'border-bottom: solid 1px; font-family: tahoma; font-size: 12px; font-weight: bold; color :" +textColor +"; text-align: center'>	"+ monthArray[(userDate.getMonth() + 1)] + " " + userDate.getFullYear() + "	</td>				<td style='border-bottom: solid 1px;' align='right'>		<a  style='margin-right:5px; cursor: pointer;' onclick = \"setDate('"+curTempDivID+"', '"+nextMonth.getFullYear()+"', '"+nextMonth.getMonth()+"', '"+1+"', '"+yearDivID+"', '"+monthDivID+"', '"+dayDivID+"', '"+divChoosenDateDivID+"', '"+htmlID+"' ) \">&raquo;&raquo;</<a>							</td>	</tr>";
	table += "<tr>";
	table += "<td valign='top' colspan='3'>";
	
	// Loop through calendar
	while((Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate())) < (Date.UTC(endDate.getFullYear(), endDate.getMonth(), endDate.getDate())) )
	{

		table += "<div style='margin-left: 2px; margin-right: 2px; clear: both; '>";
		
		temp = 1;
		for(i = 1; i < 8; i++)
		{
			if(startDate.getFullYear() == year && startDate.getMonth() == month && startDate.getDate() == day)
			{
				innerTD = " background-color:"+clickedColor;
				curTextColor = textColor;
			}
			else
			{
				curTextColor = textColor;
				if (temp == 2)
				{
					innerTD = " background-color:"+dayColor;
				}
				else
				{
					innerTD = " background-color: #FFFFFF";
				}
			}
			
			if (temp == 2)
			{
				temp=1;
			}
			else
			{
				temp=2;
			}
			
			table += "<div id='dayDivm"+startDate.getMonth()+"d"+startDate.getDate()+"' style=' float:left; padding-top: 2px; " + innerTD + "; height: 14px; width: 18px; margin-top: 4px; font-size: 11px; font-weight: bold;  border:solid 1px; vertical-align:middle;'><center>";
			var tempDivID = "dayDivm"+startDate.getMonth()+"d"+startDate.getDate();
			curOperators = "&year=" + startDate.getFullYear() + "&month="+ startDate.getMonth() + "&day="+startDate.getDate();

			
			if(oldDates == 0)
			{
				if(startDate > tempDate)
				{
					table += "<a  style = 'cursor: pointer; text-decoration : none; color :" +curTextColor +"' onclick='setDate(\""+tempDivID+"\", \""+startDate.getFullYear()+"\", \""+startDate.getMonth()+"\", \""+startDate.getDate()+"\", \""+yearDivID+"\", \""+monthDivID+"\", \""+dayDivID+"\", \""+divChoosenDateDivID+"\", \""+htmlID+"\" )' >" + startDate.getDate() + "</a>";
				}
				else
				{
					table += startDate.getDate();			
				}
			}
			else if(oldDates == 1)
			{
				
				table += "<a  style = 'cursor: pointer; text-decoration : none; color :" +curTextColor +"' onclick='setDate(\""+tempDivID+"\", \""+startDate.getFullYear()+"\", \""+startDate.getMonth()+"\", \""+startDate.getDate()+"\", \""+yearDivID+"\", \""+monthDivID+"\", \""+dayDivID+"\", \""+divChoosenDateDivID+"\", \""+htmlID+"\")' >" + startDate.getDate() + "</a>";	
			}
				
			table += "</center></div>";
			
			startDate.setDate(startDate.getDate() + 1);
		}
		table += "</div>";
	}
	table += "</tr>";
	table += "</td>";
	table += "</table>";

	document.getElementById(htmlID).innerHTML = table;

}

function setDate(divID, year, month, day, yearDivID, monthDivID, dayDivID, divChoosenDateDivID, calendarDivID)
{
	//var divElement = document.getElementById(divID);
	var yearElement = document.getElementById(yearDivID);
	var monthElement = document.getElementById(monthDivID);
	var dayElement = document.getElementById(dayDivID);
	var choosenDate = document.getElementById(divChoosenDateDivID);
	
	// Change BG-color
	//divElement.style.background = "#000";
	
	// Ökar månaden med 1
	var tempMonth = parseInt(month, 10);
	tempMonth++;
	
	// Change date values
	yearElement.value = year;
	monthElement.value = tempMonth;
	dayElement.value = day;

	choosenDate.innerHTML = day + "/" + tempMonth + " " + year; 
	
	// Print calendar again
	getCalendar(calendarDivID, year, month, day, "0", yearDivID, monthDivID, dayDivID, divChoosenDateDivID);
	
}