/**
 *
 * @access public
 * @return void
 **/
function customizechangeAddPrivacy(value){
	if(value=='Customize')
		{
			if($('notes_note_privacy'))
				{
					$('notes_note_privacy').value = 'Customize';
				}
			openModal_Window('selMsgCustomize',true);
		}
}

/**
 *
 * @access public
 * @return void
 **/
function customizePrivacyEdit(unid){
	if( $('notes_note_privacy') )
		{
			if($('notes_note_privacy').value != 'Customize')
				$('notes_note_privacy').value = 'Customize';
		}

	$('friends_select_name').value=$('some_friends_name').value;
	$('friends_filter').value=$('friends_name').value;
	$('customize_status').value=$('customize_status').value;
	onCustomize($('customize_status').value);
	$('selOnlyMyFriends').show();
	getAjaxContent(SITE_URL+'members/ajaxNotes.php','act=getSelectFriendsName&unid='+unid,'selFriendNameAdded1','post');
	getAjaxContent(SITE_URL+'members/ajaxNotes.php','act=getFriendsName&unid='+unid,'selFriendNameAdded','post');
	customizechangeAddPrivacy('Customize');
}

/**
 *
 * @access public
 * @return void
 **/
function onCustomize(cus){
	CheckAllCusRadio(cus);
	if(cus != 'OnlyMe')
		$('selUserCustomizeValue').innerHTML='';
	else
		$('selUserCustomizeValue').innerHTML=cus;
	if(cus == 'FriendsofFriends')
		{
			$('users_view_status').checked=true;
		}
	else
		$('users_view_status').checked=false;
	$('customize_status').value = cus;
}

function CheckAllCusRadio(cus)
	{
		var frm = eval('document.selFormWriteNote');
		for (var i=0;i<frm.elements.length;i++)
		{
			var e=frm.elements[i];
			if (e.type=='radio')
			{
				if (e.value==cus)
				{
					e.checked=true;
				}
			}
		}
		return false;
	}

/**
 *
 * @access public
 * @return void
 **/
function unCheckAllCusRadio(frmName){
	var frm = eval('document.'+frmName);
	for (var i=0;i<frm.elements.length;i++)
	{
		var e=frm.elements[i];
		if (e.type=='radio')
		{
			e.checked=false;
		}
	}
	return false;
}

var divForNoRecords = 'selTagNoFriends';
var divSuggestionFocus = 'selTagSuggestionFocus';

/**
 *
 * @access public
 * @return void
 **/
function getTagPeopleSuggestion(divs,divs1,url){
	var options_xml = {
		script: function (input) { return url+"?suggest="+input; },
		varname:"suggest",
		div_ids:divs,
		div_ids1:divs1,
		callback: function (obj){addToTagList(obj.id)}
	};
	var as_xml = new bsn.AutoSuggest('tag_people_name', options_xml);
}

/**
 *
 * @access public
 * @return void
 **/
function addToTagList(fname){
	$('selTagNoFriends').hide();
	createTagDiv(fname);
	addTagPeopleName(fname);
	updateTagPeopleDiv();
}

/**
 *
 * @access public
 * @return void
 **/
function addTagPeopleName(fname){
	$("notes_tag_people").value=$("notes_tag_people").value+','+fname;
}

/**
 *
 * @access public
 * @return void
 **/
function deleteNoteTagPeopleName(div_id,note_id)
	{
		$('tagNote_'+div_id).hide();
		url = SITE_URL+'members/ajaxNotes.php';
		pars='isAjax=true&remove_tag=true&tag_id='+div_id+'&unid='+note_id+'&';
		getAjaxContent(url,pars,'','post');
	}
/**
 *
 * @access public
 * @return void
 **/
function deleteTagPeopleName(fname)
	{
		var allFname = $("notes_tag_people").value;
		allFname = ','+allFname;
		var removedName = allFname.replace(","+fname,'');
		$("notes_tag_people").value = '';
		$("notes_tag_people").value = removedName.substring(1,removedName.length);
	}

/**
 *
 * @access public
 * @return void
 **/
