
//*************************************
// LOADING News Status Page
//*************************************
function loadStatus() {
	loadStatusList(0,1);
}

function loadStatusList(nsID,pageNum) {
	var listDiv = document.getElementById("myStatusList");
	listDiv.innerHTML = '';
	var loadingDiv = document.createElement("div");
	var loadingImage = document.createElement("img");
	loadingImage.src = "/images/indicators/processing_small.gif";
	loadingDiv.innerHTML = "&nbsp;loading&nbsp;";
	loadingDiv.appendChild(loadingImage);
	
	listDiv.appendChild(loadingDiv);
	
	setSpanValue('currPageNum', pageNum);
	
	engProfile.getNewsStatusList(nsID, pageNum, callback_getNewsStatus);	
}

function callback_getNewsStatus(res) {	
	
	if (res.error!=null){alert(res.error)};

	checkResponse(res.value);
	var dt = res.value;
	
	var pageNum=getSpanValue('currPageNum');
	var pageIndex=((parseInt(pageNum)-1)*5);
	
	if (dt.length!=0) {
		createStatusPageControls(dt[0]);
	}
	
	//createPageControls
	var listDiv = document.getElementById("myStatusList");
	listDiv.innerHTML = '';
	listDiv.style.textAlign='left';
	
	var tbl = document.getElementById("tblStatusUpdates");
	var rows = tbl.rows;
		
	
	
	
    while(rows.length) // length=0 -> stop 
	{
		tbl.deleteRow(rows.length-1);
	}
	if (dt.length!=0)
	{
		for (var i=0; i<dt.length; i++)
		{
			if (dt[i] != null ){
				var insertTable = document.createElement("tr");
				tbl.appendChild(insertTable);
								
				var tblCell1 = insertTable.insertCell(0) 
				var tblCell2 = insertTable.insertCell(1) 		 				


				//Set Status
				var newsStatus = document.createElement("span");
				newsStatus.innerHTML = dt[i].NewsStatus;
				newsStatus.style.display = 'block';
				
				var commentsLink = document.createElement("a");
				commentsLink.href="javascript:void(0);";
				commentsLink.className = "commentsLink";
				commentsLink.newsid = dt[i].NewsID;
				commentsLink.onclick = function() { showComments(this.newsid); }
				
				var addCommentLink = document.createElement("a");
				addCommentLink.href = "javascript:void(0);";
				addCommentLink.innerHTML = "Add a comment";
				addCommentLink.className = "addCommentLink";
				addCommentLink.newsid = dt[i].NewsID;
				addCommentLink.onclick = function() { showAddComment(this.newsid); }
				
				var spnCommentsCount = document.createElement("span");
				spnCommentsCount.id = "spnCommentsCount_" + dt[i].NewsID;
				spnCommentsCount.innerHTML = dt[i].TotalComments;
				
				commentsLink.appendChild(spnCommentsCount);
				
				if (dt[i].TotalComments == 1)
				    commentsLink.innerHTML += " Comment";
				else
					commentsLink.innerHTML += " Comments";
				
				var commentsContainer = document.createElement("div");
				commentsContainer.id = "commentsContainer_" + dt[i].NewsID;
				commentsContainer.className = "commentsContainer";
				commentsContainer.style.display = 'none';
				
				var commentsList = document.createElement("ul");
				commentsList.id = "comments_" + dt[i].NewsID;
				commentsList.className = "commentsList";
				
				var addCommentDiv = document.createElement("div");
				addCommentDiv.id = "addCommentDiv_" + dt[i].NewsID;
				addCommentDiv.style.display = 'none';
				
				var addCommentText = document.createElement("textarea");
				addCommentText.id = "commentText_" + dt[i].NewsID;
				addCommentText.className = "addCommentText";
				
				var imgAddComment = document.createElement("input");
				imgAddComment.type = "image";
				imgAddComment.src = "/images/buttons/myBlog/addComment.gif";
				imgAddComment.newsid = dt[i].NewsID;
				imgAddComment.onclick = function() { addComment(this.newsid); }
				
				addCommentDiv.innerHTML += "<br />";
				addCommentDiv.appendChild(addCommentText);
				addCommentDiv.innerHTML += "<br />";
				addCommentDiv.appendChild(imgAddComment);
				
				commentsContainer.appendChild(commentsList);
				
				tblCell1.appendChild(newsStatus);
				tblCell1.appendChild(commentsLink);
				tblCell1.appendChild(addCommentLink);
				tblCell1.appendChild(addCommentDiv);
				tblCell1.appendChild(commentsContainer);
				//Set Date
				tblCell2.className = 'security';
				tblCell2.innerHTML = dt[i].UploadDate
				tblCell2.style.width = '200px';
                SplitWordsWithFixedLength(commentsContainer);

			}
		}
	}
	else
	{
		var insertTable = document.createElement("tr");
		tbl.appendChild(insertTable);
								
		var tblCell1 = insertTable.insertCell(0)
		tblCell1.colSpan = "4";
		tblCell1.id = "cell1";
		tblCell1.innerHTML = "You have not added any status updates yet";
	}
	
    var node = document.getElementById('tblStatusUpdates');
    if (node != null) {
        SplitWordsWithFixedLength(node);
    }	
	stripetableBody();
}

