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, title, w, h) {

	//alert('loading popup...'); 
	
	if ( typeof(w) =="undefinded" ) 
		w = 600; 

	if ( typeof(h) =="undefinded" ) 
		h = 200; 

	if (window.screenX) {
		if (window.outerWidth) {
			var x = window.screenX + (( window.outerWidth - w )/2);
		}
		var y = window.screenY + h;
	} else {
		var x = (screen.width-w)/2;
		var y = (screen.height-h*2)/2;
	}

	win_h = $(window).height() -50 ; 
	//alert( win_h); 
	win_w = 780;
	
	var url = "/edit.php?page="+page;
//	var win = window.open(url, "muxEditPopup", "width=600,height=440,left="+x+",top="+y+",scrollbars=yes");
//	win.focus();
	
	if ( !title) title = "Bearbeiten Sie Ihre Daten"; 

	var options2 = { 
			title: title,
			width: win_w, 
			height: win_h,
			resizable:false,
			draggable:false,
			modal: true, 
			overlay: { 
				opacity: 0.6, 
			    background: "#333333" 
			} 
		}; 

	jQuery('#dialog').dialog(options2).html('<iframe frameborder="no" height="100%" width="100%" style="width:100%;height:100%;margin:0px;padding:0px;border:0px;overflow:auto;" src="'+url+'" ></iframe>')  ;
}


function popupInfo(id, title ){
	win_h = $(window).height() -50 ; 
	win_w = $(window).width() -50 ; 
	
	popupInfoWH( id , title , win_w, win_h); 
}

function popupInfoWH( id , title , w, h){
	
	var options = { 
			title: title,
			width: w, 
			height: h,
			resizable:false,
			draggable:false,
			modal: true, 
			overlay: { 
				opacity: 0.6, 
			    background: "#333333"   
			} 
		}; 

	jQuery(id).show().dialog(options).css('overflow','auto')  ;
//	jQuery('.ui-dialog-content').css('padding','4px');
}

function goto( url ) {
	if (!document.do_sort) {
		location.href = url;
	} else {
		//alert( 'Navigation deaktiviert beim sortieren!');
	}
}

function show_message( id_string , text ) {
	//$.growl('Data Saved', 'text', 'info.png', 'medium');
	
	$(window).scroll(function () { 
		$(id_string).css('top',$(document).scrollTop());
	});
	$(id_string).css('top',$(document).scrollTop());
	$(id_string +' .content').html(text);
	$(id_string).slideDown(1000);
	setTimeout("$('"+id_string+"').slideUp(1000)",4000);
	//$(window).scroll(function () {} ); // release
}

function StartMySortableEdit () {
	if( $('.sortable_menu').length > 0 )
		$('.sortable_menu').sortable({
			/* 
			*/
			/* axis : 'y', */
			items : '> .sortable_menu_item',
			opacity: 	0.8,
			cursor: 'move' , 
			handle: '.handle' ,
			update: function(){
			//	$('.editLink').toggle();
				//$('.sortable_products').sortable('destroy');
				//StartMySortable();
			},
			containment:'parent' 
			/*,
			update: function(){
				 visibilityUpDownButtons();
			}*/
			
			/* helper: false, */
	
		});
}

function StartMyMoveable( object_id, page_id ) {
	$('.productmove_draggable').draggable({
		revert: true,
		cursor: 'move', 
		scroll: true
	});
	$('.productmove_droppable').droppable({
		accept: ".productmove_draggable",
		activeClass: 'product_drop_active',
		hoverClass: 'product_drop_hover',
		drop: function(ev, ui){
			
			page_id = $(this).attr('id'); 
			page_id = page_id.replace(/^pageid\_/g,''); // remove prefix
			
			product_id = $(ui.draggable).attr('id'); 
			product_id = product_id.replace(/^productmove\_/g,''); 
			product_id = product_id.replace(/^productid\_/g,''); 
			
			//show_message( "#edit_message" , "dropped: " + page_id+ " from: "+ product_id );
			$('#productid_'+product_id).slideUp(1000).hide().ready(function(){
				goto('/client.php?id='+object_id+"&page="+page_id+"&product="+product_id+"&cmd=moveProduct");
			});
		}
		
	});
}


