﻿// hide / show titel bar
function ShowSettings(tbl)
{
    var objShowhide = document.getElementById(tbl);    
    if(objShowhide.style.display == 'none')
    {
        objShowhide.style.display = 'block';
        objShowhide.previousSibling.style.backgroundImage = 'url(images/min.gif)';
    }
    else
    {
        objShowhide.style.display = 'none';
        objShowhide.previousSibling.style.backgroundImage = 'url(images/max.gif)';
    }
}

// show image in a div
function ShowImage(imgSrc)
{
    document.getElementById('imgpreview').innerHTML = "<img src=\"" + imgSrc + "\" />";
}

// gives up and down scroll buttons to images, spans, ... named up_name, down_name, respectively.
// will keep the default scroll_box's style overflow if it encounters errors (so make overflow: auto;)
// usage: put this after the scrollbox div:  var div_scroll1 = new TextScroll('div_scroll1', 'scroll_box');
function TextScroll(scrollname, div_name, up_name, down_name)
{
    this.div_name = div_name;
    this.name = scrollname;
    this.scrollCursor = 0;
    this.speed = 5;
    this.timeoutID = 0;
    this.div_obj = null;
    this.up_name = up_name;
    this.dn_name = down_name;
    {
        if (document.getElementById) 
        {
            div_obj = document.getElementById(this.div_name);
            if (div_obj) 
            {
                this.div_obj = div_obj;
                this.div_obj.style.overflow = 'hidden';                
            }
            
            div_up_obj = document.getElementById(this.up_name);
            div_dn_obj = document.getElementById(this.dn_name);
                        
            if (div_up_obj && div_dn_obj) 
            {
                //div_up_obj.onmouseover = function() { eval(scrollname + ".scrollUp();") };
                //div_up_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
                div_up_obj.onmousedown = function() { eval(scrollname + ".scrollUp();"); };
                div_up_obj.onmouseup = function() { eval(scrollname + ".stopScroll();"); };
               
                //div_dn_obj.onmouseover = function() { eval(scrollname + ".scrollDown();") };
                //div_dn_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
                div_dn_obj.onmousedown = function() { eval(scrollname + ".scrollDown();") };
                div_dn_obj.onmouseup = function() { eval(scrollname + ".stopScroll();") };
            }

            if (document.all) {
                if (div_obj.innerText.length < 750)
                    document.getElementById('scrollbuttons').style.display = 'none';
            }
            else {
                if(div_obj.textContent.length < 750)
                    document.getElementById('scrollbuttons').style.display = 'none';
            }
            
            
        }
    }    
    this.stopScroll = function() 
    {
        clearTimeout(this.timeoutID);
    }
    this.scrollUp = function() 
    {
        if (this.div_obj) 
        {
            this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - this.speed;
            this.div_obj.scrollTop = this.scrollCursor;
            this.timeoutID = setTimeout(this.name + ".scrollUp()", 60);
        }
    }
    this.scrollDown = function() 
    {
        if (this.div_obj) 
        {
            this.scrollCursor += this.speed;
            this.div_obj.scrollTop = this.scrollCursor;
            this.timeoutID = setTimeout(this.name + ".scrollDown()", 60);
        }
    }
    this.resetScroll = function() 
    {
        if (this.div_obj) 
        {
            this.div_obj.scrollTop = 0;
            this.scrollCursor = 0;
        }
    }
}

/*      USAGE EXAMPLE:

<span id="scroll_up">scroll up</span> | <span id="scroll_down">scroll down</span>
<br>
<div id="scroll_box">
  <p>a lot of content</p>
</div>

<script type="text/javascript">
  var div_scroll1 = new TextScroll('div_scroll1', 'scroll_box', 'scroll_up', 'scroll_down');
</script>


*/