
function Decrypt(code) {
 var text = new String, i;
 for (i=0;i<code.length;i+=2) text = text + String.fromCharCode(parseInt(code.substr(i,2),16)^((i/2)%256));
 return text;
}

/*
	NavBar
*/

function selectLocation() {
	var e = document.getElementById('location');
	var cmd = e.options[e.selectedIndex].value;
	var type = cmd.substr(0,3);
	var cmd = cmd.substr(4);
	if (type=='pop') popUpLocation('/popup.php?page='+cmd);
	if (type=='url') gotoURL('cmd='+cmd);
	e.selectedIndex = 0;
}

function selectTime() {
	var e = document.getElementById('time');
	var i = e.selectedIndex;
	if (i==1) gotoURL('cmd=setTimeFilter&data=now');
	if (i==2) popUpTime('/popup.php?page=Time');
	e.selectedIndex = 0;
}

function selectLocationExternal() {
	var e = document.getElementById('location');
	var cmd = e.options[e.selectedIndex].value;
	var type = cmd.substr(0,3);
	var cmd = cmd.substr(4);
	if (type=='pop') popUpLocation('http://www.mux.de/popup.php?page='+cmd);
	if (type=='url') gotoURL('cmd='+cmd);
	e.selectedIndex = 0;
}

function selectTimeExternal() {
	var e = document.getElementById('time');
	var i = e.selectedIndex;
	if (i==1) gotoURL('cmd=setTimeFilter&data=now');
	if (i==2) popUpTime('http://www.mux.de/popup.php?page=Time');
	e.selectedIndex = 0;
}

/*
	PopUps
*/

function popupGoogleMap(button,prefix) {
	var c = getAnchorWindowPosition(button.id);
	var x = c.x - 400;
	var y = c.y - 400;
	var win = window.open("/popup.php?page=GoogleMap&prefix="+prefix, "muxGoogleMap", "width=716,height=544,left="+x+",top="+y);
	win.focus();
}

function popupGoogleMap2(button,prefix) {
	var c = getAnchorWindowPosition(button.id);
	var x = c.x - 400;
	var y = c.y - 400;
	var win = window.open("/popup.php?page=GoogleMap2&prefix="+prefix, "muxGoogleMap", "width=716,height=544,left="+x+",top="+y);
	win.focus();
}

function popupGoogleMap3(button,lat,lon) {
	var c = getAnchorWindowPosition(button.id);
	var x = c.x - 400;
	var y = c.y - 400;
	var win = window.open("/popup.php?page=GoogleMap3&lat="+lat+"&lon="+lon, "muxGoogleMap", "width=716,height=544,left="+x+",top="+y);
	win.focus();
}

function popupGoogleMap4(button,street) {
	var c = getAnchorWindowPosition(button.id);
	var x = c.x;
	var y = c.y - 100;
	win = window.open("/popup.php?page=GoogleMap4&street="+street, "muxGoogleMap", "width=800,height=800,left="+x+",top="+y);
	win.focus();
	document.getElementById("lc1").checked = true;
}

function popupGoogleMap5(button) {
	var c = getAnchorWindowPosition(button.id);
	var x = c.x;
	var y = c.y - 100;
	win = window.open("/popup.php?page=GoogleMap5", "muxGoogleMap5", "width=800,height=800,left="+x+",top="+y+",resizable");
	win.focus();
}

function popUpLocation(url) {
	var c = getAnchorWindowPosition('location');
	var x = c.x - 100;
	var y = c.y - 50;
	var win = window.open(url, "muxSettings", "width=440,height=170,left="+x+",top="+y);
	win.focus();
}

function popUpTime(url) {
	var c = getAnchorWindowPosition("timeButton");
	var x = c.x - 100;
	var y = c.y - 50;
	var win = window.open(url, "muxSettings", "width=440,height=204,left="+x+",top="+y);
	win.focus();
}

function popEFA(anchor,url) {
	var c = getAnchorWindowPosition(anchor);
	var x = c.x - 310;
	var y = c.y - 280;
	var win = window.open(url, "MVV_EFA", "width=620,height=560,left="+x+",top="+y+",resizable,scrollbars=yes");
	win.focus();
}

function popupEdit(page) {

	if (window.screenX) {
		if (window.outerWidth) {
			var x = window.screenX + (( window.outerWidth - 600 )/2);
		}
		var y = window.screenY + 200;
	} else {
		var x = (screen.width-600)/2;
		var y = (screen.height-440)/2;
	}

	var url = "/edit.php?page="+page;
	var win = window.open(url, "muxEditPopup", "width=600,height=440,left="+x+",top="+y+",scrollbars=yes");
	win.focus();
}

