!function(t){function e(e){var n=e.data,o=n.repeatCount+1,a=n.groupClone.clone();return t.isFunction(n.opts.beforeAdd)&&(a=n.opts.beforeAdd.call(this,a)),n.opts.maxItems>0&&n.repeatCount==n.opts.maxItems?(alert("You have hit the maximum allowable items."),!1):(r(a,o,n),n.repeatCount>=n.opts.minItems-1&&a.find("."+n.opts.btnRemoveClass).show(),"append"==n.opts.repeatMode?a.appendTo(n):"prepend"==n.opts.repeatMode?a.prependTo(n):"insertAfterLast"==n.opts.repeatMode&&a.insertAfter(n.find("."+n.opts.groupClass).last()),n.repeatCount++,t.isFunction(n.opts.afterAdd)&&n.opts.afterAdd.call(this,a),!1)}function n(e){var n=t(this),o=e.data,r=o.find("."+o.opts.groupClass);if(r.length<=o.opts.minItems)return!1;if(!(s=n.closest("."+o.opts.groupClass)).length)if("append"==o.opts.repeatMode)var s=r.filter(":last");else if("prepend"==o.opts.repeatMode)s=r.filter(":first");else if("insertAfterLast"==o.opts.repeatMode)s=r.filter(":last");return s.length&&(o.opts.animation?"slide"==o.opts.animation?s.slideUp(o.opts.animationSpeed,o.opts.animationEasing,(function(){a(s,o)})):"fade"==o.opts.animation?s.fadeOut(o.opts.animationSpeed,o.opts.animationEasing,(function(){a(s,o)})):"object"==typeof o.opts.animation&&s.animate(o.opts.animation,o.opts.animationSpeed,o.opts.animationEasing,(function(){a(s,o)})):a(s,o)),!1}function o(t,e,n,o){var a=e;if(n=parseInt(n),t){if(t.indexOf("+=")>-1){var r=t.match(/\+=(\d+)/i);if(r&&r.length&&r[1]){var s=parseInt(r[1]);a=t.replace(/\+=(\d)+/i,o.opts.startingIndex+n+s)}}t.indexOf("++")>-1&&(a=t.replace(/\+\+/gi,o.opts.startingIndex+n))}return a}function a(e,n){t.isFunction(n.opts.beforeDelete)&&n.opts.beforeDelete.call(this,e),e.remove(),"number"==typeof n.repeatCount&&n.repeatCount--,n.opts.reindexOnDelete&&function(e){var n=e.find("."+e.opts.groupClass),o=e.opts.startingIndex;n.each((function(){r(t(this),o,e),o++}))}(n),t.isFunction(n.opts.afterDelete)&&n.opts.afterDelete.call(this,e)}function r(e,n,a){var r,s,p,i,l,d,u,f,c=e.find(":input");return c.length&&c.each((function(){f=t(this),(r=f.data("pattern-name"))&&(l=f.attr("name"),l=o(r,l,n,a),f.attr("name",l),(f.is('input[type="checkbox"]')||f.is('input[type="radio"]'))&&(f.prop("checked")?f.attr("checked",!0):f.attr("checked",!1))),(s=f.data("pattern-id"))&&(i=f.attr("id"),i=o(s,i,n,a),f.attr("id",i)),(d=e.find("label[for="+f.attr("id")+"]")).length||(d=f.parent("label")),d.length||(d=f.siblings("label")),d.length&&(d=d.eq(0),p=d.data("pattern-text"),(u=d.html())&&(u=o(p,u,n,a),d.html(u)),d.attr("for")&&i&&d.attr("for",i))})),e}t.fn.repeater=function(a,s){var p,i,l,d,u,f,c,m,h,g,b,C,v=t(this);if(v.opts=t.extend({},t.fn.repeater.defaults,a),v.repeatCount=0,!v.find("."+v.opts.btnAddClass).length)return alert("You must specify a valid jQuery selector for the add button option in Form Repeater."),!1;if(v.group=t("."+v.opts.groupClass),!v.group.length)return alert("You must specify a valid jQuery selector for the form element grouping option in Form Repeater."),!1;if((p=v.group.find("."+v.opts.btnRemoveClass)).length?p.hide():(p=t('<button type="button" name="rBtnRemove" class="'+v.opts.btnRemoveClass+'" style="display:none" />')).appendTo(v),v.group=v.group.eq(0),v.groupClone=v.group.clone(),0===v.opts.minItems&&(v.group.remove(),v.repeatCount--),v.on("click","."+v.opts.btnRemoveClass,v,n),v.on("click","."+v.opts.btnAddClass,v,e),s&&s.length&&s.forEach((function(e,n){b=r(b=v.groupClone.clone(),n,v),t.isFunction(v.opts.beforeAdd)&&(b=v.opts.beforeAdd.call(this,b)),(C=b.find(":input")).length&&C.each((function(){m=t(this),h=m.attr("name"),"undefined"!=typeof s[n][h]?m.is('input[type="checkbox"]')?""!==s[n][h]&&"1"!==s[n][h]||m.attr("checked",!0):m.val(s[n][h]):m.is('input[type="checkbox"]')?m.attr("checked",!1):m.val(""),(i=m.data("pattern-name"))&&(f=m.attr("name"),f=o(i,f,n,v),m.attr("name",f)),(l=m.data("pattern-id"))&&(u=m.attr("id"),u=o(l,u,n,v),m.attr("id",u)),(g=b.find("label[for="+m.attr("id")+"]")).length||(g=m.parent("label")),g.length||(g=m.siblings("label")),g.length&&(g=g.eq(0),d=g.data("pattern-text"),(c=g.html())&&(c=o(d,c,n,v),g.html(c)),g.attr("for")&&u&&g.attr("for",u))})),"append"==v.opts.repeatMode?b.appendTo(v):"prepend"==v.opts.repeatMode?b.prependTo(v):"insertAfterLast"==v.opts.repeatMode&&b.insertAfter(v.find("."+v.opts.groupClass).last()),v.group&&(v.group.remove(),v.group=null),v.repeatCount=v.find("."+v.opts.groupClass).length-1,v.repeatCount>v.opts.minItems-1&&b.find("."+v.opts.btnRemoveClass).show(),t.isFunction(v.opts.afterAdd)&&v.opts.afterAdd.call(this,b)})),!0===v.opts.showMinItemsOnLoad&&v.repeatCount<v.opts.minItems-1)for(;v.repeatCount<v.opts.minItems-1;)t("."+v.opts.btnAddClass,v).trigger("click");return this}}(jQuery);