﻿// **********
// BN NETWORK
// **********

function bnnLink(link)
{

    if(link)
    {
    
	    oWindow = window.open(link, "bnnLink");

	    oWindow.focus();

    }

}


// *****
// FORUM
// *****

function forumQuote(source)
{

    var oTextarea = document.getElementById("dmSource");

    if (document.selection) {
    
      var oRange = document.selection.createRange();

      var selected = oRange.text; 

     }
     else if (oTextarea.selectionStart && oTextarea.selectionEnd)
     {
     
        var selected = oTextarea.value.substring(oTextarea.selectionStart, oTextarea.selectionEnd) 

    } 
    
    if(selected)
    {
    
        if(dmCheckPasteHTML()){
           
           dmPasteHTML('<div class="forumQuotes"><b>' + source + ' :</b><br/>' + selected + '</div>&nbsp;')

        }
        else{

            var oDiv = document.createElement("div");

            oDiv.className = 'forumQuotes'; 
            oDiv.innerHTML = '<b>' + source + ' :</b><br/>' + selected; 

            dmInsertNode(oDiv);

        }
        
    }

}

// *****
// MMENU
// *****

var mmenuTimers = new Array();

function mmenuDisplay(index)
{

    if(mmenuTimers[index] && mmenuTimers[index] >= 0)
    {

        window.clearTimeout(mmenuTimers[index]);

        mmenuTimers[index] = -1;
        
    }
    
    var oDiv = document.getElementById("mmenu_div_" + index);
    
    if(oDiv)
    {
    
        oDiv.style.display = "block";
    
    }

}

function mmenuHide(index)
{

    mmenuTimers[index] = window.setTimeout("mmenuHide_execute(" + index + ")", 50);
    
    
}

function mmenuHide_execute(index)
{

    var oDiv = document.getElementById("mmenu_div_" + index);
    
    if(oDiv)
    {
    
        oDiv.style.display = "none";
    
    }
    
    mmenuTimers[index] = -1;
    
}

// ******
// SCROLL
// ******

var scrollTimers = new Array();
var scrollPositions = new Array();

function scrollCheckPositions(id,positions)
{

    if(!scrollPositions[id])
    {

        scrollPositions[id] = new Array();

    }

    scrollPositions[id][0] = (!scrollPositions[id][0] || scrollPositions[id][0] > positions)?0:scrollPositions[id][0];
    

}

function scrollCheckTimer(id)
{

    if(!scrollTimers[id])
    {

        scrollTimers[id] = new Array();
        
    }

}

function scrollDiv(id,mode,step,position,amount)
{

    scrollCheckTimer(id);
    
    switch(mode)
    {
    
        case "left" :

            position = document.getElementById(id).scrollLeft + amount;
    
            scrollDivLeft(id,step,position);

            break;
    
        case "right" :

            position = document.getElementById(id).scrollLeft - amount;
    
            scrollDivRight(id,step,position);

            break;

        case "position" :

            clearTimeout(scrollTimers[id][1]);

        case "auto" :

            var move = document.getElementById(id).scrollLeft - position;
            
            switch(true)
            {
            
                case (move < 0) :

                    scrollDivLeft(id,step,position);

                    break;
            
                case (move > 0) :

                    scrollDivRight(id,step,position);

                    break;

                case (move == 0) :

                    break;

                default :

            }

            break;

        default :

    }

}

function scrollDivLeft(id,step,position)
{

    clearTimeout(scrollTimers[id][0]);

    if(document.getElementById(id).scrollLeft < position)
    {

        document.getElementById(id).scrollLeft = (document.getElementById(id).scrollLeft + step <= position)?(document.getElementById(id).scrollLeft + step):position;

        scrollTimers[id][0] = setTimeout("scrollDivLeft('" + id + "'," + step + "," + position + ")", 10);

    }
    
}

function scrollDivRight(id,step,position)
{

    clearTimeout(scrollTimers[id][0]);

    if(document.getElementById(id).scrollLeft > position)
    {

        document.getElementById(id).scrollLeft = (document.getElementById(id).scrollLeft - step >= position)?(document.getElementById(id).scrollLeft - step):position;

        scrollTimers[id][0] = setTimeout("scrollDivRight('" + id + "'," + step + "," + position + ")", 10);

    }
    
}

function scrollAutoslide(id,step,width,positions,tempo)
{

    scrollCheckTimer(id);
    scrollCheckPositions(id,positions);

    var slideto = scrollPositions[id][0] * width;

    ++scrollPositions[id][0];

    scrollDiv(id,"auto",step,slideto);

    scrollTimers[id][1] = setTimeout("scrollAutoslide('" + id + "'," + step + "," + width + "," + positions + "," + tempo + ")", tempo);
   
}


// ****
// TABS
// ****

function tabClick(tab)
{

    if(!mainGetActiveStatus(tab.className))
    {

        var index = tab.id.substring(tab.id.indexOf("tab_") + 4);
        var prefix = tab.id.substring(0, tab.id.indexOf("tab_"));
        
        for(i=0; i<=10; ++i)
        {

            var oTab = document.getElementById(prefix + "tab_" + i);
            var oDiv = document.getElementById(prefix + "div_" + i);

            if(oTab && oDiv && oTab.id == tab.id){
            
                oTab.className = "tabsActive";
                oDiv.style.display = "block";
            
            }
            else if(oTab && oDiv){

                oTab.className = "tabsDefault";
                oDiv.style.display = "none";

            }

        }

    }

}


