// the functions in this file require the supplementary library lib.js

// These defaults should be changed the way it best fits your site
//var _POPUP_FEATURES = 'location=0,statusbar=0,menubar=0,width=555,height=530';
var _POPUP_FEATURES = 'location=0,statusbar=0,menubar=0';

function raw_popup(url, target, features, w, h, Scroll) {
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target  )) target   = '_blank';
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars='+Scroll+',';
	settings +='resizable=no';
    var theWindow = window.open(url, target, settings);
    theWindow.focus();
    return theWindow;
	
	/*var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars='+Scroll+',';
	settings +='resizable=no';
	win=window.open(mypage,myname,settings);
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}*/
}

function link_popup(src, features, w, h, Scroll) {
    // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features, w, h, Scroll);
}

function event_popup(e) {
    // to be passed as an event listener
    // pops up a window grabbing the url from the event source's href
    link_popup(e.currentTarget);
    e.preventDefault();
}

function event_popup_features(features, w, h, Scroll) {
    // generates an event listener similar to event_popup, but allowing window features
    return function(e) { link_popup(e.currentTarget, features, w, h, Scroll); e.preventDefault() }
}

listen('load', window, function() {
	listen('click', 'popup-view0'  , event_popup_features('location=0,statusbar=1,menubar=1','695','600','1','qmark') );
	listen('click', 'popup-view1'  , event_popup_features('location=0,statusbar=1,menubar=1','695','600','1','qmark') );
	listen('click', 'popup-view2'  , event_popup_features('location=0,statusbar=1,menubar=1','695','600','1','qmark') );
});