function PopupWindow ( the_url,the_name,w,h,x,y,the_align,the_valign,extra_features ) {

	var the_padding = 30;

	// i am reducing the values for screen width and height because 
	// the original values don't seem to count the scrollbars and toolbar
	var the_screen_w = screen.width - the_padding;
	var the_screen_h = screen.height - the_padding;
	

	if ( ! the_url ) {
		alert( "No URL specified for pop-up window");
	}
	if ( ! the_name ) {
		name = 'CT';
	}

	// dimensions
	if ( ! w || w == 'default' ) {
		w = 500;
	}
	if ( ! h || h == 'default' ) {
		h = 400;
	}
	// x offset
	if ( the_align == 'right' ) {
		x = the_screen_w - w;
	}
	else if ( the_align == 'center' ) {
		x = the_screen_w/2 - w/2;
	}
	else if ( the_align == 'left' || ! x ) {
		x = the_padding;
	}

	// y offset
	if ( the_valign == 'bottom' ) {
		y = the_screen_h - h;
	}
	else if ( the_valign == 'middle' ) {
		y = the_screen_h/2 - h/2;
	}
	else if ( the_valign == 'top' || ! y ) {
		y = the_padding;
	}

	//alert("w="+w+",h="+h+",x="+x+",y="+y+",screenwidth="+the_screen_w+",screenheight="+the_screen_h);

	x = parseInt ( x );
	y = parseInt ( y );
	w = parseInt ( w );
	h = parseInt ( h );
	the_screen_w = parseInt ( the_screen_w );
	the_screen_h = parseInt ( the_screen_h );
	

	// sanity check - let's try and make sure the window remains within the screen limits
	if ( x < 0 ) {
		x = the_padding;
	}
	
	if ( x > the_screen_w || ( (x+w) > the_screen_w && x < the_screen_w )) {
		x = the_screen_w - w;
	}
	if ( y < 0 ) {
		y = the_padding;
	}
//	if ( y > the_screen_h || ( (y+h) > the_screen_h && y < the_screen_h )) {
//		alert('modifying y value of ' +y+ ' to allow window to fit inside screen');
//		y = the_screen_h - y;
//		alert('new value is:'+y);
//	}

	var the_features = 'resizable,scrollbars,height='+h+',width='+w+',screenX='+x+',screenY='+y+',top='+(y+1)+',left='+(x+1);
	if ( extra_features ) {
		the_features = extra_features + ',' + the_features;
	}
	new_window = window.open ( the_url, the_name, the_features );
	new_window.focus();
	return false;
}

function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for ( i = 0; i < field.length; i++) {
			if ( (field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}
