function ov_get_last_id(arg_item_array,arg_item_selected_array)
{
	var var_return_array = arg_item_array[arg_item_selected_array[0]];	
	if (typeof(var_return_array))
	{
		return var_return_array[0];
	}else
	{
		return null;
	}
}

function get_last_clicked_values(ov_object_id)
{
	// thsi returns the last callback values used by an object
	// last_clicked_values is an array wher 0=event 1=object_array 2=clicked_id in object_array
	return eval('ov_previous_values_'+ov_object_id);
}

function ov_run_event (arg_event,arg_selected_index,arg_last_selected_array,arg_item_array,arg_item_selected_array,arg_html_container_id)
{
	// this should be the div that contains the object viewer			 
	var var_object_id = arg_item_array[arg_selected_index][0];
	var var_html_container = document.getElementById(arg_html_container_id);	
	// we reset the display for all elements in the main container
	ov_set_normal_class(var_html_container);
	// with arg_last_selected_index, 0 is the las clicked object, while 1 is the object we start any selection from when doing multiple select
	arg_last_selected_index = arg_last_selected_array[0];
	arg_last_selected_array[1] = (arg_last_selected_array[1]>-1?arg_last_selected_array[1]:arg_selected_index);
	arg_select_start_index = arg_last_selected_array[1];
	
	if (((arg_event.ctrlKey && arg_event.shiftKey) || (arg_event.shiftKey)) && (arg_last_selected_index > -1))
	{
		if (arg_select_start_index > arg_selected_index)
		{
			for (var i = arg_selected_index; i < (arg_select_start_index+1); i++)
			{	arg_item_selected_array[i] = true;}
		}else if (arg_select_start_index < arg_selected_index)
		{
			for (var i = arg_select_start_index; i < (arg_selected_index+1); i++)
			{	arg_item_selected_array[i] = true;}
		}
	}else if(arg_event.ctrlKey)
	{
		arg_last_selected_array[1] = arg_selected_index;
		if (arg_item_selected_array[arg_selected_index])
		{	arg_item_selected_array[arg_selected_index] = false;}else
		{	arg_item_selected_array[arg_selected_index] = true;}
	}else
	{
		arg_last_selected_array[1] = arg_selected_index;
		arg_item_selected_array[arg_selected_index] = true;
	}
	ov_select_objects(arg_item_array,arg_item_selected_array,arg_html_container_id);

	var var_function = '';
	if (arg_event.type == 'click') 
	{
		var_function = arg_item_array[arg_selected_index][4];		
	}else if (arg_event.type == 'dblclick') 
	{
		var_function = arg_item_array[arg_selected_index][5];
	}
	if (typeof(var_function) == 'function')
	{
		var callback_items_array = new Array();
		var callback_last_selected_index = -1;
		
		for (var_index in arg_item_selected_array)
		{
			if (arg_item_selected_array[var_index])
			{
				if (var_index == arg_selected_index)
				{	callback_last_selected_index = callback_items_array.length;}
				callback_items_array[callback_items_array.length] = arg_item_array[var_index];
			}
		}		
		var_function(arg_event,callback_items_array,callback_last_selected_index);
	}
	arg_last_selected_array[0] = arg_selected_index;
	return Array(arg_event,callback_items_array,callback_last_selected_index);
}

function ov_select_objects(arg_item_array,arg_item_selected_array,arg_ov_viewer_id)
{
	for (var_index in arg_item_selected_array)
	{
		if (arg_item_selected_array[var_index])
		{
			var_object_id = arg_item_array[var_index][0]+arg_ov_viewer_id;
			if (document.getElementById(var_object_id + "_text"))
			{
				ov_set_highlight_class(document.getElementById(var_object_id + "_text"));
			}
			else
			{
				// Descriptive list doesn't have a text bit, so just highlight the whole row.
				ov_set_highlight_class(document.getElementById(var_object_id));
			}
			
		}
	}
}

function ov_set_normal_class(arg_html_object)
{
	var var_children = arg_html_object.childNodes;
	for (var i = 0; i < var_children.length; i++)
	{
		if (typeof(var_children[i].style) != 'undefined')
		{
			var_children[i].style.backgroundColor='';
			var_children[i].style.color='';
		}
		ov_set_normal_class(var_children[i]);
	}
}

function ov_set_highlight_class(arg_html_object)
{
	if(arg_html_object.id)
	{
		var arg_array = arg_html_object.id.substring(arg_html_object.id.search("id_")).split('_');

		var browse_options_found='';
		
		try{
			browse_options_found=eval('browse_options_ov_id_'+arg_array[1]);
		}
		catch(e){}

		if(browse_options_found!='single')
		{
			if (typeof(arg_html_object.style) != 'undefined')
			{
				arg_html_object.style.backgroundColor='#0071b9';
				arg_html_object.style.color='#ffffff';
				if(arg_html_object.childNodes[0].style)
				{
					arg_html_object.childNodes[0].style.color = '#ffffff';
				}
			}
			var var_children = arg_html_object.childNodes;
			for (var i = 0; i < var_children.length; i++)
			{				
				ov_set_highlight_class(var_children[i]);
			}
		}
	}
}

function ov_click (arg_ov_viewer_id,arg_html_object_id)
{
	var var_ov_viewer = document.getElementById(arg_ov_viewer_id);
	var arg_html_object = document.getElementById(arg_html_object_id);ov_set_normal_class(var_ov_viewer);ov_set_highlight_class(arg_html_object);
}
