// source --> /wp-content/themes/enfold-child/js/jquery.slicknav.js 
/*!
 * SlickNav Responsive Mobile Menu v1.0.10
 * (c) 2016 Josh Cope
 * licensed under MIT
 */
;(function ($, document, window) {
    var
    // default settings object.
        defaults = {
            label: 'MENU',
            duplicate: true,
            duration: 200,
            easingOpen: 'swing',
            easingClose: 'swing',
            closedSymbol: '&#9658;',
            openedSymbol: '&#9660;',
            prependTo: 'body',
            appendTo: '',
            parentTag: 'a',
            closeOnClick: false,
            allowParentLinks: false,
            nestedParentLinks: true,
            showChildren: false,
            removeIds: true,
            removeClasses: false,
            removeStyles: false,
			brand: '',
            animations: 'jquery',
            init: function () {},
            beforeOpen: function () {},
            beforeClose: function () {},
            afterOpen: function () {},
            afterClose: function () {}
        },
        mobileMenu = 'slicknav',
        prefix = 'slicknav',

        Keyboard = {
            DOWN: 40,
            ENTER: 13,
            ESCAPE: 27,
            LEFT: 37,
            RIGHT: 39,
            SPACE: 32,
            TAB: 9,
            UP: 38,
        };

    function Plugin(element, options) {
        this.element = element;

        // jQuery has an extend method which merges the contents of two or
        // more objects, storing the result in the first object. The first object
        // is generally empty as we don't want to alter the default options for
        // future instances of the plugin
        this.settings = $.extend({}, defaults, options);

        // Don't remove IDs by default if duplicate is false
        if (!this.settings.duplicate && !options.hasOwnProperty("removeIds")) {
          this.settings.removeIds = false;
        }

        this._defaults = defaults;
        this._name = mobileMenu;

        this.init();
    }

    Plugin.prototype.init = function () {
        var $this = this,
            menu = $(this.element),
            settings = this.settings,
            iconClass,
            menuBar;

        // clone menu if needed
        if (settings.duplicate) {
            $this.mobileNav = menu.clone();
        } else {
            $this.mobileNav = menu;
        }

        // remove IDs if set
        if (settings.removeIds) {
          $this.mobileNav.removeAttr('id');
          $this.mobileNav.find('*').each(function (i, e) {
              $(e).removeAttr('id');
          });
        }

        // remove classes if set
        if (settings.removeClasses) {
            $this.mobileNav.removeAttr('class');
            $this.mobileNav.find('*').each(function (i, e) {
                $(e).removeAttr('class');
            });
        }

        // remove styles if set
        if (settings.removeStyles) {
            $this.mobileNav.removeAttr('style');
            $this.mobileNav.find('*').each(function (i, e) {
                $(e).removeAttr('style');
            });
        }

        // styling class for the button
        iconClass = prefix + '_icon';

        if (settings.label === '') {
            iconClass += ' ' + prefix + '_no-text';
        }

        if (settings.parentTag == 'a') {
            settings.parentTag = 'a href="#"';
        }

        // create menu bar
        $this.mobileNav.attr('class', prefix + '_nav');
        menuBar = $('<div class="' + prefix + '_menu"></div>');
		if (settings.brand !== '') {
			var brand = $('<div class="' + prefix + '_brand">'+settings.brand+'</div>');
			$(menuBar).append(brand);
		}
        $this.btn = $(
            ['<' + settings.parentTag + ' aria-haspopup="true" role="button" tabindex="0" class="' + prefix + '_btn ' + prefix + '_collapsed">',
                '<span class="' + prefix + '_menutxt">' + settings.label + '</span>',
                '<span class="' + iconClass + '">',
                    '<span class="' + prefix + '_icon-bar"></span>',
                    '<span class="' + prefix + '_icon-bar"></span>',
                    '<span class="' + prefix + '_icon-bar"></span>',
                '</span>',
            '</' + settings.parentTag + '>'
            ].join('')
        );
        $(menuBar).append($this.btn);
        if(settings.appendTo !== '') {
            $(settings.appendTo).append(menuBar);
        } else {
            $(settings.prependTo).prepend(menuBar);
        }
        menuBar.append($this.mobileNav);

        // iterate over structure adding additional structure
        var items = $this.mobileNav.find('li');
        $(items).each(function () {
            var item = $(this),
                data = {};
            data.children = item.children('ul').attr('role', 'menu');
            item.data('menu', data);

            // if a list item has a nested menu
            if (data.children.length > 0) {

                // select all text before the child menu
                // check for anchors

                var a = item.contents(),
                    containsAnchor = false,
                    nodes = [];

                $(a).each(function () {
                    if (!$(this).is('ul')) {
                        nodes.push(this);
                    } else {
                        return false;
                    }

                    if($(this).is("a")) {
                        containsAnchor = true;
                    }
                });

                var wrapElement = $(
                    '<' + settings.parentTag + ' role="menuitem" aria-haspopup="true" tabindex="-1" class="' + prefix + '_item"/>'
                );

                // wrap item text with tag and add classes unless we are separating parent links
                if ((!settings.allowParentLinks || settings.nestedParentLinks) || !containsAnchor) {
                    var $wrap = $(nodes).wrapAll(wrapElement).parent();
                    $wrap.addClass(prefix+'_row');
                } else
                    $(nodes).wrapAll('<span class="'+prefix+'_parent-link '+prefix+'_row"/>').parent();

                if (!settings.showChildren) {
                    item.addClass(prefix+'_collapsed');
                } else {
                    item.addClass(prefix+'_open');
                }

                item.addClass(prefix+'_parent');

                // create parent arrow. wrap with link if parent links and separating
                var arrowElement = $('<span class="'+prefix+'_arrow">'+(settings.showChildren?settings.openedSymbol:settings.closedSymbol)+'</span>');

                if (settings.allowParentLinks && !settings.nestedParentLinks && containsAnchor)
                    arrowElement = arrowElement.wrap(wrapElement).parent();

                //append arrow
                $(nodes).last().after(arrowElement);


            } else if ( item.children().length === 0) {
                 item.addClass(prefix+'_txtnode');
            }

            // accessibility for links
            item.children('a').attr('role', 'menuitem').click(function(event){
                //Ensure that it's not a parent
                if (settings.closeOnClick && !$(event.target).parent().closest('li').hasClass(prefix+'_parent')) {
                        //Emulate menu close if set
                        $($this.btn).click();
                    }
            });

            //also close on click if parent links are set
            if (settings.closeOnClick && settings.allowParentLinks) {
                item.children('a').children('a').click(function (event) {
                    //Emulate menu close
                    $($this.btn).click();
                });

                item.find('.'+prefix+'_parent-link a:not(.'+prefix+'_item)').click(function(event){
                    //Emulate menu close
                        $($this.btn).click();
                });
            }
        });

        // structure is in place, now hide appropriate items
        $(items).each(function () {
            var data = $(this).data('menu');
            if (!settings.showChildren){
                $this._visibilityToggle(data.children, null, false, null, true);
            }
        });

        // finally toggle entire menu
        $this._visibilityToggle($this.mobileNav, null, false, 'init', true);

        // accessibility for menu button
        $this.mobileNav.attr('role','menu');

        // outline prevention when using mouse
        $(document).mousedown(function(){
            $this._outlines(false);
        });

        $(document).keyup(function(){
            $this._outlines(true);
        });

        // menu button click
        $($this.btn).click(function (e) {
            e.preventDefault();
            $this._menuToggle();
        });

        // click on menu parent
        $this.mobileNav.on('click', '.' + prefix + '_item', function (e) {
            e.preventDefault();
            $this._itemClick($(this));
        });

        // check for keyboard events on menu button and menu parents
        $($this.btn).keydown(function (e) {
            var ev = e || event;

            switch(ev.keyCode) {
                case Keyboard.ENTER:
                case Keyboard.SPACE:
                case Keyboard.DOWN:
                    e.preventDefault();
                    if (ev.keyCode !== Keyboard.DOWN || !$($this.btn).hasClass(prefix+'_open')){
                        $this._menuToggle();
                    }
                    
                    $($this.btn).next().find('[role="menuitem"]').first().focus();
                    break;
            }

            
        });

        $this.mobileNav.on('keydown', '.'+prefix+'_item', function(e) {
            var ev = e || event;

            switch(ev.keyCode) {
                case Keyboard.ENTER:
                    e.preventDefault();
                    $this._itemClick($(e.target));
                    break;
                case Keyboard.RIGHT:
                    e.preventDefault();
                    if ($(e.target).parent().hasClass(prefix+'_collapsed')) {
                        $this._itemClick($(e.target));
                    }
                    $(e.target).next().find('[role="menuitem"]').first().focus();
                    break;
            }
        });

        $this.mobileNav.on('keydown', '[role="menuitem"]', function(e) {
            var ev = e || event;

            switch(ev.keyCode){
                case Keyboard.DOWN:
                    e.preventDefault();
                    var allItems = $(e.target).parent().parent().children().children('[role="menuitem"]:visible');
                    var idx = allItems.index( e.target );
                    var nextIdx = idx + 1;
                    if (allItems.length <= nextIdx) {
                        nextIdx = 0;
                    }
                    var next = allItems.eq( nextIdx );
                    next.focus();
                break;
                case Keyboard.UP:
                    e.preventDefault();
                    var allItems = $(e.target).parent().parent().children().children('[role="menuitem"]:visible');
                    var idx = allItems.index( e.target );
                    var next = allItems.eq( idx - 1 );
                    next.focus();
                break;
                case Keyboard.LEFT:
                    e.preventDefault();
                    if ($(e.target).parent().parent().parent().hasClass(prefix+'_open')) {
                        var parent = $(e.target).parent().parent().prev();
                        parent.focus();
                        $this._itemClick(parent);
                    } else if ($(e.target).parent().parent().hasClass(prefix+'_nav')){
                        $this._menuToggle();
                        $($this.btn).focus();
                    }
                    break;
                case Keyboard.ESCAPE:
                    e.preventDefault();
                    $this._menuToggle();
                    $($this.btn).focus();
                    break;    
            }
        });

        // allow links clickable within parent tags if set
        if (settings.allowParentLinks && settings.nestedParentLinks) {
            $('.'+prefix+'_item a').click(function(e){
                    e.stopImmediatePropagation();
            });
        }
    };

    //toggle menu
    Plugin.prototype._menuToggle = function (el) {
        var $this = this;
        var btn = $this.btn;
        var mobileNav = $this.mobileNav;

        if (btn.hasClass(prefix+'_collapsed')) {
            btn.removeClass(prefix+'_collapsed');
            btn.addClass(prefix+'_open');
        } else {
            btn.removeClass(prefix+'_open');
            btn.addClass(prefix+'_collapsed');
        }
        btn.addClass(prefix+'_animating');
        $this._visibilityToggle(mobileNav, btn.parent(), true, btn);
    };

    // toggle clicked items
    Plugin.prototype._itemClick = function (el) {
        var $this = this;
        var settings = $this.settings;
        var data = el.data('menu');
        if (!data) {
            data = {};
            data.arrow = el.children('.'+prefix+'_arrow');
            data.ul = el.next('ul');
            data.parent = el.parent();
            //Separated parent link structure
            if (data.parent.hasClass(prefix+'_parent-link')) {
                data.parent = el.parent().parent();
                data.ul = el.parent().next('ul');
            }
            el.data('menu', data);
        }
        if (data.parent.hasClass(prefix+'_collapsed')) {
            data.arrow.html(settings.openedSymbol);
            data.parent.removeClass(prefix+'_collapsed');
            data.parent.addClass(prefix+'_open');
            data.parent.addClass(prefix+'_animating');
            $this._visibilityToggle(data.ul, data.parent, true, el);
        } else {
            data.arrow.html(settings.closedSymbol);
            data.parent.addClass(prefix+'_collapsed');
            data.parent.removeClass(prefix+'_open');
            data.parent.addClass(prefix+'_animating');
            $this._visibilityToggle(data.ul, data.parent, true, el);
        }
    };

    // toggle actual visibility and accessibility tags
    Plugin.prototype._visibilityToggle = function(el, parent, animate, trigger, init) {
        var $this = this;
        var settings = $this.settings;
        var items = $this._getActionItems(el);
        var duration = 0;
        if (animate) {
            duration = settings.duration;
        }
        
        function afterOpen(trigger, parent) {
            $(trigger).removeClass(prefix+'_animating');
            $(parent).removeClass(prefix+'_animating');

            //Fire afterOpen callback
            if (!init) {
                settings.afterOpen(trigger);
            }
        }
        
        function afterClose(trigger, parent) {
            el.attr('aria-hidden','true');
            items.attr('tabindex', '-1');
            $this._setVisAttr(el, true);
            el.hide(); //jQuery 1.7 bug fix

            $(trigger).removeClass(prefix+'_animating');
            $(parent).removeClass(prefix+'_animating');

            //Fire init or afterClose callback
            if (!init){
                settings.afterClose(trigger);
            } else if (trigger == 'init'){
                settings.init();
            }
        }

        if (el.hasClass(prefix+'_hidden')) {
            el.removeClass(prefix+'_hidden');
             //Fire beforeOpen callback
            if (!init) {
                settings.beforeOpen(trigger);
            }
            if (settings.animations === 'jquery') {
                el.stop(true,true).slideDown(duration, settings.easingOpen, function(){
                    afterOpen(trigger, parent);
                });
            } else if(settings.animations === 'velocity') {
                el.velocity("finish").velocity("slideDown", {
                    duration: duration,
                    easing: settings.easingOpen,
                    complete: function() {
                        afterOpen(trigger, parent);
                    }
                });
            }
            el.attr('aria-hidden','false');
            items.attr('tabindex', '0');
            $this._setVisAttr(el, false);
        } else {
            el.addClass(prefix+'_hidden');

            //Fire init or beforeClose callback
            if (!init){
                settings.beforeClose(trigger);
            }

            if (settings.animations === 'jquery') {
                el.stop(true,true).slideUp(duration, this.settings.easingClose, function() {
                    afterClose(trigger, parent)
                });
            } else if (settings.animations === 'velocity') {
                
                el.velocity("finish").velocity("slideUp", {
                    duration: duration,
                    easing: settings.easingClose,
                    complete: function() {
                        afterClose(trigger, parent);
                    }
                });
            }
        }
    };

    // set attributes of element and children based on visibility
    Plugin.prototype._setVisAttr = function(el, hidden) {
        var $this = this;

        // select all parents that aren't hidden
        var nonHidden = el.children('li').children('ul').not('.'+prefix+'_hidden');

        // iterate over all items setting appropriate tags
        if (!hidden) {
            nonHidden.each(function(){
                var ul = $(this);
                ul.attr('aria-hidden','false');
                var items = $this._getActionItems(ul);
                items.attr('tabindex', '0');
                $this._setVisAttr(ul, hidden);
            });
        } else {
            nonHidden.each(function(){
                var ul = $(this);
                ul.attr('aria-hidden','true');
                var items = $this._getActionItems(ul);
                items.attr('tabindex', '-1');
                $this._setVisAttr(ul, hidden);
            });
        }
    };

    // get all 1st level items that are clickable
    Plugin.prototype._getActionItems = function(el) {
        var data = el.data("menu");
        if (!data) {
            data = {};
            var items = el.children('li');
            var anchors = items.find('a');
            data.links = anchors.add(items.find('.'+prefix+'_item'));
            el.data('menu', data);
        }
        return data.links;
    };

    Plugin.prototype._outlines = function(state) {
        if (!state) {
            $('.'+prefix+'_item, .'+prefix+'_btn').css('outline','none');
        } else {
            $('.'+prefix+'_item, .'+prefix+'_btn').css('outline','');
        }
    };

    Plugin.prototype.toggle = function(){
        var $this = this;
        $this._menuToggle();
    };

    Plugin.prototype.open = function(){
        var $this = this;
        if ($this.btn.hasClass(prefix+'_collapsed')) {
            $this._menuToggle();
        }
    };

    Plugin.prototype.close = function(){
        var $this = this;
        if ($this.btn.hasClass(prefix+'_open')) {
            $this._menuToggle();
        }
    };

    $.fn[mobileMenu] = function ( options ) {
        var args = arguments;

        // Is the first parameter an object (options), or was omitted, instantiate a new instance
        if (options === undefined || typeof options === 'object') {
            return this.each(function () {

                // Only allow the plugin to be instantiated once due to methods
                if (!$.data(this, 'plugin_' + mobileMenu)) {

                    // if it has no instance, create a new one, pass options to our plugin constructor,
                    // and store the plugin instance in the elements jQuery data object.
                    $.data(this, 'plugin_' + mobileMenu, new Plugin( this, options ));
                }
            });

        // If is a string and doesn't start with an underscore or 'init' function, treat this as a call to a public method.
        } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {

            // Cache the method call to make it possible to return a value
            var returns;

            this.each(function () {
                var instance = $.data(this, 'plugin_' + mobileMenu);

                // Tests that there's already a plugin-instance and checks that the requested public method exists
                if (instance instanceof Plugin && typeof instance[options] === 'function') {

                    // Call the method of our plugin instance, and pass it the supplied arguments.
                    returns = instance[options].apply( instance, Array.prototype.slice.call( args, 1 ) );
                }
            });

            // If the earlier cached method gives a value back return the value, otherwise return this to preserve chainability.
            return returns !== undefined ? returns : this;
        }
    };
}(jQuery, document, window));
// source --> /wp-content/themes/enfold-child/js/custom-jokin.js?v=3 
function clonar_test()
{
	
	/* clonar par los mobiles */

	jQuery('.row_home_luz_front').clone().insertBefore('.row_home_luz_front').removeClass().addClass('luz_home_mobile').addClass('max767');
	//jQuery('.row_home_gas_front').clone().addClass('max767').insertAfter('.row_home_luz_front.solo_mobile');
	
	jQuery('.luz_home_mobile *').removeClass();
	jQuery('.luz_home_mobile').removeAttr('id');
	jQuery('.luz_home_mobile > div').removeAttr('style');

	jQuery('.row_home_gas_front').clone().insertBefore('.row_home_gas_front').removeClass().addClass('gas_home_mobile').addClass('max767');
	//jQuery('.row_home_gas_front').clone().addClass('max767').insertAfter('.row_home_luz_front.solo_mobile');
	
	jQuery('.gas_home_mobile *').removeClass();
	jQuery('.gas_home_mobile').removeAttr('id');
	jQuery('.gas_home_mobile > div').removeAttr('style');

	/* intercambiar posiciones */
	jQuery('div.gas_home_mobile.max767 > div > div > div > div > div:nth-child(2)').insertBefore('div.gas_home_mobile.max767 > div > div > div > div > div:nth-child(1)');



	var foo = jQuery(window).width();
	
	if ( foo > 767  || true )  
	{  
	
	jQuery('.row_home_luz_front > div').addClass('front');
	jQuery('.row_home_luz_back > div').clone().addClass('back').insertAfter('.row_home_luz_front > div');
	jQuery('.row_home_luz_back').remove();
	
		if ( jQuery ( window).width() > 900 )  
		{  
		jQuery('.row_home_luz_front').css('width',  '900px');
		}
		else 
		{
		jQuery('.row_home_luz_front').css('width', '100%');
		jQuery('.row_home_luz_front > div').css('width', '100%');
		jQuery('.row_home_luz_front > div').css('max-width', '100%');
		}
		
	
	//jQuery('.row_home_hogares').css('margin', '0 auto 50px');
	
	jQuery('body.home .row_home_luz_front').addClass('min768');
	
		
	/* No flipar y ocultar el back */ 
		
	//jQuery('body.home .row_home_luz_front').flip();
	jQuery ('.row_home_luz_front .back').hide();	
	
	console.log('Todos los sistemas han sido renderizados. Condensador de Fluzo funcionando. ');	
	
		
	/* centralo  */
	foo =  ( (jQuery(window).width() - jQuery('.row_home_luz_front').width() ) /2 );
	
	jQuery('.row_home_luz_front').css('left', foo + 'px');
	
	
	jQuery('.row_home_gas_front > div').addClass('front');
	jQuery('.row_home_gas_back > div').clone().addClass('back').insertAfter('.row_home_gas_front > div');
	jQuery('.row_home_gas_back').remove();
	
	if ( jQuery ( window).width() > 900 )  
	{  
	jQuery('.row_home_gas_front').css('width', '900px');
	}
	else 
	{
	jQuery('.row_home_gas_front').css('width', '100%');
	jQuery('.row_home_gas_front > div').css('width', '100%');
	jQuery('.row_home_gas_front > div').css('max-width', '100%');
	}
	
	
	//jQuery('.row_home_gas_front').css('margin', '0 auto');
	
		
	/* No flipar y ocultar el back */ 
		
	//jQuery('body.home .row_home_gas_front').flip();
	
		jQuery ('.row_home_gas_front .back').hide();
	
		
	jQuery('body.home .row_home_gas_front').addClass('min768');
	
	/* centralo  */
	foo =  ( (jQuery(window).width() - jQuery('.row_home_gas_front').width() ) /2 ) ;
	
	//console.log('margen gas ' + foo );
	
	jQuery('.row_home_gas_front').css('left', foo + 'px');
	
	}
	

	jQuery('body.empresas .row_home_luz_front').addClass('min768');
	jQuery('body.empresas .row_home_gas_front').addClass('min768');


}




