function resizePopup(popupWindow, popupWidth, popupHeight) {

   if (popupWidth > screen.width) { popupWidth = screen.width; }
   if (popupHeight > screen.height) { popupHeight = screen.height; }
   var offsetX = Math.round((screen.width - popupWidth) / 2);
   var offsetY = Math.round((screen.height - popupHeight) / 2);
   popupWindow.moveTo(offsetX, offsetY);
   popupWindow.resizeTo(popupWidth, popupHeight);
}

function UBS_refreshImage( id )
{
	if ( id && document[id] ) // ie bug: refresh image
	{
		var image = document[id].src;
		document[id].src = image;
	}
}

var UBS_popUp;

function UBS_open( url, pars, name, toCenter, button )
{
	if ( typeof( button ) != "undefined" ) UBS_refreshImage( button );
	
	function getCenterPos( type, winSize, scrDefault )
	{
		if ( !winSize ) return "";
		
		var scrSize = (screen[type]) ? screen[type] : scrDefault;
		var winPos  = (scrSize - winSize)/2;
		
		return ( type == "width" ) ? ",screenX="+winPos+",left="+winPos : ",screenY="+winPos+",top="+winPos;
	}
	
	var width  = 200; // default values
	var height = 200;
	// get width/height of window
	if ( toCenter )
	{
		// get width/height values
		var pairs = pars.split(",");
		for ( var i in pairs )
		{
			var p = pairs[i].split("=");
			if ( p[0] == "width" ) width = p[1];
			if ( p[0] == "height" ) height = p[1];
		}
	}
	
	if ( toCenter == "right" ) // right aligned
	{
		var scrSize = ( screen.width ) ? screen.width : 800;
		var winPos = scrSize - width;
		pars += ",screenX="+winPos+",left="+winPos;
		pars += ",screenY=0,top=0";
	}
	else if ( toCenter )
	{
		pars += getCenterPos("width",width,800);
		pars += getCenterPos("height",height,600);
	}
	
	UBS_popUp = window.open( url, name, pars );
	// check window due to pop-up blocking
	if ( UBS_popUp )
	{
		// use little delay to put window in foreground
		setTimeout("UBS_popUp.focus()",500);
	}
}

function UBS_openWindow( url, name, width, height, toCenter, button )
{
	var pars = "dependent=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
	
	if ( width )
	{
		// increase width to avoid scrollbars
		var innerWidth = parseInt( width )+10;
		width = innerWidth + 10;

		pars += ",width="+width+",innerWidth="+innerWidth;
	}
	if ( height )
	{
		pars += ",height="+height+",innerHeight="+height;
	}

	UBS_open( url, pars, name, toCenter, button );
}

function UBS_close()
{
	if ( opener ) opener.focus();
	window.close();
}

function UBS_linkToSelected( formname, fieldname )
{
	var form = document.forms[formname];

	if ( form )
	{
		var obj = form[fieldname];
		var url = obj.options[obj.selectedIndex].value;

		if ( url != "" )
		{
			if ( url.substring(0,11) == "javascript:" )
			{
				var jscall = url.substring(11);
				eval( jscall ); // execute javascript function
			}
			else
			{
				var urlObj = url.split(",");
				if ( urlObj[1] )
				{
					window.open( urlObj[0], urlObj[1] );
				}
				else
				{
					document.location.href = url;
				}
			}
		}
	}
}

function UBS_trim( string ) // remove leading/trailing spaces
{
	var invalid = " \n"; // characters to remove

	// check from start
	for ( var i = 0; i < string.length; i++ )
	{
		var ch = string.charAt( i );
		if ( invalid.indexOf( ch ) < 0 ) // valid char
		{
			string = string.substring( i );
			break; // stop loop
		}

		if ( i == string.length-1 ) string = ""; // no valid char found
	}

	// check from end
	for ( var i = string.length; i >= 0; i-- )
	{
		var ch = string.charAt( i );
		if ( invalid.indexOf( ch ) < 0 ) // valid char
		{
			string = string.substring( 0, i+1 );
			break; // stop loop
		}
	}

	return string;
}

function UBS_requestStat( link )
{
	if ( !link ) return true;

	var w = window.open( link, "UBS_Stats", "width=1,height=1,alwaysLowered=1" );
	w.blur();
	w.close();

	return true;
}

function UBS_search2( formname, fieldname, isSubmit )
{
	var form = document.forms[formname];

	if ( form[fieldname].value != "" && isSubmit )
	{
		var newValue = "";
		if ( form["restrictArea"] )
		{
			newValue = form["restrictArea"].value+":"+form["restrictContent"].value+" || ";
		}
		newValue += form[fieldname].value;
		form["qt"].value = newValue;
		form.submit();
		return true;
	}
	else if ( !isSubmit )
	{
		return form[fieldname].value != "";
	}
}

function UBS_search( formname )
{
	var form = document.forms[formname];
	form.submit();
	return true;
	
}
var UBS_oldImage = "";

function UBS_imageOn( imageId, newImage )
{
	if ( !document.images ) return;
	UBS_oldImage = document.images[ imageId ].src;
	document.images[ imageId ].src = newImage;
}

function UBS_imageOff( imageId )
{
	if ( document.images && UBS_oldImage )
	{
		document.images[ imageId ].src = UBS_oldImage;
		UBS_oldImage = "";
	}
}

function UBS_tweakstatusline(){
	/*
	** IE does not support the default shape of the area element in image maps.
	** By putting the image in a link, the same result can be achieved.   Unfortunately,
	** when the cursor is placed anywhere in the image, IE then displays only the URL
	** of that link in the browser status line.  The following function seems to circum-
	** vent the problem without solving it, wherefore it should be regarded as voodoo.
	*/
	if (ie) {
		status = '';	// Should be set to the URL of the area, but IE wrongly seems to					
					// interpret this as defaultStatus.
		return true;
	}
}

function UBS_rotateImages(idPlaceHolder, idImages, maxImages, invisibleClass, visibleClass) {
	var on = Math.floor(Math.random() * maxImages);
	for (i = 0; i < maxImages; i++) {
		var elt = document.getElementById(idImages + i);
		elt.className = invisibleClass;
	}
	document.getElementById(idPlaceHolder).className = invisibleClass;
	document.getElementById(idImages + on) .className = visibleClass;
	return true;
}

