var vcg_calendar_cellpadding = 2;
var vcg_calendar_cellspacing = 0;
var vcg_calendar_table_styles = "";

function VCGCloseCalendar(id)
{
	try
	{
		document.getElementById("vcg_calendar_div_" + id).style.display = "none";
	}
	catch (err)
	{
		alert("Error : vcgcalendar.js - VCGCloseCalendar() - " + err.description);
	}
}

function VCGHideAllCalendars()
{
	try
	{
		var calendar_divs = document.getElementsByTagName("div");

		for (var i = 0; i < calendar_divs.length; i++)
		{
			var calendar_div = calendar_divs[i];

			if (calendar_div.id.indexOf('vcg_calendar_div_') == 0)
				calendar_div.style.display = "none";
		}
	}
	catch (err)
	{
		alert("Error : vcgcalendar.js - VCGHideAllCalendars() - " + err.description);
	}
}

function VCGShowCalendar(id, selected_day, selected_month, selected_year, split_date, is_label, top, left, offset_top, offset_left, fix_to_item, years_from, years_to, bgcolor, calendar_bgcolor, nav_color, nav_bgcolor, nav_font_size, nav_font_weight, header_color, header_bgcolor, header_font_size, header_font_weight, selected_color, selected_bgcolor, selected_font_size, selected_font_weight, notselected_color, notselected_bgcolor, notselected_font_size, notselected_font_weight)
{
	try
	{
		VCGHideAllCalendars();

		if (is_label)
		{
			var selected_date = new Date(document.getElementById("VCGCalendarLabel_" + id).innerHTML);
		}
		else
		{
			if (split_date)
				var selected_date = new Date(VCGCalendar_GetMonthName(document.getElementById(id + "_month").value) + " " + document.getElementById(id + "_day").value + ", " + document.getElementById(id + "_year").value);
			else
				var selected_date = new Date(document.getElementById(id).value);
		}

		var cal_day = selected_date.getDate();
		var cal_month = selected_date.getMonth() + 1;
		var cal_year = selected_date.getFullYear();

		if ((top != "") && (top != null))
		{
			if ((fix_to_item != "") && (fix_to_item != null))
			{
				document.getElementById("vcg_calendar_div_" + id).style.top = parseInt(VCGCalendarGetOffsetTop(fix_to_item)) + parseInt(top);
			}
			else
			{
				document.getElementById("vcg_calendar_div_" + id).style.top = top;
			}
		}
		else
		{
			document.getElementById("vcg_calendar_div_" + id).style.top = VCGCalendarGetOffsetTop("btnVCGCalendarShow_" + id);
		}
			
		if ((left != "") && (left != null))
		{
			if ((fix_to_item != "") && (fix_to_item != null))
			{
				document.getElementById("vcg_calendar_div_" + id).style.left = parseInt(VCGCalendarGetOffsetLeft(fix_to_item)) + parseInt(left);
			}
			else
			{
				document.getElementById("vcg_calendar_div_" + id).style.left = left;
			}
		}
		else
		{
			document.getElementById("vcg_calendar_div_" + id).style.left = VCGCalendarGetOffsetLeft("btnVCGCalendarShow_" + id);
		}

		if (isNaN(offset_top) || (offset_top == "") || (offset_top == null))
			offset_top = 0;
		else
			offset_top = parseInt(offset_top);

		if (isNaN(offset_left) || (offset_left == "") || (offset_left == null))
			offset_left = 0;
		else
			offset_left = parseInt(offset_left);

		document.getElementById("vcg_calendar_div_" + id).style.top = parseInt(document.getElementById("vcg_calendar_div_" + id).style.top) + parseInt(offset_top) + "px";
		document.getElementById("vcg_calendar_div_" + id).style.left = parseInt(document.getElementById("vcg_calendar_div_" + id).style.left) + parseInt(offset_left) + "px";

		document.getElementById("vcg_calendar_div_" + id).style.display = "";

	/*
		if (selected_day != "")
			cal_day = selected_day;

		if (selected_month != "")
			cal_month = selected_month;

		if (selected_year != "")
			cal_year = selected_year;
	*/		
		if (parseInt(cal_day).toString() == "NaN")
			cal_day = "";

		if (parseInt(cal_month).toString() == "NaN")
			cal_month = "";

		if (parseInt(cal_year).toString() == "NaN")
			cal_year = "";

		VCGOutputCalendar(id, cal_day, cal_month, cal_year, split_date, is_label, years_from, years_to, bgcolor, calendar_bgcolor, nav_color, nav_bgcolor, nav_font_size, nav_font_weight, header_color, header_bgcolor, header_font_size, header_font_weight, selected_color, selected_bgcolor, selected_font_size, selected_font_weight, notselected_color, notselected_bgcolor, notselected_font_size, notselected_font_weight);
	}
	catch (err)
	{
		alert("Error : vcgcalendar.js - VCGShowCalendar() - " + err.description);
	}
}

