<!--
/*
 *	$Id: userEdit.js,v 1.1.1.1 2003/11/24 12:58:45 jgauld Exp $
 *	$Name:  $
 *
 *	User Editor
 */

// Globals
var BLOCKING = false;
var OLD_ACTIVE_STATE = 0;

//-------------------------------
// saveUser()
// - Sets 'id' to the specified id, and submits the form
//-------------------------------
function saveUser(id, form, NOTIFY_IF_ACTIVATE) {

	// Blocking
	if(BLOCKING) return false;
	BLOCKING = true;
	if(form['form[data][user][isActive]']!=null) {
	var currentActiveState = form['form[data][user][isActive]'][0].checked ? 1 : 0;
		var notify_field = form['NOTIFY_OF_ACTIVATE'];
		var isChanged = currentActiveState!=OLD_ACTIVE_STATE;
		NOTIFY_IF_ACTIVATE = parseInt(NOTIFY_IF_ACTIVATE);
	
		// Check if notification should be sent
		notify_field.value = (isChanged && parseInt(NOTIFY_IF_ACTIVATE)==2) ? "1" : "0";
		if(currentActiveState==1 && isChanged && NOTIFY_IF_ACTIVATE==1) {
			var notify = confirm("Do you want to notify this user\nof the change in their 'active' status?");
			notify_field.value = notify ? "1" : "0";
		}
	}

	// Set oid
	form['id'].value = id;

	// Submit form
	form.submit();
}

//-------------------------------
// updatePrimaryGroup()
// - Populates the primaryGroup dropdown with those
//   groups selected in usergroupList
//-------------------------------
function updatePrimaryGroup(usergroupList, primaryGroup) {

	// Test that primaryGroup dropdown exists
	if(primaryGroup==null) return false;

	// Blocking
	if(BLOCKING) return false;
	BLOCKING = true;

	// Vars
	var curSelected = null;

	// Empty primaryGroup
	var len = primaryGroup.options.length - 1;
	if(len>=0) {
		for(var i=len; i>=0; i--) {
			if(primaryGroup.options[i].selected) curSelected = primaryGroup.options[i].value;
			primaryGroup.options[i] = null;
		}
	}

	// Fill primaryGroup with selected usergroups
	var optCount = 0;
	for(var i=0; i<usergroupList.options.length; i++) {
		text = usergroupList.options[i].text;
		value = usergroupList.options[i].value;
		if(usergroupList.options[i].selected) {
			primaryGroup.options[optCount] = new Option(text, value, false, (curSelected==value));
			optCount++;
		}
	}

	// Blocking
	BLOCKING = false;
}

//-------------------------------
// VOID refineUserList( form, reset )
//--
// HTMLElement form	= Form to submit
// BOOL reset		= If set, then the form will be reset to it's blank settings before being submitted
//--
// Submits the form with the 'refine' operation
//-------------------------------
function refineUserList(form, reset) {

	// Blocking
	if(BLOCKING) return false;
	BLOCKING = true;

	// Vars
	if(reset==null) reset = false;

	// Reset
	if(reset) {
		var username = getHTMLElement('form[data][refine][username]');
		var rootUser = getHTMLElement('form[data][refine][rootUser]');
		var usergroup = getHTMLElement('form[data][refine][usergroup]');
		username.value = '';
		rootUser.selectedIndex = 0;
		usergroup.selectedIndex = 0;
	}

	// Submit form
	form.oper.value = 'refine';
	form.submit();
}

//-------------------------------
// VOID toggleRefineBox( state )
//--
// BOOL state	= Show/Hide refine box (true/false)
//--
// shows or hides the refine box
//-------------------------------
function toggleRefineBox(state) {

	// Vars
	var refineBox = getHTMLElement('refineBox');
	var curDisplay = refineBox.style.display;
	if(state==null) state = (curDisplay=='block' || curDisplay=='' || curDisplay==null) ? false : true;

	// Toggle display
	refineBox.style.display = state ? 'block' : 'none';
}

//-------------------------------
// VOID toggleDateExpire( fieldName, enabled )
//--
// STRING fieldName	= The prefix field name for all date elements
// BOOL enabled		= Whether to enable the date elements or not
//--
// Enables/Disables the date element dropdowns
//-------------------------------
function toggleDateExpire(fieldName, enabled) {

	// Vars
	if(enabled==null) enable = false;
	var suffix = ['Day', 'Month', 'Year', 'Hour', 'Minute'];

	// Disable/enable each element
	for(var i=0; i<suffix.length; i++) {
		var e = getHTMLElement(fieldName+'['+suffix[i]+']');
		if(e!=null) e.disabled = enabled;
	}
}
//-->