﻿// Dependencies on other functions in external javascript files
// Global.js: GetBrowserType, ShowElement, HideElement

var _oTab;
var pcTabBar;

function AttachEventsToTable(el)
{
    pcTabBar = el;
    
    if(window.addEventListener) // Mozilla, Netscape, Firefox
    { 
	    pcTabBar.onmouseover = TabOn;
	    pcTabBar.onmouseout = TabOff;
    } 
    else // IE
    {
	    pcTabBar.attachEvent('onmouseover', TabOn);
	    pcTabBar.attachEvent('onmouseout', TabOff);
	}
}

function LoadTabScript()
{
    var tab;
    var firstTabLoaded = false;
    
    var children = pcTabBar.rows[0].cells[0].childNodes;    
    
    // Default eerste tab tonen.
    for (var i = 0; i < children.length; i++)
	{   
		tab = children[i];
		if (tab.className == "tab")
		{
		    // Verberg alle elementen met tab classname. 
		    // Dit kan niet voor alle browsers in de stylesheet afgehandeld worden vanwege style.display en visibility.collapse issue;
		    HideElement(document.getElementById(tab.getAttribute("tabID")));
		}
	}

    for (var i = 0; i < children.length; i++)
	{   
		tab = children[i];
	    if (tab.className == "tab tabOn")
	    {
		    TabDown(null, tab, true);
		    return;
	    }
    }    

    TabDown(null, children.firstChild, true);
}

function TabDown(event, oTab, bForce)
{   
    var o = oTab;
        
    if (o.className == "tab" || bForce)
	{
	    HideElement(document.getElementById('hrGlowTab'));

        o.className = "tab tabOn";
		TabShow(document.getElementById('hrGlowTab'), o);
        
        var tabToShow = document.getElementById(o.getAttribute("tabID"));
        
        ShowElement(tabToShow);

		if (_oTab)
		{
		    var tabToHide = document.getElementById(_oTab.getAttribute("tabID"));
		    _oTab.className = "tab";
		    HideElement(tabToHide);
		}

		_oTab = o;
	}
}

function TabShow(elToShow, o)
{    
	try
	{
	    elToShow.style.left = o.offsetLeft + 1;
		elToShow.style.width = o.offsetWidth - 2;		
		elToShow.style.top = o.offsetTop - 4;
		
		ShowElement(elToShow);
	}
	catch(e)
	{}
}

function TabKey(evt, el)
{
    if (evt.keyCode == 13)
	{
		el.click();
	}
}

function TabOn(evt)
{
    var el;
    if (window.event)
    {
        el = window.event.srcElement;
    }
    else
    {
        el = evt.target;
    }
    
    if(el.id != "hrSelectedTab" && el.tagName == "SPAN")
    {
        el.style.color = "#5485A7";
        TabShow(document.getElementById('hrGlowTab'), el);        
    }
}

function TabOff(evt)
{
    var el;
    if (window.event)
    {
        el = window.event.srcElement;
    }
    else
    {
        el = evt.target;
    }
    
    el.style.color = "#000000";
    HideElement(document.getElementById('hrGlowTab'));
}

function GetCurrentTab()
{
	return _oTab;
}

function GetCurrentTabContent()
{
	return document.getElementById(_oTab.getAttribute("tabID"));
}
