/*

	WALL.JS
	All wall related functions and selector events

	Functions:
		wallModule( userID, communityID, numWallPosts, refresh ) : the core function that drives the wall module on the Community and MyAccount pages.
		wallModuleHome( userID, communityID, numWallPosts, refresh ) : the core function that drives the wall module on the Community and MyAccount pages.
		moreWall() : increases the global wall posts amount by three and reloads the wallModule()
		submitWallComment( userId, parentId, comment, communityId ) : sends wall comment to myom.wallcomment table. 
		hideWallComment( commentID ) : hides selected commentID (either child or parent) from community wall.
*/

function wallModuleHome( userID, communityID )
{	
        if( get_cookie( 'lang' ) == 'ar' )
        {
                $('#wallContainer').addClass('ar');
                $('#comwall').html('المجتمع الجدار');
        } else  {
                        $('#wallContainer').removeClass('ar');
                        $('#comwall').html('Community Wall');
                }

	var params = "func=wall&userID=" + get_cookie( 'userid' ) + "&communityID=" + communityID + "&numWallPosts=3";
	var time = new Date();
        var epoch = time.getTime();
		
	openMsgBox();
	$('#msgboxmsg').html( 'Retreiving wall comments - Please wait..' ).hide().show( 250, function()
	{
		$.ajax(
		{
			type: "POST",
			async: true,
			url: "/cgi-bin/funcHandler.cgi",
			data: params,
			dataType: "xml",
			success: function(data)
			{
				if ( $(data).find('RESULT').text() == "TRUE" )
				{
					var html= "";
					
					$(data).find('COMMENTS').each( function(index)
					{
						var thisSection = $(this).find('SECTION').text();
						var commID = $(this).find('COMMENTID').text();
						var userID = $(this).find('USERID').text();
						var userName =  $(this).find('USERNAME').text();
						var parentID =  $(this).find('PARENTID').text();
						var homeComID =  $(this).find('HOMECOMMUNITYID').text();
						var homeComName =  $(this).find('HOMECOMMUNITYNAME').text();
						var timeStamp = $(this).find('TIMESTAMP').text();
						var comment =  $(this).find('COMMENT').text();
						comment = comment.replace(/\n/g,"<br>");
											
								switch(thisSection)
								{
									case "PARENT":
									html += "<!-- start: PARENT COMMENT jquery -->\n";
									html += "<div class='wallPostParent clearfix'>\n";
									html += "<span class='wallImage'><img width=42 height=42 src='/users/" + userID + "/photos/userprofilepic-sml.jpg?seed=" + epoch +"'></span>"; 
									html += "<p><span class='meta'><a href='#'><em>" + userName + "</em></a> <a href='/community/" + getCommunityUrl( homeComID ) + "'>" + homeComName + "</a></span> ";
									comment = comment.substr(0,39);
									comment = comment + " ...";                                
									html += "<span>" + comment + "</span>";
									html += "<span class='date timeago' title='"+timeStamp+"'>" + timeStamp + "</span>";
									html += "</p></div><!-- end: PARENT COMMENT -->";
									break;
								} // END SWITCH
							}); // END COMMENTS.EACH
						} else if( $(data).find('ERROR').text() == "no comments" )
							{
								var html = "<p class='empty test'>There are no comments in this community - Be the first to add one by logging in and connect with other people who live in your community.</p>";
								$('#wallComments').html( html );
							} else	{
									$('#error').html( $(data).find('ERROR').text() ).css('display', 'block');
								}
						$('#wallComments').html(html).fadeIn(3000);
						closeMsgBox();
						$("span.timeago").timeago();
							
					} // END AJAX SUCCESS
				}); // END AJAX METHOD
				
			}); // 	END PROCESS BOX
}

function morewall( area )
{
	//alert( "Cookie = " + get_cookie('currentCommunityID') + " Javascript = " + currentCommunityID );
	if( area == "myaccount" ) 
	{ 
		currentNumWallPosts += 15;
		wallModuleBig( get_cookie( 'selectedCommunityID' ), currentNumWallPosts ); 
	}
	if( area == "community" ) 
	{ 
		currentNumWallPosts += 3;
		wallModuleBig( currentCommunityID, currentNumWallPosts ); 
	}
}

