/* TOP NAVIGATION LAYER STUFF */
var menuCount = 0; //anzahl der Navigation Tabs beginnend mit 0 ( z.B 0 bis 5 = 6 items)
var topItemIndex = -1; //aktive Navigations Tab beginnend mit 0 (z.B. 2 ist der 3 item)

function showSubNavigation(subId, isCurrentTopDir) {
    objSubNavi = document.getElementById("subNavi_" + subId);
    objMainNavi = document.getElementById("mainNavi_" + subId);
    objMainNaviImgLeft = document.getElementById("mainNaviImgLeft_" + subId);
    objmainNaviImgRight = document.getElementById("mainNaviImgRight_" + subId);

    if (objSubNavi)
        objSubNavi.style.display = "block";

    if (objMainNavi)
        objMainNavi.className = (isCurrentTopDir == "true") ? "link selected current" : "link selected";

    if (objMainNaviImgLeft) {
        objMainNaviImgLeft.src = imgDir + "topnavi_selected_left.png";
        iePNGLoader.loadThis(objMainNaviImgLeft);
    }

    if (objmainNaviImgRight) {
        objmainNaviImgRight.src = imgDir + "topnavi_selected_right.png";
        iePNGLoader.loadThis(objmainNaviImgRight);
    }

    for (i = 1; i <= menuCount; i++) {
        if (i != subId) {
            if (topItemIndex == i)
                hideSubNavigation(i, 'true');
            else
                hideSubNavigation(i, 'false');
        }
    }
}

function hideSubNavigation(subId, isCurrentTopDir) {
    objSubNavi = document.getElementById("subNavi_" + subId);
    objMainNavi = document.getElementById("mainNavi_" + subId);
    objMainNaviImgLeft = document.getElementById("mainNaviImgLeft_" + subId);
    objmainNaviImgRight = document.getElementById("mainNaviImgRight_" + subId);

    if (objSubNavi)
        objSubNavi.style.display = "none";

    if (isCurrentTopDir == "false") {
        if (objMainNavi)
            objMainNavi.className = "link";

        if (objMainNaviImgLeft) {
            objMainNaviImgLeft.src = imgDir + "topnavi_left.png";
            iePNGLoader.loadThis(objMainNaviImgLeft);
        }

        if (objmainNaviImgRight) {
            objmainNaviImgRight.src = imgDir + "topnavi_right.png";
            iePNGLoader.loadThis(objmainNaviImgRight);
        }
    }
}

function OpenPrintPopup(wFile, wWidth, wHeight, wScrolling) {
    myWin = window.open(wFile, 'PrintWindow', 'width=' + wWidth + ',height=' + wHeight + ', status=yes, resizable=yes,scrollbars=' + wScrolling);
    myWin.moveTo((screen.width / 2) - (wWidth / 2), (screen.height / 2) - (wHeight / 2));
    myWin.focus();
}

function OpenWindow(wFile, wWidth, wHeight, wScrolling) {
    OpenPrintPopup(wFile, wWidth, wHeight, wScrolling);
}

/* PNG TRANSPARENZ IE6 STUFF */
function getBrowserVersion() {
    //test for MSIE x.x;
    var myReg = /MSIE (\d+\.\d+);/
    if (myReg.test(navigator.userAgent))
        return new Number(RegExp.$1);
    else
        return -1;
}

var iePNGLoader =
{
    loadThis: function (img) {
        if (navigator.userAgent.indexOf("MSIE") > -1 && getBrowserVersion() <= 6) {
            var pSrc = img.src;
            img.onload = null;
            img.src = imgDir + "leer.gif";
            img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, src='" + pSrc + "')";
        }
    }
};

/* FONT SIZE TOOL */
const_size = 70;
const_size_step = 20;
max_size = 110;
min_size = 70;

//window.onload = InitStartSize;

function InitStartSize() {
    size = parseInt(readCookie("size"));
    if (!size) {
        setCookie("size", const_size, 30);
        size = const_size;
    }

    document.body.style.fontSize = size + "%";
}

function textVerkleinern() {
    size = parseInt(readCookie("size"));
    if (!size || size > min_size)
        size = (!size) ? const_size : (size - const_size_step);
    setCookie("size", size, 30);

    document.body.style.fontSize = size + "%";
}