function updateTagPeopleDiv()
	{
		$('tag_people_name').value='';
		$('tag_people_name').focus();
	}

/**
 *
 * @access public
 * @return void
 **/
function createTagDiv(fname)
	{
		var newdiv = document.createElement('div');
		var divIdName = 'Tag'+fname;
		newdiv.setAttribute('id',divIdName);
		newdiv.style.width = "100px";
		newdiv.style.height = "20px";
		newdiv.innerHTML = fname+"&nbsp;&nbsp;<a onClick=this.parentNode.parentNode.removeChild(this.parentNode);updateTagPeopleDiv();deleteTagPeopleName('"+fname+"');>Delete</a>";
		$('selTagPeopleNameAdded').appendChild(newdiv);
		return false;
	}

/**
 *
 * @access public
 * @return void
 **/
function updateFriendsDiv()
	{
		$('friend_name').value='';
		$('friend_name').focus();
	}

/**
 *
 * @access public
 * @return void
 **/
function deleteCustomizeFriendsName(fname,field_name)
	{
		var allFname = $(field_name).value;
		allFname = ','+allFname;
		var removedName = allFname.replace(","+fname,'');
		$(field_name).value = '';
		$(field_name).value = removedName.substring(1,removedName.length);
	}

/**
 *
 * @access public
 * @return void
 **/
function updateFriendsValue()
	{
		updateFriendsDiv();
	}

//*****************comments function start from here ***********************/
/**
 *
 */
function PostComments()
	{
		var url = arguments[0];
		var parms = arguments[1];
		var textarea_id = arguments[2];
		var resultDiv = arguments[3];
		var remainingStr = ' Characters remaining';
		if( arguments.length > 4 )
			{
				var replace_id = arguments[4];
			}
		if( arguments.length > 5 )
			{
				var max_length = arguments[5];
			}
		if(arguments.length > 6)
			{
				var selLodingPostingTest = arguments[6];
			}

		 var postValue=jstrim($(textarea_id).value);

		 if( postValue.length > max_length )
			{
				postValue = postValue.substring(0, max_length);
			}

		 parms='activity_post_comments=true&'+ parms +'&activity_comment_content='+escape(postValue);
		if( postValue=='' || $(textarea_id).style.fontSize=='12px' )
			{
				$(textarea_id).style.fontSize='12px';
				$(textarea_id).value='Write a comment...';
				new Effect.Highlight(textarea_id, { startcolor: '#FFCFCF',endcolor: '#ffffff' });
				return;
			}

		if($(selLodingPostingTest))
			{
				$(selLodingPostingTest).innerHTML='<img src="../images/ajax-page_loader.gif" />&nbsp;Posting..';
			}
		else
			{
				$(resultDiv).innerHTML='<img src="../images/ajax-page_loader.gif" />&nbsp;Posting..';
			}
		new Ajax.Request(
					url,
					{
						method:'post',
						parameters:parms +"&isAjax=true&items=" + Math.random(),
						onCreate:function(req){
							//For later use
						},
						onComplete:function(resp)
						{
							//setting the text area value to  empty
							data = resp.responseText;
							tmpArr = data.split('|||');
							if($(selLodingPostingTest))
								{
									$(selLodingPostingTest).innerHTML='';
								}
							$(textarea_id).value='';
							$(resultDiv).innerHTML='';
							 resp.responseText.evalScripts();
							$(resultDiv).innerHTML=tmpArr['0'];
							//setSlideDownEffect(resultDiv);
							if(replace_id && max_length)
								{
									$(replace_id).innerHTML = max_length+' '+remainingStr;
								}
							if(tmpArr['1'])
								{
									setCommentLastID(tmpArr['1'])
								}
						}
					}
				);
				return false;
	}
//******************* comments function end from here ****************************/
//******************* notes Profilefunction start from here *********************/
/**
 *
 * @access public
 * @return void
 **/
function setNotesVaule()
	{
		$('selProfileEditCustomizeShow').show();
		hideAllBlocks();
		updateFriendsValue();
	}

