// 	Events
var 	JO_VMM_DATA_CHANGE_MY_DATA_TYPE					= 0;
var	JO_VMM_DATA_CHANGE_SOURCE_DATA_TYPE			= 1;
var	JO_VMM_DATA_CHANGE_DESTINATION_DATA_TYPE	= 2;
var 	JO_VMM_GUI_ON_GET_FOCUS							= 3;
var	JO_VMM_GUI_ON_RESIZE								= 40;

var	JO_VMM_EVENT_DATA_CHANGE_NONE					= 0;
var	JO_VMM_EVENT_DATA_CHANGE_NEW						= 1;
var	JO_VMM_EVENT_DATA_CHANGE_EDIT					= 2;
var	JO_VMM_EVENT_DATA_CHANGE_DELETE					= 4;
var	JO_VMM_EVENT_DATA_CHANGE_SELECTION				= 8;

var 	JO_VMM_GUI_VERTICAL_TOP_GAP						= 30;
var	JO_VMM_GUI_SCROLLER_HEIGHT						= 26;
var	JO_VMM_GUI_MODELLER_VERT_GAP						= 6;
var 	JO_VMM_GUI_SCENARIO_OBJECT_WIDTH				= 8;


var 	JO_VMM_GUI_LIST_WIDTH								= 220;
var 	JO_VMM_GUI_HORZ_MARGIN								= 40;
var 	JO_VMM_GUI_HORZ_MARGIN_TITLE						= 26;
var	JO_VMM_GUI_HORZ_MARGIN_HELP						= 8;

var 	DURATION_MINUTE										= 60 * 1000;

/* ********************************************************************************************************** */
/* ********************************************************************************************************** */
/* ********************************************************************************************************** */

function joVMMApplicationClass (data_obj)
{
	this.data_obj										= data_obj;
	
	this.InitGui										= _joVMMApp_InitGui;
	this.RefreshGui									= _joVMMApp_RefreshGui;
	this.OnResizeWin									= _joVMMApp_OnResizeWin;
	this.ResizeJobResultNodes						= _joVMMApp_ResizeJobResultNodes;
	
	this.gui_current_list							= null;
	this.gui_current_modeller						= null;

	this.gui_objects									= new joChainedListClass (this);
	this.GetGuiObject									= _joVMMApp_GetGuiObject;
	this.GuiObjectAction							= _joVMMApp_GuiObjectAction;
	this.OnChangeDataSelection					= _joVMMApp_OnChangeDataSelection;
	this.SetCurrentModeller						= _joVMMApp_SetCurrentModeller; 
	this.SetCurrentList								= function (gui_obj) { this.gui_current_list = gui_obj; } 
	this.RefreshScenarios							= _joVMMApp_RefreshScenarios;
	this.ActivateEntityInSecenarios				= _joVMMApp_ActivateEntityInSecenarios;

	this.gui_dialogs									= new joChainedListClass (this);
	this.GetGuiDialog									= _joVMMApp_GetGuiDialog;
	this.RemoveGuiDialog							= _joVMMApp_RemoveGuiDialog;
	this.GuiOpenDialog								= _joVMMApp_GuiOpenDialog;
	this.OnCloseDialog								= _joVMMApp_OnCloseDialog;
	this.EntityDlgChangesAllowed					= _joVMMApp_EntityDlgChangesAllowed;
	
	this.OnUpdateFormStatus						= _joVMMApp_OnUpdateFormStatus;
	
	this.AskNewFile									= _joVMMApp_AskNewFile;
	this.NewFile										= _joVMMApp_NewFile;
	this.SaveFile										= _joVMMApp_SaveFile;
	this.ActivateMenu									= _joVMMApp_ActivateMenu;
	
	this.InitAutoSave									= _joVMMApp_InitAutoSave;
	this.SetAutoSave									= _joVMMApp_SetAutoSave;
	this.AutoSave										= _joVMMApp_AutoSave;
	this.autosave_cycle								= 0;
	this.autosaver										= null;
	
	this.ShowCopyright								= _joVMMApp_ShowCopyright;
	this.SendEvent										= _joVMMApp_SendEvent;
	
	this.AddTitle										= _joVMMApp_AddTitle;
	this.AddHelpButton								= _joVMMApp_AddHelpButton;
}