function LoadAllStatus()
{
	engProfile.getNewsStatus(0,callback_getNewsStatus);	
	window.setTimeout('ShowPage()', 500);		
}

function ShowPage() {
	document.getElementById("numOfPhotosDisplayed").style.display="none";
	
	var ul = document.getElementById("pages");
	ul.innerHTML = "";
	ul.classname="paginationControls";
	
	var asplit = document.createElement("a");
	asplit.href="javascript:loadStatus();";
	asplit.innerHTML="Split results onto separate pages";
	
	var lisplit = document.createElement("li");
	lisplit.className = "showAll";
		
	lisplit.appendChild(asplit);
	ul.appendChild(lisplit);
}

function createStatusPageControls(row)
{
	var dt = row;	
	if (dt.Pages == 1) {
		return;
	}
	
	var pageType = getSpanValue('statuspage');
	
	var ul = document.getElementById("pages");
	ul.innerHTML = "";
	ul.classname="paginationControls";
	
	var pages = dt.Pages;
	var currP = getSpanValue('currPageNum');
	
	var imgPrev = document.createElement("img");
	imgPrev.src = "/images/arrow_medium_left.gif";
	imgPrev.alt = "Previous";
		
	var aPrev = document.createElement("a");
	if (pageType == "Public")
	{
		aPrev.href = "javascript:loadStatusList(0," + (parseInt(currP) - 1) + ");";
	}
	else
	{
		aPrev.href = "javascript:loadStatusList(0," + (parseInt(currP) - 1) + ");";
	}
	aPrev.appendChild(imgPrev);
	
	var liPrev = document.createElement("li");
	liPrev.appendChild(aPrev);
	liPrev.className = "previous";
	
	var imgNext = document.createElement("img");
	imgNext.src = "/images/arrow_medium_right.gif";
	imgNext.alt = "Next";
	
	var aNext = document.createElement("a");
	if (pageType == "Public")
	{
		aNext.href = "javascript:loadStatusList(0," + (parseInt(currP) + 1) + ");";
	}
	else
	{
		aNext.href = "javascript:loadStatusList(0," + (parseInt(currP) + 1) + ");";
	}
	
	aNext.appendChild(imgNext);
	
	var liNext = document.createElement("li");
	liNext.appendChild(aNext);
	liNext.className = "next";
	
	var aShowAll = document.createElement("a");
	aShowAll.href = "javascript: LoadAllStatus();";
	aShowAll.innerHTML = "View All on Single Page";
	aShowAll.style.color = "white";
	
	var liShowAll = document.createElement("li")
	liShowAll.className = "showAll";
	
	liShowAll.appendChild(aShowAll);
	
	if (pages > 1) {
		if (getSpanValue('currPageNum') != "1") {
			ul.appendChild(liPrev);
		}
	}
			
	for (var i=0; i<pages; i++) {
		var a = document.createElement("a");
		
		a.innerHTML = i + 1;
		
		var li = document.createElement("li");
		
		if ((i + 1) == getSpanValue('currPageNum')) {
			li.className = "current";
			a.href = "#";
		}
		else {
			if (pageType == "Public")
			{
			a.href = "javascript:loadStatusList(0," + (i + 1) + ");";
			a.style.color = "white";
			}
			else
			{
			a.href = "javascript:loadStatusList(0," + (i + 1) + ");";
			a.style.color = "white";
			}
		}
		
		li.appendChild(a);
		ul.appendChild(li);	
	}
	
	if (pages > 1) 
	{
		if (getSpanValue('currPageNum') != pages) {
			ul.appendChild(liNext);
		}
		ul.appendChild(liShowAll);
	}
}

