/*
		global_show_hide_functions.js
		-Product-
		-Section-or-area-this-template-is-for-
			
		Author:			Rawdyn Nutting
		Date:			-DD-MM-.2005
			
		USE:			-How-is-this-template-accessed-by-the-application-eg-included-on-job_card_cfm-etc-
		TASK:			-Basic-task-this-template-performs-
		OUTPUT:			-Any-output-this-template-produces-
		DOCUMENTS:		-Any-documentation-on-this-template-or-its-functionality
		NOTES:			This page also includes the help hints switch as that also used the show hide function
*/
var process_frame_name = 'frame_process';						// default this javascript as being called into an inline screen
if(window.frames.name=='frame_popup_content')					// This javascript can only be called into a display window (popup or inline)
	process_frame_name = 'frame_popup_process';					// if in popup mark process to go to the popup processing screen
	
var run_under_ajax = false;
function show_hide_help(the_help_elementIDs)					// function to show or hide the help on the page
{	
	if(arguments.length > 0 && the_help_elementIDs.length > 0)							// if any help hints paseed in
	{	var help_list_array = the_help_elementIDs.split(',');	// make the list an array
	
	
		var force_state = -1;
		var save_state = -1;
		var new_state = 'auto';
		if(arguments.length > 1)								// if two arguments passed in, the second is the force of state to on or off
			force_state = arguments[1];							// reset the force_state to the one instructed by the argument passed in
		
		if(force_state == 0)
		{	new_state = 'hide';
		}
		else if(force_state == 1)
		{	new_state = 'show';
		}
		//alert(new_state +' - '+ force_state);
		for(i=0;i<help_list_array.length;i++)					// loop over all elements
		{	show_hide_set(help_list_array[i],new_state,false);		// call the generic show hide function
			if(i==0)
				if(document.getElementById(help_list_array[i]).style.display=='none')
					save_state = '0';
				else
					save_state = '1';
		}
		if(force_state == -1)
			top[process_frame_name].location='/global/global_bin/global_tool_set_variable.cfm?var_name=help_display_on&var_value='+save_state;
	}
	else
		alert('This page does not contain any hints');
}
function show_hide_set(the_elementID,the_action,switch_remember_setting)						// get var based on browser (object to action,the action to take [auto|show|none],switch_remember_setting [true|false])
{	if(arguments.length > 3 && arguments[3] == 'ajax')
		run_under_ajax = true;
	else
		run_under_ajax = false;
	
	
	
	
	if (document.getElementById && document.getElementById(the_elementID) != null)				// if modern browser
 		show_hide(document.getElementById(the_elementID),the_action,switch_remember_setting);	// access by getElement
   	else if (document.layers && document.layers[the_elementID] != null)							// if NN 4
		show_hide(document.layers[the_elementID],the_action,switch_remember_setting);			// use layers
	else if (document.all)																		// IE 4 (and above as it happens though later should be caught by getElement)
		show_hide(document.all[the_elementID],the_action,switch_remember_setting);				// document.all DOM
}

function show_hide(obj,the_action,switch_remember_setting)
{	//alert(obj.style.display);
	if(the_action=='auto')
	{	if(obj.style.display=='none')
			show_hide_switch(obj.id,'show',switch_remember_setting);
		else
			show_hide_switch(obj.id,'none',switch_remember_setting);
	}
	else
		show_hide_switch(obj.id,the_action,switch_remember_setting);
}

function show_hide_switch(the_elementID,the_action,switch_remember_setting)
{	
	if(the_action == 'show')
	{	//alert(the_elementID);
		if (document.getElementById && document.getElementById(the_elementID) != null)
	 		node = document.getElementById(the_elementID).style.display='';
		else if (document.layers && document.layers[the_elementID] != null)
			document.layers[the_elementID].display = '';
		else if (document.all)
			document.all[the_elementID].style.display = 'inline';
	}
	else
	{	if (document.getElementById && document.getElementById(the_elementID) != null)
			node = document.getElementById(the_elementID).style.display='none';
		else if (document.layers && document.layers[the_elementID] != null)
			document.layers[the_elementID].display = 'none';
		else if (document.all)
			document.all[the_elementID].style.display = 'none';
	}
	
	
	//alert("Remember Switch State: ' + switch_remember_setting + ' - Frame Target: ' + process_frame_name);
	if(switch_remember_setting == true)
	{	if(run_under_ajax == true)
			set_server_variable('session',the_elementID,the_action);//alert('Runnign AJAX');
		else
			top[process_frame_name].location='/global/global_bin/global_tool_set_variable.cfm?var_name='+the_elementID+'&var_value='+the_action;//alert('Runnign FRAMES');
	}
}