/* ********************************************************************************************************** */

function _joVMMApp_ActivateEntityInSecenarios (calling_gui_obj) 
{
	var obj = this.gui_objects.element_first;
	while (obj)
	{
		if (obj.gui_type == "scenario" && obj.data_name == calling_gui_obj.data_name)
		{
			obj.SetActiveEntity (obj.id + "_" + calling_gui_obj.data_id, true);
		}
		obj = obj.element_next;
	}
}

/* ********************************************************************************************************** */

function _joVMMApp_RefreshScenarios (data_name) 
{ 
	var result = false;
	var obj = this.gui_objects.element_first;
	
	while (!result && obj)
	{
		if (obj.gui_type == "scenario")
		{
			for (var i = 0; i < obj.source_data_types.length; i++)
			{
				if (obj.source_data_types[i] == data_name) 
				{ 
					obj.ShowData();
					break; 
				}
			}
		}
		obj = obj.element_next;
	}
}

/* ********************************************************************************************************** */

function _joVMMApp_SetCurrentModeller (gui_obj) 
{ 
	if (this.gui_current_modeller)
	{
		this.gui_current_modeller.gui_container_node.style.display = "none";
		joFIND (this.gui_current_modeller.id + "_tab").className = "tab";
	}

	this.gui_current_modeller = gui_obj; 
	this.gui_current_modeller.gui_container_node.style.display = "block";
	joFIND (this.gui_current_modeller.id + "_tab").className = "tab_active";
	
	this.gui_current_modeller.OnEvent (JO_VMM_GUI_ON_GET_FOCUS);

	obj = this.gui_objects.element_first;
	
	//...................................................................................set list buttons' status
	while (obj)
	{
		// source types
		if (obj.destination_data_types)
		{
			for (var i = 0; i < obj.destination_data_types.length; i++)
			{
//				if (obj.destination_data_types[i] == this.gui_current_modeller.data_name) 
				{ 
					obj.OnEvent (JO_VMM_EVENT_DATA_CHANGE_SELECTION, JO_VMM_DATA_CHANGE_DESTINATION_DATA_TYPE);
					break; 
				}
			}
		}
		obj = obj.element_next;
	}
	
	//.............................if list object contains active element --> auto select this object in modeller
	var list_obj = this.GetGuiObject ("vmm_" + this.gui_current_modeller.data_name + "_list");
	if (list_obj && list_obj.data_id)
	{
		this.gui_current_modeller.SetData (list_obj.data_id);
		this.ActivateEntityInSecenarios (this.gui_current_modeller);		
	}
	
}

/* ********************************************************************************************************** */

function _joVMMApp_OnChangeDataSelection (data_type, data_id, activate_modeller)
{
	var obj;
	
	obj = this.gui_objects.element_first;
	while (obj)
	{
		if (obj.gui_type == "modeller" && obj.data_name == data_type)
		{
			obj.SetData (data_id);
			if (activate_modeller)
				this.SetCurrentModeller (obj);
		}			

		obj = obj.element_next;
	}
	
	obj = this.gui_objects.element_first;
	
	while (obj)
	{
		// source types
		if (obj.destination_data_types)
		{
			for (var i = 0; i < obj.destination_data_types.length; i++)
			{
				if (obj.destination_data_types[i] == data_type) 
				{ 
					obj.OnEvent (JO_VMM_EVENT_DATA_CHANGE_SELECTION, JO_VMM_DATA_CHANGE_DESTINATION_DATA_TYPE);
					break; 
				}
			}
		}
		obj = obj.element_next;
	}
}

/* ********************************************************************************************************** */

function _joVMMApp_OnCloseDialog (dialog_id, data_type, dialog_result)
{
	if (dialog_result != JO_VMM_EVENT_DATA_CHANGE_NONE)
	{
	 if (data_type.indexOf ("device") != -1) 
		{
			var device_model = this.GetGuiObject ("vmm_device_model");
			device_model.OnEvent (dialog_result, JO_VMM_DATA_CHANGE_MY_DATA_TYPE);
		}
		else
		{
			var obj = this.gui_objects.element_first;
	
			while (obj)
			{
				if (obj.data_name == data_type) 
				{
					obj.OnEvent (dialog_result, JO_VMM_DATA_CHANGE_MY_DATA_TYPE, dialog_id);
				}
				
				// source types
				if (obj.source_data_types)
				{
					for (var i = 0; i < obj.source_data_types.length; i++)
					{
						if (obj.source_data_types[i] == data_type && obj.data_name != data_type) 
						{ 
							obj.ShowData(); 
							obj.OnEvent (dialog_result, JO_VMM_DATA_CHANGE_SOURCE_DATA_TYPE);
							break; 
						}
					}
				}
				obj = obj.element_next;
			}
		}

	}
	this.RemoveGuiDialog (dialog_id);
}

