/*************************************************************
/* Function:	clear_list_box   
/*                                                             
/* Purpose: 	Clear a list box from all options
/**************************************************************/
function clear_list_box(list)
{
	var length = list.options.length;
	while (length-- > 0)
		list.remove(0);
}

/*************************************************************
/* Function:	load_list_with_array   
/*                                                             
/* Purpose: 	Load a list box with values from a two dimensional array
/**************************************************************/
function load_list_with_array(list, arr)
{
	clear_list_box(list); // Clear the current box
	
	var length = arr.length;
	for (var i = 0; i < length; i++) // load the new options 
		list.options[i] = new Option(arr[i][1], arr[i][0]);
}

/*************************************************************
/* Function:	format_number   
/*                                                             
/* Purpose: 	Format a number to show a specific number of digits after the period
/* 				We start with the format of wx.yzabcx
/**************************************************************/
function format_number(number, after_period)
{
	if (number == 0) // Zero is simply zero
		return 0;
		
	// We want to be left with the format of wx.yz
	var temp_pow = Math.pow(10, after_period);
	number = (Math.floor(temp_pow * number)) / temp_pow;
	
	// At this point, we need to rid of trailing zeroes
	
	var temp_floor;
	for (var i = 0; i <= after_period; i++)
	{
		temp_pow = Math.pow(10, i);
		var temp_num = temp_pow * number;
		temp_floor = Math.floor(number * temp_pow);
		if (temp_floor == temp_num)
			break;
	}
	return temp_floor / temp_pow;
}

/*************************************************************
/* Function:	remove_option_from_select   
/*                                                             
/* Purpose: 	Remove a certain option from a list box
/**************************************************************/
function remove_option_from_select(listbox, option_num)
{
	// Copy all options backwards.
	var length = listbox.length - 1;
	for (var i = option_num; i < length; i++)
	{
		listbox.options[i].value = listbox.options[i + 1].value;
		listbox.options[i].text = listbox.options[i + 1].text;
	}
	// Consider deleting the last option
	listbox.length--;	
}

/*************************************************************
/* Function:	get_number_from_style   
/*                                                             
/* Purpose: 	Chop the last 2 chars from a string ('px'), and return as a number
/**************************************************************/
function get_number_from_style(pos)
{
	return parseInt(pos.substr(0, pos.length - 2));
}

var FADE = 0;
var APPEAR = 1;

/*************************************************************
/* Function:	fade   
/*                                                             
/* Purpose: 	Make an opacity change in an element
/**************************************************************/
function fade(id, fade_appear, fade_limit, fade_step, end_hook)
{
	var obj = document.getElementById(id);
	if (!obj)
		return;
	
	if (obj.style.opacity == "" || ((typeof obj.style.opacity) == "undefined"))
		obj.style.opacity = 1 - fade_appear; // 1 or zero 

	var opacity = obj.style.opacity;
		
	if(((fade_appear == FADE) && 
		((fade_limit == opacity) || opacity <= 0))
		||
		((fade_appear == APPEAR) && 
				((fade_limit == opacity) || (opacity == 1))))
	{
		if (end_hook != "" && end_hook != 0)
			eval(end_hook);
		return;
	}	
	
	if (fade_appear == FADE)
		opacity -= fade_step;
	else
		opacity = parseFloat(opacity) + fade_step;

	obj.style.opacity = opacity; // This works in firefox
	// Next line is for IE
	obj.style.filter = "Alpha(opacity=" + (opacity * 100) +")";
	
	setTimeout("fade('" + id + "'," + fade_appear + ", " + fade_limit + ", " + fade_step + ", '" + 	end_hook + "');", 1);
	
}