function createWallComment( parentID, comment )
{
	$('.clickBtn').attr('disabled','true');
	// CHECK INPUT
	if( $.trim(comment) == "" ) 
	{ 
 		$('.clickBtn').removeAttr("disabled");
		displayError( 'You must type a comment in order to post it to the wall' ); 
		return; 
	}

	var params = 	"func=createComment" + 
			"&parentID=" + parentID + 
			"&comment=" + encodeURIComponent( $.trim(comment) ) + 
			"&system=" + get_cookie('selectedSystem') + 
			"&region=" + get_cookie('selectedRegion') + 
			"&bldid=" + get_cookie('selectedBldID') +
			"&lotid=" + get_cookie('selectedLotID') +
			"&email=" + get_cookie('email') +
			"&roles=" + get_cookie('selectedRoles') +
			"&mycomUUID=" + get_cookie('mycomUUID') + 
			"&type=comment";

	if( $('body').hasClass('account') == true ) 
	{ 
		params += "&communityid=" + get_cookie('selectedCommunityID') + "&communityname=" + get_cookie('selectedCommunityName') + "&communityurl=" + get_cookie('selectedCommunityURL'); 
	}
	if( $('body').hasClass('community') == true ) 
	{ 
		params += "&communityid=" + get_cookie('currentCommunityID') + "&communityname=" + get_cookie('currentCommunityName') + "&communityurl=" + get_cookie('currentCommunityURL'); 
	}
	//alert( params ); return;

	openMsgBox();
        $('#msgboxmsg').html('Creating Wall Comment').show( 250, function()
	{
        	$.ajax(
       		{
        	        type: "POST",
        	        async: true,
        	        url: "/cgi-bin/mycom.cgi",
        	        data: params,
        	        dataType: "xml",
        	        success: function(data)
        	        {
         	      	     	$(data).find('RESULTS').each( function()
				{
					var result = $(this).find('RESULT').text();
					if (result == "TRUE")
					{
						displaySuccess( 'Comment Successfully Created' );
						setTimeout( function()
						{
							if( $('body').hasClass('account') ) { wallAccount(); } else { wallModuleBig(); }
						},  3000 );
					} else  {
							$('.clickBtn').removeAttr("disabled");
							displayError(  $(data).find('ERROR').text() );
						}
				});
                	}
        	});
	});
}

function hideBigWallComment( commentID )
{
        var params = "func=hideBigWallComment&commentID=" + commentID;
        // alert( params );

        $.ajax(
        {
                type: "POST",
                async: true,
                url: "/cgi-bin/mycom.cgi",
                data: params,
                dataType: "xml",
                success: function(data)
                {
                        $(data).find('RESULTS').each( function()
                        {       
                                var result = $(this).find('RESULT').text();
                                if (result == "TRUE") 
                                {       
					displayMessage( 'success', 'Succesfully Removed Wall Post' );
                                        wallModuleBig();
					closeFooterBar();
                                } else	{
						displayMessage( 'error', 'Could not remove comment at this, please try again later');
					}       
                        });     
                }
        });
}


function hideWallComment( messageid )
{
        var params = "func=hideBigWallComment&messageid=" + messageid;
	// alert( params );

	openMsgBox();
        $('#msgboxmsg').html('Removing Wall Comment').show(250, function()
	{
        	$.ajax(
        	{
        	        type: "POST",
        	        async: true,
        	        url: "/cgi-bin/mycom.cgi",
        	        data: params,
        	        dataType: "xml",
        	        success: function(data)
        	        {
        	            	$(data).find('RESULTS').each( function()
				{
					var result = $(this).find('RESULT').text();
					if (result == "TRUE")
					{
						displaySuccess( 'Wall Comment Removed.' );
						setTimeout( function()
						{
							if( $('body').hasClass('account') ) { wallAccount(); } else { wallModuleBig(); }	
						}, 3000);
					} else	{
							displayError( $(data).find('ERROR').text() );
						}
				});
        	        }
		});		
    	});
}