function popupFull(page) {
	var url = "/popup.php?page="+page;
	var win = window.open(url, "", "");
	win.focus();
}

/*
	General Functions
*/

function gotoURL(url) {
	location.href='/?'+url;
}

function hideDefault(n) {
	if (n.value==n.defaultValue) n.value="";
}

function showDefault(n) {
	if (n.value=="") n.value=n.defaultValue;
}

function hideValue(n,t) {
	if (n.value==t) n.value="";
}

function showValue(n,t) {
	if (n.value=="") n.value=t;
}

function hideSuche(n) {
	if (n.value=='Suche') n.value="";
}

function showSuche(n) {
	if (n.value=="" && n.defaultValue=="Suche") n.value="Suche";
}

function getStats() {
	document.login.browserInfo.value=navigator.userAgent;
	document.login.screenInfo.value=screen.width+'x'+screen.height+'x'+screen.colorDepth;
}

function getObject(o) {
	if (typeof o=="string") {
		if(document.all) return document.all(o);
		if(document.getElementById) return document.getElementById(o);
	} else {
		return o;
	}
	return null;
}

function updateCharsLeft(i,t,c) {
	var l=c-getObject(i).value.length;
	if(l<0) l=0;
	getObject(t).innerHTML=l;
}

/*
	DHTML Menu
*/

var activeButton;

function openPopUp(button,menu) {
	if (activeButton) {
	  activeButton.menu.style.visibility = "hidden";
	  if (activeButton = button) {
		  activeButton = false;
	  	return;
	  }
	  activeButton = false;
	}

  var w, dw, x, y;
	button.menu = document.getElementById(menu);

  x = getPageOffsetLeft(button)-1+180;  
  y = getPageOffsetTop(button) + button.offsetHeight-10;

  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";
  button.menu.style.visibility = "visible";

  button.isactive = true;
  activeButton = button;
}

/*
	Browser Window Size and Position - CRAP
*/

function pageWidth() {
	return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

function pageHeight() {
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

function posLeft() {
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}
function posTop() {
	return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

function posRight() {
	return posLeft()+pageWidth();
}

function posBottom() {
	return posTop()+pageHeight();
}
                    

/* 
AnchorPosition.js
Author: Matt Kruse
Last modified: 10/11/02

DESCRIPTION: These functions find the position of an <A> tag in a document,
so other elements can be positioned relative to it.

COMPATABILITY: Netscape 4.x,6.x,Mozilla, IE 5.x,6.x on Windows. Some small
positioning errors - usually with Window positioning - occur on the 
Macintosh platform.

FUNCTIONS:
getAnchorPosition(anchorname)
  Returns an Object() having .x and .y properties of the pixel coordinates
  of the upper-left corner of the anchor. Position is relative to the PAGE.

getAnchorWindowPosition(anchorname)
  Returns an Object() having .x and .y properties of the pixel coordinates
  of the upper-left corner of the anchor, relative to the WHOLE SCREEN.

NOTES:

1) For popping up separate browser windows, use getAnchorWindowPosition. 
   Otherwise, use getAnchorPosition

2) Your anchor tag MUST contain both NAME and ID attributes which are the 
   same. For example:
   <A NAME="test" ID="test"> </A>

3) There must be at least a space between <A> </A> for IE5.5 to see the 
   anchor tag correctly. Do not do <A></A> with no space.
*/ 

function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}

function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}

function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
}

function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
}	

function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
}

function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
}

// Data Dumper (http://www.mattkruse.com/javascript/datadumper/index.html)

