
var _curtimer=null;var _procPos=null;var _deps=[];var _click1=null;var _click2=null;function getQueryParam(param){var regex=new RegExp("[\\?&]"+param.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]")+"=([^&#]*)");var results=regex.exec(location.search);if(results!=null)
{return decodeURIComponent(results[1].replace(/\+/g," "));}
return null;}
$("document").ready(function(){var defaultName=getQueryParam('n');if(defaultName!=null)
{$('#txtProcName').val(defaultName);}
$('#txtProcName').focus();$('#txtStepDesc').live('keyup',function(){refreshView();});$('#txtProcName').live('keyup',function(){$('#procName').text($('#txtProcName').val());});$('#btnTransSubmit').click(function(){_deps.push({f:parseInt(_click1.Pid),t:parseInt(_click2.Pid)});_click1=null;hideCoverall();updateText();});$('#btnTransCancel').click(function(){_click1=null;hideCoverall();});$('#btnSave').click(function(){var procTitle=$.trim($('#txtProcName').val());if(procTitle.length>0){$(this).slideUp();$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({sbsession:_sbsession,processTitle:procTitle,text:$('#txtStepDesc').val(),deps:_deps}),url:'./ProcessDefinition.asmx/SaveStepPreview',success:function(data){location.href=_reposRoot+'/'+data.d;}});}
else{$('#txtProcName').fadeTo('fast',0.1).fadeTo('fast',0.9).fadeTo('fast',0.1).fadeTo('fast',1.0).focus();}});$('#btnClear').click(function(){_deps=[];$('#txtProcName').val('').focus();$('#txtStepDesc').val('');$('#procName').text('');$('#result img').attr('src','');refreshView();});$('#tryIt').click(function(){$('#txtStepDesc').val($.trim($('.help blockquote').text().replace(/(^|[\n\r])(\s)*/gm,'\n')));refreshView();});$(window).resize(function(){resizeBuilder();});resizeBuilder();});function resizeBuilder()
{var w=$(window);var edHeight=Math.max(w.height()-295,145);var imgHeight=Math.max(w.height()-190,250);$('#txtStepDesc').css({height:edHeight+"px"});$('#result .stepBuilderContainer').css({maxHeight:imgHeight+"px"});}
function refreshView()
{if($('#txtStepDesc').val()!=''){if(_curtimer!=null){window.clearTimeout(_curtimer);}
_curtimer=setTimeout(updateText,500);$('#result img').show();$('#result .help').hide();}
else{$('#result img').hide();$('#result .help').show();}}
function hideCoverall()
{$('#coverall').hide();$('#overAll').hide();}
function updateText()
{_curtimer=null;$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({sbsession:_sbsession,text:$('#txtStepDesc').val(),deps:_deps}),url:'./ProcessDefinition.asmx/StepPreview',success:function(data){$('#result img').attr('src','./files/'+data.d.ImageFile+"?t="+cBypass());$('#stepBuilderMap').html(data.d.ImageMap);var txtStepDesc=document.getElementById('txtStepDesc');var lineNum=txtStepDesc.value.substr(0,txtStepDesc.selectionStart).split("\n").length;for(var i=0;i<data.d.ProcPos.length;i++)
{if(data.d.ProcPos[i].LNum==lineNum)
{var scrollPos=Math.max(data.d.ProcPos[i].T-50,0);$('#result .stepBuilderContainer').animate({scrollTop:scrollPos},200);break;}}
_procPos=data.d.ProcPos;}});}
$(document).delegate('#txtStepDesc','keydown',function(e){var keyCode=e.keyCode||e.which;if(keyCode==9){e.preventDefault();var start=$(this).get(0).selectionStart;var end=$(this).get(0).selectionEnd;$(this).val($(this).val().substring(0,start)
+"\t"
+$(this).val().substring(end));$(this).get(0).selectionStart=$(this).get(0).selectionEnd=start+1;}});