﻿


var Events = new Array();
Events.CurrentView = null;
Events.ActiveCollection = null;
Events.List = null;
Events.Calendar = null;
Events.Map = null;
Events.ShowHistory = false;
Events.Initialized = false;

Events.SwitchView = function (mode)
{
	Events.CurrentView = mode;
	switch (mode)
	{
		case ViewMode.List:
			var layers = Events.List.getElementsByTagName("div");
			var html = "";
			for (var i = 0; i < layers.length; i++)
				if (layers[i].className == "EventCollection")
					Events.ActiveCollection = layers[i];
			for (var i = 0; i < Events.length; i++)
				html += Events[i].Container.outerHTML;
			Events.ActiveCollection.innerHTML = html;
		default:
			break;
	}
}
//<p class="EventAvailability">
//	unavailable:y2010</p>
//<p class="EventId">
//400004</p>

Events.ShowHideHistory = function ()
{
	var checkBox = document.getElementById("700001");
	Events.ShowHistory = !Events.ShowHistory;
	checkBox.className = Events.ShowHistory ? "CheckedCheckBox" : "CheckBox";
	Events.Update();
}

Events.Update = function ()
{
	var html = "";

	if (!Events.Initialized)
	{
		Events.List.innerHTML = "<div class=\"EventsListContent\"><div class=\"EventCollection\"></div></div>";
		Events.Initialized = true;
	}

	if (Events.List != null)
	{
		var listCode = "";
		var listLayers = Events.List.getElementsByTagName("div");
		var layer = null;
		for (var i = 0; i < listLayers.length; i++)
			if (listLayers[i].className == "EventCollection")
				layer = listLayers[i];
		for (var i = 0; i < Events.length; i++)
		{
			if (Events.ShowHistory || !Event.IsHistoric(Events[i]))
			{
				if (Event.IsHistoric(Events[i]))
					html = "<div class=\"HistoricEvent\">";
				else
					html = "<div class=\"Event\">";

				html += "<table class=\"EventTable\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr style=\"display: none\"><td>" + Events[i].Id + "</td></tr><tr>";
				if (Event.IsHistoric(Events[i]))
					html += "<td class=\"HistoricEventHeader\" colspan=\"2\">";
				else
					html += "<td class=\"EventHeader\" colspan=\"2\">";
				html += Events[i].Header;
				html += "</td></tr>";
				for (var j = 0; j < Events[i].Occasions.length; j++)
				{
					if (EventOccasion.IsHistoric(Events[i].Occasions[j]))
						html += "<tr style=\"font-style: italic;\"><td class=\"EventOccasion\" style=\"width: 200px; text-decoration: line-through;\" >";
					else
						html += "<tr><td class=\"EventOccasion\" style=\"width: 200px;\" >";
					html += Events[i].Occasions[j].GetDatePeriod() != null ? Events[i].Occasions[j].GetDatePeriod() : "&#160";
					html += "</td><td class=\"EventOccasion\" style=\"width: 400px\" >";
					html += Events[i].Occasions[j].Location.ToString();
					html += "</td></tr>";
				}
				if (Events[i].SignUp != null)
				{
					html += "<tr><td class=\"EventSignUp\" colspan=\"2\" >";
					if (Events[i].Contact == Events[i].SignUp)
					{
						html += "Fr&#229;gor";
						if (Events[i].InfoLink == Events[i].SignUp)
							html += "/Info";
						html += "&#160;&&#160;Anm&#228;lan";
					}
					else if (Events[i].InfoLink == Events[i].SignUp)
						html += "Info&#160;&&#160;Anm&#228;lan";
					else
						html += "Anm&#228;lan";
					html += "&#58;&#160;";
					html += Events[i].SignUp.ToString();
					html += "</td></tr>";
				}
				if (Events[i].FutureSignUpContact != null && Events[i].FutureSignUpContact != Events[i].SignUp)
				{
					html += "<tr><td class=\"EventFutureSignUpContact\" colspan=\"2\" >";
					if (Events[i].Contact == Events[i].FutureSignUpContact)
					{
						html += "Fr&#229;gor";
						if (Events[i].InfoLink == Events[i].FutureSignUpContact)
							html += "/Info";
						html += "&#160;&&#160;Anm&#228;lan&#160;f&#246;r&#160;kommande&#160;kurser";
					}
					else
						html += "Anm&#228;lan&#160;f&#246;r&#160;kommande&#160;kurser";
					html += "&#58;&#160;";
					html += Events[i].FutureSignUpContact.ToString();
					html += "</td></tr>";
				}
				if (Events[i].Contact != null && Events[i].Contact != Events[i].SignUp && Events[i].Contact != Events[i].FutureSignUpContact)
				{
					html += "<tr><td class=\"EventContact\" colspan=\"2\" >Fr&#229;gor";
					if (Events[i].InfoLink == Events[i].Contact)
						html += "&#160;&&#160;Info";
					html += "&#58;&#160;";
					html += Events[i].Contact.ToString();
					html += "</td></tr>";
				}
				if (Events[i].InfoLink != null && Events[i].InfoLink != Events[i].Contact && Events[i].InfoLink != Events[i].SignUp && Events[i].InfoLink != Events[i].FutureSignUpContact)
				{
					html += "<tr><td class=\"EventInfoLink\" colspan=\"2\" >Mer&#160;Info&#58;&#160;";
					html += Events[i].InfoLink.ToString();
					html += "</td></tr>";
				}
				if (Events[i].Description != "" && Events[i].Description != null)
				{
					html += "<tr class=\"EventDescriptionButton\"><td colspan=\"2\" ><a href=\"javascript:Event.ViewDescription (" + Events[i].Id + ")\" >Beskrivning</a></td></tr>";
					html += "<tr class=\"EventDescription\" name=\"eventDescription" + Events[i].Id + "\" ><td colspan=\"2\" >";
					html += Events[i].Description;
					html += "</td></tr>";
				}

				html += "</table></div>";
				listCode += html;
			}
		}
		layer.innerHTML = listCode;
		html = "";
	}
}

Events.Add = function (event)
{
	Events.push(event);
}

Events.GetDescription = function (id)
{
	var layers = Events.List.getElementsByTagName("div");
	var events = null;
	for (var i = 0; i < layers.length; i++)
		if (layers[i].className == "Event" || layers[i].className == "HistoricEvent")
		{
			var rows = layers[i].getElementsByTagName("tr");
			if (parseInt(rows[0].getElementsByTagName("td")[0].innerHTML) == parseInt(id))
			{
				rows[rows.length - 1].Id = id;
				return rows[rows.length - 1];
			}
		}

}