function textVergrossern() {
    size = parseInt(readCookie("size"));

    if (!size || size < max_size)
        size = (!size) ? const_size : (size + const_size_step);
    setCookie("size", size, 30);

    document.body.style.fontSize = size + "%";
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var cookieValue = null;
    var search = name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end))
        }
    }
    return cookieValue;
}

function setCookie(name, value, days) {
    eraseCookie(name);
    createCookie(name, value, days);
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function previousThema() {
    selectedThema = selectedThema - 1;
    if (selectedThema < 0)
        selectedThema = arrayThema.length - 1;

    setThemaValues();
}

function nextThema() {
    selectedThema = selectedThema + 1;
    if (selectedThema == arrayThema.length)
        selectedThema = 0;

    setThemaValues();
}

function previousIntranetNews(lblDatum, hlLink) {
    selectedThema = selectedThema - 1;
    if (selectedThema < 0)
        selectedThema = arrayThema.length - 1;

    setIntranetNews(lblDatum, hlLink);
}

function nextIntranetNews(lblDatum, hlLink) {
    selectedThema = selectedThema + 1;
    if (selectedThema == arrayThema.length)
        selectedThema = 0;

    setIntranetNews(lblDatum, hlLink);
}

function setThemaValues() {
    //alert("a")
    oThemaImage = document.getElementById("themaImage");
    oThemaHeadline = document.getElementById("themaHeadline");
    oThemaText = document.getElementById("themaText");
    oThemaMoreLink = document.getElementById("themaMoreLink");
    oThemaMoreIcon = document.getElementById("themaMoreIcon");


    arr = arrayThema[selectedThema];

    oThemaImage.src = arr[0].src;
    oThemaImage.alt = arr[2];
    oThemaHeadline.innerHTML = arr[2];
    oThemaHeadline.href = arr[1];
    oThemaHeadline.target = arr[4];
    oThemaText.innerHTML = arr[3]
    oThemaMoreLink.href = arr[1];
    oThemaMoreLink.target = arr[4];
    oThemaMoreLink.title = arr[2];
    oThemaMoreIcon.alt = arr[2];
}

function setIntranetNews(lblDatum, hlLink) {
    //alert("a")
    olblDatum = document.getElementById(lblDatum);
    ohlLink = document.getElementById(hlLink);

    arr = arrayThema[selectedThema];

    olblDatum.innerHTML = arr[1];
    ohlLink.href = arr[0];
    ohlLink.innerHTML = arr[2]
}

function navRollover(obj, imgSrc) {
    aImg = obj.getElementsByTagName("img");
    if (aImg.length > 0) {
        aImg[0].src = imgSrc;
    }


}

/** rad controls events **/
function handleKeyPress(sender, eventArgs) {
    if (eventArgs.keyCode == 27)
        sender.ClearSelection();
    else
        sender.ShowDropDown();

    objInput = document.getElementById(sender.InputID)
    processChange(objInput)
}

function handleClientFocus(sender) {
    var objInput = document.getElementById(sender.InputID)
    if (!objInput.onchange)
        objInput.onchange = function () { processChange(objInput) }
    //alert(item.ComboBox.HighlightedItem.GetText().length)
}

function processChange(obj) {
    len = obj.value.length == 0 ? 1 : obj.value.length;
    multiplier = 7;
    if (len < 10)
        multiplier = 10

    obj.style.width = (len * multiplier) + "px";
}

function handleClientSelectedIndexChanged(item) {
    clientSelectedIndexChanged(item, true);

    objInput = document.getElementById(item.ComboBox.InputID)
    objInput.focus();
}

function clientSelectedIndexChanged(item, createLi) {
    if (item.ComboBox.GetValue().length > 0 && createLi)
        createCategory(item.ComboBox.GetValue())

    item.ComboBox.ClearSelection();
    item.UnHighlight();
    item.Enabled = false;
    divItem = document.getElementById('TemplateControl_TagCloudPicker_radCombobox_c' + item.Index)
    if (divItem)
        divItem.className = 'ComboBoxItemDisabled_Telerik'
}

function createCategoryLi(val) {
    //get and create li element
    oUl = document.getElementById('selectedTags');
    var oLi = document.createElement('li')
    oLi.onclick = function () { removeCategory(oLi) }
    //oLi.setAttribute('onclick', 'removeCategory(this)');
    oLi.appendChild(document.createTextNode(val))
    oUl.appendChild(oLi);
}

function setSelectedItems(hiddenId) {
    oHidden = document.getElementById(hiddenId)
    if (oHidden && oHidden.value.length > 0) {
        arrString = oHidden.value.split('|');
        for (i = 0; i < arrString.length; i++) {
            var oComboBox = tlrkComboBoxes[1] //alert( + "my obj")
            oItem = oComboBox.FindItemByValue(arrString[i])
            if (oItem) {
                clientSelectedIndexChanged(oItem, false);
                createCategoryLi(arrString[i]);
            }
        }
    }
}

function handleItemsRequested(sender, eventArgs) {
    if (sender.Items.length == 0)
        sender.HideDropDown();
    else
        sender.ShowDropDown();
}


/** rad window ***/
function openWindow(url, winName) {
    var manager = GetRadWindowManager();
    var win = manager.GetWindowByName(winName);
    win.SetUrl(url);
    win.Show();
}

function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow)
        oWindow = window.radWindow;
    else if (window.frameElement.radWindow)
        oWindow = window.frameElement.radWindow;
    return oWindow;
}


