
$("document").ready(function()
{var first=$('#procSelList .procSel').eq(0);first.addClass("selProc");$('#selectedProcess').val(first.attr('ptid'));$('#procSelList .procSel').click(selectProcess);$('#ctl00_ctl00_ContentBody_ContentMain_txtProcessName_txtProcessName_txt').keyup(function(){nameChanged();});$('#lnkProcBuilder').click(function(){var ptxt=$.trim($('#ctl00_ctl00_ContentBody_ContentMain_txtProcessName_txtProcessName_txt').val());if(ptxt.length>0)
{$('#lnkProcBuilder').attr('href',$('#lnkProcBuilder').attr('href')+"?n="+encodeURIComponent(ptxt));}});});function selectProcess()
{$('#procSelList .procSel').removeClass("selProc");$(this).addClass("selProc");$('#selectedProcess').val($(this).attr('ptid'));}
var checkCycle=0;function nameChanged()
{checkCycle++;var filterText=$('#ctl00_ctl00_ContentBody_ContentMain_txtProcessName_txtProcessName_txt').val();if(filterText.length==0){$('#hMatching').hide();$('#lstMatches').hide();if(searchTimehandle!=null){clearTimeout(searchTimehandle);}}
else{$('#hMatching').show();if(searchTimehandle!=null)
{clearTimeout(searchTimehandle);}
var checkVer=checkCycle;var searchTimehandle=setTimeout(function(){checkProcessDup(filterText,checkVer);},500);}}
var searchTimehandle=null;function checkProcessDup(filterText,checkVer)
{searchTimehandle=null;$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({q:filterText,limit:20,timestamp:''}),url:_reposRoot+'/ProcessDefinition.asmx/GetProcesses',success:function(data){if(checkVer==checkCycle){var lstMatches=$('#lstMatches').empty().show();var chkTitle=filterText.toLowerCase();var foundCount=0;for(var i=0;i<data.d.length;i++){var fullTitle=data.d[i].ProcessTitle.toLowerCase();if(fullTitle.indexOf(chkTitle)!=-1){var newLi=$('<li><a target="_blank"></a></li>').appendTo(lstMatches);$('a',newLi).text(data.d[i].ProcessTitle).attr('href',_reposRoot+'/'+data.d[i].PrettyPostTitle);foundCount++;if(foundCount>20)
{break;}}}
if(foundCount==0){$('<li>No matching items found</li>').appendTo(lstMatches);}}}});}