/* ********************************************************************************************************** */

function _joVMMApp_RemoveGuiDialog (dialog_id)
{
	var del_dlg = this.GetGuiDialog (dialog_id);
	this.gui_dialogs.RemoveElement (del_dlg);
	del_dlg = null;
}

/* ********************************************************************************************************** */

function _joVMMApp_GetGuiDialog (dialog_id)
{
	var result = null;
	var dlg = this.gui_dialogs.element_first;
	
	while (!result && dlg)
	{
		if (dlg.id == dialog_id) result = dlg;
		else dlg = dlg.element_next;
	}

	return result;
}

/* ********************************************************************************************************** */

function _joVMMApp_GuiOpenDialog (data_collection_name, data_name, data_id)
{
	this.gui_dialogs.AppendElement (new joVMMEntityDlgClass (data_collection_name, data_name, data_id));
}

/* ********************************************************************************************************** */

function _joVMMApp_RefreshGui()
{
	var obj = this.gui_objects.element_first;
	
	while (obj)
	{
		obj.ResetData();
		obj.ShowData();
		obj = obj.element_next;
	}
}

/* ********************************************************************************************************** */

function _joVMMApp_InitGui()
{
	joGUI.OnUpdateFormStatusCallback = this.OnUpdateFormStatus;
	

	var device_list  		= new joVMMDeviceClass 
								(
									"vmm_device_model",							// my id
									"joVMMApp_lists_div",				 		// gui:	html parent node
									"device", 										// data: 	my data collection
									"device", 										// data:	my data type
									new Array ("object", "macro"), 			// data:	component data types					(= sources)
									new Array ("")									// data:	data types of which i am component	 		(= destinations)
								);

	var material_list 	= new joVMMDataListClass 
								(
									"vmm_material_list", 						// my id
									"joVMMApp_lists_div",				 		// gui:	html parent node
									"materials", 									// data: 	my data collection
									"material", 									// data:	my data type
									null, 											// data:	component data types					(= sources)
									new Array ("object", "device")			// data:	data types of which i am component			(= destinations)
								);

	var object_list  		= new joVMMDataListClass 
								(
									"vmm_object_list", 							// my id
									"joVMMApp_lists_div",				 		// gui:	html parent node
									"objects", 										// data: 	my data collection
									"object", 										// data:	my data type
									new Array ("material", "object"), 		// data:	component data types					(= sources)
									new Array ("macro", "device")			// data:	data types of which i am component 		(= destinations)
								);
	
	var macro_list  		= new joVMMDataListClass 
								(
									"vmm_macro_list", 							// my id
									"joVMMApp_lists_div",				 		// gui:	html parent node
									"macros", 										// data: 	my data collection
									"macro", 										// data:	my data type
									new Array ("object", "macro"), 			// data:	component data types					(= sources)
									new Array ("macro", "device")			// data:	data types of which i am component	 		(= destinations)
								);
																	
	var object_modeller = new joVMMDataModellerClass 
								(
									"vmm_object_modeller", 					// my id
									"joVMMApp_object_modeller_div", 		// gui:	html parent node
									"joVMMApp_object_div",						// gui:	html container node
									"objects", 										// data: 	my data collection
									"object", 										// data:	my data type
									new Array ("material"), 					// data:	component data types					(= sources)
									new Array ("macro", "device")			// data:	data types of which i am component 		(= destinations)
								);
																	
	var macro_modeller 	= new joVMMDataModellerClass 
								(
									"vmm_macro_modeller", 						// my id
									"joVMMApp_macro_modeller_div", 			// gui:	html parent node
									"joVMMApp_macro_div",						// gui:	html container node
									"macros", 										// data: 	my data collection
									"macro", 										// data:	my data type
									new Array ("object", "macro"), 			// data:	component data types					(= sources)
									new Array ("macro", "device")			// data:	data types of which i am component 		(= destinations)
								);
																	
	var device_modeller = new joVMMDataModellerClass 
								(
									"vmm_device_modeller", 					// my id
									"joVMMApp_device_modeller_div", 		// gui:	html parent node
									"joVMMApp_device_div",						// gui:	html container node
									"device", 										// data: 	my data collection
									"device", 										// data:	my data type
									new Array ("object", "macro"), 			// data:	component data types					(= sources)
									new Array ("")									// data:	data types of which i am component 		(= destinations)
								);

	var object_scenario	= new joVMMDataScenarioClass 
								(
									"vmm_object_scenario",						// my id
									"joVMMApp_object_scenario_div", 		// gui:	html parent node
									"objects", 										// data: 	my data collection
									"object", 										// data:	my data type
									new Array ("material", "object"), 		// data:	component data types					(= sources)
									object_list,									// gui:	my entity list
									object_modeller								// gui:	my entity modeller
								);

	var macro_scenario	= new joVMMDataScenarioClass 
								(
									"vmm_macro_scenario",						// my id
									"joVMMApp_macro_scenario_div", 			// gui:	html parent node
									"macros", 										// data: 	my data collection
									"macro", 										// data:	my data type
									new Array ("material", "object", "macro"),	// data:	component data types					(= sources)
									macro_list,										// gui:	my entity list
									macro_modeller									// gui:	my entity modeller
								);

	var device_scenario	= new joVMMDataScenarioClass 
								(
									"vmm_device_scenario",						// my id
									"joVMMApp_device_scenario_div",			// gui:	html parent node
									"device", 										// data: 	my data collection
									"device", 										// data:	my data type
									new Array ("material", "object", "macro", "device"),	// data:	component data types					(= sources)
									device_list,									// gui:	my entity list
									device_modeller								// gui:	my entity modeller
								);

	var device_simulator = new joVMMDataSimulatorClass 
								(
									"vmm_device_simulator",					// my id
									"joVMMApp_simulator_div",					// gui:	html parent node
									"tasks", 										// data: 	my data collection
									"task"											// data:	my data type
								);

	var calc_results 		= new joVMMDataResultClass 
								(
									"vmm_calc_results",							// my id
									"joVMMApp_results_div"						// gui:	html parent node
								);

	this.gui_objects.AppendElement (material_list);
	this.gui_objects.AppendElement (object_list);
	this.gui_objects.AppendElement (macro_list);
	this.gui_objects.AppendElement (device_list);
	
	this.gui_objects.AppendElement (object_modeller);
	this.gui_objects.AppendElement (macro_modeller);
	this.gui_objects.AppendElement (device_modeller);

	this.gui_objects.AppendElement (object_scenario);
	this.gui_objects.AppendElement (macro_scenario);
	this.gui_objects.AppendElement (device_scenario);

	this.gui_objects.AppendElement (device_simulator);
	this.gui_objects.AppendElement (calc_results);

//	this.SetCurrentModeller (calc_results);
	this.SetCurrentModeller (object_modeller);
	
	
	this.InitAutoSave();
}