function StartMySortable(  object_id , page_id , page_num, product_num) {
		
		$('.fix_scrollings').css('position','relative');
		
		// enable sortables
		if( $('.sortable_menu').length > 0 )
		$('.sortable_menu').sortable({
			/* 
			items : '> .sortable_menu_item',
			*/
			/* axis : 'y', */
			opacity: 	0.8, 
			/*cursor: 'move' , */
			handle: '.handle' ,
			containment:'parent', 
			/* helper: false, */
			update: function(){ 
				serialized = $(this).sortable('serialize') ; 
				//alert( serialized ); 
				 $.ajax({
				   type: "POST",
				   url: "/edit.php?cmd=updatePageMenuSorting&object="+object_id ,
				   data: serialized,
				   success: function(msg){
					 show_message( '#edit_message', msg );
				   }
				   
				 });
				 return false;
				
			}
		});
		
		if (page_num < 50 )
		if( $('.sortable_products').length > 0 )
		$('.sortable_products').sortable({
			/* 
			*/
			/* axis : 'y', */
			items : '> li',
			opacity: 	0.8,
			
			/* cursor: 'move' , */
			handle: '.handle' ,
			containment:'document' , 
			connectWith: [".sortable_products_menu_small",".sortable_products"] , /*  */
			//connectWith: [".sortable_products"] , /*  */
			
			dropOnEmpty: true,
			/* helper: false, */
			update: function( e, ui){ 
				serialized = $(this).sortable('serialize') ; 
				 //alert( "1 update"); 
				 
				 page_id_move = $(this).attr('id').replace(/^(menu_pageid_|content_pageid_)/,"") ;
				 //alert( page_id_move + "... "+ $(this).attr('id') ); 
				 
				 if( typeof(page_id_move) != "undefined" ) {
				 	page_id_old = page_id; 
					page_id = page_id_move; // use dynamic 
				 }
				 $.ajax({
				   type: "POST",
				   url: "/edit.php?cmd=updateProductSorting&object="+object_id+"&page="+page_id,
				   data: serialized,
				   success: function(msg){
				 	 show_message( '#edit_message',  msg );
				  }
				 
				 });
				 if( typeof(page_id_move) != "undefined" ) {
				 	if( page_id_move == page_id_old  ){
						// current page was affected so lets reload
						//setTimeout('document.location.reload();',1000); // reload after 1 second
					//	setTimeout('document.location.href="client.php?id='+object_id+'&page='+page_id+'"',1000); // reload after 1 second
					
					}
				 	page_id = page_id_old; 
				 }  
				// $('#ui-sortable-placeholder').hide();
				 return false;
				
			},
			receive: function(e,ui){ 
				//alert( page_id_sender = $(ui.sender).attr('id').replace(/^(menu_pageid_|content_pageid_)/,"") );
				 page_id_new = $(this).attr('id').replace(/^(menu_pageid_|content_pageid_)/,"") ;
				setTimeout('document.location.href="/client.php?id='+object_id+'&page='+page_id_new+'"',1000); // reload after 1 second
				show_message( '#edit_message', 'loading ...' );	
				return false;
				
			} 
		});
		
		if (page_num < 50 )
		if( $('.sortable_products_menu_small').length > 0 )
		$('.sortable_products_menu_small').sortable({
			/* 
			*/
			/* axis : 'y', */
			items : '> li',
			opacity: 	0.8,
			/* cursor: 'move' , */
			handle: '.handle' ,
			containment:'div#page_content' , 
			connectWith: [".sortable_products_menu_small",".sortable_products"] ,
			//connectWith: [".sortable_products"] ,
			
			dropOnEmpty: true,
			/* helper: false, */
			update: function( e, ui){ 
				serialized = $(this).sortable('serialize') ; 
				 //alert( "2 update"); 
				 
				 page_id_move = $(this).attr('id').replace(/^(menu_pageid_|content_pageid_)/,"") ;
				 //alert( $(ui.sender).attr('id') ); 
				 
				 if( typeof(page_id_move) != "undefined" ) {
				 	page_id_old = page_id; 
					page_id = page_id_move; // use dynamic 
				 }
				 $.ajax({
				   type: "POST",
				   url: "/edit.php?cmd=updateProductSorting&object="+object_id+"&page="+page_id,
				   data: serialized,
				   success: function(msg){
				 	 show_message( '#edit_message',  msg );
				  }
				 
				 });
				 if( typeof(page_id_move) != "undefined" ) {
				 	if( page_id_move == page_id_old  ){
						// current page was affected so lets reload
						setTimeout('document.location.href="/client.php?id='+object_id+'&page='+page_id+'"',1000); // reload after 1 second
					}
				 	page_id = page_id_old; 
				 }  
				// $('#ui-sortable-placeholder').hide();
				 return false;
				
			},
			receive: function(e,ui){ 
				//alert( page_id_sender = $(ui.sender).attr('id').replace(/^(menu_pageid_|content_pageid_)/,"") );
				 page_id_new = $(this).attr('id').replace(/^(menu_pageid_|content_pageid_)/,"") ;
				setTimeout('document.location.href="/client.php?id='+object_id+'&page='+page_id_new+'"',1000); // reload after 1 second
				show_message( '#edit_message', 'loading ...' );	
					
				return false;
				
			} 
			 
		});
		if( $('.sortable_images').length > 0 )
		$('.sortable_images').sortable({
			items : '> li',
			opacity: 	0.8,
			/* axis : 'y', */
			cursor: 'move' , 
			handle: '.handle' ,
			containment:'parent2',
			/* helper: false, */
			update: function(){ 
				serialized = $(this).sortable('serialize') ; 
				//alert( serialized ); 
				 $.ajax({
				   type: "POST",
				   url: "/edit.php?cmd=updateClientImageSorting&object="+object_id+"&page="+page_id,
				   data: serialized,
				   success: function(msg){
				 	 show_message( '#edit_message',  msg );
				  }
				   
				 });
				 return false;
				
			}
		});
		
	
}