function VCGOutputCalendar(id, selected_day, selected_month, selected_year, split_date, is_label, years_from, years_to, bgcolor, calendar_bgcolor, nav_color, nav_bgcolor, nav_font_size, nav_font_weight, header_color, header_bgcolor, header_font_size, header_font_weight, selected_color, selected_bgcolor, selected_font_size, selected_font_weight, notselected_color, notselected_bgcolor, notselected_font_size, notselected_font_weight)
{
	try
	{
		var debug_log = "";
		var body_html;
		var currentTime = new Date();

		var current_month = currentTime.getMonth() + 1;
		var current_day = currentTime.getDate();
		var current_year = currentTime.getFullYear();

		var vcg_selected_month = current_month;
		var vcg_selected_year = current_year;
		var vcg_selected_day;

		var first_of_the_month;

		var vcg_current_day;
		var vcg_current_month;
		var vcg_current_year;

		var vcg_calendar_row;
		var vcg_calendar_col;

		var vcg_calendar_start_col;

		if (selected_month != "")
			vcg_selected_month = selected_month;

		if (selected_year != "")
			vcg_selected_year = selected_year;

		if ((vcg_selected_month == current_month) && (vcg_selected_year == current_year))
			vcg_selected_day = current_day;

		if (selected_day != "")
			vcg_selected_day = selected_day;

		first_of_the_month = new Date(VCGCalendar_GetMonthName(vcg_selected_month) + " 1, " + vcg_selected_year + " 00:00:00");

		body_html = "<form method=\"post\" name=\"VCGCalendarForm_" + id + "\" id=\"VCGCalendarForm_" + id + "\" target=\"vcg_calendar_form_" + id + "\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_selected_day\" id=\"vcg_calendar_selected_day_" + id + "\" value=\"" + vcg_selected_day + "\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_selected_month\" id=\"vcg_calendar_selected_month_" + id + "\" value=\"" + vcg_selected_month + "\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_selected_year\" id=\"vcg_calendar_selected_year_" + id + "\" value=\"" + vcg_selected_year +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_split_date\" id=\"vcg_calendar_split_date_" + id + "\" value=\"" + split_date +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_is_label\" id=\"vcg_calendar_is_label_" + id + "\" value=\"" + is_label +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_years_from\" id=\"vcg_calendar_years_from_" + id + "\" value=\"" + years_from +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_years_to\" id=\"vcg_calendar_years_to_" + id + "\" value=\"" + years_to +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_bgcolor\" id=\"vcg_calendar_bgcolor_" + id + "\" value=\"" + bgcolor +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_calendar_bgcolor\" id=\"vcg_calendar_calendar_bgcolor_" + id + "\" value=\"" + calendar_bgcolor +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_nav_color\" id=\"vcg_calendar_nav_color_" + id + "\" value=\"" + nav_color +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_nav_bgcolor\" id=\"vcg_calendar_nav_bgcolor_" + id + "\" value=\"" + nav_bgcolor +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_nav_font_size\" id=\"vcg_calendar_nav_font_size_" + id + "\" value=\"" + nav_font_size +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_nav_font_weight\" id=\"vcg_calendar_nav_font_weight_" + id + "\" value=\"" + nav_font_weight +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_header_color\" id=\"vcg_calendar_header_color_" + id + "\" value=\"" + header_color +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_header_bgcolor\" id=\"vcg_calendar_header_bgcolor_" + id + "\" value=\"" + header_bgcolor +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_header_font_size\" id=\"vcg_calendar_header_font_size_" + id + "\" value=\"" + header_font_size +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_header_font_weight\" id=\"vcg_calendar_header_font_weight_" + id + "\" value=\"" + header_font_weight +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_selected_color\" id=\"vcg_calendar_selected_color_" + id + "\" value=\"" + selected_color +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_selected_bgcolor\" id=\"vcg_calendar_selected_bgcolor_" + id + "\" value=\"" + selected_bgcolor +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_selected_font_size\" id=\"vcg_calendar_selected_font_size_" + id + "\" value=\"" + selected_font_size +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_selected_font_weight\" id=\"vcg_calendar_selected_font_weight_" + id + "\" value=\"" + selected_font_weight +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_notselected_color\" id=\"vcg_calendar_notselected_color_" + id + "\" value=\"" + notselected_color +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_notselected_bgcolor\" id=\"vcg_calendar_notselected_bgcolor_" + id + "\" value=\"" + notselected_bgcolor +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_notselected_font_size\" id=\"vcg_calendar_notselected_font_size_" + id + "\" value=\"" + notselected_font_size +"\">";
		body_html = body_html + "<input type=\"hidden\" name=\"vcg_calendar_notselected_font_weight\" id=\"vcg_calendar_notselected_font_weight_" + id + "\" value=\"" + notselected_font_weight +"\">";
		body_html = body_html + "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
		body_html = body_html + "<tr><td id=\"vcg_calendar_navigation_" + id + "\">";
		body_html = body_html + "<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" width=\"100%\">";
		body_html = body_html + "<tr>";
		body_html = body_html + "<td bgcolor=\"" + nav_bgcolor + "\" valign=\"middle\" width=\"10%\">";

		if ((vcg_selected_month == current_month) && (vcg_selected_year == parseInt(current_year) - parseInt(years_from)))
		{
			body_html = body_html + "&#160;"
		}
		else
		{
			body_html = body_html + "<span onclick=\"VCGCalendarNavigateMonth('" + id + "','prev')\" style=\"cursor: pointer; color: " + nav_color + ";font-weight:" + nav_font_weight + "; font-size:" + nav_font_size + ";\">&lt;</span>";
		}

		body_html = body_html + "</td><td bgcolor=\"" + nav_bgcolor + "\" valign=\"middle\" align=\"center\">";
		body_html = body_html + "<select name=\"vcg_calendar_month_select\" id=\"vcg_calendar_month_select_" + id + "\" onchange=\"VCGCalendarSelectMonth('" + id + "')\" style=\"color: " + nav_color + "; font-size: " + nav_font_size + "; font-weight: " + nav_font_weight + ";\">";
		
		for (vcg_current_year = parseInt(current_year) - parseInt(years_from); vcg_current_year <= parseInt(current_year) + parseInt(years_to); vcg_current_year++)
		{
			if (vcg_current_year == parseInt(current_year) - parseInt(years_from))
			{
				for (vcg_current_month = current_month; vcg_current_month <= 12; vcg_current_month++)
				{
					body_html = body_html + "<option value=\"" + vcg_current_year + "_" + vcg_current_month + "\"";

					if ((vcg_current_month == vcg_selected_month) && (vcg_current_year == vcg_selected_year))
						body_html = body_html + " selected=\"selected\"";

					body_html = body_html + ">" + VCGCalendar_GetMonthName(vcg_current_month) + " " + vcg_current_year + "</option>";
				}
			}
			else
			{

				for (vcg_current_month = 1; vcg_current_month <= 12; vcg_current_month++)
				{
					if ((vcg_current_month <= current_month) || (vcg_current_year < parseInt(current_year) + parseInt(years_to)))
					{
						body_html = body_html + "<option value=\"" + vcg_current_year + "_" + vcg_current_month + "\"";

						if ((vcg_current_month == vcg_selected_month) && (vcg_current_year == vcg_selected_year))
							body_html = body_html + " selected=\"selected\"";

						body_html = body_html + ">" + VCGCalendar_GetMonthName(vcg_current_month) + " " + vcg_current_year + "</option>";
					}
				}
																			
			}
		}
		
		body_html = body_html + "</select>";
		body_html = body_html + "</td>";
		body_html = body_html + "<td bgcolor=\"" + nav_bgcolor + "\" valign=\"middle\" width=\"10%\" align=\"right\">";
		
		if ((vcg_selected_month == current_month) && (vcg_selected_year == parseInt(current_year) + parseInt(years_to)))
			body_html = body_html + "&#160;";
		else
			body_html = body_html + "<span onclick=\"VCGCalendarNavigateMonth('" + id + "','next')\" style=\"cursor: pointer; color: " + nav_color + ";font-weight:" + nav_font_weight + "; font-size:" + nav_font_size + ";\">&gt;</span>";
			
		body_html = body_html + "</td>";
		body_html = body_html + "</tr>";
		body_html = body_html + "</table>";
		body_html = body_html + "</td></tr>";
		body_html = body_html + "<tr>";
		body_html = body_html + "<td bgcolor=\"" + calendar_bgcolor + "\" id=\"vcg_calendar_display" + id + "\">";
		body_html = body_html + "<table bgcolor=\"" + calendar_bgcolor + "\" border=\"0\" cellpadding=\"" + vcg_calendar_cellpadding + "\" cellspacing=\"" + vcg_calendar_cellspacing + "\" width=\"100%\" style=\"" + vcg_calendar_table_styles + "\">";
		body_html = body_html + "<tr>";
		
		body_html = body_html + "<td width=\"17%\" valign=\"middle\" align=\"center\" style=\"color: " + header_color + "; background-color: " + header_bgcolor + "; font-size: " + header_font_size + "; font-weight: " + header_font_weight + "; border-bottom: solid 1px " + bgcolor + "; border-right: solid 1px " + bgcolor + ";\">Sun</td>";
		body_html = body_html + "<td width=\"18%\" valign=\"middle\" align=\"center\" style=\"color: " + header_color + "; background-color: " + header_bgcolor + "; font-size: " + header_font_size + "; font-weight: " + header_font_weight + "; border-bottom: solid 1px " + bgcolor + "; border-right: solid 1px " + bgcolor + ";\">Mon</td>";
		body_html = body_html + "<td width=\"17%\" valign=\"middle\" align=\"center\" style=\"color: " + header_color + "; background-color: " + header_bgcolor + "; font-size: " + header_font_size + "; font-weight: " + header_font_weight + "; border-bottom: solid 1px " + bgcolor + "; border-right: solid 1px " + bgcolor + ";\">Tue</td>";
		body_html = body_html + "<td width=\"16%\" valign=\"middle\" align=\"center\" style=\"color: " + header_color + "; background-color: " + header_bgcolor + "; font-size: " + header_font_size + "; font-weight: " + header_font_weight + "; border-bottom: solid 1px " + bgcolor + "; border-right: solid 1px " + bgcolor + ";\">Wed</td>";
		body_html = body_html + "<td width=\"16%\" valign=\"middle\" align=\"center\" style=\"color: " + header_color + "; background-color: " + header_bgcolor + "; font-size: " + header_font_size + "; font-weight: " + header_font_weight + "; border-bottom: solid 1px " + bgcolor + "; border-right: solid 1px " + bgcolor + ";\">Thu</td>";
		body_html = body_html + "<td width=\"16%\" valign=\"middle\" align=\"center\" style=\"color: " + header_color + "; background-color: " + header_bgcolor + "; font-size: " + header_font_size + "; font-weight: " + header_font_weight + "; border-bottom: solid 1px " + bgcolor + "; border-right: solid 1px " + bgcolor + ";\">Fri</td>";
		body_html = body_html + "<td valign=\"middle\" align=\"center\" style=\"background-color: " + header_bgcolor + "; font-size: " + header_font_size + "; color: " + header_color + "; font-weight: " + header_font_weight + "; border-bottom: solid 1px " + bgcolor + ";\">Sat</td>";

		body_html = body_html + "</tr>";

	/**	Output Calendar ****************************************/

		vcg_current_day = 0;
		vcg_calendar_start_col = first_of_the_month.getDay() + 1;

		// Loop through the rows
		for (vcg_calendar_row = 1; vcg_calendar_row <= 6; vcg_calendar_row++)
		{
			body_html = body_html + "<tr>";

			// Loop through the columns
			for (vcg_calendar_col = 1; vcg_calendar_col <= 7; vcg_calendar_col++)
			{
				// Get the starting cell
				if ((vcg_calendar_row == 1) && (vcg_current_day == 0) && (vcg_calendar_start_col == vcg_calendar_col))
					vcg_current_day = 1;

				body_html = body_html + "<td";

				if ((vcg_calendar_col == 1) || (vcg_calendar_col == 7))
					body_html = body_html + " width=\"15%\"";
				else
					body_html = body_html + " width=\"14%\"";

				body_html = body_html + " style=\"";

				if (vcg_calendar_col == 7)
				{
					if (vcg_calendar_row < 6)
					{																	
						if ((vcg_selected_day == vcg_current_day) && (VCGCalendarIsValidDate(vcg_selected_month + "/" + vcg_selected_day + "/" + vcg_selected_year)))
						{
							//body_html = body_html + "VCGCalendarCellRightSelected";
							body_html = body_html + "background-color: " + selected_bgcolor + "; vertical-align: top; border-bottom: solid 1px " + bgcolor + ";";
						}
						else
						{
							//body_html = body_html + "VCGCalendarCellRight";
							body_html = body_html + "background-color: " + notselected_bgcolor + "; vertical-align: top; border-bottom: solid 1px " + bgcolor + ";";
						}
					}																	
					else
					{
						if ((vcg_selected_day == vcg_current_day) && (VCGCalendarIsValidDate(vcg_selected_month + "/" + vcg_selected_day + "/" + vcg_selected_year)))
						{
							//body_html = body_html + "VCGCalendarCellSelected";
							body_html = body_html + "background-color: " + selected_bgcolor + "; vertical-align: top; border-bottom: solid 1px " + bgcolor + "; border-right: solid 1px " + bgcolor + ";";
						}
						else
						{
							body_html = body_html + "background-color: " + notselected_bgcolor + ";";
						}
					}
				}
				else
				{
					if (vcg_calendar_row < 6)
					{
						if ((vcg_selected_day == vcg_current_day) && (VCGCalendarIsValidDate(vcg_selected_month + "/" + vcg_selected_day + "/" + vcg_selected_year)))
						{
							//body_html = body_html + "VCGCalendarCellSelected";
							body_html = body_html + "background-color: " + selected_bgcolor + "; vertical-align: top; border-bottom: solid 1px " + bgcolor + "; border-right: solid 1px " + bgcolor + ";";
						}
						else
						{
							//body_html = body_html + "VCGCalendarCell";
							body_html = body_html + "background-color: " + notselected_bgcolor + "; vertical-align: top; border-bottom: solid 1px " + bgcolor + "; border-right: solid 1px " + bgcolor + ";";
						}
					}
					else
					{
						if ((vcg_selected_day == vcg_current_day) && (VCGCalendarIsValidDate(vcg_selected_month + "/" + vcg_selected_day + "/" + vcg_selected_year)))
						{
							//body_html = body_html + "VCGCalendarCellBottomSelected";
							body_html = body_html + "background-color: " + selected_bgcolor + "; vertical-align: top; border-right: solid 1px " + bgcolor + ";";
						}
						else
						{
							//body_html = body_html + "VCGCalendarCellBottom";
							body_html = body_html + "background-color: " + notselected_bgcolor + "; vertical-align: top; border-right: solid 1px " + bgcolor + ";";
						}
					}
				}
				
				body_html = body_html + "\">";
				body_html = body_html + "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
				body_html = body_html + "<td style=\"";

				if ((vcg_selected_day == vcg_current_day) && (VCGCalendarIsValidDate(vcg_selected_month + "/" + vcg_selected_day + "/" + vcg_selected_year)))
				{
					//body_html = body_html + "VCGCalendarDayCellSelected";
					body_html = body_html + "color: " + selected_color + "; font-size: " + selected_font_size + "; font-weight: " + selected_font_weight + ";";
				}
				else
				{
					//body_html = body_html + "VCGCalendarDayCell";
					body_html = body_html + "background-color: " + notselected_bgcolor + "; font-size: " + notselected_font_size + "; font-weight: " + notselected_font_weight + ";";
				}

				body_html = body_html + "\" valign=\"middle\" align=\"center\">";
				
				// Check if we have started outputing the days
				if ((vcg_current_day > 0) && (vcg_current_day < 32))
				{
					if (VCGCalendarIsValidDate(vcg_selected_month + "/" + vcg_current_day + "/" + vcg_selected_year))
					{

						// Output the day
						body_html = body_html + "<span style=\""

						if (vcg_selected_day == vcg_current_day)
						{
							//body_html = body_html + "VCGCalendarDaySelectedLink";
							body_html = body_html + "color: " + selected_color + "; cursor: pointer; font-weight: " + selected_font_weight + "; font-size: " + selected_font_size + ";";
						}
						else
						{
							//body_html = body_html + "VCGCalendarDayLink";
							body_html = body_html + "color: " + notselected_color + "; cursor: pointer; font-weight: " + notselected_font_weight + "; font-size: " + notselected_font_size + ";";
						}

						body_html = body_html + "\" onclick=\"VCGCalendarSelectDay('" + id + "','" +  vcg_current_day + "', " + split_date + ", " + is_label + ")\" style=\"cursor: pointer\">" + vcg_current_day + "</span>";

						vcg_current_day = vcg_current_day + 1;
					}
					else
						body_html = body_html + "&#160;";
				}
				else
					body_html = body_html + "&#160;";

				body_html = body_html + "</td>";
				body_html = body_html + "</table>";
				body_html = body_html + "</td>";

			}	// Loop through the columns - End

			body_html = body_html + "</tr>";

		}	// Loop through the rows - End

		body_html = body_html + "</table>";
		body_html = body_html + "</td>";
		body_html = body_html + "</tr>";
		body_html = body_html + "</table>";
		body_html = body_html + "</form>";

		//document.getElementById("vcg_calendar_div_" + id).innerHTML = body_html;
		
		var new_div = document.createElement("div");
		new_div.innerHTML = body_html;
		
		var div_children = document.getElementById("vcg_calendar_div_" + id).children;
		
		if (div_children.length > 0)
			document.getElementById("vcg_calendar_div_" + id).removeChild(document.getElementById("vcg_calendar_div_" + id).lastChild);

		document.getElementById("vcg_calendar_div_" + id).appendChild(new_div);
	}
	catch (err)
	{
		alert("Error : vcgcalendar.js - VCGOutputCalendar() - " + err.description);
	}
}

