
/*
 * Name: k500.js
 * Requires:
 *   Prototype v1.5+ (prototype.js)
 *   Scriptaculous v1.6.1+ (effects.js)
 */

function tableII(clickedElement) {
    var cmDiv = $("cmII");
    var tableViewport = $("k500LiveTable").parentNode;

    unHighlight();
    var cells = clickedElement.parentNode.getElementsByTagName("td");
    $A(cells).each(function(item) {
        item.style.backgroundColor = "#6699ff";
    });
    
    // in the event they clicked the freq and not the
    // url, I need to traverse the tree and get the url.
    // 0= row num, 1=domain
    var clickUrl = clickedElement.parentNode.getElementsByTagName('td')[1].innerHTML;

    // ajax load the cmDiv data.
    var ajax = new Ajax.Updater(
        {success: cmDiv},
        '/util/500u_cloud_xml.php',
        {
          method: 'get',
          parameters: 'domain=' + clickUrl
        });
    
}

function lineClick(e) {
    // the element that triggered the event
    var element = Event.element(e);
    var mouseX = Event.pointerX(e);
    var mouseY = Event.pointerY(e);
    // stop default behaviour and event propagation
    Event.stop(e);
    
    
    tableII(element);
}

function unHighlight() {
    var dlines = $$('#k500LiveTable tr td');
    dlines.each(function(item) {
        item.style.backgroundColor = "#ffffff";
    });
}

function k500init() {
    var dlines = $$('#k500LiveTable tr td');
    dlines.each(function(item) {
        Event.observe(item,"click",lineClick);
    });

    // need initia live table request to complete.
    window.setTimeout("initalClick()",500);
}

function initalClick() {
    // simulate a click to the first row.
    var fauxElement = $("k500LiveTable").getElementsByTagName("td")[1];
    tableII(fauxElement);
}

// Call the init onload
k500init();