function ShowMyStatus() {
 setSpanValue('callPage', 'HomePage');
 setControlValue('txtMyStatus','');
 $('radPublic').checked = true;
 showPublicPrivate();
 openModalWindow('AddMyNewsStatus');
}

function ShowMyStatusFromStatusPage() {
 setSpanValue('callPage', 'StatusPage');
 setControlValue('txtMyStatus','');
 $('radPublic').checked = true;
 showPublicPrivate();
 openModalWindow('AddMyNewsStatus'); 
}


AddMyNewsStatus = function()
{	

	var mytext = getControlValue('txtMyStatus');	
	var mystatus = getDropDownSelected('ddMyStatus');
	//Set all access to public
	//var security = 2;
	var security = getSelectedRadioValue('radSecurity');
	
	var ddStatusError = document.getElementById('txtMyStatusErr');
    if (ddStatusError)
    {
        if (mytext == "")
        {
	        ddStatusError.innerHTML = "Please enter your Status.";
	        ddStatusError.style.display = 'block';
	        return;
        }
        else
        {
            ddStatusError.style.display = 'none';
        }
    }
    
	
	
	
	var friendsIDs = new Array(1);
	friendsIDs[0] = 0;
	friendsIDs = getFriendsIDs("ulMyStatusFriends");
	
	if(friendsIDs[0] == void 0)
	{
		friendsIDs[0] = 0;
	}
	
	var goupsIDs = new Array(1);
	goupsIDs[0] = 0;
	goupsIDs = getGroupsIDs("ulMyStatusGroupsList");

	if(goupsIDs[0] == void 0)
	{
		goupsIDs[0] = 0;
	}
	
	showFeedback('AddMyNewsStatusActionContainer');
	engProfile.AddMyNewsStatus('txtMyStatus', mytext, mystatus, security, friendsIDs, goupsIDs, callback_AddMyNewsStatus);
	
}

function callback_AddMyNewsStatus(res){

if (res.error!=null){alert(res.error)};

var results = res.value.Tables[0];

	if (results.Rows[0].result == "True")
		{
		
		//if the function returns as true, ie. everything validated corrrectly then we take the 
		//value from the control as above - line 6 and set the span I added around the mystatus 
		//that displays on the main page (not the modal) to the new value
		//var newStatus = getControlValue('txtMyStatus');
		res1 = res.value.Tables[2];
		var newStatus = res1.Rows[0].myStatus;
		
		
		//I add in a check here, only for the dev page as the id "myStatusDisplay" does not exist
		//on the live version and to stop it from breaking i check if the control exists, if it does
		//then I reset its value
		if (document.getElementById("myStatusDisplay")!=null)
			{
			setSpanValue('myStatusDisplay', newStatus);	
			}
		
		//we do this all here as in the next couple of lines the textbox is cleared
		
		
		var controls = res.value.Tables[1];
		for (var i=0; i<controls.Rows.length; i++)
			{
			//clearInputField(controls.Rows[i].controlID);
			setControlErrorMessage(controls.Rows[i].controlID,'');
			
			}

			switch (results.Rows[0].errMessage)
				{

					case "valid":

						feedbackValid('Saving','Saved');
						window.setTimeout('finshStatusUpdate();', 4000);
					break
				}
		}
	else
		{
		
		var controls = res.value.Tables[1];
		switch (results.Rows[0].errMessage)
				{
					case "invalid":

						feedbackInvalid('AddMyNewsStatusActionContainer');
						window.setTimeout(function(){processValidationResponse(controls)}, 2001);
					break;
					case "Invalid- No HTML allowed.":
						feedbackInvalid('AddMyNewsStatusActionContainer');
						window.setTimeout(function(){processValidationResponse(controls)}, 2001);
					break;					
			}
		}
}


