// 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>3) {
		
			
			
		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");
	      }
	    );
    }
    
//    /* 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:5000,
		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();
     }

});

function reactivatootipcomentarios(){
    if($(".contenedorComentarios .comentario .linkAzul").length){
        $(".comentario .linkAzul").dreamyTip();
     }
}

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();
}

        
