<% /*
     $Revision$
     $Id$

     Note: Het eerste tabje wordt altijd automatisch geactiveerd.
*/ %>

<%
var func_enabled = new Array();

var sql = "SELECT DISTINCT f.fac_functie_code"
        + "  FROM fac_v_webgebruiker w, fac_functie f "
        + "  WHERE w.prs_perslid_key= "+user_key
        + "    AND w.fac_functie_key=f.fac_functie_key";
oRs = Oracle.Execute(sql);

while( !oRs.eof )
{
  func_enabled[oRs("fac_functie_code").Value]=true;
  oRs.MoveNext();
}

var _FTabs = new Array();

function AddTabItem(str, id, auth1, auth2, handler, pinnable)
{
    // PF: Hier controleren op READ rechten op een degelijker manier.
    if( handler != '' &&
        ((func_enabled[auth1]     || func_enabled[auth2]) ||
         (auth1=='' && auth2=='')
        )
      )
    {
      _FTabs.push({str: str, id: id, auth1: auth1, auth2: auth2, handler: handler, pinnable: pinnable });
    }
}


function CreateTabs()
{
    var i,id;
%>
<script type="text/javascript">
    $(document).ready(
        function()
        {
            $tabs = $("#theTabs").tabs({ activate: function(event ,ui)
                                                   {
                                                     var tabparam = getCustomParameters();
                                                     tabparam = tabparam.replace(/[&]/, ""); // verwijder eerste &
                                                     tabSetParam(tabparam);
                                                     tabRefresh();
                                                   }
                                       });

            resizetabIframe();
            var timerID=null;
            window.onresize = function()
                {
                 	if (timerID) clearTimeout(timerID);
                     timerID = setTimeout(resizetabIframe, 100);// use a delay for IE because the resize event fires repeatly
                }
        });

    var _Params = "";
    var _aPinned = new Array();

    function togglePin(pindiv, i)
    {
        if (_aPinned[i])
            _aPinned[i] = false;
        else
            _aPinned[i] = _Params;

        $(pindiv).removeClass("fa-unlock fa-lock");
        if (_aPinned[i])
            $(pindiv).addClass("fa-lock");
        else
            $(pindiv).addClass("fa-unlock");
    }
    function tabSetParam(param)
    {
        _Params=param;
    }
    function tabRefresh()
    {
        if (!window.$tabs)
            return;
        var params = _Params;
        var active = $tabs.tabs('option','active');
        var tab = $tabs.find( ".ui-tabs-nav li" )[active];
        if (!tab) // waarschijniljk helemaal geen tabs
            return;
        var panelId = $( tab ).attr( "aria-controls" );
        var frm = document.getElementById(panelId);
        var handlerpage = frm.getAttribute("orgsrc");

        if (_aPinned[active])
            params = _aPinned[active]; // Originele parameters blijven gebruiken
        frm.src = handlerpage + (handlerpage.indexOf('?')==-1?'?':'&') + params
    }

function resizetabIframe()
{
    if (!window.$tabs)
        return;
    var tabsHeaderHeight = ($(".ui-tabs-nav").height());
    var active = $tabs.tabs('option','active');
    var tab = $tabs.find( ".ui-tabs-nav li" )[active];
    if (!tab) // waarschijniljk helemaal geen tabs
        return;
    var panelId = $( tab ).attr( "aria-controls" );
    var frm = document.getElementById(panelId);
    try
    {
        var frmcontent = $(frm).contents(); // testing
        var newHeight = frmcontent.outerHeight();
        $(frm).height(newHeight);
    }
    catch (e)
    {
        return; // soms nog bezig met herladen
    }
};
</script>

    <ul class='ui-tabs-nav ui-helper-clearfix'>
    <% for (i=0; i<_FTabs.length; i++) // eerst de kopjes
    {
        %>
        <li class='ui-state-default ui-corner-top'><a href='#fr<%=_FTabs[i].id%>'><%=_FTabs[i].str%>
            </a>
            <%=_FTabs[i].pinnable?"<span class='details fa fa-unlock fa-fw' onClick='togglePin(this, "+i+")'></span>":""%>
        </li>
        <%
    } %>
    </ul>
    <% for (i=0; i<_FTabs.length; i++) // dan de iframes
    {
      %>
        <iframe src="../Shared/empty.html" frameborder='0' framespacing='0'
                orgsrc='<%=_FTabs[i].handler%>' name='fr<%=_FTabs[i].id%>' id='fr<%=_FTabs[i].id%>'
                width='100%' height='200px' style='overflow:auto;padding: 0px!important'
                onload='resizetabIframe()'>
             <!-- Wordt via tabRefresh() gevuld-->
        </iframe>
      <%
    } %>
<%
    return _FTabs.length;
}
%>

