//<![CDATA[
// ----------------------------------------------------------------------------
// utilities.js
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Kekse - Hilfsfunktionen
// ----------------------------------------------------------------------------
function Trim(p_string) {
    /// <summary>.</summary>
    /// <param name="p_string" type="String" optional="false">.</param>
    /// <returns type="String" mayBeNull="true">.</returns>
    if ("string" != typeof p_string) {
        return p_string;
    }

    var t_string = p_string;
    var t_ch = "";

    // Trim beginning spaces
    t_ch = t_string.substring(0, 1);
    while (" " == t_ch) {
        t_string = t_string.substring(1, t_string.length);
        t_ch = t_string.substring(0, 1);
    }

    // Trim trailing spaces
    t_ch = t_string.substring(t_string.length - 1, t_string.length);
    while (" " == t_ch) {
        t_string = t_string.substring(0, t_string.length - 1);
        t_ch = t_string.substring(t_string.length - 1, t_string.length);
    }

    return t_string;
}

function getCookie(p_cookie) {
    /// <summary>.</summary>
    /// <param name="p_cookie" type="" optional="false">.</param>
    /// <returns type="Number" integer="true" mayBeNull="false">.</returns>
    var t_cookie_name = "BIBNET_" + p_cookie;
    var t_cookies = document.cookie;

    t_cookies = t_cookies.split(";");

    var i = 0;
    while (i < t_cookies.length) {
        var t_cookie = t_cookies[i];

        t_cookie = t_cookie.split("=");

        if (Trim(t_cookie[0]) == t_cookie_name) {
            return t_cookie[1];
        }

        i++;
    }

    return -1;
}

function setCookie(p_cookie, p_value, p_session) {
    /// <summary>.</summary>
    /// <param name="p_cookie" type="" optional="false">.</param>
    /// <param name="p_value" type="" optional="false">.</param>
    /// <param name="p_session" type="" optional="false">.</param>
    var t_cookie_name = "BIBNET_" + p_cookie;
    var t_expires = new Date();

    t_expires.setTime(t_expires.getTime() + (365 * 24 * 60 * 60 * 1000));

    if (true == p_session) {
        document.cookie = t_cookie_name + "=" + p_value + ";";
    }
    else {
        document.cookie = t_cookie_name + "=" + p_value + "; expires=" + t_expires.toUTCString() + ";";
    }
}

// ----------------------------------------------------------------------------
// XML Utilities
// ----------------------------------------------------------------------------
function getNodeText(node) {
    /// <summary>Liefert textuellen Inhalt eines XML-/DOM-Node.</summary>
    /// <param name="node" domElement="true" optional="false">.</param>
    /// <returns type="String" mayBeNull="true">.</returns>
    if (!node) {
        return "";
    }

    // Nicht-IE
    if (node.textContent) {
        return node.textContent;
    }
    else if (node.firstChild) {
        return node.firstChild.nodeValue;
    }
    else {
        return "";
    }
}

function setNodeTextContent(node, content) {
    /// <summary>.</summary>
    /// <param name="node" domElement="true" optional="false">.</param>
    /// <param name="content" type="String" optional="false">.</param>
    /// <remarks>
    /// node kann eine (string) elementid aus dem aktuellen (x)html  dokument sein oder die elementreferenz direkt
    /// TODO funktioniert aktuell noch nicht mit anderen xmldokumenten(zb soap) im ie
    /// es gab ne methode des elements wo man aufs xmldoc objekt kommt (welches man braucht um nodes zu erzeugen) 
    /// diese sollte man noch verwenden ausserdem explodierts derzeit bei fehlern, evtl noch schoener catchen...
    /// </remarks>
    var div = node; //default: ein element

    if (typeof node == "string") {
        div = document.getElementById(node);
    }

    if (div.textContent) {
        div.textContent = content;
    } else {
        var newNode = document.createTextNode(content);

        if (div.childNodes.length > 0) {
            div.removeChild(div.lastChild);
        }

        div.appendChild(newNode);
    }
}

