﻿var _blnLeftFrameLoaded = false;
var _blnMainFrameLoaded = false;

function updatePage()
{    
    var blnStartPage;
    if (_blnAlways)
    {
        document.getElementById('frmLeft').style.display = '';
        return;
    }  

    try
        {
            if (_strStartPageID != "")
                blnStartPage = window.top.Eskion.Main.location.href.toLowerCase().indexOf(_strStartPageID.toLowerCase()) > -1
            else
                blnStartPage = false
        if (_blnTabMenu)
        {
            if (blnStartPage)  
            {  
                document.getElementById('frmLeft').style.display = 'none';
                document.getElementById('tdLeft').style.width = '0px';
            }
            else
            {
                document.getElementById('frmLeft').style.display = '';
                document.getElementById('tdLeft').style.width = '174px';
            }
                
        } 
        else
        {
            if (blnStartPage)
            {
                document.getElementById('frmLeft').style.display = '';
                document.getElementById('tdLeft').style.width = '174px';
            }
            else
            {
                document.getElementById('frmLeft').style.display = 'none';
                  document.getElementById('tdLeft').style.width = '174px';
            }
        }
    }
    catch(ex)
    { 
        if (_blnTabMenu)
        {
            document.getElementById('frmLeft').style.display = '';
            document.getElementById('tdLeft').style.width = '174px';
        }
        else
        {
            document.getElementById('frmLeft').style.display = 'none';
            document.getElementById('tdLeft').style.width = '0px';
        }
    }    
}

function stretchPage()
{
    if (_blnLeftFrameLoaded)
    {
        document.getElementById('trFooter').style.display = 'none';
        document.getElementById('divLeftContainer').style.height = '';
        document.getElementById('frmLeft').height = (Base.getWindowHeight() - 240); // '1';
        document.getElementById('frmMain').height = (Base.getWindowHeight() - 240); //'1';
        
        setTimeout(function() {updateHeight();}, 1);
    }
}

function updateHeight()
{
	var divLeftContainer = document.getElementById('divLeftContainer');
	var frmLeft = document.getElementById('frmLeft');
	var frmMain = document.getElementById('frmMain');
	var trContent = document.getElementById('trContent');
	var trFooter = document.getElementById('trFooter');
	var intY = getElementY(trContent);
	var intHeight = 0;
	var intMinHeight = 0;
	var intMinFrameheight = 350;
	
    document.getElementById('trFooter').style.display = '';
	intMinHeight = document.body.clientHeight - (intY + trFooter.offsetHeight);

    if (frmLeft.style.display != 'none' && frmLeft.contentWindow && frmLeft.contentWindow.document && frmLeft.contentWindow.document.body)
        frmLeft.height = frmLeft.contentWindow.document.body.scrollHeight;
    
    try
    {
        if (frmMain.contentWindow && frmMain.contentWindow.document && frmMain.contentWindow.document.body)
        {
            intScrollTop = frmMain.contentWindow.document.body.scrollTop;
            intHeight = frmMain.contentWindow.document.body.scrollHeight;
        }
    }
    catch(ex)
    {
        intHeight = intMinHeight;
    }    
    
    if (!_blnMainFrameLoaded)
    {
        if (intHeight < intMinHeight)
	        intHeight = intMinHeight;
	}
    
    if (divLeftContainer.offsetHeight > intHeight)
        intHeight = divLeftContainer.offsetHeight;


    if (intHeight < intMinFrameheight)
        intHeight = intMinFrameheight;
    
    divLeftContainer.style.height = intHeight + 'px';
    frmMain.height = intHeight;
        
    try
	{
		if (frmMain.contentWindow && frmMain.contentWindow.document && frmMain.contentWindow.document.body)
		{
		    frmMain.contentWindow.document.body.scrollTop = 0;
	
		    if (intScrollTop > 0)
			    document.body.scrollTop = intScrollTop + intY;
	    }
	}
	catch(ex)
	{
	
	}
}

