function chargeInvoiceCountry(){$.each(countryHash,function(value,text){$("#ft_nazione").append(setOption(text,value,value==defaultCountry))})}function chargeInvoiceRegion(){$.each(regionHash,function(value,text){$("#ft_provincia").append(setOption(text,value,false))})}function changeType(type){$(".invalid").removeClass("invalid");$(".error").html("");if(type=="p"){$(".ft_p").show();$(".ft_a").hide()}else{$(".ft_p").hide();$(".ft_a").show()}$(".ft").show()} function switchCountryLayoutTo(){if($("#ft_nazione").val()==defaultCountry){$("#no_cf").prop("checked",false).trigger("change");$("#ft_provincia, #ft_citta, #ft_cap").prop("disabled",false);$("#ft_provincia_e, #ft_citta_e, #ft_cap_e").attr("disabled",true);$(".italia").show();$(".estero").hide();$("#ft_piva_label").addClass("RequiredField")}else{$("#ft_provincia, #ft_citta, #ft_cap").attr("disabled",true);$("#ft_provincia_e, #ft_citta_e, #ft_cap_e").prop("disabled",false);$(".estero").show();$(".italia").hide(); $("#ft_piva_label").removeClass("RequiredField")}}function switchCF(){if($("#no_cf").is(":checked")){$("#ft_codfisc").attr("disabled",true);$("#ft_codfisc_e").prop("disabled",false);$(".ft_cf_i").hide();$(".ft_cf_e").show()}else{$("#ft_codfisc_e").attr("disabled",true);$("#ft_codfisc").prop("disabled",false);$(".ft_cf_e").hide();$(".ft_cf_i").show()}}function needNewInvoiceAddress(){return $("#invoiceNeeded").val()==1&&$("#invoiceNewAddress").val()==1} $(document).ready(function(){if(document.characterSet=="UTF-8"){var fattura_str=/^[\u0000-\uFFFF]*$/u;var fattura_str_address=/^[\u0000-\uFFFF]*$/u}else{var fattura_str=/^[\x20\x26\x27\x2C\x2D\x2E\x30-\x7D]*$/u;var fattura_str_address=/^[\x20\x26\x27\x2D\x2C\x2D\x2E\x2F\x30-\x7D]*$/u}chargeInvoiceCountry();chargeInvoiceRegion();if($("#ft_citta").length)fillComuniObj(null,"ft_provincia");$("#ft_nazione").on("change",switchCountryLayoutTo);$("#ft_provincia").on("change",fillComuniObj);$("#ft_citta").on("change", changeComuniCAPObj);$("#no_cf").on("change",switchCF);changeType($("#invoice_type").val());switchCountryLayoutTo();switchCF();$("#invoice_type").on("change",function(){changeType($(this).val())});$("#ft_citta, #ft_citta_e").on("focus",function(){$(this).val($("
").html($(this).val()).text())});$("[data-role='invoice-address-choice']").on("click",function(){$("[data-role='invoice-address-choice']").show();$("[data-role='invoice-address-selected']").hide();$(".cards-list .card-item").removeClass("-selected"); $(this).closest(".card-item").addClass("-selected");$(this).closest(".card-item").find("[data-role='invoice-address-selected']").show();$("#DBInvoiceAddress .event-lg-card").removeClass("bg-success");$(this).closest(".event-lg-card").addClass("bg-success");$(this).closest(".event-lg-card").find("[data-role='invoice-address-selected']").show();$(this).hide();$("#invoiceAddressId").val($(this).data("value"));if($("#formBasket").length>0)$("#formBasket").valid();else if($("#form_pd_privacy").length> 0)$("#form_pd_privacy").valid();$(".invoiceAlert").hide()});$("#InvoiceBlockTrigger").on("click",function(){if($("#InvoiceBlock").hasClass("is-open"))$("#InvoiceBlock").removeClass("is-open");else $("#InvoiceBlock").addClass("is-open")});$("#freeInvoiceAddressTrigger, #DBInvoiceAddressTrigger").on("click",function(){$(".cards-list .card-item").removeClass("-selected");$("[data-role='invoice-address-choice']").show();$("[data-role='invoice-address-selected']").hide();$("#DBInvoiceAddress .event-lg-card").removeClass("bg-success"); if($(this).attr("id")=="freeInvoiceAddressTrigger"){clickit="freeInvoiceAddress";other="DBInvoiceAddress"}else{clickit="DBInvoiceAddress";other="freeInvoiceAddress"}$("#invoiceAddressId").val("");btnTclick="ui-state-active";btnTother="ui-state-default";if(vivaversion==2){btnTclick="";btnTother="-outline"}$("#"+clickit+"Trigger").removeClass(btnTother).addClass(btnTclick);$("#"+clickit).show();$("#"+other+"Trigger").addClass(btnTother).removeClass(btnTclick);$("#"+other).hide();$("#invoiceNewAddress").val($("#freeInvoiceAddress").is(":visible")? 1:0);if($("#DBInvoiceAddress").is(":visible")){var heights=$("#DBInvoiceAddress .event-lg-card").map(function(){return $(this).height()}).get();maxHeight=Math.max.apply(null,heights);$("#DBInvoiceAddress .event-lg-card .thumbnail").css("height",maxHeight)}$(".invoiceAlert").show()});if(vivaversion==1)var sign="";else var sign='';$("#invoiceAddressId").rules("add",{required:function(){return $("#invoiceNeeded").val()==1&&$("#invoiceNewAddress").val()== 0},messages:{required:sign+frasi.carrello["selectInvoiceAddress"]}});$("#invoice_type").rules("add",{required:function(){return needNewInvoiceAddress()}});$("#ft_ragsoc").rules("add",{required:function(){return needNewInvoiceAddress()&&($("#invoice_type_a").is(":checked")||$("#invoice_type").val()=="a"||$("#invoice_type").val()=="pa")},rangelength:[2,25],pattern:fattura_str});$("#ft_nome").rules("add",{required:function(){return needNewInvoiceAddress()&&$("#invoice_type").val()=="p"},rangelength:[2, 25],pattern:fattura_str});$("#ft_cognome").rules("add",{required:function(){return needNewInvoiceAddress()&&($("#invoice_type_pf").is(":checked")||$("#invoice_type").val()=="p")},rangelength:[2,25],pattern:fattura_str});$("#ft_nazione").rules("add",{required:function(){return needNewInvoiceAddress()}});$("#ft_provincia").rules("add",{required:{depends:function(){return needNewInvoiceAddress()&&$("#ft_nazione").val()==defaultCountry}},rangelength:{depends:function(){return needNewInvoiceAddress()&& $("#ft_nazione").val()!=defaultCountry},param:[2,25]},pattern:fattura_str});$("#ft_citta").rules("add",{required:function(){return needNewInvoiceAddress()},rangelength:{depends:function(){return needNewInvoiceAddress()&&$("#ft_nazione").val()!=defaultCountry},param:[2,35]},pattern:{depends:function(){return needNewInvoiceAddress()&&$("#ft_nazione").val()!=defaultCountry},param:fattura_str}});$("#ft_cap").rules("add",{required:function(){return needNewInvoiceAddress()},rangelength:{depends:function(){return needNewInvoiceAddress()&& $("#ft_nazione").val()!=defaultCountry},param:[3,11]},pattern:fattura_str});$("#ft_indirizzo").rules("add",{required:function(){return needNewInvoiceAddress()},rangelength:[2,70],pattern:fattura_str_address});$("#ft_codfisc").rules("add",{required:function(){return needNewInvoiceAddress()},rangelength:{depends:function(){return needNewInvoiceAddress()&&$("#invoice_type").val()=="p"&&$("#no_cf").is(":checked")},param:[2,20]},NOTpattern:{depends:function(){return needNewInvoiceAddress()&&$("#invoice_type").val()== "p"&&$("#no_cf").is(":checked")},param:NOTpattern_strNum},codiceFiscale:{depends:function(){return needNewInvoiceAddress()&&$("#invoice_type").val()=="p"&&!$("#no_cf").is(":checked")},param:{name:"ft_nome",surname:"ft_cognome"}}});$("#ft_piva").rules("add",{required:function(){return needNewInvoiceAddress()},rangelength:{depends:function(){return $("#invoice_type").val()!="p"&&$("#ft_nazione").val()!=defaultCountry},param:[2,20]},NOTpattern:{depends:function(){return $("#invoice_type").val()!="p"&& $("#ft_nazione").val()!=defaultCountry},param:NOTpattern_strNum},partita_iva:{depends:function(){return $("#invoice_type").val()!="p"&&$("#ft_nazione").val()==defaultCountry}}});$("#ft_pec").rules("add",{require_from_group:{depends:function(){return needNewInvoiceAddress()&&($("#invoice_type").val()!="p"&&$("#ft_nazione").val()==defaultCountry)},param:[1,".sdi_pec"]},email:true});$("#ft_sdi").rules("add",{require_from_group:{depends:function(){return needNewInvoiceAddress()&&($("#invoice_type").val()!= "p"&&$("#ft_nazione").val()==defaultCountry)},param:[1,".sdi_pec"]},sdiIT:{depends:function(){return needNewInvoiceAddress()&&$("#ft_nazione").val()==defaultCountry},param:$("#invoice_type")},pattern:fattura_str})}); function showErrorInvoice(errorList){var invoiceError=false;$.each(errorList,function(index,value){if($(value.element).hasClass("-invoiceField"))invoiceError=true});if(invoiceError&&checkbasket){$("#cartInvoicePanel .basket-panel").addClass("-error");$("#cartInvoicePanel .basket-panel #InvoiceBlockTrigger .-error").show();$("#InvoiceBlock").addClass("panel-danger");$(".invoiceAlert").show()}else{$("#cartInvoicePanel .basket-panel").removeClass("-error");$("#cartInvoicePanel .basket-panel #InvoiceBlockTrigger .-error").hide(); $("#InvoiceBlock").removeClass("panel-danger");$(".invoiceAlert").hide()}};