var array_unique_noempty,element_box;jQuery(function(e){function s(s){e("option",c).each(function(){var n=e("#"+e(this).val().toLowerCase()+"_desc").closest("table"),t=n.prev("h2");e(this).val()==s?(n.show(),t.show(),a(n,!0)):(n.hide(),t.hide(),a(n,!1))})}function n(s){switch(s){case"YWSN_Jazz":case"YWSN_Trend_Mens":case"YWSN_Bulk_SMS_SA":case"YWSN_Crystalwebtechs":case"YWSN_Mobily_WS":case"YWSN_Uaedes":e("#ywsn_from_number").parent().parent().hide(),e("#ywsn_from_asid").parent().parent().hide();break;default:e("#ywsn_from_number").parent().parent().show(),e("#ywsn_from_asid").parent().parent().show()}}function a(s,n){e("input",s).each(function(){e(this).prop("required",n)})}var t={};e(".checkbox-column a").click(function(s){s.preventDefault();var n=e(this).attr("id").replace("-lnk",""),a="."+n+"-cb";n in t&&0!=t[n]?(e(a).prop("checked",!1),t[n]=!1):(e(a).prop("checked",!0),t[n]=!0)});var c=e("#ywsn_sms_gateway");"undefined"!=typeof c&&(s(c.val()),n(c.val())),c.on("change",function(){s(c.val()),n(c.val())}),e(document).ready(function(){"use strict";function s(s){var n=e("#ywsn_checkout_checkbox_value"),a=e("#ywsn_checkout_checkbox_text");n.parent().parent().parent().css("paddingTop","0").css("paddingBottom","0"),"requested"==s?(n.parent().parent().parent().parent().show(),a.parent().parent().show(),e(".ywsn-checkout-option").parent().parent().parent().parent().parent().css("paddingBottom","0")):(n.parent().parent().parent().parent().hide(),a.parent().parent().hide(),e(".ywsn-checkout-option").parent().parent().parent().parent().parent().css("paddingBottom","20px"))}e("#ywsn_url_shortening").change(function(){var s=e("option:selected",this).val(),n=e("#ywsn_google_api_key"),a=e("#ywsn_bitly_access_token");switch(s){case"bitly":a.parent().parent().show(),a.prop("required",!0),n.parent().parent().hide(),n.prop("required",!1);break;case"google":a.parent().parent().hide(),a.prop("required",!1),n.parent().parent().show(),n.prop("required",!0);break;default:a.parent().parent().hide(),a.prop("required",!1),n.parent().parent().hide(),n.prop("required",!1)}}).change(),e("#ywsn_sms_test_message").change(function(){var s=e("option:selected",this).val();"write-sms"==s?e(".ywsn-write-sms").show():e(".ywsn-write-sms").hide()}).change(),e(".ywsn-custom-message").on("change keyup input",function(){var s=e(this).val().length,n=ywsn_admin.sms_length-s;e(".ywsn-char-count").find("span").text(n),0>n?e(".ywsn-char-count").addClass("maxed-out"):e(".ywsn-char-count").removeClass("maxed-out")}),e(".ywsn-checkout-option").each(function(){e(this).is(":checked")&&s(e(this).val())}).click(function(){s(e(this).val())}),element_box.init()}),e("body").on("click","button.ywsn-send-test-sms",function(){var s=e(".ywsn-send-result"),n=e(".ywsn-test-sms").val(),a=e("#ywsn_sms_test_message_country").val(),t=e("#ywsn_sms_test_message").val(),c=e(".forminp-custom-send"),r="";if(c.addClass("processing"),c.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),s.show(),s.removeClass("send-progress send-fail send-success"),""==t)return s.addClass("send-fail"),s.html(ywsn_admin.sms_no_message),void c.removeClass("processing").unblock();switch(t){case"write-sms":r=e(".ywsn-custom-message").val();break;default:r=e("#ywsn_message_"+t).val()}if(""==r)return s.addClass("send-fail"),s.html(ywsn_admin.sms_empty_message),void c.removeClass("processing").unblock();if(""==n)return s.addClass("send-fail"),s.html(ywsn_admin.sms_wrong),void c.removeClass("processing").unblock();var i={action:"ywsn_send_sms",phone:n,message:r,country:a};s.addClass("send-progress"),s.html(ywsn_admin.sms_before_send),e.post(ywsn_admin.ajax_url,i,function(e){s.removeClass("send-progress"),c.removeClass("processing").unblock(),e.success===!0?(s.addClass("send-success"),s.html(ywsn_admin.sms_after_send)):(s.addClass("send-fail"),s.html(e.error))})}).on("click","button.ywsn-send-sms",function(){var s=e(".ywsn-send-result"),n=e(".ywsn-sms-metabox"),a=e("#_ywsn_receive_sms").is(":checked"),t=e(".ywsn-custom-message").val();if(n.addClass("processing"),n.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),"requested"==ywsn_admin.sms_customer_notification&&!a&&!window.confirm(ywsn_admin.sms_manual_send_advice))return void n.removeClass("processing").unblock();if(s.show(),s.removeClass("send-progress send-fail send-success"),""==t)return s.addClass("send-fail"),s.html(ywsn_admin.sms_empty_message),void n.removeClass("processing").unblock();var c={action:"ywsn_send_sms",order_id:ywsn_admin.order_id,message:t};s.addClass("send-progress"),s.html(ywsn_admin.sms_before_send),e.post(ywsn_admin.ajax_url,c,function(a){s.removeClass("send-progress"),n.removeClass("processing").unblock(),a.success===!0?(s.addClass("send-success"),s.html(ywsn_admin.sms_after_send)):(s.addClass("send-fail"),s.html(a.error)),e("ul.order_notes").prepend(a.note),e(".ywsn-custom-message").val("")})}),array_unique_noempty=function(s){var n=[];return e.each(s,function(s,a){a=e.trim(a),a&&-1===e.inArray(a,n)&&n.push(a)}),n},element_box={clean:function(e){return e=e.replace(/\s*,\s*/g,",").replace(/,+/g,",").replace(/[,\s]+$/,"").replace(/^[,\s]+/,"")},parseTags:function(s){var n=s.id,a=n.split("-check-num-")[1],t=e(s).closest(".ywcc-checklist-div"),c=t.find(".ywcc-values"),r=c.val().split(","),i=[];return delete r[a],e.each(r,function(s,n){n=e.trim(n),n&&i.push(n)}),c.val(this.clean(i.join(","))),this.quickClicks(t),!1},quickClicks:function(s){var n,a=e(".ywcc-values",s),t=e(".ywcc-value-list ul",s),c=e(s).attr("id");a.length&&(n=a.val().split(","),t.empty(),e.each(n,function(s,n){var a,r;n=e.trim(n),n&&(a=e('
  • '),r=e(''),r.on("click keypress",function(s){("click"===s.type||13===s.keyCode)&&(13===s.keyCode&&e(this).closest(".ywcc-checklist-div").find("input.ywcc-insert").focus(),element_box.parseTags(this))}),a.prepend('
    '+n+"
    ").prepend(r),t.append(a))}))},flushTags:function(s,n,a){var t,c,r,i=e(".ywcc-values",s),o=e("input.ywcc-insert",s);return n=n||!1,r=n?e(n).text():o.val(),"undefined"==typeof r?!1:(t=i.val(),c=t?t+","+r:r,c=this.clean(c),c=array_unique_noempty(c.split(",")).join(","),i.val(c),this.quickClicks(s),n||o.val(""),"undefined"==typeof a&&o.focus(),!1)},init:function(){var s=e(".ywcc-checklist-ajax");e(".ywcc-checklist-div").each(function(){element_box.quickClicks(this)}),e("input.ywcc-insert",s).keyup(function(s){return 13==s.which?(element_box.flushTags(e(this).closest(".ywcc-checklist-div")),!1):void 0}).keypress(function(e){return 13==e.which?(e.preventDefault(),!1):void 0})}}});