	var FloatLayers       = new Array();
	var FloatLayersByName = new Array();
	
	var pillArray = [ 'pill_green.gif', 'pill_purple.gif', 'pill_aqua.gif', 'pill_pink.gif' ];
	
	// Apply background images to front-page pill boxes
	function assignPills()
	{
		var pillRow = document.getElementById( "pillRow" );
		
		if ( pillRow )
		{
			for ( i = 0; i < pillRow.childNodes.length; i++ )
			{
				if ( pillRow.childNodes[i].tagName == 'td'
					|| pillRow.childNodes[i].tagName == 'TD' )
				{
					pillRow.childNodes[i].style.background = "url(/themes/bp/images/" + pillArray.shift() + ")";
				}
			}
		}
	}
	
	function setup()
	{
		//alert( regionSelectArray.length );
		
		// Set up the reg form select boxes
		for ( var region in regionList )
		{
			var regionFrag = new Array();
			selectStr = new String( regionList[region] ).split( "," );
			
			for ( var i = 0; i < selectStr.length; i++ )
			{
				regionFrag.push( selectStr[i] );
			}
			
			optionArray[region] = regionFrag;
		}
		
		var regionSelect = document.getElementById( "Form_ClientForm_Region" );
		
		if ( regionSelect )
		{
			regionSelect.onchange = function ( event )
			{
				var target;
				if ( window.event )
					target = window.event.srcElement
				else
					target = event.target;
				
				var regionIndex = target.options[target.options.selectedIndex].value;
				var diagnoseSelect = document.getElementById( "Form_ClientForm_Diagnose" );
				diagnoseSelect.disabled = false;
				
				diagnoseSelect.innerHTML = "";
				
				for ( var i = 0; i < optionArray['region'+regionIndex].length; i++ )
				{
					var split = optionArray['region'+regionIndex][i].split( "|" );
					var option = document.createElement( "option" );
					option.value = split[0];
					option.innerHTML = split[1];
					
					diagnoseSelect.appendChild( option );
				}
				
				if ( regionIndex == 0 )
					diagnoseSelect.disabled = true;
			}
		}
		
		// Set up floating elements (right-hand reg form, left-hand sub-menu)
		/* -- removed due to jerky performance 
		var floatForm = document.getElementById( "floatyForm" );
		var floatLayer = new FloatLayer( floatForm, 0, 0, 3 )
		floatLayer.detach();
		
		var floatMenu = document.getElementById( "Sidebar" );
		if ( floatMenu )
		{
			var menuLayer = new FloatLayer( floatMenu, 0, 0, 3 );
			menuLayer.detach();
		}
		
		alignFloatLayers();
		*/
	}
	
	function FloatLayer( element, offX, offY, speed )
	{
		this.element			= element;
		this.index				= FloatLayers.length;
		this.name				= element.id;
		this.tm					= null;
		this.steps				= speed;
		this.alignHorizontal	= (offX >= 0) ? leftFloater : rightFloater;
		this.alignVertical		= (offY >= 0) ? topFloater : bottomFloater;
		
		this.getXCoord			= getXCoord;
		this.getYCoord			= getYCoord;
		
		this.ifloatX			= Math.abs(offX);
		this.ifloatY			= Math.abs(offY);
		this.floatX				= this.ifloatX;
		this.floatY				= this.ifloatY;
		this.prevX				= 0;
		this.prevY				= 0;
		
		this.detach				= detach;
		this.initialize			= defineFloater;
		this.adjust				= adjust;
		this.align				= align;
		
		FloatLayers.push( this );
		FloatLayersByName[this.name]	= this;
	}
	
	function detach()
	{
		this.element.style.top			= this.getYCoord();
		this.element.style.left			= this.getXCoord();
		this.element.style.position		= 'absolute';
		
		this.initialize();
		
		this.align();
	}
	
	function getXCoord()
	{
		el = this.element;
		
		x = 0;
		while( el )
		{
			x += el.offsetLeft;
			el = el.offsetParent;
		}
		return x;
	}
	
	function getYCoord()
	{
		el = this.element;
		
		y = 0;
		while( el )
		{
			y += el.offsetTop;
			el = el.offsetParent;
		}
		return y;
	}
	
	function align()
	{
		this.alignHorizontal();
		this.alignVertical();

		if ( this.prevX != this.floatX || this.prevY != this.floatY )
		{
			if ( this.tm == null )
				this.tm = setTimeout( 'FloatLayers['+this.index+'].adjust()', 50 );
		}
	}
	
	function defineFloater()
	{
		this.width					= this.element.offsetWidth;
		this.height					= this.element.offsetHeight;
		this.prevX					= this.element.offsetLeft;
		this.prevY					= this.element.offsetTop;
		
		this.floatX					= this.prevX;
		this.floatY					= this.prevY;
		
		this.ifloatX				= this.prevX;
		this.ifloatY				= this.prevY;
	}
	
	
	function leftFloater()
	{
		this.floatX = this.ifloatX;
		this.floatX += ( document.body.scrollLeft || document.documentElement.scrollLeft );
	}
	
	function topFloater()
	{
		this.floatY = this.ifloatY;
		this.floatY += document.body.scrollTop || document.documentElement.scrollTop;
	}
	
	function rightFloater()
	{
		this.floatX = document.body.scrollLeft +
			document.body.clientWidth - this.ifloatX - this.width;
	}
	
	function bottomFloater()
	{
		this.floatY = document.body.scrollTop +
			document.body.clientHeight - this.ifloatY - this.height;
	}
	
	
	// Step floating element towards desired position on screen
	function adjust()
	{
		this.tm = null;
		
		var dx = Math.abs( this.floatX-this.prevX );
		var dy = Math.abs( this.floatY-this.prevY );
		
		if (dx < this.steps / 2)
			cx = (dx >= 1) ? 1 : 0;
		else
			cx = Math.round( dx/this.steps );
		if ( dy < this.steps/2 )
			cy = (dy >= 1) ? 1 : 0;
		else
			cy = Math.round( dy/this.steps );
		
		if ( this.floatX > this.prevX )
			this.prevX += cx;
		else if ( this.floatX < this.prevX )
			this.prevX -= cx;
		
		if ( this.floatY > this.prevY )
			this.prevY += cy;
		else if ( this.floatY < this.prevY )
			this.prevY -= cy;
		
		this.element.style.left = this.prevX + "px";
		this.element.style.top  = this.prevY + "px";
		
		if ( cx != 0 || cy != 0 )
		{
			if ( this.tm == null )
			this.tm = setTimeout( 'FloatLayers['+this.index+'].adjust()', 50 );
		}
		else
			this.align();
	}
	
	function alignFloatLayers()
	{
		for ( var i=0; i<FloatLayers.length; i++ )
		{
			FloatLayers[i].align();
		}
	}