/* ********************************************************************************************************** */

function _joVMMApp_InitAutoSave() 
{
	var select_mode;
	 
	select_node									= joFIND ("auto_save_cycle");
		joAddSelectOptionNode 				(select_node, "0", joGUI.GetLocaleText ("deactivated"));
		joAddSelectOptionNode 				(select_node, "1", "1 " + joGUI.GetLocaleText ("min"));
		joAddSelectOptionNode 				(select_node, "5", "5 " + joGUI.GetLocaleText ("min"));
		joAddSelectOptionNode 				(select_node, "20", "20 " + joGUI.GetLocaleText ("min"));
		joAddSelectOptionNode 				(select_node, "60", "1 " + joGUI.GetLocaleText ("hour"));
		select_node.onchange				= function() { joVMMApp.SetAutoSave (this.value); return false; };
}

/* ********************************************************************************************************** */

function _joVMMApp_SetAutoSave (value) 
{
	this.autosave_cycle = parseInt (value);
	
	if (this.autosaver)
	{
		window.clearTimeout (this.autosaver);
		this.autosaver = 0;
	}
	
	if (this.autosave_cycle)
	{
		this.autosaver = window.setTimeout ("joVMMApp.AutoSave()", this.autosave_cycle * DURATION_MINUTE);
	}
}

