/*
** Zur Einhaltung der Barrierefreiheit müssen Elemente, die ihren
** Inhalt per Javascript beziehen, einen Hinweis enthalten, dass
** Javascript aktiviert sein muss. Ist dies der Fall, sollen diese
** Hinweise entfernt werden.
**
** @param: Liste von Elementen, deren Javascript-Hinweis entfernt werden soll
*/
function checkScript()
{
	for(var i=0; i < checkScript.arguments.length; i++)
		document.getElementById(checkScript.arguments[i]).innerHTML = "";
}

meinBezirk.srcData = "_include/data_proxy.asp";

/*
** schreibt die aktuellsten Meldungen in die News-Übersicht
** am rechten Seitenrand
*/
function writeNewsBox()
{

	if(!meinBezirk.checkBrowser())
		return;

	var html = "";
	var newsBox;

	newsBox = new meinBezirk.getData;
	newsBox.records.group = [];

	//*** die nächsten 3 Veranstaltungen
	newsBox.records.group[0] = {};
	newsBox.records.group[0].title = "<a href='default.asp?kat=1246&mkat=1246&op=1208' title='alle Veranstaltungen anzeigen ....'>Veranstaltungen</a>";
	newsBox.records.group[0].recTypes = [4];
	newsBox.records.group[0].href = "default.asp?kat=1246&mkat=1246&op=1208" + "&" + newsBox.query.page.varName + "=0-";
	newsBox.records.group[0].limit = [0,3];
	newsBox.records.group[0].sort = ["till,asc", "from,asc"];

	//*** Meldungen der Wirtschaft
	newsBox.records.group[1] = {};
	newsBox.records.group[1].title = "<a href='default.asp?kat=1223&mkat=1223&op=1203' title='alle Meldungen der Wirtschaft anzeigen ....'>aus der Wirtschaft</a>";
	newsBox.records.group[1].recTypes = [1,2,3,4,9];
	newsBox.records.group[1].newsCat = {};
	newsBox.records.group[1].newsCat.news = [-17];
	newsBox.records.group[1].newsCat.events = [-17];
	newsBox.records.group[1].user = {};
	newsBox.records.group[1].user.userTypes = [1];
	newsBox.records.group[1].href = "default.asp?kat=1223&mkat=1223&op=1203" + "&" + newsBox.query.page.varName + "=0&" + newsBox.query.record.varName + "=";
	newsBox.records.group[1].limit = [0,5];

	//*** Essen + Trinken
	newsBox.records.group[2] = {};
	newsBox.records.group[2].title = "<a href='default.asp?kat=1228&mkat=1228&op=1204' title='alle Meldungen der Rubrik Essen+Trinken anzeigen ....'>Essen + Trinken</a>";
	newsBox.records.group[2].user = {};
	newsBox.records.group[2].user.userTypes = [1];
	newsBox.records.group[2].recTypes = [1,4];
	newsBox.records.group[2].newsCat = {};
	newsBox.records.group[2].newsCat.news = [17];
	newsBox.records.group[2].newsCat.events = [17];
	newsBox.records.group[2].href = "default.asp?kat=1228&mkat=1228&op=1204" + "&" + newsBox.query.page.varName + "=0&" + newsBox.query.record.varName + "=";
	newsBox.records.group[2].limit = [0,3];

	//*** die letzten 3 Fotoserien
	newsBox.records.group[3] = {};
	newsBox.records.group[3].title = "<a href='default.asp?kat=1231&mkat=1231&op=1204' title='alle Fotogalerien anzeigen ....'>neue Fotos</a>";
	newsBox.records.group[3].recTypes = [3];
	newsBox.records.group[3].newsCat = {};
	newsBox.records.group[3].newsCat.albums = [-18];
	newsBox.records.group[3].href = "default.asp?kat=1231&mkat=1231&op=1204" + "&" + newsBox.query.page.varName + "=0&" + newsBox.query.record.varName + "=";
	newsBox.records.group[3].limit = [0,3];


	newsBox.records.groupData = 1;
	var groupData = newsBox.getMessages();

	for(var i=0; i<groupData.recordset.length; i++)
	{

		if(!groupData.recordset[i].length)
			continue;

		html += "<div class='headline'>" + newsBox.records.group[i].title + "</div>";

		for(var j=0; j < groupData.recordset[i].length; j++)
		{

			var arrUser = newsBox.getArray("user", groupData.recordset[i][j]);
			var idUser = (arrUser.length > 0) ? arrUser[0]["id"] : 0;


			//*** Kalender: ermittle den Monat (für den richtigen Verweis)
			if(i==0 && groupData.recordset[i][j]["type"] == 4)
			{

				//*** Einzeltage
				if(groupData.recordset[i][j]["day"])
				{
					var arrDays = newsBox.getArray("day",groupData.recordset[i][j]);
					groupData.recordset[i][j]["from"] = arrDays[0]["date"];
				}

				var from = new Date(groupData.recordset[i][j]["from"]*1000);
				var fMonth = from.getMonth();

				html += "<div class='link'><a href='" + newsBox.records.group[i].href + fMonth + "&" + newsBox.query.record.varName + "=" + idUser + "-" + groupData.recordset[i][j]["type"] + "-" + groupData.recordset[i][j]["id"] + "'>" + newsBox.writeTeaser(groupData.recordset[i][j].title,20," / ", " ...") + "</a></div>";

			}
			else
				html += "<div class='link'><a href='" + newsBox.records.group[i].href + idUser + "-" + groupData.recordset[i][j]["type"] + "-" + groupData.recordset[i][j]["id"] + "'>" + newsBox.writeTeaser(groupData.recordset[i][j].title,20," / ", " ...") + "</a></div>";

		}

		html += "</div>";
		html += "<br>";

	}

	document.getElementById("newsListe").innerHTML = html;

}