function VCGCalendarNavigateMonth(id, option)
{
	try
	{
		var cur_month = parseInt(document.getElementById("vcg_calendar_selected_month_" + id).value);
		var cur_year = parseInt(document.getElementById("vcg_calendar_selected_year_" + id).value);

		if ((cur_month != NaN) && (cur_year != NaN))
		{
			if (option == "prev")
			{
				if (cur_month == 1)
				{
					cur_month = 12;
					cur_year = cur_year - 1;
				}
				else
				{
					cur_month = cur_month - 1;
				}
			}
			else
			{
				if (cur_month == 12)
				{
					cur_month = 1;
					cur_year = cur_year + 1;
				}
				else
				{
					cur_month = cur_month + 1;
				}
			}

			document.getElementById("vcg_calendar_selected_month_" + id).value = cur_month;
			document.getElementById("vcg_calendar_selected_year_" + id).value = cur_year;

			VCGOutputCalendar(id, document.getElementById("vcg_calendar_selected_day_" + id).value, document.getElementById("vcg_calendar_selected_month_" + id).value, document.getElementById("vcg_calendar_selected_year_" + id).value, document.getElementById("vcg_calendar_split_date_" + id).value, document.getElementById("vcg_calendar_is_label_" + id).value, document.getElementById("vcg_calendar_years_from_" + id).value, document.getElementById("vcg_calendar_years_to_" + id).value, document.getElementById("vcg_calendar_bgcolor_" + id).value, document.getElementById("vcg_calendar_calendar_bgcolor_" + id).value, document.getElementById("vcg_calendar_nav_color_" + id).value, document.getElementById("vcg_calendar_nav_bgcolor_" + id).value, document.getElementById("vcg_calendar_nav_font_size_" + id).value, document.getElementById("vcg_calendar_nav_font_weight_" + id).value, document.getElementById("vcg_calendar_header_color_" + id).value, document.getElementById("vcg_calendar_header_bgcolor_" + id).value, document.getElementById("vcg_calendar_header_font_size_" + id).value, document.getElementById("vcg_calendar_header_font_weight_" + id).value, document.getElementById("vcg_calendar_selected_color_" + id).value, document.getElementById("vcg_calendar_selected_bgcolor_" + id).value, document.getElementById("vcg_calendar_selected_font_size_" + id).value, document.getElementById("vcg_calendar_selected_font_weight_" + id).value, document.getElementById("vcg_calendar_notselected_color_" + id).value, document.getElementById("vcg_calendar_notselected_bgcolor_" + id).value, document.getElementById("vcg_calendar_notselected_font_size_" + id).value, document.getElementById("vcg_calendar_notselected_font_weight_" + id).value);
		}
	}
	catch (err)
	{
		alert("Error : vcgcalendar.js - VCGCalendarNavigateMonth() - " + err.description);
	}
}