function finshStatusUpdate(){
	cleanupFeedback('AddMyNewsStatusActionContainer');
	window.setTimeout("closeModalWindow('AddMyNewsStatus');", 1000);
	var page = getSpanValue('callPage');
	if (page == 'StatusPage') {
		loadStatus();
	}
}


function callback_AutoCompleteMyStatusFriends(res)
{
	checkResponse(res.value);
	if (res.value != null)
	{
		var ds = res.value;
		var listControlID = "autoCompleteListtxtMyStatusFriends";
		var listControlWrapper = "txtMyStatusFriendsListWrapper";
		document.getElementById(listControlID).innerHTML = "";
		
		var ul = document.createElement("ul");
		ul.id = "autoList";
		
		if (ds != null && typeof(ds) == "object" && ds.Rows.length != 0)
		{
			for (var i=0; i<ds.Rows.length; i++)
			{
				var li = document.createElement("li");
				var a = document.createElement("a");
			
				a.href = "javascript:completeMyStatusFriends('" + ds.Rows[i].UserID + "','" + ds.Rows[i].Username + " ("+ds.Rows[i].firstname + " " + ds.Rows[i].lastname+")"+ "');void(0);";
				a.innerHTML = ds.Rows[i].Username+ " ("+ds.Rows[i].firstname + " " + ds.Rows[i].lastname+")";
				
				li.appendChild(a);
				ul.appendChild(li)
			}				
			document.getElementById(listControlID).appendChild(ul);
			document.getElementById(listControlWrapper).style.display = "block";
			document.getElementById(listControlID).style.display = "block";
		}
		else
		{
			document.getElementById(listControlWrapper).style.display = "none";
			document.getElementById(listControlID).style.display = "none";
		}		
	}
}

//**********************
//EDIT My Friends Drop Down lists


function callback_AutoCompleteEditMyStatusFriends(res)
{
	checkResponse(res.value);
	if (res.value != null)
	{
		var ds = res.value;
		var listControlID = "autoCompleteListtxtEditMyStatusFriends";
		var listControlWrapper = "txtEditMyStatusFriendsListWrapper";
		document.getElementById(listControlID).innerHTML = "";
		
		var ul = document.createElement("ul");
		ul.id = "autoList";
		
		if (ds != null && typeof(ds) == "object" && ds.Rows.length != 0)
		{
			for (var i=0; i<ds.Rows.length; i++)
			{
				var li = document.createElement("li");
				var a = document.createElement("a");
			
				a.href = "javascript:completeEditUsername('" + ds.Rows[i].UserID + "','" + ds.Rows[i].Username + " ("+ds.Rows[i].firstname + " " + ds.Rows[i].lastname+")"+ "');void(0);";
				a.innerHTML = ds.Rows[i].Username+ " ("+ds.Rows[i].firstname + " " + ds.Rows[i].lastname+")";
				
				li.appendChild(a);
				ul.appendChild(li)
			}				
			document.getElementById(listControlID).appendChild(ul);
			document.getElementById(listControlWrapper).style.display = "block";
			document.getElementById(listControlID).style.display = "block";
		}
		else
		{
			document.getElementById(listControlWrapper).style.display = "none";
			document.getElementById(listControlID).style.display = "none";
		}		
	}
}


