//------------------------------------
// Main Menu functions
//------------------------------------

function findPosX(obj)
{
	var curleft = 0;

	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
	{
		curleft += obj.x;
	}
	
	return curleft;
}

var NaviHelperLeft = 0;
var PointerName = "hand";
var ActiveDropDown;

function MainMenuOver1(aobject, linkcolor, bgcolor, left, description)
{
	//
	// Set background, color & cursor
	//
	aobject.style.backgroundColor = bgcolor;
	aobject.style.color			  = linkcolor;
	
	if (document.all)
	{
		aobject.style.cursor = "hand";
	}
	else
	{
		aobject.style.cursor = "pointer";
	}
	
		ShowDropDownMenu (aobject.id + "Div", findPosX(aobject) - NaviHelperLeft - 1);
}

function MainMenuOut1 (aobject, linkcolor, bgcolor)
{
	aobject.style.backgroundColor = bgcolor;
	aobject.style.color			  = linkcolor;

	//
	// Hide navigation hint
	//
	//document.getElementById('NavigationHint').style.display = 'none';
}

function ShowDropDownMenu (LayerName, left)
{
	//nav = LayerName.substring (3, 4);

	//
	// Check weither we have an different element
	//
	if (ActiveDropDown)
	{
		ActiveDropDown.style.display = "none";

		//
		// Get id for the main navi item
		//
		id = ActiveDropDown.id.replace ("Div", "");

		//
		// Set background, color
		//
		if ((ActiveDropDown != document.getElementById(LayerName)) && (document.getElementById(id).style.fontWeight == "normal" || document.getElementById(id).style.fontWeight == ""))
		{
			document.getElementById(id).style.backgroundColor = "#7B7B7B";
			document.getElementById(id).style.color			  = "#CECECE";
		}
	}

	if (document.getElementById(LayerName))
	{
		document.getElementById(LayerName).style.display = "block";
		document.getElementById(LayerName).style.left = left + NaviHelperLeft;
		ActiveDropDown = document.getElementById(LayerName);	

		//
		// Hide form elements / flash
		//
		if (DropDownExceptions != null)
		{
			for (i = 0; i < DropDownExceptions.length; i++)
			{
				document.getElementById(DropDownExceptions[i]).style.visibility = "hidden";
			}
		}
	}
}

// ----------------------------------------------------------------
// leftpane functions
// ----------------------------------------------------------------
function ToggleSearch ()
{
	if (document.getElementById("LeftPaneSearchTable").style.display == 'none')
	{
		//
		// set an cookie for future visits, set lifetime to one year
		//
		//setCookie ("mymtwcommon", "1", 31104000);
	
		document.getElementById("LeftPaneSearchImg").src = "/images/symbols/collapse.gif";
		//document.getElementById('CommonImg').alt = "Hier klicken um die weiteren Informationen zu \"Allgemeines\" zuzuklappen";
	
		document.getElementById("LeftPaneSearchTable").style.display = "";
		document.getElementById("LeftPaneSearchTable1").style.borderBottom = "1px solid black";
	}
	else
	{
		//
		// set an cookie for future visits, set lifetime to one year
		//
		//setCookie ("mymtwcommon", "0", 31104000);
	
		document.getElementById("LeftPaneSearchImg").src = "/images/symbols/expand.gif";
		//document.getElementById('CommonImg').alt = "Hier klicken um die weiteren Informationen zu \"Allgemeines\" aufzuklappen";

		document.getElementById("LeftPaneSearchTable").style.display = "none";
		document.getElementById("LeftPaneSearchTable1").style.borderBottom = "0px";
	}
}

function ToggleLanguage ()
{
	if (document.getElementById("LeftPaneLanguageTable").style.display == 'none')
	{
		//
		// set an cookie for future visits, set lifetime to one year
		//
		//setCookie ("mymtwcommon", "1", 31104000);
	
		document.getElementById("LeftPaneLanguageImg").src = "/images/symbols/collapse.gif";
		//document.getElementById('CommonImg').alt = "Hier klicken um die weiteren Informationen zu \"Allgemeines\" zuzuklappen";
	
		document.getElementById("LeftPaneLanguageTable").style.display = "";
	}
	else
	{
		//
		// set an cookie for future visits, set lifetime to one year
		//
		//setCookie ("mymtwcommon", "0", 31104000);
	
		document.getElementById("LeftPaneLanguageImg").src = "/images/symbols/expand.gif";
		//document.getElementById('CommonImg').alt = "Hier klicken um die weiteren Informationen zu \"Allgemeines\" aufzuklappen";

		document.getElementById("LeftPaneLanguageTable").style.display = "none";
	}
}

