
/**/



/**/


/**/
var ajax;
var hitlistInfoLoading; // wird aus der Trefferliste befuellt
var hitlistPagesLoading // wird aus der Trefferliste befuellt
var articleInfoLoading; // wird aus der Trefferliste befuellt
var articlePagesLoading // wird aus der Trefferliste befuellt
var sourceTopicId; // fuer showContainedSources
var topicId; // fuer closeSubTopicsBox
var subTopicId; // fuer closeSubTopicsBox
var lastTopicImgObj; // fuer Topic-Icon Highlighting
var lastTopicFolderImgObj; // fuer Topic-Icon Highlighting
var lastSubtopicFolderImgObj; // fuer Topic-Icon Highlighting

var cockpitUpdaterInterval; //Cockpit Refresh Interval
var intervall = 1; //1= Cockpit darf geupdatet werden

String.prototype.trim = function () {
  return this.replace(/^\s+|\s+$/g,'');
};

/**/


/* Funktionen fuer IE-Bug ("Flash-Bug") */
function hideViz(){
	var vizDiv = document.getElementById("visualizationContent");
	if (vizDiv) {
		vizDiv.style.visibility = 'hidden';
	}
}

function showViz(){
	var vizDiv = document.getElementById("visualizationContent");
	if (vizDiv) {
		vizDiv.style.visibility = 'visible';
	}
}

/* laedt die Image-Map */ 


var Map3dUpdater = { 
	imageId: "",
 	vizType: "",
 	isFullZoom: false,

	setVars: function(imageId, vizType, isFullZoom) {
		this.imageId = imageId;
		this.vizType = vizType;
		// optional param:
		if (isFullZoom) {
			this.isFullZoom = true;
		}
		else{
			this.isFullZoom = false;
		}
	},

	runVars: function() {
	  if(this.imageId != "" && this.vizType != ""){
      this.run(this.imageId, this.vizType, this.isFullZoom);
		}
	},
 	
	run: function(imageId, vizType, isFullZoom) {
	
		console.group('Map3dUpdater');
		console.debug('imageId:' + imageId + ' vizType: ' + vizType + " isFullZoom: " +  isFullZoom);
		
		var url = ''; 
		var params = 'task=map&imageId=' + imageId;
		var processMethod = null;
		if (vizType == "clusters") {
			if (isFullZoom) {
				url = '/wissenswelt/restricted/clusters3dFull.htm';
				processMethod = this.processClustersFull;
			} else {
				url = '/wissenswelt/restricted/clusters3d.htm';
				processMethod = this.processClusters;
			}
		} else if (vizType == "timerange") {
			if (isFullZoom) {		
				url = '/wissenswelt/restricted/timerange3dFull.htm';
				processMethod = this.processTimerangeFull;
			} else {
				url = '/wissenswelt/restricted/timerange3d.htm';
				processMethod = this.processTimerange;
			}
		}else if (vizType == "trend") {	
			if(isFullZoom) {
				url = '/wissenswelt/restricted/trend3dFull.htm';
				processMethod = this.processTrendFull;	
			}else{
				url = '/wissenswelt/restricted/trend3d.htm';
				processMethod = this.processTrend;	
			}		
		} else if (vizType == "geo") {	
			if(isFullZoom) {
				url = '/wissenswelt/restricted/geo3dFull.htm';
				processMethod = this.processGeoFull;
			} else {
				url = '/wissenswelt/restricted/geo3d.htm';
				processMethod = this.processGeo;
			}
		}
				
		if (processMethod) {
			console.debug(url + '?' + params);
			ajaxObj.request.add(processMethod, 'GET', url, params, true);
		} else {
			console.error("unknown vizType: " + vizType);
		}
		
		console.groupEnd();		
	}, 

	processClusters: function(pXml, pText) {
		var mapId = 'clustersMap';
		document.getElementById(mapId).innerHTML = pText;
	},

	processClustersFull: function(pXml, pText) {
		var mapId = 'clustersMapFull';
		document.getElementById(mapId).innerHTML = pText;
	},
	
	processTimerange: function(pXml, pText) {
		var mapId = 'timerangeMap';
		document.getElementById(mapId).innerHTML = pText;
	},
	
	processTimerangeFull: function(pXml, pText) {
		var mapId = 'timerangeMapFull';
		document.getElementById(mapId).innerHTML = pText;
	},
	
	processTrend: function(pXml, pText) {
		var mapId = 'trendMap';
		document.getElementById(mapId).innerHTML = pText;
	},
	
	processTrendFull: function(pXml, pText) {
		var mapId = 'trendMapFull';
		document.getElementById(mapId).innerHTML = pText;
	},
	
	processGeo: function(pXml, pText) {
		var mapId = 'geoMap';
		document.getElementById(mapId).innerHTML = pText;
	},
	
	processGeoFull: function(pXml, pText) {
		var mapId = 'geoMapFull';
		document.getElementById(mapId).innerHTML = pText;
	}   
}


var Img3dUpdater = { 

	imageId: "", 
	vizType: "",
	isFullZoom: false,
	
	setVars: function(imageId, vizType, isFullZoom) {
		this.imageId = imageId;
		this.vizType = vizType;
		// optional param:
		if (isFullZoom) {
			this.isFullZoom = true;
		}
		else{
			this.isFullZoom = false;
		}
	},

	// noch extra fuer die viz, wenn full ist und dann gewechselt wird.
    setFullZoomVars: function(isFullZoom) {
            this.isFullZoom = isFullZoom;
    },

	runVars: function(imageId, vizType, isFullZoom) {
		if(this.imageId != "" && this.vizType != ""){
	      this.run(this.imageId, this.vizType, this.isFullZoom);
	    }
	},

	run: function() {
		console.group('Image3dUpdater');
		console.debug('imageId:' + this.imageId + ' vizType: ' + this.vizType + " isFullZoom: " +  this.isFullZoom);
		var imgObj;
		var imgSrc;
		
		if (this.vizType == 'clusters') {
			if (this.isFullZoom) {
				imgObj = document.getElementById('3dImageClustersFull');
				imgSrc = '/wissenswelt/restricted/clusters3dFull.htm?';
			} else {
				imgObj = document.getElementById('3dImageClusters');
				imgSrc = '/wissenswelt/restricted/clusters3d.htm?';
			}
		} else if (this.vizType == "timerange") {
			if (this.isFullZoom) {
				imgObj = document.getElementById('3dImageTimeRangeFull');
		 		imgSrc = '/wissenswelt/restricted/timerange3dFull.htm?';
			} else {
				imgObj = document.getElementById('3dImageTimeRange');
		 		imgSrc = '/wissenswelt/restricted/timerange3d.htm?';
			}
		}
		else if (this.vizType == "trend") {	
			if(this.isFullZoom) {
				imgObj = document.getElementById('3dImageTrendFull');
				imgSrc = '/wissenswelt/restricted/trend3dFull.htm?';
			}else{
				imgObj = document.getElementById('3dImageTrend');
				imgSrc = '/wissenswelt/restricted/trend3d.htm?';
			}		
		} else if (this.vizType == "geo") {	
			if(this.isFullZoom) {
				imgObj = document.getElementById('3dImageGeoFull');
				imgSrc = '/wissenswelt/restricted/geo3dFull.htm?';
			} else {
				imgObj = document.getElementById('3dImageGeo');					
				imgSrc = '/wissenswelt/restricted/geo3d.htm?';
			}
		}
		//bild aufrufen und austauschen
		if(imgObj){
    		if(imgObj.src){
                imgObj.src = imgSrc + 'imageId=' + this.imageId;
		    }
        }
		console.groupEnd();
	}
}

var Selector3d = {

	run: function(imageId, index, vizType) {
		
		console.group("Selector3d.run");
		console.debug("imageId " + imageId + "index" + index + " vizType: " + vizType);
		if(index == ""){
			return;
		}
		var form = null;
		if (vizType == 'clusters') {
			if (window.visualizationZoom) {
				form = document.Clusters3dFullForm;
			} else {
				form = document.Clusters3dForm;
			}
		} else if (vizType == "trend") {
			if (window.visualizationZoom) {	
				form = document.Trend3dFullForm;
			} else {
				form = document.Trend3dForm;
			}		
		} else if (vizType == "geo") {	
			if (window.visualizationZoom) {	
				form = document.Geo3dFullForm;
			} else {
				form = document.Geo3dForm;
			}
		}
		else {
			if (window.visualizationZoom) {
				form = document.TimeRange3dFullForm;
			} else {
				form = document.TimeRange3dForm;
			}
		}
		console.debug("form: " + form.name);

		form.task.value = 'select';
		form.imageId.value = imageId;
		form.index.value = index;
		form.submit();
		
		console.groupEnd();
		
	}
}

var visualization3dManager = { 

	setType: function(vizType) {

		window.visualizationType = vizType + "3d";

		// in animations.js:
		updateVisualizationButtons(vizType);
		
		var url  = '/wissenswelt/restricted/search.htm';
		var params = 'task=setCurrentVizType&currentVizType=' + window.visualizationType;
		ajaxObj.request.add(this.processSetType, 'GET', url, params, true);
	},
	
	setZoom: function(vizZoom) {

		window.visualizationZoom = vizZoom; // Boolean
		var vizZoomString = "false";
		if (window.visualizationZoom) {
			vizZoomString = "true";
		}
		
		var url  = '/wissenswelt/restricted/search.htm';
		var params = 'task=setCurrentVizZoom&currentVizZoom=' + vizZoomString;
		ajaxObj.request.add(this.processSetZoom, 'GET', url, params, true);
	},
	
	setZoomTA: function(vizZoom) {

		window.visualizationZoom = vizZoom; // Boolean
		var vizZoomString = "false";
		if (window.visualizationZoom) {
			vizZoomString = "true";
		}
		
		var url  = '/wissenswelt/restricted/ta_question.htm';
		var params = 'task=setCurrentVizZoom&currentVizZoom=' + vizZoomString;
		ajaxObj.request.add(this.processSetZoom, 'GET', url, params, true);
	},
	
	processSetType: function(pXml, pText) {
		var vizZoomString = "false";
		if (window.visualizationZoom) {
			vizZoomString = "true";
		}
		console.debug("visualization3dManager.processSetType(): " + vizZoomString);
	},
	
	processSetZoom: function(pXml, pText) {
		var vizZoomString = "false";
		if (window.visualizationZoom) {
			vizZoomString = "true";
		}
		console.debug("visualization3dManager.processSetZoom(): " + vizZoomString);
	}
}

/*
 * Holt eine Cockpit-Seite
 */
function fetchCockpitPage(type, tabAction) {

    intervall = 0;
    clearInterval(cockpitUpdaterInterval);
    
	var urlContent = document.CockpitForm.action + "?task=changeCockpitTab&tabToBeSet=" + type;
	var urlTabs    = tabAction;	
	
	var content = getAjaxResponseSynchron(urlContent);	
	document.getElementById("cockpitContent").innerHTML = content;
	
	// "doppelt", weil das via AJAX eingefuegte JS nicht ausgefuehrt 
	// wird! (wirkt nur beim direkten insert)
	intervall = 1;
	cockpitTabsUpdater.run();
}