function getElementY(objElement)
{
    var intY = 0;
    var intIEOffsetFix = 0;
    var intScrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    
    if (window.top == window.self && navigator.appName.toLowerCase() == 'microsoft internet explorer' && window.event && document.compatMode == 'BackCompat')
        intIEOffsetFix = 2;
    
    if (objElement.getBoundingClientRect())
    {
        var objBody = document.documentElement || document.body;
        return (objElement.getBoundingClientRect().top - intIEOffsetFix - objBody.clientTop);
    }
    else
    {
        while (objElement.tagName.toLowerCase() != 'body' && objElement.tagName.toLowerCase() != 'html')
        { 
            intY += objElement.offsetTop;
            
            if (objElement.clientTop)
                intY += objElement.clientTop;
            	                
            if (objElement.offsetParent)
                objElement = objElement.offsetParent;
            else
                break;
        } 
        
        if (objElement.tagName.toLowerCase() == 'body' || objElement.tagName.toLowerCase() == 'html')
            intY += objElement.offsetTop;
    
        return intY - intIEOffsetFix - intScrollTop;
    }        
}

function stretchFooter()
{
    var frmFooterLogo = document.getElementById('frmFooterLogo');
    
    if (frmFooterLogo.src != '' && frmFooterLogo.contentWindow && frmFooterLogo.contentWindow.document && frmFooterLogo.contentWindow.document.body)
    {
        frmFooterLogo.style.display = '';
        frmFooterLogo.width = frmFooterLogo.contentWindow.document.body.scrollWidth;
    }
}

function search()
{
	if (document.getElementById('txtSearchBox').value != "")
		window.top.Eskion.Main.location.href = 'search/searchresults.aspx?Q=' + document.getElementById('txtSearchBox').value;
}

function searchBoxFocus(txtSearchBox)
{
	if (txtSearchBox.value == 'zoek op trefwoord')
		txtSearchBox.value = '';
}

function searchBoxBlur(txtSearchBox)
{
	if (txtSearchBox.value == '')
		txtSearchBox.value = 'zoek op trefwoord';
}

function openQuickLaunchItem(strUrl, intFrame, strTreeCode)
{
    if (intFrame == 0)
        window.top.location.href = strUrl;
    else if (intFrame == 1)
        window.open(strUrl);
    else
        window.top.Eskion.location.href = 'Frameset.aspx?ContentURL=' + encodeURIComponent(strUrl) + '&TreeCode=' + strTreeCode;
}

function openLogin() 
{
	var top = (screen.height-240)/2;
	var left = (screen.width-350)/2;
	window.open('login/login.aspx','Login','top='+top+',left='+left+',width=350,height=240,toolbar=no,menubar=no,status=no,resizable=no,scrollbars=no');
}

function printDocument()
{
    window.top.Eskion.Main.focus();
    window.top.Eskion.Main.print();
}

function HighlightLeft(strcode)
{
    deHighlightLeft();
    _strHighlightedLeft = strcode;
    var strArray = new Array();
    strArray = strcode.split('.');
    var x;

    for (var x = 0; x < strArray.length - 1; x++)
    {
        var strTemp;
        strTemp = 'objMenuTree_';
        var y;
        for (var y = 0; y <= (x + 1); y ++)
        {
            strTemp += strArray[y].toString();
            strTemp += '.';
        }
        strTemp = strTemp.substring(0, strTemp.length - 1)
        strTemp += '_A';
        if (document.getElementById(strTemp))
        {
            document.getElementById(strTemp).className = document.getElementById(strTemp).className.replace('_Hover','');
		    document.getElementById(strTemp).className = document.getElementById(strTemp).className.replace('_Highlight','');
		    document.getElementById(strTemp).className += '_Highlight';
        }
    }
}

function deHighlightLeft()
{
    if (_strHighlightedLeft != '')
    {
        var strArray = new Array();
        strArray = _strHighlightedLeft.split('.');
        var x;
        for (var x = 0; x < strArray.length - 1; x++)
        {
	        // Dehighlight all parent items
            var strTemp;
            strTemp = 'objMenuTree_';
            var y;
            for (var y = 0; y <= x; y ++)
            {
                strTemp += strArray[y].toString();
                strTemp += '.';
            }
            strTemp = strTemp.substring(0, strTemp.length - 1)
            strTemp += '_A';
            if (document.getElementById(strTemp))
            {
                document.getElementById(strTemp).className = document.getElementById(strTemp).className.replace('_Highlight','');
	        }
        }

        // Dehighlight the actual item that was opened
        var strTemp;
        strTemp = "objMenuTree_";
        strTemp += _strHighlightedLeft;
        strTemp += "_A";
		
        if (document.getElementById(strTemp))
        {
            document.getElementById(strTemp).className = document.getElementById(strTemp).className.replace('_Highlight','');
        }
    }
}

