if(!jQuery.cookie){jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};}
var fixJQUIDialogStyles=function(){$('.ui-widget').css('font-size','1em');$('.ui-dialog').css('overflow','visible').css('padding','0 0 10px').addClass('soft-box dark');$('#alert_dialog').css('overflow','visible').css('padding','0');$('.ui-dialog-titlebar').removeClass('ui-dialog-titlebar').addClass('OW-ui-dialog-titlebar');$('.ui-dialog-titlebar-close').hide();$('#alert_dialog').parent().css('top','100px');$('.ui-dialog').wrap('<div id="alert-modal" class="modal-window" />');}
var getAlertsModal=function(topic,expert,srcButton,extraStyle,hideSuggestions){$('#alert_dialog').remove();$('.modal-window').remove();if(typeof pageTracker!=='undefined'){pageTracker._trackEvent('3.0','Alerts','Get Alerts Button Click');}
if(!hideSuggestions)hideSuggestions=0;genericMessageUnwrapped('<p style="text-align: center; margin-top: 20px;">Creating Update - Please Wait<br /><br /><img src="/skins/orgwis2/images/transparent-loader.gif"></p>','Creating Update');$.post('/alert/get_alerts_dlg/med',{'t':topic,'e':expert,'ns':hideSuggestions},function(ret){$('#alert_dialog').remove();$('.modal-window').remove();$('body').append('<div id="alert_dialog"></div>');$('#alert_dialog').html(ret);$('#alert_dialog').dialog({'modal':false,'resizable':false,'title':'Expert Health Updates','width':'450px','zIndex':10000,'closeOnEscape':false});fixJQUIDialogStyles();if(extraStyle){var parts=extraStyle.split(':');$('#alert_dialog').css(parts[0],parts[1]);}
if(srcButton){var button=$('#'+srcButton);button.parent().removeClass('green');button.html('Update Created');button.attr('title','You have subscribed to this update!');button.tipTip({defaultPosition:"top"});$('#reactivateOnCancel').attr('value',srcButton);var count=button.next('span').html();count++;button.next('span').html(count);}
$('#alerts_manage').load('/alert/get_alerts_manage/pxna/med',{},function(ret){fixSoleTabRendering();});},'html');}
var fixSoleTabRendering=function(){$('#rightCol-header').css('border-radius','0 10px 0 0').css('-webkit-border-radius','0 10px 0 0').css('-moz-border-radius','0 10px 0 0');}
var reactivateGetAlertsButton=function(){if($('#reactivateOnCancel').length>0&&$('#reactivateOnCancel').val()!=''){var button=$('#'+$('#reactivateOnCancel').val());if(button){button.parent().addClass('green');button.html('Get Updates');button.attr('title','Receive e-mail updates about this topic.');}}}
var genericMessage=function(message,title){$('#alert_dialog').remove();$('.modal-window').remove();$.post('/utility/genericMessageDialog/med',{'m':message},function(ret){$('body').append('<div id="alert_dialog">'+ret+'</div>');$('#alert_dialog').dialog({'modal':false,'resizable':false,'title':title,'width':'450px','min-height':'54px','zIndex':10000,'closeOnEscape':false});$('#alert_dialog').css('min-height','54px');fixJQUIDialogStyles();});}
var genericMessageUnwrapped=function(message,title){$('#alert_dialog').remove();$('.modal-window').remove();$('body').append('<div id="alert_dialog">'+message+'</div>');$('#alert_dialog').dialog({'modal':false,'resizable':false,'title':title,'width':'450px','min-height':'54px','zIndex':10000,'closeOnEscape':false});$('#alert_dialog').css('min-height','54px');fixJQUIDialogStyles();}
var genericConfirm=function(message,confirmCallbackFunctionName,title){$('#alert_dialog').remove();$('.modal-window').remove();$.post('/utility/genericConfirmDialog/med',{'m':message,'c':confirmCallbackFunctionName},function(ret){$('body').append('<div id="alert_dialog">'+ret+'</div>');$('#alert_dialog').dialog({'modal':false,'resizable':false,'title':title,'width':'450px','zIndex':10000,'closeOnEscape':false});$('#alert_dialog').css('min-height','54px');fixJQUIDialogStyles();});}
function getSelectedFolders(){var selectedFolders='';$('.health-library li span.active').each(function(){if($(this).parent().attr('id').replace('folder_','')!=''){if(selectedFolders!=''){selectedFolders+=",";}
selectedFolders+=$(this).parent().attr('id').replace('folder_','');}});return selectedFolders;}
function saveFavorite(post,uid){$('#saveFavorite').remove();$('.nugget.video iframe').hide();$('body').append('<div id="saveFavorite" class="modal-window"><div class="savefavorite soft-box" id="modal-wrapper"><h2>Save to Health Library Folders</h2><br /><p>Loading...</p>');if(uid==''){var appendMe='<div id="saveFavorite" class="modal-window"><div class="savefavorite soft-box" id="modal-wrapper"><h2>Log In to Save Content</h2>';appendMe+='<p>Please log in below to save this content to your Health Library. If you do not have an expert profile, please <a href="/auth/register/expert/med" target="_blank">apply for a profile here</a>.</p>';appendMe+='<p>Username: <input type="text" id="savefavorite_login" style="width: 175px; margin-top: 10px;" /><br />';appendMe+='<p>Password: <input type="password" id="savefavorite_password" style="width: 175px; margin-top: 10px;" /><br />';appendMe+='<p>Please enter the name of the folder where you want to save this content:</p>';appendMe+='<p>Folder Name:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" id="addnew_'+post+'" value="" onfocus="$(this).val($(this).val().replace(\'Add to New Folder\', \'\'));" style="width: 175px; margin-top: 5px"></p>';appendMe+='<button style="float: none; margin-left: 155px;" onClick="$(\'#saveFavorite\').remove();">Cancel</button>';appendMe+='<button style="float: none;" class="green" id="savefavorites_'+post+'">Save</button>';$('#saveFavorite').remove();$('body').append(appendMe);attachSaveFavoriteLogic(post,uid);}
else{$.post('/getFoldersForPost/'+post+'/fxp/med',{},function(folderlist){$.post('/getFoldersWithChildIndent/'+uid+'/fxu/med',{},function(ret){var appendMe='<div id="saveFavorite" class="modal-window"><div class="savefavorite soft-box" id="modal-wrapper"><h2>Save to Health Library Folders</h2>';appendMe+='<p>Please select what folders you would like this content saved under. If you select no folders, the content will not be saved. Uncheck all folders to remove from your library entirely.</p>';appendMe+='<ul>';$.each(ret,function(i,j){if(i!='Edit This Folder'){appendMe+='<li><input type="checkbox"';for(var k in folderlist){if(folderlist[k]==j){appendMe+=' checked="checked" ';}}
appendMe+='style="width: 50px" id="savefolder_'+j+'"> <label for="savefolder_'+j+'">'+i+'</label></li>';}});appendMe+='</ul>';appendMe+='<input type="text" id="addnew_'+post+'" value="Add to New Folder" onfocus="$(this).val($(this).val().replace(\'Add to New Folder\', \'\'));" style="width: 200px; margin-left: 50px; margin-top: 5px">';appendMe+='<button style="float: none; margin-left: 155px;" onClick="$(\'#saveFavorite\').remove();$(\'.nugget.video iframe\').show();">Cancel</button>';appendMe+='<button style="float: none;" class="green" id="savefavorites_'+post+'" onclick="$(\'.nugget.video iframe\').show();">Save</button>';appendMe+='<p class="tagline" style="font-size: 0.7em; margin-top: 5px;">You can view and manage your Health Library <a href="/auth/profile/med">here</a> anytime.</p>';$('#saveFavorite').remove();$('body').append(appendMe);attachSaveFavoriteLogic(post,uid);},'json');},'json');}
$('html, body').animate({scrollTop:0},'slow');}
function attachSaveFavoriteLogic(post,uid){$('#savefavorites_'+post).click(function(){var abort=false;if($('#savefavorite_login').length==1){$.ajax({'async':false,'url':'/auth/login_ajax/med','type':'POST','data':'login='+escape($('#savefavorite_login').val())+'&password='+escape($('#savefavorite_password').val()),'success':function(ret){if(ret!='ok'){alert('The login or password provided was not correct. Please try again, or click apply for a profile, or click cancel.');abort=true;return;}}});}
if(abort)return;$('#saveFavorite input').each(function(){if($(this).attr('checked')){$.post('/addFavoriteByFolderId/'+$(this).attr('id').replace('savefolder_','')+'/'+post+'/fxfp/med',{},null,'html');}
else{$.post('/deleteFavoriteByFolderId/'+$(this).attr('id').replace('savefolder_','')+'/'+post+'/fxfp/med',{},null,'html');if(getSelectedFolders()==$(this).attr('id').replace('savefolder_','')){if(window.currentTab=='library'){$('#nugget-wrapper-'+post).remove();}else{$('#postfolders_'+post).remove();}}}});if($('#addnew_'+post).val()!='Add to New Folder'&&$('#addnew_'+post).val()!=''){var newFolder=$('#addnew_'+post).val();$.post('/addFavorite/'+escape(newFolder)+'/'+post+'/fxfp/med',{},function(){if($('.health-library ul:last').length>0){$.post('/getFolderId/'+escape(newFolder)+'/fxf/med',{},function(ret){window.tree[0].addNode('folder_'+ret,newFolder+' <span class="private" id="private_'+ret+'" style="display: none;"></span>',null);$('#folder_'+ret+' span:first').addClass('text').addClass('empty').attr('id','folder_'+ret);$('.user-folders').append('<li><label for="id_'+ret+'"><input type="checkbox" name=id_'+ret+'" value="'+newFolder+'">'+newFolder+'</label></li>');$('#nofolders_warning').remove();},'html');}},'html');}
$('#saveFavorite').remove();genericMessage('Your changes to your Health Library have been saved!','Changes Saved');$.post('/getFoldersForPostWithLink/'+post+'/fxp/med',{},function(ret){var newtext='';for(var key in ret){if(newtext!='')newtext+=', ';newtext+='<a href="'+ret[key]+'">'+key+'</a>';}
if(newtext==''){if(window.currentTab=='library'){$('#nugget-wrapper-'+post).remove();}else{$('#postfolders_'+post).remove();}}
else{newtext+=' <a class="edit" href="javascript:void(0);" onclick="saveFavorite('+post+', '+uid+');">Edit</a>';if($('#postfolders_'+post).length>0){$('#postfolders_'+post).html('<span class="strong">Your Folders:</span> '+newtext);}
else{$('#categories_'+post).after('<p class="categories folders" id="postfolders_"'+post+'"><span class="strong">Your Folders:</span> '+newtext+'</p>');}}
if(uid=='')location.reload();},'json');});}