function popupClose() {
	top.jQuery('#dialog').dialog('close');
}

function popupTitle2(title2) {
	top.jQuery('#dialog').data('title.dialog', title2); 
}

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

function window_resizeTo( x, y) {
	//top.jQuery('#dialog').css('width', x ).css('height',y);
}

function window_moveBy( x,y ) {
	//window.moveBy(x,y);
}

/*
	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;
}

// Simulates PHP's date function
Date.prototype.format = function(format) {
	var returnStr = '';
	var replace = Date.replaceChars;
	for (var i = 0; i < format.length; i++) {
		var curChar = format.charAt(i);
		if (replace[curChar])
			returnStr += replace[curChar].call(this);
		else
			returnStr += curChar;
	}
	return returnStr;
};
Date.replaceChars = {
	shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
	longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
	shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
	longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
	
	// Day
	d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
	D: function() { return Date.replace.shortDays[this.getDay()]; },
	j: function() { return this.getDate(); },
	l: function() { return Date.replace.longDays[this.getDay()]; },
	N: function() { return this.getDay() + 1; },
	S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); },
	w: function() { return this.getDay(); },
	z: function() { return "Not Yet Supported"; },
	// Week
	W: function() { return "Not Yet Supported"; },
	// Month
	F: function() { return Date.replace.longMonths[this.getMonth()]; },
	m: function() { return (this.getMonth() +1 < 10 ? '0' : '') + (this.getMonth() + 1); },
	M: function() { return Date.replace.shortMonths[this.getMonth()]; },
	n: function() { return this.getMonth() + 1; },
	t: function() { return "Not Yet Supported"; },
	// Year
	L: function() { return "Not Yet Supported"; },
	o: function() { return "Not Supported"; },
	Y: function() { return this.getFullYear(); },
	y: function() { return ('' + this.getFullYear()).substr(2); },
	// Time
	a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
	A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
	B: function() { return "Not Yet Supported"; },
	g: function() { return this.getHours() == 0 ? 12 : (this.getHours() > 12 ? this.getHours() - 12 : this.getHours()); },
	G: function() { return this.getHours(); },
	h: function() { return (this.getHours() < 10 || (12 < this.getHours() < 22) ? '0' : '') + (this.getHours() < 10 ? this.getHours() + 1 : this.getHours() - 12); },
	H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
	i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
	s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },
	// Timezone
	e: function() { return "Not Yet Supported"; },
	I: function() { return "Not Supported"; },
	O: function() { return (this.getTimezoneOffset() < 0 ? '-' : '+') + (this.getTimezoneOffset() / 60 < 10 ? '0' : '') + (this.getTimezoneOffset() / 60) + '00'; },
	T: function() { return "Not Yet Supported"; },
	Z: function() { return this.getTimezoneOffset() * 60; },
	// Full Date/Time
	c: function() { return "Not Yet Supported"; },
	r: function() { return this.toString(); },
	U: function() { return this.getTime() / 1000; }
}

var menu_sub_open_state = new Array(); 

function menu_sub_open_delayed( id_str ) {
	t= setTimeout( "$( '"+ id_str +"' ).show();" ,1000 ); 
	menu_sub_open_state[ id_str ] = t; 
}
function menu_sub_open_cancel( id_str) {
	t = menu_sub_open_state[ id_str ]; 
	if (t) {
		clearTimeout(t); // could be more specific by id
		menu_sub_open_state[id_str] = "";
	}
}

function limitChars(textid, limit, infodiv)
	{
		var text = $('#'+textid).val();	
		var textlength = text.length;
		if(textlength + 10 > limit && textlength <= limit )
		{
			$('#' + infodiv).html('<span style="color:green !important">(Sie können noch '+ (limit - textlength) +' Zeichen schreiben.)</span>')
			$('#'+textid).css('border-color','silver');
			return false;
		}
		else if(textlength > limit)
		{
			$('#' + infodiv).html('<span style="color:red !important;font-weight:bold;">(Sie haben '+ ( -(limit - textlength)) +' Zeichen zuviel.)</span>').css('border-color','red');;
			$('#'+textid).css('border-color','red');
			return false;
		}
		else
		{
			$('#' + infodiv).html('<span style="">(Sie können noch '+ (limit - textlength) +' Zeichen schreiben.)</span>').css('border-color','silver');;
			$('#'+textid).css('border-color','silver');
			return true;
		}
	}