/* ********************************************************************************************************** */

function _joVMMApp_AutoSave() 
{
	if (this.autosaver)
	{
		joVMM.SaveTaskFormData();
		
		if (joVMM.project_name == "")
		{
			if (!dlg_load_save_open) joOpenLoadSaveDialog (false);
		}
		else
		{
			joVMMApp.SaveFile();
		}
	
		this.autosaver = window.setTimeout ("joVMMApp.AutoSave()", this.autosave_cycle * DURATION_MINUTE);
	}
}

/* ********************************************************************************************************** */

function _joVMMApp_OnUpdateFormStatus (form_node, form_status, field_node) 
{ 
	var form_owner_name = joDOM.GetAttribute (form_node, "vmm_gui_name", "");
	
	if (form_owner_name != "")
	{
		var form_owner = joVMMApp.GetGuiObject (form_owner_name);
		if (form_owner) 
			form_owner.OnUpdateFormStatus (form_node, form_status, field_node);
	}
}

/* ********************************************************************************************************** */

function _joVMMApp_GuiObjectAction (action_type, gui_object)
{
	switch (action_type)
	{
		case "new":
			this.GuiOpenDialog (gui_object.data_collection_name, gui_object.data_name, "");
			break;
		case "edit":
			{
				var collection_name = gui_object.data_collection_name;
				switch (collection_name)
				{
					case "tasks":
						gui_object.EditTask();
						break;
					case "device":
						joVMMApp.GuiOpenDialog ("device", "device", "");
						break;
					default:
						this.GuiOpenDialog (collection_name, gui_object.data_name, gui_object.data_id);
						break;
				}
			break;
			}
		case "add":
			joVMMApp.gui_current_modeller.AddEntity (gui_object); return false;
			break;
		case "first":
		case "left":
		case "right":
		case "last":
		case "top":
		case "bottom":
		case "up":
		case "down":
			gui_object.MoveActiveEntity (action_type); return false;
			break;
		case "delete":
			gui_object.RemoveActiveEntity();
			break;
		case "model":
			gui_object.ModelActiveEntity();
			this.ActivateEntityInSecenarios (gui_object);
			break;
		case "regex":
			gui_object.ExecRegex();
			break;
		case "genfile":
			gui_object.StartSimulation (false);
			break;
		case "start":
			gui_object.StartSimulation (true);
			break;
	}
}

/* ********************************************************************************************************** */

function _joVMMApp_GetGuiObject (object_id)
{
	var result = null;
	var obj = this.gui_objects.element_first;
	
	while (!result && obj)
	{
		if (obj.id == object_id) result = obj;
		else obj = obj.element_next;
	}

	return result;
}

/* ********************************************************************************************************** */

function _joVMMApp_AskNewFile()
{
	joGUI.Alert (joGUI.GetLocaleText ("joGUI_sure"), joGUI_ALERT_TYPE_NOTE, joGUI_ALERT_BUTTON_OK | joGUI_ALERT_BUTTON_CANCEL, joVMMApp.NewFile, this);
}

/* ********************************************************************************************************** */

function _joVMMApp_NewFile (result)
{
	if (result == joGUI_ALERT_BUTTON_OK)
	{
		joVMM.NewData();
		
		var obj = joVMMApp.gui_objects.element_first;

		while (obj)
		{
			if (obj.gui_title_node)
			{
				obj.gui_title_node.innerHTML = joGUI.GetLocaleText (obj.gui_type);
			}

			obj = obj.element_next;
		}
	}
}

/* ********************************************************************************************************** */

function _joVMMApp_SaveFile()
{
	joVMM.SaveTaskFormData();

	var upload_filename = joVMM.UserDir + joVMM.project_name + ".xml";
	var file_content 		= joVMM.PrepareSaveData (false);

 	joFIND ("vmm_device_model_Body").innerHTML = joVMM.project_name;
	ajax_upload (joGUI.GetLocaleText('php_path') + '/file_save.php', upload_filename, file_content, OnUpload);
}

/* ********************************************************************************************************** */

