
// POP UP
// usage: popuplink(['js-only url',] this[, w[, h[, scroll[, extras]]]])
// basic usage: <a href="popup.html" target="_blank" onclick="return(popuplink(this));">new pop</a>
// advanced usage: <a href="popup_nojs.html" target="_blank" onclick="return(popuplink('popup_yesjs.html', this, 200, 100, false));">new pop</a>
// site-wide defaults:
POPUP_W = 400;
POPUP_H = 300;
POPUP_SCROLL = true;
POPUP_EXTRAS = 'location=0,statusbar=0,menubar=0';
function popuplink() {
	var undef, i=0, args=popuplink.arguments;
	var url = (typeof(args[i])=='string') ? args[i++] : args[i].getAttribute('href');
	var target = args[i++].getAttribute('target') || '_blank';
	var w = args[i++];
	var h = args[i++];
	var s = (args[i]===undef) ? POPUP_SCROLL : args[i++];
	var features = 'width=' + (w || POPUP_W)
				 + ',height=' + (h || POPUP_H)
				 + ',scrollbars=' + (s ? 'yes,' : 'no,')
				 + ',resizable=yes,'
				 + (args[i] || POPUP_EXTRAS);
	var win = window.open(url, target, features);
	win.focus();
	return false;
}
// END POP UP

var EnterClick = Class.create({
	relevantTypes: $w('text password checkbox radio'),
	initialize: function (elForm, elButton) {
		this.elForm = elForm;
		this.elForm.addClassName("enterclick");
		this.elButton = elButton;
		this.elForm.observe('keypress', this.__keyPress.bindAsEventListener(this));
	},
	__keyPress: function (e) {
		var elSrc = e.element();
		if ((e.keyCode == Event.KEY_RETURN)
			&& (elSrc.nodeName == 'INPUT')
			&& (this.relevantTypes.include(elSrc.type))) {
			e.stop();
			this.elButton.click();
		}
	}
});
// Extend Element with enterclick
Element.addMethods({
	onEnterClick: function (elForm, elButton) {
		new EnterClick(elForm, elButton);
		return elForm;
	}
});