function completeEditUsername(accID, username)
{
	Effect.Fade('txtEditMyStatusFriendsListWrapper');
	var ul = document.getElementById("ulEditMyStatusFriendsList");	
	var chks = document.getElementById("ulEditMyStatusFriendsList").getElementsByTagName("input");
	var counter = 0;
	if(chks.length != 0)
	{
		for(var i=0;i<chks.length;i++)
		{
				if(accID == chks[i].value)
				{
					counter = 1;
				}
		}			
			
		if(counter == 0)
		{
			var chk = document.createElement("input");
			chk.type = "checkbox";
			chk.value = accID;
			chk.id = "c_"+accID;
			chk.style.display = "none"; 
			var lbl = document.createElement("label");
			lbl.innerHTML = username;
			lbl.id = "l_"+accID;
			var img = document.createElement("img");
			img.id = "i_"+accID;
			img.alt ="Remove";
			img.src="/images/icons/delete.gif";
			var aImg = document.createElement("a");
			aImg.href ="javascript:deleteEditFriend(" + accID + ");";
			aImg.id = "a_"+accID;
			aImg.appendChild(img);
			var li = document.createElement("li");
			li.id="l_"+accID;
			li.appendChild(chk);
			li.appendChild(lbl);
			li.appendChild(aImg);			
			ul.appendChild(li);
		}
		else
		{
			alert('You have already selected to share the event with this person.');
		}
		
	}
	else
	{
		var chk = document.createElement("input");
		chk.type = "checkbox";
		chk.value = accID;
		chk.id = "c_"+accID;
		chk.style.display = "none"; 
		var spn = document.createElement("span")
		spn.innerHTML = accID;
		
		var lbl = document.createElement("label");
		lbl.innerHTML = username;
		lbl.id = "l_"+accID;
		var img = document.createElement("img");
		img.id = "i_"+accID;
		img.alt ="Remove";
		img.src="/images/icons/delete.gif";
		var aImg = document.createElement("a");
		aImg.href ="javascript:deleteEditFriend(" + accID + ");";
		aImg.id = "a_"+ accID;
		aImg.appendChild(img);
		var li = document.createElement("li");
		li.id="l_"+accID;
		li.appendChild(chk);
		//li.appendChild(spn);
		li.appendChild(lbl);
		li.appendChild(aImg);			
		ul.appendChild(li);
	}
	document.getElementById("txtEditMyStatusFriends").value = "";
}


function deleteEditFriend(accID)
{
	var ul = document.getElementById("ulEditMyStatusFriendsList");
	var chks = document.getElementById("ulEditMyStatusFriendsList").getElementsByTagName("input");
	var lis = document.getElementById("ulEditMyStatusFriendsList").getElementsByTagName("li");
	for(var i=0;i<chks.length;i++)
		{
				if(accID == chks[i].value)
				{
					var li = document.getElementById(lis[i].id);
					ul.removeChild(li);
				}
		}	
	
	
}

//**********************

//**********************
// EDIT NEWS FUNTIONS
//**********************

function showEditNews(nsId)
{
	setSpanValue('EditMyNewsStatusID', nsId);	
	engProfile.populateObjectMyStatus(nsId,callback_populateEditNewsStatus);
}

function callback_populateEditNewsStatus(res)
{
	if (res.error!=null){alert(res.error)};

	var status = res.value;
	
	if (status.NewsStatus == null)
		status.NewsStatus = "";	
		
	setControlValue('txtEditMyStatus', status.NewsStatus);
	
	setSelectedRadioValue('radEditSecurity', status.SecurityID);

	var ul = document.getElementById("ulEditMyStatusFriendsList");	
	ul.innerHTML = "";
					
	switch (status.SecurityID)
		{
			case 0:
				document.getElementById("updateStatus").style.display = "none";
			break
			case 1:
			
				document.getElementById("updateStatus").style.display = "none";
			break
			case 4:
				if (status.users!=null)
					{
						for (var j = 0;j< status.users.length;j++)
						{
							var chk = document.createElement("input");
							chk.type = "checkbox";
							chk.value = status.users[j].UserID;
							chk.id = "c_"+status.users[j].UserID;
							chk.style.display = "none"; 
							
							var lbl = document.createElement("label");
							lbl.innerHTML = status.users[j].Username;
							lbl.id = "l_"+status.users[j].UserID;
							
							var img = document.createElement("img");
							img.id = "i_"+status.users[j].UserID;
							img.alt ="Remove";
							img.src="/images/icons/delete.gif";
							
							var aImg = document.createElement("a");
							aImg.href ="javascript:deleteEditFriend(" + status.users[j].UserID + ");";
							aImg.id = "a_"+status.users[j].UserID;
							aImg.appendChild(img);
							
							var li = document.createElement("li");
							li.id="l_"+status.users[j].UserID;
							
							li.appendChild(chk);
							li.appendChild(lbl);
							li.appendChild(aImg);	
									
							ul.appendChild(li);
						}
					
					}		
					showEditMyStatusFriendsOptions();
			break
			case 2:
				if (status.groups!=null)
					{
						var chks = document.getElementById("ulEditMyStatusGroupsList").getElementsByTagName("input");
						
						for (var i = 0;i<chks.length;i++)
						{							
							chks[i].checked = false;								

						}
							
						for (var i = 0;i<chks.length;i++)
						{
							for (var j = 0;j<status.groups.length;j++)
							{
								if (chks[i].value == status.groups[j].GroupID)
								{
										chks[i].checked = true;
								}
							}
						}
							
						showEditMyStatusGroupsOptions();
				}
			break
		}
	 openModalWindow('EditMyNewsStatus');
}

