var g_AllowDocActionGenerateLink
if (g_AllowDocActionGenerateLink == undefined) {
	g_AllowDocActionGenerateLink = false;
}
var g_InlineDocUri;
if (g_InlineDocUri == undefined || g_InlineDocUri == null)
	g_InlineDocUri = "";

function shiChangeImg(sId, sPath1, sPath2, sIdOld, sPath1old, sPath2old) {
	var changeImg = document.getElementById(sId);
	var sCheckStr = changeImg.src;
	var iResult = sCheckStr.search(sPath2);

	if (iResult != -1) {
		changeImg.src = sPath1;
	} else {
		changeImg.src = sPath2;
	}

	var changeImgOld = document.getElementById(sIdOld);
	if (changeImgOld == null)
		return;
	var sCheckStrOld = changeImgOld.src;
	var iResultOld = sCheckStrOld.search(sPath2old);

	if (iResultOld != -1) {
		changeImgOld.src = sPath1old;
		// }else{
		//  
		// changeImgOld.src = sPath1old;
	}

}

function shiFadeElementOut(sFadeElementId) {
	if (g_iIsFadedCounter[sFadeElementId] == undefined
			|| g_iIsFadedCounter[sFadeElementId] == 0) {
		void (dojo.style.setOpacity(dojo.byId(sFadeElementId), 0.3));
		g_iIsFadedCounter[sFadeElementId] = 1;
	} else {
		g_iIsFadedCounter[sFadeElementId] = g_iIsFadedCounter[sFadeElementId] + 1;
	}
}
function shiFadeElementIn(sFadeElementId) {
	g_iIsFadedCounter[sFadeElementId] = g_iIsFadedCounter[sFadeElementId] - 1;

	if (g_iIsFadedCounter[sFadeElementId] == 0) {
		void (dojo.style.setOpacity(dojo.byId(sFadeElementId), 1.0));
	}
}

function expandedSearchPopUp(start) {

	var implodeDiv = document.getElementById('indexSearchPopup');
	var popupDivExps = document.getElementById('exps');
	var topPos = getPosTop(start);

	popupDivExps.style.top = topPos + 16 + "px";
	popupDivExps.style.left = getPosLeft(start) - 496 + "px";
	if ((getPosLeft(start) - 496) < 1) {
		popupDivExps.style.left = 0 + "px";
	}
	var popupDivIframeS = document.getElementById('frameExps');

	popupDivIframeS.style.top = getPosTop(start) + 19 + "px";
	popupDivIframeS.style.left = getPosLeft(start) - 496 + "px";
	if ((getPosLeft(start) - 496) < 1) {
		popupDivIframeS.style.left = 0 + "px";
	}

	if (implodeDiv.style.display != 'none') {
		dojo.lfx.implode("indexSearchPopup", start, 500).play();
		dojo.lfx.implode("indexSearchFramePopup", start, 500).play();
		// shiFadeElementIn('documentwindow');
	}

	if (popupDivExps.style.display == 'none') {
		dojo.lfx.explode(start, "frameExps", 500).play();
		dojo.lfx.explode(start, "exps", 500).play();
		// shiFadeElementOut('documentwindow');

		// Spez_WebNG_V1.0.pdf, Seite 12:
		// >>Wählt der Nutzer erneut die erweiterte Suche, so sollen die
		// einzelnen Felder so
		// >>erscheinen, wie dies per default definiert ist;
		var ofrm = getelement("expandedsearchform");
		if (ofrm) {
			// ofrm.reset();
			// unselectlistitems(ofrm);
			selectListItemsCheckBoxes(ofrm);
		}
	} else {

		dojo.lfx.implode("exps", start, 500).play();
		dojo.lfx.implode("frameExps", start, 500).play();
		// shiFadeElementIn('documentwindow');
	}
	var search = getelement("expandedsearchform:text");
	if (search != null) {
		search.value = getSearchText();
	}
}


function setExpandenSearchText2() {
	var doc = document.getElementById('expandedsearchform:text');
	if (doc != null)
		doc.value = getSearchText();
}