/**/ 
var cockpitUpdater = { 

	run: function() {
	    var url  = '/wissenswelt/cockpit.htm';
		var params = "isAjaxCall=true";
		if(intervall == 1){
		    ajaxObj.request.add(this.process, 'GET', url, params, true);
		}
	}, 

	process: function(pXml, pText) {
		var divId = 'cockpitContent';
		document.getElementById(divId).innerHTML = pText;
	} 
}
/**/ 
var cockpitTabsUpdater = { 
	run: function() {
		var url  = '/wissenswelt/cockpitTabs.htm';
		var params = null;
		if(intervall ==1){
		    ajaxObj.request.add(this.process, 'GET', url, params, true);
		}
	}, 

	process: function(pXml, pText) {
		var divId = 'cockpitTabs';
		document.getElementById(divId).innerHTML = pText;
	} 
}

var searchSourceRefresh = { 
	run: function() {
		var tab = 'all';
		var url  = '/wissenswelt/restricted/search.htm';
		var params = 'task=changeTabSources&sourceTabToSet=' + tab;
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	}, 

	process: function(pXml, pText) {
		var topicsDivId = 'searchSourcesTopicsWrapper';
		document.getElementById(topicsDivId).innerHTML = pText;
	} 
}

/**/ 
var favoritesManager = { 
	
	popupDivId: 'mainPopup',
	topicsDivId: 'searchSourcesTopicsWrapper',
	
	create: function(favName) {
		var url  = '/wissenswelt/restricted/search.htm';
		var params = 'task=saveAsFavorite';
		params += '&favoriteNameToSet=' + encodeURIComponent(favName);
		ajaxObj.request.add(this.process, 'GET', url, params, true);
		if (document.forms.SaveFavoriteForm.favoriteNameToSet.value != '') window.setTimeout('favoritesManager.hidePopup()', 2000);;
	}, 

	remove: function(favId) {
		var url  = '/wissenswelt/restricted/search.htm';
		var params = 'task=deleteFavorite';
		params += '&favoriteIdToSet=' + encodeURIComponent(favId);
		ajaxObj.request.add(this.process, 'GET', url, params, true);
		window.setTimeout('favoritesManager.hidePopup()', 2000);
	}, 

	process: function(pXml, pText) {
		searchSourceRefresh.run();
		var popupDiv = document.getElementById(favoritesManager.popupDivId);
		popupDiv.style.display = 'block';
		popupDiv.style.visibility = 'visible';
		popupDiv.style.width = '250px';
		popupDiv.style.height = '60px';
		popupDiv.style.left = '500px';
		popupDiv.style.top = '330px';
		popupDiv.innerHTML = pText;
	},
	
	processRemove: function(pXml, pText) {
		var topicsDiv = document.getElementById(favoritesManager.topicsDivId);
		topicsDiv.innerHTML = pText;
	},
	
	showPopup: function(pXml, pText) {
		var url  = '/wissenswelt/restricted/searchSaveFavorite.htm';
		var params = null;
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	},
	
	hidePopup: function(pXml, pText) {
		var popupDiv = document.getElementById(favoritesManager.popupDivId);
		popupDiv.innerHTML = '';
		popupDiv.style.display = 'none';
		popupDiv.style.visibility = 'hidden';
	}
}



/**/ 
var searchFieldsUpdater = { 

	run: function() {
		var url  = '/wissenswelt/restricted/search.htm?task=updateFields';
		var params = null;
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	}, 

	process: function(pXml, pText) {
		var divId = 'searchFieldsBox';
		document.getElementById(divId).innerHTML = pText;
		evalInnerScripts(divId);
		//doResizesWrapper();
	} 
}

/*
    Die folgenden Werte sind applikationsweit in index.jsp definiert: 
    - height
    - width
    - widthOfButton
    - widthOfDelimiter
    - showDescriptions
    - magneticZone
    Da sie auch im zentralen CSS zur Groessenberechnung verwendet werden,
    koennen sie NICHT pro Einbettung veraendert werden.
    Einbettungsspezifisch definierbar sind:
    - useTokenSelectPopup (true|false)
    - units (day|minute)
*/ 
var timeslideUpdater = { 

	run: function() {
		var url  = '/wissenswelt/restricted/timeslide.htm?action=&height=17&width=418&widthOfDelimiter=8&widthOfButton=18&showDescriptions=true&magneticZone=15&useTokenSelectPopup=true&units=day';
		var params = null;
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	}, 

	process: function(pXml, pText) {
	
		var divId = 'timeSlideContainer';
		try {
			document.getElementById(divId).innerHTML = pText;
			timeSelector = null;
			evalInnerScripts(divId);
			initTimeSelector();
		} catch(e) {
			//
		}

	} 
}

/**/ 
var articleInfoLoader = { 

	showPopup: function(idx, callFromClipboard) {
		
		var url  = '/wissenswelt/restricted/article.htm';
        var params = 'task=showInfo&indexToSet=' + idx + '&callFromClipboard='+ callFromClipboard;
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	}, 
	
	process: function(pXml, pText) {
				
		var popupDiv = document.getElementById("mainPopup");
		popupDiv.style.width = 400 + "px";
	    popupDiv.style.height = 400 + "px";    
		popupDiv.style.display = "block";	
		popupDiv.style.overflow = "auto";
		popupDiv.style.visibility = "visible";			
		popupDiv.innerHTML = pText;
	},
	
	closePopup: function() {
		var popupDiv = document.getElementById("mainPopup");
		popupDiv.innerHTML = '<!-- emptied -->';
		popupDiv.style.visibility = "hidden";
		popupDiv.style.display = "none";
	}
}

/**/ 
var articleRatingLoader = { 

	showRatingPopup: function(idx, callFromClipboard) {
		
		var url  = '/wissenswelt/restricted/article.htm';
        var params = 'task=showRating&indexToSet=' + idx + '&callFromClipboard='+ callFromClipboard;
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	}, 

	process: function(pXml, pText) {
				
		var popupDiv = document.getElementById("mainPopup");
		popupDiv.style.width = 400 + "px";
	    popupDiv.style.height = 400 + "px";    
		popupDiv.style.display = "block";	
		popupDiv.style.overflow = "auto";
		popupDiv.style.visibility = "visible";			
		popupDiv.innerHTML = pText;
	},
	
	closePopup: function() {
		var popupDiv = document.getElementById("mainPopup");
		popupDiv.innerHTML = '<!-- emptied -->';
		popupDiv.style.visibility = "hidden";
		popupDiv.style.display = "none";
	}
}

/**/ 
var clipboardHitlistLoader = { 

	run: function() {
		var url  = '/wissenswelt/restricted/clipboard.htm';
		var params = 'task=showHitlist';
		
		var loadingTxt = '';
		var divId = 'clipboardHitlist';
		var div = document.getElementById(divId);
		// im Clipboard-Volltext gibts keine Liste:
		if (div) {	
			div.innerHTML = loadingTxt;
		}
		
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	}, 

	process: function(pXml, pText) {
		var divId = 'clipboardHitlist';
		var div = document.getElementById(divId);
		// im Clipboard-Volltext gibts keine Liste:
		if (div) {	
			document.getElementById(divId).innerHTML = pText;
		}
		updateClipboardInfoBox();
	} 
}

/**/ 
var printLoader = { 

	showPrintPopup: function() {
		
		var url  = '/wissenswelt/restricted/ta_question.htm';
        var params = 'task=showPrintDialog';
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	}, 

	process: function(pXml, pText) {
				
		var popupDiv = document.getElementById("mainPopup");
		popupDiv.style.width = 400 + "px";
	    popupDiv.style.height = 400 + "px";    
		popupDiv.style.top = 100 + "px";
		popupDiv.style.left = 100 + "px";
		popupDiv.style.display = "block";	
		popupDiv.style.overflow = "auto";
		popupDiv.style.visibility = "visible";			
		popupDiv.innerHTML = pText;
	},
	
	closePopup: function() {
		var popupDiv = document.getElementById("mainPopup");
		popupDiv.innerHTML = '<!-- emptied -->';
		popupDiv.style.visibility = "hidden";
		popupDiv.style.display = "none";
	}
}
/**/ 
var printArticleLoader = { 

	showPrintArticlePopup: function(index) {
		var url  = '/wissenswelt/restricted/article.htm';
        var params = 'task=showPrintDialog&indexToSet=' + index;
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	}, 

	process: function(pXml, pText) {
				
		var popupDiv = document.getElementById("mainPopup");
		popupDiv.style.width = 400 + "px";
	    popupDiv.style.height = 400 + "px";    
		popupDiv.style.top = 100 + "px";
		popupDiv.style.left = 100 + "px";
		popupDiv.style.display = "block";	
		popupDiv.style.overflow = "auto";
		popupDiv.style.visibility = "visible";			
		popupDiv.innerHTML = pText;
	},
	
	closePopup: function() {
		var popupDiv = document.getElementById("mainPopup");
		popupDiv.innerHTML = '<!-- emptied -->';
		popupDiv.style.visibility = "hidden";
		popupDiv.style.display = "none";
	}
}


/**/ 


var hitlistPrinter = { 
	
	getCheckboxes: function() {
		return document.getElementsByName('indexesToProcess');
	},
	
	checkAll: function(checked)	{
		var checkboxes = this.getCheckboxes();
		if (checkboxes) {
			var selurl = "";
			if(checked == true){
				selurl = "/wissenswelt/restricted/hitlist.htm?task=selectArticle";
			}
			else{
				selurl = "/wissenswelt/restricted/hitlist.htm?task=deselectArticle";
			}
			for (var i = 0; i < checkboxes.length; i++) {
				checkboxes[i].checked = checked;
				selurl = selurl + "&indexesToSelect=" + checkboxes[i].value;
			}
			doAjaxRequest(selurl, processNothingToDo);
		}
		return checkboxes;
	},	
	
	selectArticle: function(elem){
		var selurl = "";
		if(elem.checked == true){
			selurl = "/wissenswelt/restricted/hitlist.htm?task=selectArticle" + "&indexesToSelect=" + elem.value;
		}
		else{
			selurl = "/wissenswelt/restricted/hitlist.htm?task=deselectArticle" + "&indexesToSelect=" + elem.value;
		}
		doAjaxRequest(selurl, processNothingToDo);
	},

	isCheckedPresent: function() {
		var checkedPresent = false;
		var checkboxes = this.getCheckboxes();
		if (checkboxes) {
			for (var i = 0; i < checkboxes.length; i++) {
				if (checkboxes[i].checked) {
					checkedPresent = true;
				}
			}
		}
		return checkedPresent;
	},
	
	run: function() {
		document.HitListForm.task.value = 'print';
		document.HitListForm.submit();
	} 
}

function processNothingToDo(){
	//nothing to do
}

/**/ 
var articlePrinter = { 
	
	run: function() {
		var originalTask = document.ArticleForm.task.value;
		document.ArticleForm.task.value = 'print';
		
		/* 
			Anti IE submit() Bug via setTimeout() (Stephan)
			
			Da submit() dann in einem eigenen Thread rennt, wuerde die folgende 
			Zeile evtl. zu frueh ausgefuehrt (Race Condition); darum beides in einem
			setTimeout()-Call.
			
		*/
		window.setTimeout('document.ArticleForm.submit(); ' +
           ' document.ArticleForm.task.value = "' + originalTask + '";', 10);

	}
}