meinBezirk.prototype.writePages = function()
{

	var html = '';
	html += '<div style="text-align:left; border-bottom:1px solid #DCDCDC">';

	for(i=0; i<this.pages.length; i++)
	{

		var strTarget = (this.pages[i].target) ? this.pages[i].target : "_self";
		var strHref = (this.pages[i].href) ? this.pages[i].href : this.href + i;

		html += (i == this.page.index) ? '<div class="reiter_akt">' : '<div class="reiter">';

		html += '<span class="nowrap">';
		html += '<a href="' + strHref + '" target="' + strTarget + '">&nbsp;' + this.pages[i].title + '&nbsp;</a>';
		html += '</span>';

		html += '</div>';

	}


	html += '<div style="clear:both"></div>';
	html += '</div>';
	html += '<br><br>';

	return html;
}


/*
** USER-LISTE
** @param "records": (optional) alternative Datensätze
** @return: HTML
*/
meinBezirk.user.prototype.writeList = function(records)
{

	if(!records)
		var records = this.records;

	var strCss = "odd";
	var html = "<div class='list'>";

	for(var i=0; i < records.length; i++)
	{

		var strUrl = this.href + this.query.page.value[0] + "&" + this.query.record.varName + "=" + records[i]["id"];

		html += "<div class='" + strCss + "' onClick='window.location.href=\"" + strUrl + "\"'>";

		html += "<div><a href='" + strUrl + "'><b>" + records[i]["name"] + "</b></a></div>";

		if(records[i]["text"] && records[i]["text"].length > 0)
			html += this.writeTeaser(records[i]["text"],200, " / ", " ...");

		if(records[i]["news"])
		{
			html += "<div class='news'>";
			var arrNews = this.getArray("news", records[i]);
			for(var j=0; j < arrNews.length; j++)
				html += "<a href='" + this.href + "0&" + this.query.record.varName + "=" + records[i]["id"] + "&" + this.query.recType.varName + "=" + arrNews[j] + "'><img src='" + this.icons.news[arrNews[j]] + "' border='0'></a>";

			html += "</div>";
		}

		html += "</div>";
		strCss = (strCss == "odd") ? "even" : "odd";
	}

	// Seitennavigation (blättern)
	html += this.writeSubPageNav(this.subPages, this.href + this.query.page.value.join("-"));

	html += "</div>";

	return html;

}