function ShowDropDown(strTreecode)
{
	HideDropDown();
	var objParentTable = document.getElementById('TABLE_QuickLaunchTab');
	var objParent = document.getElementById(strTreecode);
	var objChild = document.getElementById('DD_' + strTreecode);
	var intDropDownLeft = 0;
	//CalculateOffset
	if (objParent)
	{			
		if(objChild)
		{
		    objChild.style.display = 'block';
            objChild.style.left = objParent.getBoundingClientRect().right - objChild.clientWidth  + 'px';
            objChild.style.top = objParent.getBoundingClientRect().top + objParent.offsetHeight + getScrollY() + 'px';
			
			_strShowingDropDown = 'DD_' + strTreecode;					
		}
	}
}

function getScrollY()
{
    scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number')
    {
        //Netscape compliant
        scrOfY = window.pageYOffset;        
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
    {
        //DOM compliant
        scrOfY = document.body.scrollTop;        
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
    {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;        
    }
    return scrOfY;
}

function HideDropDown()
{
	if (document.getElementById(_strShowingDropDown))
	{
		document.getElementById(_strShowingDropDown).style.display = 'none';
	}
}

function clearTimer()
{
    window.clearTimeout(_objTimer);
    _blnAllowHide = false;
}

function setTimer(intTimeout)
{
	if (!intTimeout)
	{
		intTimeout = 1000;
	}

	if (_blnAllowHide)
	{
		_objTimer = setTimeout('HideDropDown();', intTimeout);
	}
}

function Hover(strCode)
{
	if(document.getElementById(strCode).className != 'QuickLaunchTabItem_Highlight')
	{
		document.getElementById(strCode).className = 'QuickLaunchTabItem_Hover';
	}
}

function deHover(strCode)
{
	if(document.getElementById(strCode).className == 'QuickLaunchTabItem_Hover')
	{
		document.getElementById(strCode).className = 'QuickLaunchTabItem';
	}
}

function HoverDropDown(strCode)
{
	if(document.getElementById(strCode))
	{
		document.getElementById(strCode).className = 'DropDownItem_Hover';
	}
}

function HoverOutDropDown(strCode)
{
	if(document.getElementById(strCode))
	{
		document.getElementById(strCode).className = 'DropDownItem';
	}
}

function Highlight(strCode)
{
    deHighlight();
    _strHighlightedMain = strCode;

    document.getElementById(strCode).className = 'QuickLaunchTabItem_Highlight';
}

function deHighlight()
{
    if (_strHighlightedMain != '')
    {
		document.getElementById(_strHighlightedMain).className = 'QuickLaunchTabItem';
	}
}

function readspeaker(objElement, rs_call, rs_file_name)
{    
	var x=document.getElementById('rs_div');
	
	rs_call=rs_call+'&output=audio';
	rs_call=escape(rs_call);
	start_rs_table='<table style="border:1px solid #aeaeae; font-size: 10px;"><tr><td>';
	rs_embed='<object type="application/x-shockwave-flash" data="http://media.readspeaker.com/flash/rplayerpro.swf?mp3='+rs_call+'&autoplay=1&rskin=bump" height="20" width="250"><param name="movie" value="http://media.readspeaker.com/flash/rplayerpro.swf?mp3='+rs_call+'&autoplay=1&rskin=bump"><param name="quality" value="high"><param name="SCALE" value="exactfit"><param name="wmode" value="transparent"><embed wmode="transparent" src="http://media.readspeaker.com/flash/rplayerpro.swf?mp3='+rs_call+'&autoplay=1&rskin=bump" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwaveflash" scale="exactfit" height="20" width="250"></embed></object>';
	close_rs='<br /><a href="#" onclick="close_rs_div(); return false;">Sluiten</a>';
	end_rs_table='</td></tr></table>';
	
	x.innerHTML=start_rs_table+rs_embed+close_rs+end_rs_table;
	
	x.style.left = ((objElement.getBoundingClientRect().left - x.offsetWidth) + (objElement.offsetWidth)) + 'px';
}

function close_rs_div()
{
	var x=document.getElementById('rs_div');
	x.innerHTML='';
}
