var namesList=[],storedFiles=[],filesCount=0;function a(e){return Date.parse(e)}e=/^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i;if($("#attach-files-button").length){$("#order_attachments").change(function(event){if(event.target.files){let files=Array.prototype.slice.call(event.target.files);files.forEach(function(file){if(!namesList.includes(file.name)){storedFiles.push(file);namesList.push(file.name)}});let html="";for(let i=0;i`;html+=``;html+=`${fileName}`;html+=``;html+=""}$("#selected-files").html(html);let fileCountText=storedFiles.length===1?" File Selected":" Files Selected";$("#selected-files-count").html(storedFiles.length+fileCountText)}});$(document.body).on("click","#attach-files-button",function(event){event.preventDefault();$("#order_attachments").trigger("click")});$(document.body).on("click",".remove-appended-file",function(event){event.preventDefault();let fileName=$(this).data("file");namesList=namesList.filter(name=>name!==fileName);storedFiles=storedFiles.filter(file=>file.name!==fileName);$(this).parent().remove();let fileCountText=storedFiles.length===1?" File Selected":" Files Selected";$("#selected-files-count").html(storedFiles.length+fileCountText)})}$(document.body).on("click","#submit-order-button",function(event){event.preventDefault();let hasError=false;let numberPattern=/^[0-9]+$/;$(".order-form-input").each(function(index,element){if($(element).data("rule")!==undefined){let value=$(element).val().trim();let fieldName=$(element).data("field-name");console.log($(element));let message=$(element).data("msg");let id=$(element).prop("id");$(element).data("rule").split("|").forEach(function(rule){let ruleParts=rule.split(":");let ruleValue=ruleParts.length==2?ruleParts[1]:"";rule=ruleParts[0];if(rule==="number"&&!value.match(numberPattern)){showError(element,fieldName+" must be numbers");hasError=true}else if(rule==="starts"&&parseInt(value)ruleValue){showError(element,fieldName+" must be less than "+ruleValue+" "+message.toLowerCase());hasError=true}else if(rule==="with"&&(!value||parseInt(value)<=0)&&(!$("#"+ruleValue).val().trim()||parseInt($("#"+ruleValue).val().trim())<=0)){showError(element,$(element).data("mixedname")+" is required");$("#"+ruleValue).addClass("is-invalid");hasError=true}else if(rule==="minlen"&&value.lengthruleValue){showError(element,fieldName+" must be less than "+ruleValue+" characters");hasError=true}else if(rule==="email"&&!e.test(value)){showError(element,fieldName+" must be in a valid email format");hasError=true}else if(rule==="date"&&isNaN(a(value))){showError(element,fieldName+" must be in a valid date format");hasError=true}else if(rule==="mindate"&&a(value)a(ruleValue)){showError(element,fieldName+" must be less than "+ruleValue);hasError=true}})}});if(!hasError){$("#submit-order-button").html(" Submitting Order");$("#submit-order-button").prop("disabled",true);let behaviour=$("#submit-order-form").data("behaviour");if(document.getElementById("order_attachments")!=null){let files=getFiles(storedFiles);document.getElementById("order_attachments").files=files}$("#submit-order-form").submit()}});$(document.body).on("keyup change",".order-form-input",function(event){let inputType=$(this).prop("type");let inputValue=$(this).val().trim();let isMixedRole=$(this).hasClass("mixed-role");let mixedRuleName=$(this).data("mixedrulename");let feedbackId=$(this).data("feedback");if(inputValue&&isMixedRole&&$("#"+mixedRuleName).val().trim()){$("#"+feedbackId).hide()}if(["text","email","date"].includes(inputType)&&inputValue){$(this).removeClass("is-invalid")}});function showError(element,message){if($(element).hasClass("mixed-role")){$("#"+$(element).data("feedback")).html(message);$(element).addClass("is-invalid");$("#"+$(element).data("feedback")).show()}else{$("#"+$(element).prop("id")+"-feedback").html(message);$(element).addClass("is-invalid")}}function getFiles(storedFiles){let dataTransfer=new ClipboardEvent("").clipboardData||new DataTransfer();for(let i=0;i