// JavaScript Document
function ComprobacionMail(emailStr,campo){
	
    var emailPat=/^(.+)@(.+)$/
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    var validChars="\[^\\s" + specialChars + "\]"
    var quotedUser="(\"[^\"]*\")"
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    var atom=validChars + '+'
    var word="(" + atom + "|" + quotedUser + ")"
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
    var matchArray=emailStr.match(emailPat)
	

    if (matchArray==null) {
		
        return false
    }
    var user=matchArray[1]
    var domain=matchArray[2]
    if (user.match(userPat)==null) {
        alert('El nombre de usuario no es vÃ¡lido');
        return false
    }
	
    var IPArray=domain.match(ipDomainPat)
    if (IPArray!=null) {
		  
        return true
    }
	
    var domainArray=domain.match(domainPat)
    if (domainArray==null) {
		
		
        return false
    }
	
    var atomPat=new RegExp(atom,"g")
    var domArr=domain.match(atomPat)
    var len=domArr.length
    if (domArr[domArr.length-1].length<2 ||
        domArr[domArr.length-1].length>4) {
		
			
			
        return false
    }
	
    if (len<2) {
	  
			 
		
        return false
    }
    return true;
}

jQuery(document).ready(function(){
    /*scroll*/
    $('head').append("<style> .scrollThis{height:222px;overflow: scroll;width:115px;z-index:1}#right-column .scrollThis{width:185px}</style>");
    $('head').append("<style>div.cont-submenu{display:block;}</style>");
    $('.scrollThis').jScrollPane();
	
    $('head').append("<style>div.cont-submenu{display:none;}</style>");
	
    /*acordeon*/
    function set_cookie(name, value, days, path, domain, secure){
        var cookie_string = name + "=" + escape(value);
		
        function expires(days){
            var hoy = new Date();
            var msEnXDias = eval(days) * 24 * 60 * 60 * 1000;
            hoy.setTime(hoy.getTime() + msEnXDias);
            return (hoy.toGMTString());
        }
        if(days){
            cookie_string += "; expires=" + expires(days);
        }
        if(path){
            cookie_string += "; path=" + escape(path);
        }
	
        if(domain){
            cookie_string += "; domain=" + escape(domain);
        }
	
        if(secure){
            cookie_string += "; secure";
        }
	
        document.cookie = cookie_string;
    //alert(document.cookie);
    }

    function get_cookie(cookie_name){
        var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
        if(results){
            return(unescape(results[2]));
        }else{
            return null;
        }
    }
	
    function delete_cookie(cookie_name){
        var cookie_date = new Date ( );  // current date & time
        cookie_date.setTime ( cookie_date.getTime() - 1 );
        document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
    }
	
    /*acordeon pequeÃ±o
	$.each($('#sub-menu-small h3'), function(i){
		$(this).attr('theIndex', i);
	});
		
	$('#sub-menu-small').accordion({active: 'none', collapsible: true, autoHeight: false, changestart: function(event, ui){set_cookie('smallIndex',ui.newHeader.attr('theIndex'),30)}});
	
	var smallIndex = get_cookie('smallIndex');
	
	if(smallIndex != 'undefined'){
		if(smallIndex != undefined && smallIndex != null){
			$('#sub-menu-small').accordion('activate' , parseInt(smallIndex));
		}else{
		    if(smallIndex == null){
		        $('#sub-menu-small').accordion('activate' , 1);
		    }
		}	
	}*/
	
	
    /*acordeon grande*/
    if($('#secondary-menu-big').length > 0 ){
        $('#secondary-menu-big h3').next().css('margin-top', 0);
        $('#secondary-menu-big h3').next().hide();
		
        $.each($('#secondary-menu-big h3'), function(i){
            $(this).attr('theIndexBig', i);
            theIndexBig = get_cookie('theIndexBig' + i);
            if(theIndexBig=='1'){
                $(this).next().slideDown("slow");
                $(this).addClass('boton-activo');
            }
			
            if(i==0 && theIndexBig==null){
                $(this).next().slideDown("slow");
                $(this).addClass('boton-activo');
            }
            if(i==1 && theIndexBig==null){
                $(this).next().slideDown("slow");
                $(this).addClass('boton-activo');
            }
            if(i==2 && theIndexBig==null){
                $(this).next().slideDown("slow");
                $(this).addClass('boton-activo');
            }
			
        });
			
        $('#secondary-menu-big h3').next().after("<div style='height:5px'>&nbsp;</div>");

		
        $('#secondary-menu-big h3 .boton').css({
            marginBottom: 0,
            paddingBottom: 0
        });
			
        $('#secondary-menu-big h3').click(function() {
            if($(this).next().is(":hidden")){
                $(this).next().slideDown("slow");
                set_cookie('theIndexBig' + $(this).attr('theIndexBig') , '1',30);
                $(this).addClass('boton-activo');
            }else{
                $(this).next().slideUp("slow");
                set_cookie('theIndexBig' + $(this).attr('theIndexBig') , '0',30);
                $(this).removeClass('boton-activo');
            }
        })
    }

    /*paneles filtros busqueda*/
    xmarcas = get_cookie('xmarcas');
	
    if(xmarcas == null){
        $(".boton-slider.filtro-x-marcas").addClass('abierto');
    }else{
        if(xmarcas == 1){
            $(".boton-slider.filtro-x-marcas").addClass('abierto');
        }else{
            $("#filtro-x-marcas").hide();
        }
    }
	
    avanzado = get_cookie('avanzado');
    if(avanzado == null){
        $(".boton-slider.filtro-avanzado").addClass('abierto');
    }else{
        if(avanzado == 1){
            $(".boton-slider.filtro-avanzado").addClass('abierto');
        }else{
            $("#filtro-avanzado").hide();
        }
    }
	
    //$("#filtro-x-marcas, #filtro-avanzado").hide();
	
    $(".boton-slider.filtro-x-marcas").click(function () {
        $(this).toggleClass('abierto');
        $("#filtro-x-marcas").slideToggle("slow");
        if($(this).hasClass('abierto')){
            set_cookie('xmarcas',1);
        }else{
            set_cookie('xmarcas',0);
        }
    });
	
    $(".boton-slider.filtro-avanzado").click(function () {
        $(this).toggleClass('abierto');
        $("#filtro-avanzado").slideToggle("slow");
        if($(this).hasClass('abierto')){
            set_cookie('avanzado',1);
        }else{
            set_cookie('avanzado',0);
        }
    });
	
    /*hover resultados de busqueda*/
    /*$(".item-resultado").hover(
      function () {
        $(this).toggleClass("hover");
      }, 
      function () {
       $(this).toggleClass("hover");
      }
    );*/
	
    /*checkboxs*/
    if($('#checkBoxGroup').length > 0){
        $("input[type='checkbox']").custCheckBox();
        $.each($('.cust_checkbox'), function(i){
            if($(this).hasClass('cust_checkbox_on')){
                $(this).parent().addClass('check-active');
            }
            $(this).click(function () { 
                $(this).parent().toggleClass('check-active');
            });
        });  
    }
	
    //activar boton agregar al carrito
    function activarBtn(){
        if($('#radioButton1').attr("checked") || $('#radioButton2').attr("checked")){
            $('div.btn-red-large').addClass('btn-desactivado');
            $('input.btn-red-large').removeClass('btn-desactivado');
        }
    }
    activarBtn();
    $('#radioButton1, #radioButton2').click(function () {
        activarBtn();
    });
	
    /*seleccionar checkbox pasarela paso 2*/
    if($('.radio-envio').length > 0){
        function activarForm(param){
            if($('.radio-envio .radioButton').attr("checked")){
                $('.radio-envio').addClass('selected-radio');
                $('.radio-envio1').removeClass('selected-radio');
                $('.select-tipo-envio-form').removeClass('displayNone');
            }else if($('.radio-envio1 .radioButton').attr("checked")){
                $('.radio-envio1').addClass('selected-radio');
                $('.radio-envio').removeClass('selected-radio');
                $('.select-tipo-envio-form').removeClass('displayNone');
            }else if($('.radio-envio2 .radioButton').attr("checked")){
                $('.radio-envio1').removeClass('selected-radio');
                $('.radio-envio').removeClass('selected-radio');
                $('.select-tipo-envio-form').addClass('displayNone');
            }else{
                $('.radio-envio, .radio-envio1').removeClass('selected-radio');
                $('.select-tipo-envio-form').addClass('displayNone');
            }
        }
        activarForm();
        $('.radio-envio, .radio-envio1, .radio-envio2').click(function () {
            activarForm();
        });
    }
	
    //scroll horizontal marcas
    if ( $('.marcas').length > 0 ) {
        $('.marcas').scrollIt({
            menuWidth: 540,
            itemWidth: 60,
            menuHeight: 60,
            scrollDuration: 400
        });
    }
    //scroll horizontal detalles
    if ( $('.col-Desc-pri .slider-detalle1').length > 0 ) {
        $('.col-Desc-pri .slider-detalle1').scrollIt({
            menuWidth: 416,
            itemWidth: 101,
            itemHeight:111,
            menuHeight: 120,
            scrollDuration: 400
        });
        $('.col-Desc-pri .slider-detalle1').css({
            'width':'402px',
            'margin':'5px 7px'
        });

    }
    if ( $('.col-Desc-pri .slider-detalle2').length > 0 ) {
        $('.col-Desc-pri .slider-detalle2').scrollIt({
            menuWidth: 416,
            itemWidth: 101,
            itemHeight:111,
            menuHeight: 120,
            scrollDuration: 400,
            scrollItwrapper: 'scrollItwrapper2'
        });
        $('.col-Desc-pri .slider-detalle2').css({
            'width':'402px',
            'margin':'5px 7px'
        });
    }
	
    if ( $('.directorio li').length > 0 ) {
        $(".directorio li").hover(
            function () {
                $(this).toggleClass("highlight");
            },
            function () {
                $(this).toggleClass("highlight");
            }
            );
    }
    //cont-slider slider-detalle-carrito

    function sliderCarrito(){
        if ( $('.col-Desc-pri .slider-detalle-carrito').length > 0 ) {
            $('.col-Desc-pri .slider-detalle-carrito').scrollIt({
                menuWidth: 520,
                itemWidth: 101,
                itemHeight:111,
                menuHeight: 120,
                scrollDuration: 400
            });
            $('.col-Desc-pri .slider-detalle-carrito').css({
                'width':'502px',
                'margin':'5px 7px'
            });

        }
    }
    // Andres 25-8
    // funcion a llamar cuando se ejecute con ajax.

    sliderCarrito();
    
    //    /* codigo para rediseï¿½ar pagina gastos envio */
    //
    //	if ( $('.gastos-envios').length) {
    //		var flag = false;
    //		if($('.radio-entrega .radioButton').attr('checked')){
    //			$('.radio-entrega .radioButton').parent().parent().toggleClass('item-activo');
    //			flag = true;
    //		}else if($('.radio-recogida .radioButton').attr('checked')){
    //			$('.radio-recogida .radioButton').parent().parent().toggleClass('item-activo');
    //		}
    //
    //		$('.radioButton').click(function() {
    //			if(flag){
    //		  		$('.radioButton').parent().parent().toggleClass('item-activo')
    //			}else{
    //				$(this).parent().parent().toggleClass('item-activo');
    //				flag = true;
    //			}
    //
    //		});
    //	}
    //	/* fin codigo para rediseÃ±ar pagina gastos envio */

	
    if ( $('#slider').length){
        $('#slider').nivoSlider({
            effect:'sliceDown',
            slices:15,
            animSpeed:500,
            pauseTime:8000,
            directionNav:true, //Next & Prev
            controlNav:true, //1,2,3...
            keyboardNav:true, //Use left & right arrows
            pauseOnHover:true, //Stop animation while hovering
            manualAdvance:false, //Force manual transitions
            beforeChange: function(){},
            afterChange: function(){},
            slideshowEnd: function(){} //Triggers after all slides have been shown
        });
        $('.nivo-controlNav').slideToggle();
        $('#slider').hover(
            function () {
                $('.nivo-controlNav').slideToggle();
            },
            function () {
                $('.nivo-controlNav').slideToggle();
            }
            )
    }

    /*votacion feedback*/
    if($('.estrellas').length){
        var rating = $('.estrellas');
        jQuery.each(rating, function() {
            var clickeado = false;
            var laClase;
            var botones = $(this).children();
            var ratingTxt = $(this).next();
            jQuery.each(botones, function(i) {
                $(this).hover(
                    function () {
                        $(this).parent().removeClass();
                        $(this).parent().addClass('estrellas index-' + i);
                        ratingTxt.children(':eq('+ (i + 1) +')').addClass('visible');
                        if(clickeado == false){
                            ratingTxt.children(':eq(0)').removeClass('visible');
                        }else if(elTexto != (i + 1)){
                            ratingTxt.children(':eq('+ elTexto +')').removeClass('visible')
                        }
                    },
                    function () {
                        if(clickeado == false){
                            $(this).parent().removeClass().addClass('estrellas');
                            ratingTxt.children(':eq('+ (i + 1) +')').removeClass('visible');
                            ratingTxt.children(':eq(0)').addClass('visible');
                        }else{
                            $(this).parent().removeClass().addClass('estrellas ' + laClase);
                            if(elTexto != (i + 1)){
                                ratingTxt.children(':eq('+ elTexto +')').addClass('visible');
                                ratingTxt.children(':eq('+ (i + 1) +')').removeClass('visible');
                            }
                        }
                    }
                    );
                $(this).click(function() {
                    clickeado = true;
                    laClase = 'index-' + i;
                    elTexto = i + 1;
                });
            });
        });
    }
        
    
    
    //acordeon detalle
    $(".accordion").accordion();
	
	        
    //tooltip comentarios
    if($(".contenedorComentarios .comentario .linkAzul").length){
        $(".comentario .linkAzul").dreamyTip({insertCSS: false});
    }
    //bloque tajetas
    if($(".tarjetas").length){
        estado = false;
        function abre(){
            var t = $("#tj");
            var bot = $("#bt");
            var elem = $("#oculto");

            if(estado == false){
                t.css({
                    'height': "66px",
                    backgroundColor: "#121c2a"
                });
                
                bot.css('background-position' ,"0 -15px");

                elem.css({
                    'visibility': "visible",
                    'display': 'block'
                })
                estado = true;

            }
            else{
                t.css({
                    'height': "40px",
                    backgroundColor: "transparent"
                });
                bot.css('background-position' ,"0 0px");
                elem.css({
                    'visibility': "hidden",
                    'display': 'none'
                })

                estado = false;
            }


        }
        $(".tarjetas-inner").bind('click', function(){
            abre();
        });
    }
    //tabs carrito
    if($(".tabs-carrito").length){
        $(".tabs-carrito .bt-op a").removeAttr('href').css('cursor','pointer');
        function openTab(element){
            if(!element.hasClass('activo')){
                element.parent().parent().find('.activo').addClass('close').removeClass('activo');
                element.addClass('activo').removeClass('close');
                if(element.hasClass('personaliza')){
                    element.parent().parent().parent().parent().find('.persoDesp').css('display','block');
                    element.parent().parent().parent().parent().find('.slider').css('display','none');
                }else{
                    element.parent().parent().parent().parent().find('.slider').css('display','block');
                    element.parent().parent().parent().parent().find('.persoDesp').css('display','none');
                }
            }else{
                if(element.hasClass('personaliza')){
                    element.parent().parent().parent().parent().find('.persoDesp').css('display','none');
                    element.parent().parent().find('.activo').addClass('close').removeClass('activo');
                }else{
                    element.parent().parent().parent().parent().find('.slider').css('display','none');
                    element.parent().parent().find('.activo').addClass('close').removeClass('activo');
                }
            }
        }
        $(".bt-op .personaliza, .bt-op .relacionados").bind('click', function(){
            openTab($(this));
        });
    }
    //columna movil que aparece en el carrito
    if($(".bloque-movil").length){
        var name = ".bloque-movil";
        var altoBloque = $(name).height();
        var bottomLimit = $(".content-full-bloque").height() - altoBloque;
        var altoTotal =$(".content-full-bloque").height() + 234;
        var menuYloc = null;
        menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")));
        
        $(window).scroll(function () {
            var theScrollTop = $(document).scrollTop();
            var bottomLimit2=altoBloque + theScrollTop;
            offset = menuYloc + theScrollTop;
            if(bottomLimit2 > altoTotal){
                offset = bottomLimit + 234;
            }
            if((menuYloc + theScrollTop) > 234){
                $(name).animate({
                    top:offset - 234
                },{
                    duration:500,
                    queue:false
                });
            }else{
                $(name).animate({
                    top:-5
                },{
                    duration:500,
                    queue:false
                });
            }
        });
    }
    if($(".bloque-form .bloque-radio").length){
       $(".bloque-form .bloque-radio:even").addClass('bloque-par');

       function setAcces(varActiveButton){
          if(varActiveButton){
                $('.btn-carrito').css('display','none');
                $('.btn-carrito-inactivo').css('display','block');
                $('.txt-error').css('display','block');

            }else{
                $('.btn-carrito').css('display','block');
                $('.btn-carrito-inactivo').css('display','none');
                $('.txt-error').css('display','none');
          }
        }
       $('.label-condiciones input').removeAttr('checked');
       
       function reloj(){
        $('.label-condiciones input').attr('checked','checked');
       }
       function reloj2(){
        $('.label-condiciones input').removeAttr('checked');
       }                
       var condicionTrue = true; 
       $('.label-condiciones').toggle(function(){
           setAcces(false);
           if(condicionTrue){ 
            setTimeout(reloj,100);
            condicionTrue = false
           }else{
            setTimeout(reloj2,100);
            condicionTrue = true
           }
       },function(){
           setAcces(true);
           if(!condicionTrue){           
            setTimeout(reloj2,100);
            condicionTrue = true
           }else{                        
            setTimeout(reloj,100);
            condicionTrue = false
           }      
       })                

    }
    //scripts para pagina de promos en detalle
    
    if($(".cont-promo").length){
        var promoSliders = $(".cont-slider-promo");
        promoSliders.each(function(i) {
            $(this).scrollIt({
                menuWidth: 95,
                itemWidth: 95,
                itemHeight:115,
                menuHeight: 150,
                scrollDuration: 400,
                scrollItwrapper: 'scrollItwrapperPromo' + i
            }).parent().parent().addClass('sliderParent');
            $('.scrollItwrapperPromo' + i + ' .cont-slider-promo').removeClass('bloque-img-promo').wrap('<div class="bloque-img-promo" />')
        })

        /*var contPromo = $(".cont-promo");

        contPromo.each(function(i) {
            $(this).addClass('contt'+i)
            var selects = $(this).find('select')
            selects.find('option:eq(0)').attr('selected','selected');
            var selectsChanges=0;
            selects.each(function(b){
                $(this).addClass('select'+b+i)
                var lastCurrentSelect = 0;
                $('.select'+b+i).change(function(){
                    if($('.select'+b+i).attr('value')!=0){
                        if(lastCurrentSelect==0){
                            selectsChanges++;
                            lastCurrentSelect=$(this).attr('value');
                        }
                    }else{
                        selectsChanges--;
                        lastCurrentSelect=$(this).attr('value');
                    }
                    if(selects.length==selectsChanges){
                        $('.contt'+i+' .btn-rojo-promo-inactivo').css('display','none')
                        $('.contt'+i+' .btn-rojo-promo').css('display','block')
                    }else{
                        $('.contt'+i+' .btn-rojo-promo-inactivo').css('display','block')
                        $('.contt'+i+' .btn-rojo-promo').css('display','none')
                    }
                })
            })
        })*/
    }
    
    

    if(($.browser.msie && parseInt(jQuery.browser.version) <= 6 )) {  // descomentar para otros navegadores ||($.browser.safari && parseInt(jQuery.browser.version) < 500)||($.browser.mozilla && jQuery.browser.version.substr(0,3)<"1.9")){
        $('#header, #content, #footer').wrapAll('<div class="bodyWrapper" />');

        //si quieren poner el html desde aca
        //hay que descomentar la linea que sigue
        //$('body').prepend('<div class="browserWarning"><div class="browserWarningInner"><p>Apreciado usuario de Motocard.com,<br />Hemos detectado que está accediendo a nuestra tienda Online con un explorador muy antiguo.<br />Puede que nuestra página y los procesos de compra no funcionen correctamente con esta versión.<br />Le ofrecemos estos links para actualizarlo. Si necesita ayuda, contacte con nosotros en el 902 102 802.</p><div class="browserWbtn"><a href="#" class="btn-ff">Firefox</a><a href="#" class="btn-chrome">Google Chrome</a><a href="#" class="btn-ie">Internet Explorer</a></div></div></div>');
        
        $('.browserWarning').css('height',0).animate({height: 180},2000);       
    }
    
    if ( $('#slider-tienda').length){
        $('#slider-tienda').nivoSlider({
            effect:'sliceDown',
            slices:8,
            animSpeed:5000,
            pauseTime:3000,
            directionNav:false, //Next & Prev
            controlNav:false, //1,2,3...
            keyboardNav:false, //Use left & right arrows
            pauseOnHover:false, //Stop animation while hovering
            manualAdvance:false, //Force manual transitions
            beforeChange: function(){},
            afterChange: function(){},
            slideshowEnd: function(){} //Triggers after all slides have been shown
        });
        $('.nivo-controlNav').slideToggle();
        $('#slider').hover(
            function () {
                $('.nivo-controlNav').slideToggle();
            },
            function () {
                $('.nivo-controlNav').slideToggle();
            }
        )
    }  
});

