/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function getNoticias(cA) {
  ajax = objetoAjax();

  fN = document.getElementById('Buscar').value;

//  alert('[' + fN + '][' + cA + ']')

  if (ajax) {
    ajax.onreadystatechange = function() {
      if (ajax.readyState == 1  || ajax.readyState == "loading") {
        document.getElementById('listaNoticias').innerHTML = "<br /><br /><center><img src='./imagenes/cargando.gif' width='32' height='32' /><br /><br /></center>";
      }
      if (ajax.readyState == 4 || ajax.readyState == "complete") {
        if (ajax.status == 200) {
//          alert(ajax.responseText);
          document.getElementById('listaNoticias').innerHTML = ajax.responseText;
        }
        else {
          alert("There was a problem while using XMLHTTP:\n" + ajax.statusText);
        }
      }
    }

    ajax.open("GET", "noticiasLista.php?fN="+fN+"&cA="+cA, true);
    ajax.send(null);
  }		 
}

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function validarFoto() {
  var foto = document.getElementById("userfile_foto").value;

  if (textoNulo(foto)) {
    alert('Debe seleccionar una foto para agregar \n');
    return false;
  }

  if (foto.split(" ").length > 1) {
    alert('El nombre de la foto no puede tener espacios en blanco. \n');
    return false;
  }

  var extP = new Array(".jpg", ".JPG");
  if (!extensionOK(foto, extP)) {
    alert('La extensión de la foto no es válida. Debe ser .jpg \n');
    return false;
  }

  return true;
}

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/
function validarNoticia(op, form) {
  var str = 'Por favor, revise los siguientes datos obligatorios: \n';
  var flag = false;
  var archivo = '';

  if (textoNulo(form.titulo.value)) {
    str = str + '  - Titulo \n';
    flag = true;
  }

  if (textoNulo(form.corta.value)) {
    str = str + '  - Descripción corta \n';
    flag = true;
  }

  if (op == 1) {
    if (textoNulo(form.foto_portada.value)) {
      str = str + '  - Foto portada \n';
      flag = true;
    }
  }
  else {
    if (textoNulo(form.foto_portada.value) && textoNulo(form.foto_actual.value)) {
      str = str + '  - Foto portada \n';
      flag = true;
    }
  }

  if (flag) {
    alert(str);
    return false;
  }

//  alert('[' + op + '][' + form.foto_portada.value + '][' + form.foto_actual.value + ']' );

  if (op == 1) {
    archivo = form.foto_portada.value;
  }
  else {
    if (textoNulo(form.foto_portada.value)) {
      archivo = form.foto_actual.value;
    }
    else {
      archivo = form.foto_portada.value;
    }
  }

  if (archivo.split(" ").length > 1) {
    alert('El nombre de la foto de portada no puede tener espacios en blanco. \n');
    return false;
  }

//  alert('[' + op + '][' + archivo + ']' );

  var extP = new Array(".jpg", ".JPG");
  if (!extensionOK(archivo, extP)) {
    alert('La extensión de la foto de portada no es válida. Debe ser .jpg \n');
    return false;
  }

  return true;
}

/*----------------------------------------------------------------------*/
/*                                                                      */
/*----------------------------------------------------------------------*/