function expandedSearchExtendedPopUp(start) {

	var implodeDiv = document.getElementById('indexSearchPopup');
	var popupDivExps = document.getElementById('exps');
	var topPos = getPosTop(start);

	popupDivExps.style.top = topPos + 16 + "px";
	popupDivExps.style.left = getPosLeft(start) - 315 + "px";
	if ((getPosLeft(start) - 496) < 1) {
		popupDivExps.style.left = 0 + "px";
	}
	var popupDivIframeS = document.getElementById('frameExps');

	popupDivIframeS.style.top = getPosTop(start) + 19 + "px";
	popupDivIframeS.style.left = getPosLeft(start) - 315 + "px";
	if ((getPosLeft(start) - 496) < 1) {
		popupDivIframeS.style.left = 0 + "px";
	}

	if (implodeDiv.style.display != 'none') {
		dojo.lfx.implode("indexSearchPopup", start, 500).play();
		dojo.lfx.implode("indexSearchFramePopup", start, 500).play();
		// shiFadeElementIn('documentwindow');
	}

	if (popupDivExps.style.display == 'none') {
		dojo.lfx.explode(start, "frameExps", 500).play();
		dojo.lfx.explode(start, "exps", 500).play();
		// shiFadeElementOut('documentwindow');

		// Spez_WebNG_V1.0.pdf, Seite 12:
		// >>Wählt der Nutzer erneut die erweiterte Suche, so sollen die
		// einzelnen Felder so
		// >>erscheinen, wie dies per default definiert ist;
		var ofrm = getelement("expandedsearchform");
		if (ofrm) {
			// ofrm.reset();
			// unselectlistitems(ofrm);
			selectListItemsCheckBoxes(ofrm);
		}
	} else {

		dojo.lfx.implode("exps", start, 500).play();
		dojo.lfx.implode("frameExps", start, 500).play();
		// shiFadeElementIn('documentwindow');
	}
	var search = getelement("expandedsearchform:text");
	if (search != null) {
		search.value = getSearchText();
	}

}

function limetedSearchPopUp(popId, framepopId, start) {
	var popupDiv = document.getElementById(popId);
	if (popupDiv == null)
		return;
	var topPos = getPosTop(start);

	popupDiv.style.top = topPos + 18 + "px";
	popupDiv.style.left = getPosLeft(start) + "px";

	var popupDivIframe = document.getElementById(framepopId);

	popupDivIframe.style.top = getPosTop(start) + 18 + "px";
	popupDivIframe.style.left = getPosLeft(start) + "px";

	var pos = 500;

	if (popupDiv.style.display == 'none') {
		dojo.lfx.explode(start, framepopId, pos).play();
		dojo.lfx.explode(start, popId, pos).play();

	} else {

		dojo.lfx.implode(popId, start, pos).play();
		dojo.lfx.implode(framepopId, start, pos).play();

	}

}

function expandChange2abo(start) {
	// debugger;
	var popupDivExps = document.getElementById('change2AboPopup');
	var topPos = getPosTop(start);
	var leftPos = getPosLeft(start);

	popupDivExps.style.top = 10 + "px";
	popupDivExps.style.left = 50 + "px";

	var popupDivIframeS = document.getElementById('change2AboFramePopup');

	popupDivIframeS.style.top = 10 + "px";
	popupDivIframeS.style.left = 50 + "px";

	if (popupDivExps.style.display == 'none') {
		dojo.lfx.explode(start, "change2AboFramePopup", 500).play();
		dojo.lfx.explode(start, "change2AboPopup", 500).play();
	} else {
		dojo.lfx.implode("change2AboFramePopup", start, 500).play();
		dojo.lfx.implode("change2AboPopup", start, 500).play();
	}
}

