/**
 * Interactive tab component related javascript module.  It is responsible for 
 * building interactive tab component, currently it has 7 tabs.  Also, it 
 * handles the responsibility of initializing other components by Ajax. Based 
 * on the selected tab, it needs to update respective components with related
 * data.  
 *
 * @author Veeresh D. 
 * @date March 2008
 */

var curId, curColor, preId, cTab, tempEle
var fontColor, backColor, prevColor, defColor;
var initFlag;

var tab =
{
    /**
    Initializes the Tab controller component with necessary content and styles
    */
    initTabPanel: function(tabNo)
	{
	    if ( !(tabNo > 0) )
	        tabNo = 1; 
	    fontColor 	= "#116591";
	    backColor 	= "STEELBLUE";
	    prevColor 	= fontColor;
	    defColor 	= "gray";
	    cTab 		= 0;
	    initFlag	= 0;
	    tab.setTabFocus(tabNo);
	    tab.setTabDivdata(tabNo, tabNo);
	    getfullDateValue();
	    initFlag	= 1;
	},
	
	/**
    Sets the current tab focus based on onmouseover over particular tab

    @param tid Id of a current tab and needs to get focused
    */
    setTabFocus: function(tid)	//Set Focus, On mouseover
    {
	    curId = tid;			//For onclick
	    tempEle = document.getElementById("tabId" + tid);   	
	    tempEle.style.backgroundImage = "url(images/panelbgBlueTab.gif)";
	    tempEle.style.color = "white";//fontColor;
	    document.getElementById("tabLinkId" + tid).style.color = "white";
	    curColor = tempEle.style.backgroundImage;
    },
    
    /**
    Resets the current tab focus based on onmouseout event over previously visited tab
    
    @param tid Id of a current tab and needs to get unfocused
    */
    resetTabFocus: function(tid)	//Delete Focus , On mouseout
    {
	    if ( preId == tid )		//To retain the previous color
	    {
		    tempEle = document.getElementById("tabId" + curId);
		    tempEle.style.background = prevColor;		    
	    }
	    else
	    {
	        tempEle = document.getElementById("tabId" + tid);
		    tempEle.style.color = fontColor;
		    document.getElementById("tabLinkId" + tid).style.color = fontColor;
		    tempEle.style.backgroundImage = "url(images/panelbgWhiteTab.gif)";
	    }
    },
    
    /**
    Sets the current tab focus based on onclick event over particular tab, It also
    loads necessary components of current and month's issues, top articles etc
    
    @param k 
    @param tn 
    */
    setTabDivdata: function(tn)
    {
	    cTab = tn;
	    k = tn;
	    if ( document.getElementById("tabLinkId" + preId))
	        document.getElementById("tabLinkId" + preId).style.color = "#116591";
	        
	    if (preId != null && preId != k)	//To set back the default color of previously clicked tab
	    {
		    tempEle = document.getElementById("tabId" + preId);
		    tempEle.style.color = "#116591";//fontColor;
		    tempEle.style.backgroundImage = "url(images/panelbgWhiteTab.gif)";
	    }	
	    if ( tn == 1 && initFlag == 0)		//ComSoc Home
	    {
		    components.penel.showMonthIssues();		/* Control gets in here on initial load event */
		    components.penel.showCurrentIssues();		
		    components.penel.getAds("ads/mainAds.htm");	
		    searchResults.emptySearchResults();			
		    components.penel.getTopArticles("Home");    //It may cause synchronization problem.  Yet it needs to investigate further		    
	    }
	    else if ( tn == 1 && initFlag == 1)	//ComSoc Home
	    {	
		    components.penel.getCurrentIssues("home/AllCurrentIssues.htm"); //In >> PanelBox.js		
		    components.penel.getMonthIssues("home/AllMonthsIssues.htm"); //In >> PanelBox.js		
		    components.penel.getAds("ads/mainAds.htm");	
		    components.penel.getTopArticles("Home");        
	    }
	    else if ( tn == 2)	//Journal
	    {
		    components.penel.getCurrentIssues("journal/JournalCurrentIssues.htm");
		    components.penel.getMonthIssues("journal/JournalMonthsIssues.htm"); //In >> PanelBox.js		
		    components.penel.getAds("ads/mainAds.htm");	
		    components.penel.getTopArticles("Journal");	
	    }
	    else if ( tn == 3)	//Magazine
	    {
		    components.penel.getCurrentIssues("magazine/MagazineCurrentIssues.htm");
		    components.penel.getMonthIssues("magazine/MagazineMonthsIssues.htm"); //In >> PanelBox.js		
		    components.penel.getAds("ads/mainAds.htm");		
		    components.penel.getTopArticles("Magazine");			
	    }
	    else if ( tn == 4)	//Conference Proceedings
	    {
		    components.penel.getCurrentIssues("conference/ConferenceCurrentIssues.htm");
		    components.penel.getMonthIssues("conference/ConferenceMonthsIssues.htm"); //In >> PanelBox.js		
		    components.penel.getAds("ads/mainAds.htm");		
		    components.penel.getTopArticles("Conference");			
	    }
	    else if ( tn == 5)	//E-publications
	    {
		    components.penel.getNewsLetters("newsLetters/newsLetters.htm");	
		    components.penel.hideAds();		
	    }
	    else if ( tn == 6)	//Online tutorials
	    {
		    components.penel.getOnlineTutorials("tutorials/onlineTutorial.htm");	
		    components.penel.hideAds();					
	    }	
	    else if ( tn == 7)	//Other Resources
	    {
		    components.penel.getOtherResources("otherResources/otherResources.htm");
		    //components.penel.getOtherResources("global/login.html");
		    components.penel.hideAds();		    
	    }
	    else if ( tn == 8)	//Help
	    {
		    components.penel.getHelpPages("helpPages/helpMain.htm");
		    components.penel.hideAds();
	    }
	    
	    if ( tn >= 1 && tn < 8 ) /* Except for help pages */
	    {
	        printer.hidePrinterPageLink();	        
	    }
	    components.penel.loadBanner();
	    
	    prevColor = curColor;
	    preId = k;	    
    }
}