function emptyElement(node) {
    /// <summary>.</summary>
    /// <param name="node" domElement="true" optional="false">.</param>
    if (node != null) {
        if (node.childNodes != null) {
            while (node.childNodes.length > 0) {
                node.removeChild(node.childNodes[0]);
            }
        }
    }
}

// ----------------------------------------------------------------------------
// Cool (In)definite Progressbar
// ----------------------------------------------------------------------------
var pbiStyle = null;
var pbiLeft = 0;
var pbiVisible = false;

function updateProgbarIndefiniteStyle() {
    /// <summary>.</summary>
    /// <param name="" domElement="true" optional="false">.</param>
    /// <returns domElement="true" mayBeNull="true">.</returns>
    /// <remarks>
    /// Generell auf den Seiten starten mit:
    /// window.setTimeout("updateProgbarIndefiniteStyle()", 10);
    /// und sobald wirklich eine pbi eingeblendet wird auch aktivieren (kann man natürlich auch wieder deaktivieren):
    /// pbiVisible = true;
    /// (das ist separat weil der MSIE sich ziemlich doof verhält und permanent sanduhrt)
    /// </remarks>
    if (!pbiVisible) {
        window.setTimeout("updateProgbarIndefiniteStyle()", 150);
        return;
    }

    if (pbiStyle == null) {
        var head = document.getElementsByTagName("head")[0];

        pbiStyle = document.createElement("style");
        pbiStyle.type = "text/css";

        head.appendChild(pbiStyle);
    }
    else {
        pbiLeft = pbiLeft > 20 ? -5 : pbiLeft + 1;

        if (document.styleSheets[0].rules) {
            // MSIE (bei den vernünftigen Browsern heissts cssRules)
            // Achtung: bei MSIE is das etwas gefaehrlich: es wird vorrausgesetzt, dass ein leeres 
            // .pbiInner { } die letzte cssrule im letzten stylesheet ist!
            var mySheet = document.styleSheets[document.styleSheets.length - 1];
            mySheet.rules[mySheet.rules.length - 1].style.marginLeft = "" + pbiLeft + "em";
        }
        else {
            // Alle außer IE
            pbiStyle.textContent = ".pbiInner { margin-left: " + pbiLeft + "em; }";
        }
    }

    window.setTimeout("updateProgbarIndefiniteStyle()", 150);
}

function createProgbar(iPos, iMax) {
    /// <summary>.</summary>
    /// <param name="iPos" type="Number" integer="true" optional="false">.</param>
    /// <param name="iMax" type="Number" integer="true" optional="false">.</param>
    /// <returns domElement="true" mayBeNull="false">.</returns>
    var divci, i_span, pbiSpan, divcb, divcv;
    var divc = document.createElement("div");

    divc.className = "progbarContainer";

    if (-1 == iMax && -1 == iPos) {
        // indefinite
        divc.className = "pbiContainer";

        divci = document.createElement("div");
        divci.className = "pbiInner";

        for (i_span = 0; i_span < 5; i_span++) {
            pbiSpan = document.createElement("span");
            pbiSpan.className = "progressBarHandle-" + i_span;
            divci.appendChild(pbiSpan);
        }

        divc.appendChild(divci);
        pbiVisible = true;
    }
    else {
        // normale progbar
        divcb = document.createElement("div");
        divcb.className = "progbarBar";

        divcv = document.createElement("div");
        divcv.className = "progbarValue";

        if (0 == iMax && 0 == iPos) {
            // eine indefinite die fertig ist
            divcb.style.width = "100%";
            divcv.appendChild(document.createTextNode("100%"));
        }
        else {
            divcb.style.width = "" + ((iPos / iMax) * 100) + "%";
            divcv.appendChild(document.createTextNode("" + iPos + "/" + iMax));
        }

        divc.appendChild(divcb);
        divc.appendChild(divcv);
    }

    return divc;
}

