// base.js
// *******

function showinner (pPage, pMenu)
// clears up the menu and 
// displays the html page pPage in the iframe with id=theContent
	{	// alert ("base.js: showInner (pPage='" + pPage + ", " + pMenu + "') called.");
		if (pMenu != null)
			{	menulowlight (pMenu);
				hidemenus (pMenu);
				}
		if (pPage == null) return;
		if (pPage == "") return;
		var myIFrame = parent.document.getElementById ('theContent');
		if (myIFrame == null)
			{	myIFrame = self.document.getElementById ('theContent');
				if (myIFrame == null)
					{	alert ("base.js: showInner (pPage='" + pPage + "') says iFrame with id=theContent not found");
						return;
						}
				}
		myIFrame.src = pPage;
		top.status = pPage;
		}


function showouter (pPage, pMenu)
// clears up the menu and 
// displays the html page pPage in a new browser window
	{	// alert ("base.js: showInner (pPage='" + pPage + ", " + pMenu + "') called.");
		if (pMenu != null)
			{	menulowlight (pMenu);
				hidemenus (pMenu);
				}
		if (pPage == null) return;
		if (pPage == "") return;
		window.open (pPage);
		}


function showpicture (pPicture)
// displays the picture pPicture in a new browser window
	{	// alert ("base.js: showpicture (pPicture='" + pPicture + "') called.");
		if (pPicture == null) return;
		if (pPicture == "") return;
		var jetzt = new Date();
 		myH = jetzt.getHours();
		myM = jetzt.getMinutes();
 		myS = jetzt.getSeconds();
 		myHS = Math.floor(jetzt.getMilliseconds() / 10);
		myTotal = myS * 100 + myM * 60 * 100 + myH * 60 * 60 * 100 + myHS;
 		myNewWindow = window.open (pPicture, "Picture" + myTotal, "innerWidth=1200px,height=924px,top=10px,left=10px,location=no,menubar=no,resizable=yes,status=no,toolbar=no,scrollbars=yes");
		myNewWindow.focus();
		}


function setChangingImage ()
	{	// alert ("setChangingImage");
		var tI = document.getElementById ('ChangingImage');
		var myImages = new Array ("Hund6c_250.jpg", "IMG_0940c_250.JPG", "Pferd7c_250.jpg", "Pferd4c_250.jpg", "Katze2c_250.jpg", "cow1.jpg");
		var myNumberOfImages = myImages.length;
		// alert(myNumberOfImages);
		var x = Math.min (myNumberOfImages-1, Math.round (Math.random () * myNumberOfImages - 0.3));
		// alert (x);
		tI.src = "../images/" + myImages[x];
		}

function showmenus (pMenuname, pIndex)
/*  show the menu named "pMenuname<pIndex>"
    if pIndex is 0 just the menu is displayed and pMenuname must include the index!!
	else the neighboring menus are lowlighted and hidden
		and the menu is highlighted
	*/
	{	// alert ("showmenus ('" + pMenuname + "', " + pIndex + ")");
		var menuFound = true;
		var i = 1;
		if (pIndex != 0)
			{	while (menuFound)
					{	if (i != pIndex)
							{	mySiblingMenu = document.getElementById (pMenuname + i);
								if (mySiblingMenu != null)
									{	menulowlight (mySiblingMenu.id);
										hidemenus (mySiblingMenu.id);
										}
								else
									menuFound = false;
								}
						i++;
						}
				pMenuname = pMenuname + pIndex;
				menuhighlight (pMenuname);
				}
		menuFound = true;
		i = 1;
		while (menuFound)
		 	{	myMenu = document.getElementById (pMenuname + i);
				if (myMenu == null)
					menuFound = false;
				else
					myMenu.style.visibility = 'visible';
				i++;
				}
		}

function hidemenus (pMenuname)
	{	// alert ("hidemenus (" + pMenuname);
		var menuFound = true;
		var i = 1;
		while (menuFound)
		 	{	var myMenu = top.document.getElementById (pMenuname + i);
				if (myMenu == null)
					menuFound = false;
				else
					myMenu.style.visibility = 'hidden';
				i++;
				}
		}

function togglemenus (pMenuname)
	{	// alert ("hello");
		var myMenu = top.document.getElementById (pMenuname + "1");
		if (myMenu == null) return;
		if (myMenu.style.visibility == 'hidden')
			showmenus (pMenuname, 0);
		else
			hidemenus (pMenuname);
		}

function menuhighlight (pId)
	{	// alert ("menuhighlight");
		var myself = top.document.getElementById (pId)
		myself.className="menuhighlight";
		myself.firstChild.className="menuhighlightCell";
		}

function menulowlight (pId)
	{	var myself = top.document.getElementById (pId)
		myself.className="menulowlight";
		myself.firstChild.className="menulowlightCell";
		}

function nomenus ()
	{	hidemenus ('menu1');
		hidemenus ('menu2');
		hidemenus ('menu3');
		hidemenus ('menu4');
		hidemenus ('menu5');
		menulowlight ('menu1');
		menulowlight ('menu2');
		menulowlight ('menu3');
		menulowlight ('menu4');
		menulowlight ('menu5');
		hidemenus ('mmenu1');
		hidemenus ('mmenu2');
		hidemenus ('mmenu3');
		hidemenus ('mmenu4');
		menulowlight ('mmenu1');
		menulowlight ('mmenu2');
		menulowlight ('mmenu3');
		menulowlight ('mmenu4');
		}

function showPasswordDialog ()
	{	var myDialog = document.getElementById ("passwordDialog");
		var myInputField = document.getElementById ("passwordField");
		if (myDialog != null)
			{	myDialog.style.visibility = 'visible';
				myInputField.focus ();
				}
		}
		
function hidePasswordDialog ()
	{	var myDialog = document.getElementById ("passwordDialog");
		if (myDialog != null)
		myDialog.style.visibility = 'hidden';
		}
				
function checkPassword ()
	{	var myInputField = document.getElementById ("passwordField");
		if (myInputField != null)
			{	if (myInputField.value == "stvah")
				{	showinner ("mitgliederbereich.html");
					}
				else
					alert ("Passwort falsch, mot de passe faux");
				}
		}

function setProtectedMenus ()
	{	parent.hidemenus ("menu");
		parent.showmenus ("mmenu", 0);
		parent.setChangingImage ();
		}

function hideOldEntries ()
	// this function hides table <tr>'s with names
	// that contain YYYYMMDD older than today
	{	var today = new Date ();
		var todayAsYYYYMMDD = today.getFullYear () + get2Digits (today.getMonth () + 1) + get2Digits (today.getDate ());
		var myTableRows = document.getElementsByTagName ("tr");
		i = 0;
		var myTable = myTableRows [0].parentNode;
		while (myTableRows [i] != null)
			{	if (myTableRows [i].name < todayAsYYYYMMDD)
					myTable.removeChild (myTableRows [i]);
				else
					i++;
				}
		}

var myString;
function get2Digits (pNumber)
	{	pNumber = pNumber + 100;
		myString = pNumber.toString ();
		return myString.substr (1, 2);
		}

function setRecipients (pEmailAddress)
	{	var myInputField = document.getElementById ("toAnchor");
		if (myInputField != null) myInputField = myInputField.nextSibling.nextSibling;
		else myInputField = (document.getElementsByName ("recipients"))[0];
		if (myInputField != null) myInputField.value = pEmailAddress;
		else alert ("Kein recipients-Feld");
		}

