/**************************************
/* POP-UP FUNCTIONS
/**************************************/
var _POPUP_FEATURES = "top=10,left=10,width=600,height=450,menubar=no,scrollbars=yes,toolbar=no";


function linksAsPopup(target, features) 
{
	if (target == '') target= 'popup';
	if (features == '') features	= _POPUP_FEATURES;
	var callback = function(el) { xAddEventListener(el, "click", event_popup_features(features)); };
	xGetElementsByAttribute("a", "target", "^" + target + "$", callback); 
}


// pops up a window containing url optionally named target, optionally having features 
function raw_popup(url, target, features) 
{
   	// Set parent window name - for easy reference from popup
   	
    if ( !xDef(features) ) {
		features = _POPUP_FEATURES;
	}
    if ( !xDef(target) ) {
		target   = '_blank';
	}

    var popupWindow = window.open(url, target, features);
    popupWindow.focus();
    return popupWindow;
}

function link_popup(src, features) 
{
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features); 
}

function event_popup(e)
{
    link_popup( findParentLink(e.target || event.srcElement) );
    xPreventDefault(e);
}

function event_popup_features(features) 
{
    return function(e) { link_popup( findParentLink(e.target || event.srcElement), features); xPreventDefault(e); }; 
}
function findParentLink(el)
{
	if (el == null) return null;
	if ( el.tagName == "A" ) return el;
	return findParentLink(el.parentNode);
}

