﻿// JScript File

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//  Basic scripts
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// Function is used to determine if the browser is IE 6 or older

function IsIE6() {
    /// <summary>Used to verify if the browser happens to be IE6</summary>
    /// <returns type="bool">True is browser is IE6 or older version, else false</returns>

    var MSIE = navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE")).split(";");
    var parseVal = MSIE[0].split(' ');
    var verNum = parseFloat(parseVal[1]);
    if(isNaN(verNum) == false && verNum < 7)
        return true;
    else
        return false;
}
function IsIDVisible(id) {
    /// <summary>Test if a control is visible or hidden</summary>
    /// <param name="id" type="string">ID for control to be tested</param>
    /// <returns type="string">true if visible, false if hidden, and null if not found</returns>

    if (id != null) 
        return IsObjVisible(document.getElementById(id));

    return null;
}
function IsObjVisible(obj) {
    /// <summary>Test if a control is visible or hidden</summary>
    /// <param name="obj" type="Object">Pointer to element to be tested</param>
    /// <returns type="string">true if visible, false if hidden, and null if not found</returns>

    if (obj != null) {
        if (obj.style.visibility == 'visible')
            return true;
        else
            return false;
    }
    return null;
}
function SetIDVisibility(sID, bVisible, sDisplay) {
    /// <summary>Set the control visibility state by the control's id and the display value if present</summary>
    /// <param name="sID" type="string">ID for control to be set</param>
    /// <param name="bFlag" type="bool">true if the control is to be visible</param>
    /// <param name="sDisplay" type="string">Value of the display setting (i.e. block, inline, none).  null or missing if to be ignored and not set.</param>
    /// <returns type="bool">last visiblility state of the control, null if not found</returns>

    if (sID != null)
        return SetObjVisibility(document.getElementById(sID), bVisible, sDisplay);
    else
        return null;
}
function SetObjVisibility(obj, bFlag, sDisplay) {
    /// <summary>Set the control visibility state and the display value if present</summary>
    /// <param name="obj" type="Object">Handle for control to be set</param>
    /// <param name="bFlag" type="bool">true if the control is to be visible</param>
    /// <param name="sDisplay" type="string">Value of the display setting (i.e. block, inline, none).  null or missing if to be ignored and not set.</param>
    /// <returns type="bool">Last visiblility state of the control, null if not found</returns>

    var bRtn = null;
    if(obj != null)
    {
        var bVal = new Boolean(bFlag);

        if(bVal == true)
            obj.style.visibility = 'visible';
        else
            obj.style.visibility = 'hidden';

        if (sDisplay != null)
            obj.style.display = sDisplay;
    }
    return bRtn;
}

function ToggleVisibilityByID(sID) {
    /// <summary>Toggle the control visibility of a control by ID.  Don't use on non block display items</summary>
    /// <param name="sID" type="string">ID for control to be set</param>
    /// <returns type="bool">last visiblility state of the control, null if not found</returns>

    if (sID != null)
        return ToggleVisibilityByObj(document.getElementById(sID));
    else
        return null;
}
function ToggleVisibilityByObj(obj) {
    /// <summary>Set the control visibility state and the display value if present</summary>
    /// <param name="obj" type="Object">Handle for control to be set</param>
    /// <returns type="bool">Last visiblility state of the control</returns>

    var bRtn = false;
        
    if(obj != null) {
        if (obj.style.visibility == 'visible')
            bRtn = true;
        else
            bRtn = false;
            
        if(bRtn == false)
        {
            obj.style.visibility = 'visible';
            obj.style.display = 'block';
        }
        else
        {
            obj.style.visibility = 'hidden';
            obj.style.display = 'none';
        }
    }
    return bRtn;
}
function Trim(sData) {
    /// <summary>Removes leading and trailing spaces from a string</summary>
    /// <param name="sData" type="string">String to be cleaned up</param>
    /// <returns type="string">string that has been cleaned of leading and trailing spaces.</returns>

    return LTrim(RTrim(sData));
}
function LTrim(sData) {
    /// <summary>Removes leading spaces from a string</summary>
    /// <param name="sData" type="string">String to be cleaned up</param>
    /// <returns type="string">string that has been cleaned of leading spaces.</returns>

    var sRtn = new String();
    sRtn = sData;
    
    while(sRtn.length > 0)
    {
        if(sRtn.substr(0,1) == " ")
        {
            if(sRtn.length > 1) // Still ' ' characters and need to be removed
                sRtn = sRtn.substr(1,sRtn.length - 1);
            else
            {   // Only one character and it is a space
                sRtn = "";
                break;
            }
        }
        else  // No more leading spaces break out of the while 
            break;
    }
    return sRtn;
}
function RTrim(sData) {
    /// <summary>Removes trailing spaces from a string</summary>
    /// <param name="sData" type="string">String to be cleaned up</param>
    /// <returns type="string">string that has been cleaned of trailing spaces.</returns>

    if(sData != null)
    {
        var sRtn = new String();
        sRtn = sData;
        while(sRtn.length > 0)
        {
            if(sRtn.substr(sRtn.length - 1,1) == " ")
            {
                if(sRtn.length > 1) // Still ' ' characters and need to be removed
                    sRtn = sRtn.substr(0,sRtn.length - 1);
                else
                {   // Only one character and it is a space
                    sRtn = "";
                    break;
                }
            }
            else  // No more leading spaces break out of the while 
                break;
        }
        return sRtn;
    }
    else
        return '';
}

