
jQuery(document).ready(function() {

    jQuery(document).on('keyup', '#_elex_fpf_gtin',function(){

        var gtin_valid = isValidGtinProd( this.value );
               if( false === gtin_valid){
                jQuery("#_elex_fpf_gtin_error").removeClass('hide');
               }
                function isValidGtinProd(str) {
                    return !/[/ ]/g.test(str);
                }
    })

    jQuery(document).on('keyup', '.elex_fpf_gtin_number input',function(){
        const error_div_var= jQuery(this).parents('.elex_fb_custom_fields').find("._elex_fpf_gtin_var_error");
        if( !jQuery.isNumeric(this.value) ){
            error_div_var.removeClass('hide');
        }else{
            error_div_var.addClass('hide');
        }
    })

    jQuery("._elex_fpf_gtin_field").hide();


    jQuery("#elex_fb_india_field").hide();
    jQuery("#elex_fb_usa_field").hide();

    jQuery(document).on('change', '#product-type', function() {
        if('simple' === this.value){
            jQuery('.brand_gtin_mpn_field_fb_feed').removeClass('hide')
            jQuery('.message_field_variable_elex_fb').addClass('hide')
            jQuery('.elex_fpf_product_data_options').css({ "display" : "block" })

        }else if('variable' === this.value){
            jQuery('.brand_gtin_mpn_field_fb_feed').addClass('hide')

            jQuery('.elex_fpf_product_data_options').css({ "display" : "none" })
        }    
    });

   if( jQuery("#_elex_fpf_simple_gtin").val()){
    jQuery("._elex_fpf_gtin_field").show();

   }

  

    jQuery("#_elex_fpf_simple_gtin").change(function(){
        if(this.value){
            jQuery("._elex_fpf_gtin_field").show();

        }else{
            jQuery("._elex_fpf_gtin_field").hide();
        }
    })
    if (jQuery("#_additional_field_india").is(':checked')) {
        jQuery("#elex_fb_india_field").show();

    }

    if (jQuery("#_additional_field_usa").is(':checked')) {
        jQuery("#elex_fb_usa_field").show();

    }

    jQuery( "#_additional_field_india" ).on( "click", function(){
        if( jQuery("#_additional_field_india").is(":checked") ){
            jQuery("#elex_fb_india_field").show();

        }else{
            jQuery("#elex_fb_india_field").hide();

        }

    } );

    jQuery( "#_additional_field_usa" ).on( "click", function(){
        if( jQuery("#_additional_field_usa").is(":checked") ){
            jQuery("#elex_fb_usa_field").show();

        }else{
            jQuery("#elex_fb_usa_field").hide();

        }

    } );


        
        jQuery(document).on("change", "[id^=_elex_fpf_variable_gtin_type]", function(){
            const gtin_number_field = jQuery(this).parents('.elex_fb_custom_fields').find(".elex_fpf_gtin_number");
           
            if(this.value){
                gtin_number_field.show();
    
            }else{
                gtin_number_field.hide();
            }
        })

        jQuery(document).on("change","[id^=_additional_field_india]",function(){
            const elex_fpf_india_field = jQuery(this).parents('.elex_fb_custom_fields').find(".elex_fb_india_field");
            if( this.checked ){
                elex_fpf_india_field.show();
    
            }else{

                elex_fpf_india_field.hide();
    
            }
        })

        jQuery(document).on("change","[id^=_additional_field_usa]",function(){
            const elex_fpf_usa_field = jQuery(this).parents('.elex_fb_custom_fields').find(".elex_fb_usa_field");
            if( this.checked ){
                elex_fpf_usa_field.show();
    
            }else{

                elex_fpf_usa_field.hide();
    
            }
        })

      

 });

