var vTreeChildIds = "";

function BptMenuTree()
{
    // Properties
    this.oRow = null;
    this.oField = null;
    this.oCheck = null;
    this.iSelected = -1;

    // Functions
    this.onBptClick = onBptClickX;
    this.doBptSH = doBptSHX;
    this.onBptCheck = onBptCheckX;
    this.setAllChildIds = setAllChildIdsX;
    this.getBptSelectedText = getBptSelectedTextX;
    this.getBptSelectedValue = getBptSelectedValueX;
    this.getBptCheckedText = getBptCheckedTextX;
    this.getBptCheckedValues = getBptCheckedValuesX;
    this.doBptOver = doBptOverX;
    this.doBptOut = doBptOutX;
}

function selectItem(map)
{
   var winOpen = window.open(map,null,null,true);
}

function onBptClickX(r)
{
    if (this.iSelected == r) return;
    
    if ( this.oRow == null )
        this.oRow = document.getElementsByName("bptROW");
        
    if ( this.oField == null )
        this.oField = document.getElementsByName("bptRFIELD");
    
    // Disabled/Blocked.
    if ( this.oField[r].className == "pLinkDisabled" ) return;

    if ( this.iSelected != -1 )
    {
        this.oField[this.iSelected].className = "pLink"
    }
    this.oField[0].className = "pLink" // Root

    this.oField[r].className = "pLinkSelected"

    this.iSelected = r;
}

function doBptSHX(r,sh)
{
    if ( this.oRow == null )
        this.oRow = document.getElementsByName("bptROW");
    
    var iC = 0;
    var iM = this.oRow.length;

    if ( sh == "inline" )
    {
        for ( iC=0; iC<iM; iC++ )
        {
            if ( arDada[iC] == r )
            {
                if ( arKiddies[iC] == "T" )
                {
                    if ( arState[iC] == "o" )
                    {
                        // Recurse
                        doBptSH(iC,sh);
                    }
                }
                this.oRow[iC].style.display = sh;
            }
        }
    }
    else
    {
        for ( iC=0; iC<iM; iC++ )
        {
            if ( arDada[iC] == r )
            {
                // Recurse
                doBptSH(iC,sh);
                this.oRow[iC].style.display = sh;
            }
        }
    }
}
function onBptCheckX(r,bVal)
{
    if ( this.oRow == null )
        this.oRow = document.getElementsByName("bptROW");
        
    if ( this.oCheck == null )
        this.oCheck = document.getElementsByName("bptCHECK");
    
    var iC = 0;
    var iM = this.oRow.length;
    
    var bCheckIt;
    if ( bVal == undefined )
    {
        if ( arValue[r] == "" )
            bCheckIt = true;
        else
            bCheckIt = false;
    }
    else
    {
        bCheckIt = bVal;
    }

    if ( bCheckIt )
    {
        //alert( r + " - " + arUid );
        this.oCheck[r].src = "/wps/images/bp/check1.gif";
        arValue[r] = arUid[r];
        
        // Recurse and select the parents.
        for ( iC=r; iC>=0; iC-- )
        {
            if ( arSubRows[iC].indexOf(r+";") >= 0 )
            {
                this.oCheck[iC].src = "/wps/images/bp/check1.gif";
                arValue[iC] = arUid[iC];
                // Recurse
                onBptCheck(iC,true);
            }
        }
    }
    else
    {
        this.oCheck[r].src = "../_images/check.gif";
        arValue[r] = "";
        
        // Deselect the children.
        for ( iC=r; iC<iM; iC++ )
        {
            if ( arDada[iC] == r )
            {
                this.oCheck[iC].src = "/wps/images/bp/check.gif";
                arValue[iC] = "";
                // Recurse
                onBptCheck(iC,false);
            }
        }
    }
}
function setAllChildIdsX(r,seq)
{
    vTreeChildIds = "";

    // Get all child IDs.
    setAllChildIdsExX(r,seq)
}
function setAllChildIdsExX(r,seq)
{
    if ( this.oRow == null )
        this.oRow = document.getElementsByName("bptROW");

    var iC = 0;
    var iM = this.oRow.length;

    for ( iC=r; iC<iM; iC++ )
    {
        if ( arDadaSeq[iC] == seq )
        {
            vTreeChildIds += (arUid[iC]+";");
            // Recurse so we can get all the children.
            setAllChildIdsExX(iC,arUid[iC])
        }
    }
}
function getBptSelectedTextX()
{
    if ( this.iSelected == -1 )
        return "";
    
    var oDesc = document.getElementsByName("bptRFIELD");
    if ( oDesc != null )
        return oDesc[this.iSelected].innerText;
}
function getBptSelectedValueX()
{
    if ( this.iSelected == -1 )
        return "";
    
    return arUid[this.iSelected];
}
function getBptCheckedTextX()
{
    var oDesc = document.getElementsByName("bptRFIELD");
    if ( oDesc != null )
    {
        var iC;
        var iMax = arValue.length;
        var sRet = "";
        for ( iC=0; iC<iMax; iC++ )
        {
            if ( arValue[iC] != "" )
                sRet += oDesc[iC].innerText+",";
        }
        return ( sRet.substr(0,sRet.length-1) );
    }
    else
        return "";
}
function getBptCheckedValuesX()
{
    var iC;
    var iMax = arValue.length;
    var sRet = "";
    for ( iC=0; iC<iMax; iC++ )
    {
        if ( arValue[iC] != "" )
            sRet += arValue[iC]+",";
    }
    return ( sRet.substr(0,sRet.length-1) );
}
function doBptOverX(r)
{
    if ( this.oField == null )
        this.oField = document.getElementsByName("bptRFIELD");
        
    if ( this.oField[r].className == "pLink" )
        this.oField[r].className = "pLinkOver";
    else if ( this.oField[r].className == "pLinkSelected" )
        this.oField[r].className = "pLinkSelectedOver";
    else if ( this.oField[r].className == "pNorm" )
        this.oField[r].className = "pNormOver";
}
function doBptOutX(r)
{
    if ( this.oField == null )
        this.oField = document.getElementsByName("bptRFIELD");
        
    if ( this.oField[r].className == "pLinkOver" )
        this.oField[r].className = "pLink";
    else if ( this.oField[r].className == "pLinkSelectedOver" )
        this.oField[r].className = "pLinkSelected";
    else if ( this.oField[r].className == "pNormOver" )
        this.oField[r].className = "pNorm";
}