function VCGCalendarSelectMonth(id)
{
	try
	{
		if (document.getElementById("vcg_calendar_month_select_" + id).value != "")
		{
			var date_array = document.getElementById("vcg_calendar_month_select_" + id).value.split("_");

			if (date_array.length == 2)
			{
				var cur_year = parseInt(date_array[0]);
				var cur_month = parseInt(date_array[1]);

				if ((cur_month != NaN) && (cur_year != NaN))
				{
					document.getElementById("vcg_calendar_selected_day_" + id).value = "";
					document.getElementById("vcg_calendar_selected_month_" + id).value = cur_month;
					document.getElementById("vcg_calendar_selected_year_" + id).value = cur_year;

					VCGOutputCalendar(id, document.getElementById("vcg_calendar_selected_day_" + id).value, document.getElementById("vcg_calendar_selected_month_" + id).value, document.getElementById("vcg_calendar_selected_year_" + id).value, document.getElementById("vcg_calendar_split_date_" + id).value, document.getElementById("vcg_calendar_is_label_" + id).value, document.getElementById("vcg_calendar_years_from_" + id).value, document.getElementById("vcg_calendar_years_to_" + id).value, document.getElementById("vcg_calendar_bgcolor_" + id).value, document.getElementById("vcg_calendar_calendar_bgcolor_" + id).value, document.getElementById("vcg_calendar_nav_color_" + id).value, document.getElementById("vcg_calendar_nav_bgcolor_" + id).value, document.getElementById("vcg_calendar_nav_font_size_" + id).value, document.getElementById("vcg_calendar_nav_font_weight_" + id).value, document.getElementById("vcg_calendar_header_color_" + id).value, document.getElementById("vcg_calendar_header_bgcolor_" + id).value, document.getElementById("vcg_calendar_header_font_size_" + id).value, document.getElementById("vcg_calendar_header_font_weight_" + id).value, document.getElementById("vcg_calendar_selected_color_" + id).value, document.getElementById("vcg_calendar_selected_bgcolor_" + id).value, document.getElementById("vcg_calendar_selected_font_size_" + id).value, document.getElementById("vcg_calendar_selected_font_weight_" + id).value, document.getElementById("vcg_calendar_notselected_color_" + id).value, document.getElementById("vcg_calendar_notselected_bgcolor_" + id).value, document.getElementById("vcg_calendar_notselected_font_size_" + id).value, document.getElementById("vcg_calendar_notselected_font_weight_" + id).value);
				}
			}
		}
	}
	catch (err)
	{
		alert("Error : vcgcalendar.js - VCGCalendarSelectMonth() - " + err.description);
	}
}