function getSel() {
    /// <summary>.</summary>
    /// <returns type="String" mayBeNull="false">.</returns>
    var txt = "";
    var foundIn = "";

    if (window.getSelection) {
        txt = window.getSelection();
    }
    else if (document.getSelection) {
        txt = document.getSelection();
    }
    else if (document.selection) {
        txt = document.selection.createRange().text;
    }
    else {
        return;
    }

    return txt;
}

function searchForSelectionAtWikipedia(lang) {
    /// <summary>.</summary>
    /// <param name="lang" type="String" optional="false">.</param>
    if (5 == lang.length) {
        lang = lang.substring(0, 2);
    }

    var getsel = getSel();
    if ("" != getsel) {
        window.open("http://" + lang + ".wikipedia.org/wiki/Special:Search?search=" + encodeURI(getsel), "_blank");
    }
    else {
        try {
            window.alert(TL_WikiSelUsage);
        }
        catch (e) {
        }
    }
}

// ----------------------------------------------------------------------------
// EditableList - JavaScript
// ----------------------------------------------------------------------------
function EditableList_getList(uid) {
    /// <summary>.</summary>
    /// <param name="uid" type="String" optional="false">.</param>
    /// <returns domElement="true" mayBeNull="true">.</returns>
    return document.getElementById((uid + "_lstList").replace(/[:$]/g, "_"));
}
function EditableList_getInput(uid) {
    /// <summary>.</summary>
    /// <param name="uid" type="String" optional="false">.</param>
    /// <returns domElement="true" mayBeNull="true">.</returns>
    return document.getElementById(uid + "_txtEntry");
}
function EditableList_getDbcc(uid) {
    /// <summary>.</summary>
    /// <param name="uid" type="String" optional="false">.</param>
    /// <returns domElement="true" mayBeNull="true">.</returns>
    return document.getElementById((uid + "_dbccPerson_DbCombo1_textbox").replace(/[:$]/g, "_"));
}

function EditableList_add(uid, newEntry) {
    /// <summary>.</summary>
    /// <param name="uid" type="String" optional="false">.</param>
    /// <param name="newEntry" type="" optional="false">.</param>
    var opt1;
    var list = EditableList_getList(uid);

    if (null == newEntry || "undefined" == typeof newEntry) {
        newEntry = EditableList_getInput(uid).value;
        EditableList_getInput(uid).value = "";
    }

    if ("" == newEntry || null == newEntry) {
        return;
    }

    opt1 = document.createElement("option");
    opt1.text = newEntry;
    opt1.value = newEntry;

    try {
        // So wie es sich gehoert
        list.add(opt1, null);
    }
    catch (ex) {
        // So dass es der IE auch kapiert
        list.add(opt1);
    }

    EditableList_syncGuiToHidden(uid);
}

function EditableList_add_beifuegungen(uid) {
    /// <summary>.</summary>
    /// <param name="uid" type="String" optional="false">.</param>
    var newEntryTitle = EditableList_getInput(uid).value;
    var newEntryAuthor = EditableList_getDbcc(uid).value;

    if (-1 != newEntryTitle.indexOf(" / ") || -1 != newEntryTitle.indexOf(". ") ||
        -1 != newEntryTitle.indexOf("|!|") || -1 != newEntryAuthor.indexOf(" / ") || 
        -1 != newEntryAuthor.indexOf(". ") || -1 != newEntryAuthor.indexOf("|!|")) {
        window.alert("Ungueltige Zeichen");
        return;
    }

    if ("" == newEntryTitle || null == newEntryTitle) {
        return;
    }

    EditableList_getInput(uid).value = "";
    EditableList_getDbcc(uid).value = "";

    var newEntry = newEntryTitle;

    if (null != newEntryAuthor && newEntryAuthor.length > 0) {
        newEntry += " / " + newEntryAuthor;
    }

    EditableList_add(uid, newEntry);
}

