

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_search( formname )
{
	var form = document.forms[formname];
	form.submit();
	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;
}