jQuery(document).ready( function () {
	
	if (jQuery('body').hasClass('empresas') ) 
	{
		jQuery('.menu_empresas').addClass('selected');	
	}
	else 
	{
	jQuery('.menu_hogares').addClass('selected');	
	}
	
	
	if ( jQuery(window).width() >= 768  || true ) 
	{
	
	clonar_test();
	
	}
	else 
	{
		
		/* console.log('Bombilla y fogon '); */

		jQuery('.bombilla_home').height(  jQuery('.bombilla_home img ').width()  * 0.8 );
		jQuery('.fogon_home').height(  jQuery('.fogon_home img').width()  );



	}	
	
	
	
	
});



function ajustar_slider ()
{
	
	/* centrar horizontal en mobil hasta 767 */
	/* imagenes encabezado */

	if  ( jQuery (window).width()  >= 1000 ) 
	{
		//
		jQuery('.encabezado_paginas .container').height(350);
	}	
	else
	{
		
		jQuery('.encabezado_paginas .container').removeAttr('style');
	}	


}

jQuery(window).load( function () {
		ajustar_slider ();
	
	});

jQuery(window).resize( function () {
		ajustar_slider ();
	
	});



function activar_formulario ()
{
		

	jQuery('input[name="nombre"]').focus();
	
	jQuery('.boton_enviar').click( function () {
						
	jQuery('.warning_').remove();
			
			if (!validar_formulario())
			{
				jQuery('.formulario_ario').after('<div class="warning_">Faltan campos</div>');
			
			
			}
			
			else 
			{ 		
					var variables = jQuery('#formu').serialize();
					var seconds = new Date().getTime() / 1000;

				
					jQuery.ajax({
						url: "/wp-content/themes/enfold-child/ajax/enviar-formulario.ajax.php?timer="+seconds,
						data: variables, 
						type: 'POST',
						cache: false,
						dataType: 'json', // Choosing a JSON datatype
						success: function ( data ) 
						{
							jQuery('.contrae').slideUp();
							jQuery('.formulario_ario').after('<div class="warning_ ok">'+  data.respuesta_ajax +'</div>');
							
							jQuery('html, body').animate({
							scrollTop: jQuery(".contrae").offset().top }, 2000);
							
							ga('send', 'event', 'formulario_ok', 'formulario-contacto.php');
							
							
						}
					});	
			}
	});	
}  /* activar_formulario */
	
 function validar_formulario()
 {
	 jQuery('.formulario_ario .obligatorio').css({'background-color':'white'});
	
	 resultado=true;
	 
	jQuery('.formulario_ario .obligatorio').each(function(){
		
		if ( jQuery(this).val()=='' ) 
		{
		resultado=false;
		jQuery(this).css({'background-color':'#FBA3BE'});
		
		}
		
	});
	
	
	
	
	
	return resultado;
}