function EditableList_removeSelected(uid) {
    /// <summary>.</summary>
    /// <param name="uid" type="String" optional="false">.</param>
    var i;
    var list = EditableList_getList(uid);

    for (i = list.length - 1; i >= 0; i--) {
        if (list.options[i].selected) {
            list.remove(i);
        }
    }

    EditableList_syncGuiToHidden(uid);
}

function EditableList_moveSelectedUp(uid) {
    /// <summary>.</summary>
    /// <param name="uid" type="String" optional="false">.</param>
    var list = EditableList_getList(uid);
    var index = list.selectedIndex;
    var first, second;

    if (index > 0) {
        first = list[index - 1].innerHTML;
        second = list[index].innerHTML;
        list[index - 1].innerHTML = second;
        list[index].innerHTML = first;
        list.selectedIndex = index - 1;
    }

    EditableList_syncGuiToHidden(uid);
}

function EditableList_moveSelectedDown(uid) {
    /// <summary>.</summary>
    /// <param name="uid" type="String" optional="false">.</param>
    var list = EditableList_getList(uid);
    var index = list.selectedIndex;
    var first, second;

    if (-1 == index) {
        return;
    }

    if (index < list.length - 1) {
        first = list[index].innerHTML;
        second = list[index + 1].innerHTML;
        list[index].innerHTML = second;
        list[index + 1].innerHTML = first;
        list.selectedIndex = index + 1;
    }

    EditableList_syncGuiToHidden(uid);
}

function EditableList_syncHiddenToGui(uid) {
    /// <summary>.</summary>
    /// <param name="uid" type="String" optional="false">.</param>
    var list = EditableList_getList(uid);
    var hidden = document.getElementById(uid + "_txtHidden");
    var items, i;

    if (0 == hidden.value.length) {
        return;
    }

    items = hidden.value.split("|!|");

    for (i = 0; i < items.length; i++) {
        EditableList_add(uid, items[i]);
    }
}

function EditableList_syncGuiToHidden(uid) {
    /// <summary>.</summary>
    /// <param name="uid" type="String" optional="false">.</param>
    var list = EditableList_getList(uid);
    var hidden = document.getElementById(uid + "_txtHidden");
    var tmp = "";
    var i;

    for (i = 0; i < list.length; i++) {
        if (list[i].innerHTML == "") {
            continue;
        }

        tmp = "" == tmp ? list[i].innerHTML : tmp + "|!|" + list[i].innerHTML;
    }

    hidden.value = tmp;
}

// ----------------------------------------------------------------------------
// Kleiner MSIE PNG Fix-Helper
// ----------------------------------------------------------------------------
function msie_fixImgPng(img, w, h) {
    /// <summary>.</summary>
    /// <param name="img" domElement="true" optional="false">object/string HtmlImgObject or id as string.</param>
    /// <param name="w" type="" optional="false">int/string numeric width (pixel).</param>
    /// <param name="h" type="" optional="false">int/string numeric height (pixel).</param>
    /// <returns domElement="true" mayBeNull="true">.</returns>
    var needFix = /MSIE (5\.5)|[6]/.test(navigator.userAgent) && "Win32" == navigator.platform;

    if (!needFix) {
        return;
    }

    if ("string" == typeof img) {
        img = document.getElementById(img);
    }

    if (img == null) {
        return;
    }

    var imgSrc = img.src;
    var blankSrc = "../Deko/blank.gif";

    img.runtimeStyle.height = "" + h + "px";
    img.runtimeStyle.width = "" + w + "px";
    img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgSrc + "',sizingMethod='scale')";

    img.src = blankSrc;
}