/*
** NEWS-LISTE
** @param "records": (optional) alternative Datensätze
** @return: HTML
*/
meinBezirk.news.prototype.writeList = function(records)
{

	if(!records)
		var records = this.records;

	var strCss = "odd";
	var html = "<div class='list'>";

	for(i=0; i < records.length; i++)
	{

		//*** ein Datensatz kann mehreren Usern zugeordnet sein!
		var arrUser = this.getArray("user", records[i]);
		var idUser = (arrUser.length > 0) ? arrUser[0]["id"] : 0;

		//*** Beilagen
		var strAttm = (records[i]["attm"]["size"] > 0) ? " <img src='" + this.icons.attm + "' border='0'>" : "";

		var strUrl = this.href + this.query.page.value[0] + "&" + this.query.record.varName + "=" + idUser + "-" + records[i]["type"] + "-" + records[i]["id"];

		html += "<div class='" + strCss + "' onClick='window.location.href=\"" + strUrl + "\"'>";
		html += "<div><a href='" + strUrl + "'><b>" + records[i]["title"] + "</b></a>" + strAttm + "</div>";

		if(records[i]["text"] && records[i]["text"].length > 0)
			html += this.writeTeaser(records[i]["text"],200, " / ", " ...");

		//*** User
		if(arrUser.length > 0)
			html += "<br><span class='userName'>[von: " + arrUser[0]["name"] + "]</span>";

		html += "</div>";

		strCss = (strCss == "even") ? "odd" : "even";

	}

	// Seitennavigation (blättern)
	if(this.subPages)
		html += this.writeSubPageNav(this.subPages, this.href + this.query.page.value.join("-"));

	html += "</div>";

	return html;

}