function VCGCalendarSelectDay(id, value, split_date, is_label)
{
	try
	{
		document.getElementById("vcg_calendar_selected_day_" + id).value = value;

		if (is_label)
		{
			if (VCGCalendarIsValidDate(document.getElementById("vcg_calendar_selected_month_" + id).value + "/" + document.getElementById("vcg_calendar_selected_day_" + id).value + "/" + document.getElementById("vcg_calendar_selected_year_" + id).value))
				document.getElementById("VCGCalendarLabel_" + id).innerHTML = document.getElementById("vcg_calendar_selected_day_" + id).value + " " + VCGCalendar_GetMonthName(document.getElementById("vcg_calendar_selected_month_" + id).value) + " " + document.getElementById("vcg_calendar_selected_year_" + id).value
		}
		else
		{
			if (split_date)
			{
				document.getElementById(id + "_day").value = document.getElementById("vcg_calendar_selected_day_" + id).value;
				document.getElementById(id + "_month").value = document.getElementById("vcg_calendar_selected_month_" + id).value;
				document.getElementById(id + "_year").value = document.getElementById("vcg_calendar_selected_year_" + id).value;

				// Get the day input
				var vcg_cal_input = document.getElementById(id + "_day");

				// On IE
				if(vcg_cal_input.fireEvent)
				{
					vcg_cal_input.fireEvent("onchange");
				}

				// On Gecko based browsers
				if(document.createEvent)
				{
					var vcg_cal_event = document.createEvent("HTMLEvents");
					if(vcg_cal_event.initEvent)
					{
						vcg_cal_event.initEvent("change", true, true);
					}
					
					if(vcg_cal_input.dispatchEvent)
					{
						vcg_cal_input.dispatchEvent(vcg_cal_event);
					}
				}
				
				// Get the month input
				vcg_cal_input = document.getElementById(id + "_month");

				// On IE
				if(vcg_cal_input.fireEvent)
				{
					vcg_cal_input.fireEvent("onchange");
				}

				// On Gecko based browsers
				if(document.createEvent)
				{
					var vcg_cal_event = document.createEvent("HTMLEvents");
					if(vcg_cal_event.initEvent)
					{
						vcg_cal_event.initEvent("change", true, true);
					}
					
					if(vcg_cal_input.dispatchEvent)
					{
						vcg_cal_input.dispatchEvent(vcg_cal_event);
					}
				}
				
				// Get the year input
				vcg_cal_input = document.getElementById(id + "_year");

				// On IE
				if(vcg_cal_input.fireEvent)
				{
					vcg_cal_input.fireEvent("onchange");
				}

				// On Gecko based browsers
				if(document.createEvent)
				{
					var vcg_cal_event = document.createEvent("HTMLEvents");
					if(vcg_cal_event.initEvent)
					{
						vcg_cal_event.initEvent("change", true, true);
					}
					
					if(vcg_cal_input.dispatchEvent)
					{
						vcg_cal_input.dispatchEvent(vcg_cal_event);
					}
				}
			}
			else
			{
				document.getElementById(id).value = document.getElementById("vcg_calendar_selected_day_" + id).value + " " + VCGCalendar_GetMonthName(document.getElementById("vcg_calendar_selected_month_" + id).value) + " " + document.getElementById("vcg_calendar_selected_year_" + id).value;

				// Get the input
				var vcg_cal_input = document.getElementById(id);

				// On IE
				if(vcg_cal_input.fireEvent)
				{
					vcg_cal_input.fireEvent("onchange");
				}

				// On Gecko based browsers
				if(document.createEvent)
				{
					var vcg_cal_event = document.createEvent("HTMLEvents");
					if(vcg_cal_event.initEvent)
					{
						vcg_cal_event.initEvent("change", true, true);
					}
					
					if(vcg_cal_input.dispatchEvent)
					{
						vcg_cal_input.dispatchEvent(vcg_cal_event);
					}
				}
			}
		}

		VCGCloseCalendar(id);
	}
	catch (err)
	{
		alert("Error : vcgcalendar.js - VCGCalendarSelectDay() - " + err.description);
	}
}