/**/ 
var clipboardArticleSaver = { 

	run: function(articleId) {
		var url  = '/wissenswelt/restricted/article.htm';
		var params = 'task=addToClipboard';
		params += '&indexToSet=' + articleId;
		params += '&popup=true';
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	}, 

	process: function(pXml, pText) {
		document.getElementById('clipboardSuccess').innerHTML = 'Artikel wurde zur Ablage hinzugefügt<br><br>';
		window.setTimeout('clipboardArticleSaver.hidePopup()', 2000);
	},
	
	showPopup: function(width, height, topOffset, leftOffset) {

		var url  = '/wissenswelt/restricted/clipboard.htm';		
		var params = 'task=showPage';
		params += '&popup=true';
		ajaxObj.request.add(this.processShowPopup, 'GET', url, params, true);
				
		var popupDiv = document.getElementById("mainPopup");
        popupDiv.style.width = width + "px";
	    popupDiv.style.height = height + "px";    
		popupDiv.style.top = topOffset + "px";
		popupDiv.style.left = leftOffset + "px";
		popupDiv.style.display = "block";	
		popupDiv.style.overflow = "auto";
		popupDiv.style.visibility = "visible";
	},
	
	processShowPopup: function(pXml, pText) {

		var popupDiv = document.getElementById("mainPopup");	
		popupDiv.innerHTML = pText;
		
		clipboardArticleSaver.fillPopup();	
		
	},

	hidePopup: function() {
		var popupDiv = document.getElementById("mainPopup");
		popupDiv.innerHTML = '<!-- emptied -->';
		popupDiv.style.visibility = "hidden";
		popupDiv.style.display = "none";
	},
	
	fillPopup: function() {

		var url  = '/wissenswelt/restricted/clipboard.htm';		
		var params = 'task=showClipboards';
		params += '&popup=true';
		ajaxObj.request.add(this.processFillPopup, 'GET', url, params, true);

	},

	processFillPopup: function(pXml, pText) {

		var adminDiv = document.getElementById("clipboardAdminBox");	
		adminDiv.innerHTML = pText;		
		
	}
	
}

/**/ 
var clipboardArticleMover = { 
	
	currentClipboardId: false,
	
	run: function() {
	
		var url  = '/wissenswelt/restricted/hitlist.htm';
		var params = 'task=moveArticles&callFromClipboard=true';
	
		var checkBoxes = document.getElementsByName('indexesToProcess');
		var checkedPresent = false;

		if (checkBoxes) {
			for (var i = 0; i < checkBoxes.length; i++) {
				if (checkBoxes[i].checked) {
					checkedPresent = true;
					params += '&indexesToProcess=' + checkBoxes[i].value;					
				}
			}		
		}

		if (checkedPresent == false) {	
			alert('Es wurde kein Artikel selektiert');
		} else {
			if (confirm('Sollen die Artikel wirklich verschoben werden?')) {
				ajaxObj.request.add(this.process, 'GET', url, params, true);
			}
		} 
		
	},
	
	setTarget: function(clipboardId) {
		
		/* 
			nur ausfuehren, wenn wirklich geaendert wird
			(quasi onClick->onChange)
		*/
		if (clipboardId != this.currentClipboardId) {
			this.currentClipboardId = clipboardId;
			var url  = '/wissenswelt/restricted/clipboard.htm';
			var params = 'task=setActiveClipboardToMove';
			params += '&clipboardIdToSet=' + encodeURIComponent(clipboardId);
			ajaxObj.request.add(this.processSetTarget, 'GET', url, params, true);
		} else {
			console.log("clipboardArticleMover.setTarget() idle...");
		}

	}, 

	process: function(pXml, pText) {
		alert('Artikel wurde(n) verschoben');
		/**/
		submitLink('ClipboardForm', 'showPage');
	},
	
	processSetTarget: function(pXml, pText) {
		//nix;
	} 
}

/**/ 
var clipboardArticleRemover = { 

	run: function(articleId) {
	
		if (confirm('Soll der Artikel wirklich entfernt werden?')) {
	
			var url  = '/wissenswelt/restricted/article.htm';
			var params = 'task=removeFromClipboard&callFromClipboard=true';
			params += '&indexToSet=' + articleId;
			ajaxObj.request.add(this.process, 'GET', url, params, true);
		}
		
	}, 

	runList: function() {
	
		var url  = '/wissenswelt/restricted/hitlist.htm';
		var params = 'task=removeFromClipboard&callFromClipboard=true';
	
		var checkBoxes = document.getElementsByName('indexesToProcess');
		var checkedPresent = false;

		if (checkBoxes) {
			for (var i = 0; i < checkBoxes.length; i++) {
				if (checkBoxes[i].checked) {
					checkedPresent = true;
					params += '&indexesToProcess=' + checkBoxes[i].value;					
				}
			}		
		}
	
		if (checkedPresent == false) {	
			alert('Es wurde kein Artikel selektiert');
		} else {
			if (confirm('Sollen die Artikel wirklich entfernt werden?')) {
				ajaxObj.request.add(this.process, 'GET', url, params, true);
			}
		} 
		
	}, 

	process: function(pXml, pText) {
		
		alert('Artikel wurde(n) entfernt');
		
		/**/
		submitLink('ClipboardForm', 'showPage');
	} 
}

/**/ 
var clipboardChanger = { 

	open: function(clipboardId, updateList, isPopup) {
		var url  = '/wissenswelt/restricted/clipboard.htm';
		var params = 'task=changeClipboard';
		params += '&clipboardIdToSet=' + clipboardId;
		params += '&popup=' + isPopup;

		if (updateList) {
			document.getElementById("clipboardInfoBox").innerHTML = '';	
			document.getElementById("clipboardDropdownBox").style.visibility = 'hidden';	
			ajaxObj.request.add(this.processWithList, 'POST', url, params, true);
		} else {
			ajaxObj.request.add(this.process, 'POST', url, params, true);
		}

	}, 

	create: function(clipboardName, updateList, isPopup) {
		
		if (clipboardName && clipboardName.length > 0) {
		
			var url  = '/wissenswelt/restricted/clipboard.htm';
			var params = 'task=newClipboard';
			params += '&clipboardNameToSet=' + clipboardName;
			params += '&popup=' + isPopup;
			
			if (updateList) {
				ajaxObj.request.add(this.processWithList, 'POST', url, params, true);
			} else {
				ajaxObj.request.add(this.process, 'POST', url, params, true);
			}

		} else {
			alert('Es wurde kein Name für die Ablage angegeben');
		}
	},
	
	remove: function(clipboardId, updateList, isPopup) {
	
		if (confirm('Soll die Ablage wirklich gelöscht werden?')) {
			var url  = '/wissenswelt/restricted/clipboard.htm';
			var params = 'task=removeClipboard';
			params += '&clipboardIdToSet=' + clipboardId;
			params += '&popup=' + isPopup;
	
			if (updateList) {
				ajaxObj.request.add(clipboardChanger.processWithList, 'POST', url, params, true);
			} else {
				ajaxObj.request.add(clipboardChanger.process, 'POST', url, params, true);
			}
		}
	},

	process: function(pXml, pText) {
		clipboardChanger.updateAdminBox(pText);
	},
	
	processWithList: function(pXml, pText) {

		/**/
		clipboardHitlistLoader.run();
		
		clipboardChanger.updateAdminBox(pText);
	},
	
	updateAdminBox: function(pText) {
		var divId = 'clipboardAdminBox';
		document.getElementById(divId).innerHTML = pText;
		//doResizesWrapper();
	} 
}

/**/ 
var loginPopupLoader = { 

	showEmpty: function(url) {
		var params = '';
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	}, 

	process: function(pXml, pText) {
				
		var popupDiv = document.getElementById("mainPopup");
		
		popupDiv.style.width = 300 + "px";
	  popupDiv.style.height = 100 + "px";    
		popupDiv.style.top = 280 + "px";
		popupDiv.style.left = 200 + "px";
		
		popupDiv.style.display = "block";	
		popupDiv.style.overflow = "auto";
		popupDiv.style.visibility = "visible";		
		
		popupDiv.innerHTML = pText;
		if ($('#homeSearchbutton').hasClass('clicked')) $('#loginAddInfo').html('');
		else $('#loginAddInfo').html('<p>Nach dem Einloggen recherchieren Sie nach dem ausgewählten Begriff. Die Trefferliste dafür kostet € 1,-. Wollen Sie einloggen ohne eine Recherche zu aktivieren, dann löschen Sie den Suchbegriff aus der Suchzeile.</p>');
	},
	
	close: function() {
	
		var popupDiv = document.getElementById("mainPopup");
		popupDiv.innerHTML = '<!-- emptied -->';
		popupDiv.style.visibility = "hidden";
		popupDiv.style.display = "none";
		
	}
}

function evalInnerScripts(divId) {

	var div = document.getElementById(divId);
	//alert(div.id);
	var scripts = document.getElementsByTagName('script');
	
	for (var i = 0; i < scripts.length; i++) {
	
		var isChild = false;
		var parent = scripts[i].parentNode;
		while (parent) {
			if (parent == div) {
				isChild = true;
			}
			parent = parent.parentNode;
		}
		
		if (isChild) {
			/*
			alert(i + "/" + scripts.length + " " + div.id + ": " 
				+ scripts[i].text);
			*/
			eval(scripts[i].text);
		} else {
			/*
			alert(i + "/" + scripts.length + " no: " + scripts[i].parentNode.id 
				+ " " + scripts[i].text);
			*/
		}
	}
}

/**/

/**/

/**/
function doAjaxRequest(url, ajaxfunction) {
	try {
		ajax = new XMLHttpRequest();
	} catch (w3c) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(msie) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(msie_alt) {
				return false;
			}
		}
	}
	ajax.onreadystatechange = ajaxfunction;
	ajax.open("GET", url, true);
	ajax.send(null);
}

/* 
 * holt einen AJAX-ResponseText (synchron) 
 * damit man mehrere hintereinander ausfuehren kann 
 */
function getAjaxResponseSynchron(url) {
	try {
		ajax = new XMLHttpRequest();
	} catch (w3c) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(msie) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(msie_alt) {
				return false;
			}
		}
	}
	ajax.open("GET", url, false);
	ajax.send(null);
	return ajax.responseText;
}





/*
	Laedt bei Bedarf die aktuell geforderte Visualisierung
	(Erkennung an enthaltenem "map")
*/
function loadVisualization3d() {

	var updateBox = getVisualizationUpdateBox3d();
	
	console.group("loadVisualization3d()");
	console.debug(updateBox.id);

	if (!updateBox.innerHTML.match(/map/i)) { // IE6 konvertiert Tags zu Uppercase!
		console.debug("load!");
		doAjaxRequest(getVisualizationAction3d(), processLoadVisualization3d);
	} else {
		console.debug("already loaded!");
	}
	console.groupEnd();
}

/*
	Verarbeitet die per AJAX geholte Visualisierung
*/
function processLoadVisualization3d() {
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response
			
			var updateBox = getVisualizationUpdateBox3d();
			updateBox.innerHTML = ajax.responseText;
			evalInnerScripts(updateBox.id);
			
			Img3dUpdater.runVars();
			Map3dUpdater.runVars();
		} 
	}
}

/*
	Ermittelt die 3dViz-Action abhaengig von 
	window.visualizationType und window.visualizationZoom
*/
function getVisualizationAction3d() {

	var action;
	
	if (window.visualizationType == "clusters3d") {
		if (window.visualizationZoom == true) {
			action = '/wissenswelt/restricted/clusters3dFull.htm?task=tag';
		} else {
			action = '/wissenswelt/restricted/clusters3d.htm?task=tag';
		}
	} else if (window.visualizationType == "timerange3d"){
		if (window.visualizationZoom == true) {	
			action = '/wissenswelt/restricted/timerange3dFull.htm?task=tag';
		} else {
			action = '/wissenswelt/restricted/timerange3d.htm?task=tag';
		}
	} else if (window.visualizationType == "GEO"){
		if (window.visualizationZoom == true) {	
			action = '/wissenswelt/restricted/geo3dFull.htm?task=tag';
		} else {
			action = '/wissenswelt/restricted/geo3d.htm?task=tag';
		}
	} else {
		if (window.visualizationZoom == true) {	
			action = '/wissenswelt/restricted/trend3dFull.htm?task=tag';
		} else {
			action = '/wissenswelt/restricted/trend3d.htm?task=tag';
		}
	}
	
	console.debug("getVisualizationAction3d(): " 
		+ window.visualizationType + " " + window.visualizationZoom + " " + action);
	return action;
}

