.elementor-kit-16{--e-global-color-primary:#6EC1E4;--e-global-color-secondary:#54595F;--e-global-color-text:#7A7A7A;--e-global-color-accent:#61CE70;--e-global-typography-primary-font-family:"Roboto";--e-global-typography-primary-font-weight:600;--e-global-typography-secondary-font-family:"Roboto Slab";--e-global-typography-secondary-font-weight:400;--e-global-typography-text-font-family:"Roboto";--e-global-typography-text-font-weight:400;--e-global-typography-accent-font-family:"Roboto";--e-global-typography-accent-font-weight:500;}.elementor-kit-16 e-page-transition{background-color:#FFBC7D;}.elementor-section.elementor-section-boxed > .elementor-container{max-width:1140px;}.e-con{--container-max-width:1140px;}.elementor-widget:not(:last-child){--kit-widget-spacing:20px;}.elementor-element{--widgets-spacing:20px 20px;--widgets-spacing-row:20px;--widgets-spacing-column:20px;}{}h1.entry-title{display:var(--page-title-display);}.site-header .site-branding{flex-direction:column;align-items:stretch;}.site-header{padding-inline-end:0px;padding-inline-start:0px;}.site-footer .site-branding{flex-direction:column;align-items:stretch;}@media(max-width:1024px){.elementor-section.elementor-section-boxed > .elementor-container{max-width:1024px;}.e-con{--container-max-width:1024px;}}@media(max-width:767px){.elementor-section.elementor-section-boxed > .elementor-container{max-width:767px;}.e-con{--container-max-width:767px;}}/* Start custom CSS */<!-- 
    העתק את כל הקוד הזה ל-Elementor Custom Code widget
    או HTML widget ב-Elementor
-->

<script>
(function() {
    'use strict';
    
    console.log('🚀 Elementor Serial Auto-Fill - Inline Code Started');
    
    // Get serial from URL - try query parameter first, then hash
    function getSerial() {
        // Try ?serial=123456
        const urlParams = new URLSearchParams(window.location.search);
        let serial = urlParams.get('serial');
        if (serial) {
            console.log('✅ Found serial from query parameter:', serial);
            return decodeURIComponent(serial);
        }
        
        // Try #serial=123456
        const hash = window.location.hash;
        if (hash) {
            const match = hash.match(/[#&]serial=([^&]*)/);
            if (match) {
                serial = decodeURIComponent(match[1]);
                console.log('✅ Found serial from hash:', serial);
                return serial;
            }
        }
        
        console.log('❌ No serial found in URL');
        return null;
    }
    
    const serial = getSerial();
    if (!serial) {
        return; // No serial to fill
    }
    
    console.log('🔢 Serial to fill:', serial);
    
    let filled = false;
    let attempts = 0;
    const maxAttempts = 100; // More attempts
    
    function tryFill() {
        if (filled) return;
        
        attempts++;
        if (attempts % 10 === 0) {
            console.log(`🔄 Attempt ${attempts}/${maxAttempts} - Looking for field_065db90...`);
        }
        
        // Method 1: Direct ID lookup
        let input = document.getElementById('field_065db90');
        
        // Method 2: Try jQuery if available
        if (!input && typeof jQuery !== 'undefined') {
            const $input = jQuery('#field_065db90');
            if ($input.length > 0) {
                input = $input[0];
                console.log('✅ Found via jQuery');
            }
        }
        
        // Method 3: Try querySelector
        if (!input) {
            input = document.querySelector('#field_065db90');
        }
        
        // Method 4: Try all inputs and check ID
        if (!input) {
            const allInputs = document.querySelectorAll('input[type="text"], input[type="number"]');
            for (let inp of allInputs) {
                if (inp.id === 'field_065db90' || inp.id.includes('field_065db90')) {
                    input = inp;
                    console.log('✅ Found by checking all inputs, ID:', inp.id);
                    break;
                }
            }
        }
        
        // Method 5: Try by label text
        if (!input) {
            const labels = document.querySelectorAll('label');
            for (let label of labels) {
                const text = (label.textContent || label.innerText || '').trim();
                if (text.includes('מספר סריאלי') || text.includes('סריאלי')) {
                    // Try 'for' attribute
                    const forId = label.getAttribute('for');
                    if (forId) {
                        input = document.getElementById(forId);
                        if (input) {
                            console.log('✅ Found by label for:', forId);
                            break;
                        }
                    }
                    // Try to find input in parent
                    let parent = label.parentElement;
                    for (let i = 0; i < 10 && parent; i++) {
                        input = parent.querySelector('input[type="text"], input[type="number"]');
                        if (input) {
                            console.log('✅ Found near label');
                            break;
                        }
                        parent = parent.parentElement;
                    }
                    if (input) break;
                }
            }
        }
        
        if (input) {
            console.log('✅✅✅ FOUND INPUT FIELD! ID:', input.id, 'Name:', input.name, 'Type:', input.type);
            
            // Fill it multiple times to ensure it sticks
            input.value = serial;
            
            // Try jQuery
            if (typeof jQuery !== 'undefined') {
                jQuery(input).val(serial);
                jQuery(input).trigger('input');
                jQuery(input).trigger('change');
                jQuery(input).trigger('keyup');
            }
            
            // Trigger events
            ['input', 'change', 'blur', 'keyup'].forEach(function(eventType) {
                try {
                    const event = new Event(eventType, { bubbles: true, cancelable: true });
                    input.dispatchEvent(event);
                } catch (e) {}
            });
            
            // Force update
            setTimeout(function() {
                input.value = serial;
                if (typeof jQuery !== 'undefined') {
                    jQuery(input).val(serial).trigger('input').trigger('change');
                }
            }, 100);
            
            // Visual feedback
            input.style.backgroundColor = '#e7f3ff';
            input.style.borderColor = '#0d6efd';
            setTimeout(function() {
                input.style.backgroundColor = '';
                input.style.borderColor = '';
            }, 3000);
            
            console.log('✅✅✅ SERIAL FILLED! Value in field:', input.value);
            filled = true;
            return true;
        }
        
        // Continue trying
        if (attempts < maxAttempts) {
            setTimeout(tryFill, 200);
        } else {
            console.error('❌ Could not find field_065db90 after', maxAttempts, 'attempts');
            console.log('💡 Debug: All inputs on page:', document.querySelectorAll('input').length);
            console.log('💡 Debug: All elements with ID containing "field":', 
                Array.from(document.querySelectorAll('[id*="field"]')).map(el => el.id));
        }
        
        return false;
    }
    
    // Start immediately
    tryFill();
    
    // Also try on various events
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', tryFill);
    }
    
    window.addEventListener('load', function() {
        if (!filled) {
            console.log('🌐 Window loaded, trying again...');
            tryFill();
        }
    });
    
    // Wait for jQuery
    if (typeof jQuery === 'undefined') {
        let waitCount = 0;
        const waitJQuery = setInterval(function() {
            waitCount++;
            if (typeof jQuery !== 'undefined') {
                clearInterval(waitJQuery);
                console.log('✅ jQuery loaded');
                if (!filled) tryFill();
            } else if (waitCount > 30) {
                clearInterval(waitJQuery);
            }
        }, 200);
    }
    
    // MutationObserver
    if (typeof MutationObserver !== 'undefined' && document.body) {
        const observer = new MutationObserver(function() {
            if (!filled) {
                tryFill();
            }
        });
        observer.observe(document.body, {
            childList: true,
            subtree: true,
            attributes: true,
            attributeFilter: ['id']
        });
        console.log('👀 MutationObserver started');
    }
    
    // Periodic check
    const periodicCheck = setInterval(function() {
        if (!filled) {
            tryFill();
        } else {
            clearInterval(periodicCheck);
        }
    }, 1000);
    
    // Stop periodic check after 30 seconds
    setTimeout(function() {
        clearInterval(periodicCheck);
    }, 30000);
    
})();
</script>/* End custom CSS */