function validar_email ( foo )
{

	  if(  foo.indexOf('@', 0) == -1 || foo.indexOf('.', 0) == -1) 
	  {
           
            return false;
       }
		else
		{
			return true;
		
		
		}



}


function validar_nif ( foo ) 
{
	if ( validaNif( foo )==false 
		&&  validaCif(foo)==false
		/*
		&& validaNie(foo)==false
	   */
	   )
	    {
		   return false; 
	   }
      else 
		{  
			return true;
		}

}

 //Funciones validadoras
 
function validaNif(control) 
{	
  if (control=="")
	return;
  var dni=control;    
  var numero = dni.substr(0,dni.length-1);
  var let = dni.substr(dni.length-1,1);
  let=let.toUpperCase();
  numero = numero % 23;
  var letra='TRWAGMYFPDXBNJZSQVHLCKET';
  letra=letra.substring(numero,numero+1);    
  //alert(letra);
  if (letra!=let)   
  {
    return false;
  }
	else 
	{ 
		console.log('Es un NIF o DNI correcto ');
		return true;
	}
}
 
 
function validaCif(control)
{ 
  if (control=="")
  {
	return;
  }
        var texto=control;
        var pares = 0; 
        var impares = 0; 
        var suma; 
        var ultima; 
        var unumero; 
        var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I"); 
        var xxx; 
         
        texto = texto.toUpperCase(); 
         
        var regular = new RegExp(/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g); 
         if (!regular.exec(texto)) 
			{
				return false ;	
			}
		 
              
         ultima = texto.substr(8,1); 
 
         for (var cont = 1 ; cont < 7 ; cont ++){ 
             xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + "0"; 
             impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1)); 
             pares += parseInt(texto.substr(cont,1)); 
         } 
         xxx = (2 * parseInt(texto.substr(cont,1))).toString() + "0"; 
         impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1)); 
          
         suma = (pares + impares).toString(); 
         unumero = parseInt(suma.substr(suma.length - 1, 1)); 
         unumero = (10 - unumero).toString(); 
         if(unumero == 10) unumero = 0; 
          
         if ((ultima == unumero) || (ultima == uletra[unumero])) 
			{
             	console.log('Es un CIF correcto');
				return true; 
			}
		else 
             {
				return false;	
			 }
 
    } 
 
	