// ----------------------------------------------------------------
// comment functions
// ----------------------------------------------------------------

function ToggleCommentEntry (id)
{
	if (document.getElementById("CommentDiv_" + id).style.display == 'none')
	{
		document.getElementById("CommentImg" + id).src = "/images/symbols/collapse.gif";
		document.getElementById("CommentDiv_" + id).style.display = "block";
		document.getElementById("CommentImg" + id).alt = "Hier klicken um diesen Beitrag anzuzeigen";
	}
	else
	{
		document.getElementById("CommentImg" + id).src = "/images/symbols/expand.gif";
		document.getElementById("CommentDiv_" + id).style.display = "none";
		document.getElementById("CommentImg" + id).alt = "Hier klicken um diesen Beitrag zu verstecken";
	}
}

function TogglePostingEntry (id)
{
	if (document.getElementById("PostingDiv_" + id).style.display == 'none')
	{
		document.getElementById("PostingImg_" + id).src = "/images/symbols/collapse.gif";
		document.getElementById("PostingDiv_" + id).style.display = "block";
		document.getElementById("PostingImg_" + id).alt = "Hier klicken um diesen Beitrag anzuzeigen";
	}
	else
	{
		document.getElementById("PostingImg_" + id).src = "/images/symbols/expand.gif";
		document.getElementById("PostingDiv_" + id).style.display = "none";
		document.getElementById("PostingImg_" + id).alt = "Hier klicken um diesen Beitrag zu verstecken";
	}
}

function ToggleFrontNews (id)
{
	if (document.getElementById("FrontNewsRow_" + id).style.display == 'none')
	{
		document.getElementById("FrontNewsImg_" + id).src = "/images/symbols/collapse.gif";
		document.getElementById("FrontNewsRow_" + id).style.display = "";
		document.getElementById("FrontNewsImg_" + id).alt = "Hier klicken um die weiteren Infos Beitrag anzuzeigen";
	}
	else
	{
		document.getElementById("FrontNewsImg_" + id).src = "/images/symbols/expand.gif";
		document.getElementById("FrontNewsRow_" + id).style.display = "none";
		document.getElementById("FrontNewsImg_" + id).alt = "Hier klicken um die weiteren Infos zu verstecken";
	}
}

function ToggleCompleteNews (id)
{
	if (document.getElementById("newsrow1_" + id).style.display == 'none')
	{
		document.getElementById("CompleteNewsImg_" + id).src = "/images/symbols/collapse.gif";
		document.getElementById("CompleteNewsImg_" + id).alt = "Hier klicken um die volle News anzuzeigen";	
	
		document.getElementById("newsrow1_" + id).style.display = "inline";
		document.getElementById("newsrow2_" + id).style.display = "inline";
		document.getElementById("newsrow3_" + id).style.display = "inline";

		if (document.getElementById("newsrow4_" + id) != null)
		{
			document.getElementById("newsrow4_" + id).style.display = "inline";
		}
		
		if (document.getElementById("newsrow5_" + id) != null)
		{
			document.getElementById("newsrow5_" + id).style.display = "inline";
			document.getElementById("newsrow6_" + id).style.display = "inline";
		}
	}
	else
	{
		document.getElementById("CompleteNewsImg_" + id).src = "/images/symbols/expand.gif";
		document.getElementById("CompleteNewsImg_" + id).alt = "Hier klicken um nur den Titel anzuzeigen";
		
		document.getElementById("newsrow1_" + id).style.display = "none";
		document.getElementById("newsrow2_" + id).style.display = "none";
		document.getElementById("newsrow3_" + id).style.display = "none";

		if (document.getElementById("newsrow4_" + id) != null)
		{
			document.getElementById("newsrow4_" + id).style.display = "none";
		}
		
		if (document.getElementById("newsrow5_" + id) != null)
		{
			document.getElementById("newsrow5_" + id).style.display = "none";
			document.getElementById("newsrow6_" + id).style.display = "none";
		}
	}
}

