﻿function SetRecipeOptionValue(itemId, chkId, txtId)
{
    var SEPERATOR = "|";
    var currentValue = txtId.value.split(SEPERATOR);
    if (currentValue == "" || txtId.value[0] != SEPERATOR)
    {
        txtId.value = txtId.value + SEPERATOR;
    }
    if (chkId.checked)
    {
        var found = false;
        for (i = 0; i < currentValue.length; i++)
        {
            if (currentValue[i] == itemId)
            {
                found = true;
                break;
            }
        }
        if (!found)
        {
            //add the item
            txtId.value = txtId.value + itemId + SEPERATOR;
        } 
    }
    else
    {
        for (i = 0; i < currentValue.length; i++)
        {
            if (currentValue[i] == itemId)
            {
                //remove the item
                txtId.value = txtId.value.replace(itemId + SEPERATOR, "");
                break;
            }
        }
    }
}