function addClass(tar, cls){
    /// <summary>Adds a class to the class tag after it verifies the class doesn't exists</summary>
    /// <param name="tar" type="Object">Target element</param>
    /// <param name="cls" type="string">Name of class to add</param>
    /// <returns type="void">Always returns true</returns>

    var rem = tar.className.toString().split(' ');
    var found = null;
    for(var i = 0 ; i < rem.length; i++)
    {
        if(rem[i].toString().toLowerCase() == cls.toString().toLowerCase())
        {
            found = true;
            break;
        }
    }
    if(found == null)
        tar.className += ' ' + cls;
        
    return true;
}
function removeClass(tar, cls){
    /// <summary>Removes a class from the class tag</summary>
    /// <param name="tar" type="Object">Target element</param>
    /// <param name="cls" type="string">Name of class to add</param>
    /// <returns type="void">Always returns true</returns>

    var rem = tar.className;
    rem = rem.replace(cls, '');
    Trim(rem);
    tar.className = rem;
    return true;
}
function GetIncrementValue(obj){
    /// <summary>Takes a single digit off the end of the elment id for an index to be used</summary>
    /// <param name="obj" type="Object">Element to have the index removed from</param>
    /// <returns type="string">last character off the element id</returns>
    return obj.id.toString().substring(obj.id.toString().length - 1);
}
function MenuMouseHover(obj)
{
    var found = null;
    for(var i = 0; i < mnuSel.length; i++)
        if(mnuSel[i] == obj)
            found = true;
            
    if(found == null)
        addClass(obj, 'textHighlight');
}
function MenuMouseOut(obj)
{
    removeClass(obj, 'textHighlight');
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//  Actual page scripts
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

var oTab = null;
var mnuSel = new Array(5);
var mnuOld = null;

function SelectTab(obj, id){
    /// <summary>Event for the tab changing</summary>
    /// <param name="obj" type="Object">Object that was clicked on</param>
    /// <param name="id" type="string">ID for the menu associated with the tab</param>
    /// <returns type="void">Not used</returns>

    if(obj != null)
    {
        if(oTab != obj)  // Verify we didn't select current tab again
        {
            var mnu = document.getElementById(id);
            var oldPan = GetIncrementValue(oTab);
            var newPan = GetIncrementValue(obj);
            removeClass(oTab, 'bg' + oldPan);
            addClass(oTab, 'bgNoSel');
            oTab.style.cursor = 'pointer';
            removeClass(obj, 'bgNoSel');
            addClass(obj, 'bg' + newPan);
            obj.style.cursor = 'default';
            SetIDVisibility('panAppWin' + oldPan, false, 'none');
            SetIDVisibility('panAppWin' + newPan, true, 'block');
            
            oTab = obj;
            SetMainMenuView(mnu);
        }
    }
}
function SetMainMenuView(obj){
    /// <summary>Event for the menu changing</summary>
    /// <param name="obj" type="Object">Object that was clicked on</param>
    /// <returns type="void">Not used</returns>

    if(obj != null)
    {
        if(oMenu != null)
            SetObjVisibility(oMenu, false, 'none');
            
        SetObjVisibility(obj, true, 'block');
        oMenu = obj;
    }
    else
        alert('Tab Menu missing');
}

function SetOrchMenuView(obj, old){
    /// <summary>Event for the Home menu changing</summary>
    /// <param name="obj" type="Object">Object that was clicked on</param>
    /// <returns type="void">Not used</returns>
    if(obj == old)
        return;
        
    if(obj != null && old != null)
    {
        var o = GetIncrementValue(old);
        var n = GetIncrementValue(obj);
        
        var oldPan = document.getElementById('panOrch' + o);
        var newPan = document.getElementById('panOrch' + n);

        SetObjVisibility(oldPan, false, 'none');
        SetObjVisibility(newPan, true, 'block');
        obj.style.cursor = 'default';
        old.style.cursor = 'pointer';
        
        
        mnuSel[1] = obj;
    }
    else
        alert('Orchestra Menu missing');
}

function SetStartupMenuView(obj, old){
    /// <summary>Event for the Home menu changing</summary>
    /// <param name="obj" type="Object">Object that was clicked on</param>
    /// <returns type="void">Not used</returns>
    if(obj == old)
        return;
        
    if(obj != null && old != null)
    {
        var o = GetIncrementValue(old);
        var n = GetIncrementValue(obj);
        
        var oldPan = document.getElementById('panMain' + o);
        var newPan = document.getElementById('panMain' + n);

        SetObjVisibility(oldPan, false, 'none');
        SetObjVisibility(newPan, true, 'block');
        obj.style.cursor = 'default';
        old.style.cursor = 'pointer';
        
        
        mnuSel[0] = obj;
    }
    else
        alert('Menu missing');
}
function SetEventMenuView(obj, old){
    /// <summary>Event for the Home menu changing</summary>
    /// <param name="obj" type="Object">Object that was clicked on</param>
    /// <returns type="void">Not used</returns>
    if(obj == old)
        return;
        
    if(obj != null && old != null)
    {
        var o = GetIncrementValue(old);
        var n = GetIncrementValue(obj);
        
        var oldPan = document.getElementById('panEvent' + o);
        var newPan = document.getElementById('panEvent' + n);

        SetObjVisibility(oldPan, false, 'none');
        SetObjVisibility(newPan, true, 'block');
        obj.style.cursor = 'default';
        old.style.cursor = 'pointer';
        
        
        mnuSel[2] = obj;
    }
    else
        alert('Menu missing');
}
function SetLessonsMenuView(obj, old){
    /// <summary>Event for the Home menu changing</summary>
    /// <param name="obj" type="Object">Object that was clicked on</param>
    /// <returns type="void">Not used</returns>
    if(obj == old)
        return;
        
    if(obj != null && old != null)
    {
        var o = GetIncrementValue(old);
        var n = GetIncrementValue(obj);
        
        var oldPan = document.getElementById('panLessons' + o);
        var newPan = document.getElementById('panLessons' + n);

        SetObjVisibility(oldPan, false, 'none');
        SetObjVisibility(newPan, true, 'block');
        obj.style.cursor = 'default';
        old.style.cursor = 'pointer';
        
        
        mnuSel[3] = obj;
    }
    else
        alert('Menu missing');
}
function SetMiscMenuView(obj, old){
    /// <summary>Event for the Home menu changing</summary>
    /// <param name="obj" type="Object">Object that was clicked on</param>
    /// <returns type="void">Not used</returns>
    if(obj == old)
        return;
        
    if(obj != null && old != null)
    {
        var o = GetIncrementValue(old);
        var n = GetIncrementValue(obj);
        
        var oldPan = document.getElementById('panMisc' + o);
        var newPan = document.getElementById('panMisc' + n);

        SetObjVisibility(oldPan, false, 'none');
        SetObjVisibility(newPan, true, 'block');
        obj.style.cursor = 'default';
        old.style.cursor = 'pointer';
        
        
        mnuSel[4] = obj;
    }
    else
        alert('Menu missing');
}