function validaNie(control) 
{	
  if (control=="")
	return;	
 
	var a=control;		
	
	console.log ('a vale ' + a );
	
	var temp=a.toUpperCase();
	var cadenadni="TRWAGMYFPDXBNJZSQVHLCKET";
	var v1 = new Array(0,2,4,6,8,1,3,5,7,9);
	var posicion=0;
	var letra=" ";
	
	
	console.log ('Longitud de la cadena ' + a.lenght );
	
	//Residente en España	
	if (a.length==9)
	{
		if (temp.substr(0,1)=="X")
		{
			var temp1=temp.substr(1,7);
 
			posicion = temp1 % 23; /*Resto de la division entre 23 es la posicion en la cadena*/
			letra = cadenadni.substring(posicion,posicion+1);
			if (!/^[A-Za-z0-9]{9}$/.test(temp))
			{ 
				return false;
			}
			else
			{ 
				//Tiene los 9 dígitos, comprobamos si la letra esta bien
				var temp1=temp.substr(1,7);
				posicion = temp1 % 23; /*Resto de la division entre 23 es la posicion en la cadena*/
				letra = cadenadni.charAt(posicion);
				var letranie=temp.charAt(8);
				if (letra != letranie){			
					
					return true;
				}				
			}
		}
		else
		{
			return false;			
		}		
	}else if (a.length==14){//14 caracteres, los 2 primeros letras
		var temp1=temp.substr(0,2);
		if (isAlphabetic(temp1)!=true)	
			{
			return false;	
			}
	}
	else
	{
			return false;		
 
	}
	
}
 
 







