var isIE6 = (window.navigator.userAgent.indexOf('MSIE 6.0') > -1);
var baseURL = "";
var baseTmplURL = "";

/* swap world image */
function setWorld(activate) 
{
    if (activate == 1) {
        var elmwelt = document.getElementById('welt');

        if (typeof (elmwelt) != "undefined" && elmwelt != null) {
            //alert(elmwelt.getAttribute("backgroundImage"));
            elmwelt.style.backgroundImage = "url(http://www.kienbaum.de/portaldata/3/images/Kienbaum_Iconkarte_grau.jpg)";
            //alert(elmwelt.getAttribute("backgroundImage"));
        }
    }
    else 
    {
        var elmwelt = document.getElementById('welt');

        if (typeof (elmwelt) != "undefined" && elmwelt != null) {
            elmwelt.style.backgroundImage = "url(http://www.kienbaum.de/portaldata/3/images/Kienbaum_Iconkarte_blau.jpg)";
        }
    }
}


/* --=== resize window action ===-- */
var curr={}

if (isIE6)
{
    onresize=function()
    {
        var win=new getSize();
        if(curr.H!=win.H||curr.W!=win.W)
        {
            SetContentHeight();
            //alert('Window was resized!')
        }
        
        curr=new getSize();
    }
}

function getSize()
{
    if(typeof(window.innerHeight)=='number'||typeof(window.innerHeight)=='undefined')
    {//IE
        this.H=document.documentElement.clientHeight;
        this.W=document.documentElement.clientWidth;
    } 
    else 
    {//other
        this.H=window.innerHeight;
        this.W=window.innerWidth;
    }
}
/* ====== resize window end ======*/


/* --=== initialize procedures ===-- */
function Start()
{           
    SetContentHeight();
    InitNavigationLayers();
    CheckHeadline();
}


function CheckHeadline()
{
    var elmOvH1 = document.getElementById('overrideH1');
    
    if (typeof(elmOvH1) != "undefined" && elmOvH1 != null )
    {
        var elmStH1 = document.getElementById('staticH1');
        elmStH1.style.display = 'none';
        elmOvH1.style.display = 'block';
        
        var elmBrcrmb = document.getElementById('breadcrumbNavi');
        elmBrcrmb.innerHTML = elmBrcrmb.innerHTML + "<a href=\"\" id=\"brcOverriden\" class=\"brcrActiv\">" + elmOvH1.innerHTML + "</a>"
        
        var elmBrcOverridden = document.getElementById('brcOverriden');
        elmBrcOverridden.previousSibling.className = '';
    }
}

function SetContentHeight()
{
    if (isIE6)
    {
        var elmMainPane = document.getElementById('mainPane');
        var elmCenterPane = document.getElementById('center');
        if (elmMainPane != null)
        {
            elmMainPane.style.height = (document.body.clientHeight - 267 - 42) + "px";
        }
        if (elmCenterPane != null)
        {
            elmCenterPane.style.height = (document.body.clientHeight - 267 - 42 - 44) + "px";
        }        
    }
}

function InitNavigationLayers()
{
    var elmLayers = $$('.topNaviItemLayer');
    var x=0;
    
    //alert("" + elmLayers.length);
    for(x=0; x < elmLayers.length; x++)
    {
       elmLayers[x].className = 'topNaviItemLayerIE';
       
       var elmChilds =  elmLayers[x].childElements();
       //alert(elmChilds.length-1);
       elmChilds[elmChilds.length-1].style.borderBottom = "none";
       
        //alert("" + elmLayers);
    }
}

/* ====== end initialize procedures ====== */



/* --=== Layer Navigations ===-- */
function showLayer(lID, show)
{
    //if (show) 
        ShowLayerLater(lID, show);
    //else
    //    window.setTimeout(function(){ShowLayerLater(lID, show)}, 100);
}

function ShowLayerLater(lID, show)
{
    var elm = document.getElementById("layer" + lID);
    var topElm = document.getElementById('topNaviItem' + lID);
    
    if (elm != null)
    {
        elm.style.left = 181 + topElm.offsetLeft + "px";
        elm.style.display = (show)? 'block' : 'none';
    
        topElm.style.color = (show)? '#FFFFFF' : '#666666';
        topElm.style.backgroundColor = (show)? '#B8B8B8' : '';
    }
}

function CheckJSCalls(ttl, tabid, url)
{
    //alert('ttl: ' + ttl + " id: " + tabid + " url: " + url);
    if (ttl == 'International_Layer')
        ShowLocations(baseURL + "desktopdefault.aspx/tabid-" + tabid + "/");
    else if (ttl == 'National_Layer')
        ShowLocations(baseURL + "desktopdefault.aspx/tabid-" + tabid + "/");
    else
        location.href = baseURL + url;
}
/* ===== Layer Navigation END ===== */


function ShowLocations(url)
{
    var elmLocations = document.getElementById('locations');
    var elmLocFrame = document.getElementById('loc_frame');
    
    if (elmLocations.style.display == 'none')
    {
        elmLocFrame.src = url;
        elmLocations.style.display = 'block';
    }
    else
    {
        elmLocations.style.display = 'none';
        elmLocFrame.src = 'about:blank';
    }
}

function CallUrl(url)
{    
    if (url.indexOf('http://') == -1) url = "http://" + url;
    location.href = url;
}

function CallBaseUrl(url)
{
    url = baseURL + url;
    if (url.indexOf('http://') == -1) url = "http://" + url;
    location.href = url;
}

function ShowFlashMatrix()
{   
    var flashObject = null;
    
    if (window.document['flashteaser']) 
    {
        flashObject = window.document['flashteaser'];
    }
  
    if (navigator.appName.indexOf('Microsoft Internet')==-1)
    {
        if (document.embeds && document.embeds['flashteaser'])
        {
            flashObject = document.embeds['flashteaser']; 
        }
    }
    else if (navigator.appName.indexOf('Microsoft Internet')!=-1)
    {
        flashObject = document.getElementById('flashteaser');
    }

    var flashMatrixPath = baseTmplURL + "flash/matrix.swf?xmlfile=" + baseTmplURL + "flash/xml/matrix" + actualLangId + ".xml";
  
    if (flashObject.movie != null)
    {
        flashObject.movie = flashMatrixPath;
    }
    else if(flashObject.src != null)
    {
        flashObject.src = flashMatrixPath;  
    }
}    

function ProcessMatrixSelection()
{    
    var elmBranch = document.getElementById('matrixBranch');
    var elmAccomp = document.getElementById('matrixAccomplishment');

    if (elmBranch.selectedIndex == 0 && elmAccomp.selectedIndex == 0) 
        return;
    else if (elmBranch.selectedIndex > 0 && elmAccomp.selectedIndex > 0)
    {
        location.href = baseURL + arMatrix[elmBranch.options[elmBranch.selectedIndex].text][elmAccomp.options[elmAccomp.selectedIndex].text];
    
    } else if (elmBranch.selectedIndex > 0)
    {
        location.href = baseURL + elmBranch.options[elmBranch.selectedIndex].value;
    }else
    {
        location.href = baseURL + elmAccomp.options[elmAccomp.selectedIndex].value;           
    }
}

/* ======== Matrix Selection END ========*/