var selectedTabPage = null;
var selectedTab = null;

function InitTab()
{
    var hiddenTab         = document.getElementById( "tabPane_ActiveTab" ); 
    if( hiddenTab != null)
    {
        var currentSelectedTab = hiddenTab.value;
        if( currentSelectedTab != null )
        {
            // select the last selected tab
            SelectTab(  currentSelectedTab );
        }
        else
        {
            alert('[SmartTabPane]: Hidden field value is null!');            
        }
    }
    else
    {
        alert('[SmartTabPane]: Hidden field not found!');
    }   
}

function SelectTab(tabID) 
{
    if ( !hasSupport())
    {
        alert('No support!');
        return;
    } 
	var tab         = document.getElementById( tabID );
	var tabPage     = document.getElementById( tabID + "_Page" );
	
	if( tab != null && tabPage != null )
	{
	    if( selectedTab != null )
	    {
	        selectedTab.className = "tabSelector";
	    }
	    selectedTab             = tab;
	    selectedTab.className   = "tabSelectorSelected";
	    
	    if( selectedTabPage != null )
	    {
	        selectedTabPage.style.display = 'none';
	    }		    
	    selectedTabPage                 = tabPage;
	    selectedTabPage.style.display   = 'block';
//	    var hiddenTab           = document.getElementById( "tabPane_ActiveTab" );
//	    if( hiddenTab != null)
//        {
//            hiddenTab.value = selectedTabPage.id;
//            //alert('[SmartTabPane]: Setting hidden field value to:' + hiddenTab.value);            
//        }	
//        else
//        {
//            alert('[SmartTabPane]: Hidden field value is null!');                        
//        }    
	}	    	
	
}
function HoverTab(tabID)
{
    var obj             = document.getElementById(tabID);    
    if( obj != null )
	{
	    if( selectedTab == obj)
	    {
	        obj.className = "tabSelectorSelected";	            
	    }
	    else
	    {
	        obj.className = "tabSelectorHover";
	    }	 
	}
}
function UnhoverTab(tabID)
{
    var obj             = document.getElementById(tabID);    
    if( obj != null )
	{
	    if( selectedTab == obj)
	    {
	        obj.className = "tabSelectorSelected";	            
	    }
	    else
	    {
	        obj.className = "tabSelector";
	    }	    
	}
}



function hasSupport() {

	if (typeof hasSupport.support != "undefined")
		return hasSupport.support;
	
	var ie55 = /msie 5\.[56789]/i.test( navigator.userAgent );
	
	hasSupport.support = ( typeof document.implementation != "undefined" &&
			document.implementation.hasFeature( "html", "1.0" ) || ie55 )
			
	// IE55 has a serious DOM1 bug... Patch it!
	if ( ie55 ) {
		document._getElementsByTagName = document.getElementsByTagName;
		document.getElementsByTagName = function ( sTagName ) {
			if ( sTagName == "*" )
				return document.all;
			else
				return document._getElementsByTagName( sTagName );
		};
	}

	return hasSupport.support;
}