jQuery( document).ready( function () {
	/* Hack añadir listado total BLOG en HOME */ 
	jQuery ('.listado_blog .avia-content-slider-inner').after('<div class="lineaja_blog"></div><div class="listado_blog_total"><a href="/blog">Ver todos los artículos ></a></div>');
	
	activa_popup_llamada ();

});

/** POPUP de NOSOTREOS TE LLAMAMOS **/

popup_active=0;


function activa_popup_llamada () 
{
	
jQuery('.activa_pop_llamada').click ( function ()
{
	
	console.log('Activa popup llamada');
	
	
	jQuery ('.main_menu_jokin').hide(); /* escondemos el menu porque interfiere para cerrar */
	
	if ( popup_active ==0 )
	{
		jQuery('body').prepend ('<div class="popup_background" style="background:rgba(0,0,0,0.5); z-index:200;"></div>');
		jQuery('.popup_background').height ( jQuery(document).height()  );
		jQuery('.popup_background').width ( jQuery(document).width()  );
		
		
		jQuery('.popup_background').after('<div class="popup_wrap" style="z-index:200;"></div>');
		
		var seconds = new Date().getTime() / 1000;

		jQuery('.popup_wrap').load('/wp-content/themes/enfold-child/ajax/formulario-contacto.php?t=' + seconds , function (){ 
			
			activar_formulario();
			
			
			jQuery('.boton-cierra').click(function(){
				
				console.log('boton cierra');
				
				if ( jQuery(window).width() > 963 ) {   jQuery('.main_menu_jokin').show(); /* escondemos el menu porque interfiere para cerrar */ }
				
				popup_active=0;
				jQuery('.popup_wrap').remove();
				jQuery('.popup_background').remove();
			
			});	
			
			centra_elemento_en_ventana('popup_wrap');
			
			
			
		});
		popup_active =1;
		
		foo_scroll = jQuery(window).scrollTop();
		jQuery('.popup_wrap').css('top', foo_scroll + 'px');
		
		
		ancho_del_popup = jQuery('.popup_wrap').width();
		
		console.log  ('ancho_del_popup ' + ancho_del_popup);
		 
		foo_left = (  jQuery(window).width() - ancho_del_popup ) /2;
		jQuery('.popup_wrap').css ('left', foo_left + 'px' );
		
		
	}


});



} /* activa popup llamada */ 