/*
** VERANSTALTUNGEN
** @return: HTML
*/
meinBezirk.calendar.prototype.writeList = function(records)
{

	if(!records)
		var records = this.records;

	var strCss = "odd";
	var html = "<div class='list'>";

	for(i=0; i < records.length; i++)
	{

		// ermittle die Veranstaltungsdauer ...
		if(records[i]["day"])
		{

			var strDate = "";

			for(var j=0; j < records[i]["day"].length; j++)
			{

				if(j == 3)
				{
					strDate += "<br>(" + (records[i]["day"].length - j) + " weitere Termine)";
					break;
				}

				var from = new Date(records[i]["day"][j]["date"]*1000);
				var fDay = from.getDay();
				var fDate = from.getDate();
				var fMonth = from.getMonth();
				var fYear = from.getFullYear();

				strDate += (j == 0) ? "" : ",<br>";
				strDate += this.weekdays.terms.shortName[fDay] + ", " + fDate + ". " + this.month.terms.shortName[fMonth] + " " + fYear;

			}

		}
		else
		{
			// Beginnzeit ermitteln
			var from = new Date(records[i]["from"]*1000);
			var fDay = from.getDay();
			var fDate = from.getDate();
			var fMonth = from.getMonth();
			var fYear = from.getFullYear();
			var fHours = from.getHours();
			var fMin = from.getMinutes();
			var strfHours = (fHours < 10) ? "0" + fHours : fHours;
			var strfMin = (fMin < 10) ? "0" + fMin : fMin;

			// Endezeit ermitteln
			var till = new Date(records[i]["till"]*1000);
			var tDay = till.getDay();
			var tDate = till.getDate();
			var tMonth = till.getMonth();
			var tYear = till.getFullYear();
			var tHours = till.getHours();
			var tMin = till.getMinutes();
			var strtHours = (tHours < 10) ? "0" + tHours : tHours;
			var strtMin = (tMin < 10) ? "0" + tMin : tMin;

			// Zeit ermitteln
			var strTime = "";
			var strTimeFrom = ((fHours != 0) || (fMin != 0)) ? strfHours + ":" + strfMin : ""
			var strTimeTill = ((tHours != 23) || (tMin != 59)) ? strtHours + ":" + strtMin : ""

			if(strTimeFrom.length > 0)
				strTime += "[" + strTimeFrom;

			if(strTimeTill.length > 0)
				strTime += (strTime.length > 0) ? " - " + strTimeTill + " Uhr]" : " [bis " + strTimeTill + " Uhr]";
			else if(strTimeFrom.length > 0)
				strTime = "[ab " + strTimeFrom + " Uhr]";


			// eintägige Veranstaltungen
			if((fDate == tDate) && (fMonth == tMonth) && (fYear == tYear))
			{
				var strDate = this.weekdays.terms.fullName[fDay] + ",<br>";
				strDate += fDate + ". " + this.month.terms.fullName[fMonth] + " " + fYear;
				strDate += (strTime.length > 0) ? "<br>" + strTime : "";
			}
			// mehrtägige Veranstaltungen
			else
			{
				var strDate = this.weekdays.terms.shortName[fDay] + ", " + fDate + ". " + this.month.terms.shortName[fMonth] + " " + fYear;
				strDate += "<br>bis<br>";
				strDate += this.weekdays.terms.shortName[tDay] + ", " + tDate + ". " + this.month.terms.shortName[tMonth] + " " + tYear;
				strDate += (strTime.length > 0) ? "<br>" + strTime : "";
			}
		}

		// ein Datensatz könnte mehrere Eigentümer haben
		var arrUser = this.getArray("user", records[i]);
		var idUser = (arrUser.length > 0) ? arrUser[0]["id"] : 0;

		// Beilagen-Symbol
		var strAttm = (records[i]["attm"]["size"] > 0) ? " <img src='" + this.icons.attm + "' border='0'>" : "";

		var strUrl = this.href + this.query.page.value[0] + "-" + this.query.page.value[1] + "&" + this.query.record.varName + "=" + idUser + "-" + records[i]["type"] + "-" + records[i]["id"];

		html += "<div class='" + strCss + "' onClick='window.location.href=\"" + strUrl + "\"'>";
		html += "<table cellpadding='0' cellspacing='0' border='0' width='100%'>";
		html += "<tr>";
		html += "<td valign='top'>";
		html += "<div><a href='" + strUrl + "'><b>" + records[i]["title"] + "</b></a>" + strAttm + "</div>";

		if(records[i]["text"] && records[i]["text"].length > 0)
			html += this.writeTeaser(records[i]["text"],150, " / ", " ...");

		//*** User
		if(arrUser.length > 0)
			html += "<br><span class='userName'>[von: " + arrUser[0]["name"] + "]</span>";

		html += "</td>";
		html += "<td valign='top' width='150' align='right'><div style='width:120px;height:70px;vertical-align:middle;padding:8px;font-size:10px;color:#FFFFFF;text-align:center;border:1px solid #000000;background-color:#8F271A;'>" + strDate + "</div></td>";
		html += "</tr>";
		html += "</table>";
		html += "</div>";

		strCss = (strCss == "odd") ? "even" : "odd";

	}

	// Seitennavigation (blättern)
	html += this.writeSubPageNav(this.subPages, this.href + this.query.page.value.join("-"));


	html += "</div>";

	return html;

}