/**
 *
 * @access public
 * @return void
 **/
function onProfileCustomizeAddCancel()
	{
		$('notes_note_privacy').value='FriendsofFriends';
		$('friends_select_name').value='';
		$('customize_status').value='';
		$('selUserCustomizeValue').innerHTML='';
		$('selFriendNameAdded').innerHTML='';
		$('selProfileEditCustomizeShow').innerHTML='';
		unCheckAllCusRadio('msgCustomizeform');
		updateFriendsValue();
		hideAllBlocks();
	}
//***************** notes Profile function end here ******************************/
/**
 *
 * @access public
 * @return void
 **/
function resetPosition()
{
	var photoPosition = $('notesphotoposition').value;
	var photoPosition = photoPosition.substr(1);
	var splitValue = photoPosition.split('|');
	if($('photoEditCount').value)
		{
			i=$('photoEditCount').value;
			var split_length = parseInt(splitValue.length) + parseInt($('photoEditCount').value);
		}
	else
		{
			i=0;
			var split_length = splitValue.length;
		}

	for(i;i<split_length;i++)
		{
			if($('photoEditCount').value)
				var splitIndex = parseInt(i) - parseInt($('photoEditCount').value);
			else
				var splitIndex =i;
			if(splitValue[splitIndex]  )
				{
					var div_name = 'selViewPhoto_'+splitValue[splitIndex];
					if($('photoDeleteCount').value)
						{
							if(parseInt($('photoEditCount').value) < parseInt($('photoDeleteCount').value))
								{
									var new_pos = parseInt(i)+1;
								}
							else
								{
									var new_pos = parseInt(i);
								}
						}
					else
						{
							var new_pos = parseInt(i)+1;
						}
					$(div_name).innerHTML = " &lt; Photo "+new_pos+" &gt; ";
				}
		}
}
/**
 *
 * @access public
 * @return void
 **/
function findPhotoCheckPoxVal(val,count)
	{
		var testVal = $('notes_body').value;
		var div_name = 'selViewPhoto_'+count;
		if(val.checked==true)
			{
				$('photoName').value = $('photoName').value+'@'+val.value;
				var photocount = parseInt($('photocount').value)+1;
				$('photocount').value = photocount;
				$('notes_body').value = testVal+'<Photo '+photocount+'>';
				$(div_name).innerHTML = " &lt; Photo "+photocount+" &gt; ";
				$('notesphotoposition').value = $('notesphotoposition').value+'|'+count;
				resetPosition();
			}
		else
			{
				var photocount = parseInt($('photocount').value);
				$('notes_body').value = testVal.replace('<Photo '+photocount+'>', "");
				$('photocount').value = photocount-1;
				var photonameRepl = $('photoName').value;
				$('photoName').value = photonameRepl.replace('@'+val.value, "");
				var notesphotopositionRepl = $('notesphotoposition').value;
				var notePhotoRepl = notesphotopositionRepl.split('|');
				$('notesphotoposition').value = notesphotopositionRepl.replace('|'+count, "");
				$(div_name).innerHTML = '';
				resetPosition();
			}
	}

/**
 *
 * @access public
 * @return void
 **/
function noteImageBuildBody(val,position)
	{
		var testVal = $('notes_body').value;
		var photocount = parseInt($('photocount').value);
		var photoDeleteCount = parseInt($('photoDeleteCount').value);
		$('notes_body').value = testVal.replace('<Photo '+position+'>', "");
		$('photocount').value = parseInt(photocount-1);
		$('photoDeleteCount').value = parseInt(photoDeleteCount-1);
		var photoEditCount = $('photoEditCount').value;
		resetBodyPosition(photocount,position);
	}

/**
 *
 * @access public
 * @return void
 **/
function showDeletePhotoLink(type,url,note_id)
	{
		var image_count = $('photoEditCount').value;
		for(i=1;i<=image_count;i++)
			{
				var div_name = 'selNotesImageDelete_'+i;
				if(type=='hide' && $(div_name))
					$(div_name).hide();
			}
		if(type=='hide')
			{
				$('selIframeImageLoder').show();
				$('selUploadDeleteLink').hide();
				if(url)
					getAjaxContent(url,'show_ifram=true&unid='+note_id,'selIframeImageLoder','post');
			}
	}

