
$("document").ready(function()
{jQuery.extend(jQuery.expr[":"],{containsNoCase:function(a,i,m){return a.innerHTML.toUpperCase().indexOf((m[3]).toUpperCase())!=-1;}});$('#txtFilter').keypress(function(e){if(e.keyCode==13){$('#btnFilter').click();return false;}});$("#tabs").tabs();$("#procDragTagList").accordion({collapsible:true,autoHeight:false,active:-1});$('#btnSelectProc').click(function(){showSelectProcess();return false;});$('#btnName').click(function(){showName();return false;});$('#btnSaveProjPlan').click(function(){showFinish();return false;});$("#procDragTagList li").click(function(){selectStep($(this).attr('procid'));});loadStructure();$('#txtProjectPlanName').keyup(function(){checkProjectName();});$('#tabsProjectHome a').click(function(){selectHomeLink($(this));return false;});});function selectHomeLink(pThis)
{var hr=pThis.attr('href');var dSend={path:hr};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/ProcessIdFromPath',success:function(data){onSelectedHomeLink(data,hr);}});}
function onSelectedHomeLink(data,hr)
{if(data.d==0)
{window.location.href=hr;}
else
{selectStep(data.d);}}
var _loadEvent=0;function checkProjectName()
{_loadEvent++;var dSend={projectName:$('#txtProjectPlanName').val()};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/CheckProjectName',success:function(data){onGotCheck(data,_loadEvent);}});}
function onGotCheck(data,loadEvent)
{if(loadEvent==_loadEvent)
{displayFeedback(data);}}
function displayFeedback(data)
{if(data.d.Allowed)
{$('#projectNameCheck').removeClass('ui-state-error');$('#btnSaveProjPlan').css('display','');}
else
{$('#projectNameCheck').addClass('ui-state-error');$('#btnSaveProjPlan').css('display','none');}
$('#projectNameCheck').text(data.d.Message);}
function onAddedIterations(iters,tsk)
{if((iters.length>0)&&(iters[0].length>0))
{tsk.children('.taskName').children('a').text(iters[0]);if(tsk.children('.taskName').children('a').length==0)
tsk.children('.taskName').text(iters[0]);}}
function filterChanged()
{var filterText=$('#txtFilter').val();$("#procDragTagList li").attr('flt','no');$("#procDragTagList li:not(:containsNoCase('"+filterText+"'))").attr('flt','yes');$("#procDragTagList li[flt='no']").css('display','');$("#procDragTagList li[flt='yes']").css('display','none');$("#procDragTagList h3").css('display','none');var visDiv=$("#procDragTagList div:has(li[flt='no'])");visDiv.each(function(i)
{var pNodes=$(this).prev();var lstHead=pNodes.eq(0);lstHead.css('display','');});$('#procDragTagList').accordion('activate',false);}
function loadStructure()
{$.get(_reposRoot+'/files/'+reposName+'/explorer.html?t='+cBypass(),function(data){loadedStructure(data);});}
function loadedStructure(data)
{$('#struct').append(data);$('#struct a').removeAttr('href');$('#struct .pin').remove();$('.stepExplorer .step').mouseover(highlightStep);$('.stepExplorer .step').mouseout(unhighlightStep);$('#structTab').css('display','');$('#tabsStruct').css('display','');$('#struct .step').click(function(){selectStep($(this).attr('nodeid'));});}
function unhighlightStep()
{$('#struct table.stepExplorer .stepName.stepHi').removeClass('stepHi');$('#struct table.stepExplorer .stepName.stepDep').removeClass('stepDep');}
function highlightStep()
{unhighlightStep();highlightDep(this);$('.stepName',this).addClass('stepHi');}
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)
{$("#struct table.stepExplorer .step[nodeId='"+targets[i]+"']").each(function(i){highlightDep(this);});}}}}
function showName()
{$('#btnName .ui-icon').addClass('ui-icon-carat-1-e');$('#btnName .ui-icon').removeClass('ui-icon-none');$('#projectName').slideDown('fast',function(){$('#txtProjectPlanName').focus();});$('#btnDefine .ui-icon').removeClass('ui-icon-carat-1-e');$('#btnDefine .ui-icon').addClass('ui-icon-none');$('#projectTailor').slideUp('fast');$('#selectProcess').slideUp('fast');$('#findQ').slideUp();$('#projectFinish').slideUp('fast');}
function showDefine()
{$('#btnName .ui-icon').removeClass('ui-icon-carat-1-e');$('#btnName .ui-icon').addClass('ui-icon-none');$('#btnSelectProc .ui-icon').removeClass('ui-icon-carat-1-e');$('#btnSelectProc .ui-icon').addClass('ui-icon-none');$('#selectProcess').slideUp('fast');$('#projectName').slideUp('fast');$('#btnDefine').slideDown('fast');$('#btnName').slideDown('fast');$('#btnDefine .ui-icon').addClass('ui-icon-carat-1-e');$('#btnDefine .ui-icon').removeClass('ui-icon-none');$('#projectTailor').slideDown('fast',function(){whereAmI();});$('#btnFinish .ui-icon').removeClass('ui-icon-carat-1-e');$('#btnFinish .ui-icon').addClass('ui-icon-none');$('#btnFinish').slideUp();$('#projectFinish').slideUp('fast');$('#findQ').slideDown();}
function showFinish()
{$('#btnName').slideUp('fast');$('#projectName').slideUp('fast');$('#btnDefine').slideUp('fast');$('#projectTailor').slideUp('fast');$('#btnSelectProc').slideUp('fast');$('#btnFinish').slideDown();$('#btnFinish .ui-icon').addClass('ui-icon-carat-1-e');$('#btnFinish .ui-icon').removeClass('ui-icon-none');$('#projectFinish').slideDown('fast');$('#findQ').slideUp();finish();}
function showSelectProcess()
{$('#btnName .ui-icon').removeClass('ui-icon-carat-1-e');$('#btnName .ui-icon').addClass('ui-icon-none');$('#btnName').slideUp('fast');$('#btnDefine .ui-icon').removeClass('ui-icon-carat-1-e');$('#btnDefine .ui-icon').addClass('ui-icon-none');$('#selectProcess').slideDown('fast');$('#projectName').slideUp('fast');$('#btnDefine').slideUp('fast');$('#btnSelectProc .ui-icon').addClass('ui-icon-carat-1-e');$('#btnSelectProc .ui-icon').removeClass('ui-icon-none');$('#projectTailor').slideUp('fast');$('#btnFinish .ui-icon').removeClass('ui-icon-carat-1-e');$('#btnFinish .ui-icon').addClass('ui-icon-none');$('#btnFinish').slideUp();$('#projectFinish').slideUp('fast');$('#findQ').slideUp();}
function selectStep(procId)
{$('#tailorDlg').insertAfter($('#projectTailorProcess'));$('#projectTailorProcess').html('<div class="hBlurb ui-state-highlight"><h3>Loading...</h3><p>Loading process structure for tailoring</p><br/><br/></div>');$('#selectProcess').slideUp('fast',function(){$('#projectTailor').slideDown('fast');});$('#tailorDlg').css('display','none');$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{'processId':"+procId+"}",url:_reposRoot+'/ProcessDefinition.asmx/GetProcessTaskHtml',success:function(data){loadedProcess(data);}});}
function loadedProcess(data)
{$('#projectTailorProcess').html(data.d);showDefine();}