/* JS FILES COMBINED:
/js/vne/inlineFavorite.js
/js/vne/inlineObjectComment.js
*/

var inlineFavorite=function(favoritesSaveMode,identifier,urn,nRank,nFavoriteId)
{var oSelectorDiv=document.getElementById('UserFavoriteRankControl'+identifier);var spinner=document.createElement('img');spinner.id='spinner_'+identifier;spinner.src='/images/loading.gif';spinner.align='absbottom';oSelectorDiv.appendChild(spinner);var oActionMessage=document.createElement("span");oActionMessage.id='ActionMessage_'+identifier;if(favoritesSaveMode=='SET_RANK')
{oActionMessage.innerHTML="&nbsp;Ranking ...";}
else if(favoritesSaveMode=='DELETE')
{oActionMessage.innerHTML="&nbsp;No longer Following...";}
else
{oActionMessage.innerHTML="&nbsp;You are now following...";}
oSelectorDiv.appendChild(oActionMessage);document.getElementById('removeFavorite'+identifier).style.display='none';document.getElementById('addFavorite'+identifier).style.display='none';var manageFavoritesForm=document.getElementById('manageFavoritesForm');manageFavoritesForm.favoritesSaveMode.value=favoritesSaveMode;manageFavoritesForm.identifier.value=identifier;manageFavoritesForm.urn.value=urn;if(manageFavoritesForm.nRank!=null)
{manageFavoritesForm.nRank.value=nRank;}
manageFavoritesForm.nFavoriteId.value=nFavoriteId;var local_favoritesSaveMode=favoritesSaveMode;$(manageFavoritesForm).ajaxSubmit({dataType:'json',success:function(returnObj)
{if((typeof returnObj==='object')&&(typeof returnObj.bIsSuccess==='boolean'))
{if(returnObj.bIsSuccess==true)
{oSelectorDiv.removeChild(document.getElementById('ActionMessage_'+identifier));oSelectorDiv.removeChild(document.getElementById('spinner_'+identifier));if(returnObj.sMode==='DELETE')
{document.getElementById('addFavorite'+returnObj.identifier).style.display='block';document.getElementById('removeFavorite'+returnObj.identifier).style.display='none';}
else
{document.getElementById('addFavorite'+returnObj.identifier).style.display='none';document.getElementById('removeFavorite'+returnObj.identifier).style.display='block';}
if(local_favoritesSaveMode=='SET_RANK')
{favoriteRank[identifier]=nRank;document.getElementById('removeFavorite'+identifier).style.display='block';highlightBars('UserFavoriteRankControl'+identifier,'imgBar'+identifier+nRank);}}
else
{alert('Error occurred during attempt to manage list:\n'+returnObj.sMessage);}}
else
{alert('Server returned unknown status on attempt to manage list.');}},error:function()
{alert('An error occured during processing.');}});}
function highlightBars(sContainerId,iUpToIdx)
{var bOn=true,aBarOnImages=highlightBars.aBarOnImages,aBarOffImages=highlightBars.aBarOffImages;$('[id="'+sContainerId+'"]').find('img').each(function(index,Element)
{if(this.id.indexOf('Bar')>=0)
{if(bOn)
{Element.src=aBarOnImages[index];bOn=!(this.id==iUpToIdx);}
else
{Element.src=aBarOffImages[index];}}});}
highlightBars.aBarOnImages=['/images/menuicon/add.gif','/images/intness/intness_clear_hover.gif','/images/intness/intness_20_hover.gif','/images/intness/intness_40_hover.gif','/images/intness/intness_60_hover.gif','/images/intness/intness_80_hover.gif','/images/intness/intness_100_hover.gif'];highlightBars.aBarOffImages=['/images/menuicon/add.gif','/images/intness/intness_clear.gif','/images/intness/intness_20.gif','/images/intness/intness_40.gif','/images/intness/intness_60.gif','/images/intness/intness_80.gif','/images/intness/intness_100.gif'];function setEmailFavorite(urn,nFavoriteId)
{var userFavoritesEmailForm=document.getElementById('userFavoritesEmailForm');var oFavoriteCheckbox=document.getElementById('fav_'+nFavoriteId);if(oFavoriteCheckbox)
{userFavoritesEmailForm.urn.value=urn;userFavoritesEmailForm.nFavoriteId.value=nFavoriteId;if(oFavoriteCheckbox.checked===true)
{userFavoritesEmailForm.sSendMessage.value='E';}
else
{userFavoritesEmailForm.sSendMessage.value='';}
$(userFavoritesEmailForm).ajaxSubmit({dataType:'json',success:function(returnObj)
{if((typeof returnObj==='object')&&(typeof returnObj.bIsSuccess==='boolean'))
{if(returnObj.bIsSuccess===true)
{}
else
{alert('Error occurred during attempt to manage list:\n'+returnObj.sMessage);}}
else
{alert('Server returned unknown status on attempt to manage list.');}},error:function()
{alert('An error occured during processing.');}});}};

