function itsg_gf_abnlookup_function(e,i,a){var s=gf_abnlookup_settings.ajax_url,o=gf_abnlookup_settings.validation_message_loading,t=gf_abnlookup_settings.validation_message_not_valid,n=gf_abnlookup_settings.validation_message_error_communicating,l=gf_abnlookup_settings.validation_message_11_char,d=gf_abnlookup_settings.text_checking,r=gf_abnlookup_settings.text_check_abn,_=gf_abnlookup_settings.gst_value_yes,p=gf_abnlookup_settings.gst_value_no,g=gf_abnlookup_settings.lookup_timeout,c=gf_abnlookup_settings.lookup_retries;!function(i){"use strict";var a=function(e){var a=i.ajax({type:"POST",url:s,data:e,tryCount:0,retryLimit:c,beforeSend:function(){h.hide(),v.html(o),y.val(d+" ... "),v.addClass("loading"),v.removeClass("error Active Cancelled validation_message")},success:function(e){if("undefined"!=typeof e)try{console.log(e),y.val(r);var i=JSON.parse(e);if(void 0!=i.exception)h.hide(),"Search text is not a valid ABN or ACN"==i.exception.exceptionDescription?v.html(t):v.text(i.exception.exceptionDescription),v.removeClass("Active Cancelled loading"),v.addClass("error validation_message"),m.hide(),C.hide(),E.hide(),w.hide(),S.hide(),T.hide(),F.hide(),Q.hide(),x.val("").change(),N.val("").change(),A.val("").change(),D.val("").change(),j.val("").change(),P.val("").change(),B.val("").change(),b.prop("disabled",!1),k.prop("disabled",!1),b.prop("checked",!1).change().keyup(),k.prop("checked",!1).change().keyup(),x.prop("readonly",!1),N.prop("readonly",!1),A.prop("readonly",!1),D.prop("readonly",!1),j.prop("readonly",!1),P.prop("readonly",!1),B.prop("readonly",!1);else if(void 0!=i.businessEntity){console.log(i.businessEntity);var a=i.businessEntity.entityType.entityTypeCode,s=i.businessEntity.entityType.entityDescription,o=i.businessEntity.entityStatus.entityStatusCode,n=i.businessEntity.mainBusinessPhysicalAddress.postcode,l=i.businessEntity.mainBusinessPhysicalAddress.stateCode,d=i.businessEntity.entityStatus.effectiveFrom,_=new Date(d),p=("0"+_.getDate()).slice(-2),g=("0"+(_.getMonth()+1)).slice(-2),c=_.getFullYear();if(P.hasClass("dmy"))var f=p+"/"+g+"/"+c;else if(P.hasClass("dmy_dash"))var f=p+"-"+g+"-"+c;else if(P.hasClass("dmy_dot"))var f=p+"."+g+"."+c;else if(P.hasClass("ymd_slash"))var f=c+"/"+g+"/"+_;else if(P.hasClass("ymd_dash"))var f=c+"-"+g+"-"+_;else if(P.hasClass("ymd_dot"))var f=c+"."+g+"."+_;else var f=g+"/"+p+"/"+c;if(void 0!=i.businessEntity.goodsAndServicesTax){var u=i.businessEntity.goodsAndServicesTax.effectiveFrom,_=new Date(u),p=("0"+_.getDate()).slice(-2),g=("0"+(_.getMonth()+1)).slice(-2),c=_.getFullYear();if(P.hasClass("dmy"))var O=p+"/"+g+"/"+c;else if(B.hasClass("dmy_dash"))var O=p+"-"+g+"-"+c;else if(B.hasClass("dmy_dot"))var O=p+"."+g+"."+c;else if(B.hasClass("ymd_slash"))var O=c+"/"+g+"/"+_;else if(B.hasClass("ymd_dash"))var O=c+"-"+g+"-"+_;else if(B.hasClass("ymd_dot"))var O=c+"."+g+"."+_;else var O=g+"/"+p+"/"+c;B.val(O).change(),B.prop("readonly",!0),Q.show()}else Q.hide(),B.val("").change();if("IND"==a)var G="string"==typeof i.businessEntity.legalName.familyName?i.businessEntity.legalName.familyName:"",L="string"==typeof i.businessEntity.legalName.givenName?i.businessEntity.legalName.givenName:"",M="string"==typeof i.businessEntity.legalName.otherGivenName?i.businessEntity.legalName.otherGivenName:"",Y=G+", "+L+" "+M;else var Y=i.businessEntity.mainName.organisationName;h.hide(),v.text(o+" - "+Y),x.val(s).change(),x.prop("readonly",!0),N.val(o).change(),N.prop("readonly",!0),A.val(Y).change(),A.prop("readonly",!0),D.val(n).change(),D.prop("readonly",!0),j.val(l).change(),j.prop("readonly",!0),P.val(f).change(),P.prop("readonly",!0),v.removeClass("error loading validation_message"),v.addClass(o),void 0!=i.businessEntity.goodsAndServicesTax&&"0001-01-01"==i.businessEntity.goodsAndServicesTax.effectiveTo?(b.prop("checked",!0).click().change().keyup(),b.prop("disabled",!1),k.prop("disabled",!0)):(k.prop("checked",!0).click().change().keyup(),k.prop("disabled",!1),b.prop("disabled",!0)),m.show(),C.show(),w.show(),E.show(),S.show(),T.show(),F.show()}}catch(q){console.log(e),v.text(q),v.removeClass("loading Active Cancelled"),v.addClass("error validation_message")}},error:function(e,a,s){if("timeout"==a){if(this.tryCount++,this.tryCount<=this.retryLimit)return void i.ajax(this);v.text(n)}else v.text(e.responseText);y.val(r),v.removeClass("loading Active Cancelled"),v.addClass("error validation_message")},timeout:g});return a},f=!1,u=i(".gform_abnlookup_field_"+e+' input[type="text"]'),h=i(".gform_abnlookup_field_"+e+" .gfield_description.validation_message"),v=i(".itsg_abnlookup_response_"+e),y=i(".itsg_abnlookup_checkabn_"+e),m=i(".gform_abnlookup_entity_gst_field_"+e),b=i(".gform_abnlookup_entity_gst_field_"+e+' input[value="'+_+'"]'),k=i(".gform_abnlookup_entity_gst_field_"+e+' input[value="'+p+'"]'),C=i(".gform_abnlookup_entity_type_field_"+e),x=i(".gform_abnlookup_entity_type_field_"+e+" input"),E=i(".gform_abnlookup_entity_status_field_"+e),N=i(".gform_abnlookup_entity_status_field_"+e+" input"),w=i(".gform_abnlookup_entity_name_field_"+e),A=i(".gform_abnlookup_entity_name_field_"+e+" input"),S=i(".gform_abnlookup_entity_postcode_field_"+e),D=i(".gform_abnlookup_entity_postcode_field_"+e+" input"),T=i(".gform_abnlookup_entity_state_field_"+e),j=i(".gform_abnlookup_entity_state_field_"+e+" input"),F=i(".gform_abnlookup_entity_effective_from_field_"+e),P=i(".gform_abnlookup_entity_effective_from_field_"+e+" input"),Q=i(".gform_abnlookup_gst_effective_from_field_"+e),B=i(".gform_abnlookup_gst_effective_from_field_"+e+" input");""!==v.html()?((b.is(":visible")&&1!=b.prop("checked")&&1!=k.prop("checked")||x.is(":visible")&&""==x.val()||N.is(":visible")&&""==N.val()||A.is(":visible")&&""==A.val()||D.is(":visible")&&""==D.val()||j.is(":visible")&&""==j.val()||P.is(":visible")&&""==P.val()||B.is(":visible")&&""==B.val())&&u.trigger("change"),b.is(":checked")?k.prop("disabled",!0):k.is(":checked")&&b.prop("disabled",!0),x.prop("readonly",!0),N.prop("readonly",!0),A.prop("readonly",!0),D.prop("readonly",!0),j.prop("readonly",!0),P.prop("readonly",!0),B.prop("readonly",!0)):(m.closest("li.gfield").hide(),C.closest("li.gfield").hide(),E.closest("li.gfield").hide(),w.closest("li.gfield").hide(),S.closest("li.gfield").hide(),T.closest("li.gfield").hide(),F.closest("li.gfield").hide(),Q.closest("li.gfield").hide()),u.unbind("change").change(function(){var e=i(this).val().replace(/\D/g,"");if(11==e.length){console.log(e);var s=e,o={action:"itsg_gf_abnlookup_check_ajax",abn:s};f&&4!==f.readyState&&(console.log("Abort! -- another request has been submitted."),f.abort()),f=a(o)}else m.hide(),C.hide(),E.hide(),w.hide(),S.hide(),T.hide(),F.hide(),Q.hide(),x.val("").change(),N.val("").change(),A.val("").change(),D.val("").change(),j.val("").change(),P.val("").change(),B.val("").change(),b.prop("disabled",!1),k.prop("disabled",!1),b.prop("checked",!1).change().keyup(),k.prop("checked",!1).change().keyup(),h.hide(),v.html(l),v.addClass("error validation_message"),v.removeClass("loading Active Cancelled")})}(jQuery)}jQuery(document).bind("gform_post_render gform_post_conditional_logic",function(e){var i=gf_abnlookup_settings.abnlookup_fields,a=gf_abnlookup_settings.form_id;for(var s in i)if(i.hasOwnProperty(s)){var o=s,t=i[s].validate,n=i[s].dateFormat;"undefined"!=typeof t&&(console.log("abn-lookup-for-gravity-forms :: field_id: "+o+" field_validate_abnlookup: "+t+" field_dateFormat: "+n),itsg_gf_abnlookup_function(o,t,n),jQuery("#input_"+a+"_"+o).unbind("keydown").keydown(function(e){(13==e.which||13==e.keyCode)&&(e.preventDefault(),jQuery(this).trigger("change"))}))}});