// Global vars to hold the object in the panel.
var totalLink = 4;
var tabPanelArray = new Array();
var tabMenuArray = new Array();
var currentMenuIndex = 0;
var numberOfCharacter = 150;

function gotoURL(siteAddress)
{
    window.location = siteAddress;
}

/**
 * This MUST be called on page load to fill up the shared global values.
 * Having the panes object accessible by index makes things easier.
 * This is also a good place to display the first page.
 */
function bodyOnLoad()
{
    for(index=0; index<totalLink; index++)
    {
        tabPanelArray[index] = getItemObj('tabPane'+index);
        tabMenuArray[index] = getItemObj('tabMenu'+index);
       // alert(tabPanelArray[index].innerHTML);
    }

    raisePanel(currentMenuIndex);
}

/**
 * Utility function just to show an error if I try to get non existen objects
 */
function getItemObj(itemId)
{
    obj = document.getElementById(itemId);
    //alert(obj.innerHTML);
    
    if(obj == null)
        alert('Script Error: id='+itemId+' does not exist');

    return obj;
}

/**
 * raising a panel means setting all the other panels to a lower level
 * and setting the raided panel to a higher level
 * note that also the size must be set correctly !
 * to activate a menu i switch the class between active and not active.
 */
function raisePanel(panelIndex)
{
    for(index=0; index<totalLink; index++)
    {
    
        if(index == panelIndex)
        {
            //alert(tabMenuArray[index].className);
            objDisplay = document.getElementById('tabPaneDisplay');

            /*var indexOfP = tabPanelArray[index].innerHTML.indexOf("<P");
            if(indexOfP == -1)
                indexOfP = tabPanelArray[index].innerHTML.indexOf("<p");
            
            if(indexOfP != -1)                
            {
                indexOfP = indexOfP + numberOfCharacter;
                objDisplay.innerHTML = tabPanelArray[index].innerHTML.substr(0,indexOfP) + ".... <a class='linkMore' href='#'>More</a></P></div>";
            }
            else
            {
                objDisplay.innerHTML = "";
            }
            */
            objDisplay.innerHTML = tabPanelArray[index].innerHTML;
            tabMenuArray[panelIndex].className = 'current';
        }
        else
        {
            tabMenuArray[index].className = 'deActive';
        }
    }

    currentMenuIndex=panelIndex;
    return true;
}