function indexSearchPopUp(start) {

	var implodeDiv = document.getElementById('exps');
	var popupDivExps = document.getElementById('indexSearchPopup');
	var topPos = getPosTop(start);

	popupDivExps.style.top = topPos + 20 + "px";
	popupDivExps.style.left = getPosLeft(start) - 496 + "px";
	if ((getPosLeft(start) - 496) < 1) {
		popupDivExps.style.left = 0 + "px";
	}
	var popupDivIframeS = document.getElementById('indexSearchFramePopup');

	popupDivIframeS.style.top = getPosTop(start) + 20 + "px";
	popupDivIframeS.style.left = getPosLeft(start) - 496 + "px";
	if ((getPosLeft(start) - 496) < 1) {
		popupDivIframeS.style.left = 0 + "px";
	}

	if (implodeDiv.style.display != 'none') {
		dojo.lfx.implode("exps", start, 500).play();
		dojo.lfx.implode("frameExps", start, 500).play();
		// shiFadeElementIn('documentwindow');
	}

	if (popupDivExps.style.display == 'none') {
		dojo.lfx.explode(start, "indexSearchFramePopup", 500).play();
		dojo.lfx.explode(start, "indexSearchPopup", 500).play();
		// shiFadeElementOut('documentwindow');

		// Spez_WebNG_V1.0.pdf, Seite 12:
		// >>Wählt der Nutzer erneut die erweiterte Suche, so sollen die
		// einzelnen Felder so
		// >>erscheinen, wie dies per default definiert ist;
		var ofrm = getelement("expandedsearchform");
		if (ofrm) {
			// ofrm.reset();
			// unselectlistitems(ofrm);
			selectListItemsCheckBoxes(ofrm);
		}
	} else {

		dojo.lfx.implode("indexSearchPopup", start, 500).play();
		dojo.lfx.implode("indexSearchFramePopup", start, 500).play();
		// shiFadeElementIn('documentwindow');
	}
	var search = getelement("expandedsearchform:text");
	if (search != null) {
		search.value = getSearchText();
	}

}

// function to close FF window/tab//
function shiFFcloseWindow() {
	window.open('', '_parent', '');
	window.close();
}

function doWekaWebLink(docReqFP) {
	// Dumb wrapping
	doSHIWebLink(docReqFP);
}

function download_popup(popId, framepopId, start) {
	debugger;
	var popupDiv = document.getElementById(popId);
	if (popupDiv == null)
		return;

	var topPos = getPosTop(start);

	popupDiv.style.top = topPos + 18 + "px";
	popupDiv.style.left = getPosLeft(start) + "px";

	var popupDivIframe = document.getElementById(framepopId);

	popupDivIframe.style.top = getPosTop(start) + 18 + "px";
	popupDivIframe.style.left = getPosLeft(start) + "px";

	var pos = 500;

	if (popupDiv.style.display == 'none') {
		dojo.lfx.explode(start, framepopId, pos).play();
		dojo.lfx.explode(start, popId, pos).play();
	} else {
		dojo.lfx.implode(popId, start, pos).play();
		dojo.lfx.implode(framepopId, start, pos).play();
	}
}

function oeffnefenster(message) {
	if (message != null && message != "") {
		fenster = window.open(
				'weka/jspf/message.jsp?message=' + escape(message),
				"Information",
				"width=200,height=100,status=no,scrollbars=yes,resizable=yes");
		if (fenster != null)
			fenster.focus();
	}
}

function iFrameRefresh() {
	if (!g_sCurrentSrc)
		return;
	if (g_sCurrentSrc.indexOf('wm_office_preview.jsp') >= 0)
		setIframeSrc();
}

function iFrameScrollRumbler() {
	if (!g_sDocumentWindowID)
		return;
	var oIframe = document.getElementById(g_sDocumentWindowID);
	if (!oIframe)
		return;

	oIframe.style.width = "100%";
}

// for index search:
var g_searchIndexLinkId = "";
function searchIndexDoLink(doLink) {
	if (doLink == false)
		return;

	var sId = g_searchIndexLinkId;
	sId = sId.replace(/searchIndexCommandLink$/, "indexSearchLink");
	var cmdButton = document.getElementById(sId);
	if (cmdButton == null)
		return;
	cmdButton.click();
}

