--------------------------------------------------------------------------------
-- HELPER FUNCTIONS
--------------------------------------------------------------------------------
function FromWS( WString )
	return userMods.FromWString( WString )
end
--------------------------------------------------------------------------------
function ToWS( str )
	return userMods.ToWString( str )
end
--------------------------------------------------------------------------------
function FromCFG( section, config_internal )
	if not config_internal then
		return userMods.GetAvatarConfigSection( section ) or {}
	else
		local config = userMods.GetAvatarConfigSection( section ) or {}
		local config_new = config_internal
		for k, v in config do
			if not config_internal[ k ] then
				config_new[ k ] = v
			else
				for l, m in v do
					config_new[ k ][ l ] = m
				end
			end
		end
		return config_new
	end
end
--------------------------------------------------------------------------------
function ToCFG( section, config, config_internal )
	if not config_internal then
		userMods.SetAvatarConfigSection( section, config )
	else
		local config_new = {}
		for k, v in config do
			if ( not config_internal[ k ] ) or ( config_internal[ k ] ~= v ) then
				config_new[ k ] = v
			end
		end
		userMods.SetAvatarConfigSection( section, config_new )
	end
end
--------------------------------------------------------------------------------
function GetGameLocalization()
	local LocOption = options.GetOptionsByCustomType( "interface_option_localization" )
	if LocOption then for _, id in LocOption do
		for i, v in options.GetOptionInfo( id ) do 
			if i == "values" then
				for _, l in v do 
					for j, m in l do 
						if j == "name" then	return FromWS( m ) end 
					end 
				end 
			end 
		end 
	end	end
end
--------------------------------------------------------------------------------
function L( text )
	if Locales[ localization ] and Locales[ localization ][ text ] then
		return Locales[ localization ][ text ]
	else
		return Locales[ "eng" ][ text ] or text
	end
end
--------------------------------------------------------------------------------
function ValInTable( table, value )
	local result = false
	for i, v in table do
		if value == v then
			result = true
		end
	end
	return result
end
--------------------------------------------------------------------------------
function GetDistance( pos1, pos2 )
	return math.sqrt( ( pos2.posX - pos1.posX )^2 + ( pos2.posY - pos1.posY )^2 + ( pos2.posZ - pos1.posZ )^2 )
end
--------------------------------------------------------------------------------
function GetChildCheckedEx( wtParent, name )
	local result1, result2 = nil, nil
	local children = wtParent:GetNamedChildren()
	for i = 0, GetTableSize( children ) - 1 do
		local wtChild = children[i]
		if string.find( wtChild:GetName(), name ) then
			result1 = wtParent:GetChildChecked( wtChild:GetName(), false )
			result2 = wtChild:GetName()
			--LogInfo( result2 )
		end
	end
	return result1, result2
end
--------------------------------------------------------------------------------
function ToLowerCase( str )
	for x = 192, 223 do
		str = string.gsub( str, string.char( x ), string.char( x + 32 ) )
	end
	for x = 65, 90 do
		str = string.gsub( str, string.char( x ), string.char( x + 32 ) )
	end
	return str
end
--------------------------------------------------------------------------------
function ToUpperCase( str )
	for x = 192 + 32, 223 + 32 do
		str = string.gsub( str, string.char( x ),string.char( x - 32 ) )
	end
	for x = 65 + 32, 90 + 32 do
		str = string.gsub( str, string.char( x ), string.char( x - 32 ) )
	end
	return str
end
--------------------------------------------------------------------------------
local function toHex( N )
	if N == nil then
		return "00"
	elseif N == 0 then 
		return "00"
	else
		N = math.max	( 0, N 		)
		N = math.min	( N, 255 	)
		N = math.ceil	( N 		)
		return string.sub("0123456789ABCDEF", 1+(N-(N-math.floor(N/16)*16))/16, 1+(N-(N-math.floor(N/16)*16))/16)..string.sub("0123456789ABCDEF", 1+(N-math.floor(N/16)*16), 1+(N-math.floor(N/16)*16))
	end
end
--------------------------------------------------------------------------------
function GetHexFromRGBA( RGBA )
	return "0x"..toHex( RGBA.a*255 )..toHex( RGBA.r*255 )..toHex( RGBA.g*255 )..toHex( RGBA.b*255 )
end
--------------------------------------------------------------------------------
-- REDEFINITIONS
--------------------------------------------------------------------------------
--
--------------------------------------------------------------------------------
