function AddNewKey (theKeyID, theKey, newKey)
{
	var oIdx;
	if (newKey) {	
		if (!CheckField (newKey, szMsgAddNewKeywords, "'|#\"", false, true, true))
			return;
	}
	if(newKey && newKey.value.length > 0)
	{
		var theNewOtpion;
		var nInser
		// need to check if key is OK
		oIdx = GetOrderIndex (theKey.options, "text", newKey.value);
		// la chiave c'e` gia`
		if (oIdx.bExist)
			return;
		nInser = oIdx.i;

		oIdx = GetOrderIndex (theKeyID.options, "text", newKey.value);
		if (oIdx.bExist) {
			//la chiave e` presente tra quelle disponibili
			theNewOption = new Option (theKeyID.options[oIdx.i].text, theKeyID.options[oIdx.i].value);
		}
		else {
			if (!confirm (szMsgNewKey + "\n" + newKey.value))
				return;
			theNewOption = new Option (newKey.value, 0);
		}

		InserIntoOptions (theKey.options, nInser, theNewOption);	
		newKey.value = "";
		return;
	}
	for (var i = theKeyID.options.selectedIndex; i != -1 && i < theKeyID.options.length; i++) {
		if (!theKeyID.options[i].selected)
			continue;
		oIdx = GetOrderIndex (theKey.options, "text", theKeyID.options[i].text);
		if (oIdx.bExist)
			continue;
		InserIntoOptions (theKey.options, oIdx.i, new Option (theKeyID.options[i].text, theKeyID.options[i].value));
	}
}



function RemoveNewKey(theKeyID)
{
	var i = theKeyID.options.selectedIndex;
	if (i < 0)
		return;
	var nIndexErased = i;
	for (; i < theKeyID.length; i ++) {
		if (!theKeyID.options[i].selected) 
			theKeyID.options[nIndexErased++] =  new Option (theKeyID.options[i].text, theKeyID.options[i].value);
	}
	for (;i >= nIndexErased; i--) {
		theKeyID.options[i] =  null;
	}
}

function FillHiddenKey (TheField, TheSelectField, bValue)
{
	TheField.value = "";
	for (var i = 0; i < TheSelectField.options.length; i++) {
		if (TheField.value.length)
			TheField.value += '|';
		if (bValue)
			TheField.value += TheSelectField.options[i].value;
		else
			TheField.value += TheSelectField.options[i].text;
		TheSelectField.options[i].selected = false;
	}
}