function editNewsStatus() {
	var mytext = getControlValue('txtEditMyStatus');	
	var mystatus = getDropDownSelected('ddEditMyStatus');
	var newsId = getSpanValue('EditMyNewsStatusID');
	//Set all access to public
	//var security = 2;
	var security = getSelectedRadioValue('radEditSecurity');
	
	
	
	var friendsIDs = new Array(1);
	friendsIDs[0] = 0;
	friendsIDs = getFriendsIDs("ulEditMyStatusFriends");

	if(friendsIDs[0] == void 0)
	{
		friendsIDs[0] = 0;
	}
	
	var goupsIDs = new Array(1);
	goupsIDs[0] = 0;
	goupsIDs = getGroupsIDs("ulEditMyStatusGroupsList");

	if(goupsIDs[0] == void 0)
	{
		goupsIDs[0] = 0;
	}
	
	showFeedback('EditMyNewsStatusActionContainer');
	engProfile.EditMyStatus(newsId,'txtMyStatus', mytext, mystatus, security, friendsIDs, goupsIDs, callback_editNewsStatus);
}

function callback_editNewsStatus(res) {
if (res.error!=null){alert(res.error)};

var results = res.value.Tables[0];

	if (results.Rows[0].result == "True")
		{
		
		//if the function returns as true, ie. everything validated corrrectly then we take the 
		//value from the control as above - line 6 and set the span I added around the mystatus 
		//that displays on the main page (not the modal) to the new value
		//var newStatus = getControlValue('txtMyStatus');
		res1 = res.value.Tables[2];
		var newStatus = res1.Rows[0].myStatus;
		
		
		//I add in a check here, only for the dev page as the id "myStatusDisplay" does not exist
		//on the live version and to stop it from breaking i check if the control exists, if it does
		//then I reset its value
		if (document.getElementById("myStatusDisplay")!=null)
			{
			setSpanValue('myStatusDisplay', newStatus);	
			}
		
		//we do this all here as in the next couple of lines the textbox is cleared
		
		
		var controls = res.value.Tables[1];
		for (var i=0; i<controls.Rows.length; i++)
			{
			//clearInputField(controls.Rows[i].controlID);
			setControlErrorMessage(controls.Rows[i].controlID,'');
			
			}

			switch (results.Rows[0].errMessage)
				{

					case "valid":

						feedbackValid('Saving','Saved');
						window.setTimeout('hideEditNewsStatus();', 4000);
					break
				}
		}
	else
		{
		
		var controls = res.value.Tables[1];
		switch (results.Rows[0].errMessage)
				{
					case "invalid":

						feedbackInvalid('statusActionContainer');
						window.setTimeout(function(){processValidationResponse(controls)}, 2001);
					break
			}
		}
}

function hideEditNewsStatus()
{
	loadStatus();
	closeModalWindow('EditMyNewsStatus');
	cleanupFeedback('EditMyNewsStatusActionContainer');
}