var deleteComment=function(formIdentifier,nObjectCommentId)
{var form=document.getElementById('deleteObjectComment'+formIdentifier);form.Command.value='DELETE';form.ObjectCommentId.value=nObjectCommentId;$.post(form.action,$(form).serialize(),function(oData,sStatus)
{if((typeof oData==='object')&&(typeof oData.success==='boolean'))
{if(oData.success===true)
{var divCommentNode=$('#commentNode'+formIdentifier+'_'+nObjectCommentId)[0];divCommentNode.parentNode.removeChild(divCommentNode);var sNewLabel=updateObjectCommentCount(oData.nTotalComments,formIdentifier);if(form.objectType.value=='RESOURCE')
{updateFlightboardDisplay(form.objectId.value,sNewLabel);}}
else
{alert('An error occurred in processing the request to delete the comment: '+oData.message);}}
else
{alert('Server returned unknown status on attempt to delete the comment.');}},'json');}
var insertComment=function(thisForm,response)
{var sInstanceIdentifier=response.sInstanceIdentifier;var nObjectCommentId=response.id;var sCommand=response.Command;var sCommentNode='commentNode'+sInstanceIdentifier+'_'+nObjectCommentId;try
{var sNewLabel='Comments';$('#comments'+sInstanceIdentifier).each(function()
{if(sCommand=='EDIT')
{$('#commentNode'+sInstanceIdentifier+'_'+nObjectCommentId).remove();}
$('<div />').attr('id',sCommentNode).html(response.sObjectCommentDisplay).appendTo(this);sNewLabel=updateObjectCommentCount(response.nTotalComments,sInstanceIdentifier,thisForm.objectId.value);return false;});if(thisForm.objectType.value=='RESOURCE')
{updateFlightboardDisplay(thisForm.objectId.value,sNewLabel);}}
catch(e)
{alert('e:'+e.toSource()+'\n\n Data received for ObjectComment:\n'+response);}}
var likeThis=function(sIdentifier)
{var form=document.getElementById('likeThis'+sIdentifier),olikeBtn=$('[id="btnLikeThis'+sIdentifier+'"]');olikeBtn.removeClass('ui-button-text-only').addClass('ui-button-text-icon-primary').html('<span class="ui-button-icon-primary ui-yakabox-icon ui-yakabox-icon-loading"></span><span class="ui-button-text">Saving...</span>');$.post(form.action,$(form).serialize(),function(oData,sStatus)
{if((typeof oData==='object')&&(typeof oData.success==='boolean'))
{if(oData.success===true)
{if(oData.Command=='LIKE')
{form.Command.value='UNLIKE';olikeBtn.html('<span class="ybx-microprofile-dialog-noclose">Unlike This</span>');sNewUserLikeDisplay='<li class="ui-state-default ui-corner-all" id="tagUser'+oData.aNewUserLikeInfo.id+'_'+sIdentifier+'">';sNewUserLikeDisplay+='<a href="/common/getObject.html?urn='+oData.aNewUserLikeInfo.urn+'"';sNewUserLikeDisplay+='style="background-image: url('+oData.aNewUserLikeInfo.icon+');"';sNewUserLikeDisplay+='class="ui-yakabox-icon-link"';sNewUserLikeDisplay+='title="Likes &quot;'+oData.sObjectTitle+'&quot;">';sNewUserLikeDisplay+=oData.aNewUserLikeInfo.name+'</a></li>';$('[id="tagUsersThatLikeThis'+sIdentifier+'"]').find('.ybx-likeList').prepend(sNewUserLikeDisplay);}
else
{form.Command.value='LIKE';olikeBtn.html('<span class="ybx-microprofile-dialog-noclose">Like This</span>');$('[id="tagUser'+oData.nActiveUserId+'_'+sIdentifier+'"]').remove();$('[id="commentNode'+sIdentifier+'_'+oData.id+'"]').remove();}
var sCountDisplay='';if(parseInt(oData.nTotalComments,10)!==0)
{sCountDisplay='<strong><a href="/" onclick="return false;" target="_blank" title="See Who Likes This" ><strong>';sCountDisplay+=oData.nTotalComments;sCountDisplay+=' </strong><span class="ui-yakabox-icon ui-yakabox-icon-like"></span></a>';}
$('[id="tagUsersThatLikeThisCount'+sIdentifier+'"]').html(sCountDisplay);}
else
{alert('An error occurred in processing the request to like the object: '+oData.message);}}
else
{alert('Server returned unknown status on attempt to like the object.');}},'json');}
function updateObjectCommentCount(nCount,sInstanceIdentifier)
{var sLabel=nCount+" Comment";if(nCount!=1)
{sLabel+="s";}
oObj=document.getElementById('totalComments'+sInstanceIdentifier);if(oObj)
{oObj.innerHTML=sLabel;}
return sLabel;}
function updateFlightboardDisplay(nObjectId,sLabel)
{var sDiv='viewComments'+nObjectId;var divCommentTab=$('#'+sDiv)[0];if(divCommentTab)
{var childNode=divCommentTab.childNodes[0];if(childNode)
{childNode.innerHTML=sLabel;}
if(typeof removeMetaFromCache=='function')
{removeMetaFromCache(nObjectId);}}}

