﻿
//function reloadPage(init) {  //reloads the window if Nav4 resized
//  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
//    document.pgW=innerWidth; document.pgH=innerHeight; onresize=reloadPage; }}
//  else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
//}
//reloadPage(true);

function findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function swapImgRestore() { //v3.0
    var i, x, a = document.sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function swapImageFirst(id, p) {
    var element;
    if ((element = document.getElementById(id)) != null) {
        element.src = p;
    }
}

function swapImageBack(id, p) {
    var element;
    if ((element = document.getElementById(id)) != null) {
        element.src = p;
    }
}

// sets the default style to the editor's content on its loading
function OnRadEditorLoad(editor) {
    if (editor) {
        //	   var html = editor.GetHtml(true);
        //	   if (html == "")
        //	   {	
        //	  		editor.SetHtml("<span class='ArticleText'>&nbsp;</span>");
        //	   }	   

        // this is done in order to disable the default parent div css class when the radeditor is loading
        // unfortunately, this is the best solution I found
        if (document.getElementById('TheVeryEasyIdWhichCanBeFoundByJavascript')) {
            document.getElementById('TheVeryEasyIdWhichCanBeFoundByJavascript').className = "ArticleMainContainerEdit";
        }
    }
}

// a small anti-spam function (taken from old website)
function sendTo(sName, sDomain) {
    document.location.href = "mailto:" + sName + "@" + sDomain
}


// used to assign a default button to a textbox
function clickButton(e, buttonid) {
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);
    if (bt) {
        if (evt.keyCode == 13) {
            bt.click();
            return false;
        }
    }
}

function getHelpImage() {
    var url = "http://pro.unibz.it/opacuni/help_card.asp";
    var width = 560;
    var height = 300;
    var x = (window.screen.availWidth - width) / 2;
    var y = (window.screen.availHeight - height) / 2;
    window.open(url, "Fenster", "width=" + width + ", height=" + height + ", top=" + y + ", left=" + x + ", scrollbars=no, toolbar=NO, menubar=NO, status=no, resizable=no");
}

function getPasswordHelp() {
    var url = "https://pro.unibz.it/illordering/passwordhelp.aspx";
    var width = 560;
    var height = 300;
    var x = (window.screen.availWidth - width) / 2;
    var y = (window.screen.availHeight - height) / 2;
    window.open(url, "Fenster", "width=" + width + ", height=" + height + ", top=" + y + ", left=" + x + ", scrollbars=no, toolbar=NO, menubar=NO, status=no, resizable=no");
}

function performLibrarySearch(sOpacUrl, textboxid, performEscaping, language) {
    var textbox = document.getElementById(textboxid);
    var textValue = "";
    var myUrl = "";
    var languageId = 2;

    if (language == "IT") {
        languageId = 3;
    } else if (language == "DE") {
        languageId = 1;
    } else if (language == "RM") {
        languageId = 4;
    }

    if (textbox) {
        if (textbox.value != null && textbox.value.length > 0) {
            if (performEscaping) {
                textValue = escape(textbox.value);
            }
            else {
                textValue = textbox.value;
            }
        }
    }

    myUrl = stringFormat(sOpacUrl, textValue, languageId);

    window.open(myUrl);
    return false;
}

function performJournalSearch(sJournalUrl, ddlId, txttitleId, txtissnId) {
    var textboxTitle = document.getElementById(txttitleId);
    var textboxIssn = document.getElementById(txtissnId);
    var ddl = document.getElementById(ddlId);

    if (textboxTitle && textboxIssn && ddl) {
        var selIndex = ddl.selectedIndex;
        var myUrl = stringFormat(sJournalUrl, textboxTitle.value, ddl[selIndex].value, textboxIssn.value, '', '', '', '');
        window.open(myUrl);
    }
    return false;
}

function stringFormat(inputString) {
    for (i = 1; i < arguments.length; i++) {
        inputString = inputString.replace('{' + (i - 1) + '}', arguments[i]);
    }
    return inputString;
}