jQuery( document).ready( function () {
	
	ajusta_elementos();

	/* conversiones de llamada de ADS */

	jQuery('a[href="tel:+34900190300"]').click ( function (){


		return gtag_report_conversion('tel:+34900190300');
		console.log ('Reportando conversión gtag de ADS');

	});
	



	
	});




var rtime;
var timeout = false;
var delta = 200;

jQuery(window).resize(function() {
    rtime = new Date();
    if (timeout === false) {
        timeout = true;
        setTimeout(resizeend, delta);
    }
});

function resizeend() {
    if (new Date() - rtime < delta) {
        setTimeout(resizeend, delta);
    } else {
        timeout = false;
        console.log ('finish resizing ');
        //location.reload();

    }               
}	
	


function ajusta_elementos () {
	
	/* hace las fotos de la HOME BLOG el alto = 0,66 * ancho */
	
	console.log ('ajusta elememtos: ancho ventana' + jQuery (window).width() );
	
	jQuery('.listado_blog img').each( function (){
		
		
		jQuery(this).height ( 0.60 *  jQuery(this).width());
		
		});	
	
	jQuery('.wrap_list_blog .left .image').each( function (){
		
		
			jQuery(this).height ( 0.8 * jQuery(this).width() );
		
		});	
		
	
	jQuery('.make_h_like_image_inside').each ( function () {
	
		
		//return(1);
		
		/*
		foo = jQuery(this).find ('img').height();
		console.log ( 'altura imagen  ' + foo );
		jQuery(this).height (foo - 5   );
		jQuery(this).css ('overflow', 'hidden' );
		*/
		
		if ( jQuery (window).width() >= 768 )
		{ 
		
		
		/*hace las dos columnas igual de grandes que la mayor */
		
		
			
		
			if ( false ) 
			{
			
			foo = jQuery(this).find ('.content').height();
			jQuery(this).find ('.av_textblock_section').closest('.flex_column').height( foo ); 
			
			
			console.log ( 'altura content   ' + foo );
			
			jQuery(this).find ('img').height( foo );
			jQuery(this).find ('.content').css ('overflow', 'hidden' );
			}
		
		
		}
		
			
	
	});
	
	
	
	if ( jQuery (window).width() >= 768  )
	{ 
	
	

	console.log ('la ventana mide '  + jQuery (window).width() );
	
	/* hacer gas back igual que el front */
	
	fook = jQuery('.row_home_gas_front .container.front').height();
	console.log ('altura del front gas ' +  fook );
	
	jQuery ('.row_home_gas_front .container.front .flex_column').height(fook);
	jQuery ('.row_home_gas_front .container.front .flex_column img').height(fook);
	
	/* hacer luz front igual de alta que el back */

	fook = jQuery('.row_home_luz_front .container.front').height();
	console.log ('altura del front luz ' +  fook );
	
	jQuery ('.row_home_luz_front .container.front .flex_column').height(fook);
	jQuery ('.row_home_luz_front .container.front .flex_column img').height(fook);






	}
	else 
	{
		jQuery ('.row_home_luz_front .container').removeAttr('style');
		console.log ('Quitando altura del ..'); 
	
	}
	
	
	
	
	
	
	
	

}