//**********************
// DELETE NEWS FUNTIONS
//**********************
function showDeleteNews(nsId)
{
	setSpanValue('deleteNewsStatusID', nsId);
	engProfile.getNewsStatus(nsId, callback_populateDeleteNewsStatus);
}

function callback_populateDeleteNewsStatus(res)
{
	checkResponse(res.value);
	setSpanValue('deleteNewsStatusID', res.value.Rows[0].News_id);
	openModalWindow('deleteNewsStatus');
}

function deleteNewsStatus() {
	var newsId = getSpanValue('deleteNewsStatusID');
	showFeedback('deleteNewsStatusActionContainer');
	engProfile.DeleteNewsStatus(newsId, callback_deleteNewsStatus);
}

function callback_deleteNewsStatus(res) {
	checkResponse(res.value);
	
	if (res.error!=null){alert(res.error)};
	
	if (res.value)
	{
		feedbackValid('Deleting','Deleted');
		window.setTimeout("hideDeleteNewsStatus();", 4000);
	}
	else
	{
		feedbackInvalid('deleteNewsStatusActionContainer');
	}
}

function hideDeleteNewsStatus()
{
	loadStatus();
	closeModalWindow('deleteNewsStatus');
	cleanupFeedback('deleteNewsStatusActionContainer');
}


//**********************
// GENERAL FUNTIONS
//**********************

function getFriendsIDs(controlID){
	var chks = document.getElementById(controlID).getElementsByTagName("input");
	var idList = new Array();
	var counter = 0;
	for (var i=0; i<chks.length; i++)
		{
		if (chks[i].type == "checkbox")
			{
						
				idList[counter] = chks[i].value;
				counter = counter + 1;
				
			}
		}
	return idList;
}

function getGroupsIDs(controlID){
	var chks = document.getElementById(controlID).getElementsByTagName("input");
	var idList = new Array();
	var counter = 0;
	for (var i=0; i<chks.length; i++)
		{
		if (chks[i].type == "checkbox")
			{
				if (chks[i].checked)
					{
					idList[counter] = chks[i].value;
					counter = counter + 1;	
					}		
				
				
			}
		}
	return idList;
}



function showMyStatusFriendsOptions(){
	document.getElementById("addMyStatusFriends").style.display = "block";
	document.getElementById("addMyStatusGroups").style.display = "none";
		
}

function hideMyStatusFriendsOptions(){
	document.getElementById("addMyStatusFriends").style.display = "none";
}

function showMyStatusGroupsOptions(){
	document.getElementById("addMyStatusFriends").style.display = "none";
	document.getElementById("addMyStatusGroups").style.display = "block";
		
}

function showPublicPrivate(){
	document.getElementById("addMyStatusFriends").style.display = "none";
	document.getElementById("addMyStatusGroups").style.display = "none";
		
}

function showMyStatusFriendsOptions(){
	document.getElementById("addMyStatusFriends").style.display = "block";
	document.getElementById("addMyStatusGroups").style.display = "none";
}

function hideMyStatusFriendOptions(){
	document.getElementById("addMyStatusFriends").style.display = "none";
}

function showMyStatusGroupsOptions(){
	document.getElementById("addMyStatusFriends").style.display = "none";
	document.getElementById("addMyStatusGroups").style.display = "block";
		
}

function showMyStatusPublicPrivate(){
	document.getElementById("addMyStatusFriends").style.display = "none";
	document.getElementById("addMyStatusGroups").style.display = "none";
		
}


//////////////////////////
////////My News Status Page
function showEditMyStatusFriendsOptions(){
	document.getElementById("addMyStatusFriends").style.display = "block";
	document.getElementById("addMyStatusGroups").style.display = "none";
		
}

function hideEditMyStatusFriendsOptions(){
	document.getElementById("editMyStatusFriends").style.display = "none";
}

function showEditMyStatusGroupsOptions(){
	document.getElementById("editMyStatusFriends").style.display = "none";
	document.getElementById("editMyStatusGroups").style.display = "block";
		
}

