$.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
  while(x<c.length){var m=r.exec(c.substr(x));
    if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
    }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
    o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
  while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
});

$(document).ready(function(){

$('.msgAlert').fadeOut('slow').fadeIn('slow').fadeOut('slow').fadeIn('slow');

$('a.zoomImage').lightBox();

$.get("/cuidado-integral-masculino/ajax/banners/",
 function(data){
   randomnumber=Math.floor(Math.random()*$(data).find('a').size());
   $("#bannerRandom").append($(data).find("a:eq("+randomnumber+")"));
 });

$('input:text, textarea').focus(function(){$(this).addClass('inputSelected')})
$('input:text, textarea').blur(function(){$(this).removeClass('inputSelected')})



$("#newsSummaryList").load('/cuidado-integral-masculino/ajax/newsSummary/?'+Date.parse(Date()),'',function(){
  $('.noticia img').click(function(){
    $(this).parent().parent().find('.newsSummary').toggle();
    if($(this).attr('src').indexOf('goto') != -1)
	  $(this).attr('src',$(this).attr('src').replace('goto','collapse'))
	else
	  $(this).attr('src',$(this).attr('src').replace('collapse','goto'))
  })
});

$("#theBrandSelector").load('/cuidado-integral-masculino/ajax/marcasDropDown/?'+Date.parse(Date()),'',function(){
  $('#brandSelector').change(function(){
     document.location.href=jquerySiteURL+ '/' + 'cuidado-integral-masculino/inicio/marcas-de-cosmetica-y-accesorios-para-hombres/'+ $(this).val() + '/'
  })
});

$("#problemaSolucionDD").load('/cuidado-integral-masculino/ajax/solucionesDropDown/?'+Date.parse(Date()),'',function(){
  $('.listaProblemas').change(function(){
     document.location.href=jquerySiteURL+ '/' + 'cuidado-integral-masculino/inicio/soluciones-para-cuidado-belleza-y-estetica-masculino/'+ $(this).val()
  })
});

$(".menuTools li").hoverIntent(function() {
$(this).children("span").stop(true, true).animate({opacity: "show", top: "-45"}, "slow");
}, function() {
$(this).children("span").animate({opacity: "hide", top: "-55"}, "fast");
});

});

$(document).ready(function(){

// loading random banner
// var randomnumber=Math.floor(Math.random()*((banners.length-1)/2))+1;

// $("#bannerRandom").html("<a href=\""+banners[randomnumber*2-2]+"\"><img src=\""+banners[randomnumber*2-1]+"\" alt=\"\" /></a>");

// $("#bannerRandom a").show();


$('.menuTools li').click(function() {

var theIndex = $(this).prevAll("li").size();
$(".menuTools li").removeClass("selected");
$(this).addClass("selected");

$("#allTools").children("div:visible").slideUp("fast",function() {

$("#allTools").children("div:eq("+theIndex+")").slideDown("fast");
});


});
});



$(document).ready(function(){

if  ($("div.page").size() > 1)
$("#paginado, #paginado-Bottom").show();


 if ($("#allProds").length != 0)
{
  var totPages = $("#allProds div.page").size();
$("#pageTot, #pageTot-Bottom").text(totPages);
 var thePageNow = ($("#allProds").css("left").replace("px","") / (-710)) + 1;
 $("#pageNo, #pageNo-Bottom").text(thePageNow);
 var contWidth = totPages * 710;
  $("#allProds").css("width",""+contWidth+"px");

}


//FIRST
$('#paginado li:eq(0), #paginado-Bottom li:eq(0)').click(function() 
{

 $("#pageNo, #pageNo-Bottom").text("1");
    $("#allProds").animate({ left : '0px'}, 1500 );
 
});

//NEXT
$('#paginado li:eq(2), #paginado-Bottom li:eq(2)').click(function() 
{
if (!($("#allProds").is(":animated")))
{
var marginNow = $("#allProds").css("left"); 
if ((parseFloat(marginNow))!=(-1*(contWidth-710)))
{

 var thePageNow = ($("#allProds").css("left").replace("px","") / (-710)) + 2;
 $("#pageNo, #pageNo-Bottom").text(thePageNow);

   var marginN = (parseFloat(marginNow) -710);
   marginNow = marginN + "px";
    $("#allProds").animate({ left : marginNow },  1000 );
 }
 }
});

//PREV
$('#paginado li:eq(1), #paginado-Bottom li:eq(1)').click(function() 
{
if (!($("#allProds").is(":animated")))
{
var marginNow = $("#allProds").css("left");

if (parseFloat(marginNow)!=0)
{

var thePageNow = ($("#allProds").css("left").replace("px","") / (-710));
 $("#pageNo, #pageNo-Bottom").text(thePageNow);

    var marginN = (parseFloat(marginNow) +710);
    marginNow = marginN + "px";

    $("#allProds").animate({ left : marginNow }, 1000 );
 }
}
});
 
// LAST
$('#paginado li:eq(3), #paginado-Bottom li:eq(3)').click(function() 
{
 
 $("#pageNo, #pageNo-Bottom").text(totPages);

var marginN = contWidth-710;

marginNow = (-1)*marginN + "px";



    $("#allProds").animate({ left : marginNow }, 1500 );
 
});

});

