<!--
// Hier kommen alle Projekt individuellen JS-Funktionen rein.

function individuell()
{	
}

// Spezielle DHTML NaviEffekte, Bsp: O2
// mu? dann nach der mnav im Navi Header included werden
function mnavHandler(menu,level) {
}

function openSearchWindow (url){
	openFreeWindow(
		url,			//url
		'searchPopupFE',	//name
		null,			//mbar
		null,			//sta
		null,			//loc
		'yes',		//tbar
		null,			//res
		1,				//scr
		550,			//width
		520,			//height
		null,			//left
		null			//top
	);
}

function goSearchResult(url) {
	if (needleString !== undefined) {
		url += '&needle=' + needleString;
	}
	top.location.href = url;
}


function matchHeight(){ 
     var divs,contDivs,maxHeight,divHeight,d; 
     // get all <div> elements in the document 
     divs=document.getElementsByTagName('div'); 
     contDivs=[]; 
     // initialize maximum height value 
     maxHeight=0; 

     // iterate over all <div> elements in the document 

     for(var i=0;i<divs.length;i++){ 
          // make collection with <div> elements with class attribute 'container' 
          if(/\bContainer\b/.test(divs[i].className)){ 
                d=divs[i]; 
                contDivs[contDivs.length]=d; 

                // determine height for <div> element 
                if(d.offsetHeight){ 
                     divHeight=d.offsetHeight; 
                } 

                else if(d.style.pixelHeight){ 
                     divHeight=d.style.pixelHeight; 
                } 

                // calculate maximum height 
                maxHeight=Math.max(maxHeight,divHeight); 
          } 

     } 

     
     // assign maximum height value to all of container <div> elements 
	minHeight=600;
     for(var i=0;i<contDivs.length;i++){ 
		  if (maxHeight<minHeight) maxHeight=minHeight; 
		  
          contDivs[i].style.height=maxHeight; 

     } 

} 

// execute function when page loads 

window.onload=function(){ 

     if(document.getElementsByTagName){ 

          matchHeight(); 

     } 

} 

if (typeof Ext != 'undefined') {
	Ext.namespace('dbcjs.customMethods');

	dbcjs.customMethods.wikiLayer = null;
	
	if (!dbcjs.customMethods.vars) {
		dbcjs.customMethods.vars = {};
	}
	
	if (!dbcjs.customMethods.lang) {
		dbcjs.customMethods.lang = {};
	}
	
	if (!dbcjs.lang) {
		dbcjs.lang = {};
	}
	
	dbcjs.customMethods.showWikiLayer = function(wikiId, context) {
		if (!dbcjs.customMethods.vars['wikiListLayerPageUrl']) {
			Ext.MessageBox.alert(dbcjs.lang['information'], dbcjs.customMethods.lang['wikiListLayerPageUrlMissing']);
		} else {
			if (!dbcjs.customMethods.wikiLayer) {
				var config = {
					iframeUrl: dbcjs.customMethods.vars['wikiListLayerPageUrl'],
					title: dbcjs.customMethods.lang['wikiLayerLoading'],
					width: 800,
					height: 600
				};
				dbcjs.customMethods.wikiLayer = new dbcjs.wikiLayer.WikiLayer(config);
			}
			
			dbcjs.customMethods.wikiLayer.show({ wikiId: wikiId });
		}
	}

} else {
	var dbcjs = {};
	dbcjs.customMethods = {};
	dbcjs.customMethods.showWikiLayer = function() {
		alert('Ext is not defined!');
	};
}

function getSearchURL (languageid, dbcsessionid, path, f) {
	if (f == null) {
		var f = document.forms.search;
	}
	var needle = f.needle.value;
	var rule = f.rule.value;
	var ar = f.needle.value.split(" ");
	//var clients = f.elements['client\[\]'];
	var clients = [];
	for (var i = 0; i < f.elements.length; i++) {
		if (f.elements[i].name.match(/client\[[0-9]*\]/gi)) {
			clients[clients.length] = f.elements[i];
		}
		
	}
	var nd = '';
	var con = '';
	var url = '';
	var isSearchPopup = 0;
	if (f.isSearchPopup) {
		isSearchPopup = f.isSearchPopup.value;
	}
	
	// Gucken ob von index.php oder von page.php der Aufruf kommt
	lookFor = document.location.href;
	
	if (lookFor.indexOf('?') >= 0) {
		lookForPath = lookFor.substring(0, lookFor.indexOf('?'));
	} else {
		lookForPath = lookFor;
	}
	var lastChar = lookForPath.substring(lookFor.length - 1 , lookFor.length);
	if (lookFor.indexOf('content_manager') == -1 && 
			(lookFor.indexOf('index.php') > 0
			|| lastChar == '/' // direct call to index document, invisible in path
			)
	) {
		url = './content_manager/';
	} 
	
	if (path) {
		url = path;
	}
	
	if (lookFor.indexOf('content_manager') == -1 && lookFor.indexOf('/go/') > -1) {
		if (path) {
			url = path + '/content_manager/';
		} else {
			url = '../../../../content_manager/';
		}
	}	
	
	needle = needle.replace(/%/g, '*');
	if (needle == '*') {
		nd = "'#ANYWORD#'";
	} else {
		// Verbindung der Suchwörter ermitteln
		if (f.rule.value) con = f.rule.value;
		if (!con) con = "OR";
		
		// Wörter mit Verbindungswort verbinden
		/*
		for (i=0; i<ar.length; i++)
		{
			if ((i+1)<ar.length) nd+="'"+ar[i]+"' "+con+" ";
			else nd+="'"+ar[i]+"'";
		}
		*/
		
		var a = 0;
		var s = '';
		for (i=0; i<ar.length; i++)
		{
			var curWord = ar[i];
			if (curWord.length > 2) {
				nd += s + "'" + curWord + "'";
				s = " " + con + " ";
			}
		}
	}
	
	f.searchString.value = nd;
	url += 'page.php';
	url += '?ID=' + languageid;
	url += '&dbc=' + dbcsessionid;
	url += '&mod=communicate';
	url += '&searchString=' + escape(f.searchString.value);
	url += '&needle=' + escape(needle);
	url += '&rule=' + rule;
	url += '&isSearchPopup=' + isSearchPopup;
	if (f.display && f.display.checked) {
		url += '&display=' + f.display.value;
	}
	
	if (clients != undefined && clients.length > 0) {
		for (var i = 0; i < clients.length; i++) {
			if (clients[i].type == 'hidden' || (clients[i].type == 'checkbox' && clients[i].checked)) {
				url += '&client[]=' + clients[i].value;
			}
		}
	}
	
	return url;
}

var extSearchWin = null;

/* New Ext-Layer Function for the Search-Window */

function openExtSearchWindow(url) {

	extSearchWin = new Ext.Window({
		id: 'dbcjs.searchLayer.window',
		width: 800,
		height: 600,
		modal: true,
		header: false,
		resizable: false,
		layout: 'fit',
		html: '<iframe id="dbcjs.searchLayer.window" frameborder="0" width="100%" style="overflow-x: hidden;" height="100%" src="'+url+'">'
	});
	extSearchWin.show();
	return false;
};

dbcjs.writeSearchValue = function () {
	if (document.location.search.match(/&needle=([^&]*)/)) {
		var searchField = document.location.search.replace(/.*&needle=([^&]*).*/, '$1');
		if (searchField) {
			document.forms.search.needle.value = decodeURI(searchField);
		}
	}
}
//-->
