
function showUnitIndexLoading() {
	var loading_overlay = 
		"<div id=\"loading_overlay\">" +
			"<div id=\"loading_notice\">" +
				"<img src=\"/img/loadingAnimation.gif\"></div>"
			"</div>"
		"</div>";
	new Insertion.Top('the_dialog', loading_overlay);
	Position.clone('the_dialog', 'loading_overlay', {setWidth:false, setHeight:true});
	var mt = Math.round($('loading_overlay').getHeight() / 3);
	$('loading_notice').setStyle({'margin-top':mt + 'px'});
	new Effect.Opacity('units_index', {duration:0.2, from:1.0, to:0.4});
	new Effect.Opacity('loading_overlay', {duration:0.2, from:0.0, to:0.5});
}

function hideUnitIndexLoading() {
	Position.clone('the_dialog', 'loading_overlay', {setWidth:false, setHeight:true});
	new Effect.Opacity('units_index', {duration:0.2, from:0.4, to:1.0});
	new Effect.Opacity('loading_overlay', {duration:0.2, from:0.5, to:0.0, afterFinish: removeLoadingOverlay});
}

function removeLoadingOverlay() {
	$('loading_overlay').remove();
}


var unit_index_filterWindow;

function unit_index_showFilterWindow() {

	if (unit_index_filterWindow != null) { 
		 unit_index_filterWindow.destroy();
	} else { 
		unit_index_filterWindow = new Window({ 
			maximizable: false, resizable: false, minimizable: false, 
			hideEffect:Element.hide, showEffect:Element.show, minWidth: 10, 
			destroyOnClose: true, height:'480px', width:'540px'}); 
		unit_index_filterWindow.setContent('units_index_form', false, false);
		unit_index_filterWindow.showCenter(); 
		$('units_index_form').show();
		
		
		// Set up a windows observer, check ou debug window to get messages 
		myObserver = { 
			onDestroy: function(eventName, win) { 				
				if (win == unit_index_filterWindow) {

					/* 'saveCheckboxValues' will be function only in IE6 */
					if(typeof(saveCheckboxValues) == 'function') {
						saveCheckboxValues();
					}

					unit_index_filterWindow = null; 
					Windows.removeObserver(this);
					$('units_index_form').hide(); 
				} 				
			} 
		} 
		Windows.addObserver(myObserver); 
	}
}

function unit_index_setCheckboxes(name, checked) {
	if(!name)
		return;
	var elements = $$(name);
	if(!elements)
		return;
	elements.each(function (item) { item.checked = checked});
}

function unit_index_hideFilterForm() {
	if (unit_index_filterWindow != null) { 
		unit_index_filterWindow.destroy();

		/* 'restoreCheckboxValues' will be function only in IE6 */
		if(typeof(restoreCheckboxValues) == 'function') {
			restoreCheckboxValues();
		}
		return false;
	}	
	
}
