function toggle_tab(tab, task, focus_tab, hide_errors, extras)
	{ 
	extras=typeof(extras)!='undefined'?extras:'';

	if (tab==focus_tab)
		{
		return window.location='index.php?task='+task+'&tab='+focus_tab+extras;
		}

	// clear all errors
	if (hide_errors)
		{
		changed=false;
		$$("#spbas .success, #spbas .error").each(function(element)
			{
			element.remove();
			changed=true;
			});

		if (changed)
			{
			$$("#spbas div.inner_tab_content").each(function(element)
				{
				element.setStyle({'marginTop': '-12px'});
				});
			}
		}

	// set all to off
	$$("#inner_tab_container a.on").each(function(element)
		{
		element.toggleClassName('on');
		});

	// set all to off
	$$("#spbas div.inner_tab_content").each(function(element)
		{
		element.hide();
		});

	// set the target tab to focus
	tab_focus='tab_'+tab;
	$(tab_focus).toggleClassName('on');
	$(tab).show();
	}

function toggle_login_resend(focus_group)
	{
	if (focus_group=='resend_group')
		{
		$('resend_group').show();
		$('login_group').hide();
		$('resend_email').value=$('login_email').value;
		}
	else
		{
		$('resend_group').hide();
		$('login_group').show();
		$('login_email').value=$('resend_email').value;
		}
	}

function ignore() {}

/**
* A generic wrapper to prompting for a decision. 
* Loads the page if the user clicks the OK button.
*
* @param string page The page requested.
* @param string confirm_message The message to display to the end user.
*/
function prompt_decision(task, params, confirm_message)
	{
	if (confirm(confirm_message))
		{
		// lpp(module, page, params)
		window.location='index.php?task='+task+params;
		}

	return false;
	}


function toggle_state_province()
	{
	var has_states='states'+$F($('country_id'));

	$$('.states').each(function(item) { item.hide(); });
	if ($(has_states))
		{
		$(has_states).show();
		$('countries').hide();
		$('sop').value='state';
		}
	else
		{
		// $('states').hide();
		$('countries').show();
		$('sop').value='province';
		}
	}


function set_state_choice(country_id)
	{
	var state_id='states_'+country_id;

	$('state_id').value=$F($(state_id));
	}


function toggle_rows_to_show(link_out)
	{
	var max_rows=$F($('max_rows'));

	return window.location=link_out+'&max_rows='+max_rows;
	}


function discard_reply(id)
	{
	$('n'+id).hide();
	hide_uploads(id);
	}

function addFileInput(id) 
	{ 
	var file = document.createElement("input"); 

	file.setAttribute("type", "file"); 
	file.setAttribute("name", "attachment"+id+upload_number[id]); 
	file.setAttribute("class", "upload_box"); 

	var l = document.createElement("a"); 

	l.setAttribute("href", "javascript:removeFileInput('f"+id+upload_number[id]+"', "+id+");"); 
	l.appendChild(document.createTextNode("Remove")); 
	l.setAttribute("class", "upload_box"); 

	var d = document.createElement("div"); 

	d.setAttribute("id", "f"+id+upload_number[id]); 
	d.appendChild(file); 
	d.appendChild(document.createTextNode(" ")); 
	d.appendChild(l); 
 	d.setAttribute("class", "upload_container"); 

	document.getElementById("moreUploads_"+id).appendChild(d); 
	upload_number[id]++; 
	}

function show_uploads(s) 
	{ 
	$('a'+s).show();
	$('us'+s).hide();
	$('uh'+s).show();
	}

function hide_uploads(s) 
	{ 
	$('us'+s).show();
	$('uh'+s).hide();

	$('attachment1').value='';
	$('a'+s).hide();

	$$(".upload_box").each(function(elm)
		{
		elm.remove();
		});
	}

function removeFileInput(i, id) 
	{
	var elm = document.getElementById(i); 
	document.getElementById("moreUploads_"+id).removeChild(elm); 
	upload_number[id]-=1; // decrement the max file upload counter if the file is removed 
	} 

function choose_department(package_id)
	{
	department_id=$F($('department_id'));

	if (department_id==0)
		{
		return window.location='index.php?task=helpdesk&tab=start_ticket';
		}
	new Ajax.Updater('department_options', 'index.php', {
	evalScripts: true,
	method: 'POST',
	parameters: 'task=helpdesk&choose_department=y&department_id='+department_id+'&package_id='+package_id,
	onSuccess: function (t) { $('department_options').show(); }
	});
	}

function package_options(package_id)
	{
	//package_id=Form.getInputs('ticket_options','radio','package_id').find(function(radio) { return radio.checked; }).value;
	department_id=$F($('department_id'));

	new Ajax.Updater('package_renewal_options', 'index.php', {
	evalScripts: true,
	method: 'POST',
	parameters: 'task=helpdesk&choose_department=y&renewal_options=y&department_id='+department_id+'&package_id='+package_id, 
	onSuccess: function (t) { $('package_renewal_options').show(); }
	});
	}