var DumperIndent = 1;
var DumperIndentText = " ";
var DumperNewline = "\n";
var DumperObject = null; // Keeps track of the root object passed in
var DumperMaxDepth = -1; // Max depth that Dumper will traverse in object
var DumperIgnoreStandardObjects = true; // Ignore top-level objects like window, document
var DumperProperties = null; // Holds properties of top-level object to traverse - others are igonred
var DumperTagProperties = new Object(); // Holds properties to traverse for certain HTML tags
function DumperGetArgs(a,index) {
	var args = new Array();
	// This is kind of ugly, but I don't want to use js1.2 functions, just in case...
	for (var i=index; i<a.length; i++) {
		args[args.length] = a[i];
	}
	return args;
}
function DumperPopup(o) {
	var w = window.open("about:blank");
	w.document.open();
	w.document.writeln("<HTML><BODY><PRE>");
	w.document.writeln(Dumper(o,DumperGetArgs(arguments,1)));
	w.document.writeln("</PRE></BODY></HTML>");
	w.document.close();
}
function DumperAlert(o) {
	alert(Dumper(o,DumperGetArgs(arguments,1)));
}
function DumperWrite(o) {
	var argumentsIndex = 1;
	var d = document;
	if (arguments.length>1 && arguments[1]==window.document) {
		d = arguments[1];
		argumentsIndex = 2;
	}
	var temp = DumperIndentText;
	var args = DumperGetArgs(arguments,argumentsIndex)
	DumperIndentText = "&nbsp;";
	d.write(Dumper(o,args));
	DumperIndentText = temp;
}
function DumperPad(len) {
	var ret = "";
	for (var i=0; i<len; i++) {
		ret += DumperIndentText;
	}
	return ret;
}
function Dumper(o) {
	var level = 1;
	var indentLevel = DumperIndent;
	var ret = "";
	if (arguments.length>1 && typeof(arguments[1])=="number") {
		level = arguments[1];
		indentLevel = arguments[2];
		if (o == DumperObject) {
			return "[original object]";
		}
	}
	else {
		DumperObject = o;
		// If a list of properties are passed in
		if (arguments.length>1) {
			var list = arguments;
			var listIndex = 1;
			if (typeof(arguments[1])=="object") {
				list = arguments[1];
				listIndex = 0;
			}
			for (var i=listIndex; i<list.length; i++) {
				if (DumperProperties == null) { DumperProperties = new Object(); }
				DumperProperties[list[i]]=1;
			}
		}
	}
	if (DumperMaxDepth != -1 && level > DumperMaxDepth) {
		return "...";
	}
	if (DumperIgnoreStandardObjects) {
		if (o==window || o==window.document) {
			return "[Ignored Object]";
		}
	}
	// NULL
	if (o==null) {
		ret = "[null]";
		return ret;
	}
	// FUNCTION
	if (typeof(o)=="function") {
		ret = "[function]";
		return ret;
	} 
	// BOOLEAN
	if (typeof(o)=="boolean") {
		ret = (o)?"true":"false";
		return ret;
	} 
	// STRING
	if (typeof(o)=="string") {
		ret = "'" + o + "'";
		return ret;
	} 
	// NUMBER	
	if (typeof(o)=="number") {
		ret = o;
		return ret;
	}
	if (typeof(o)=="object") {
		if (typeof(o.length)=="number" ) {
			// ARRAY
			ret = "[";
			for (var i=0; i<o.length;i++) {
				if (i>0) {
					ret += "," + DumperNewline + DumperPad(indentLevel);
				}
				else {
					ret += DumperNewline + DumperPad(indentLevel);
				}
				ret += Dumper(o[i],level+1,indentLevel-0+DumperIndent);
			}
			if (i > 0) {
				ret += DumperNewline + DumperPad(indentLevel-DumperIndent);
			}
			ret += "]";
			return ret;
		}
		else {
			// OBJECT
			ret = "{";
			var count = 0;
			for (i in o) {
				if (o==DumperObject && DumperProperties!=null && DumperProperties[i]!=1) {
					// do nothing with this node
				}
				else {
					if (typeof(o[i]) != "unknown") {
						var processAttribute = true;
						// Check if this is a tag object, and if so, if we have to limit properties to look at
						if (typeof(o.tagName)!="undefined") {
							if (typeof(DumperTagProperties[o.tagName])!="undefined") {
								processAttribute = false;
								for (var p=0; p<DumperTagProperties[o.tagName].length; p++) {
									if (DumperTagProperties[o.tagName][p]==i) {
										processAttribute = true;
										break;
									}
								}
							}
						}
						if (processAttribute) {
							if (count++>0) {
								ret += "," + DumperNewline + DumperPad(indentLevel);
							}
							else {
								ret += DumperNewline + DumperPad(indentLevel);
							}
							ret += "'" + i + "' => " + Dumper(o[i],level+1,indentLevel-0+i.length+6+DumperIndent);
						}
					}
				}
			}
			if (count > 0) {
				ret += DumperNewline + DumperPad(indentLevel-DumperIndent);
			}
			ret += "}";
			return ret;
		}
	}
}