/*
** FOTOGALERIE
** @return: HTML
*/
meinBezirk.album.prototype.writeList = function(records)
{

	if(!records)
		var records = this.records;

	var strCss = "odd";
	var html = "<div class='list'>";

	for(i=0; i < records.length; i++)
	{

		// ein Datensatz kann mehreren Usern zugeordnet sein!
		var arrUser = this.getArray("user", records[i]);
		var idUser = (arrUser.length > 0) ? arrUser[0]["id"] : 0;

		//*** Anzahl Fotos
		var intAttm = (records[i]["attm"]["size"] > 0) ? records[i]["attm"]["size"] : 0;

		// ermittle das Datum der Aufnahme ...
		var from = new Date(records[i]["date"]*1000);
		var fDay = from.getDate();
		var fMonth = from.getMonth();
		var fYear = from.getFullYear();
		var fHours = from.getHours();
		var fMin = from.getMinutes();

		var strDate = this.month.terms.shortName[fMonth] + " " + fYear;

		var strUrl = this.href + this.query.page.value[0] + "&" + this.query.record.varName + "=" + idUser + "-" + records[i]["type"] + "-" + records[i]["id"];

		html += "<div class='" + strCss + "' onClick='window.location.href=\"" + strUrl + "\"'>";
		html += "<table cellpadding='0' cellspacing='0' border='0' width='100%'>";
		html += "<tr>";
		html += "<td valign='top' align='right' style='padding-right:20px;'>";

		if(records[i]["thumb"]["url"])
			html += "<img src='" + records[i]["thumb"]["url"] + "' width='120' height='90' border='0'>";

		html += "</td>";
		html += "<td valign='top'>";
		html += "<div><a href='" + strUrl + "'><b>" + records[i]["title"] + "</b></a></div>";

		if(records[i]["text"] && records[i]["text"].length > 0)
			html += "(" + strDate + " - " + intAttm + " Fotos) " + this.writeTeaser(records[i]["text"],150, " / ", " ...");

		//*** User
		if(arrUser.length > 0)
			html += "<br><span class='userName'>[von: " + arrUser[0]["name"] + "]</span>";

		html += "</td>";
		html += "</tr>";
		html += "</table>";
		html += "</div>";

		strCss = (strCss == "odd") ? "even" : "odd";

	}

	// Seitennavigation (blättern)
	html += this.writeSubPageNav(this.subPages, this.href + this.query.page.value.join("-"));

	html += "</div>";

	return html;

}


/*
** USER-BLATT: Datensatz-Listen
** @return: HTML
*/
meinBezirk.userpage.prototype.writeList = function(records)
{

	if(!records)
		var records = this.records;


	var strCss = "odd";
	var html = "<div class='list'>";

	for(var i=0; i < records.length; i++)
	{

		var strUrl = this.href + records[i]["type"] + "-" + records[i]["id"];

		html += "<div class='" + strCss + "' onClick='window.location.href=\"" + strUrl + "\"'>";

		var strAttm = (records[i]["attm"]["size"] > 0) ? " <img src='" + this.icons.attm + "' border='0'>" : "";

		html += "<div class='headline'><a href='" + strUrl + "'><b>" + records[i]["title"] + "</b></a>" + strAttm + "</div>";

		if(records[i]["type"] == this.recTypes.albums)
		{
			var intAttm = (records[i]["attm"]) ? records[i]["attm"].size : 0;

			if(intAttm == 1)
				html += "(" + intAttm + " Foto) ";
			else
				html += "(" + intAttm + " Fotos) ";
		}

		if(records[i]["text"] && records[i]["text"].length > 0)
			html += this.writeTeaser(records[i]["text"],150, " / ", " ...");

		html += "</div>";
		strCss = (strCss == "odd") ? "even" : "odd";
	}


	// Seitennavigation (blättern)
	html += this.writeSubPageNav(this.subPages, this.href + this.tab);


	html += "</div>";
	
	return html;

}