function VCGCalendarGetOffsetTop(item)
{
	try
	{
		var ended = false;
		var offset_top = document.getElementById(item).offsetTop;
		var parentObj = null;
	
		// Loop until there are no more parent objects
		while (ended == false)
		{
			// Check if this is the first time through the loop
			if (parentObj == null)
				parentObj = document.getElementById(item).parentNode;
			else
				parentObj = parentObj.parentNode;

			// Add the top offset of this object
			if (parentObj.tagName != "TD")
				offset_top = offset_top + parentObj.offsetTop;

			// Check if this is the top parent
			if (parentObj.tagName == "HTML")
				ended = true;
		}

		return offset_top;
	}
	catch (err)
	{
		alert("Error : vcgcalendar.js - VCGCalendarGetOffsetTop() - " + err.description);
	}
}

function VCGCalendarGetOffsetLeft(item)
{
	try
	{
		var ended = false;
		var offset_left = document.getElementById(item).offsetLeft;
		var parentObj = null;
	
		// Loop until there are no more parent objects
		while (ended == false)
		{	
			// Check if this is the first time through the loop
			if (parentObj == null)
				parentObj = document.getElementById(item).parentNode;
			else
				parentObj = parentObj.parentNode;
			
			// Add the left offset of this object
			offset_left = offset_left + parentObj.offsetLeft;
			
			// Check if this is the top parent
			if (parentObj.tagName == "HTML")
				ended = true;
		}	
	
		return offset_left;
	}
	catch (err)
	{
		alert("Error : vcgcalendar.js - VCGCalendarGetOffsetLeft() - " + err.description);
	}
}

