var recipientCount=0;function addToList(id,name)
{if(id!=null&&name!=null&&document.getElementById("recipient_"+id)==null){if(recipientCount==0)document.getElementById("recipientList").innerHTML="";addElements(id,name);recipientCount++;}}
function addOrRemove(id,name)
{if(document.getElementById("recipient_"+id)==null){addToList(id,name);}}
function clearList()
{allSpans=document.getElementsByTagName("span");for(i=0;i<allSpans.length;i++){if(allSpans[i].getAttribute("id")!=null&&allSpans[i].getAttribute("id").indexOf("recipient_")==0){idAttr=allSpans[i].getAttribute("id");userId=parseInt(idAttr.substring(idAttr.lastIndexOf("_")+1,idAttr.length));window.setTimeout('removeFromList(userId);',100);if(document.getElementById("chooser_row_"+userId)!=null){document.getElementById("chooser_row_"+userId).style.backgroundImage="url("+IMAGE_HOST+"/images/icon_mail_add.gif)";}}}}
function addMultipleToList(idArray,nameArray)
{if(idArray!=null&&nameArray!=null&&idArray.length>0&&nameArray.length>0){for(i=0;i<idArray.length;i++){if(document.getElementById("recipient_"+idArray[i])==null){if(recipientCount==0)document.getElementById("recipientList").innerHTML="";addElements(idArray[i],nameArray[i]);recipientCount++;}}}}
function removeFromList(id)
{var elements=new Array(document.getElementById("recipient_"+id),document.getElementById("recipient_a_"+id));for(i=0;i<elements.length;i++){if(elements[i]!=null){elements[i].parentNode.removeChild(elements[i]);}}
if(document.getElementById("chooser_row_"+id)!=null){document.getElementById("chooser_row_"+id).style.backgroundImage="url("+IMAGE_HOST+"/images/icon_mail_add.gif)";}
recipientCount--;if(recipientCount==0)document.getElementById("recipientList").innerHTML="(Click names below to add them to the recipient list)&nbsp;&nbsp;&nbsp;";}
function addElements(id,name)
{var inputElement=document.createElement("input");var spanElement=document.createElement("span");var linkSpanElement=document.createElement("span");var linkElement=document.createElement("a");var removeImage=document.createElement("img");var recipientList=document.getElementById("recipientList");removeImage.setAttribute("src",IMAGE_HOST+"/images/clear.gif");removeImage.setAttribute("border","0");inputElement.setAttribute("type","hidden");inputElement.setAttribute("id","recipient_"+id);inputElement.setAttribute("name","recipients[]");inputElement.setAttribute("value",id);linkElement.setAttribute("title","click to remove");linkElement.className="messageScreenname";linkElement.setAttribute("href","javascript:removeFromList("+id+")");linkSpanElement.appendChild(document.createTextNode(name));linkElement.appendChild(linkSpanElement);linkElement.appendChild(document.createTextNode(', '));spanElement.setAttribute("id","recipient_a_"+id);spanElement.className="recipient";spanElement.appendChild(linkElement);recipientList.appendChild(inputElement);recipientList.appendChild(spanElement);if(document.getElementById("chooser_row_"+id)!=null){document.getElementById("chooser_row_"+id).style.backgroundImage="url("+IMAGE_HOST+"/images/clear.gif)";}}
function updateMessageBackground(){var backgroundUrl=document.getElementById('theme_image_name').value;if(backgroundUrl){if(plainText){var el=document.getElementById('bodyText');}
else{var el=tinyMCE.get('bodyText').getBody();}
el.style.backgroundImage='url(\''+backgroundUrl+'\')';}}