function getVisualizationUpdateBox3d() {

	var updateBox;
	var fullSuffix = "";
	
	// Zoom: Wenn true, die "Full"-Boxen nehmen
	if (window.visualizationZoom) {
		fullSuffix = "Full";
	}
	
	if (window.window.visualizationType == "clusters3d") {
		updateBox = document.getElementById("visualizationClusters" + fullSuffix);
	} else if (window.window.visualizationType == "timerange3d"){
		updateBox = document.getElementById("visualizationTimerange" + fullSuffix);
	} else {
		updateBox = document.getElementById("visualizationTA" + fullSuffix);
	}
	return updateBox;
}

/*
	zwischen Clusters und Zeitverteilung umschalten
*/
function toggleVisualization() {

	var clustersBox = document.getElementById("visualizationClusters");
	var timerangeBox = document.getElementById("visualizationTimerange");

	var action = false;
	
	// anhand der aktuellen Sichtbarkeit die anzuzeigende Box ermitteln:	
	if (clustersBox.style.display == 'none') {

		// Sichtbarkeit switchen
		clustersBox.style.display = 'block';
		timerangeBox.style.display = 'none';
		
		// schon befuellt? dann nicht nochmal laden
		if (!clustersBox.innerHTML) {
			// Clusters laden
			action = document.ClustersForm.action;
		}

	} else {

		// Sichtbarkeit switchen
		clustersBox.style.display = 'none';
		timerangeBox.style.display = 'block';
		
		// schon befuellt? dann nicht nochmal laden
		if (!timerangeBox.innerHTML) {
			// Zeitverteilung laden
			action = document.TimeRangeForm.action;
		}
	}
	
	if (action) {
		doAjaxRequest(action, processToggleVisualization);
	}
}
function processToggleVisualization() {
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response
			
			var updateBox = getVisualizationUpdateBox();
			eval(ajax.responseText);

		} 
	}
}

function getVisualizationUpdateBox() {

	var updateBox;

	// anhand der (neuen) aktuellen Sichtbarkeit die zu fuellende Box ermitteln:	
	var clustersBox = document.getElementById("visualizationClusters")
	if (clustersBox.style.display == 'block') {
		updateBox = clustersBox;
	} else {
		updateBox = document.getElementById("visualizationTimerange");
	}
	
	return updateBox;
}

function checkLiquidity(){
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response
			if(ajax.responseText != 'OK'){
				alert('Ihr Guthaben reicht für diesen Vorgang leider nicht aus.');
			}
			else{
				var attNewWindow = document.getElementById("attNewWindow");
				var attUrl = document.getElementById("attPlainUrl").innerHTML;
				attUrl += "?aid="+document.getElementById("attAid").innerHTML;
				attUrl += "&articleSourceToken=" + document.getElementById("articleSourceToken").innerHTML;
				attUrl += "&articleSourceDescription=" + document.getElementById("articleSourceDescription").innerHTML;
				attUrl += "&articleKey=" + document.getElementById("articleKey").innerHTML;
				attUrl += "&articleTitle=" + document.getElementById("articleTitle").innerHTML;
				window.open(attUrl, "defactoAtt");
			}			
		} 
	}
}

/*
 * Blaettert zur angegebenen Seite der Trefferliste
 */
function gotoHitlistPage(page) {
	document.getElementById("hitlistPagesBox").innerHTML = hitlistPagesLoading;	
	var action = document.HitListForm.action + "?task=changeCurrentPage&showHitlistEmbedded=true&currentPageToSet=" + page;
	//alert(action);
	doAjaxRequest(action, processGotoHitlistPage);
}
function processGotoHitlistPage() {
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response
			
			var divId = "flexBody";
			document.getElementById(divId).innerHTML = ajax.responseText;
			
			// die neuen Werte fuer Treffer, Seiten, Blaettern...
			evalInnerScripts(divId);
		} 
		else if (ajax.status == 401) {
			window.location.href='/wissenswelt/home.htm';		
	}
}
}

/*
 * Blaettert zum angegebenen Volltext
 */
function gotoArticle(idx, extraParams) {
	// document.getElementById("hitlistInfoBox").innerHTML = hitlistInfoLoading; // eher nicht noetig
	document.getElementById("articlePagesBox").innerHTML = articlePagesLoading;	
	
	var action = document.ArticleForm.action;
	action += "?task=changeArticle&indexToSet=" + idx;
	if (extraParams) {
		action += "&" + extraParams;
	}
	
	//alert(action);
	doAjaxRequest(action, processGotoArticle);
}

// die neuen aehnlichen Artikel werden im rechten Fenster aktualisiert
function processLoadSimilarArticles(){
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response
			document.getElementById("similarArticlesContainer").innerHTML = ajax.responseText;
		}
    }
}

function processGotoArticle() {
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response
			document.getElementById("flexBody").innerHTML = ajax.responseText;
			evalInnerScripts("flexBody");
			cockpitUpdater.run(); // Cockpit refreshen (Dokumente werden raufgezaehlt)
			// Wenn man sich in der SearchEngine befindet, muessen auch die aehnlichen Artikel
			// auf der rechten Seite geladen werden.
			//cockpitTabsUpdater.run();
			if(document.getElementById("similarArticlesContainer")){
				// Falls das Container Element vorhanden ist, wird der Task in der HitListAction aufgerufen
				// und der Request abgesetzt
				var actionLoadSimilarArticles = document.ArticleForm.action;
				actionLoadSimilarArticles += "?task=loadSimilarArticles&indexToSet=" + document.ArticleForm.indexToSet.value;
				doAjaxRequest(actionLoadSimilarArticles, processLoadSimilarArticles);
			}
		} 
		else if (ajax.status == 401) {
			window.location.href='/wissenswelt/home.htm';		
	    }
    }
}


/* Das Info-Popup zu einem Treffer aus der Trefferliste */
function showInfoPopup(idx, callFromClipboard) {
        articleInfoLoader.showPopup(idx, callFromClipboard);
}

/* Das Bewertungs-Popup zu einem Treffer aus der Trefferliste */
function showRatingPopup(idx, callFromClipboard) {
        articleRatingLoader.showRatingPopup(idx, callFromClipboard);
}

/* Das Report drucken-Popup aus der Trendanalyse*/
function showPrintPopup() {
        printLoader.showPrintPopup();
}

/* Das Popup mit den Quellen aus der Trefferliste (Info-Box) */
function showSelectedSourcesPopup() {

	var sources = document.getElementById("hitlistSourcesTemp").innerHTML;
	var topPos = 100;
	// todo:
	
	/* 
	"hitlistSelectedSourcesCount" ist die SPAN mit der verlinkten Anzahl 
	der Quellen; das Popup wird direkt darunter positioniert
	*/
	var anchorElement = document.getElementById("hitlistSelectedSourcesCount");
	var topOffset = getTopOffset(anchorElement);
	topOffset += anchorElement.offsetHeight;
	var leftOffset = getLeftOffset(anchorElement);
	
	var popupDiv = document.getElementById("mainPopup");
	
	// einschalten, damit clientHeight bestimmt werden kann; 
	// visibility bleibt erstmal hidden
	popupDiv.style.display = "block";	
	popupDiv.style.width = "400px";

	// Inhalt laden -> height wird erzeugt...
	popupDiv.innerHTML = sources;
	// ... und bei Bedarf gedeckelt
	if (popupDiv.offsetHeight > 300) {
		popupDiv.style.height = "300px";
		popupDiv.style.overflow = "auto";
	}
	
	popupDiv.style.top = topOffset + "px";
	popupDiv.style.left = leftOffset + "px";
	
	popupDiv.style.visibility = "visible";	

}
function hideSelectedSourcesPopup() {
	var popupDiv = document.getElementById("mainPopup");
	popupDiv.style.visibility = "hidden";
	popupDiv.style.display = "none";
	
}

function gotoSearchForm() {
	var url = '/wissenswelt/restricted/search.htm?task=showForm';
	document.location.href = url;
}

function showContainedSources(selectedTopicId) {

	// definiert, ob nur das aktive Item gezeigt werden soll
	var showAlone = true;
	
	// wenn schon offen: Liste zeigen und raus!
	if (sourceTopicId && sourceTopicId == selectedTopicId) {
		
		// Highlighting ausschalten
		// Folder-Icon rechts
		if (lastTopicImgObj) {
			lastTopicImgObj.src = lastTopicImgObj.src.replace("_hi.gif", "_lo.gif");
		}
		//Folder-Icon links		
		if (lastSubtopicFolderImgObj) {
			lastSubtopicFolderImgObj.src = lastSubtopicFolderImgObj.src.replace("_hi.gif", "_lo.gif");
		}
		
		// SourcesBox weg
		document.getElementById("searchSourcesSubTopicSourcesBox_" + sourceTopicId).style.display = "none";
		document.getElementById("showContainedSources_" + sourceTopicId).style.backgroundImage = 'url(/wissenswelt/images/icons/plus_s.gif)';
		
		// Liste komplett zeigen
		if (showAlone) {
			var parentNode = document.getElementById("searchSourcesSubTopic_" + sourceTopicId).parentNode;
			var subTopicDivs = parentNode.childNodes;
			for (var i = 0; i < subTopicDivs.length; i++) {
				if (subTopicDivs[i].className == "searchSourcesSubTopic") {
					subTopicDivs[i].style.display = "block";
				}
			}
		}

		// die sind dann obsolet (und wuerde das Wiederoeffnen verhindern)
		sourceTopicId = false;
		subTopicId = false;		

		return false;
	}
	
	if (sourceTopicId && showAlone) {
		// das vorige (sofern vorhanden) ausblenden
		document.getElementById("searchSourcesSubTopicSourcesBox_" + sourceTopicId).style.display = "none";
		document.getElementById("showContainedSources_" + sourceTopicId).style.backgroundImage = 'url(/wissenswelt/images/icons/plus_s.gif)';
	}
	
	sourceTopicId = selectedTopicId; // damit das in process... lesbar ist
	
	/**/

	if (showAlone) {
		var parentNode = document.getElementById("searchSourcesSubTopic_" + sourceTopicId).parentNode;
		var subTopicDivs = parentNode.childNodes;
		//alert(parentNode.id + " " + subTopicDivs.length);
		for (var i = 0; i < subTopicDivs.length; i++) {
			//alert(subTopicDivs[i].id + " " + subTopicDivs[i].className);
			if (subTopicDivs[i].className == "searchSourcesSubTopic") {
				if (subTopicDivs[i].id != "searchSourcesSubTopic_" + sourceTopicId) {
					//subTopicDivs[i].style.display = "none";
				} else {
					subTopicDivs[i].style.display = "block";
				}
			}
		}
	}

	// "loading..." anzeigen	
	document.getElementById("searchSourcesSubTopicSourcesBox_" + sourceTopicId).style.display = "block";
	document.getElementById("searchSourcesSubTopicSourcesBox_" + sourceTopicId).innerHTML = "loading...";
	document.getElementById("showContainedSources_" + sourceTopicId).style.backgroundImage = 'url(/wissenswelt/images/icons/minus_s.gif)';

	var action = document.SearchForm.action;
	action += "?task=getSourcesOfSubtopics&selectedItemOfSubtopics=" + selectedTopicId;

	doAjaxRequest(action, processShowContainedSources);
	
}