function TogglePostingPane (id)
{
	if (document.getElementById("PostingPaneTable_" + id).style.display == 'none')
	{
		document.getElementById("PostingPaneImg_" + id).src = "/images/symbols/collapse.gif";
		document.getElementById("PostingPaneTable_" + id).style.display = "inline";
		document.getElementById("PostingPaneImg_" + id).alt = "Hier klicken um die weiteren Infos ueber den Autor zu verstecken";
	}
	else
	{
		document.getElementById("PostingPaneImg_" + id).src = "/images/symbols/expand.gif";
		document.getElementById("PostingPaneTable_" + id).style.display = "none";
		document.getElementById("PostingPaneImg_" + id).alt = "Hier klicken um die weiteren Infos ueber den Autor anzuzeigen";
	}
}


function CommentPopup(url, height, comment_id, returnurl, type_id, type, comment_itemsperpage, comment_page)
{
	commentwindow = window.open('' + url + '?comment_id=' + comment_id + '&returnurl=' + returnurl + '&type_id=' + type_id + '&type=' + type + '&comment_itemsperpage=' + comment_itemsperpage + '&comment_page=' + comment_page +  '','commentwindow','toolbar=no, location=no, scrollbars=1, width=535, height=' + height + ', left=100, top=100, alwaysRaised=true');
	commentwindow.focus();
	
	if (commentwindow.opener == null)
	{
		commentwindow.opener = self;
	}
}

function boardjump()
{
	if (document.getElementById('board_id').options[document.getElementById('board_id').selectedIndex].value != -1) 
	{
		document.getElementById('jumpform').submit();
	}
}

function ClickSearchBox (aobject)
{
	aobject.value = "";
}

function LeaveSearchBox (aobject, Text)
{
	if (aobject.value == "")
	{
		aobject.value = Text;
	}
}

function ToggleSearchEntry (id)
{
	if (document.getElementById("SearchRow_" + id).style.display == 'none')
	{
		document.getElementById("SearchImg_" + id).src = "/images/symbols/collapse.gif";
		document.getElementById("SearchRow_" + id).style.display = "block";
		document.getElementById("SearchImg_" + id).alt = "Hier klicken um weitere Infos zu diesem Ergebnis anzuzeigen";
	}
	else
	{
		document.getElementById("SearchImg_" + id).src = "/images/symbols/expand.gif";
		document.getElementById("SearchRow_" + id).style.display = "none";
		document.getElementById("SearchImg_" + id).alt = "Hier klicken um weitere Infos zu diesem Ergebnis verstecken";
	}
}

function RedirectCompleteSearch ()
{
	window.location = document.getElementById("CompleteSearchSelect").options[document.getElementById("CompleteSearchSelect").selectedIndex].value;
}

// ------------------------------------------------------------------
// forum functions
// ------------------------------------------------------------------
function ToggleForumCategory (id)
{
	if (document.getElementById("ForumCategoryImg_" + id).src.indexOf ("/images/symbols/expand.gif") > 0)
	{
		//
		// set an cookie to show that forum on future visits, set lifetime to one year
		//
		setCookie ("forum" + id, "1", 31104000);
	
		document.getElementById("ForumCategoryImg_" + id).src = "/images/symbols/collapse.gif";
		document.getElementById("ForumCategoryImg_" + id).alt = "Hier klicken um diese Forum-Kategory anzuzeigen";

		//
		// hide all boards which belong to that forum
		//
		var items = this.document.getElementsByTagName("TR")

		for (i = 0; i < items.length; i++)
		{
			if (items[i].id.indexOf ('row_' + id) == 0)
			{
				items[i].style.display = '';
			}
		}
	}
	else
	{
		//
		// set an cookie to hide that forum on future visits, set lifetime to one year
		//
		setCookie ("forum" + id, "0", 31104000);

		document.getElementById("ForumCategoryImg_" + id).src = "/images/symbols/expand.gif";
		document.getElementById("ForumCategoryImg_" + id).alt = "Hier klicken um diese Forum-Kategory zu verstecken";

		//
		// hide all boards which belong to that forum
		//
		var items = this.document.getElementsByTagName("TR")
		var length = items.length;
		
		for (i = 0; i < length; i++)
		{
			if (items[i].id.indexOf ('row_' + id) == 0)
			{
				items[i].style.display = 'none';
			}
		}
	}
}