/*
** USER-STAMMDATEN
** @return: HTML
*/
meinBezirk.userpage.prototype.writeUserData = function()
{

	var html = "";

	var strUserName = (this.user.web.length > 0 && this.user.id != 1111) ? "<div><a href='" + this.user.web[0] + "' target='_blank' class='userName'>" + this.user.name + "</a></div>" : "<div class='userName'>" + this.user.name + "</div>"

	html += "<div class='userData'>";
	html += strUserName;
	html += "<span class='userAddress'>" + this.user.street + ", " +  this.user.city.zip + " " + this.user.city.name + "</span>";
	html += (this.user.tel) ? "<span class='userTel'>Tel: " + this.user.tel + "</span>" : "";
	html += (this.user.fax) ? "<span class='userFax'>Fax: " + this.user.fax + "</span>" : "";
	html += (this.user.email) ? "<a href='mailto:" + this.user.email + "' class='userMail'>" + this.user.email + "</a>" : "";
	html += "</div>";

	return html;

}

meinBezirk.userpage.prototype.getHomepageTab = function()
{

	if(this.user.web.length > 0 && this.user.id != 1111)
	{
		var arrHP = {};
		arrHP.title = "Homepage";
		arrHP.recTypes = [];
		arrHP.href = this.user.web[0];
		arrHP.target = "_blank";

		return arrHP;
	}

	return false;

}

/*
** Veranstaltung hinzufügen: Info-Text
*/
meinBezirk.calendar.addRecord.prototype.writeInfo = function()
{

	var html = "";

	html += "<b>Melden Sie uns Ihre fehlende Veranstaltung!</b><br><br>Sie helfen dabei mit, das reichhaltige Angebot an Veranstaltungen in der Marktgemeinde Loosdorf einer gro&szlig;en Zahl von Lesern bekannt zu machen und dabei den Aufwand gering zu halten.<br><br>";
	html += "Einzige Voraussetzung ist, dass die Veranstaltung innerhalb des Loosdorfer Gemeindegebietes stattfinden mu&szlig;. Bitte verwenden Sie eines der beiden folgende Formulare:<br>&nbsp;";
	html += "<ul>";
	html += "<li><a href='" + this.href + "1'><b>Formular 1</b>: Veranstaltung vorschlagen</a><br>&nbsp;</li>";
	html += "<li><a href='http://www.loosdorf.at/wartung' target='_blank'><b>Formular 2</b>: registrierte Mitglieder von &quot;www.loosdorf.at&quot; k&ouml;nnen in ihrem Wartungsbereich Veranstaltungen nachtr&auml;glich bearbeiten, Beilagen hinzuf&uuml;gen, Einzeltage erfassen, mehrere Kategorien ausw&auml;hlen, auf verschiedene Webseiten exportieren, ...</a></li>";
	html += "</ul><br>";
	html += "Hinweis: f&uuml;r gemeldete Veranstaltungen besteht kein Anspruch auf Ver&ouml;ffentlichung.";
	return html;

}

/*
** Fotoserien hinzufügen: Info-Text
*/
meinBezirk.album.prototype.addRecord = function()
{

	var html = "";

	html += "<b>Möchten Sie hier Ihre Fotos veröffentlichen?</b><br><br>";
	html += "Einzige Voraussetzung ist, dass Sie auf \"www.loosdorf.at\" registriert und dazu berechtigt sind.<br>&nbsp;";
	html += "<ul>";
	html += "<li><a href='http://www.loosdorf.at/wartung' target='_blank'><b>hier anmelden ...</b></a></li>";
	html += "</ul><br>";
	html += "Hinweis: f&uuml;r gemeldete Veranstaltungen besteht kein Anspruch auf Ver&ouml;ffentlichung.";
	return html;

}

/*
** User hinzufügen: Info-Text
*/
meinBezirk.user.addRecord.prototype.writeInfo = function()
{

	var html = "";

	html += "<b>Fehlt Ihr Eintrag?</b><br><br>Sie können sich in dieser Rubrik registrieren, sofern Sie einen festen Sitz in der Marktgemeinde Loosdorf angemeldet haben.<br><br>";

	html += "Bitte verwenden Sie dieses <a href='" + this.href + "1'><b>Anmelde-Formular</b></a>.";

	html += "<br><br>Hinweis: es besteht kein Anspruch auf Aufnahme.";
	return html;

}