$(document).ready(function(){
$('.external').click(function() {
window.open($(this).attr("href"),null);
return false;
})});

$(document).ready(function(){

$("#brandSelector").change(function(){
  var theSelected = $("#brandSelector option:selected").val();
if (theSelected != '' && theSelected != null)
   window.location.href = jquerySiteURL + "/cuidado-integral-masculino/inicio/marcas-de-cuidado-masculino/"+theSelected+"/";

});

$(".detallesCesta").click(basketClick);

  $("#searchBox #q").click(function(){
    $(this).val("");
  });


});

// **** MOUSE OVER OBJECTS *****

$(document).ready(function(){

    var srcNow = "";
$(".objHover").hover(
      function () {
       srcNow = $(this).attr("src");
       srcNow = srcNow.replace(".gif","_over.gif").replace(".jpg","_over.jpg").replace(".png","_over.png");
        $(this).attr("src",srcNow);
      }, 
      function () {
       srcNow = $(this).attr("src");
       srcNow = srcNow.replace("_over.gif",".gif").replace("_over.jpg",".jpg").replace("_over.png",".png");
        $(this).attr("src",srcNow);
      }
    );

});



$(document).ready(function(){

$("#tablaTallas img").click(function(){
if ($("#tablaConversion").is(":visible")) { 

$("#tablaTallas span").html("Ver Tabla<br />de Tallas");
$("#tablaConversion").slideUp();

}
else
{
$("#tablaTallas span").html("Ocultar Tabla<br />de Tallas");
$("#tablaConversion").slideDown();
}
  });


var theThumbURL = "";
  $("#typeSelector div").each(function(i){

   theThumbURL = $(this).children("img").attr("src");
   theThumbURL = "url(" + theThumbURL + ")";

   $(this).css("background-image",""+theThumbURL+"");

});

 $("#sizeSelector div div").click(function(){
  
      
   $("#sizeSelector h5 strong").text($(this).attr('title'));
       if (!($(this).hasClass("Selected")))
    {
        $(this).prevAll("div").removeClass("Selected");
        $(this).nextAll("div").removeClass("Selected");   
       $(this).addClass("Selected");
    }
  });


  $("#typeSelector div").click(function(){

        $("#typeSelector h5 strong").text($(this).attr('title'));

    if (!($(this).hasClass("Selected")))
    {
        $(this).prevAll("div").removeClass("Selected");
        $(this).nextAll("div").removeClass("Selected");
    var classNow = $(this).attr("class");
       $(this).addClass("Selected");

  var itemN = $(this).prevAll("div").size();


// var theSizeSelected = $('#sizeSelector div.sizesBlock:eq('+itemN+')').children('div.Selected').attr('title');

 var theSizeSelected = $("#sizeSelector h5 strong").text();

 var sizeExists = $('#sizeSelector div.sizesBlock:eq('+itemN+')').children("div[title='" +theSizeSelected+ "']");

if (sizeExists.size() == 0)
{

$('#sizeSelector div.sizesBlock:eq('+itemN+')').children("div").removeClass('Selected');
$("#sizeSelector h5 strong").text("");

}
else
{

 $('#sizeSelector div.sizesBlock:eq('+itemN+')').children("div[title='" +theSizeSelected+ "']").addClass('Selected');
 $('#sizeSelector div.sizesBlock:eq('+itemN+')').children("div[title='" +theSizeSelected+ "']").prevAll().removeClass('Selected');
 $('#sizeSelector div.sizesBlock:eq('+itemN+')').children("div[title='" +theSizeSelected+ "']").nextAll().removeClass('Selected');
}

   $("#sizeSelector div.sizesBlock").removeClass("chosen");

  $('#sizeSelector div.sizesBlock:eq('+itemN+')').addClass("chosen");



  $(".productPic img.Selected").fadeOut('fast',
      function(){
      $(this).removeClass("Selected"); $(".linksZoomProducto li.Selected").removeClass("Selected"); 
    $(".productPic img."+classNow+"").fadeIn('fast',function(){$(this).addClass("Selected"); $(".linksZoomProducto li."+classNow+"").addClass("Selected"); });
      });
   

    }


  });


});