function AddFavouriteBoard (id)
{
	//
	// open popup
	//
	CommonPopup ('popup_addfavourite.aspx?board_id=' + id, 535, 120, 'addfavouritewnd');
}

function DelFavouriteBoard (id)
{
	//
	// open popup
	//
	CommonPopup ('popup_delfavourite.aspx?board_id=' + id, 535, 120, 'delfavouritewnd');
}


// --------------------------------------------------------------
// helper functions
// --------------------------------------------------------------
function PreviewPopup(url, width, height, input)
{
	previewwindow = window.open('' + url + '?&input=' + input + '','previewwindow','toolbar=no, location=no, scrollbars=1, width=' + width + ', height=' + height + ', left=100, top=100, alwaysRaised=true');
	previewwindow.focus();
	
	if (previewwindow.opener == null) 
		previewwindow.opener = self;
}

function CommonPopup(url, width, height, wndname)
{
	wnd = window.open(url, wndname,'toolbar=no, location=no, scrollbars=1, width=' + width + ', height=' + height + ', left=100, top=100, alwaysRaised=true');
	wnd.focus();
	
	if (wnd.opener == null)
	{ 
		wnd.opener = self;
	}
}

function CommonPopupNoScroll(url, width, height, wndname)
{
	wnd = window.open(url, wndname,'toolbar=no, location=no, scrollbars=0, width=' + width + ', height=' + height + ', left=100, top=100, alwaysRaised=true');
	wnd.focus();
	
	if (wnd.opener == null)
	{ 
		wnd.opener = self;
	}
}

function ShowBookmarkPopup()
{
	CommonPopup ('/mymtw/bookmarks/popup_addbookmark.aspx', 535, 200, 'bookmarkwnd');
}

// 
// gets the value of an querystring variable
// 
function retVal(sName)
{
	/*
	get last loc. of ?
	right: find first loc. of sName
	+2
	retrieve value before next &
	*/
  
	var sURL	  = new String(window.location);
	var iQMark    = sURL.lastIndexOf('?');
	var iLensName = sName.length;

	//retrieve loc. of sName
	var iStart = sURL.indexOf('?' + sName + '='); //limitation 1
	
	if (iStart == -1)
	{
		//not found at start
		iStart = sURL.indexOf('&' + sName + '='); //limitation 1
		
		if (iStart == -1)
		{
			//not found at end
			return 0;
		}   
	}
	    
	iStart = iStart + iLensName + 2;
	
	var iTemp = sURL.indexOf('&', iStart); //next pair start
	
	if (iTemp ==-1)
	{
		//EOF
		iTemp = sURL.length;
	}  
	
	return sURL.slice(iStart, iTemp) ;
	
	sURL = null;
}

// -------------------------------------------------------------------------------------------
// Tooltip functions
// -------------------------------------------------------------------------------------------

var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
offsetX = 0;
offsetY = 20;
var toolTipSTYLE = "";

function initToolTips()
{
	if (ns4 || ns6 || ie4 || ie55)
	{
		if (ns4)
		{
			toolTipSTYLE = document.toolTipLayer;
		}
		else if (ns6)
		{
			toolTipSTYLE = document.getElementById("toolTipLayer").style;
		}
		else if (ie4 || ie55)
		{
			toolTipSTYLE = document.all.toolTipLayer.style;
		}
		
		if (ns4)
		{
			document.captureEvents(Event.MOUSEMOVE);
		}
		else
		{
			toolTipSTYLE.visibility = "visible";
			toolTipSTYLE.display	= "none";
		}
    
		document.onmousemove = moveToMouseLoc;
	}

	NaviHelperLeft = findPosX (document.getElementById('NavigationControl'));
}

