// -*- mode: java -*-
/*
 * Javascript popup window library
 *
 * provides functions for popping popup windows.
 *
 * REQUIRES: util.js
 *
 * PROVIDES:
 *
 * pop(name,href,w,h) -- pop up a pop up window
 * 
 * updateLinks(class,windowName,windowWidth,windowHeight) -- update 
 *     links with class class to pop up their href in a window as 
 *     defined by the other params.
 *  
 * updateLinksTag(tag,class,windowName,windowWidth,windowHeight) -- update
 *     links with tag tag, etc.
 */

function pop(name,href,w,h)
{
    var spec = 'scrollbars=yes, resizable=no,width=' + w + ',height=' + h
    return window.open(href,name,spec);
}

function updateLinks(cl,name,w,h)
{
    updateLinksTag('A',cl,name,w,h);
    updateLinksTag('AREA',cl,name,w,h);   
}

function updateLinksTag(tag,cl,name,w,h)
{
    var links = document.getElementsByTagName(tag);
    for (var i = 0; i < links.length; i++) {
        var ll = links[i];
        if (ll.className.indexOf(cl) >= 0) {
            var popw = curryPop(name,ll.href,w,h);
            if (ll.onclick) {
                ll.onclick = compositeFunc(ll.onclick,popw);
            } else {
                ll.onclick = popw;
            }

            // ll.href = null;
            // ll.target = null;   
        }
    }
}

// private
function curryPop(name,href,w,h)
{
    return function() {
        pop(name,href,w,h);
        return false;
    }
}