function closeWindow(arg) {

    var oWindow = GetRadWindow();
    oWindow.argument = arg;
    oWindow.Close();
}

function OnWindowClose(radWindow) {
    if (radWindow.argument)
        document.location.href = radWindow.argument;
}

function showLeftNavigation() {
    obj = document.getElementById("siteSubNavigation");
    if (obj) {
        obj.style.display = "block";
    }
}

CONST_LANDS = 9
function prevLand() {
    activLand = getActiveLand()
    previousLand = activLand - 1;
    if (previousLand < 0)
        previousLand = CONST_LANDS - 1;

    document.getElementById("imageLand" + activLand).style.display = "none"
    document.getElementById("imageLand" + previousLand).style.display = "block"
}

function nextLand() {
    activLand = getActiveLand()
    nexLand = activLand + 1;
    if (nexLand >= CONST_LANDS)
        nexLand = 0;

    document.getElementById("imageLand" + activLand).style.display = "none"
    document.getElementById("imageLand" + nexLand).style.display = "block"
}


function getActiveLand() {
    for (i = 0; i < CONST_LANDS; i++) {
        if (document.getElementById("imageLand" + i).style.display == "block")
            return i;
    }
}

function previousThema() {
    selectedThema = selectedThema - 1;
    if (selectedThema < 0)
        selectedThema = arrayThema.length - 1;

    setThemaValues();
}

function nextThema() {
    selectedThema = selectedThema + 1;
    if (selectedThema == arrayThema.length)
        selectedThema = 0;

    setThemaValues();
}

function setThemaValues() {
    //alert("a")
    arr = arrayThema[selectedThema];

    oThemaImg.src = arr[0].src;
    oThemaImg.alt = arr[2];

    oThemaHeadline.innerHTML = arr[2];
    oThemaHeadline.href = arr[1];
    oThemaHeadline.target = arr[4];

    oThemaText.innerHTML = arr[3];

    oThemaImgMore.href = arr[1];
    oThemaImgMore.target = arr[4];
    oThemaImgMore.title = arr[2];
}

function OpenParagraph(obj) {
    oDiv = obj.parentNode.parentNode;
    if (oDiv.className.indexOf("aufklapItemActive") > -1)
        oDiv.className = "aufklapItem";
    else
        oDiv.className = "aufklapItemActive";

}

function openPopUp(url) {
    wWidth = 300;
    wHeight = 155;
    myWin = window.open(url, 'windowPopUp', 'width=' + wWidth + 'px,height=' + wHeight + 'px,resizable,scrollbars=0');
    myWin.moveTo((screen.width / 2) - (500 / 2), (screen.height / 2) - (wHeight / 2));
    myWin.focus();
    return false;
}

function openStandort(obj, errObj) {
    url = obj[obj.selectedIndex].value
    if (url.length > 0) {
        errObj.className = 'noDisplay';
        window.open(url, '_blank');
    }
    else
        errObj.className = ''

    return false;
}