function processShowContainedSources() {
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response
			document.getElementById("searchSourcesSubTopicSourcesBox_" + sourceTopicId).innerHTML = ajax.responseText;
			
		// Highlighting:
		// - SubTopic-Folder links
		if (lastSubtopicFolderImgObj) {
			lastSubtopicFolderImgObj.src = lastSubtopicFolderImgObj.src.replace("_hi.gif", "_lo.gif");
		}
			lastSubtopicFolderImgObj = document.images["topiclist_subtopic_" + sourceTopicId];
			// TODO: wird im Firefox nicht angezeigt (?):
			//alert(lastSubtopicFolderImgObj.src + " " + lastSubtopicFolderImgObj.name);
			lastSubtopicFolderImgObj.src = lastSubtopicFolderImgObj.src.replace("_lo.gif", "_hi.gif");	
			//alert(lastSubtopicFolderImgObj.src + " " + lastSubtopicFolderImgObj.name);
		} 
		// - Subtopic-Icon rechts
		if (lastTopicImgObj) {
			lastTopicImgObj.src = lastTopicImgObj.src.replace("_hi.gif", "_lo.gif");
		}
		var folderIcon = document.images["topiclist_subtopic_icon_" + sourceTopicId];
		if (folderIcon) {
			lastTopicImgObj = folderIcon;
			lastTopicImgObj.src = lastTopicImgObj.src.replace("_lo.gif", "_hi.gif");
		}
	
	}
}

function closeSubTopicsBox() {
	if (topicId) {
		try {
			// das vorige samt MouseOver (sofern vorhanden) ausblenden
			document.getElementById("searchSourcesSubTopicsBox_" + topicId).style.height = "auto";
			document.getElementById("searchSourcesSubTopicsBox_" + topicId).style.display = "none";
			document.getElementById("showSubTopics_" + topicId).style.backgroundImage = 'url(/wissenswelt/images/icons/plus_s.gif)';
		} catch(e) {
			// kann bei Favorites fliegen, weil da das "vorige" nicht existiert
		}
	}
}
function showSubTopics(selectedTopicId, selectedItemOfSubTopics, imgObj) {
	
	/**/
	if ((typeof(selectedItemOfSubTopics) == 'undefined') 
		&& (topicId && (topicId == selectedTopicId))) {
	
		// Highlighting ausschalten
		// Folder-Icon links
		if (lastTopicFolderImgObj) {
			lastTopicFolderImgObj.src = lastTopicFolderImgObj.src.replace("_hi.gif", "_lo.gif");
		}
		// Subtopic-Icon rechts
		if (lastTopicImgObj) {
			lastTopicImgObj.src = lastTopicImgObj.src.replace("_hi.gif", "_lo.gif");
		}
		
		closeSubTopicsBox();
		
		// die sind dann alle obsolet (und wuerde das Wiederoeffnen verhindern)
		topicId = false; 
		subTopicId = false;
		sourceTopicId = false;		

		return false;
	}
	
	if (typeof(selectedItemOfSubTopics) != 'undefined') {
		subTopicId = selectedItemOfSubTopics;
	} else {
		subTopicId = false;
	}
	
	// Highlighting
	if (imgObj) {
		// Folder-Icon rechts
		if (lastTopicImgObj) {
			lastTopicImgObj.src = lastTopicImgObj.src.replace("_hi.gif", "_lo.gif");	
		}
		imgObj.src = imgObj.src.replace("_lo.gif", "_hi.gif");	
		lastTopicImgObj = imgObj;
	}
	// Folder links
	if (lastTopicFolderImgObj) {
		lastTopicFolderImgObj.src = lastTopicFolderImgObj.src.replace("_hi.gif", "_lo.gif");
	}
	lastTopicFolderImgObj = document.images["topiclist_topic_" + selectedTopicId];
	lastTopicFolderImgObj.src = lastTopicFolderImgObj.src.replace("_lo.gif", "_hi.gif");	
	
	
	//evtl. offene Boxen schliessen
	closeSubTopicsBox(); // auch bei doSourceSearch!
	closeSourcesFoundBox();
	
	topicId = selectedTopicId; // damit das in process... lesbar ist

	// TopicBox flexibel machen (kann wegen MouseOver noch fixe Hoehe haben)
	//document.getElementById('searchSourcesTopicBox_' + topicId).style.height = "auto";
	
	// "loading..." anzeigen
	if (document.getElementById("favWrapper")) document.getElementById("favWrapper").style.display = "none";
	if (document.getElementById("favInfo")) document.getElementById("favInfo").style.backgroundImage = 'url(/wissenswelt/images/icons/plus_s.gif)';
	document.getElementById("searchSourcesSubTopicsBox_" + topicId).style.display = "block";
	document.getElementById("searchSourcesSubTopicsBox_" + topicId).innerHTML = "loading...";
	document.getElementById("showSubTopics_" + topicId).style.backgroundImage = 'url(/wissenswelt/images/icons/minus_s.gif)';

	var action = document.SearchForm.action;
	action += "?task=showSubTopics&selectedItemOfTopics=" + selectedTopicId;
	
	doAjaxRequest(action, processFetchSubtopics);
}
	
function showFavTopics () {
	var display = document.getElementById("favWrapper").style.display;
	if ((display == "") || (display == "none")) {
		closeSubTopicsBox();
		document.getElementById("favInfo").style.backgroundImage = 'url(/wissenswelt/images/icons/minus_s.gif)';
		document.getElementById("favWrapper").style.display = "block";
	}
	else {
		document.getElementById("favInfo").style.backgroundImage = 'url(/wissenswelt/images/icons/plus_s.gif)';
		document.getElementById("favWrapper").style.display = "none";
	}
}
	
function processFetchSubtopics() {
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response
			document.getElementById("searchSourcesSubTopicsBox_" + topicId).innerHTML = ajax.responseText;
			// wenn noetig, Sourcen oeffnen
			// (wenn Seite neu geladen wurde)
			if (subTopicId != false) {
				try {
					showContainedSources(subTopicId);
				} catch(e) {
					/**/
				}
			}
		} 
		else if (ajax.status == 401) {
			window.location.href='/wissenswelt/home.htm';		
	}
}
}

// wenn imgObj kommt, wird doSelect ueberschrieben
function selectSourcesOfTopic(topicId, doSelect, imgObj) {
	var action;
	
	if(topicId == ''){ /*alle*/
		//if (document.getElementById("searchSourcesFoundBox").childNodes[0].hasChildNodes()){
		if ($('#searchSourcesFoundBox input').length > 0){
			var i = 0;
			while (i < document.getElementById("searchSourcesFoundBox").getElementsByTagName("input").length){
				if(doSelect == true) document.getElementById("searchSourcesFoundBox").getElementsByTagName("input")[i].checked=true;
				if(doSelect == false) document.getElementById("searchSourcesFoundBox").getElementsByTagName("input")[i].checked=false;
				i ++;
			}
		}
	} 
	
	// Switch via Image:
	if (imgObj) {
		try {
		    //bei status 2 = "alles markiert" sollen alle demarkiert werden
			if (imgObj.src.match(/_2_/)) {
				doSelect = false;
			} else {
				doSelect = true;
			}
		} catch(e) {
		}
	}
	//alert("doselect= " + doSelect);
	
	if (doSelect == true) {
		action = document.SearchForm.action +
			"?task=changeSelectedTopics&topicsToBeSelected=" + topicId;
	} else {
		action = document.SearchForm.action +
			"?task=changeSelectedTopics&topicsToBeUnselected=" + topicId;
	}
			
	// weiter wie changeSelectedSources!
	g_ajax_obj.CallXMLHTTPObjectGETParamPartial ( action, processChangeSelectedSourcesDetail, '', '', '' );
	
}

function changeSelectedSourcesDetail(selectedSource, callFrom) {
	
	var action;
	if (selectedSource.checked) {
		action = document.SearchForm.action +
			"?task=changeSelectedSources&sourcesToBeSelected=" + selectedSource.value;
		if ($('#searchSourcesContentRight input:checkbox').length == 0) {
			$('#searchSourcesUncheckAll2').css('display','none');
		}
		else {
			$('#searchSourcesUncheckAll2').css('display','block');
		}

	} else {
		action = document.SearchForm.action +
			"?task=changeSelectedSources&sourcesToBeUnselected=" + selectedSource.value;
	}
	
	g_ajax_obj.CallXMLHTTPObjectGETParamPartial ( action, processChangeSelectedSourcesDetail, callFrom, '', '' );	
}
	
function processChangeSelectedSourcesDetail(in_text, in_param, in_param2) {

			/*alle Quellen die in dieser liste sind deselektieren*/
			if(in_param != "checkbox"){
				$('.sourcesSelectedCheckbox input').each(
				function(){
					var name = $(this).attr('value');
					$('#searchSources_SourceCheckBox_'+name).attr('checked', false);
				}
				);
			}
			//neue Quellen setzen
			document.getElementById("searchSourcesSelectedBox").innerHTML = in_text;
			// danach die Topics, Timeslide und Fields refreshen
			updateTopicsWrapper();
			// neu: Zeitverzoegerung 2 Sekunden fuer Zeitbandaktualisierung
			$().stopTime();
			$().everyTime(1000,function(i) {
				if (i == 2) {
					//searchFieldsUpdater.run();
					timeslideUpdater.run();
					checkSearchFormDate('from', true);
					checkSearchFormDate('to', true);
				}
			});
			
			if ($('#searchSourcesContentRight input:checkbox').length == 0) {
				$('#searchSourcesUncheckAll2').css('display','none');
			}
			else {
				$('#searchSourcesUncheckAll2').css('display','block');
			}
			
			countSources();	/*Quellen zeahlen*/
			
			/*alle Quellen die in dieser liste sind selektieren*/
			if(in_param != "checkbox"){
				$('.sourcesSelectedCheckbox input').each(
				function(){
					var name = $(this).attr('value');
					$('#searchSources_SourceCheckBox_'+name).attr('checked', "checked");
				}
				);
			}
}

function updateTopicsWrapper() {
	var action = '/wissenswelt/restricted/search.htm?task=showTopics';	
	doAjaxRequest(action, processUpdateTopicsWrapper);
}

function processUpdateTopicsWrapper() {
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response

			eval(ajax.responseText);
		} 
	}
}

function changeSelectedSourcesMyServices(selectedSource) {
	var action;
	if (selectedSource.checked) {
		action = document.SearchForm.action +
			"?task=changeSelectedSources&sourcesToBeSelected=" + selectedSource.value;
	} else {
		action = document.SearchForm.action +
			"?task=changeSelectedSources&sourcesToBeUnselected=" + selectedSource.value;
	}
	doAjaxRequest(action, processChangeSelectedSourcesMyServices);
}
	
function processChangeSelectedSourcesMyServices() {
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response
			/**/
			//document.getElementById("searchMyServicesSelectedSources").innerHTML = ajax.responseText;

			// danach das Zeitband updaten (Felder und Topics gibt es hier nicht)
			timeslideUpdater.run();
            checkSearchFormDate('from', true);
            checkSearchFormDate('to', true);
		} 
		else if (ajax.status == 401) {
			window.location.href='/wissenswelt/home.htm';		
	}
}
}

function closeSourcesFoundBox() {
	document.getElementById("searchSourcesFoundBox").style.display = "none";
}

