
var RightsStr = new String( );

function AddSpecificRight( id )
{
	if( RightsStr.length > 0 )
		RightsStr += ",";
	RightsStr += id;
}

function AddRight( fld )
{
	if( fld && fld.checked )
	{
		if( !fld.disabled )
		{
			if( RightsStr.length > 0 )
				RightsStr += ",";
			RightsStr += fld.value;
		}
		return true;
	}
	return false;
}

function OnPublicUserClick()
{
	if( document.f.public_user.checked )
	{
		document.f.un.disabled = true;	
		document.f.pw.disabled = true;	
		document.f.confirm_pw.disabled = true;	
		document.f.fullname.disabled = true;	
		document.f.email.disabled = true;	
	}
	else
	{
		document.f.un.disabled = false;	
		document.f.pw.disabled = false;	
		document.f.confirm_pw.disabled = false;	
		document.f.fullname.disabled = false;	
		document.f.email.disabled = false;	
	}	
}

function SetRightsAndSubmit( )
{
	var bAdmin = false;
	RightsStr = "";
	
	AddRight( document.f.rights_superuser );

	if( AddRight( document.f.rights_settings ) )
		bAdmin = true;
	if( AddRight( document.f.rights_information ) )
		bAdmin = true;
	if( AddRight( document.f.rights_users ) )
		bAdmin = true;
	if( AddRight( document.f.rights_groups ) )
		bAdmin = true;
	if( AddRight( document.f.rights_statistics ) )
		bAdmin = true;
	if( AddRight( document.f.rights_adminemail ) )
		bAdmin = true;

	// Set generic 'Admin' flga if any of the admin rights have been granted
	if( bAdmin )
		AddSpecificRight( 100 );

	AddRight( document.f.rights_sitemap );
	AddRight( document.f.rights_newentries );
	AddRight( document.f.rights_guestbook );
	AddRight( document.f.rights_search );

	AddRight( document.f.rights_modify );
	AddRight( document.f.rights_delete );
	AddRight( document.f.rights_view );
	AddRight( document.f.rights_move );
	AddRight( document.f.rights_assign );
	AddRight( document.f.rights_email );

	AddRight( document.f.rights_addsections );
	AddRight( document.f.rights_addfolders );
	AddRight( document.f.rights_addmedia );

	AddRight( document.f.rights_viewmedia );
	AddRight( document.f.rights_viewmediafullsize );
	AddRight( document.f.rights_printmedia );
	AddRight( document.f.rights_sendmedia );
	AddRight( document.f.rights_enhancemedia );

	AddRight( document.f.rights_altname );
	AddRight( document.f.rights_restrictions );
	AddRight( document.f.rights_acceptref );
	AddRight( document.f.rights_createref );
	AddRight( document.f.rights_reorder );

	document.f.rights_delim.value = RightsStr;
	return true;
}

function SetupRight( str, right_fld )
{
	if( !right_fld )
		return;

	var rightsFlag = 0;
	rightsFlag = getrightflag( str, right_fld.value );
	
	if( rightsFlag & 1 )
		right_fld.checked=true;
}

function SetRights( str )
{
	SetupRight( str, document.f.rights_superuser );

	SetupRight( str, document.f.rights_settings );
	SetupRight( str, document.f.rights_information );
	SetupRight( str, document.f.rights_users );
	SetupRight( str, document.f.rights_groups );
	SetupRight( str, document.f.rights_statistics );
	SetupRight( str, document.f.rights_adminemail );

	SetupRight( str, document.f.rights_sitemap );
	SetupRight( str, document.f.rights_newentries );
	SetupRight( str, document.f.rights_guestbook );
	SetupRight( str, document.f.rights_search );

	SetupRight( str, document.f.rights_modify );
	SetupRight( str, document.f.rights_delete );
	SetupRight( str, document.f.rights_view );
	SetupRight( str, document.f.rights_move );
	SetupRight( str, document.f.rights_assign );
	SetupRight( str, document.f.rights_email );

	SetupRight( str, document.f.rights_addsections );
	SetupRight( str, document.f.rights_addfolders );
	SetupRight( str, document.f.rights_addmedia );

	SetupRight( str, document.f.rights_viewmedia );
	SetupRight( str, document.f.rights_viewmediafullsize );
	SetupRight( str, document.f.rights_printmedia );
	SetupRight( str, document.f.rights_sendmedia );
	SetupRight( str, document.f.rights_enhancemedia );

	SetupRight( str, document.f.rights_altname );
	SetupRight( str, document.f.rights_restrictions );
	SetupRight( str, document.f.rights_acceptref );
	SetupRight( str, document.f.rights_createref );
	SetupRight( str, document.f.rights_reorder );
}

function SetAccountRights( )
{
	// attempt to get existing cookie values for this user
	// NOTE: passing type=1 indicates to look for a user
//	if( !getusercookierights( 1 ) )
//		return;

	// if rights have been found for this user in the cookie, 
	// then set them as the default settings
	SetRights( account_rights );
}

function SetGroupRights( )
{
	// attempt to get existing cookie values for this group
	// NOTE: passing type=2 indicates to look for a group
//	if( !getusercookierights( 2 ) )
//		return;

	// if rights have been found for this user in the cookie, 
	// then set them as the default settings
	SetRights( account_rights);
}
