/*
These global variables must be declared in the file that
is drawing the table.

var visible_trs = new Array();
var last_shown_index = "0";
var last_hl_index    = "0";
*/

/* Utility functions */
function isIE() {
    /*@cc_on
      /*@if (@_jscript)
      return 1;
      @else @*/
        return 0;
        /*@end @*/
}

function style_table () {
    var elem = YAHOO.util.Dom.get("ie-table-border");
      if (elem) {
          /*@cc_on
            elem.style.borderRight  = "1px solid #DDDDDD";
            elem.style.borderBottom = "1px solid #DDDDDD";
          @*/
      }
}

function deselect () {
    if (document.selection)
        document.selection.empty();
    else if (window.getSelection())
        window.getSelection().removeAllRanges();
}

function get_hl_color (elem) {
    var odd = parseInt(elem.id.split('_')[1]) % 2
        if (odd) {
            return "#DDEEFF";
        }
    return "#AABBCC";
}

function get_bg_color (elem) {
    var odd = parseInt(elem.id.split('_')[1]) % 2
        if (odd) {
            return "#F7F7EF";
        }
    return "#E7E7CE";
}

function hide_summary (index) {
    in_num = parseInt(index);
    visible_trs[in_num] = 0;
    var button_id_str = "button_" + String(index);
    var button = YAHOO.util.Dom.get(button_id_str);
    button.innerHTML = "[+]";
    var id_str = "summ_" + String(index);
    var elem =YAHOO.util.Dom.get(id_str);
    elem.style.display = "none";
}

function show_summary (index) {
    var button_id_str = "button_" + String(index);
    var button = YAHOO.util.Dom.get(button_id_str);
    button.innerHTML = "[&ndash;]";
    var summ_id = "summ_" + index;
    var elem = YAHOO.util.Dom.get(summ_id);
    var new_style;
    if (isIE()) {
        new_style = "block";
    } else {
        new_style = "table-row";
    }
    elem.style.display = new_style;
    visible_trs[index] = 1;
}

function restore_bgcolor (index) {
    var id_str = "title_" + index;
    var elem =YAHOO.util.Dom.get(id_str);
    elem.style.backgroundColor = get_bg_color(elem); 
}

/* event handling functions */
function on_mouseout_tr (index) {
    restore_bgcolor(index);
}

function on_mouseover_tr (index) {
    id_str = "title_" + index;
    var elem = YAHOO.util.Dom.get(id_str);

    restore_bgcolor(last_hl_index);
    elem.style.backgroundColor = get_hl_color(elem);
    last_hl_index = index;
}

function on_click_tr (event, index) {
    /* Check visibility before hiding the previous row
       in case we are clicking on the row we just
       opened.
    */
    src = YAHOO.util.Event.getTarget(event);

    deselect();
    
    /* If the user clicked on a link, ignore the click
       event. */
    if (src.tagName=="NOBR" || src.tagName=="A") return;

    var visible = visible_trs[parseInt(index)];
    hide_summary(last_shown_index);
    last_shown_index = index;

    if (visible) hide_summary(index);
    else show_summary(index);
}
