function pos_dropdown(anchorid, dropdiv, align) {
    var o=getobj(anchorid);
    if (!o) return;
	if (align == 'right') {
		left_pos = get_page_left(o) + o.offsetWidth - dropdiv.scrollWidth - 2;
	} else {
		left_pos = get_page_left(o);
	}
	if (bw.ie5 && bw.mac) {
		top_pos = o.offsetHeight - 1;
	} else {
		top_pos = get_page_top(o) + o.offsetHeight - 1;
	}
	if (dropdiv.style.pixelLeft != null) {
		dropdiv.style.pixelLeft=left_pos;
		dropdiv.style.pixelTop=top_pos;
	} else {
		dropdiv.style.left=left_pos + 'px';
		dropdiv.style.top=top_pos + 'px';
	}
}

function size_dropdown (dropdiv, contentid) {
	// size dropdown menu to available browser space, or length of content, whichever is less
	content_obj = getobj(contentid);
	drop_top = get_page_top(dropdiv);
	win_bottom = get_window_height() + get_scroll_y();
	drop_height = (win_bottom - drop_top - 10);

	if (content_obj && content_obj.clientHeight != null) {
		content_height = content_obj.clientHeight;
		if (drop_height > content_height) drop_height = content_height;
	}
	if (drop_height != null && dropdiv.style) {
		if (dropdiv.style.pixelHeight != null) {
			dropdiv.style.pixelHeight = drop_height;
		} else if (dropdiv.style.height != null) {
			dropdiv.style.height = drop_height + 'px';
		}
	}
}

var dd;
function show_dropdown(id, e, align) {
	dropid   = id + '_drop';
	anchorid = id + '_menu';
	contentid  = id + '_content';
	if (dd) { 
		dd.style.visibility = 'hidden'; 
		dd.style.overflow = 'hidden';
	}
	dd = getobj(dropid);
    if (!dd || !dd.style || dd.style.visibility == 'visible') return;
	pos_dropdown(anchorid, dd, align);
	size_dropdown(dd, contentid);
    dd.style.visibility = 'visible';
    dd.style.overflow = 'scroll';
    document.onkeypress = keypress;
    document.onclick = hidedropdown;
    e.cancelBubble = true;
}
function is_clicked(e, id) {
    if (e.srcElement) t = e.srcElement; 
    else if (e.originalTarget) t = e.originalTarget; 
    while (t != null && t.parentNode != null) {
        if (t.id==id) return true;
        t = t.parentNode;
    }
    return false;
}
function do_hidedropdown() {
    dd.style.visibility='hidden';
    dd.style.overflow='hidden';
    document.onkeypress = null;
    document.onclick = null;
}
function hidedropdown(e) {
    if (window.event) e = window.event;
    if (dd && dd.style.visibility=='visible' && !is_clicked(e, 'funddrop')) 
        do_hidedropdown();
}
function keypress(e) {
    if (!e) e = window.event;
    if (e.keyCode) ekey = e.keyCode; 
    switch(ekey) {
    case 27:
        do_hidedropdown();
    }
}