function clearTextbox(textboxid) {
    var textbox = document.getElementById(textboxid);
    if (textbox) {
        if (textbox.value != null && textbox.value.length > 0) {
            textbox.value = '';
        }
    }
    return false;
}

function resetDropdown(dropdownid) {
    var dropdown = document.getElementById(dropdownid);
    if (dropdown) {
        if (dropdown.selectedIndex != null) {
            dropdown.selectedIndex = 0;
        }
    }
    return false;
}

function modifyEventsHref(txtDateId, ddlCategoryId, oldHref) {

    var dropdown = document.getElementById(ddlCategoryId);
    if (dropdown) {
        if (dropdown.selectedIndex != null) {
            var myIndex = dropdown.selectedIndex;
            var myValue = dropdown[myIndex].value;
            oldHref += '&Classes=' + myValue;
        }
    }

    if (txtDateId != '') {
        var textbox = document.getElementById(txtDateId);
        if (textbox) {
            if (textbox.value != null && textbox.value.length > 0) {
                oldHref += '&Date=' + textbox.value;
            }
        }
    }

    return oldHref;
}

function myServicesRedirect(ddlId) {
    var dropdown = document.getElementById(ddlId);
    if (dropdown) {
        if (dropdown.selectedIndex != null) {
            var myIndex = dropdown.selectedIndex;
            var myValue = dropdown[myIndex].value;
            var myId = dropdown[myIndex].id;
            if (myId == '1') {
                window.open(myValue);
            }
            else {
                window.location.href = myValue;
            }
        }
    }
}

// the function is referenced in all masterpages, so DO NOT DELETE until you 
// don't remove the references from masterpages
function replaceOnKeyPress() {
    var theFunction = "S6F789EBA_Submit();";
    var theInputID = "ctl00_SearchBox_S6F789EBA_InputKeywords";

    var txt = document.getElementById(theInputID);
    var browser = navigator.appName;

    if (txt && (browser == "Netscape")) {
        txt.onkeypress = function (e) {
            var key = String.fromCharCode(e.keyCode);

            if (key == "\n" || key == "\r") {
                eval(theFunction);
                return false;
            }
        }
    }
}

// delays the menu expansion of myservices 
var sendingCel;
var outID;

//Two javascript funcions

function CallMenuDelayed(sender) {
    sendingCel = sender;

    outID = setTimeout('Menu_HoverStatic(sendingCel)', 400);
}

function CloseMenuDelayed(sender) {

    clearTimeout(outID);

    Menu_Unhover(sender);

}
// end delay myservices


var subLevel;

function MyServicesDelay(sender) {
    var tmpNode;

    for (i = 0; i <= sender.childNodes.length; i++) {
        if ((sender.childNodes[i] != undefined) && (sender.childNodes[i].nodeName === 'LI') && (tmpNode === undefined)) {
            tmpNode = sender.childNodes[i]
        }
    }

    if (tmpNode != undefined) {
        subLevel = tmpNode.childNodes[1];

        //if((subLevel.className.substr(('sVisible MyServices '.length)) != 'sVisible MyServices ' ) &&
        //(subLevel.className.substr(('sHidden MyServices '.length)) != 'sHidden MyServices ' ))
        if (subLevel.className === 'subLevelContainer') {
            subLevel.className = subLevel.className.replace(/^(sVisible|sHidden) ?/, '');
            subLevel.className = 'sHidden ' + subLevel.className;
            //subLevel.className = 'sHidden ';
        }

        outID = setTimeout('AddDelay(subLevel)', 600);
    }

}

function AddDelay(subLevel) {
    subLevel.className = subLevel.className.replace(/^(sVisible|sHidden) ?/, '');
    subLevel.className = 'sVisible ' + subLevel.className;
    //subLevel.className = 'sVisible';
}

function MyServicesDelayOut(sender) {
    clearTimeout(outID);
    subLevel.className = subLevel.className.replace(/^(sVisible|sHidden) ?/, '');
    subLevel.className = 'sHidden ' + subLevel.className;
    //subLevel.className = 'sHidden';
}