function printCurrentDocument() {
	var printFrame = frames['documentwindow'];
	var docUrl;
	if (printFrame == null) {
		if (g_InlineDocUri == "") {
			return false;
		}
		docUrl = g_InlineDocUri;
	} else {
		docUrl = printFrame.location.href;
	}

	if (printFrame == null || docUrl.toLowerCase().indexOf("q=") > 0) {
		docUrl = setparam(docUrl, "q", "");
		docUrl = setparam(docUrl, "printyourself", "1");
		doSHIDownload(docUrl);
		return false;
	}

	printFrame.focus();
	printFrame.print();
	return false;
}

function selectWMDocumentAction(selectElement, sISBN, sFN, sAli, sAnchor,
		sTitle, sDocType) {
	if ((selectElement.value.toLowerCase() == "favourite")
			|| (selectElement.value.toLowerCase() == "favourites")) {
		openFeatPopup(
				12,
				'./weka/static/wmfavourites.html?fn=' + getDocRelUrl()
						+ "&isbn=" + sISBN + "&alias=" + sAli + "&anchor="
						+ sAnchor + "&doctype=" + sDocType + "&title=" + sTitle
						+ "#" + sAnchor,
				'favourites',
				'dependent=yes,width=700,height=200,resizable=yes,scrollbars=yes,menubar=no,status=yes');
		return false;
	}
	// Do nothing
	if (selectElement.value == 1) {
		return;
	}

	// Print it
	if (selectElement.value == 2) {
		if (frames['documentwindow'].location.href.toLowerCase().indexOf("q=") > 0) {
			var sUrl = setparam(frames['documentwindow'].location.href, "q", "");
			sUrl = setparam(sUrl, "printyourself", "1");
			doSHIDownload(sUrl);
			return;
		}
		frames['documentwindow'].focus();
		frames['documentwindow'].print();
		selectElement.value = 1;
		return;
	}

	// Send it as PDF
	if (selectElement.value == 3) {
		document.forms['documentSelected'].submit();
		selectElement.value = 1;
		return;
	}

	// Add to Favorites
	if (selectElement.value == 4) {
		document.forms['documentSelected'].submit();
		selectElement.value = 1;
		return;
	}

	// Generate Link (= show hidden field with link)
	if (selectElement.value.toLowerCase() == "generatelink") {
		if (g_isUserPersonalized || g_AllowDocActionGenerateLink) {
			var _linkField = document
					.getElementById('generatedLinkForm:generatedLink');
			if (_linkField != null) {
				_linkField.style.display = 'inline';
			}

			setsizes();
			selectElement.value = 1;
			return false;
		}

		document.forms['documentSelected'].submit();
		selectElement.value = 1;
		return;
	}

	// add to profile service
	if (selectElement.value.toLowerCase() == "addtoprofileservice") {
		document.forms['documentSelected'].submit();
		selectElement.value = 1;
		return;
	}

}

function selectAppFrameTab(tabIndex, isHomeTab) {
	
	for(var i = 0; true; i++){
		var link = document.getElementById("appFrameTabForm:appFrameTabDataList:" + i + ":appFrameTabLinkActive");
		if(link == null)
			break;
		link.style.display = tabIndex == i ? "inline" : "none";
		
		link = document.getElementById("appFrameTabForm:appFrameTabDataList:" + i + ":appFrameTabLinkInactive");
		link.style.display = tabIndex == i ? "none" : "inline";
	}
	
	var mainContentDiv = document.getElementById("appFrameMainContent");
	if(mainContentDiv == null)
		return;
	
	if(isHomeTab)
		mainContentDiv.style.display = "block";
	else
		mainContentDiv.style.display = "none";
}

/**
 * @author as
 */
function openPPTDownload() {
	window.open('./pptexport','pptexport');
}

/**
 * @author mf
 */
function setCursorWait(source) {
	document.body.style.cursor = 'wait'; 
	source.style.cursor='wait';
}

/**
 * @author mf
 */
function resetCursor(source) {
	document.body.style.cursor = 'auto'; 
	source.style.cursor='auto';
}