function reactivatootipcomentarios(){
    if($(".contenedorComentarios .comentario .linkAzul").length){
        $(".comentario .linkAzul").dreamyTip();
    }
}

function sliderCarrito(){
        if ( $('.col-Desc-pri .slider-detalle-carrito').length > 0 ) {
            $('.col-Desc-pri .slider-detalle-carrito').scrollIt({
                menuWidth: 520,
                itemWidth: 101,
                itemHeight:111,
                menuHeight: 120,
                scrollDuration: 400
            });
            $('.col-Desc-pri .slider-detalle-carrito').css({
                'width':'502px',
                'margin':'5px 7px'
            });

        }
    }

function customBlock(chk){
    
    var chek = document.getElementById(chk);
              
    if(chek.checked){
        $('body').addClass('iechecked');
        if($.browser.msie){           
            $('.bloque-custom .form-custom').animate({
                height:178
            }, 'fast', function(){
                $(this).css('overflow', 'auto')
                })
        }else{
            $('.bloque-custom .form-custom').animate({
                height:181
            }, 'fast', function(){
                $(this).css('overflow', 'auto')
                })
        }
        $('.bloque-lavado').animate({
            height:128
        }, 'fast');
        
    }else{
        $('body').removeClass('iechecked');
        $('.bloque-custom .form-custom').css('overflow', 'hidden')
        $('.bloque-custom .form-custom').animate({
            height:0
        }, 'fast')
        $('.bloque-lavado').animate({
            height:0
        }, 'fast')
           
    /*
if(chek.checked){
        if($.browser.msie){           
            $('.bloque-custom .form-custom').animate({
                height:178
            }, 'fast', function(){$(this).css('overflow', 'auto')})
        }else{
            $('.bloque-custom .form-custom').animate({
                height:181
            }, 'fast', function(){$(this).css('overflow', 'auto')})
        }
        $('.bloque-lavado').animate({
            height:128
        }, 'fast');
        $('.detalle-custom .columna-detalle-content .bg-custon-bottom').animate({
            bottom:-5
        }, 'fast');
        
    }else{
        $('.bloque-custom .form-custom').css('overflow', 'hidden')
        $('.bloque-custom .form-custom').animate({
            height:0
        }, 'fast')
        $('.bloque-lavado').animate({
            height:0
        }, 'fast')
        $('.detalle-custom .columna-detalle-content .bg-custon-bottom').animate({
           bottom:-1
           }, 'fast', function(){
              $(this).css('bottom',-4)
           })
*/          
           
    }
    ActivarPersonalizar();
    RedoImages();
}

        

