/**
 * (./) utils.js, v0.1, 05/12/07 13:12
 * (by) cousot stephane @ http://www.ubaa.net/
 * (cc) some right reserved
 *
 * Miscellaneous useful functions
 *
 * This document is a part of the AJAX Admin Framework project, based on the Wrapper project.
 * This project is released under a Creative Commons Licence BY
 * ‹ http://creativecommons.org/licenses/by/3.0/ ›
 */



/**
 * Return whether the current key pressed is not ENTER or not one of the given keyCode.
 * Use this function to disable form submit on enter keypress : see the onKeyPressed event
 *
 *	onkeypressed = "return pass(event)";
 *
 * @param Event		the key pressed event
 * @param array		[ a list of all accepted keycode ]
 */
function pass( event, mask ) {

	if ( !event ) event = window.event;	 // IE only
	
	var key = event.keyCode ? event.keyCode : event.which ;
	
	if ( !mask ) return key!=13;		// ENTER only
	for( var i=0; i<mask.length; i++ ) 	// use mask
		if ( mask[i]==key ) return true;
		
	return false;
	
}

/**
 * Open document in a new window with the given dimensions.
 * 
 * @param String	the target document
 * @param int		the window width
 * @param int		the window height
 */
function popup( url, width, height ) {
	
	width  = Math.min( screen.availWidth, width );
	height = Math.min( screen.availHeight, height );
	
	var x = Math.max( (screen.availWidth-width) / 2, 0 );
	var y = Math.max( (screen.availHeight-height-33) / 2, 0 );
	
	window.open(
		url,
		'_btpopup', 
		'toolbar=0,resizable=1,scrollbars=1,screenx='+x+',screeny='+y+',width='+width+',height='+height
	);
}
