
$(document).ready(function(){var addDeleteRowLinks='<a class="btn btn-link wizard-add-row">Add Row</a> | <a class="btn btn-link wizard-del-row" title="Deletes bottom row">Delete Row</a>';var addRowLink='<a class="btn btn-link wizard-add-row">Add Row</a>';$(addDeleteRowLinks).insertAfter('.adddeleterow');$(addRowLink).insertAfter('.addrow');$("body").on("click","a.wizard-add-row",function(){var newId=wizard_add_row(this);var parentDiv=document.getElementById($(this).parent().attr('id'));if(!parentDiv){console.log("adddeleterow is not setup for scrolling!");}else{if(!$(parentDiv).isOnScreen()){parentDiv.scrollIntoView({behavior:"smooth",block:"end"});}}});$("body").on("click","a.wizard-del-row",function(){wizard_del_row(this);});$("#wizardimportonly").change(function(){if(this.checked){var val=1}else{var val=0}
var optsarr={"keyname":"wizard_import_only","keyvalue":val};var opts=JSON.stringify(optsarr);get_ajax_data('setusermeta',opts);});$('#sel-default-tpl').change(function(){var wizard=$('input[name="wizard"]').val();var optsarr={"keyname":"wizard_"+wizard+"_tpl_default","keyvalue":$(this).val()};var opts=JSON.stringify(optsarr);get_ajax_data('setusermeta',opts);});if($('#open-cwform').length>0){var p=$('#open-cwform').position();var left=Math.floor(p.left+16)-($('#cwform').outerWidth()/2);var top=Math.floor(p.top+26);$('#cwform').css('left',left+'px');$('#cwform').css('top',top+'px');$("#open-cwform").click(function(){var d=$("#cwform").css("display");if(d=="none"){$("#cwform").fadeIn("fast");}else{$("#cwform").fadeOut("fast");}});}
$.fn.isOnScreen=function(){var elementTop=$(this).offset().top;var elementBottom=elementTop+$(this).outerHeight();var viewportTop=$(window).scrollTop();var viewportBottom=viewportTop+$(window).height();var footerOverlayTop=$(".divider").offset().top;return elementBottom>viewportTop&&elementTop<footerOverlayTop&&elementBottom<footerOverlayTop;};function onFocusHandler(){var $this=$(this);$this.data('original-name',$this.attr('name')||null);$this.data('original-id',$this.attr('id')||null);if($this.attr('name')){$this.attr('name','obfuscated-name-'+Math.random());}
if($this.attr('id')){$this.attr('id','obfuscated-id-'+Math.random());}
$this.on('keydown',function(e){if(e.which===13){revertToOriginal($this);}});}
function onBlurHandler(){revertToOriginal($(this));}
function revertToOriginal($element){if($element.data('original-name')){$element.attr('name',$element.data('original-name'));}else{$element.removeAttr('name');}
if($element.data('original-id')){$element.attr('id',$element.data('original-id'));}else{$element.removeAttr('id');}}
var selectors=['input[id="address"]','input[id="hostname"]','input[id="ip_address"]','input[id="domain_name"]','input[name="address"]','input[name="hostname"]','input[name="ip_address"]','input[name="domain_name"]'];$(selectors.join(',')).focus(onFocusHandler);$(selectors.join(',')).blur(onBlurHandler);$('input[type="text"], textarea').change(function(){var $this=$(this);$this.val($this.val().trim());});});function wizard_add_row(clickedelement){var adddeleterowDiv=$(clickedelement).prev()[0];var lastRow=$(adddeleterowDiv).children('.row').last().clone();var newid='';lastRow.find("input,select").attr("name",function(){var parts=this.name.match(/(\d+)/g);newname=this.name.replace(/[\d]+/g,++parts);switch(this.type){case"text":this.value="";break;case"checkbox":this.checked=true;break;case"select-one":this.selectedIndex=0;break;}
return newname;});lastRow.find("input,select").attr("id",function(){var parts=this.id.match(/(\d+)/g);newid=this.id.replace(/[\d]+/g,++parts);switch(this.type){case"text":this.value="";break;case"checkbox":this.checked=true;break;case"select-one":this.selectedIndex=0;break;}
return newid;});lastRow.find("i").attr("id",function(){var parts=this.id.match(/(\d+)/g);alertName=this.id.replace(/[\d]+/g,++parts);return alertName;});$(adddeleterowDiv).children('.row').last().after(lastRow);return newid;}
function wizard_del_row(clickedelement){try{var adddeleterowDiv=$(clickedelement).prev().prev()[0];var row_count=$(adddeleterowDiv).children('.row').length;if(row_count<=2){return;}
$(adddeleterowDiv).children('.row').last().remove();}catch(e){alert(e);}}