document.addEventListener("DOMContentLoaded", () => { showPopup(); }) function toggleNav(){ document.getElementById("header_nav").classList.toggle('active'); const icon = document.getElementById('nav_icon'); if(icon.classList.contains('fa-bars')){ icon.className = "fa-solid fa-xmark"; } else { icon.className = "fa-solid fa-bars"; } } function getAddress(){ let sameAddress = document.getElementById("same_comm_address"); let commField = ['house', 'street', 'locality', 'city', 'state', 'pincode']; let perm_Field = ['perm_house', 'perm_street', 'perm_locality', 'perm_city', 'perm_state', 'perm_pincode']; if (sameAddress.checked){ let i = 0; perm_Field.forEach(field => { document.getElementById(field).value = document.getElementById(commField[i]).value; i++; }); } else { perm_Field.forEach(field => { document.getElementById(field).value = ""; }); } } function showPopup(){ setTimeout(() => { document.getElementById('popUp_div').style.display = "flex"; }, 3000) } function callPopup(){ document.getElementById('popUp_div').style.display = "flex"; } function closePopup(){ document.getElementById('popUp_div').style.display = "none"; } function redirect(){ let count = document.getElementById("count-down"); let timeLeft = 3; let countDown = setInterval(() => { if(timeLeft > 0){ count.innerText = "You Will Redirect in : " + timeLeft; timeLeft--; } else { clearInterval(countDown); window.location.href = "index.html"; } }, 1000); } // ── Toast utility ──────────────────────────────────────────────────────────── (function () { const toastEl = document.createElement('div'); toastEl.id = 'toast'; toastEl.innerHTML = ''; document.body.appendChild(toastEl); })(); let _toastTimer; function showToast(msg, type) { const el = document.getElementById('toast'); const icon = document.getElementById('toast-icon'); const text = document.getElementById('toast-msg'); el.className = type === 'success' ? 'toast-success' : 'toast-error'; icon.className = type === 'success' ? 'fa-solid fa-circle-check' : 'fa-solid fa-circle-exclamation'; text.textContent = msg; clearTimeout(_toastTimer); setTimeout(() => el.classList.add('toast-show'), 10); _toastTimer = setTimeout(hideToast, 5000); } function hideToast() { const el = document.getElementById('toast'); el.classList.remove('toast-show'); } // ── AJAX form submit (shared) ───────────────────────────────────────────────── function submitEnquiry(form, onSuccess) { const btn = $(form).find('button[type="submit"]'); btn.addClass('btn-loading').prop('disabled', true); $.ajax({ url: $(form).attr('action'), type: 'POST', data: $(form).serialize(), dataType: 'json', success: function (res) { if (res.success) { onSuccess(); } else { showToast(res.message || 'Something went wrong. Please try again.', 'error'); btn.removeClass('btn-loading').prop('disabled', false); } }, error: function () { showToast('Network error. Please check your connection and try again.', 'error'); btn.removeClass('btn-loading').prop('disabled', false); } }); } // ── Popup contact form ──────────────────────────────────────────────────────── $(document).ready(function () { $('#popUp_form').on('submit', function (e) { e.preventDefault(); submitEnquiry(this, function () { window.location.href = 'thank_you.php'; }); }); }); //Enquiry Form Validation $(document).ready(function(){ $("#enquiryForm").validate({ rules:{ mobile:{maxlength: 14, minlength: 10}, }, messages:{ mobile:{maxlength: "Max Length Void", minlength: "Min Length Void"} }, submitHandler: function(form){ submitEnquiry(form, function () { window.location.href = 'thank_you.php'; }); } }); }); //Register Form Validation $(document).ready(function(){ $("#regForm").validate({ rules:{ pincode:{maxlength: 6, minlength: 6}, mobile:{maxlength: 14, minlength: 10}, telephone:{maxlength: 14, minlength: 10}, }, messages:{ pincode:{maxlength: "Not a Valid Pincode", minlength: "Not a Valid Pincode"}, mobile:{maxlength: "Enter a Valid Number", minlength: "Enter a Valid Number"}, telephone:{maxlength: "Enter a Valid Number", minlength: "Enter a Valid Number"} }, submitHandler: function(form){ form.submit(); } }); }); //KYC Form Validation //defaune custom validation for newspaper-name $.validator.addMethod("news_validName", function(value, element){ return this.optional(element) || /^[A-Za-z0-9]/.test(value.trim()); }, "Please Enter a Valid Name"); $(document).ready(function(){ $("#kyc_form").validate({ rules:{ newspaper_name:{required: true, minlength: 2, news_validName: true}, employer_name:{required: true, minlength: 2, news_validName: true}, father_on_aadhar:{required: true, minlength: 2, news_validName: true}, aadhar_number:{minlength: 12, maxlength: 12}, }, messages:{ newspaper_name:{minlength: "At least 2 characters required", news_validName: "Only spaces or special characters are not allowed"}, employer_name:{minlength: "At least 2 characters required", news_validName: "Only spaces or special characters are not allowed"}, father_on_aadhar:{minlength: "At least 2 characters required", news_validName: "Only spaces or special characters are not allowed"}, }, submitHandler: function(form){ form.submit(); } }); });