function centra_elemento_en_ventana ( clase )
{

		foo_ancho = jQuery('.' + clase ).width();
		//console.log  ('foo_ancho ' + foo_ancho);
		foo_left = (  jQuery(window).width() - foo_ancho ) /2;
		jQuery('.' + clase).css ('left', foo_left + 'px' );

		foo_alto = jQuery('.' + clase ).height();
		//console.log  ('foo_alto ' + foo_alto);
		foo_top = (  jQuery(window).height() - foo_alto ) /2;
		jQuery('.' + clase).css ('top', foo_top + 'px' );
		
		jQuery('.' + clase).css ('position','fixed' );


}

function mask_emails_antispam ()
{
	
	//return 1;
	
	jQuery('.page-id-1373 .cuadro_gris a[href], .mask_emails a[href]').each(function(){
		
		let foo = jQuery(this).attr('href');	
		
		if ( foo.includes('mailto:') )
		{	
			
			foo= foo.replace('mailto:','');
			
			let array_mail = foo.split('@');
			jQuery(this).attr('address', array_mail[0] );
			jQuery(this).attr('domain', array_mail[1] );
			
			jQuery(this).attr('href', '' );
			jQuery(this).addClass('masked');
			
			jQuery(this).html('Ver email');
			
			//jQuery(this).html( address + '@');
		
			
			
			jQuery(this).click(function(){
							   
							   foo = jQuery(this).attr('address') + '@' + jQuery(this).attr('domain');
				
							
							   jQuery(this).html(foo);
								jQuery(this).attr('href', 'mailto:' + foo);
				
				
							   
							   
							   });
		
		}
		
	});

	
};