// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// navi/subnavi-functions
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var activeSubnaviID = null;
var activeMainnaviID = null;
var subnaviAry;
var subnaviPos = null;

function getObj(id){
	if( document.getElementById ){
		var obj = document.getElementById(id);
	}else if( document.all ){
		var obj = document.all(id);
	}else{
		alert("unsupported");
	};
	return obj;
}

// @function	toggleNavi(id)
// @date		2003-09-22
function toggleNavi(id){
	if( typeof mainnaviAry!="object" ){
		return;
	};
	if( activeSubnaviID!=null ){
		// hide active subnavi
		/* var activeSubnavi = document.getElementById("sn"+activeSubnaviID); */
		var activeSubnavi = getObj("sn"+activeSubnaviID);
		activeSubnavi.style.visibility = "hidden";
		/* Keine Personen im Rechtenbereich
		
		if( parseInt(activeSubnaviID)>=5 ){
			var titleOverlay1 = getObj("titleOverlay1");
			var titleOverlay2 = getObj("titleOverlay2");
			//document.getElementById("titleOverlay1").src = titleOverlayAry["filled"][0].src;
			//document.getElementById("titleOverlay2").src = titleOverlayAry["filled"][1].src;
			titleOverlay1.src = titleOverlayAry["filled"][0].src;
			titleOverlay2.src = titleOverlayAry["filled"][1].src
			
		};
		*/
		if( typeof mainnaviAry[activeMainnaviID]['norm'].src=="string" ){
			document.images['mn'+activeMainnaviID].src = mainnaviAry[activeMainnaviID]['norm'].src;
		};
		if( activeSubnaviID == id ){
			activeSubnaviID = null;
			return;
		}
		activeMainnaviID = null;
	};
	/* Keine Personen im Rechtenbereich
	if( parseInt(id)>=5 ){
		var titleOverlay1 = getObj("titleOverlay1");
		var titleOverlay2 = getObj("titleOverlay2");
		titleOverlayAry["filled"][0].src = titleOverlay1.src;
		titleOverlayAry["filled"][1].src = titleOverlay2.src;
		titleOverlay1.src = titleOverlayAry["blank"][0].src;
		titleOverlay2.src = titleOverlayAry["blank"][1].src;
		
		

	};
	*/
	// var subnavi = document.getElementById("sn"+id);
	// better version:
	var subnavi = getObj("sn"+id);
	if( subnavi == null ){
		activeSubnaviID = null;
		return;
	}
	subnavi.style.visibility = "visible";
	if( typeof mainnaviAry[id]['norm'].src=="string" ){
		document.images['mn'+id].src = mainnaviAry[id]['over'].src;
	};
	activeSubnaviID = id;
	activeMainnaviID = id;
	return false;
}


// @function	mnOver(id)
// @date		2003-09-19
function mnOver(id){
	if( !document.images || typeof document.images['mn'+id]=="undefined" || typeof mainnaviAry!="object"){
		return false;
	};
	document.images['mn'+id].src = mainnaviAry[id]['over'].src;
	return false;
}

// @function	mnOut(id)
// @date		2003-09-19
function mnOut(id){
	if( !document.images || typeof document.images['mn'+id]=="undefined" || typeof mainnaviAry!="object"){
		return false;
	};
	if( activeMainnaviID!=null && activeMainnaviID==id ){
		return;
	}
	document.images['mn'+id].src = mainnaviAry[id]['norm'].src;
	return false;
}

// @function 	snOver(subnaviID,imgID)
// @date		2003-07-23
function snOver(subnaviID,imageID){
	if( typeof subnaviAry[subnaviID][Number(imageID)]['over'] != "object" ){
		printDebug("error - image not found. (subnaviID: " + subnaviID + ", imageID: " + imageID + " parseInt():" + Number(imageID)+")<br>");
		debugSubnaviPreloader();
		return;
	};
	//document.getElementById(subnaviID+'_'+imageID).src = subnaviAry[subnaviID][Number(imageID)]['over'].src;
	document.images[subnaviID+'_'+imageID].src = subnaviAry[subnaviID][Number(imageID)]['over'].src;
}

// @function 	snOut(snID,imgID)
// @date		2003-07-23
function snOut(subnaviID,imageID){
	if( typeof subnaviAry[subnaviID][Number(imageID)]['norm'] != "object" ){
		return;
	}
	//document.getElementById(subnaviID+'_'+imageID).src = subnaviAry[subnaviID][Number(imageID)]['norm'].src;
	document.images[subnaviID+'_'+imageID].src = subnaviAry[subnaviID][Number(imageID)]['norm'].src;
}

// @function 	sbOver(id)
// @date		2003-09-22
function sbOver(id){
	if( !document.images || typeof document.images['sb'+id]=="undefined" || typeof servicebarAry!="object" ){
		return false;
	};
	document.images['sb'+id].src = servicebarAry[id]['over'].src;
	return false;
}

