  function windowOpen( name, page, params ) {
    window.open( page, 'window' + name, params );
  }

  function cutWaiting( ) {
    if ( document.getElementById('espera') ) {
      document.getElementById('espera').style.display = 'none';
    }
  }
  function showWaiting( ) {
    if ( document.getElementById('espera') ) {
      document.getElementById('espera').style.display = '';
    }
  }


  var cats        = 0;
  var brands      = 0;

  function toggleSubs( index ) {

    var subs                        = document.getElementById( 'subs' + index );
    if ( subs ) {

      var icon                      = document.getElementById( 'icono' + index );

      if ( subs.style.display == 'none' ) {
        subs.style.display          = '';
        icon.src                    = 'img/icono-menos.gif';
      }
      else {
        subs.style.display          = 'none';
        icon.src                    = 'img/icono-mas.gif';
      }
    }
  }

  function togglePanel( name ) {

    var panel     = document.getElementById( name );
    if ( panel ) {

      var button  = document.getElementById( name + '_boton' );
      var content = document.getElementById( name + '_contenido' );

      if ( content.style.display == 'none' ) {
        content.style.display       = '';
        button.src                  = 'img/flecha-abierto.gif';
        panel.style.height          = parseFloat(content.style.height) + 28 + 'px';
        ark_do( '_ark.php?accion=setPanel&nombre=' + name + '&estado=on' );
      }
      else {
        panel.style.height          = '32px';
        content.style.display       = 'none';
        button.src                  = 'img/flecha-cerrado.gif';
        ark_do( '_ark.php?accion=setPanel&nombre=' + name + '&estado=off' );
      }
    }
  }

  function toggleDetails( id ) {

    showWaiting();
    var prod      = document.getElementById( 'prod' + id );
    if ( prod ) {

      var details = document.getElementById( 'detalle' + id );
      var button  = document.getElementById( 'boton' + id );
      var mini    = document.getElementById( 'mini' + id );

      if ( details.style.display == 'none' ) {
        ark_do( '_ark.php?accion=showProduct&id=' + id );
        details.style.display     = '';
        button.src                = 'img/icono-info-on.gif';
      }
      else {
        details.style.display     = 'none';
        button.src                = 'img/icono-info-off.gif';
        cutWaiting();
      }
    }
  }

  function setProducts( elem, value ) {
    ark_do( '_ark.php?accion=set' + elem + '&valor=' + value );
  }

  function setOn( type, count, index ) {
    showWaiting();
    var elem                      = document.getElementById( type + '[' + index + ']' );
    if ( elem ) {
      for ( var i = 0; i < count; i++ ) {
        if ( type.indexOf('_parent') > 0 ) {
          if ( document.getElementById( type.substring( 0, type.indexOf('_parent') ) + '[' + i + ']' ) )
            document.getElementById( type.substring( 0, type.indexOf('_parent') ) + '[' + i + ']' ).className = 'panelLink';
          if ( document.getElementById( type + '[' + i + ']' ) )
            document.getElementById( type + '[' + i + ']' ).className        = 'panelLinkParent';
        }
        else {
          if ( document.getElementById( type + '[' + i + ']' ) )
            document.getElementById( type + '[' + i + ']' ).className        = 'panelLink';
          if ( document.getElementById( type + '_parent[' + i + ']' ) )
            document.getElementById( type + '_parent[' + i + ']' ).className = 'panelLinkParent';
        }
      }
      elem.className              = 'panelLinkOn';
    }
  }

  function setQuantity( id, action, cant, reload ) {

    if ( !cant && cant != 0 ) {
      var cant                    = document.getElementById( 'cant' + id );
      if ( parseFloat(cant.value) > 0 ) {
        if ( action == 'add' )
          cant.value              = parseFloat(cant.value) + 1;
        if ( action == 'sub' )
          cant.value              = parseFloat(cant.value) - 1;
      }
      else {
        if ( action == 'add' )
          cant.value              = 1;
        if ( action == 'sub' )
          cant.value              = 0;
      }
      var cant                    = cant.value;
    }

    var content = document.getElementById('carrito_contenido' );
    if ( content.style.display == 'none' ) {
      togglePanel('carrito');
    }
    ark_do( '_ark.php?accion=shop&id=' + id + '&cant=' + cant + '&reload=' + reload );
  }

  function validar( form ) {

    var error = false;
    var first = -1;
    var chain = '';

    for ( var i = 0; i < form.elements.length; i++ ) {
      if ( form.elements[i].title != '' && form.elements[i].value == '' ) {
        if ( first < 0 ) {
          first   = i;
        }
        chain = chain + '- ' + form.elements[i].title + '\n';
        error = true;
      }
    }

    if ( error ) {
      alert( 'Los siguientes campos no pueden quedar sin completar:\n' + chain );
      form.elements[first].focus();
      return false;
    }
    else {
      return true;
    }
  }

  function validarContacto( ) {
    if ( !document.contacto.contacto.value.length || !document.contacto.email.value.length || !document.contacto.empresa.value.length ) {
      alert( 'Debe completar los campos requeridos antes de proceder con el envío del formulario.' );
      return false;
    }
    else {
      return true;
    }
  }