/**
 *
 * @access public
 * @return void
 **/
function resetBodyPosition(count,position)
	{
		var testVal = $('notes_body').value;
		var nowPhoto ='';
		for(i=1;i<=count;i++)
			{
				if(parseInt(position) < i)
					{
						var newvalue = parseInt(i)-1;
						$('notes_body').value = testVal.replace('<Photo '+i+'>', '<Photo '+newvalue+'>');
						testVal = $('notes_body').value;
					}
			}
	}

//admin side js
/**
 *
 * @access public
 * @return void
 **/
function chkSelectCheckBox(thisForm)
	{
			var unChkCount=0;
			var chkBoxCount = 0;
			for (var i=0; i<thisForm.elements.length; i++)
				{
					if (thisForm.elements[i].type == "checkbox")
						{
							chkBoxCount++;
							if(!thisForm.elements[i].checked)
								{
									unChkCount++;
								}
						}
				}
			if(unChkCount==1 && !document.selMemberForum.checkall.checked)
				{
					document.selMemberForum.checkall.checked=true;
				}
			else if(chkBoxCount!=unChkCount)
				{
					document.selMemberForum.checkall.checked=false;
				}

	}

/**
 *
 * @access public
 * @return void
 **/
function redirectToHome(html_url)
	{
		window.location = html_url;
	}

/**
 *
 * @access public
 * @return void
 **/
function adminCustomizePrivacyEdit(note_id)
	{
		$('friends_select_name').value=$('friends_name').value;
		$('customize_status').value=$('customize_status_value').value;
		onCustomize($('customize_status_value').value);
		getAjaxContent(SITE_URL+'admin/ajaxManageNotes.php','ajax_page=true&action=getFriendsName&note_id='+note_id,'selFriendNameAdded','post');
		customizechangeAddPrivacy('Customize');
	}

/**
 *
 * @access public
 * @return void
 **/
function postPreviewValue(frmName)
	{
		if(frmName == 'frmPreview')
			document.frmPreview.submit();
		else if(frmName == 'frmDeleteNote')
			document.frmDeleteNote.submit();
	}

/**
 *
 * @access public
 * @return void
 **/
function addNoteValidation()
	{
		var action_value = arguments[0];
		var form = arguments[1];
		if( arguments.length > 2 )
			{
				$('msg').value = arguments[2];
			}
		var notes_title_value = $('notes_title').value;
		var notes_title_lenght = notes_title_value.length;
		if(IsBlank('notes_title') || parseInt(notes_title_lenght) > 150 || IsBlank('notes_body') )
			{
				var url = SITE_URL+'members/ajaxNotes.php';
				var notes_title = $('notes_title').value;
				var photoName = $('photoName').value;
				var notes_body = $('notes_body').value;
				var notes_tag_people = $('notes_tag_people').value;
				var photocount = $('photocount').value;
				var unid = $('unid').value;
				var params = 'view=validateValue&photocount='+escape(photocount)+'&photoName='+escape(photoName)+'&notes_title='+escape(notes_title)+'&notes_body='+escape(notes_body)+'&unid='+escape(unid);
				getAjaxContent(SITE_URL+'members/ajaxNotes.php',params+'&notes_tag_people='+notes_tag_people,'selUserNotes','post');
			}
		else
			{
				$('write_note_function').value=action_value;
				form.submit();
			}
	}

/**
 *
 * @access public
 * @return void
 **/
function showNoteList(url,pars,resultDiv)
	{
		getAjaxContent(url,pars,resultDiv,'post');
	}

/**
 *
 * @access public
 * @return void
 **/
function changeTextAreaPosition(t)
	{
		 t.rows =1
	}

/**
 *
 * @access public
 * @return void
 **/
function goToPreviewAction(div_name,html_url)
{
	closeModal_Window_OK(div_name);
	window.location=html_url;
}