function toolTip (msg, width)
{
	fg = "#000000";
	bg = "#FFFFCC";
	
	if (toolTip.arguments.length < 1) // hide
	{
		if (ns4)
		{
			toolTipSTYLE.visibility = "hidden";
		}
		else 
		{
			toolTipSTYLE.display = "none";
		}
	}
	else // show
	{
		/*if (!fg)
		{
			fg = "#000000";
		}
    
		if (!bg)
		{
			bg = "#FFFFCC";
		}*/
		
		if (!width)
		{
			width = 180;
		}
		if (width == 0)
		{
			width = null;
		}

		var content =
		'<table width="' + width + '" border="0" cellspacing="1" cellpadding="0" bgcolor="' + fg + '"><td>' +
		'<table width="' + width + '" height="30" border="0" cellspacing="0" cellpadding="5" bgcolor="' + bg + 
		'"><td align="left"><span class="tooltip">' + msg +
		'&nbsp\;</span></td></table></td></table>';

		if (ns4)
		{
			toolTipSTYLE.document.write(content);
			toolTipSTYLE.document.close();
			toolTipSTYLE.visibility = "visible";
		}
	    else if (ns6)
		{
			document.getElementById("toolTipLayer").innerHTML = content;
			toolTipSTYLE.display = 'block';
		}
		else if (ie4 || ie55)
		{
			document.all("toolTipLayer").innerHTML = content;
			toolTipSTYLE.display = 'block';
		}
		else
		{
			document.all("toolTipLayer").innerHTML = content;
			toolTipSTYLE.display = 'block';
		}
	}
}

function moveToMouseLoc(e)
{
	if (ns4 || ns6)
	{
		x = e.pageX;

		if ((x + 220) > window.screen.availWidth)
		{
			x = window.screen.availWidth - 210;
		}

		y = e.pageY;
	}
	else
	{
		x = event.x + document.body.scrollLeft;

		if ((x + 220) > window.screen.availWidth)
		{
			x = window.screen.availWidth - 210;
		}

		y = event.y + document.body.scrollTop;
	}

	toolTipSTYLE.left = x + offsetX;
	toolTipSTYLE.top  = y + offsetY;


	//
	// get left, top, width, height for active dropdown
	//
	/*if (ActiveDropDown)
	{
		var aleft   = ActiveDropDown.offsetLeft;
		var awidth  = aleft + ActiveDropDown.offsetWidth;

		if (ns4 || ns6)
		{
			var atop    = ActiveDropDown.offsetTop - 20; // 18
			var aheight = atop + ActiveDropDown.offsetHeight + 20;

			x = e.pageX;
			y = e.pageY;
		}
		else
		{
			var atop    = ActiveDropDown.offsetTop - 18; // 16
			var aheight = atop + ActiveDropDown.offsetHeight + 18;
		
			x = event.x + document.body.scrollLeft;
			y = event.y + document.body.scrollTop;
		}
		
		//
		// Check if the mouse was moved outside the bound-area
		//
		if (!(x >= aleft && x <= awidth && y >= atop && y <= aheight) && !(x >= NaviHelperLeft && x >= (aleft - 25) && x <= awidth && y >= atop && y <= (atop + 18)))
		{
			ActiveDropDown.style.display = "none";

			//
			// Get id for the main navi item
			//
			id = ActiveDropDown.id.replace ("Div", "");

			//
			// Set background, color
			//
			if (document.getElementById(id).style.fontWeight == "normal" || document.getElementById(id).style.fontWeight == "")
			{
				document.getElementById(id).style.backgroundColor = "#7B7B7B";
				document.getElementById(id).style.color			  = "#CECECE";
			}

			//
			// Show form elements / flash
			//
			if (DropDownExceptions != null)
			{
				for (i = 0; i < DropDownExceptions.length; i++)
				{
					document.getElementById(DropDownExceptions[i]).style.visibility = "visible";
				}
			}
		}
	}*/

	return true;
}

function navimove (aobject, bgcolor, linkcolor)
{
	//
	// Get id for the main navi item
	//
	id = aobject.id.replace ("Div", "");
	
	//
	// Set background, color
	//
	document.getElementById(id).style.backgroundColor = bgcolor;
	document.getElementById(id).style.color			  = linkcolor;
}