function printNodeTree(el) {
    /// <summary>.</summary>
    /// <param name="el" domElement="true" optional="false">.</param>
    /// <returns domElement="true" mayBeNull="true">.</returns>
    var popup, styleUrl;
    var el2, Ehead, Estylelink, Ebody;

    popup = window.open("", "_blank");
    popup.document.open();

    if ("undefined" != typeof PHOENIX_STYLEDIR) {
        styleUrl = "../Deko/" + PHOENIX_STYLEDIR + "/StyleSheets/print.css";
    }
    else {
        styleUrl = "../Deko/CleanStyle/StyleSheets/print.css";
    }

    if (popup.document.importNode) {
        // Den tollen XML/XHTML-Weg zum Erfolg nehmen
        el2 = popup.document.importNode(el, true);
        Ehead = popup.document.createElement("head");

        popup.document.childNodes[0].appendChild(Ehead);
        Estylelink = popup.document.createElement("link");
        Estylelink.rel = "stylesheet";
        Estylelink.type = "text/css";
        Estylelink.href = styleUrl;
        Ehead.appendChild(Estylelink);
        Ebody = popup.document.createElement("body");
        popup.document.childNodes[0].appendChild(Ebody);
        Ebody.appendChild(el2);

        popup.window.onload = function() {
            popup.window.print();
        };

    }
    else {
        // Der MSIE kann das natürlich nicht
        popup.document.write("<html>\n" +
                             "<head>\n" +
                             "    <link rel=\"stylesheet\" type=\"text/css\" href=\"" + styleUrl + "\" />\n" +
                             "</head>\n" +
                             "<body onload=\"print();\">\n" +
                             el.innerHTML +
                             "\n</body>\n" +
                             "</html>");
    }

    popup.document.close();
}


function CoverImageFallback() {
}

/* for the fucking grid suddenly its very complex */
CoverImageFallback.cache = {}

/**
* binds the img load/error events
*/
CoverImageFallback.bind = function(id) {
	//alert('bindingfor ' + id);
	qliste_updateCoverHack(id);
}

/**
* statically replace urls in the text from the known-bad cache
* another fucking hack for the grid
*/
CoverImageFallback.staticReplace = function(text) {
	for (var k in CoverImageFallback.cache) {
		//alert('replacing ' + k + ' with ' + CoverImageFallback.cache[k]);
		text = text.replace(k, CoverImageFallback.cache[k]);
	}
	return text;
}


function setImageFallback(id, url) {
	var tmp = "string" == typeof id ? document.getElementById(id) : id;

	tmp.onerror = function() {
		this.onerror = function() {
		};

		CoverImageFallback.cache[this.src] = url;
		this.src = url;
		
		if (this.parentNode!=null
			&& this.parentNode.className == 'amazonlink') {
			
			this.parentNode.removeAttribute('href');
			this.parentNode.title = '';
			this.parentNode.className = 'amazonlink_dead';
			
			var parent2 = this.parentNode.parentNode;
			
			if (parent2 != null && parent2.className == 'GridImageBox') {
				parent2.className += ' nohover';
			}
		}
	};

	tmp.onload = function() {
		if (!this.naturalWidth) {
			//drecks-MSIE again
			var anotherImg = document.createElement('img');
			anotherImg.src = this.src;
			if (anotherImg.width == 1) {
				this.onerror();
				return;
			}
		}
	
		if ((this.naturalWidth || this.width) == 1) {
			this.onerror();
		}
	}
}


function qliste_updateCoverHack(id) {
    /// <summary>.</summary>
    /// <param name="id" type="String" optional="false">Element-Id unter der gesucht werden soll nach den imgs mit class=tl_aimage.</param>
    /// <remarks>TODO: rename to qliste_jsInit?</remarks>
    var i;
    var Etl = document.getElementById(id);
    if (Etl == null) {
		//alert(id + " not found");
		return;
    }
    var imgs = Etl.getElementsByTagName("img");

	try {
		for (i = 0; i < imgs.length; i++) {
			var altUrl = null;
			if (imgs[i].longDesc) altUrl = imgs[i].longDesc;
			if (imgs[i].className == "tl_aimage"
				&& altUrl != null
				&& !( /\.aspx$/.test(altUrl) ) //another hack, sometimes it is ...StandardRecherche.aspx
				&& altUrl != '') {
				setImageFallback(imgs[i], imgs[i].longDesc);
				imgs[i].longDesc = null;
				
//				var test = document.createTextNode(imgs[i].id + ";");
//				Etl.appendChild(test);
			}
		}
    } catch (e) { alert(e); }
}