function MyServicesSubLevel(sender) {
    subLevel.className = subLevel.className.replace(/^(sVisible|sHidden) ?/, '');
    subLevel.className = 'sVisible ' + subLevel.className;
    //subLevel.className = 'sVisible';
}

// end delay myservices

////////////////AddressesWebPart////////////////
//if you change the selection in the dropdownlist, show only the selected seat and hide all the other seats
function AddressesWebPartSelectedIndexChanged(e) {
    var mainPanelWithDepartment = $(e).parent();
    mainPanelWithDepartment.find(".addressesWebPartDepartmentSeats:visible").hide();
    mainPanelWithDepartment.find(".addressesWebPartDepartmentSeats:eq(" + e.selectedIndex + ")").show();
}

////////////////NewsWebPart////////////////
//Builds the url for the newsOverview after clicking search by newsWebPart
function ShowAllNewsFiltered(e) {
    var newsSearchPanel = $(e).parent().parent();
    var newsTextBoxKeyword = newsSearchPanel.find("#newsTextBoxKeyword");
    var langDropDownList = newsSearchPanel.find("#langDropDownList option:selected");
    var mediaDropDownList = newsSearchPanel.find("#mediaDropDownList option:selected");
    var subjectDropDownList = newsSearchPanel.find("#subjectDropDownList option:selected");
    var newsTextBoxDateFrom = newsSearchPanel.find("#newsTextBoxDateFrom");
    var newsTextBoxDateTo = newsSearchPanel.find("#newsTextBoxDateTo");
    var pressCuttingsMode = newsSearchPanel.find("#pressCuttingsMode").text();
    var newsSearchFullUrl = newsSearchPanel.find("#newsSearchFullUrl").text();
    var newsSearchtopicIds = $.trim(newsSearchPanel.find("#newsSearchtopicIds").text());
    var fromDate = '';
    var toDate = '';
    var keyword = '';
    var media = '';
    var lang = '';
    var media = '';
    var subject = '';

    if (newsTextBoxDateFrom && newsTextBoxDateFrom.val() != '') {
        fromDate = newsTextBoxDateFrom.val();
    }
    if (newsTextBoxDateTo && newsTextBoxDateTo.val() != '') {
        toDate = newsTextBoxDateTo.val();
    }
    if (langDropDownList && langDropDownList.val() != '') {
        lang = langDropDownList.attr('value');
    }

    if (pressCuttingsMode == 'true') {
        if (mediaDropDownList && mediaDropDownList.val() != '') {
            media = mediaDropDownList.attr('value');
        }
        if (subjectDropDownList && subjectDropDownList.val() != '') {
            subject = subjectDropDownList.attr('value');
        }
        var url = newsSearchFullUrl + '/NewsOverview.html?Classes=' + newsSearchtopicIds + '&From=' + fromDate + '&To=' + toDate + '&Lang=' + lang + '&Media=' + media + '&Subject=' + subject;
    }
    else {
        if (newsTextBoxKeyword && newsTextBoxKeyword.val() != '') {
            keyword = newsTextBoxKeyword.val();
        }
        var url = newsSearchFullUrl + '/NewsOverview.html?Classes=' + newsSearchtopicIds + '&From=' + fromDate + '&To=' + toDate + '&Lang=' + lang + '&Keyword=' + keyword;
    }
    window.location.href = url;
    return false;
}

function setNewsSearchLanguage(e, LangID, LangDesc) {
    var newsSearchPanel = $(e).parent().parent();

    $('#langDropDownList').val(LangID);
    $('#mySearchLanguage').text(LangDesc);
    MyServicesDelayOut(e);

    return false;

}

////////////////EventsWebPart////////////////
function ClickGoButtonEventWebPart(e) {
    var eventsNavDateDiv = $(e).parent().parent();
    var categoriesDropDown = eventsNavDateDiv.find("#categoriesDropDown option:selected");
    var dateTime = eventsNavDateDiv.find("#dateTextBox");
    var classTmp = eventsNavDateDiv.find("#classes").text();
    var pagingMode = eventsNavDateDiv.find("#pagingMode").text();
    var fullUrl = eventsNavDateDiv.find("#fullUrl").text();

    var classes = '';
    var date = '';

    if (dateTime && dateTime.val() != '') {
        date = dateTime.val();
    }

    if (categoriesDropDown && categoriesDropDown.val() != '') {
        classes = categoriesDropDown.attr('value');
    }
    if (classes == undefined) {
        classes = classTmp;
    }

    var url = fullUrl + '?ePagingMode=' + pagingMode + '&Classes=' + classes + '&Date=' + date;
    window.location.href = url;
    return false;
}