function wallAccount()
{
	var html = '';

        // WALL HEADER
	if( get_cookie('lang') == 'ar' )
	{
        	var bigWall = '\
<h2>المجتمع -- وول</h2>\
        <div id="wall-container">\
                <div id="wall-head" class="wall-padding wall-block">\
                        <div id="main-comment">\
                                <div id="comment-input"></div>\
                        </div>\
                        <div id="community-wall-info">\
                                <h3>سياسة الاستخدام المجتمع الجدار</h3>\
                                <ul>\
                                        <li>ولا يتم رصد هذا الجدار من قبل الإدارة</li>\
                                        <li>لا تقدم طلبات الصيانة على الجدار</li>\
                                        <li>وتقدم الجدار للتفاعل الاجتماعي <br />(قضايا الصيانة لا)</li>\
                                        <li>يمكن أن تحول قبالة الجدار اذا اسيء استعمالها</li>\
                                </ul>\
                        </div>\
                        <!-- end: community wall info -->\
                <div id="service-req">\
                        <h3>وأود أن أتقدم بطلب من أجل :</h3>\
                        <form id="sWallForm">\
                                <input type="radio" checked="" value="security-request" name="request">\
                                <label for="problemInside">طلب الأمن</label>\
                                </span> <span>\
                                <input type="radio" value="maintenance-request" name="request">\
                                <label for="problemOutside">طلب الصيانة</label>\
                                </span>\
                                <div class="button-wrap">\
                                        <input type="submit" value="يأخذني هناك" class="clickBtn">\
                                </span></div>\
                        </form>\
                </div>\
                <!-- end: service request -->\
        </div>\
        <!-- end: WALL HEAD -->\
        <div id="wall" class="wall-block"></div>\
</div>';
	} else	{

        		var bigWall = '\
<h2>COMMUNITY > Wall</h2>\
        <div id="wall-container">\
                <div id="wall-head" class="wall-padding wall-block">\
                        <div id="main-comment">\
                                <div id="comment-input"></div>\
                        </div>\
                        <div id="community-wall-info">\
                                <h3>Community Wall Usage</h3>\
                                <ul>\
                                        <li>This wall is NOT monitored by management</li>\
                                        <li>Do not submit maintenance requests on the wall <br />(use options on right)</li>\
                                        <li>The wall is provided for social interaction <br />(not maintenance issues)</li>\
                                        <li>The wall can be turned off if misused (so be nice :)</li>\
                                </ul>\
                        </div>\
                        <!-- end: community wall info -->\
';
			
			if( checkThisSystemRoles( 'Lot Owner,Tenant') == 1 )
			{
				bigWall += '\
                	<div id="service-req">\
                        	<h3>I would like to make a</h3>\
                        	<form id="sWallForm">\
                                	<input type="radio" checked="" value="security-request" name="request">\
                                	<label for="problemInside">Service Request</label>\
                                	</span> <span>\
                                	<input type="radio" value="maintenance-request" name="request">\
                                	<label for="problemOutside">Maintenance Request</label>\
                                	</span>\
                                	<div class="button-wrap">\
                                        	<input type="submit" value="Take me there" class="clickBtn">\
                               		</span></div>\
                        	</form>\
                	</div>\
                	<!-- end: service request -->\
';
			}
			
			bigWall += '\
        </div>\
        <!-- end: WALL HEAD -->\
        <div id="wall" class="wall-block"></div>\
</div>';
		}
	// IF LOGGED IN CREATE COMMENT INPUT AREA
        if( get_cookie( 'mycomUUID' ) != false )
        {
                var time = new Date();
                var epoch = time.getTime();
                if( get_cookie( 'lang' ) == 'ar' ) // line added to add arabic default text values
                {
                        var commentInput = "<span class='user-image'><img width='64' height='64' src='/users/" + get_cookie( 'mycomUUID' ) + "/photos/userprofilepic-sml.jpg?seed=" + epoch + "'></span><form><input type='hidden' id='parentId' value=''><textarea class='usercomment' id='myComments' placeholder='ﺄﻀﻓ ﺖﻌﻠﻴﻘﻛ ﻪﻧﺍ...'></textarea><div class='button-wrap'><input type='button' class='clickBtn' value='إنشاء التعليق' /></div></form></div>";
                } else  {
                                var commentInput = "<span class='user-image'><img width='64' height='64' src='/users/" + get_cookie( 'mycomUUID' ) + "/photos/userprofilepic-sml.jpg?seed=" + epoch + "'></span><form id='parentWallComment'><input type='hidden' id='parentId' value=''><textarea class='usercomment' id='myComments' placeholder='Write your comments here...'></textarea><div class='button-wrap'><input type='submit' class='clickBtn' value='Post Comment' /></div></form></div>";
                        }
        }

	// GET WALL COMMENTS
        var params = "func=getComments&type=wall&numPosts=" + currentNumWallPosts + "&communityID=" + get_cookie('selectedCommunityID');

	openMsgBox();
	if( get_cookie('lang') == "ar" )
	{
		var message = "استرداد الجماعة الجدار";
	} else	{
			var message = "Retrieving MyCommunity Wall";
		}
        $('#msgboxmsg').html( message ).hide().show( 750, function()
        {
                $.ajax(
                {
                        type: "POST",
                        async: true,
                        url: "/cgi-bin/mycom.cgi",
                        data: params,
                        dataType: "xml",
                        success: function(data)
                        {
                                if ( $(data).find('RESULT').text() == "TRUE")
                                {
                                        $(data).find('PARENT').each( function()
                                        {
                                                var commentID = $(this).find('COMMENTID:first').text();
                                                var mycomUUID = $(this).find('MYCOMUUID:first').text();
                                                var comment = $(this).find('COMMENT:first').text();
                                                var fname = $(this).find('FNAME:first').text();
                                                var lname = $(this).find('LNAME:first').text();
                                                var timeAgo = $(this).find('TIMEAGO:first').text();

                                                html += "<!-- start: WALL ITEM  --><div class='wall-item wall-padding'><div class='wall-post'><div class='likes-comments'>";
                                                if( checkThisSystemRoles( 'oaManager' ) )
                                                {
                                                        html += "<span id=" + commentID + "><a href='#' class='remove-comment'>Remove Comment</a> | </span>";
                                                }
                                                html += "<span class='comment'><a href='#'>Comment</a></span></div>";
						html += "<span class='user-image'> <img width='64' height='64' src='/users/" + mycomUUID + "/photos/userprofilepic-sml.jpg?seed=" + epoch +"'> </span>";
                                                if( $.trim(fname) == "" && $.trim(lname) == "" )
                                                {
                                                        html +="<span class='name'><a href='/profile/" + mycomUUID + "'>User "+ mycomUUID +"</a></span>";
                                                } else  {
                                                                html +="<span class='name'><a href='/profile/" + mycomUUID + "'>"+ fname +" "+ lname +"</a></span>";
                                                        }
                                                html +="| <span class='date'>" + timeAgo + "</span><span><p>" + comment +"</p></span></div> <!-- end: WALL-POST --><div class='child-items'>";

                                                $(this).find('CHILD').each( function()
                                                {
                                                        var commentID = $(this).find('COMMENTID').text();
                                                        var mycomUUID = $(this).find('MYCOMUUID').text();
                                                        var parentID = $(this).find('PARENTID').text();
                                                        var comment = $(this).find('COMMENT').text();
                                                        var fname = $(this).find('FNAME').text();
                                                        var lname = $(this).find('LNAME').text();
                                                        var usercomName =  $(this).find('USERCOMNAME').text();
                                                        var usercomUrl =  $(this).find('USERCOMURL').text();
                                                        var timeAgo = $(this).find('TIMEAGO:first').text();

                                                        html += "<!-- start: CHILD POST --><div class='child-post'> ";
                                                        html += "<span class='user-image'><img width='48' height='48' src='/users/" + mycomUUID + "/photos/userprofilepic-sml.jpg?seed=" + epoch + "'></span>";
                                                        if( $.trim(fname) == "" && $.trim(lname) == "" )
                                                        {
                                                        	html +="<span class='name'><a href='/profile/" + mycomUUID + "'>User "+ mycomUUID +"</a></span>";
                                                        } else  {
                                                                        html +="<span class='name'><a href='/profile/" + mycomUUID + "'>"+ fname +" "+ lname +"</a></span>";
                                                                }
                                                        html +=" <span class='date'>" + timeAgo + "</span>";
                                                        html += "<span><p>" + comment + "</p></span>";
                                                        if( checkThisSystemRoles( 'oaManager' ) ) 
							{ 
								html += "<span id=" + commentID + "><a href='#' class='remove-comment'>Remove Comment</a></span>"; 
                                                        }
                                                        html += "</div><!-- end: CHILD POST -->";

                                                }); // END CHILD.EACH

						// COMMENT INPUT
                                                html += "<!-- start: COMMENT INPUT CHILD -->";
                                                html += "<div class='comment-input-child'> ";

                                                html += "<span class='user-image-small'><img width='48' height='48' src='/users/" + get_cookie( 'mycomUUID' ) + "/photos/userprofilepic-sml.jpg?seed=" + epoch + "' /></span>";
                                                html += "<form><input type='hidden' id='parentId' value='" + commentID + "'>";
                                                if( get_cookie( 'lang' ) == 'ar' )  // line added to add arabic default text values
                                                {
                                                        html += "<textarea class='usercomment' placeholder='ﺄﻀﻓ ﺖﻌﻠﻴﻘﻛ ﻪﻧﺍ...'></textarea>";
                                                } else  {
                                                                html += "<textarea class='usercomment' placeholder='Write your comments here...'></textarea>";
                                                        }
                                                html += "<div class='button-wrap'><input type='button' class='clickBtn' value='Post' /></div></form>";
                                                html += "</div><!-- end: COMMENT INPUT  -->";
                                                html += "</div><!-- end: CHILD ITEM  -->";
                                                html += " </div><!-- end: WALL  ITEM  -->";
                                                html += " </div><!-- end: WALL  ITEM  -->";

                                        }); // END PARENT.EACH

                                        html += "<div class='clear'></div>";

                                        // HTML MARKUP FOR BOTTOM OF WALL EXPAND
                                        html += "<div id='expand'><img src='/img/wall-expand-arrow.jpg' width='18' height='19' /></div>";
					closeMsgBox();	
                                } else if( $(data).find('ERROR').text() == "No Results" )
                                        {
                                                if( get_cookie('lang') == 'ar' )
						{
							html += "<p class='empty'>ليست هناك ملاحظات في هذا المجتمع -- كن أول من إضافة واحد عن طريق تسجيل الدخول والتواصل مع غيرهم من الناس الذين يعيشون في مجتمعك.</p>";
						} else	{
								html += "<p class='empty'>There are no comments in this community - Be the first to add one by logging in and connect with other people who live in your community.</p>";
							}
                                        	//$('#wallComments').html( html );
						closeMsgBox();
                                        } else  {
                                                        displayError( $(data).find('ERROR').text() );
                                                } // END IF RESULT == TRUE
				$('#wall-head').attr('display','block');
                                $('#innerContent').html( bigWall );
                                $('#comment-input').html( commentInput );
                                $('#wall').html( html );

                                $(".usercomment").blur(function()
                                {
                                        if( this.value == '' )
                                        {
                                                if ($(this).parent().parent().hasClass("comment-input-child"))
                                                {
                                                        $(this).parent().parent().animate(
                                                        {
                                                                opacity:'toggle',
                                                                height:'toggle'
                                                        },400);
                                                }
                                        }
                                });

                                // JQUERY: ELASTIC - MAKE USER STATUS BOX GROW/SHRINK WITH INPUT
                                $('.usercomment').elastic();

                               	$('span.comment a').click( function(e)
                               	{
                                        e.preventDefault();
                                        $(this).parent().parent().parent().parent().find('div.child-items div.comment-input-child').slideToggle(300,'easeInSine');
                                });
                                // BIG WALL EXPAND FUNCTION 
                                $('wallExt').click( function(e)
                                {
                                        e.preventDefault();
                                        morewallBig();
                                });

			} // END AJAX SUCCESS
		}); // END AJAX MODULE
	}); // END AJAX LOADER
}