function qliste_jsInit_MSIE6(id) {
    /// <summary>.</summary>
    /// <param name="id" type="String" optional="false">.</param>
    /// <remarks>Call this additionally if msie6</remarks>
    var els, i;
    var Etl = document.getElementById(id);

    // EMEDIENPOPUPMENU
    if (window.attachEvent) {
        els = Etl.getElementsByTagName("div");

        for (i = 0; i < els.length; i++) {
            if ("simplepopup_a" == els[i].className.substring(0, 13)) {
                sfRegister(els[i]);
            }
        }
    }
}

function filterRet(event, func) {
    /// <summary>.</summary>
    /// <param name="event" domElement="true" optional="false">.</param>
    /// <param name="func" type="Object" optional="false">.</param>
    /// <returns domElement="true" mayBeNull="true">.</returns>
    /// <remarks>Nicht funktional atm</remarks>
    return;

    if (13 == event.keyCode) {
        func();
    }
}

function sfRegister(el) {
    /// <summary>.</summary>
    /// <param name="el" domElement="true" optional="false">.</param>
    el.onmouseover = function() {
        /// <summary>.</summary>
        this.className += " sfhover";
    }

    el.onmouseout = function() {
        /// <summary>.</summary>
        this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
    }
}

function getPosInParent(el) {
    /// <summary>.</summary>
    /// <param name="el" domElement="true" optional="false">.</param>
    var sibs = el.parentNode.childNodes;

    for (var i = 0; i < sibs.length; i++) {
        if (sibs[i] == el) {
            return i;
        }
    }
}

Function.prototype.bind = function() {
    /// <summary>.</summary>
    /// <returns domElement="true" mayBeNull="true">.</returns>
    /// <remarks>Imported from prototype.js</remarks>
    var __method = this;
    var args = $A(arguments);
    var object = args.shift();

    return function() {
        return __method.apply(object, args.concat($A(arguments)));
    }
}

Function.prototype.bindAsEventListener = function(object) {
    /// <summary>.</summary>
    /// <param name="object" domElement="true" optional="false">.</param>
    /// <returns domElement="true" mayBeNull="true">.</returns>
    var __method = this;

    return function(event) {
        return __method.call(object, event || window.event);
    }
}

function $(element) {
    /// <summary>.</summary>
    /// <param name="element" domElement="true" optional="false">.</param>
    /// <returns domElement="true" mayBeNull="true">.</returns>
    /// <remarks>Imported from prototype.js</remarks>
    var i;

    if (arguments.length > 1) {
        for (i = 0, elements = [], length = arguments.length; i < length; i++) {
            elements.push($(arguments[i]));
        }

        return elements;
    }

    if ("string" == typeof element) {
        // Object.isString(element)
        element = document.getElementById(element);
    }

    return element; // original: return Element.extend(element);
}

function $_compat(element) {
    /// <summary>.</summary>
    /// <param name="element" domElement="true" optional="false">.</param>
    /// <returns domElement="true" mayBeNull="true">.</returns>
    /// <remarks>
    /// Kompatible version von $ (shortcut getElementById by prototype.js) für die alten Bib.Net Controls. 
    /// Moderne id mit _ übergeben und wenns das nicht gibt wird geschaut obs was mit $ statt _ gibt.
    /// </remarks>
    var ret = $(element);

    if (!ret && "string" == typeof element) {
        ret = $(element.replace(/_/g, "$"));
    }

    return ret;
}