function doSourceSearch() {
	var action = document.SearchForm.action;
	action += "?task=findSources&sourcePhrase=";
        action += encodeURIComponent(document.searchSourcesForm.sourcePhrase.value);

	// evtl. offene TopicBox schliessen
	closeSubTopicsBox();
	
	document.getElementById("searchSourcesFoundBox").style.display = "block";
	document.getElementById("searchSourcesFoundBox").innerHTML= "loading...";

	doAjaxRequest(action, processDoSourceSearch);
}

function processDoSourceSearch() {
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response
			if (ajax.responseText.match(/input/) != null) {
				document.getElementById("searchSourcesFoundBox").innerHTML = ajax.responseText;
			}
			else {
				document.getElementById("searchSourcesFoundBox").innerHTML = '<span style="font-weight: bold;">Es wurden keine Quellen gefunden</span>';
			}
		} 
		else if (ajax.status == 401) {
			window.location.href='/wissenswelt/home.htm';		
	}
}
}

/* PROGRESSBAR */

function doUpdateOfProgressBar() {
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response
			document.getElementById("progressbarContainer").innerHTML =
			ajax.responseText;
			if (ajax.responseText.indexOf('|Es ist getan|') != -1) {
				// loadSite() definiert in progressbar/wrapper.jsp
				window.setTimeout('loadSite();', 500);
			} else {
				window.setTimeout('updateProgressBar();', 10);
			}
		}
	}
}

function doLoadSite() {
	if (ajax.readyState == 4) { // Complete
		if (ajax.status == 200) { // OK response
			// loadSite() definiert in progressbar/wrapper.jsp
			loadSite();
		}
	}
}

function updateProgressBar() {
	doAjaxRequest(
		'/wissenswelt/restricted/progressbar.htm?task=update',
		doUpdateOfProgressBar);
}

function finalizeProgressBar() {
	doAjaxRequest(
		'/wissenswelt/restricted/progressbar.htm?task=finalize',
		doLoadSite);
}
/* /PROGRESSBAR */


/* ### /AJAX ### */

/* 
 * Ermittelt den absoluten Abstand eines Elemets (DIV...) 
 * zum linken Rand des Browserfensters
 */
function getLeftOffset(element) {
	var offset = 0;
	while(element) {
		offset += element.offsetLeft;
       	element = element.offsetParent || null;
	}
	return offset; // todo: NaN abfangen -> 0
}

/* 
 * Ermittelt den absoluten Abstand eines Elemets (DIV...) 
 * zum oberen Rand des Browserfensters
 */
function getTopOffset(element) {
	var offset = 0;	
	while(element) {
		offset += element.offsetTop;
       	element = element.offsetParent || null;
	}
	return offset; // todo: NaN abfangen -> 0
}

/*
 * Fuehrt das Login mit Suche durch
 */
function doLoginSearch(isCalledFromExternalForm) {
	
	var searchTerm = false;
	var searchForm = document.loginSearchForm;
	if (searchForm) {
		searchTerm = searchForm.searchTerm.value;
	}
	//aus dem cockpit
	var searchFormCockpit = document.loginForm;
	if (searchFormCockpit) {
    	if (searchFormCockpit.searchTerm){
			if(searchFormCockpit.searchTerm.value){
		  		searchTerm = searchFormCockpit.searchTerm.value;
			}
		}
	}
	
	var loginForm = document.getElementById("loginForm");
	if (loginForm) {
	
		if (checkLoginInputs('/wissenswelt/cms/login-popup-empty.htm', loginForm)) {
	
			//alert('ok');
			if (searchTerm) {
				loginForm.link.value = '/restricted/search.htm';
				loginForm.linkParams.value = 'task=showHits&detailSearchToSet=false';
				loginForm.linkParams.value += '&searchTerm=' + searchTerm;
				//alert(loginForm.link.value + '?'  + loginForm.linkParams.value);
			}
			
			if (isCalledFromExternalForm) {
				loginForm.submit();
			} else {
				return true;
			}
			
		} else {
			return false;
		}
	}
}

/* 
 * Wird nach dem Laden der Seite aufgerufen 
 * @param Boolean centered
 * 		zentrierte oder normale Layoutvariante
 */
function doOnloads(centered) {
	
	initTimeSelector();

	initSearchFormCalendars();
	initNewsAgentCalendars();
	initCostinfoCalendars();	
	//changeLogo();
	/**/
	window.centeredLayout = centered;
	//doResizesWrapper();
}

/*function doResizesWrapper() {
	try {
		if (window.centeredLayout) {
			doResizesCentered();
		} else {
			doResizes();
		}
	} catch(e) {
		console.warn("doResizesWrapper(): " + e.message);
	}
}*/

function initSearchFormCalendars() {
	try {
		if(typeof(document.SearchForm) != 'undefined') {
	
			/**/
			if(typeof(document.SearchForm.dateFromHour) != 'undefined'
				&& document.SearchForm.dateFromHour.type != 'hidden') {

				/**/			
				try {
					Calendar.setup( {
						/**/
						inputField : "searchFromYear|searchFromMonth|searchFromDay|searchFromHour|searchFromMinute",
						/**/
						ifFormat : "%Y%m%d%I%M",
						/**/
						button : "calFromTrigger",
						showsTime: true
					} );
				} catch(e) {
				    alert("1 " + e.message);
				}
			} else if(typeof(document.SearchForm.dateFromYear) != 'undefined') {
				/**/
				try {
					Calendar.setup( {
						/**/
						inputField : "searchFromYear|searchFromMonth|searchFromDay",
						/**/
						ifFormat : "%Y%m%d",
						/**/
						button : "calFromTrigger",
						showsTime: false
					} );
				} catch(e) {
					alert("2 " + e.message);
				}
			}
			
			/**/
			if(typeof(document.SearchForm.dateToHour) != 'undefined'
				&& document.SearchForm.dateToHour.type != 'hidden') {
				
				/**/
				try {
					Calendar.setup( {
						/**/
						inputField : "searchToYear|searchToMonth|searchToDay|searchToHour|searchToMinute",
						/**/
						ifFormat : "%Y%m%d%I%M", 
						/**/
						button : "calToTrigger",
						showsTime: true
					} );
				} catch(e) {
					alert("3 " + e.message);
				}		
			} else if(typeof(document.SearchForm.dateToYear) != 'undefined') {
				/**/
				try {
					Calendar.setup( {
						/**/
						inputField : "searchToYear|searchToMonth|searchToDay",
						/**/
						ifFormat : "%Y%m%d", 
						/**/
						button : "calToTrigger",
						showsTime: false
					} );
				} catch(e) {
					alert("4 " + e.message);
				}		
			}
		
		} 
		else{
			try {
				Calendar.setup( {
					/**/
					inputField : "searchFromYear|searchFromMonth|searchFromDay",
					/**/
					ifFormat : "%Y%m%d",
					/**/
					button : "calFromTrigger",
					showsTime: false
				} );
				
				Calendar.setup( {
					/**/
					inputField : "searchToYear|searchToMonth|searchToDay",
					/**/
					ifFormat : "%Y%m%d", 
					/**/
					button : "calToTrigger",
					showsTime: false
					} );
			} catch(e) {
				//alert("4_1 " + e.message);
			}
		}
	} catch(e) {
		alert("5 " + e.message);
	}
}

function initNewsAgentCalendars() {
	try {
		if(typeof(document.NewsAgentForm) != 'undefined'
			&& typeof(document.NewsAgentForm.dateToYear) != 'undefined') {

			/**/
			try {
				Calendar.setup( {
					/**/
					inputField : "searchFromYear|searchFromMonth|searchFromDay",
					/**/
					ifFormat : "%Y%m%d",
					/**/
					button : "calFromTrigger",
					showsTime: false
				} );
			} catch(e) {
				//alert(e.message);
			}
			
			/**/
			try {
				Calendar.setup( {
					/**/
					inputField : "searchToYear|searchToMonth|searchToDay",
					/**/
					ifFormat : "%Y%m%d", 
					/**/
					button : "calToTrigger",
					showsTime: false
				} );
			} catch(e) {
				//alert(e.message);
			}		
		
		}
	} catch(e) {
		console.warn(e.message);
	}
}

function initCostinfoCalendars() {
	try {
		if(typeof(document.CostinfoForm) != 'undefined') {
	
			/**/
			try {
				Calendar.setup( {
					/**/
					inputField : "searchFromYear|searchFromMonth|searchFromDay|searchFromHour|searchFromMinute",
					/**/
					ifFormat : "%Y%m%d%I%M",
					/**/
					button : "calFromTrigger",
					showsTime: true
				} );
			} catch(e) {
				console.error(e);
			}
			
			/**/
			try {
				Calendar.setup( {
					/**/
					inputField : "searchToYear|searchToMonth|searchToDay|searchToHour|searchToMinute",
					/**/
					ifFormat : "%Y%m%d%I%M", 
					/**/
					button : "calToTrigger",
					showsTime: true
				} );
			} catch(e) {
				console.error(e);
			}		
		
		}
	} catch(e) {
		console.error(e);
	}
}

function initTimeSelector() {
	/**/
	try {
		if (typeof(timeSelector) != 'undefined') {
			timeSelector.init();
		}
	} catch(e) {
		console.error(e);
	}
}

/*
 * Schreibt die Inhalte der Temp-DIVs der Trefferliste in die DIVs der Boxen 
 */
function updateClipboardInfoBox() {
	try {
		document.getElementById('clipboardInfoBox').innerHTML = document.getElementById('hitlistPagesTemp').innerHTML;
		if (!document.getElementById('clipboardInfoBox').innerHTML.match(/^\s*&nbsp;\s*$/)) {
			document.getElementById("clipboardDropdownBox").style.visibility = 'visible';
			document.getElementById('clipboardDropdownBox').innerHTML = document.getElementById('clipboardDropdownBoxTemp').innerHTML;
		}	
	} catch (e) {
		//alert(e.message);
	}
}
function updateHitlistBoxes() {
	try {
		document.getElementById('hitlistHitsInfo').innerHTML = document.getElementById('hitlistInfoTemp').innerHTML;
		document.getElementById('hitlistPagesBox').innerHTML = document.getElementById('hitlistPagesTemp').innerHTML;
	} catch (e) {
		//alert(e.message);
	}
}
function updateArticleBoxes() {
	try {
		/* 
			Nicht mehr grundsaetzlich 'articleInfoBox', weil im normalen Volltext /hitstatistic.htm 
			eingebettet wird; im Clipboard-Volltext dagegen bleibt 'articleInfoBox'
		*/
		var infoBoxDiv = document.getElementById('hitlistHitsInfo');
		if (!infoBoxDiv) {
			infoBoxDiv = document.getElementById('articleInfoBox');
		}
		infoBoxDiv.innerHTML = document.getElementById('articleInfoTemp').innerHTML;
		document.getElementById('articlePagesBox').innerHTML = document.getElementById('articlePagesTemp').innerHTML;
	} catch (e) {
		console.error(e);
	}
}

/*
 * blendet alle Fokusse in der Trefferliste ein|aus
 */
