/*
 * Plasma Control Bar - Library for Control Bar navigation in Plasma.
 * Copyright (C) 1995-2006 IonicWeb, LLC.  All rights reserved.
 *
 * This library is only available for use as part of the Plasma 2007
 * Web Application Server by IonicWeb, LLC.  Any other use is currently
 * prohibited.  For more information and license options for this
 * work, please send requests to info@ionicweb.com. 
 *
 * The Plasma license is found at http://ionicweb.com/plasma/license
 */

/*
 * Display Control Bar - Displays a control bar used in Plasma editors.
 *
 * ATTRIBUTES:
 *
 * bar_props - This object contains all information required to generate ther
 *             control bar including:
 *             width - The physical width of the control bar.
 *             image_path - current path to images based on Plasma URI
 *             help_topic - If a help button is to be generated this is the topic
 *             buttons - Array of button objects
 *             button - Button object contains in the buttons array with attribures:
 *                 icon - name of image to be used as icon
 *                 display - initial display state for button
 *                 id - identifies button to other functions
 *                 title - title (name) of button that displays
 */
function displayControlBar(bar_props)
{
    document.write("<table class=\"CB\" width=\"" + bar_props.width + "\">");
    document.write("<tr>");
    document.write("<td><table class=\"CB\"><tr>");

    for ( var i=0; i < bar_props.buttons.length; i++ ) {
        
        var button = bar_props.buttons[i];
	
        if ( button.text ) {
            document.write("<td><input id=\"" + button.id + "\" class=\"content_form\" style=\"display:" + button.display + "\" size=\"5\" maxlength=\"25\"></td>");
        } else {
            if ( i == 0 ) {
                document.write("<td id=\"" + button.id + "\" onClick=\"" + button.call_function + ";\" id=\"" + button.id + "\" class=\"CB_button CB_button_left\" style=\"display:" + button.display + "\" onmouseup=\"cb_up(this);\" onmousedown=\"cb_dn(this);\" onMouseOver=\"cb_hi_left(this);\" onMouseOut=\"cb_low_left(this);\"><img height=\"16\" src=\"" + bar_props.image_path + "/" + button.icon + "\"> " + button.title + "</td>");
            } else {
                document.write("<td id=\"" + button.id + "\" onClick=\"" + button.call_function + ";\" id=\"" + button.id + "\" class=\"CB_button\" style=\"display:" + button.display + "\" onmouseup=\"cb_up(this);\" onmousedown=\"cb_dn(this);\" onMouseOver=\"cb_hi(this);\" onMouseOut=\"cb_low(this);\"><img height=\"16\" src=\"" + bar_props.image_path + "/" + button.icon + "\"> " + button.title + "</td>");
            }
        }
    }
    
    document.write("</tr></table></td>\n");

    if ( bar_props.help_topic != null && bar_props.help_topic != "" ) {
        document.write("<td align=\"right\">");
        document.write("<img alt=\"Help!\" width=20 src=\"" + bar_props.image_path + "/help.gif\">");
        document.write("<img width=1 height=28 src=\"" + bar_props.image_path + "/blank.gif\">");
        document.write("</td>");
    } else {
        document.write("<td align=\"right\">");
        document.write("<img width=1 height=28 src=\"" + bar_props.image_path + "/blank.gif\">");
        document.write("</td>");
    }
    
    document.write("</tr>");
    document.write("</table>");

}

function getControlBar(bar_props)
{
    var control_bar = "";
    control_bar = control_bar + "<table class=\"CB\" width=\"" + bar_props.width + "\">";
    control_bar = control_bar + "<tr>";
    control_bar = control_bar + "<td><table class=\"CB\"><tr>";

    for ( var i=0; i < bar_props.buttons.length; i++ ) {
        
        var button = bar_props.buttons[i];
        if ( i == 0 ) {
            control_bar = control_bar + "<td id=\"" + button.id + "\" onClick=\"" + button.call_function + ";\" id=\"" + button.id + "\" class=\"CB_button CB_button_left\" style=\"display:" + button.display + "\" onmouseup=\"cb_up(this);\" onmousedown=\"cb_dn(this);\" onMouseOver=\"cb_hi_left(this);\" onMouseOut=\"cb_low_left(this);\"><img height=\"16\" src=\"" + bar_props.image_path + "/" + button.icon + "\"> " + button.title + "</td>";
        } else {
            control_bar = control_bar + "<td id=\"" + button.id + "\" onClick=\"" + button.call_function + ";\" id=\"" + button.id + "\" class=\"CB_button\" style=\"display:" + button.display + "\" onmouseup=\"cb_up(this);\" onmousedown=\"cb_dn(this);\" onMouseOver=\"cb_hi(this);\" onMouseOut=\"cb_low(this);\"><img height=\"16\" src=\"" + bar_props.image_path + "/" + button.icon + "\"> " + button.title + "</td>";
        }
    }
    
    control_bar = control_bar + "</tr></table></td>\n";

    if ( bar_props.help_topic != null && bar_props.help_topic != "" ) {
        control_bar = control_bar + "<td align=\"right\">";
        control_bar = control_bar + "<img alt=\"Help!\" width=20 src=\"" + bar_props.image_path + "/help.gif\">";
        control_bar = control_bar + "</td>";
    } else {
        document.write("<td align=\"right\">");
        document.write("<img width=1 height=20 src=\"" + bar_props.image_path + "/blank.gif\">");
        document.write("</td>");
    }
    
    control_bar = control_bar + "</tr>";
    control_bar = control_bar + "</table>";

    return control_bar;

}
            
/*
 * State changing functions to change the visual effect of control bars when
 * mousing over, clicking, etc.
 */
    function cb_hi(div) {
       div.className = "CB_button_over";
    }

    function cb_low(div) {
       div.className = "CB_button";
    }

    function cb_hi_left(div) {
       div.className = "CB_button_over CB_button_left_over";
    }

    function cb_low_left(div) {
       div.className = "CB_button  CB_button_left";
    }
    

    function cb_dn(div) {
       div.className = "CB_button_dn";
    }

    function cb_up(div) {
       div.className = "CB_button_over";
    }

