// -----------------------------------------------------------------------------

function cambiarImagen (obj, url) {
  obj.src = url;
}

function preloadImagen (url) {
  picture = new Image (1, 1);
  picture.src = url;
}

function cambiarClase (obj, clase) {
  var obj = document.getElementById (obj);
  obj.className = clase;
}

// -----------------------------------------------------------------------------

function mostrarCuadroDetalles (obj) {
  ocultarCuadroDetalles ();
  var a = document.getElementById ('cuadroDetalle');
  a.style.display = 'block';
  a.style.left = obj.offsetLeft + 'px';
  a.style.top = obj.offsetTop + 'px';
  var i = document.getElementById ('verDetalle');
  i.onclick = function () {
    location.href = 'detalle_producto.asp?id='+obj.innerHTML;
  }
  var i = document.getElementById ('hojaSeguridad');
  i.onclick = function () {
    location.href = 'seguridad_producto.asp?id='+obj.innerHTML;
  }
}

function ocultarCuadroDetalles () {
  var a = document.getElementById ('cuadroDetalle');
  a.style.display = 'none';
}

function mostrarComboProductos (obj) {
  var a = document.getElementById ('comboProductos');
  if (a.style.display == 'block') {
    ocultarComboProductos ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 93) + 'px';
    if (document.all) {
      a.style.top = (obj.offsetTop + 128) + 'px';
    } else {
      a.style.top = (obj.offsetTop + 123) + 'px';
    }
  }
}

function mostrarComboProductos2 (obj) {
  var a = document.getElementById ('comboProductos');
  if (a.style.display == 'block') {
    ocultarComboProductos ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 191) + 'px';
    if (document.all) {
      a.style.top = (obj.offsetTop + 188) + 'px';
    } else {
      a.style.top = (obj.offsetTop + 183) + 'px';
    }
  }
}

function mostrarComboProductos3 (obj) {
  var a = document.getElementById ('comboProductos');
  if (a.style.display == 'block') {
    ocultarComboProductos ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 93) + 'px';
    if (document.all) {
      a.style.top = (obj.offsetTop + 159) + 'px';
    } else {
      a.style.top = (obj.offsetTop + 154) + 'px';
    }
  }
}


function ocultarComboProductos () {
  var a = document.getElementById ('comboProductos');
  a.style.display = 'none';
}

function mostrarAmpliarNoticia (obj) {
  var a = document.getElementById ('ampliarNoticia');
  if (a.style.display == 'block') {
    ocultarAmpliarNoticia ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 820) + 'px';
    a.style.top = (obj.offsetTop + 205) + 'px';
  }
}

function ocultarAmpliarNoticia () {
  var a = document.getElementById ('ampliarNoticia');
  a.style.display = 'none';
}

function mostrarComboPrensa () {
  var a = document.getElementById ('comboProductos');
  if (a.style.display == 'block') {
    ocultarComboPrensa ();
  } else {
    a.style.display = 'block';
  }
}

function ocultarComboPrensa () {
  var a = document.getElementById ('comboProductos');
  a.style.display = 'none';
}

function mostrarAmpliarNoticia2 (obj) {
  var a = document.getElementById ('ampliarNoticia');
  if (a.style.display == 'block') {
    ocultarAmpliarNoticia ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 810) + 'px';
    a.style.top = (obj.offsetTop + 209) + 'px';
  }
}

function mostrarAmpliarNoticia3 (obj) {
  var a = document.getElementById ('ampliarNoticia');
  if (a.style.display == 'block') {
    ocultarAmpliarNoticia ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 340) + 'px';
    a.style.top = (obj.offsetTop + 269) + 'px';
  }
}

function mostrarBajarNota (obj) {
  var a = document.getElementById ('ampliarNoticia');
  if (a.style.display == 'block') {
    ocultarAmpliarNoticia ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 100) + 'px';
    a.style.top = (obj.offsetTop + 295) + 'px';
  }
}

function mostrarBajarNota2 (obj) {
  var a = document.getElementById ('ampliarNoticia');
  if (a.style.display == 'block') {
    ocultarAmpliarNoticia ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 423) + 'px';
    a.style.top = (obj.offsetTop + 295) + 'px';
  }
}

function mostrarBajarNota3 (obj) {
  var a = document.getElementById ('ampliarNoticia');
  if (a.style.display == 'block') {
    ocultarAmpliarNoticia ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 100) + 'px';
    a.style.top = (obj.offsetTop + 556) + 'px';
  }
}

function mostrarBajarNota4 (obj) {
  var a = document.getElementById ('ampliarNoticia');
  if (a.style.display == 'block') {
    ocultarAmpliarNoticia ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 423) + 'px';
    a.style.top = (obj.offsetTop + 556) + 'px';
  }
}

function mostrarBajarNota5 (obj) {
  var a = document.getElementById ('ampliarNoticia');
  if (a.style.display == 'block') {
    ocultarAmpliarNoticia ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 100) + 'px';
    a.style.top = (obj.offsetTop + 750) + 'px';
  }
}

function mostrarBajarNota6 (obj) {
  var a = document.getElementById ('ampliarNoticia');
  if (a.style.display == 'block') {
    ocultarAmpliarNoticia ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 423) + 'px';
    a.style.top = (obj.offsetTop + 750) + 'px';
  }
}

function mostrarBajarNota7 (obj) {
  var a = document.getElementById ('ampliarNoticia');
  if (a.style.display == 'block') {
    ocultarAmpliarNoticia ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 100) + 'px';
    a.style.top = (obj.offsetTop + 910) + 'px';
  }
}

function mostrarBajarNota8 (obj) {
  var a = document.getElementById ('ampliarNoticia');
  if (a.style.display == 'block') {
    ocultarAmpliarNoticia ();
  } else {
    a.style.display = 'block';
    a.style.left = (obj.offsetLeft + 423) + 'px';
    a.style.top = (obj.offsetTop + 910) + 'px';
  }
}

// -----------------------------------------------------------------------------

function ocultarObjeto (obj) {
  document.getElementById (obj).style.visibility = 'hidden';
  try {
    WCH.Discard (obj);
  } catch (e) { }
}

function mostrarObjeto (obj) {
  try {
    WCH.Apply (obj, true);
  } catch (e) { }
  document.getElementById (obj).style.visibility = 'visible';
}

function validarEMail (str) {

  var at = "@"
  var dot = "."
  var lat = str.indexOf (at)
  var lstr = str.length
  var ldot = str.indexOf (dot)

  if (lstr == 0) return true;
  if (str.indexOf (at) == -1) return false;
  if (str.indexOf (at) == -1 || str.indexOf (at) == 0 || str.indexOf (at) == lstr) return false;
  if (str.indexOf (dot) == -1 || str.indexOf (dot) == 0 || str.indexOf (dot) == lstr) return false;
  if (str.indexOf (at, (lat+1)) != -1) return false;
  if (str.substring (lat-1, lat) == dot || str.substring (lat+1, lat+2) == dot) return false;
  if (str.indexOf (dot, (lat+2)) == -1) return false;
  if (str.indexOf (" ") != -1) return false;

  return true

}

function mascaraFecha (obj, evt) {

  var charCode = (evt.which) ? evt.which : event.keyCode
  var valor = true;
  if (charCode > 31 && (charCode < 48 || charCode > 57)) valor = false;
  if ((obj.value.length == 2) || (obj.value.length == 5)) obj.value = obj.value + "/";
  return (valor);

}