  function showTag(tagId){
    new Effect.Opacity(tagId, { from: 0, to: 1, duration: 0.4});
    new Effect.Opacity(tagId, { from: 1, to: 1, duration: 1.5, queue: 'end'});
    new Effect.Opacity(tagId, { from: 1, to: 0, duration: 0.4, queue: 'end'});
  }

  function setCatalogCookie(page, initial)
  {
    document.cookie = 'artistsPage=' + page;
    document.cookie = 'artistsInitial=' + initial;
  }

  function tabSelect(im){
    if(!document.all)
      var imgs = document.getElementsByName(im.name);
    else{
      var allimgs = document.getElementsByTagName('img');
      var imgs = new Array();
      for(var i = 0; i < allimgs.length; i++)
        if(allimgs[i].name == im.name)
    	    imgs.push(allimgs[i]);
    }
    for(var i = 0; i < imgs.length; i++){    
      if(imgs[i].id == im.id){
        imgs[i].style.display = 'none';
        imgs[i].previousSibling.style.display = 'block';
      }else{
        imgs[i].style.display = 'block';
        imgs[i].previousSibling.style.display = 'none';
      }
    }
  }

  function showWraps(baseId){
    if(!document.wrapsView)
      new Ajax.Request('/gift_wraps/index',{onSuccess: setWrapsView, asynchronous: false });
    document.wrapsView.reset();
    document.wrapsView.setFormId('pf_'+baseId);
    document.wrapsView.setUpdate(baseId);
    document.getElementById('ws_'+baseId).innerHTML = document.wrapsView.html;
    Effect.toggle('ws_'+baseId,'blind', {duration: 0.5});
  }

  function setWrapsView(response){
        document.wrapsView = new Object();
        document.wrapsView.basehtml = response.responseText;
        document.wrapsView.reset = function (){
                                     this.html = this.basehtml;
                                   }
        document.wrapsView.setFormId = function (formId){
                                          this.html = this.html.replace(/---idform---/g, formId);
                                        }
        document.wrapsView.setUpdate = function (update){
                                          this.html = this.html.replace(/---update---/g, update);
                                        }
  }

  function hideWraps(baseId){
    Effect.toggle('ws_'+baseId,'blind', {duration: 0.5});
  }

  function showWrapsIE(baseId){
    var e = document.getElementById('ws_'+baseId);
    e.style.display = (e.style.display == 'block')?'none':'block';
  }

  function hideWrapsIE(){
    var e = document.getElementsByTagName('div');
    for(i = 0; i < e.length; i++){
    if(e[i].name == 'ws')
      e[i].style.display = 'none';
    }
  }

  function productAdd(baseId){
    var prodForm = document.getElementById('pf_' + baseId);
    new Ajax.Updater(baseId, '/templates/productListAddToCart', {asynchronous:true, evalScripts:true, onComplete:function(request, json){new Ajax.Updater('cart','/index.php/cart/minicart');showTag(baseId);}, parameters:Form.serialize(prodForm)}); return false;
  }
  
  function returnEvent(e){
   var event = e || window.event;
   return event;
  }

  function returnKeyStroke(e){
    var event = returnEvent(e);
    return event.charCode || event.keyCode;
  }

  function isValidChar(char){
    var validChars = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyzáéíóúÁÉÍÓÚ1234567890,.:;!?@#_/" + String.fromCharCode(8,13,32,35,36,37,38,39,40,41,46,161,191);
    if(validChars.indexOf(String.fromCharCode(char)) != -1)
	return true;
    else
	return false;
  }
  
  function pbbtdisplay(counter){
    var nds = counter.form.childNodes;
    for(i = 0; i < counter.form.childNodes.length; i++){
	if(counter.form.childNodes[i].name == 'bton')
	    var bton = counter.form.childNodes[i];
	if(counter.form.childNodes[i].name == 'btoff')
	    var btoff = counter.form.childNodes[i];
    }
    if(counter.value == 300){
	bton.style.display = 'none';
	btoff.style.display = 'block';
    }else{
	bton.style.display = 'block';
	btoff.style.display = 'none';
    }
  }

  function cttavalidate(e){
    var char = returnKeyStroke(e);
    var event = returnEvent(e);
    var ctta = event.target || event.srcElement;

    if(ctta.value.length == 300 && (char != 8 && char != 46 && !(char >= 35 && char <=40)))
	return false;

    if(isValidChar(char))
	return true;

    return false;
  }

  function ctcounter(e){
    var event = returnEvent(e);
    var ctta = event.target || event.srcElement;
    ctta.form.counter.value = 300 - ctta.value.length;
    pbbtdisplay(ctta.form.counter);
  }