function VCGCalendarIsValidDate(dateStr)
{
	try
	{
		// Checks for the following valid date formats:
		// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY

		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

		var matchArray = dateStr.match(datePat); // is the format ok?
		if (matchArray == null) {
		//alert(dateStr + " Date is not in a valid format.")
		return false;
		}
		month = matchArray[1]; // parse date into variables
		day = matchArray[3];
		year = matchArray[4];
		if (month < 1 || month > 12) { // check month range
		//alert("Month must be between 1 and 12.");
		return false;
		}
		if (day < 1 || day > 31) {
		//alert("Day must be between 1 and 31.");
		return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		//alert("Month "+month+" doesn't have 31 days!")
		return false;
		}
		if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
		//alert("February " + year + " doesn't have " + day + " days!");
		return false;
		   }
		}
		return true;
	}
	catch (err)
	{
		alert("Error : vcgcalendar.js - VCGCalendarIsValidDate() - " + err.description);
	}
}

function VCGCalendar_GetMonthName(value)
{
	try
	{
		var retval = "";

		switch (parseInt(value))
		{
			case 1:
				retval = "January";
			break;

			case 2:
				retval = "February";
			break;

			case 3:
				retval = "March";
			break;

			case 4:
				retval = "April";
			break;

			case 5:
				retval = "May";
			break;

			case 6:
				retval = "June";
			break;

			case 7:
				retval = "July";
			break;

			case 8:
				retval = "August";
			break;

			case 9:
				retval = "September";
			break;

			case 10:
				retval = "October";
			break;

			case 11:
				retval = "November";
			break;

			case 12:
				retval = "December";
			break;

			default:
				retval = "Invalid Month";
			break;
		}

		return retval;
	}
	catch (err)
	{
		alert("Error : vcgcalendar.js - VCGCalendar_GetMonthName() - " + err.description);
	}
}
