EventWall={};
EventWall.initialize=function()
{
}
EventWall.addComment=function()
{
   if(Utilities.getElement('calendar_id').value>0 && Utilities.getElement('comment').value!='' && (Utilities.getElement('user_id').value>0 || (Utilities.getElement('name') && Utilities.getElement('name').value!='')))
   {
      Utilities.getElement('commenterror').style.display='none';
      var comment=Utilities.getElement('comment').value;
      comment=comment.replace(/&/g,"and");
      comment=comment.replace(/;/g,"|");
      comment=comment.replace(/\n/g,"<br>");
      comment=escape(comment);
      var url="/phpclasses/serviceConnector.php?object=EventWallManager&method=addComment&params="+ Utilities.getElement('calendar_id').value +";"+ comment +";"+ Utilities.getElement('user_id').value +";"+ Utilities.getElement('name').value;
      AjaxUpdater.Update("GET",url,EventWall.onAddComment);
   }
   else
   {   
      Utilities.getElement('commenterror').style.display='block';
      Utilities.getElement('commenterror').innerHTML="Please enter your comment AND your name.";
   }
}
EventWall.onAddComment=function()
{
   if(Ajax.checkReadyState('loading')=="200")
   {
      var response=Ajax.getResponse();
        Utilities.getElement('comments_container').style.opacity = "1.0";
        Utilities.getElement('comments_container').style.filter='alpha(opacity=100)';
	//Utilities.getElement('comment').value='';
      if(response!="moderating" && !response.match("ERROR"))	//refresh comments list
      {
	 var comments=response.split("<comment>");
	 var html="";
	 if(comments.length==1)
		html+="<p>There is 1 post on this event's wall.  Join the discussion!</p>";
	 else
		html+="<p>There are "+ comments.length +" posts on this event's wall.  Join the discussion!</p>";
	 for(var i=0;i<comments.length;i++)
	 {
		if(i%2==0) var color="#f0f0f0";
		else var color="#ffffff";
		var details=comments[i].split("<detail>");	//comment<detail>user_id<detail>photo<detail>name<detail>l, F j, Y at g:ia T
		html+="<div class='eventwallpost' style='background-color:"+ color +";'><div style='text-align:center;margin:2px;float:left;'><a class=postlink2 href='/profiles/view/"+ details[1] +"'><img src='/images/"+ details[2] +"' border=0 width='40px'><br>"+ details[3] +"</a></div>"+ details[0] +"<p class='posted'>"+ details[4] +"</p><div style='clear:both;'></div></div>";
	 }
	 if(comments.length==0)
		html+="<p class=spacious><i>No one has posted on this wall yet.  Be the first!</i></p>";
	 Utilities.getElement('comments_container').innerHTML = html;
      }
      else if(response=="moderating")
      {
	 Utilities.getElement('comments_container').innerHTML+="<p class=spacious><i>Your comment is awaiting moderation.  It will be published once the moderator has approved its content.</i></p>";
      }
      Utilities.getElement('comment').value="";
   }
   else
   {
	Utilities.getElement('comments_container').style.opacity = "0.8";
        Utilities.getElement('comments_container').style.filter='alpha(opacity=80)';
   }
}

