﻿function updateRsLink()
{
    document.getElementById('aReadspeaker').href = 'http://app.readspeaker.com/proreader/proreader.php?cid=4753&amp;lang=nl_nl&amp;url=' + encodeURIComponent(window.top.Eskion.Main.location.href);
    document.getElementById('aReadspeaker').style.visibility = 'visible';
}

function updatePage()
{
    var frmMain = document.getElementById('frmMain');
    
    if (frmMain.contentWindow && frmMain.contentWindow.document && frmMain.contentWindow.document.body)
    {            
        if (window.top.Eskion.Main.location.href.toUpperCase().indexOf(_strStartPageID.toUpperCase()) > -1)
            document.getElementById('trEntrance').style.display = 'none';
        else
            document.getElementById('trEntrance').style.display = '';
    }
    
    stretchPage();
}

function stretchPage()
{
    document.getElementById('divMenuTreeContainer').style.height = '';
    document.getElementById('frmMain').height = '1';
    document.getElementById('frmRightBar').height = '1';
    setTimeout(function() {updateHeight();}, 1);
}

function updateHeight()
{
	var trContent = document.getElementById('trContent');
	var tblLeftBar = document.getElementById('tblLeftBar');
	var frmMain = document.getElementById('frmMain');
	var frmRightBar = document.getElementById('frmRightBar');
	var trBottomMargin = document.getElementById('trBottomMargin');
	var trFooter = document.getElementById('trFooter');
	var divMenuTreeContainer = document.getElementById('divMenuTreeContainer');
	var intScrollTop = 0;
	var intContentY = getElementY(trContent);
	var intMainY = getElementY(frmMain);
	var intYMargin = intMainY - intContentY;
	var intContentMinHeight = document.body.clientHeight - (intContentY + trBottomMargin.offsetHeight + trFooter.offsetHeight);
	var intMainMinHeight = document.body.clientHeight - (intMainY + trBottomMargin.offsetHeight + trFooter.offsetHeight);
    var intMainHeight = 0;
    var intLeftBarHeight = 0;
    var intRightBarHeight = 0;
    var intHeight = 0;

    intLeftBarHeight = tblLeftBar.offsetHeight;
	
    if (frmRightBar.contentWindow && frmRightBar.contentWindow.document && frmRightBar.contentWindow.document.body)
	    intRightBarHeight = (frmRightBar.contentWindow.document.body.scrollHeight);
	
	try
	{
	    if (frmMain.contentWindow && frmMain.contentWindow.document && frmMain.contentWindow.document.body)
	    {
	        intScrollTop = frmMain.contentWindow.document.body.scrollTop;
	        intMainHeight = (frmMain.contentWindow.document.body.scrollHeight);
        }
    }
    catch (ex)
	{
    	intMainHeight = intMainMinHeight;
    }
	
	
	if (intMainHeight < intMainMinHeight)
	    intMainHeight = intMainMinHeight;
	    

    if (intMainHeight + intYMargin >= intRightBarHeight && intMainHeight + intYMargin >= intLeftBarHeight)
    {
        frmMain.height = intMainHeight;
        frmRightBar.height = intMainHeight + intYMargin;
        divMenuTreeContainer.style.height = ((intMainHeight + intYMargin) - 133) + 'px';
    }
	else if (intRightBarHeight >= intMainHeight + intYMargin && intRightBarHeight >= intLeftBarHeight)
	{
        frmMain.height = intRightBarHeight - intYMargin;
        frmRightBar.height = intRightBarHeight;
        divMenuTreeContainer.style.height = (intRightBarHeight - 133) + 'px';	
    }
    else
    {
        frmMain.height = intLeftBarHeight - intYMargin;
        frmRightBar.height = intLeftBarHeight;
        divMenuTreeContainer.style.height = (intLeftBarHeight - 133) + 'px';
    }	
	
	try
	{
		if (frmMain.contentWindow && frmMain.contentWindow.document && frmMain.contentWindow.document.body)
		{
		    frmMain.contentWindow.document.body.scrollTop = 0;
	
		    if (intScrollTop > 0)
			    document.body.scrollTop = intScrollTop + intContentY;
	    }
	}
	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 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 == 'doorzoek deze site')
		txtSearchBox.value = '';
}

function searchBoxBlur(txtSearchBox)
{
	if (txtSearchBox.value == '')
		txtSearchBox.value = 'doorzoek deze site';
}

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();
}