function showEditPublicPrivate(){
	document.getElementById("editMyStatusFriends").style.display = "none";
	document.getElementById("editMyStatusGroups").style.display = "none";
		
}

function showEditMyStatusFriendsOptions(){
	document.getElementById("editMyStatusFriends").style.display = "block";
	document.getElementById("editMyStatusGroups").style.display = "none";
}

function hideEditMyStatusFriendOptions(){
	document.getElementById("editMyStatusFriends").style.display = "none";
}

function showEditMyStatusGroupsOptions(){
	document.getElementById("editMyStatusFriends").style.display = "none";
	document.getElementById("editMyStatusGroups").style.display = "block";
		
}

function showEditMyStatusPublicPrivate(){
	document.getElementById("editMyStatusFriends").style.display = "none";
	document.getElementById("editMyStatusGroups").style.display = "none";
		
}
/////////////////////////

function completeMyStatusFriends(accID, username)
{
	Effect.Fade('txtMyStatusFriendsListWrapper');
	var ul = document.getElementById("ulMyStatusFriendsList");	
	var chks = document.getElementById("ulMyStatusFriendsList").getElementsByTagName("input");
	var counter = 0;
	if(chks.length != 0)
	{
		for(var i=0;i<chks.length;i++)
		{
			if(accID == chks[i].value)
			{
				counter = 1;
			}
		}			
			
		if(counter == 0)
		{
			var chk = document.createElement("input");
			chk.type = "checkbox";
			chk.value = accID;
			chk.id = "c_"+accID;
			chk.style.display = "none"; 
			var lbl = document.createElement("label");
			lbl.innerHTML = username;
			lbl.id = "l_"+accID;
			var img = document.createElement("img");
			img.id = "i_"+accID;
			img.alt ="Remove";
			img.src="/images/icons/delete.gif";
			var aImg = document.createElement("a");
			aImg.href ="javascript:deleteMyStatusFriend(" + accID + ");";
			aImg.id = "a_"+accID;
			aImg.appendChild(img);
			var li = document.createElement("li");
			li.id="l_"+accID;
			li.appendChild(chk);
			li.appendChild(lbl);
			li.appendChild(aImg);			
			ul.appendChild(li);
		}
		else
		{
			alert('You have already selected to share the event with this person.');
		}
		
	}
	else
	{
		var chk = document.createElement("input");
		chk.type = "checkbox";
		chk.value = accID;
		chk.id = "c_"+accID;
		chk.style.display = "none"; 
		var lbl = document.createElement("label");
		lbl.innerHTML = username;
		lbl.id = "l_"+accID;
		var img = document.createElement("img");
		img.id = "i_"+accID;
		img.alt ="Remove";
		img.src="/images/icons/delete.gif";
		var aImg = document.createElement("a");
		aImg.href ="javascript:deleteMyStatusFriend(" + accID + ");";
		aImg.id = "a_"+ accID;
		aImg.appendChild(img);
		var li = document.createElement("li");
		li.id="l_"+accID;
		li.appendChild(chk);
		li.appendChild(lbl);
		li.appendChild(aImg);			
		ul.appendChild(li);
	}
	document.getElementById("txtMyStatusFriends").value = "";
}

function deleteMyStatusFriend(accID)
{
	var ul = document.getElementById("ulMyStatusFriendsList");
	var chks = document.getElementById("ulMyStatusFriendsList").getElementsByTagName("input");
	var lis = document.getElementById("ulMyStatusFriendsList").getElementsByTagName("li");
	for(var i=0;i<chks.length;i++)
	{
		if(accID == chks[i].value)
		{
			var li = document.getElementById(lis[i].id);
			ul.removeChild(li);
		}
	}	
}



function getFriendsCheckedIDs(controlID){
	var chks = document.getElementById(controlID).getElementsByTagName("input");
	var idList = new Array();
	var counter = 0;
	for(var i=0; i<chks.length; i++)
		{
			if(chks[i].type == "checkbox")
				{
					if(chks[i].checked)
					{
						idList[counter] = chks[i].value;
						counter = counter + 1;
					}
				}
		}
		return idList;
}