// Calendar

var day;
var month;
var year;
var hour;
var minute;
var second;
var clock_set = 0;

var month_names = new Array('Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
var day_names = new Array('Mo','Di','Mi','Do','Fr','Sa','So');

/**
 * Formats number to two digits.
 *
 * @param   int number to format.
 */
function formatNum2(i, valtype) {
    f = (i < 10 ? '0' : '') + i;
    if (valtype && valtype != '') {
        switch(valtype) {
            case 'month':
                f = (f > 12 ? 12 : f);
                break;

            case 'day':
                f = (f > 31 ? 31 : f);
                break;

            case 'hour':
                f = (f > 24 ? 24 : f);
                break;

            default:
            case 'second':
            case 'minute':
                f = (f > 59 ? 59 : f);
                break;
        }
    }

    return f;
}

/**
 * Formats number to four digits.
 *
 * @param   int number to format.
 */
function formatNum4(i) {
    return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
}

function initCalendar() {
	if (!year && !month && !day) {
		day = document.master.day.value;
		month = document.master.month.value-1;
		year = document.master.year.value;
	} else {
		dt = new Date();
		if (year<dt.getFullYear()) {
			if (year<100)	year = parseInt(year)+2000;
			if (year<dt.getFullYear()) year = dt.getFullYear();
		}

		if (month > 11) {
		    month = 0;
		    year++;
		}

		if (month < 0) {
		    month = 11;
		    year--;
		}

		var lastDay = new Date(year, month + 1, 0).getDate();
		if (day<1) day = 1;
		if (day>lastDay) day = lastDay;
	}
	
	document.master.day.value = day;
	document.master.month.value = month+1;
	document.master.year.value = year;
	
	if (document.getElementById) {
		cnt = document.getElementById("calendar_data");
	} else if (document.all) {
		cnt = document.all["calendar_data"];
	}
	
	cnt.innerHTML = "";
	
	str = ""
	str += '<table class="calendar"><tr><th width="8%">';
	str += '<a href="javascript:month--;initCalendar();updateText();">&laquo;</a> ';
	str += '</th><th width="40%">';
	str +=  month_names[month];
	str += '</th><th width="8%">';
	str += ' <a href="javascript:month++;initCalendar();updateText();">&raquo;</a>';
	str += '</th><th width="8%">';
	str += '<a href="javascript:year--;initCalendar();updateText();">&laquo;</a> ';
	str += '</th><th width="28%">';
	str +=  year;
	str += '</th><th width="8%">';
	str += ' <a href="javascript:year++;initCalendar();updateText();">&raquo;</a>';
	str += '</th></tr></table>';
	
	str += '<table class="calendar"><tr>';
	for (i = 0; i < 7; i++) {
		str += "<th>" + day_names[i] + "</th>";
	}
	str += "</tr>";
	
	var firstDay = new Date(year, month, 1).getDay();
	var lastDay = new Date(year, month + 1, 0).getDate();

	str += "<tr>";

	if (firstDay==0) firstDay=7;

	dayInWeek = 1;
	for (i = 1; i < firstDay; i++) {
		str += "<td>&nbsp;</td>";
		dayInWeek++;
	}
	for (i = 1; i <= lastDay; i++) {
		if (dayInWeek == 8) {
		    str += "</tr><tr>";
		    dayInWeek = 1;
		}
		
		dispmonth = 1 + month;
		
		actVal = formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
		
		if (i == day) {
		    style = ' class="selected"';
		} else {
		    style = '';
		}
		str += "<td" + style + "><a href=\"javascript:day=" + i + ";initCalendar();updateText();\">" + i + "</a></td>"
		dayInWeek++;
	}
	for (i = dayInWeek; i < 7; i++) {
		str += "<td>&nbsp;</td>";
	}
	
	str += "</tr></table>";
	
	cnt.innerHTML = str;
}

function updateCalendar() {
	day = document.master.day.value;
	month = document.master.month.value-1;
	year = document.master.year.value;

	initCalendar();
}

/*
	Textarea resize
*/

function expandTextfield(e) {
  var pixel = /(\d+)px/;
  pixel.exec(e.style.height);
	var h = parseInt(RegExp.$1);
	e.style.height = h+52;
}

function shrinkTextfield(e) {
  var pixel = /(\d+)px/;
  pixel.exec(e.style.height);
	var h = parseInt(RegExp.$1);
	if (h>80) e.style.height = h-52;
}
