private bool Save()
	{

		if (!EditMode)
		{
			Item.CustomTypeId = UserTypeIdList.SelectedValue;
			string e = (Request["entityid"] == null) ? EntityIdTextBox.Text : entityid;
			if (String.IsNullOrEmpty(e))
				throw new BXEventException(GetMessage("Error.EntityIdRequired"));
			Item.OwnerEntityId = e;
			Item.Multiple = MultipleCheckBox.Checked;
			Item.Name = FieldNameTextBox.Text;
		}
		ValidateFieldName();


		Item.XmlId = XmlId.Text;
		int i;
		if (!int.TryParse(Sort.Text, out i))
			i = 10;
		Item.Sort = i;

		Item.Mandatory = Mandatory.Checked;
		Item.ShowInFilter = (BXCustomFieldFilterVisibility)Enum.Parse(typeof(BXCustomFieldFilterVisibility), ShowFilter.SelectedValue, true);
		Item.ShowInList = !DontShowInList.Checked;
		Item.EditInList = !DontEditInList.Checked;
		Item.IsSearchable = IsSearchable.Checked;
		Item.Settings.Clear();
		if (settings != null)
			Item.Settings.Assign(settings.GetSettings());

		BXCustomFieldLocalizationCollection loc = Item.Localization;
		loc.Clear();
		foreach (KeyValuePair<string, Dictionary<string, TextBox>> langLine in locControls)
		{
			BXCustomFieldLocalization l = new BXCustomFieldLocalization();

			l.EditFormLabel = langLine.Value["EditFormLabel"].Text;
			l.ListColumnLabel = langLine.Value["ListColumnLabel"].Text;
			l.ListFilterLabel = langLine.Value["ListFilterLabel"].Text;
			l.ErrorMessage = langLine.Value["ErrorMessage"].Text;
			l.HelpMessage = langLine.Value["HelpMessage"].Text;

			loc[langLine.Key] = l;
		}

		Item.Save();

		id = Item.Id;
		entityid = Item.OwnerEntityId;
		usertypeid = Item.CustomTypeId;
		fieldname = Item.Name;
		multiple = Item.Multiple;

		//EXTRA SETTINGS
		if (extraSettings != null)
			extraSettings.Save();

		return true;
	}
	public void FillLocalization(BXCustomField field, BXParamsBag<object> state)
	{
		foreach (string lang in BXLoc.Locales)
		{
			string key = "Loc." + lang;


			BXCustomFieldLocalization l = field.Localization[lang];
			if (l == null) 
			{
				l = new BXCustomFieldLocalization();
				field.Localization[lang] = l;
			}

			if (!state.ContainsKey(key))
				continue;

			string[] phrases = state.Get<string[]>(key);
			l.EditFormLabel = phrases[0];
			l.ErrorMessage = phrases[1];
			l.HelpMessage = phrases[2];
			l.ListColumnLabel = phrases[3];
			l.ListFilterLabel = phrases[4];
		}
	}