Svetlana_,
if (document.getElementById("tags").length > 0) {
document.getElementById("tags").value += document.getElementById("tags").value.charAt(document.getElementById("tags").length-1) != "," ? ","+mas.join(',') : mas.join(",");
} else {
document.getElementById("tags").value = mas.join(",");
}