(function(){var f=document.getElementById('cr-form');if(!f)return;var m=document.getElementById('cr-msg'); var E=f.elements,k=E['kind'],box=document.getElementById('cr-tech'); function sync(){var on=k&&k.value==='tech';if(box)box.hidden=!on;if(E['github'])E['github'].required=on;if(E['homepage'])E['homepage'].required=on;} if(k){k.addEventListener('change',sync);sync();} function url(v){v=(v||'').trim();if(v&&!/^https?:\/\//i.test(v))v='https://'+v;return v;} f.addEventListener('submit',function(e){e.preventDefault(); var n=(E['name'].value||'').trim(),em=(E['email'].value||'').trim(),t=E['request'].value.trim(),kind=k?k.value:'',gh='',hp=''; if(!n){m.textContent='Please add your name.';return;} if(!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(em)){m.textContent='Please add a valid email.';return;} if(k&&!kind){m.textContent='Please choose what kind of work.';return;} if(kind==='tech'){gh=url(E['github'].value);hp=url(E['homepage'].value); if(!/^https:\/\/(www\.)?(github\.com|branchwell\.ai)\/[A-Za-z0-9_.-]+/i.test(gh.replace(/^http:/i,'https:'))){m.textContent='Tech roles need your Branchwell profile link.';return;} if(!/^https?:\/\/[^\s\/]+\.[^\s\/]{2,}/i.test(hp)||/^https?:\/\/(www\.)?(github\.com|branchwell\.ai)(\/|$)/i.test(hp)){m.textContent='Tech roles need a link to your own website too.';return;}} if(!t){m.textContent='Please write a short message.';return;} var head='Name: '+n+'\nEmail: '+em+(kind?'\nKind of work: '+(kind==='tech'?'Tech':'Everything else'):'')+(gh?'\nBranchwell: '+gh:'')+(hp?'\nWebsite: '+hp:''); var b=f.querySelector('button');b.disabled=true;m.textContent='Sending…'; fetch('/api/request',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({request:head+'\n\n'+t,name:n,email:em,message:t,kind:kind,github:gh,homepage:hp,site:location.hostname,website:E['website'].value})}) .then(function(r){if(!r.ok)throw 0;f.reset();sync();m.textContent='Thanks. We got your note and will be in touch about joining our team.';}) .catch(function(){m.textContent='That didn’t go through. Please try again in a minute.';}) .then(function(){b.disabled=false;});});})();