function _joVMMApp_ShowCopyright()
{
	joGUI.Alert ("Copyright 2008<br />by Austrian Research Centers GmbH &amp; Joachim Legat", joGUI_ALERT_TYPE_NOTE, joGUI_ALERT_BUTTON_OK);
}

/* ********************************************************************************************************** */

function _joVMMApp_ActivateMenu()
{
	joFIND ("menu_save_file").style.visibility = (joVMM.project_name != "" ? "visible" : "hidden");
}

/* ********************************************************************************************************** */

function _joVMMApp_SendEvent (event_type, event_data_type)
{
	var obj = this.gui_objects.element_first;
	
	//...................................................................................set list buttons' status
	while (obj)
	{
		obj.OnEvent (event_type, event_data_type);
		obj = obj.element_next;
	}
}	

/* ********************************************************************************************************** */

function _joVMMApp_EntityDlgChangesAllowed (old_data_id, new_data_id, data_name, old_is_virtual, new_is_virtual)
{
	var result = true;
	var element;
	var element_id;
	var entity_used_by = "";

	if (old_data_id != new_data_id || old_is_virtual != new_is_virtual)
	{
		entity_used_by = joVMM.EntityIsInUse (data_name, old_data_id);
		if (entity_used_by != "")
		{
			joGUI.Alert(joGUI.GetLocaleText ("msg_cannot_change_entity") + "<br />" + entity_used_by, joGUI_ALERT_TYPE_WARNING, joGUI_ALERT_BUTTON_OK);
			result = false;
		}
	}

	//....................................................evaluate if renaming obect is allowed or already in use
	if (result && old_is_virtual != new_is_virtual)
	{
		var data_entity = joVMM.GetEntityByID (data_name, new_data_id);
		if (data_entity)
		{
			var entity_body 	= data_entity.FindNode ("body", false);
			if (entity_body && entity_body.childNodes && entity_body.childNodes.element_first) result = false;
		}
		
		if (!result)
		{
			joGUI.Alert (joGUI.GetLocaleText ("msg_cannot_change_entity_state"), joGUI_ALERT_TYPE_WARNING, joGUI_ALERT_BUTTON_OK);
			result = false;
		}
	}

	if (result)
	{
		var data_collection = joVMM.entities[data_name];
		if (data_collection && data_collection.childNodes && data_collection.childNodes.element_first)
		{
			element = data_collection.childNodes.element_first;
			while (element && result)
			{
				element_id = element.GetAttribute ("id");
				if (element_id == new_data_id && element_id != old_data_id) result = false;
				else element = element.element_next;		
			}
		}
		
		if (!result)
		{
			joGUI.Alert(joGUI.GetLocaleText ("msg_cannot_add_entity"), joGUI_ALERT_TYPE_WARNING, joGUI_ALERT_BUTTON_OK);
		}
	}
	
	return result;
}

/* ********************************************************************************************************** */
/* ********************************************************************************************************** */
/* ********************************************************************************************************** */

var win_height;
var win_width;
var main_width;
var main_height;

var modeller_width;
var modeller_height;
var scenario_height;
var regex_width;

/* ********************************************************************************************************** */

function joOnResizeWin() { if (joVMMApp) joVMMApp.OnResizeWin(); }