// @function 	sbOut(id)
// @date		2003-09-22
function sbOut(id){
	if( !document.images || typeof document.images['sb'+id]=="undefined" || typeof servicebarAry!="object" ){
		return false;
	};
	document.images['sb'+id].src = servicebarAry[id]['norm'].src;
	return false;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// misc functions
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// @function	openHistory()
// @date		2003-07-10
function openHistory(){
	var hWin = window.open('history.php','historyWin','width=335,height=300');
	hWin.focus();
	return false;
}

// @function	openInfogate()
// @date		2004-07-05
function openInfogate(){
	var infWin = window.open('http://infogate.eurogate.de','infogateWin','width=760,height=550,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes');
	infWin.focus();
	return false;
}

// @function 	openIndex()
// @date		2003-07-16
function openIndex(ps_url){
	var siWin = window.open(ps_url,'siteindexWin','width=400,height=400,scrollbars=yes,resizable=yes');
	siWin.focus();
	return false;
}

// @function	openPrintversion()
// @date		2003-07-10
function openPrintversion(ps_url){
	var printWin = window.open(ps_url,'printWin','width=640,height=500,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes');
	printWin.focus();
	return false;
}

// @function 	openRecommendPage()
// @date		2003-07-16
function openRecommendPage(){
	var url = 'recommend_page.php';
	var rpWin = window.open(url,'rpWin','width=340,height=450');
	rpWin.focus();
	return false;
}

// @function 	openLanguageSelector(ps_url)
// @date		2003-07-16
function openLanguageSelector(ps_url){
	//var url = 'select_language.php';
	var slWin = window.open(ps_url,'slWin','width=100,height=50');
	slWin.focus();
	return false;
}

// @function	openDownloadcenter()
// @date		2003-07-10
function openDownloadcenter(ps_url){
	// var url = 'downloadcenter.php';
	var downloadCenterWin = window.open(ps_url,'downloadCenterWin','width=702,height=487');
	downloadCenterWin.focus();
	return false;
}

// @function	openGallery(gallery_url)
// @date		2004-01-16
function openGallery(ps_url){
	var galleryWin = window.open(ps_url,'galleryWin','width=663,height=487');
	galleryWin.focus();
	return false;
}

// @function	openOrgchart(chart_url)
// @date		2004-01-16
function openOrgchart(ps_url){
	var wWidth = screen.width ? screen.width -10 : 600;
	var wHeight = screen.height ? screen.height -70  : 450;
     if ( document.all && !window.opera )  {
         var wh = window.open(ps_url,'firmenstruktur','width='+wWidth+',height='+wHeight+',resizable=yes,scrollbars=no');
     } else {
         my_url = ps_url.replace('_js','_nojs');
	    var wh = window.open(my_url,'firmenstruktur','width='+wWidth+',height='+wHeight+',resizable=yes,scrollbars=yes');
     }
	wh.moveTo(0,0);
	wh.focus();
	return false;
}





// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// js-debugger!
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var mcmEnableDebugger = true;

/**
* @function printDebug(html)
* @date		2003-05-27
*/
function printDebug(html){
	if( typeof mcmEnableDebugger == "undefined" || mcmEnableDebugger!=true ){
		return;
	};
	if( typeof mcmDebugWindow=="undefined" || mcmDebugWindow.closed == true){
		var left = 1152; var width = 400;
		left -= (width + 13);
		mcmDebugWindow = window.open('','mcmDebugWin','width='+width+',height=400,status=yes,resizable=yes,scrollbars=yes,left='+left+',top=0');
		mcmDebugWindow.document.open();
		mcmDebugWindow.document.writeln('<html>\n<title>Javascript-Debugger</title>\n<head>\n<style type="text/css">\nbody,th,td { font-family:Courier; font-size:11px;}\n</style>\n</head><body scroll="auto">');
		mcmDebugWindow.document.writeln('<div align="center" style="background-color:buttonface;"><button onclick="document.getElementById(\'debugOutput\').innerHTML=\'\';">clear page</button></div><div id="debugOutput"></div>');
		mcmDebugWindow.document.writeln('</body></html>');
		mcmDebugWindow.document.close();
	};
	mcmDebugWindow.document.getElementById("debugOutput").innerHTML += html;
	//mcmDebugWindow.focus();
};


/**
* @function printDebugOject(obj,bSortIt)
* @param	obj		object 	object to inspect
* @param	bSortIt	bool	sort the object-properties?
* @date		2003-05-27
*/
function printDebugObject(obj,bSortIt){
	if( typeof mcmEnableDebugger == "undefined" || mcmEnableDebugger!=true ){
		return;
	};
	if( typeof obj=="object" ){
		var i;
		var htmlBuffer = '';
		var bufferAry = new Array();
		var htmlStr = "";
		for( i in obj ){
			htmlStr  = '<tr><td valign="top"><b>'+i+'</b></td><td valign="top">';
			if( typeof obj[i] == "boolean" ){
				htmlStr += obj[i]==true ? 'true' : 'false';
			//}else if( typeof obj[i] == "object" ){
			//	htmlStr += '<a href="#" onclick="printDebugObject(obj[i]);">' + obj[i] + '</a>';
			}else{
				htmlStr += (obj[i]==''?'&nbsp;':obj[i])
			};
			htmlStr += '</td><td>['+(typeof obj[i])+']</td></tr>';
			bufferAry[bufferAry.length] = htmlStr;
		};
		if( bSortIt!=false ){
			bufferAry.sort();
		};
		htmlBuffer  = '<table border="1" cellpadding="2" cellspacing="0">';
		htmlBuffer += bufferAry.join("\n");
		htmlBuffer += '</table>';
		printDebug(htmlBuffer);
	};
}

// wrapper functions
function printObject(obj,bSortIt){
	if( typeof mcmEnableDebugger == "undefined" || mcmEnableDebugger!=true ){
		return;
	};
	printDebugObject(obj,bSortIt);
}

/**
* @function htmlentitites(str)
* @param	string	text containg some html-code
* @return	string	text with html-entities replaced!
* @date		2003-06-23
*/
function htmlentities(str){
	if( typeof str == "undefined" ){
		return;
	};
	var re1 = /</g;
	var re2 = />/g;
	var re3 = /&/g;
	var re4 = /\n/g;
	str = str.replace(re3,'&amp;');
	str = str.replace(re1,'&lt;');
	str = str.replace(re2,'&gt;');
	str = str.replace(re4,'<br>');
	return str;
};
