let container=document.querySelector("#RA-enter"),registerFormContainer=document.createElement("div"),reCaptchaToken;if(container)start();else for(let e=0;e<2;e++)setTimeout(()=>{(container=document.querySelector("#RA-enter"))&&start()},300);function start(){var e=Math.floor(20*Math.random()),a=Math.floor(20*Math.random());let p=e+a,c=container.attachShadow({mode:"open"}),d=(c.innerHTML=`
`,c.querySelector("#RA-form")),u=c.querySelector("#RA-thankyou-message"),A=c.querySelector("#RA-checkIfRobot");e=c.querySelector("#RA-form-submit");let t=c.querySelector("#RA-section-1"),l=c.querySelector("#RA-section-2"),r=c.querySelector("#RA-section-3");var a=c.querySelector("#RA-section-next-1"),i=c.querySelector("#RA-section-next-2"),o=c.querySelector("#RA-section-back-2"),s=c.querySelector("#RA-section-back-3"),n=[...t.children];let f=n.find(e=>"RA-select-country"===e.id),R=n.find(e=>"RA-select-country-other"===e.id),b=n.find(e=>"RA-label-country-other"===e.id),m=n.find(e=>"RA-label-state"===e.id),h=n.find(e=>"RA-select-state"===e.id),v=n.find(e=>"RA-label-region"===e.id),y=n.find(e=>"RA-input-region"===e.id),g=n.find(e=>"RA-label-zipcode"===e.id);R.className="RA-none",b.className="RA-none",y.className="RA-none",v.className="RA-none";var n=e=>{"other"===e.target.value?(R.className="RA-input",R.required="1",b.className="RA-label"):(R.className="RA-none",b.className="RA-none",R.required=""),"US"!==e.target.value?(m.className="RA-none",h.className="RA-none",h.required="",y.className="RA-input",y.required="1",v.className="RA-label"):(m.className="RA-label",h.className="RA-select",h.required="1",y.className="RA-none",y.required="",v.className="RA-none"),"AU"===e.target.value?g.innerText="Postcode: *":g.innerText="Zipcode: *"},x=new Event("onCountrySelectorLoad");f.addEventListener("change",n),f.addEventListener("onCountrySelectorLoad",n),f.dispatchEvent(x),c.querySelector("#RA-popup-close").addEventListener("click",()=>{c.querySelector("#RA-popup").style.display="none"}),a.addEventListener("click",e=>{let a=0;e.preventDefault(),[...c.querySelector("#RA-section-1").querySelectorAll("input, select")].map(e=>{e.required&&!e.value.trim()?(e.className="RA-input RA-error",a++):e.required&&e.value&&(e.className="RA-input")}),a||(t.className="RA-none",l.className="RA-section")}),i.addEventListener("click",async e=>{let a=0,t=0;e.preventDefault();var e=[...c.querySelector("#RA-section-2").querySelectorAll("input")],[i,o]=(e.map(e=>{e.required&&!e.value.trim()?(e.className="RA-input RA-error",a++):e.className="RA-input","password"!==e.type||8<=e.value.length&&e.value.length<=16||(e.className="RA-input RA-error",t++),"email"!==e.type||e.value.match(/^[^ ]+@[^ ]+\.[a-z]{2,10}$/)||(t++,e.className="RA-input RA-error",alert("Invalid email"))}),c.querySelectorAll('input[type="password"]'));if((i.value.length<8||16"email"===e.type),o=i?i.value:null;try{var s=await fetch("https://dev-signup.cbdaffs.com/check-unique-affiliate?email="+encodeURIComponent(o),{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json()),n=c.querySelector("#RA-popup");s.data?(n.style.display="none",l.className="RA-none",r.className="RA-section"):0{e.preventDefault(),t.className="RA-section",l.className="RA-none"}),s.addEventListener("click",e=>{e.preventDefault(),l.className="RA-section",r.className="RA-none"}),e.addEventListener("click",async e=>{e.preventDefault();e=e.target;let a=0,i={},o={},s={};var n=[...c.querySelector("#RA-section-1").querySelectorAll("input, select")],t=[...c.querySelector("#RA-section-2").querySelectorAll("input")],l=[...c.querySelector("#RA-section-3").querySelectorAll("input, select, textarea")];if(u.className="RA-none",n.map(e=>{i[e.name]=e.value.trim(),R.value&&R.required?i["Affiliate data[country]"]=R.value:i["Affiliate data[country]"]=f.value,y.value&&y.required?i["Affiliate data[region]"]=y.value:i["Affiliate data[region]"]=h.value}),t.map(e=>{o[e.name]=e.value.trim(),e.required&&!e.value.trim()?(e.className="RA-input RA-error","TEXTAREA"===e.tagName&&(e.className="RA-textarea RA-error"),a++):e.className="RA-input"}),l.map(e=>{s[e.name]=e.value.trim(),"checkbox"===e.type&&(e.value=e.checked?1:"",s[e.name]=!!e.checked,e.checked||alert('Agree with "Terms and Conditions" and rules')),e.required&&!e.value.trim()?("checkbox"!==e.type&&(e.className="RA-input RA-error"),"TEXTAREA"===e.tagName&&(e.className="RA-textarea RA-error"),a++):"TEXTAREA"===e.tagName?e.className="RA-textarea":"checkbox"!==e.type&&(e.className="RA-input")}),!a)if(A&&+p!=+A.value.trim())A.className="RA-input RA-error";else{e.innerText="Loading...";let t="";document.cookie.split(" ").forEach(e=>{var a=e.split("=");"gclid"!==a[0]&&"keyword"!==a[0]&&"adgr"!==a[0]&&"ref_ID"!==a[0]&&"ReferralURL"!==a[0]&&"camp"!==a[0]&&"partner_id"!==a[0]||(t+=e+" ")});n={"QuestionAnswer data[answer] 66":t};try{var r=await fetch("https://dev-signup.cbdaffs.com/register-affiliate",{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({...i,...o,...s,reCaptchaToken:reCaptchaToken,referralId:"",...n})});403===r.status||400===r.status||404===r.status?(alert(await r.json()),e.innerText="Something went wrong"):200===r.status&&(u.className="RA-section RA-center",d.className="RA-none",setTimeout(()=>{window.location.href="https://CBDAffs.com"},1e4))}catch(e){alert("Error, try again")}}})}