function toggleAllFokuses() {

	// Da DIV kein name-Attribut hat: Anker als Behelf; die DIV ist
	// dann jeweils der parentNode
	var fokusAnchors = document.getElementsByName("hitlistFokus");

	if (fokusAnchors && fokusAnchors.length > 0) {

		var newDisplay = 'table-row';

		try {
			
			doToggleAllFokuses(fokusAnchors, newDisplay);
			
		} catch (e) {
			/* IE6 kennt 'table-row nicht; Firefox und Opera
			brauchen das aber, d.h. stellen 'inline' bei <tr>s
			nicht sinnvoll dar */
			
			newDisplay = 'inline'; /* fallback */
			doToggleAllFokuses(fokusAnchors, newDisplay);
		}
	}
}
/* die eigentliche Ausfuehrung... */
function doToggleAllFokuses(fokusAnchors, newDisplay) {

	// der erste bestimmt die Richtung, d.h. wird tatsaechlich getoggled
	if (fokusAnchors[0].parentNode.parentNode.style.display == newDisplay) {
 		newDisplay = 'none';
	} 	

	for (var i = 0; i < fokusAnchors.length; i++) {
		fokusAnchors[i].parentNode.parentNode.style.display = newDisplay;
	}
}

/*
 * blendet ein Elemet via display: 'none' resp. displayOnType (block|table-row...)
 * ein resp. aus 
 */
function toggleElementDisplay(elementId, displayOnType, element) {
	try {
		
		doToggleElementDisplay(elementId, displayOnType, element);
		
	} catch (e) {
		/* IE6 kennt z.B. 'table-row nicht; Firefox und Opera
		   brauchen das aber, d.h. stellen 'inline' bei <tr>s
		   nicht sinnvoll dar */
		//alert(e.name + ': ' + e.message);
		
		displayOnType = 'inline'; /* fallback */
		doToggleElementDisplay(elementId, displayOnType, element);
		
	}		 
}
/* die eigentliche Ausfuehrung... */
function doToggleElementDisplay(elementId, displayOnType, element) {
	if (document.getElementById(elementId).style.display == displayOnType) {
		document.getElementById(elementId).style.display = 'none';
		element.style.backgroundImage = 'url(/wissenswelt/images/icons/toggle_small.gif)';
	} else {
		document.getElementById(elementId).style.display = displayOnType;
		element.style.backgroundImage = 'url(/wissenswelt/images/icons/toggle_small_clicked.gif)';
	}
}

/*
 * blendet ein Elemet via visibility: hidden|visible
 * ein resp. aus 
 */
function toggleElementVisibility(elementId) {
 	if (document.getElementById(elementId).style.visibility == 'visible') {
 		document.getElementById(elementId).style.visibility = 'hidden';
 	} else {
 		document.getElementById(elementId).style.visibility = 'visible';
 	}
}

/* LOGOUT aus dem Cockpit */
function doLogout() {
	document.CockpitForm.task.value = "logout";
	document.CockpitForm.tabToBeSet.value = "logout";
	document.CockpitForm.submit();
}

/* wenn formObj leer, dann SearchForm*/
function checkSearchFormDateChange(which, withTime, formObj) {
	/*
		formObj kann alternativ uebergeben werden
		(fuer costinfo; so keine Aenderung bei search noetig)
	*/	
	if (!formObj) {
		formObj = document.SearchForm;
	}
	
	// Token auf '' stellen (da das sonst overrulen wuerde)
	var tokenElementName = 'date' 
		+ which.substring(0, 1).toUpperCase()
		+ which.substring(1).toLowerCase() 
		+ 'RelativeToken';

	if (formObj.elements) {
		var tokenElement = formObj.elements[tokenElementName];
		if (tokenElement) {
			tokenElement.value = '';
		}
	}
	
	checkSearchFormDate(which, withTime, formObj);
}

function checkSearchFormDate(which, withTime, formObj) {
	
	/*
		formObj kann alternativ uebergeben werden
		(fuer costinfo; so keine Aenderung bei search noetig)
	*/	
	if (!formObj) {
		formObj = document.SearchForm;
	}
	
	var fromDate = getSearchFormDate('from', formObj);
	var toDate   = getSearchFormDate('to', formObj);	

	var fromTime = '';
	var toTime   = '';	

	/**/
	var from     = 0;
	var to       = 0;

	// TODO: check date	
	
	if(withTime) {
		fromTime = getSearchFormTime('from', formObj);
		toTime   = getSearchFormTime('to', formObj);		
	}
	
	from = parseInt('' + fromDate + fromTime);
	to   = parseInt('' + toDate + toTime);	
	//alert(which + ' ' + from + '-' + to);
	
	if (which == 'from') {
		
		/**/
		if (from > to) {
			//alert(from + '>' + to);
			fromDate = toDate;
			fromTime = toTime;
		}	

		changeFrom(fromDate, fromTime, '', ''); /**/

	} else {
		
		var date1 = new Date();
		var todayDate = Date.parse(date1.getMonth()+1 + '/' + date1.getDate() + '/' + date1.getFullYear());
		var formDate = Date.parse(document.getElementById('searchToMonth').value + '/' + document.getElementById('searchToDay').value + '/' + document.getElementById('searchToYear').value);
		
		/**/
		if (from > to) {
			//alert(from + '>' + to);
			toDate = fromDate;
			toTime = fromTime;
		}
		
		/*if (formDate > todayDate) {
			document.getElementById('searchToYear').value = date1.getFullYear();
			document.getElementById('searchToMonth').value = date1.getMonth()+1;
			document.getElementById('searchToDay').value = date1.getDate();
		}*/
		
		if (formDate <= todayDate) changeTo(toDate, toTime, '', ''); /**/

	}
}

function getSearchFormDate(which, formObj) {
	
	/*
		formObj kann alternativ uebergeben werden
		(fuer costinfo; so keine Aenderung bei search noetig)
	*/	
	if (!formObj) {
		formObj = document.SearchForm;
	}
	
	var date = '';
	
	if (which == 'from') {
		which = 'From';
	} else {
		which = 'To';
	}
	
	
	try {
		var year  = formObj.elements['search' + which + 'Year'].value;
		var month = formObj.elements['search' + which + 'Month'].value;
		var day   = formObj.elements['search' + which + 'Day'].value;	
		year = zeroPad(year, 4);
		month = zeroPad(month, 2);
		day = zeroPad(day, 2);
		date = '' + year + month + day;
	} catch(e) {
		console.warn('SearchForm ERROR: ' + e.message);	
	}
	
	return date;	
}

function getSearchFormTime(which, formObj) {
	
	/*
		formObj kann alternativ uebergeben werden
		(fuer costinfo; so keine Aenderung bei search noetig)
	*/	
	if (!formObj) {
		formObj = document.SearchForm;
	}
	
	var time = '';
	
	if (which == 'from') {
		which = 'From';
	} else {
		which = 'To';
	}
	
	try {
		var hour   = formObj.elements['search' + which + 'Hour'].value;
		var minute = formObj.elements['search' + which + 'Minute'].value;
		hour = zeroPad(hour, 2);
		minute = zeroPad(minute, 2);
		time = '' + hour + minute;
	} catch(e) {
		console.warn('SearchForm ERROR: ' + e.message);			
	}
	
	return time;	
}

function zeroPad(string, targetLength) {
	while (string.length < targetLength) {
		string = '0' + string;
	}
	return string.substr(0, targetLength);
}

function checkLoginInputs(errorUrl, formObj) {

	loginPopupLoader.close();
	
	var user = formObj.j_username.value;
	var pass = formObj.j_password.value;
	
	// debugging
	var posted = formObj.action + "?";
	for (var i = 0; i < formObj.elements.length; i++) {
		var element = formObj.elements[i];
		posted += element.name + "=" + element.value;
		if (i < (formObj.elements.length - 1)) {
			posted += "&";
		}
	}
	//alert(posted);

	if (user && pass) {
		return true;
	} else {
		//alert(errorString);
		loginPopupLoader.showEmpty(errorUrl);
		return false;
	}
}

function checkNewsagentDelivery(formObj) {
	
	checkStatus = true;
	
	if (formObj) {
		
		try {
		var fromYear  = parseInt(formObj.dateFromYear.value.replace(/^[0]+/, ''));
		var fromMonth = parseInt(formObj.dateFromMonth.value.replace(/^[0]+/, ''));
		var fromDay   = parseInt(formObj.dateFromDay.value.replace(/^[0]+/, ''));
		
		var toYear  = parseInt(formObj.dateToYear.value.replace(/^[0]+/, ''));
		var toMonth = parseInt(formObj.dateToMonth.value.replace(/^[0]+/, ''));
		var toDay   = parseInt(formObj.dateToDay.value.replace(/^[0]+/, ''));
		
		// Am vorhandenen FromYear wird die richtige Form erkannt
		if (formObj.dateFromYear) {
			if (   (fromYear < 1000) || (fromYear > 9999)
				|| (fromMonth < 1)	 || (fromMonth > 12)
				|| (fromDay < 1) 	 || (fromDay > 31)
				) {
				checkStatus = false;
				alert('???de_AT.newsagent.error.invalid.from???: ' 
					+ fromDay + '.' + fromMonth + '.' + fromYear);
			}
			if (   (toYear < 1000)	|| (toYear > 9999)
				|| (toMonth < 1)	|| (toMonth > 12)
				|| (toDay < 1)		|| (toDay > 31)
				) {
				checkStatus = false;
				alert('???de_AT.newsagent.error.invalid.to???: '
					+ toDay + '.' + toMonth + '.' + toYear);
			}
		}
		
		} catch(e) {
			// alert(e.message);
		}
		
	}
	
	return checkStatus;

}

/**/

function fromChanged(date, time, name, token) {
	//apatecwolf: es werden nur ganze tage gesucht
	time = "0000";
	
    logger("fromChanged " + date + " " + time + " " + name + " " + token);

	// Searchform: Einzelfelder
	try {
	    document.getElementById("searchFromYear").value = date.substr(0, 4);
   	    document.getElementById("searchFromMonth").value = date.substr(4, 2);
   	    document.getElementById("searchFromDay").value = date.substr(6, 2);

   	    document.getElementById("searchFromHour").value = time.substr(0,2);
   	    document.getElementById("searchFromMinute").value = time.substr(2,2);   	    
		
   	    document.getElementById("searchFromRelativeToken").value = token;
	} catch(e) {
		logger(e.message);
	}
	
	// Costinfo: Gesamtfelder
	try {
	    document.getElementById("fromDate").value = date;
	    document.getElementById("fromTime").value = time;
   	    document.getElementById("fromRelativeToken").value = token;
	} catch(e) {
		//alert(e.message);
	}
}

function toChanged(date, time, name, token) {

	//apatecwolf: es k�nnen nur ganze Tage gesucht werden
	time = "2359";
	
    logger("toChanged " + date + " " + time + " " + name + " " + token);

	// Searchform: Einzelfelder
	try {
	    document.getElementById("searchToYear").value = date.substr(0, 4);
   	    document.getElementById("searchToMonth").value = date.substr(4, 2);
   	    document.getElementById("searchToDay").value = date.substr(6, 2);

   	    document.getElementById("searchToHour").value = time.substr(0,2);
   	    document.getElementById("searchToMinute").value = time.substr(2,2);


   	    document.getElementById("searchToRelativeToken").value = token;
   	} catch(e) {
		logger(e.message);
	}
	
	// Costinfo: Gesamtfelder
	try {
	    document.getElementById("toDate").value = date;
	    document.getElementById("toTime").value = time;
   	    document.getElementById("toRelativeToken").value = token;
	} catch(e) {
		//alert(e.message);
	}
}

