
var winHref;var $tabs=null;$(document).ready(function()
{jQuery.extend(jQuery.expr[":"],{isImageHref:function(a,i,m)
{var hrefao=a.getAttribute('href');if(hrefao!=null&&hrefao!=undefined)
{var hrefa=hrefao.toUpperCase();if(hrefa.length>4)
{var lastFour=hrefa.substring(hrefa.length-4,hrefa.length).toUpperCase();if((lastFour=='.GIF')||(lastFour=='.PNG')||(lastFour=='.JPG'))
{return true;}}
if(hrefa.length>5)
{var lastFive=hrefa.substring(hrefa.length-5,hrefa.length).toUpperCase();if(lastFive=='.JPEG')
{return true;}}}
return false;}});$("#txtSendTo").autocomplete(_reposRoot+"/ProcessDefinition.asmx/GetMembers",{parse:function(data)
{var parsed=[];for(var i=0;i<data.d.length;i++)
{parsed[parsed.length]={data:htmlEncode(data.d[i].DisplayName),value:data.d[i].UserId.toString(),result:data.d[i].DisplayName};}
return parsed;},selectFirst:true,dataType:"json",mustMatch:true,formatItem:function(data){return data;}});$('#txtSendTo').result(function(event,data,formatted)
{if(data)
{if($("#selSendTo li[uid='"+formatted+"']").length==0)
{$("<li uid='"+formatted+"'>").html(data+"<span class='del ui-icon-close'></span>").appendTo("#selSendTo");updateAssignButton();}
$('#txtSendTo').val('');}});$('#selSendTo li .del').live('click',function()
{$(this).parent().fadeOut
('fast',function()
{$(this).remove();updateAssignButton();});});winHref=window.location.href;var winHash=window.location.href.indexOf('#');var winHashVal=null;if(winHash!=-1)
{winHashVal=winHref.substring(winHash+1);winHref=winHref.substring(0,winHash);}
$('.toggleStepDescription').click(function(){var pThis=$(this);pThis.toggleClass('toggleStepDescriptionOpen');$('.stepDescriptionList .stepDescription').slideToggle('fast');});$('.showHideStepDetails').click(function()
{$('.stepDescription').slideToggle('fast');$('.stepDiv').slideToggle('fast');$('.showHideStepToggle').toggleClass('ui-icon-zoomout').toggleClass('ui-icon-zoomin');var currentText=$('#showHideStepText',$(this)).text();if(currentText=="Collapse")
$('#showHideStepText',$(this)).text('Expand');else
$('#showHideStepText',$(this)).text('Collapse');}).hover(function()
{$(this).fadeTo('fast',1);},function()
{$(this).fadeTo('fast',0.3);});$('.showEditTaskDetails').hover(function()
{$(this).fadeTo('fast',1);},function()
{$(this).fadeTo('fast',0.3);});$('#assignTask').click(showAssignTask);$('#btnAssignTaskOk').click(assignTask);$('#btnAssignTaskCancel').click(cancelAssignTask);$('#btnPostDiscussion').click(postDiscussion);$('.discOpt .delComment').live('click',function(){deleteDiscussionItem($(this));});$('.discOpt .editComment').live('click',function(){editDiscussionItem($(this));});$('.discEditOpt .discEditCancel').live('click',function(){cancelDiscussionEdit($(this));});$('.discEditOpt .discEditSave').live('click',function(){saveDiscussionEdit($(this));});if(isFrozen)
{$('#freezeProcess a').text('Frozen');$('#freezeProcess a').css('cursor','default');}
else
{$('#freezeProcess').click(showFreezeProcessDlg);$('#btnFreezeProcess').click(freezeProcess);$('#btnCancelFreeze').click(cancelFreezeProcess);}
$('#upgradeProcess').click(showUpgradeProcessDlg);$('#btnUpgradeProcess').click(upgradeProcess);$('#btnCancelUpgrade').click(cancelUpgradeProcess);$('#deleteProcess').click(showDeleteProcessDlg);$('#btnDeleteProcess').click(deleteProcess);$('#btnCancelDelete').click(cancelDeleteProcess);if(thisTaskId!=null)
{$('#tabsBpmn').replaceWith("");addMetadataTabs();refreshAssignedUsers();}
else
{$('#ifMetadataTabs').replaceWith("");$tabs=$("#tabs").tabs({select:function(ev,ui){onSelectPostTab(ev,ui);},show:function(ev,ui){onShowPostTab(ev,ui);}});}
if($("a[strtab='1']").length>0)
{$.get(_reposRoot+'/files/'+reposName+_explorerOffset+'?t='+cBypass(),function(data){loadedStructure(data);});}
$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{processId:"+processId+"}",url:_reposRoot+'/ProcessDefinition.asmx/GetProcessDiscussion',success:function(data){onGotDiscussion(data);}});$('#ifLinkedMetadata').load(metadataLoaded);if((gotoBpmn!=false)||(winHashVal=='tabsBpmn'))
{$tabs.tabs('select','#tabsBpmn');retrieveBpmnDiagram();}
$(".postBody a:isImageHref:has(>img)").fancybox();$(".bpmnOpt li").click(selectBpmnOpt);$("#viewUsesGraph").click(function(){loadRelationshipList('usesProcList',true);});$("#viewUsedByGraph").click(function(){loadRelationshipList('usedByProcList',false);});$('.postBody h2').each(function(){$("<a name='"+$(this).text()+"'/>").insertBefore(this);});$("#dialogDeleteGraphConfirmation").dialog({autoOpen:false,bgiframe:true,resizable:false,height:140,modal:true,overlay:{backgroundColor:'#000',opacity:0.5},buttons:{Cancel:function()
{$(this).dialog('close');},'Ok':function()
{$(this).dialog('close');deleteRelationshipGraph();}}});if(top.location.href.indexOf('/framed')!=-1)
{$('#showNavigation a').text("Hide navigation");$('#showNavigation a').attr("href","javascript:  top.location.href = location.href");}
$('#processStepSvgDiagram rect,#processStepSvgDiagram path').live('click',function(){clickSvgRect($(this).attr('processid'));});$('#stepRep area').live('click',function(event){clickAreaRect($(this).attr('processid'),event);});});function selectBpmnOpt()
{if(!$(this).hasClass('bmpnOptSel'))
{$('li',$(this).parents('ul.bpmnOpt')).removeClass('bmpnOptSel');$(this).addClass('bmpnOptSel');bpmnOpt=$('#bpmnViewOrient li.bmpnOptSel').attr('diagPrefix')+'-'+$('#bpmnViewDetail li.bmpnOptSel').attr('diagSuffix');var date=new Date();date.setTime(date.getTime()+(30*24*60*60*1000));var expires="; expires="+date.toGMTString();document.cookie="bpmnOpt="+bpmnOpt+expires+"; path=/";retrieveBpmnDiagram();}}
function onSelectPostTab(ev,ui){$('.bpmnLoading').show();$('#bpmnContent').hide();var tabSel=$(ui.tab).parent();if(tabSel.hasClass('bpmnTab')){retrieveBpmnDiagram();}}
function onShowPostTab(ev,ui){var tabSel=$(ui.tab).parent();if(tabSel.hasClass('viewTab')){var dParams={processId:processId,processHistoryId:tprocHistoryId,useFrozen:false};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dParams),url:_reposRoot+'/ProcessDefinition.asmx/GetProcessRelationshipsJson',success:function(data){onGotRelationshipJson(data);}});}
unloadRelationshipGraph();$("#usesProcList").show();$("#usedByProcList").show();}
function retrieveBpmnDiagram()
{$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{processId:"+processId+", viewParams:'"+bpmnOpt+"'}",url:_reposRoot+'/ProcessDefinition.asmx/GetProcessBpmn',success:function(data){onGotBpmn(data);}});}
function onGotBpmn(data){$('.bpmnLoading').hide();$('#bpmnContent').show();var gotObj=$(data.d);var loadedObj=$('#bpmnContent').html('').append(gotObj);$('img#bpmnDiag',loadedObj).load(function(){$(this).zoomable();});}
function loadedStructure(data)
{$('#pstructure').html(data);var t=$("#pstructure div[nodeId='"+processId+"']");if(t.length>0)
{highlightDep(t);highlightDepee(t);$('.stepName',t).addClass('stepHi');$('.stepExplorer .step:not(:has(.stepName.stepHi,.stepName.stepDep,.stepName.stepDepee))').remove();}}
function highlightDep(dep)
{var jDep=$(dep);if(!$('.stepName',jDep).hasClass('stepDep')&&!$('.stepName',jDep).hasClass('stepHi'))
{$('.stepName',jDep).addClass('stepDep');var targetId=jDep.attr('targetId');var targets=targetId.split(',');for(var i=0;i<targets.length;i++)
{if(targets[i].length>0)
{$("#pstructure .stepExplorer .step[nodeId='"+targets[i]+"']").each(function(i){highlightDep(this);});}}}}
function highlightDepee(dep)
{var jDep=$(dep);if(!$('.stepName',jDep).hasClass('stepDepee')&&!$('.stepName',jDep).hasClass('stepHi'))
{$('.stepName',jDep).addClass('stepDepee');$('.stepName .pin',jDep).insertAfter($('.stepName a',jDep));var targetId=jDep.attr('nodeId');$("#pstructure .stepExplorer .step[targetId*='"+targetId+"']").each(function(i){highlightDepee(this);});}}
function assignTask()
{var uArr=[];$('#selSendTo li').each(function(i)
{uArr[uArr.length]=parseInt($(this).attr('uid'));});var dSend={taskId:thisTaskId,users:uArr,note:$('#txtComments').val()};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/AssignToMembers',success:function(data){onAssignedTask();}});}
function onAssignedTask()
{$('#assignTask a').text('Assigning...');$('#assignTaskDlg').slideUp('fast',function()
{$('#assignTask').effect('pulsate',{times:2},500,function()
{$('#assignTask a').text('Assign task');});});$('#selSendTo li').remove();$('#txtComments').val('');$('#txtSendTo').val('');updateAssignButton();refreshAssignedUsers();}
function updateAssignButton()
{if($("#selSendTo li").length==0)
{$('#btnAssignTaskOk').css('display','none');}
else
{$('#btnAssignTaskOk').css('display','');}}
function refreshAssignedUsers(){$('#selAssignedTo li').remove();$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({taskId:thisTaskId}),url:_reposRoot+'/ProcessDefinition.asmx/GetTaskAssignments',success:function(data){onGotAssignedUsers(data);}});}
function onGotAssignedUsers(data){var html="";for(var i=0;i<data.d.length;i++){var dispName=data.d[i].DisplayName;if(data.d[i].MemberEmailAddress)
{dispName='<a target="_blank" href="mailto:'+data.d[i].MemberEmailAddress+'">'+dispName+'</a>';}
html+="<li uid='"+data.d[i].AssignedToId+"'>"+dispName+"<span class='del ui-icon-close'></span></li>";}
$('#selAssignedTo').html(html+"<br class='clear'/><br class='clear'/>");$('#selAssignedTo li .del').live('click',function(){$(this).parent().fadeOut
('fast',function(){$(this).remove();$('#showAssignedRoles').hide().html("");$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({removeUserId:$(this).attr("uid"),taskId:thisTaskId}),url:_reposRoot+'/ProcessDefinition.asmx/RemoveTaskAssignment'});});});setupAssignmentEventHandlers();}
function setupAssignmentEventHandlers(){if(jQuery.support.opacity)
$("#selAssignedTo li").hover(function(){showUserAssignedRoles($(this));},function(){$('#showAssignedRoles').fadeOut("fast").hide().html("");});else
$("#selAssignedTo li").hover(function(){showUserAssignedRoles($(this));},function(){$('#showAssignedRoles').hide().html("");});}
function showUserAssignedRoles(user){var popupWidth=$('#showAssignedRoles').width();$('#showAssignedRoles').css({'top':user.position().top+user.outerHeight(),'left':user.position().left+user.width()-popupWidth});if(jQuery.support.opacity)
$('#showAssignedRoles').html("<ul><li>Loading...</li></ul>").show().fadeIn("fast");else
$('#showAssignedRoles').html("<ul><li>Loading...</li></ul>").show();$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({userId:user.attr("uid"),taskId:thisTaskId}),url:_reposRoot+'/ProcessDefinition.asmx/GetUserRoleAssignments',success:function(data){onGotUserRoles(data);}});}
function onGotUserRoles(data){var html="<ul>";for(var i=0;i<data.d.length;i++){html+="<li>"+data.d[i].ProcessTitle+"</li>";}
if(data.d.length==0){html+="<li>No roles assigned.</li>";}
html+="</ul>";$('#showAssignedRoles').html(html);}
function cancelAssignTask()
{$('#assignTaskDlg').slideUp('fast');return false;}
function showAssignTask()
{$('#taskProgressDlg').slideUp('fast');$('#assignTaskDlg').css({'top':$(this).position().top,'right':$(window).width()-($(this).parent().position().left+($(this).parent().outerWidth()))}).slideDown('fast',function(){$('#txtSendTo').focus();});}
function showFreezeProcessDlg(){$('#freezeProcessDlg').slideUp('fast');$('#freezeProcessDlg').insertAfter('#assignTaskDlg');$('#freezeProcessDlg').css({'top':$(this).position().top,'right':$(window).width()-($(this).parent().position().left+($(this).parent().outerWidth()))}).slideDown('fast',function(){});}
function freezeProcess(){$('#freezeProcessDlg').slideUp('fast');$('#freezeProcess a').text('Freezing...');$('#freezeProcessDlg').slideUp('fast',function(){$('#freezeProcess').effect('pulsate',{times:2},500,function(){$('#freezeProcess a').text('Frozen');});});var dSend={processId:processId};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/FreezeProcess',success:function(data){onFrozeProcess();}});return false;}
function onFrozeProcess(){$('#freezeProcess a').css('cursor','default');}
function cancelFreezeProcess(){$('#freezeProcessDlg').slideUp('fast');return false;}
function showUpgradeProcessDlg(){$('#upgradeProcessDlg').slideUp('fast');$('#upgradeProcessDlg').insertAfter('#assignTaskDlg');$('#upgradeProcessDlg').css({'top':$(this).position().top,'right':$(window).width()-($(this).parent().position().left+($(this).parent().outerWidth()))}).slideDown('fast',function(){});}
function upgradeProcess(){$('#upgradeProcessDlg').slideUp('fast');$('#upgradeProcess a').text('Upgrading...');$('#upgradeProcessDlg').slideUp('fast',function(){$('#upgradeProcess').effect('pulsate',{times:2},500,function(){$('#upgradeProcess a').text('Upgraded');});});var dSend={taskId:thisTaskId};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/UpgradeTask',success:function(data){onUpgradeProcess();}});return false;}
function onUpgradeProcess(){$('#upgradeProcess a').css('cursor','default');reloadMainProcWindow();}
function cancelUpgradeProcess(){$('#upgradeProcessDlg').slideUp('fast');return false;}
function showDeleteProcessDlg(){$('#deleteProcessDlg').slideUp('fast');$('#deleteProcessDlg').insertAfter('#freezeProcessDlg');$('#deleteProcessDlg').css({'top':$(this).position().top,'right':$(window).width()-($(this).parent().position().left+($(this).parent().outerWidth()))}).slideDown('fast',function(){});}
function deleteProcess(){$('#deleteProcessDlg').slideUp('fast');$('#deleteProcess a').text('Deleting...');$('#deleteProcessDlg').slideUp('fast',function(){$('#deleteProcess').effect('pulsate',{times:2},500,function(){$('#deleteProcess a').text('Deleted');});});var dSend={processId:processId};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/DeleteProcess',success:function(data){onDeleteProcess();}});return false;}
function onDeleteProcess(){$('#deleteProcess a').css('cursor','default');window.location.href=_reposRoot;}
function cancelDeleteProcess(){$('#deleteProcessDlg').slideUp('fast');return false;}
function saveSteps()
{}
function onGotDiscussion(data)
{var html="";for(var i=0;i<data.d.length;i++)
{var ad=data.d[i];html+=formatDiscussionItem(ad);}
$('#prevDiscussions').html(html);}
function formatDiscussionItem(ad)
{var html="<div class='discussion'><div class='avatar'><img src='"+ad.MemberEmailAddress+"'/></div>";html+="<div class='discFrame'><div class='discPoster'><span class='discPosterName'>"+ad.DisplayName+"</span><span class='discPosterDate'>"+ad.CreatedDateTimeText+" (rev "+ad.MinorVersion+")</span></div>";html+="<div class='discBody'>"+ad.DiscussionText+"</div></div>";if(_isReposAdmin)
{html+='<div class="discOpt" data-did="'+ad.DiscussionId+'"><span class="delComment">delete</span><span class="editComment">edit<span></div>';}
html+="</div>";html+="<br class='clear'/>";return html;}
function postDiscussion()
{var dSend={processId:processId,processHistoryId:tprocHistoryId,discussionText:$('#txtDiscussion').val()};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/PostProcessDiscussion',success:function(data){onPostedDiscussion(data);}});}
function onPostedDiscussion(data){var html=formatDiscussionItem(data.d);var addItem=$(html);addItem.prependTo($('#prevDiscussions')).slideDown('slow');$('#txtDiscussion').val("");}
function editDiscussionItem(item)
{item.css('visibility','hidden');var disc=item.closest('.discussion');var frame=$('.discFrame',disc);var discId=item.closest('.discOpt').data('did');var dSend={processId:processId,discussionId:discId};$('.discBody',disc).hide();$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/GetProcessDiscussionItem',success:function(data){$('<textarea></textarea>').appendTo(frame).val(data.d.DiscussionText).focus();$('<div class="discEditOpt"><span class="discEditSave">Save</span><span class="discEditCancel">Cancel</span></div>').appendTo(frame);}});}
function finishedDiscussionEdit(item)
{var disc=item.closest('.discussion');var frame=$('.discFrame',disc);$('.discOpt .editComment',disc).css('visibility','visible');$('.discBody',disc).show();$('textarea',frame).remove();$('.discEditOpt',frame).remove();}
function cancelDiscussionEdit(item)
{finishedDiscussionEdit(item);}
function saveDiscussionEdit(item){var disc=item.closest('.discussion');var newText=$('textarea',disc).val();var discId=$('.discOpt',disc).data('did');$('.discBody',disc).html('');var dSend={processId:processId,discussionId:discId,newText:newText};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/UpdateProcessDiscussionItem',success:function(data){$('.discBody',disc).html(data.d.DiscussionText);}});finishedDiscussionEdit(item);}
function deleteDiscussionItem(item)
{var discId=item.closest('.discOpt').data('did');var dSend={processId:processId,discussionId:discId};var discItem=item.closest('.discussion').slideUp('fast',function(){$(this).remove();});$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/DeleteProcessDiscussion'});}
function showMetadata(tabName,isDataTab){if(isDataTab)
$('#ifLinkedMetadata').attr('src',_reposRoot+"/TaskMetadata.aspx?taskId="+thisTaskId+"&t="+cBypass());else
$('#ifLinkedMetadata').attr('src',_reposRoot+"/LinkMetadata.aspx?taskId="+thisTaskId+"&section="+escape(tabName)+"&t="+cBypass());}
function clickSvgRect(processId)
{if(_svgSteps&&processId)
{for(var i=0;i<_svgSteps.length;i++)
{var taskStep=$('a.pid_'+processId);if(taskStep.length>0)
{window.location.href=taskStep.eq(0).attr('href');}
else
if(_svgSteps[i].processId==processId)
{window.location.href=_reposRoot+"/"+_svgSteps[i].prettyPostTitle;}}}}
function clickAreaRect(processId){var taskStep=$('a.pid_'+processId);if(taskStep.length>0){event.preventDefault();window.location.href=taskStep.eq(0).attr('href');}}