////////////////PagerFunctions////////////////

////On clicking at next,prev,first or last, the new page numbers will be displayed and the first page will be selected
function ShowNewPagerField(e, prev_next_first_last) {
    var pagerField = $(e).parent();
    var pagerMain = $(e).parent().parent();

    var newPagerField;
    if (prev_next_first_last == "prev")
        newPagerField = $(pagerField).prev("#pagerField");
    if (prev_next_first_last == "next")
        newPagerField = $(pagerField).next("#pagerField");
    if (prev_next_first_last == "first")
        newPagerField = $(pagerMain).find("#pagerField").first();
    if (prev_next_first_last == "last")
        newPagerField = $(pagerMain).find("#pagerField").last();

    var url = newPagerField.find(".EventsPagerNumeric").first().attr("href");
    window.location.href = url;
    return false;
}

////////////////VacanciesWebPart////////////////
function VacanciesWebPartSearchButtonClick(e) {
    var controllerPanel = $(e).parent();
    var fullUrl = controllerPanel.find("#fullUrl").text();
    var callDropDownVacancies = controllerPanel.find("#callDropDownVacancies option:selected");

    var selectedTargetGroup = '';

    if (callDropDownVacancies && callDropDownVacancies.val() != '') {
        selectedTargetGroup = callDropDownVacancies.attr('value');
    }

    var url = fullUrl + '?TargetId=' + selectedTargetGroup;
    window.location.href = url;
    return false;
}

////////////////CallsWebPart////////////////
function CallsWebPartSearchButtonClick(e) {
    var callsControllers = $(e).parent().parent();
    var fullUrl = callsControllers.find("#fullUrl").text();
    var callType = callsControllers.find("#callType").text();
    var callsDropDownKeyword = callsControllers.find("#callsDropDownKeyword option:selected");
    var callsDropDownProgramm = callsControllers.find("#callsDropDownProgramm option:selected");
    var callsDropDownMonth = callsControllers.find("#callsDropDownMonth option:selected");

    var selectedMonth = '';
    var selectedKeyword = '';
    var selectedProgramm = '';

    if (callsDropDownMonth && callsDropDownMonth.val() != '') {
        selectedMonth = callsDropDownMonth.attr('value');
    }
    if (callsDropDownKeyword && callsDropDownKeyword.val() != '') {
        selectedKeyword = callsDropDownKeyword.attr('value');
    }
    if (callsDropDownProgramm && callsDropDownProgramm.val() != '') {
        selectedProgramm = callsDropDownProgramm.attr('value');
    }

    var url = fullUrl + '?CallType=' + callType + '&Month=' + selectedMonth + '&Keyword=' + selectedKeyword + '&Programm=' + selectedProgramm;
    window.location.href = url;
    return false;
}

////////////////StaffOverviewWebPart////////////////
var staffPopup;
var liItemPopUpHtml;
var liItem;

function OpenModaDialogStaffOverview(e) {
    liItem = $(e).parent();
    staffPopup = liItem.find('.staffPopup');
    liItemPopUpHtml = staffPopup.clone();

    staffPopup.dialog({
        autoOpen: false,
        minHeight: 50,
        minWidth: 100,
        modal: true,
        bgiframe: true,
        close: function () {
            CloseModaDialogStaffOverview();
        }
    });
    staffPopup.dialog('open');
}

function CloseModaDialogStaffOverview() {
    staffPopup.remove();
    liItem.append(liItemPopUpHtml);
}