function isFilled(searchWord)
{

if (document.getElementById('search_id').value == '' || document.getElementById('search_id').value == searchWord)
{
document.getElementById('search_id').value='';
document.getElementById('search_id').focus();
return false;
}
else
return true;
}

function basketClick()
{
  if ($("#shoppingBasket").is(":visible"))
  {
    $("#shoppingBasket").slideUp("slow");
    $(".detallesCesta").text("Ver detalles");
  }
  else
  {
    $(".detallesCesta").text("Ocultar detalles");
    $("#shoppingBasket").slideDown("slow");
  }
}

jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"],
{
    random: function(a, i, m, r) {
        if (i == 0) {
            jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
        };
        return i == jQuery.jQueryRandom;
    }
});

$(document).ready(function(){

/* send to a friend */

 $('#sendtoFriend_your_name, #sendtoFriend_their_name, #sendtoFriend_their_email').hide();
 $('#webpacFormRecommend').submit(function(){
  var d = new Date()
  var isOK=true, errMsg=''
  if($('#sendtoFriend_your_name').val() + $('#sendtoFriend_their_name').val() + $('#sendtoFriend_their_email').val() == '')
  {
    if ($('#erbmonut').val() == '')
	  errMsg = 'Por favor introduzca tu nombre.';
 	
    if ($('#erbmonogima').val() == '')
	  errMsg = 'Por favor introduzca el nombre de tu amigo.';
 	
	if ($('#liameus').val() == '')
	  errMsg = 'Por favor introduzca el email de tu amigo.';
 	
	if(errMsg=='')
	{   $('.recomiendaBlock h4').load('/cuidado-integral-masculino/ajax/recomendar/?yourname='+$.URLEncode($('#erbmonut').val())+'&friendname='+$.URLEncode($('#erbmonogima').val())+'&friendmail='+$.URLEncode($('#liameus').val())+'&url='+$.URLEncode(document.location.href)+'&nocache='+Date.parse(d)+'/')
	$('.recomiendaBlock h4').fadeOut().fadeIn().fadeOut().fadeIn();
	$('#liameus, #erbmonogima, #erbmonut').val('');
	}
	else
	  alert(errMsg)
	
  }
  
return false;
})


/* send to a friend */



  $('.addButton').click(function(){
      theImage = $(this).parent().parent().find('.imgProd img:not(.sello)')
      theNewImage = theImage.clone().appendTo('body').attr('alt','').css({'position':'absolute','top':theImage.offset().top,'left':theImage.offset().left})
      theNewImage.animate({'top':$('#cesta').offset().top,'left':$('#cesta').offset().left,'opacity':'0'},1000,function(){
	  $(this).remove();
	  $('#cesta').fadeOut('slow',function(){$(this).fadeIn('slow',function(){$('#cesta').fadeOut('slow',function(){$(this).fadeIn('slow')})})})
	  
    })
  })

  $('.addButton2').click(function(){
  if (!checkExtraData())
{
 $(".productDetails").css("margin-left","10px");
 $(".sizeandtype").css("padding-left","5px").css("padding-right","0px");

$(".sizeandtype").append("<h4 class=\"alertmsg\">Por favor selecciona una talla y un tipo para añadir este producto a tu cesta</h4>");



var myApi = $(".sizeandtype").expose({

        api: true,
        closeOnClick: true,
        onLoad: function(event) {   


$(".sizesBlock div").click(function(){
    myApi.close(); 
});
  
       $(".sizeandtype h4").fadeOut().fadeIn().fadeOut().fadeIn();
    } ,


        onClose: function(event) {     
        $(".productDetails").css("margin-left","15px");
 $(".sizeandtype").css("padding-left","0px").css("padding-right","0px"); 
        $(".alertmsg").remove(); 
    } 
     
   }).load(); 




        return;
}
      theImage = $('.productPic img.Selected')
      theNewImage = theImage.clone().appendTo('body').attr('alt','').css({'position':'absolute','top':theImage.offset().top,'left':theImage.offset().left})
      theNewImage.animate({'top':$('#cesta').offset().top,'left':$('#cesta').offset().left,'opacity':'0'},1000,function(){
	  $(this).remove();
	  $('#cesta').fadeOut('slow',function(){$(this).fadeIn('slow',function(){$('#cesta').fadeOut('slow',function(){$(this).fadeIn('slow')})})})
	  
    })
  })


})

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function blink(elementid)
{
  $("#"+elementid).fadeOut().fadeIn().fadeOut().fadeIn();
}