var $A = Array.from = function(iterable) {
    /// <summary>.</summary>
    /// <param name="iterable" tyype="Boolean" optional="false">.</param>
    /// <returns elementType="Array" elementMayBeNull="false">.</returns>
    if (!iterable) {
        return [];
    }

    if (iterable.toArray) {
        return iterable.toArray();
    }
    else {
        var results = [];

        for (var i = 0; i < iterable.length; i++) {
            results.push(iterable[i]);
        }
        
        return results;
    }
}

Function.prototype.bind = function() {
    /// <summary>.</summary>
    /// <returns domElement="true" mayBeNull="true">.</returns>
    var __method = this;
    var args = $A(arguments);
    var object = args.shift();

    return function() {
        return __method.apply(object, args.concat($A(arguments)));
    }
}

function Event() {
    /// <summary>.</summary>
    /// <remarks>Abgespeckte Version</remarks>
}

Event.observe = function(element, name, observer, useCapture) {
    /// <summary>.</summary>
    /// <param name="element" domElement="true" optional="false">.</param>
    /// <param name="name" type="String" optional="false">.</param>
    /// <param name="observer" type="String" optional="false">.</param>
    /// <param name="useCapture" type="Boolean" optional="true">.</param>
    useCapture = useCapture || false;

    if (element.addEventListener) {
        element.addEventListener(name, observer, useCapture);
    }
    else if (element.attachEvent) {
        if ("keypress" == name) {
            name = "keydown";
        }

        element.attachEvent("on" + name, observer);
    }
}

function bibnet_onHelp(event) {
    /// <summary>Kontextsensitive Hilfe.</summary>
    /// <param name="event" domElement="true" optional="false">.</param>
    var F2 = 113;
    if (F2 == event.keyCode) {
        var el = event.target || event.srcElement;

        while (el != null && !el.id) {
            el = el.parentNode;
        }

        var elid = el ? el.id : "";

        var url = "{0}App/Pages/Allgemein/KSHilfe/Hilfe.aspx?controlId={1}&fileLocation={2}";
        url = url.replace("{0}", PHOENIX_PROJECTPATH)
                 .replace("{1}", encodeURIComponent(elid))
                 .replace("{2}", encodeURIComponent(location.pathname));

        window.open(url, "ksHilfe_Popup");

    }
}

// Event.observe(document, "keypress", bibnet_onHelp);

window.request_in_progress = false;

function block_parallel_server_requests() {
    /// <summary>.</summary>
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(function(sender, args) {
        window.request_in_progress = true;
    });

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(sender, args) {
        window.request_in_progress = false;
    });

    // *g*
    var tmpPostback = window.__doPostBack;
    window.__doPostBack = function(et, ea) {
        if (window.request_in_progress) {
            return;
        }

        tmpPostback(et, ea);
    }
}


/**
* Verwaltung des Refresh-10sec-nach-SessionTimeout:
* UpdatePanel-beachtende neue Variante gegen das alte Problem mit den updatepanel-postbacks, 
* wo der refresh-timer nicht zurueckgesetzt wird
* aufruf nach moeglichkeit nicht manuell sondern durch Bibliotheca.generateTimeoutRefreshJS()
*/
var BibnetTimeout = {
	timeoutId: null,
	
	/**
	* sollte bei jedem refresh, egal ob neu-laden, per postback oder per updatepanel
	* aufgerufen werden. resetted den aktuell laufenden countdown und startet einen neuen
	* @param url string url to NeuAnmelden
	* @param timeout timeout in seconds (incl. 10 seconds)
	*/
	refresh: function(url, timeout) {
		if (this.timeoutId)
			window.clearTimeout(this.timeoutId);
			
		this.timeoutId = window.setTimeout(function() {
			window.location.href = url;
		}, timeout * 1000);
	}
}


// ----------------------------------------------------------------------------
// Ende utilities.js
// ----------------------------------------------------------------------------
//]]>