function _joVMMApp_OnResizeWin()
{
	win_height 					= joGetWinInfo ("height");
	win_width 					= joGetWinInfo ("width");
	main_width					= win_width - JO_VMM_GUI_LIST_WIDTH - JO_VMM_GUI_HORZ_MARGIN;
	main_height					= win_height - JO_VMM_GUI_HORZ_MARGIN * 2;
	
	modeller_width 			= main_width - JO_VMM_GUI_HORZ_MARGIN - (ie? 171 : 176);
	modeller_height			= Math.round (main_height / 2 - (ie ? 50 : 61));
	scenario_height			= Math.round (main_height / 2 - (ie ? 49 : 60) - JO_VMM_GUI_SCROLLER_HEIGHT);
	regex_width					= main_width - JO_VMM_GUI_HORZ_MARGIN - (ie ? 35: 30);

	SetGUINodeSize ("container_app_bar", 					"width", 	JO_VMM_GUI_LIST_WIDTH);

	SetGUINodeSize ("DEBUG_CONTENT", 						"width", 	win_width - 60);
	SetGUINodeSize ("DEBUG_CONTENT", 						"height", 	win_height - JO_VMM_GUI_HORZ_MARGIN * 2 - JO_VMM_GUI_SCROLLER_HEIGHT - JO_VMM_GUI_VERTICAL_TOP_GAP);


	// ............................................................................................... modellers
	SetGUINodeSize ("object_modeller_resize", 			"width", 	modeller_width);
	SetGUINodeSize ("object_modeller_resize", 			"height", 	modeller_height);
	SetGUINodeSize ("object_modeller_resize_table", 	"width", 	modeller_width - JO_VMM_GUI_SCROLLER_HEIGHT);
	SetGUINodeSize ("object_modeller_resize_table", 	"height", 	modeller_height - JO_VMM_GUI_MODELLER_VERT_GAP);
	SetGUINodeSize ("object_regex", 						"width", 	regex_width);
	SetGUINodeSize ("object_regex", 						"height", 	18);
	SetGUINodeSize ("object_modeller_title", 			"width", 	main_width - JO_VMM_GUI_HORZ_MARGIN);
	SetGUINodeSize ("object_modeller_title", 			"height", 	12);

	SetGUINodeSize ("macro_modeller_resize", 			"width", 	modeller_width);
	SetGUINodeSize ("macro_modeller_resize", 			"height", 	modeller_height);
	SetGUINodeSize ("macro_regex", 							"width", 	regex_width);
	SetGUINodeSize ("macro_regex", 							"height", 	18);
	SetGUINodeSize ("macro_modeller_title", 			"width", 	main_width - JO_VMM_GUI_HORZ_MARGIN);
	SetGUINodeSize ("macro_modeller_title", 			"height", 	12);

	SetGUINodeSize ("device_modeller_resize", 			"width", 	modeller_width);
	SetGUINodeSize ("device_modeller_resize", 			"height", 	modeller_height);
	SetGUINodeSize ("device_regex", 						"width", 	regex_width);
	SetGUINodeSize ("device_regex", 						"height", 	18);
	SetGUINodeSize ("device_modeller_title", 			"width", 	main_width - JO_VMM_GUI_HORZ_MARGIN);
	SetGUINodeSize ("device_modeller_title", 			"height", 	12);
	
	// ................................................................................................ scenarios
	SetGUINodeSize ("object_scenario_resize", 			"width", 	main_width - JO_VMM_GUI_HORZ_MARGIN);
	SetGUINodeSize ("object_scenario_resize", 			"height", 	scenario_height);
	SetGUINodeSize ("object_scenario_title", 			"width", 	main_width - JO_VMM_GUI_HORZ_MARGIN);
	SetGUINodeSize ("object_scenario_title", 			"height", 	12);
	SetGUINodeSizeByNode (joFIND ("object_scenario_resize").firstChild, "height", scenario_height - (ie ? 12 : 6) - JO_VMM_GUI_SCROLLER_HEIGHT);

	SetGUINodeSize ("macro_scenario_resize", 			"width", 	main_width - JO_VMM_GUI_HORZ_MARGIN);
	SetGUINodeSize ("macro_scenario_resize", 			"height", 	scenario_height);
	SetGUINodeSize ("macro_scenario_title", 			"width", 	main_width - JO_VMM_GUI_HORZ_MARGIN);
	SetGUINodeSize ("macro_scenario_title", 			"height", 	12);
	SetGUINodeSizeByNode (joFIND ("macro_scenario_resize").firstChild, "height", scenario_height - (ie ? 12 : 6) - JO_VMM_GUI_SCROLLER_HEIGHT);

	SetGUINodeSize ("device_scenario_resize", 			"width", 	main_width - JO_VMM_GUI_HORZ_MARGIN);
	SetGUINodeSize ("device_scenario_resize", 			"height", 	scenario_height);
	SetGUINodeSize ("device_scenario_title", 			"width", 	main_width - JO_VMM_GUI_HORZ_MARGIN);
	SetGUINodeSize ("device_scenario_title", 			"height", 	12);
	SetGUINodeSizeByNode (joFIND ("device_scenario_resize").firstChild, "height", scenario_height - (ie ? 12 : 6) - JO_VMM_GUI_SCROLLER_HEIGHT);

	this.ResizeJobResultNodes();
	
	this.SendEvent (JO_VMM_GUI_ON_RESIZE, 0);
}