function fromSelected(date, time, name, token) {

	//apatecwolf: nur ganze Tage k�nnen gesucht werden
	time = "0000";
    console.info("fromSelected " + date + " " + time + " " + name + " " + token);

	// Searchform: Einzelfelder
	try {
		document.getElementById("searchFromRelativeToken").value = token;
	    document.getElementById("searchFromYear").value = date.substr(0, 4);
   	    document.getElementById("searchFromMonth").value = date.substr(4, 2);
   	    document.getElementById("searchFromDay").value = date.substr(6, 2);

   	    document.getElementById("searchFromHour").value = time.substr(0,2);
   	    document.getElementById("searchFromMinute").value = time.substr(2,2);   	    
		
   	    
	} catch(e) {
		//alert(e.message);
	}
	
	// Costinfo: Gesamtfelder
	try {
	    document.getElementById("fromDate").value = date;
	    document.getElementById("fromTime").value = time;
   	    document.getElementById("fromRelativeToken").value = token;
	} catch(e) {
		//alert(e.message);
	}
}

function toSelected(date, time, name, token) {

	//apatecwolf: nur ganze Tage k�nnen gesucht werden
	time = "2359";
    console.info("toSelected " + date + " " + time + " " + name + " " + token);

   	// Searchform: Einzelfelder
	try {
	    document.getElementById("searchToYear").value = date.substr(0, 4);
   	    document.getElementById("searchToMonth").value = date.substr(4, 2);
   	    document.getElementById("searchToDay").value = date.substr(6, 2);

   	    document.getElementById("searchToHour").value = time.substr(0,2);
   	    document.getElementById("searchToMinute").value = time.substr(2,2);   	    

   	    document.getElementById("searchToRelativeToken").value = token;    
	} catch(e) {
		//alert(e.message);
	}
	
	// Costinfo: Gesamtfelder
	try {
	    document.getElementById("toDate").value = date;
	    document.getElementById("toTime").value = time;
   	    document.getElementById("toRelativeToken").value = token;
	} catch(e) {
		//alert(e.message);
	}
}

function changeFrom(date, time, name, token) {
	//alert("changeFrom " + date + " " + time + " " + name + " " + token)
	try {
		timeSelector.updateFrom(new timeSelector.TimePoint(date, time, token, name));
	} catch(e) {
		console.warn(e.message);
	}
}

function changeTo(date, time, name, token) {
	//alert("changeTo " + date + " " + time + " " + name + " " + token)
	try {
		timeSelector.updateTo(new timeSelector.TimePoint(date, time, token, name));
	} catch(e) {
		console.warn(e.message);
	}
}
// nur zum testen:
function logger(value){
	/*
	var outputHandle = document.SearchForm.searchTerm.value;
	if (outputHandle) {
		outputHandle = value;
  	} 
  	*/
}
function getDiv(id) {
    // DHTML (dzt. hier einziger Zugriff)
    return document.getElementById(id);
}

/**/

/**/


/**/
var toggleSearchManager = { 
	switchState: function() {
	    //switchen
	    if (window.searchMaskFullState == 'true'){
	        window.searchMaskFullState = 'false';
	    }else {
	        window.searchMaskFullState = 'true';
	    }
	    var url  = '/wissenswelt/restricted/search.htm';
		var params = 'task=switchSearchMaskFull';
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	},
	
	process: function(pXml, pText) {
	    
	} 
}

function toggleSearchMaskView(onlySwitchDisplay) {
    //nur bei switch auch Werte setzen, sonst nur display aendern   
    if(!onlySwitchDisplay){
        // Seite komplett geladen? (Anti-Schnell-Klick-Error)
    	var footerDiv = document.getElementById("mainFooter");
    	if (!footerDiv) {
    		console.warn('mainFooter noch nicht geladen!');
    		return;
    	}
        toggleSearchManager.switchState();
    }

  	var elemente = new Array();
    elemente.push(document.getElementById("searchMaskExtras"));
    elemente.push(document.getElementById("searchMaskTime"));
    elemente.push(document.getElementById("searchMaskMyDef"));
    
  	for (var i = 0; i < elemente.length; i++) {
        if(elemente[i] != null){
      	    
      	    if (window.searchMaskFullState == 'true') {
                elemente[i].style.display='block';
            }else{
                elemente[i].style.display='none';
            }
        }
    }
    
    /*try{ 
        doResizesWrapper();
    } catch(e) {
     
	}*/
	
	//wenn alles fertig ist, Bilder wechseln
    if (window.searchMaskFullState == 'true') {
    	document.getElementById("toggleViewSearchMask").src='/wissenswelt/images/icons/einklappen.gif'; 
    }else{
        document.getElementById("toggleViewSearchMask").src='/wissenswelt/images/icons/ausklappen.gif'; 
    }
}


/**/
var toggleVisManager = { 
	switchState: function() {
	    //pr�fe in welchem Zustand sich das Visualisierung-Element befindet.
		if(document.getElementById('VIZcontainer').style.display == 'block'){
			window.visMaskFullState = 'true';
		}else{
			window.visMaskFullState = 'false';
		}
		//switchen
	    if (window.visMaskFullState == 'true'){
	        window.visMaskFullState = 'false';
	    }else {
	        window.visMaskFullState = 'true';
	    }
	    var url  = '/wissenswelt/restricted/hitlist.htm';
		var params = 'task=switchVisStatMaskFull';
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	},
	
	process: function(pXml, pText) {
	} 
}

function toggleVisMaskView(onlySwitchDisplay) {
    //nur bei switch auch Werte setzen, sonst nur display aendern   
    if(!onlySwitchDisplay){
        // Seite komplett geladen? (Anti-Schnell-Klick-Error)
    	var footerDiv = document.getElementById("mainFooter");
    	if (!footerDiv) {
    		console.warn('mainFooter noch nicht geladen!');
    		return;
    	}
        toggleVisManager.switchState();
    }

  	var elemente = new Array();
    /* alte Visualsierung
    elemente.push(document.getElementById("vizMask3dWrapper"));
    elemente.push(document.getElementById("statisticMask"));*/
	
	/* apatecwolf: neue Flash Visualisierung*/
	elemente.push(document.getElementById("VIZcontainer"));
    
    for (var i = 0; i < elemente.length; i++) {
        if(elemente[i] != null){
      	    
      	    if (window.visMaskFullState == 'true') {
                elemente[i].style.display='block';
								document.getElementById('hitlistSeparator2').style.display='none';
            }else{
                elemente[i].style.display='none';
								document.getElementById('hitlistSeparator2').style.display='block';
            }
        }
    }
    
    /*try{ 
        doResizesWrapper();
    } catch(e) {
	}*/
	
	//wenn alles fertig ist, Bilder wechseln
    if (window.visMaskFullState == 'true') {
    	//document.getElementById("toggleViewVisMask").src='/wissenswelt/images/icons/einklappen.gif';
		document.getElementById("toggleViewVisMask").style.display = "none";
    }else{
        //document.getElementById("toggleViewVisMask").src='/wissenswelt/images/icons/ausklappen.gif';
		document.getElementById("toggleViewVisMask").style.display = "";
    }
}


/* laedt die Namen der selektierten Kategorien in einem Popup Trendanalyse */
function showSelectedCategoriesPopup() {
        showSelectedCategoriesLoader.showSelectedCategoriesPopup();
}
var showSelectedCategoriesLoader = { 

	showSelectedCategoriesPopup: function() {
		var url  = '/wissenswelt/restricted/ta_question.htm';
        var params = 'task=showSelectedCategorieNames';
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	}, 

	process: function(pXml, pText) {
				
		var popupDiv = document.getElementById("mainPopup");
		
		// wegen Flash-Bug: ausblenden
		//hideViz();

		popupDiv.style.width = 400 + "px";
	    popupDiv.style.height = 400 + "px";    
		popupDiv.style.top = 100 + "px";
		popupDiv.style.left = 100 + "px";
		
		popupDiv.style.display = "block";	
		popupDiv.style.overflow = "auto";
		popupDiv.style.visibility = "visible";			
		
		popupDiv.innerHTML = pText;
	},
	
	closePopup: function() {
		var popupDiv = document.getElementById("mainPopup");
		popupDiv.innerHTML = '<!-- emptied -->';
		popupDiv.style.visibility = "hidden";
		popupDiv.style.display = "none";
		
		// wegen Flash-Bug: wieder einblenden
		//showViz();
	}
}


/**/
var toggleStatisticManager = { 
	switchState: function() {
	    //switchen
	    if (window.statisticCaptionFullState == 'true'){
	        window.statisticCaptionFullState = 'false';
	    }else {
	        window.statisticCaptionFullState = 'true';
	    }
	    //alert('starte den switcher - setze form auf ' + window.statisticCaptionFullState);
	    
	    var url  = '/wissenswelt/restricted/ta_question.htm';
		var params = 'task=switchStatisticCaptionFull';
		ajaxObj.request.add(this.process, 'GET', url, params, true);
	},
	
	process: function(pXml, pText) {
	} 
}

function toggleStatisticView(onlySwitchDisplay) {
    //nur bei switch auch Werte setzen, sonst nur display aendern   
    if(!onlySwitchDisplay){
        // Seite komplett geladen? (Anti-Schnell-Klick-Error)
    	var footerDiv = document.getElementById("mainFooter");
    	if (!footerDiv) {
    		console.warn('mainFooter noch nicht geladen!');
    		return;
    	}
    	toggleStatisticManager.switchState();
    }

  	var elemente = new Array();
  	elemente.push(document.getElementById("ta_statisticCaption"));
    elemente.push(document.getElementById("ta_categoryBox"));
    elemente.push(document.getElementById("hitstatisticBoxTA"));
        
    for (var i = 0; i < elemente.length; i++) {
        if(elemente[i] != null){
      	    if (window.statisticCaptionFullState == 'true') {
                elemente[i].style.display='block';
            }else{
                elemente[i].style.display='none';
            }
        }
    }
    
    /*try { 
        doResizesWrapper();
    } catch(e) {
	}*/
	
	//wenn alles fertig ist, Bilder wechseln
    if (window.statisticCaptionFullState == 'true') {
    	document.getElementById("toggleStatistic").src='/wissenswelt/images/icons/statistikLegendeAusblenden.gif'; 
    }else{
        document.getElementById("toggleStatistic").src='/wissenswelt/images/icons/statistikLegendeEinblenden.gif'; 
    }
}

/*
 * Ruft aus dem Cockpit die Suche zu einen Alarm auf
 */
/*var openSearchFromAlarm = { 

    run: function(task, searchIdToSet, productIdToSet) {
        alert("openSearchFromAlarm: " + task + " searchIdToSet: " + searchIdToSet + " productIdToSet: " + productIdToSet);
    		
    	//auch hier kein Update vom Cockpit erlauben!
        intervall = 0;
        clearInterval(cockpitUpdaterInterval);
        var url = '/wissenswelt/restricted/hitlist.htm';
    	var params = 'task='+task+'&searchIdToSet='+searchIdToSet+'&productIdToSet='+productIdToSet;
        ajaxObj.request.add(this.process, 'GET', url, params, true);
        intervall = 1;
	},
	
	process: function(pXml, pText) {
		alert('process OK');
		//submitLink('HitlistForm', 'showPage');
	},
	
	processSetTarget: function(pXml, pText) {
		//nix;
	} 
}
 */
/*
wird doch nciht mehr verwendet!
function openSearchFromAlarm(task, searchIdToSet, productIdToSet) {
    alert('url: ' + task + " searchIdToSet: " + searchIdToSet + " productIdToSet: " + productIdToSet);
    //auch hier kein Update vom Cockpit erlauben!
    intervall = 0;
    clearInterval(cockpitUpdaterInterval);
    var url = '/wissenswelt/restricted/hitlist.htm';
	var params = 'task='+task+'&searchIdToSet='+searchIdToSet+'&productIdToSet='+productIdToSet;
    ajaxObj.request.add(this.process, 'GET', url, params, true);
    intervall = 1;
}
*/

