"),r=$(' ").append(n[t].Name)).append($("
").append(n[t].Address)).append($(" ").append(n[t].Contact)).append($(" ").append(i)).append($(" ").append(r))))}function i(n,t,r){var u=[];for(var f in n)n.hasOwnProperty(f)&&(typeof n[f]=="object"?u=u.concat(i(n[f],t,r)):f==t&&n[t]==r&&u.push(n));return u}function s(n){var t,i,r;$("#TblBodyOwners").empty();for(t in n)console.log(n[t].OwnerId),n[t].OwnerId!=undefined&&(i=$('<\/i> <\/button>'),r=$(' <\/i> <\/button>'),$("#TblBodyOwners").append($("").append($("").append(n[t].OwnerFullName)).append($(" ").append(n[t].OwnerDateOfBirth)).append($(" ").append(n[t].OwnerFullAddress)).append($(" ").append(n[t].OwnerPostCode)).append($(" ").append(n[t].OwnerDriversLicenceNo)).append($(" ").append(n[t].OwnerPhoneNo)).append($(" ").append(n[t].OwnerMobileNo)).append($(" ").append(i).append(r))))}function c(){$("#CorporateCustomerCompanyOwners_FullName").val("");$("#CorporateCustomerCompanyOwners_DateOfBirth").val("");$("#CorporateCustomerCompanyOwners_PrivateAddress").val("");$("#CorporateCustomerCompanyOwners_Postcode").val("");$("#CorporateCustomerCompanyOwners_DriversLicenceNo").val("");$("#CorporateCustomerCompanyOwners_PhoneNo").val("");$("#CorporateCustomerCompanyOwners_MobileNo").val("")}var n,r,u,t,f,e;$("#register-button").on("click",function(){var n=$("#TblBodyreference > tbody > tr, #TblBodyreference > tr").is(":empty");return $("#accept-consent").is(":checked")&n==!1?!0:(n==!0?alert("At least one reference is required."):alert("Please accept privacy policy"),!1)});$("#reference-popup-show").on("click",function(){h();$("#ReferencesModal").show();$(this).hide()});$("#reference-popup-close").on("click",function(){$("#ReferencesModal").hide();$("#reference-popup-show").show()});Array.prototype.sortBy=function(n){return this.slice(0).sort(function(t,i){return t[n]>i[n]?1:t[n]0?(n=JSON.parse($("#CorporateCustomer_CorporateReferences").val()),r=[],u=1,n.forEach(function(n){var t={ReferenceId:u,Name:n.Name,Address:n.Address,Contact:n.PhoneFaxEmail};r.push(t);u=u+1}),o(r),n=r):n=[];$("#SaveReferences").on("click",function(){var r,u,t,f;$("#frmReferences").valid()&&(parseInt($("#frmReferenceId").val())>0&&(r=i(n,"ReferenceId",$("#frmReferenceId").val()),u=n.indexOf(r[0]),n.splice(u,1),$("#frmReferenceId").val(0)),t=1,n.length>0&&(t=n.length+1),f={ReferenceId:t,Name:$("#CorporateCustomerTradeReferences_Name").val(),Contact:$("#CorporateCustomerTradeReferences_PhoneFaxEmail").val(),Address:$("#CorporateCustomerTradeReferences_Address").val()},n.push(f),o(n),console.log(n),h())});$("#Owners-popup-show").on("click",function(){c();$("#OwnersModal").show();$(this).hide()});$(document).on("click","#Edit-Reference",function(){var t=i(n,"ReferenceId",$(this).attr("data-referenceId"));$("#ReferencesModal").show();$("#CorporateCustomerTradeReferences_Name").val(t[0].Name);$("#CorporateCustomerTradeReferences_PhoneFaxEmail").val(t[0].Contact);$("#CorporateCustomerTradeReferences_Address").val(t[0].Address);$("#frmReferenceId").val($(this).attr("data-referenceId"))});$(document).on("click","#Delete-Reference",function(){if(confirm("Are you sure do you want to delete the Reference?")){var t=i(n,"ReferenceId",$(this).attr("data-referenceId")),r=n.indexOf(t[0]);n.splice(r,1);o(n)}return!1});$("#owners-popup-close").on("click",function(){$("#OwnersModal").hide();$("#Owners-popup-show").show()});t=[];$(".validation-summary-errors").length>0?(t=JSON.parse($("#CorporateCustomer_CorporateOwners").val()),f=[],e=1,t.forEach(function(n){var t={OwnerId:e,OwnerFullName:n.FullName,OwnerDateOfBirth:n.DateOfBirth,OwnerFullAddress:n.PrivateAddress,OwnerPostCode:n.Postcode,OwnerDriversLicenceNo:n.DriversLicenceNo,OwnerPhoneNo:n.PhoneNo,OwnerMobileNo:n.MobileNo};f.push(t);e=e+1}),s(f),t=f):t=[];$("#SaveOwners").on("click",function(){var r,u,n,f;$("#frmSaveOwners").valid()&&(parseInt($("#frmOwnerId").val())>0&&(r=i(t,"OwnerId",$("#frmOwnerId").val()),u=t.indexOf(r[0]),t.splice(u,1),$("#frmOwnerId").val(0)),n=1,t.length>0&&(n=t.length+1),f={OwnerId:n,OwnerFullName:$("#CorporateCustomerCompanyOwners_FullName").val(),OwnerDateOfBirth:$("#CorporateCustomerCompanyOwners_DateOfBirth").val(),OwnerFullAddress:$("#CorporateCustomerCompanyOwners_PrivateAddress").val(),OwnerPostCode:$("#CorporateCustomerCompanyOwners_Postcode").val(),OwnerDriversLicenceNo:$("#CorporateCustomerCompanyOwners_DriversLicenceNo").val(),OwnerPhoneNo:$("#CorporateCustomerCompanyOwners_PhoneNo").val(),OwnerMobileNo:$("#CorporateCustomerCompanyOwners_MobileNo").val()},t.push(f),s(t),c())});$(document).on("click","#Edit-Owner",function(){var n=i(t,"OwnerId",$(this).attr("data-OwnerId"));$("#OwnersModal").show();$("#CorporateCustomerCompanyOwners_FullName").val(n[0].OwnerFullName);$("#CorporateCustomerCompanyOwners_DateOfBirth").val(n[0].OwnerDateOfBirth);$("#CorporateCustomerCompanyOwners_PrivateAddress").val(n[0].OwnerFullAddress);$("#CorporateCustomerCompanyOwners_Postcode").val(n[0].OwnerPostCode);$("#CorporateCustomerCompanyOwners_DriversLicenceNo").val(n[0].OwnerDriversLicenceNo);$("#CorporateCustomerCompanyOwners_PhoneNo").val(n[0].OwnerPhoneNo);$("#CorporateCustomerCompanyOwners_MobileNo").val(n[0].OwnerMobileNo);$("#frmOwnerId").val($(this).attr("data-OwnerId"))});$(document).on("click","#Delete-Owner",function(){if(confirm("Are you sure do you want to delete the Owner?")){var n=i(t,"OwnerId",$(this).attr("data-OwnerId")),r=t.indexOf(n[0]);t.splice(r,1);s(t)}return!1});$("#frmCorporateCustomer").submit(function(){var r=[],i;return n.forEach(function(n){var t={CorporateCustomer_Id:0,Name:n.Name,Address:n.Address,PhoneFaxEmail:n.Contact};r.push(t)}),i=[],t.forEach(function(n){var t={CorporateCustomer_Id:0,FullName:n.OwnerFullName,DateOfBirth:n.OwnerDateOfBirth,PrivateAddress:n.OwnerFullAddress,Postcode:n.OwnerPostCode,DriversLicenceNo:n.OwnerDriversLicenceNo,PhoneNo:n.OwnerPhoneNo,MobileNo:n.OwnerMobileNo};i.push(t)}),$("#CorporateCustomer_CorporateOwners").val(JSON.stringify(i)),$("#CorporateCustomer_CorporateReferences").val(JSON.stringify(r)),console.log(i),console.log(r),$.ajax({url:"/Customer/CorporateCustomerRegistration",type:"POST",contentType:"application/json;",dataType:"json",data:{model:JSON.parse($("#frmCorporateCustomer").serialize())},success:function(){alert("success")},error:function(){alert("Something went wrong.")}}),!1})})