/* ********************************************************************************************************** */

function _joVMMApp_ResizeJobResultNodes()
{
	SetGUINodeSize ("jobs_list_title", "width", main_width - JO_VMM_GUI_HORZ_MARGIN_TITLE);
	SetGUINodeSize ("jobs_list_title", "height", 12);

	SetGUINodeSize ("job_detail_info", "width", Math.floor (main_width / 3));
	SetGUINodeSize ("job_detail_info", "height", modeller_height);

	SetGUINodeSize ("job_details_title", "width", Math.floor (main_width / 3) - JO_VMM_GUI_HORZ_MARGIN_HELP);
	SetGUINodeSize ("job_details_title", "height", 12);
	
	SetGUINodeSize ("job_result_list", "width", Math.floor (main_width / 3 * 2) - JO_VMM_GUI_HORZ_MARGIN);
	SetGUINodeSize ("job_result_list", "height", modeller_height);
	
	SetGUINodeSize ("job_result_title", "width", Math.floor (main_width / 3 * 2) - JO_VMM_GUI_HORZ_MARGIN - JO_VMM_GUI_HORZ_MARGIN_HELP);
	SetGUINodeSize ("job_result_title", "height", 12);
}	

/* ********************************************************************************************************** */

function SetGUINodeSize (node_id, size_type, fixed_size)
{
	var node = joFIND (node_id);
	if (node)
	{
		SetGUINodeSizeByNode (node, size_type, fixed_size);

	}
}	

/* ********************************************************************************************************** */

function SetGUINodeSizeByNode (node, size_type, fixed_size)
{
	if (fixed_size < 0) fixed_size = 10;
	var size = fixed_size;
	if (!size) size = GetGUINodeSize (node_id, size_type); 
	switch (size_type)
	{
		case "width": node.style.width 		= size;
		case "height": node.style.height 	= size;
	}
}



/* ********************************************************************************************************** */

function GetGUINodeSize (node_id, size_type)
{
	var result = 10;
	
	switch (size_type)
	{
		case "width":
		{
			switch (node_id)
			{
				case "job_list":
				{
					result = main_width  - JO_VMM_GUI_HORZ_MARGIN + 20;
					break;
				}
			}
			break;
		}
		case "height":
		{
			switch (node_id)
			{
				case "job_list":
				{
					result =  main_height / 2 - (ie ? 50 : 61);
					break;
				}
			}
			break;
		}
	}
	return result;
}

/* ********************************************************************************************************** */

function ShowHelp (anchor_name)
{
	var help_url 	= joGUI.GetLocaleText ("help_path");
	var win_id		= joGUI.GetLocaleText ("help_window_id");
	
	if (anchor_name && anchor_name != "") help_url += "#" + anchor_name;

	window.open (help_url, win_id);
}

/* ********************************************************************************************************** */

function _joVMMApp_AddTitle (parent_node, title_id, title_text, help_node_id)
{
	var table_node, tr_node, td_node, title_node;
	
	table_node							= joAddTableChildNode (parent_node, "gui_title", title_id + "_title");
		tr_node							= joAddHTMLChildNode (table_node, "TR");
			title_node					= joAddHTMLChildNode (tr_node, "TD");
				joAddTextChildNode 	(title_node, (title_text && title_text != "") ? title_text : joGUI.GetLocaleText (title_id));
			td_node						= joAddHTMLChildNode (tr_node, "TD");
				td_node.style.textAlign = "right";
				this.AddHelpButton	(td_node, title_id);
	
	return title_node;
}

/* ********************************************************************************************************** */

function _joVMMApp_AddHelpButton (parent_node, help_anchor)
{
	var a_node, img_node;
	
	if (parent_node)
	{
		a_node						= joAddHTMLChildNode (parent_node, "A", "help", help_anchor + "_link_node");
			a_node.href				= "javascript:ShowHelp ('" + help_anchor + "')";
				a_node.title		= joGUI.GetLocaleText ("help_link");
				img_node				= joAddHTMLChildNode (a_node, "IMG");
					img_node.src	= "images/button_help_link.gif";
					img_node.alt	= joGUI.GetLocaleText ("help_link");
	}
}