function StaffOverviewWebPartSearchButtonClick(e) {
    var staffOverviewSearchMask = $(e).parent().parent();
    var fullUrl = staffOverviewSearchMask.find("#fullUrl").text();
    var selectedLName = staffOverviewSearchMask.find("#staffOverviewInputLName").val();
    var selectedFName = staffOverviewSearchMask.find("#staffOverviewInputFName").val();
    var staffOverviewDepDropDown = staffOverviewSearchMask.find("#staffOverviewDepDropDown option:selected");
    var staffOverviewRadioAll = staffOverviewSearchMask.find("#staffOverviewRadioAll");
    var staffOverviewRadioSeconded = staffOverviewSearchMask.find("#staffOverviewRadioSeconded");
    var staffOverviewRadioAdmin = staffOverviewSearchMask.find("#staffOverviewRadioAdmin");
    var staffOverviewRadioAcademic = staffOverviewSearchMask.find("#staffOverviewRadioAcademic");

    var department = '';
    var staffType = '';

    if (staffOverviewDepDropDown && staffOverviewDepDropDown.val() != '') {
        department = staffOverviewDepDropDown.attr('value');
    }
    if (staffOverviewRadioAll.is(':checked')) {
        staffType = staffOverviewRadioAll.attr('value');
    }
    else {
        if (staffOverviewRadioSeconded.is(':checked')) {
            staffType = staffOverviewRadioSeconded.attr('value');
        }
        else {
            if (staffOverviewRadioAdmin.is(':checked')) {
                staffType = staffOverviewRadioAdmin.attr('value');
            }
            else {
                if (staffOverviewRadioAcademic.is(':checked')) {
                    staffType = staffOverviewRadioAcademic.attr('value');
                }
            }
        }
    }

    var url = fullUrl + '?LName=' + selectedLName + '&FName=' + selectedFName + '&Dep=' + department + '&StaffType=' + staffType;
    window.location.href = url;
    return false;
}

////////////////LibrarySearchBoxWebPart////////////////
function LibrarySearchClickClearMode1_2(e) {
    var libraryContentMainInner = $(e).parent().parent().parent();
    libraryContentMainInner.find("#librarySearchBoxKeyWord").val('');
}

function LibrarySearchClickClearMode3(e) {
    var libraryContentMainInner = $(e).parent().parent().parent().parent().parent();
    libraryContentMainInner.find("#librarySearchWebPartTextInput").val('');
    libraryContentMainInner.find("#librarySearchWebPartISSNInput").val('');
    libraryContentMainInner.find("#librarySearchWebPartSelect option:selected").attr('selected', '');
    libraryContentMainInner.find("#librarySearchWebPartSelect option[0]").attr('selected', 'selected'); ;
}

////////////////StaffMemberSimpleWebPart////////////////
function StaffMemberFilterClick(e) {
    var staffMembersMain = $(e).parent().parent();
    var lastName = staffMembersMain.find("#staffMemberLastNameInput").val();
    var firstName = staffMembersMain.find("#staffMemberFirstNameInput").val();
    var lettersMode = staffMembersMain.find("#lettersMode").text();
    var fullUrl = staffMembersMain.find("#fullUrl").text();

    var url;
    if (lettersMode != ' ')
        url = fullUrl + '?letters=' + lettersMode + '&lName=' + lastName + '&fName=' + firstName;
    else
        url = fullUrl + '?lName=' + lastName + '&fName=' + firstName;
    window.location.href = url;
    return false;
}

////////////////LibrarySearchWebPartNew////////////////
function performLibrarySearchNew(textboxid, sOpacUrl, performEscaping, language) {
    var textbox = document.getElementById(textboxid);
    var textValue = "";
    var myUrl = "";
    var languageId = 2;

    if (language == "IT") {
        languageId = 3;
    } else if (language == "DE") {
        languageId = 1;
    } else if (language == "RM") {
        languageId = 4;
    }

    if (textbox) {
        if (textbox.value != '') {
            if (performEscaping == 'true') {
                textValue = escape(textbox.value);
            }
            else {
                //textValue = encodeURI(textbox.value);
                textValue = encodeURIComponent(textbox.value);
            }
        }
    }

    myUrl = stringFormat(sOpacUrl, textValue, languageId);

    window.open(myUrl);
}