///////////////////////////////////////////////////////////////////////////////////
/////////////////// BIG WALL FUNCTIONS ////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

function wallModuleBig()
{
	$('.clickBtn').removeAttr('disabled');
	var html="";
		
	if( !$('body').hasClass('account') )
	{
		html ='<h3 id="comwall">Community Wall</h3><div id="wallLoader"><img src="/img/ajax-loader2.gif" width="42" height="42"/></div><div id="comment-input"></div>';
	}
	
	// IF LOGGED IN CREATE COMMENT INPUT AREA
	if( get_cookie( 'mycomUUID' ) ) 
        {
                var time = new Date();
                var epoch = time.getTime();
                if( get_cookie( 'lang' ) == 'ar' ) // line added to add arabic default text values
                {
			var commentInput = "<span class='user-image'><img width='64' height='64' src='/users/" + get_cookie( 'mycomUUID' ) + "/photos/userprofilepic-sml.jpg?seed=" + epoch + "'></span><form><input type='hidden' id='parentId' value=''><textarea class='usercomment' id='myComments'>أضف تعليقك هنا...</textarea><div class='button-wrap'><input type='button' class='clickBtn' value='Post' /></div></form></div>";
		} else  {
			 	var commentInput = "<span class='user-image'><img width='64' height='64' src='/users/" + get_cookie( 'mycomUUID' ) + "/photos/userprofilepic-sml.jpg?seed=" + epoch + "'></span><form id='parentWallComment'><input type='hidden' id='parentId' value=''><textarea class='usercomment' id='myComments'>Write your comments here...</textarea><div class='button-wrap'><input type='submit' class='clickBtn' value='Post' /></div></form></div>";
                        }
        }
		
        var time = new Date();
        var epoch = time.getTime();
	
	if( $('body').hasClass('account') ) 
	{ 
		partparams = "&communityID=" + get_cookie('selectedCommunityID'); 
	}

	if( $('body').hasClass('community public') || $('body').hasClass('burjHome public') || $('body').hasClass('burjCommunity')  )
	{ 
		partparams = "&communityID=" + currentCommunityID; 
	}

	// AJAX REQUEST: RETRIEVE COMMUNITY WALL COMMENTS
	var params = "func=getComments&type=wall&numPosts=" + currentNumWallPosts + partparams;
	//alert( params ); return;

        openMsgBox();
        $('#msgboxmsg').html('Retrieving MyCommunity Wall').show(250, function()
        {
        	$.ajax(
        	{
        	        type: "POST",
        	        async: true,
        	        url: "/cgi-bin/mycom.cgi",
        	        data: params,
        	        dataType: "xml",
        	        success: function(data)
        	        {
				if ( $(data).find('RESULT').text() == "TRUE")
				{
					$(data).find('PARENT').each( function()
					{
						var commentID = $(this).find('COMMENTID:first').text();
						var mycomUUID = $(this).find('MYCOMUUID:first').text();
						var comment = $(this).find('COMMENT:first').text();
						var fname = $(this).find('FNAME:first').text();
						var lname = $(this).find('LNAME:first').text();
						var timeAgo = $(this).find('TIMEAGO:first').text();
						
						if( $('body').hasClass('account') )
						{
							html += "<!-- start: WALL ITEM  --><div class='wall-item wall-padding'><div class='wall-post'><div class='likes-comments'>";
							if( checkThisSystemRoles( 'oaManager' ) ) 
							{ 
								html += "<span id=" + commentID + "><a href='#' class='remove-comment'>Remove Comment</a> | </span>"; 
							}
							html += "<span class='comment'><a href='#' class='comment'>Comment</a></span></div>";
               						html += "<span class='user-image'> <img width='64' height='64' src='/users/" + mycomUUID;
							html += "/photos/userprofilepic-sml.jpg?seed=" + epoch +"'> </span>";
							if( $.trim(fname) == "" && $.trim(lname) == "" ) 
							{ 
								html +="<span class='name'><a href='/profile/" + mycomUUID + "'>User "+ mycomUUID +"</a></span>"; 
							} else	{
									html +="<span class='name'><a href='/profile/" + mycomUUID + "'>"+ fname +" "+ lname +"</a></span>"; 
								}
							html += "| <span class='date'>" + timeAgo + "</span>";
							html += "<span><p>" + comment + "</p></span>";
							html += "</div> <!-- end: WALL-POST --><div class='child-items'>";
						}
						if( $('body').attr('class') == 'community public' )
						{
                                                        html += "<!-- start: PARENT COMMENT -->";
                                                        html += "<div class='wallPostParent wallParent clearfix'>";
                                                        html += "<span class='wallImage'><img height='50' width='50' src='/users/" + mycomUUID;
							html += "/photos/userprofilepic-sml.jpg?seed=" + epoch + "'></span>";
                                                        if( $.trim(fname) == "" && $.trim(lname) == "" )
                                                        {
                                                                html += "<span class='name'><a href='/profile/" + mycomUUID + "'>User "+ mycomUUID +"</a></span>";
                                                        } else  {
                                                                        html += "<span class='name'><a href='/profile/" + mycomUUID + "'>" + fname + " " + lname + "</a></span>";
                                                                }

							html += "<span class='date'>" + timeAgo + "</span>";
                                                        html += "<span><p>" + comment + "</p></span>";
                                                        
                                                        if( get_cookie('mycomUUID' ) )
                                                        {
                                                        	if( checkAllSystemRoles( 'oaManager' ) && checkThisCommunityForSystemRoles( 'oaManager' ) ) 
                                                                {
                                                                	html += "<span class='commentSpan' id='" + commentID + "'>";
									html += "<a href='#' class='remove-comment'>Remove Comment</a> | <a href='#' class='comment'>Comment</a></span>";
                                                                } else if( checkAllSystemRoles( 'oaManager' ) && !checkThisCommunityForSystemRoles( 'oaManager' ) )
									{

									} else	{
                                                                       			html += "<span class='commentSpan'><a href='#' class='comment'>Comment</a></span>";
                                                                      		}
                                                        }
                                                       	html += "</div><!-- end: PARENT COMMENT -->";
						}	

						$(this).find('CHILD').each( function()
                                        	{
                                                	var commentID = $(this).find('COMMENTID').text();
                                                	var mycomUUID = $(this).find('MYCOMUUID').text();
                                                	var parentID = $(this).find('PARENTID').text();
                                                	var comment = $(this).find('COMMENT').text();
                                                	var fname = $(this).find('FNAME').text();
                                                	var lname = $(this).find('LNAME').text();
                                                	var usercomName =  $(this).find('USERCOMNAME').text();
                                                	var usercomUrl =  $(this).find('USERCOMURL').text();
							var timeAgo = $(this).find('TIMEAGO:first').text();
							
							if( $('body').hasClass('account') )
							{
								html += "<!-- start: CHILD POST -->";
								html += "<div class='child-post'> ";
								html += "<span class='user-image'><img width='48' height='48' src='/users/" + mycomUUID + "/photos/userprofilepic-sml.jpg?seed=" + epoch + "'></span>";
								
						        	if( $.trim(fname) == "" && $.trim(lname) == "" ) 
                                                        	{ 
                                                        	        html +="<span class='name'><a href='/profile/" + mycomUUID + "'>User "+ mycomUUID +"</a></span>";  
                                                        	} else  {
                                                        	              	html +="<span class='name'><a href='/profile/" + mycomUUID + "'>"+ fname +" "+ lname +"</a></span>"; 
                                                        	        }
								//html += " <span class='community-name'><a href='/community/" + usercomUrl + "'>" + usercomName + "</a></span>";
								html +=" <span class='date'>" + timeAgo + "</span>";
								html += "<span><p>" + comment + "</p></span>";
								if( checkThisSystemRoles( 'oaManager' ) ) { html += "<span id=" + commentID + "><a href='#' class='remove-comment'>Remove Comment</a></span>"; }
								html += "</div><!-- end: CHILD POST -->";
							}

							if( $('body').attr('class') == 'community public')
							{

                                                                html += "<!-- start: CHILD COMMENT -->";
                                                                html += "<div class='wallPostChild'>";
                                                                html += "<img height='40' width='40' src='/users/" + mycomUUID + "/photos/userprofilepic-sml.jpg?seed=" + epoch + "'>";
                                                               	if( $.trim(fname) == "" && $.trim(lname) == "" )
                                                                {
                                                                        html +="<span class='name'><a href='/profile/" + mycomUUID + "'>User "+ mycomUUID +"</a></span>";
                                                                } else  {
                                                                                html +="<span class='name'><a href='/profile/" + mycomUUID + "'>"+ fname +" "+ lname +"</a></span>";
                                                                        }

								//html += "<span class='community-name'><a href='/community/" + usercomUrl + "'>" + usercomName + "</a></span>";
								html += "<span class='date'>" + timeAgo + "</span>";
                                                                html += "<span><p>" + comment + "</p></span>";
								if( get_cookie('mycomUUID' ) )
                                                        	{
                                                                	if( checkAllSystemRoles( 'oaManager' ) && checkThisCommunityForSystemRoles( 'oaManager' ) )
                                                                	{
                                                                	      html += "<span class='commentSpan' id='" + commentID + "'><a href='#' class='remove-comment'>Remove Comment</a></span>";
                                                                	} 
								}
                                                               	html += "</div>";
                                                                html += "<!-- end: CHILD COMMENT -->";
							}
								
						}); // END CHILD.EACH
					
						if( $('body').hasClass('account') )
						{	
							html += "<!-- start: COMMENT INPUT CHILD -->";
							html += "<div class='comment-input-child'> ";
								
							html += "<span class='user-image-small'><img width='48' height='48' src='/users/" + get_cookie( 'mycomUUID' ) + "/photos/userprofilepic-sml.jpg?seed=" + epoch + "' /></span>";
							html += "<form><input type='hidden' id='parentId' value='" + commentID + "'>";
							if( get_cookie( 'lang' ) == 'ar' )  // line added to add arabic default text values
							{
								html += "<textarea class='usercomment'>أضف تعليقك هنا...</textarea>";
							} else	{
									html += "<textarea class='usercomment'>Write your comments here...</textarea>";
								}
							html += "<div class='button-wrap'><input type='button' class='clickBtn' value='Post' /></div></form>";
							html += "</div><!-- end: COMMENT INPUT  -->";
							html += "</div><!-- end: CHILD ITEM  -->";
							html += " </div><!-- end: WALL  ITEM  -->";
						}
						
						if( $('body').attr('class') == 'community public' )
						{
                                                        html += "<!-- start: INPUT COMMENT -->";
                                                        html += "<div id='commentInputChild' class='commentInputChild'>";
                                                        html += "<img height='40' width='40' src='/users/" + get_cookie( 'mycomUUID' ) + "/photos/userprofilepic-sml.jpg?seed=" + epoch + "'>";
                                                        html += "<form><input type='hidden' id='parentId' value='" + commentID + "'>";
                                                        if( get_cookie( 'lang' ) == 'ar' )  // line added to add arabic default text values
                                                        {
                                                               html += "<textarea class='usercomment' id='usercomment'>ﺄﻀﻓ ﺖﻌﻠﻴﻘﻛ ﻪﻧﺍ...</textarea>";
                                                        } else  {
                                                                        html += "<textarea class='usercomment' id='usercomment'\">Write your comments here...</textarea>";
                                                                }
                                                        html += "<div class='buttonWrap'><input type='button' class='clickBtn' value='post' /></div></div></form>";
                                                        html += "<!-- end: INPUT COMMENT -->";
						}
					}); // END PARENT.EACH

					html += "<div class='clear'></div>";
					// HTML MARKUP FOR BOTTOM OF WALL EXPAND
                   			if( $('body').hasClass('account') )
					{
						html += "<div id='expand'><img src='/img/wall-expand-arrow.jpg' width='18' height='19' /></div>";
					}
					closeMsgBox();
					
				} else if( $(data).find('ERROR').text() == "No Results" )
					{
						html += "<p class='empty'>There are no comments in this community - Be the first to add one by logging in and connect with other people who live in your community.</p>";
						$('#wallComments').html( html );
						closeMsgBox();
					} else	{
							displayError( $(data).find('ERROR').text() );
						} // END IF RESULT == TRUE

				if( $('body').hasClass('account') )
				{
					$('#wall-head').attr('display','block'); 
                                	$('#innerContent').html( bigWall );
                                	$('#comment-input').html( commentInput );
                                	$('#wall').html( html );
					closeMsgBox();
				}

                                if( $('body').attr('class') == 'community public' )
                                {
                                        $('#wall').html( html );
                                        if( checkAllSystemRoles( 'oaManager' ) == 1 && checkThisCommunityForSystemRoles( 'oaManager' ) == 1 ) 
					{ 
						$('#comment-input').html( commentInput ); 
					} else if( checkAllSystemRoles( 'oaManager' ) == 1 && checkThisCommunityForSystemRoles( 'oaManager' ) == 0 )
						{
							$('#comment-input').hide(); 
						} else  if( get_cookie('mycomUUID') )
							{ 
								$('#comment-input').html( commentInput ); 
							} else	{
									$('#comment-input').hide();
								}
                                }

						
                		// RE-CONNECT ALL SELECTORS TO EVENTS
               			/* Need to disable and check this -----------*/
			   
				$('.usercomment').each(function()
                		{
                		        var default_value = this.value;
                		        $(this).css('color', '#aaa');
        		
        		                $('.usercomment').focus(function()
        		                {
        		                        if( this.value == default_value )
        		                        {
        		                                this.value = '';
        		                                $(this).css('color', '#333');
        		                        }
        		                });
        		        
        		                $(".usercomment").blur(function()
        		                {
        		                        if( this.value == '' )
        		                        {
        		                                this.value = default_value;
        		                                $( this ).css( 'color', '#aaa' );
        		                                if ($(this).parent().parent().hasClass("commentInputChild"))
        		                                {
        		                                        $(this).parent().parent().animate(
        		                                        {
        		                                                opacity:'toggle',
        		                                                height:'toggle'
        		                                        },400);
        		                                }
        		                        }
        		                });
        		        });
						
        			// JQUERY: ELASTIC - MAKE USER STATUS BOX GROW/SHRINK WITH INPUT
        			$('.usercomment').elastic();
	
	        		// SETTING THE HEIGHT BACK TO THE ORIGINAL AFTER ELASTIC IS APPLIED
	        		$('.commentInputChild .usercomment').css("height", "15px");
	        		$('.commentInputChild .usercomment').blur( function()
	        		{
	                		$(this).css("height", "15px");
	        		});
	
				$("span.commentSpan a.comment").click( function(e)
                                {
                                       e.preventDefault();
                                       $(this).parent().parent().nextAll('div.commentInputChild:first').slideToggle(300,'easeInSine');
                                });
                                $("span.comment a").click( function(e)
                                {
                                       e.preventDefault();
                                       $(this).parent().parent().parent().parent().find('div.child-items div.comment-input-child').slideToggle(300,'easeInSine');
                                });
                                // BIG WALL EXPAND FUNCTION 
                                /*
				$('#wallExt').click( function(e)
                                {
                                	e.preventDefault();
                                       	morewallBig();
                                });
				*/

			} // END AJAX SUCCESS
		}); // END AJAX METHOD
	}); // END AJAX LOADER
} // WALL MODULE BIG FUNCTION ENDS

function morewallBig()
{
	if( $('body').hasClass('account') ) 
	{ 
		currentNumWallPosts += 15; 
		wallAccount(); 
	} else 	{ 
			currentNumWallPosts += 3; 
			wallModuleBig(); 
		}
}

