var en_marcha = false;
var ie5 = (document.getElementById && document.all);
var ns6 = (document.getElementById && !document.all);
var totalPreguntas = 0;
var totalRespuestas = new Array();
var totalEnlaces = 0;

function cambiarEstilo(id, cssKO, cssOK){
  if (id == 'ultima') {
    document.getElementById(id).className = cssOK;
    document.getElementById('visto').className = cssKO;
    document.getElementById('votado').className = cssKO;
  }
  if (id == 'visto') {
    document.getElementById(id).className = cssOK;
    document.getElementById('ultima').className = cssKO;
    document.getElementById('votado').className = cssKO;
  }
  if (id == 'votado') {
    document.getElementById(id).className = cssOK;
    document.getElementById('visto').className = cssKO;
    document.getElementById('ultima').className = cssKO;
  }
}

function lomas(accion){
  if (en_marcha) {
    document.getElementById('listados').innerHTML = 'Hay un proceso pendiente, espere a que termine porfavor.<br>Enviando...'
    return;
  }
  en_marcha = true;
  document.getElementById('listados').innerHTML = 'Enviando...'
  new Ajax.Request('acciones_ajx.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        document.getElementById('listados').innerHTML = transport.responseText;
        en_marcha = false;
      }
    },
    parameters: {
      accion: accion,
      ptll: 'M_un_vistazo_ajax.tpl'
    },
    asynchronous: true
  });
  
}

function limpiarBuscadorAvanzado(){
  document.getElementById('bus_fecha_desde').value = '';
  document.getElementById('bus_fecha_hasta').value = '';
  var contador = 1;
  var contador2 = 1;
  var identificador = '';
  while (1) {
    identificador = 'bus_secciones' + contador;
    if (document.getElementById(identificador) == null) {
      break;
    }
    if (document.getElementById(identificador).type == 'checkbox') {
      document.getElementById(identificador).checked = false;
      contador2++;
    }
    contador++;
  }
}

function buscarPalabras(bus_avanzado, capa, menu_id, paginaActual, bus_palabras, fechadesde, fechahasta, secciones){
  var capa = document.getElementById(capa);
  var buscador = document.getElementById('buscador_avanzado');
  var palabras = '';
  if(paginaActual == ''){
    paginaActual = 1;
  }

  if(bus_palabras == ''){
    palabras = document.getElementById('bus_palabras_s').value;
  }else{
    palabras = bus_palabras;
  }
  var parametroseccionstr = secciones;
  if (true || bus_avanzado == '1') {
    if(fechadesde == '' && document.getElementById('bus_fecha_desde') != null){
      fechadesde = document.getElementById('bus_fecha_desde').value;
    }
    if(fechahasta == '' && document.getElementById('bus_fecha_hasta') != null){
      fechahasta = document.getElementById('bus_fecha_hasta').value;
    }
    if (secciones == '') {
      var contador = 1;
      var contador2 = 1;
      var identificador = '';
      while (1) {
        identificador = 'bus_secciones' + contador;
        if (document.getElementById(identificador) == null) {
          break;
        }
        if (document.getElementById(identificador).type == 'checkbox' && document.getElementById(identificador).checked) {
          if (contador2 > 1) {
            parametroseccionstr += ', ';
          }
          parametroseccionstr += document.getElementById(identificador).value;
          contador2++;
        }
        contador++;
      }
    }
  }
  if(palabras == ''){
    return false;
  }
  if (en_marcha) {
    return;
  }
  en_marcha = true;
  capa.innerHTML = '<br><br>Enviando peticion...'
  
  // Enviamos la peticion
  new Ajax.Request('acciones_ajx.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        capa.innerHTML = transport.responseText;
        buscador.className = 'mostrar_buscador';
        en_marcha = false;
      }
    },
    parameters: {
      accion: 'RESULTBUS',
      avanzado: bus_avanzado,
      bus_palabras: palabras,
      secciones: parametroseccionstr,
      fechadesde: fechadesde,
      fechahasta: fechahasta,
      paginaSel: paginaActual,
      menu_id: menu_id
    },
    asynchronous: true
  });
}

function gestionaCapaBloqueo(bloquear, capaBloqueo, capaDatos, cssBloqueo, cssDatos){
	if(bloquear == 1){
		document.getElementById(capaBloqueo).style.width = '0px';
		document.getElementById(capaBloqueo).style.height = '0px'
		document.getElementById(capaBloqueo).className = cssBloqueo;
		document.getElementById(capaDatos).className = cssDatos;
	}else{
		var anchoCapa = document.body.scrollWidth;
		var altoCapa = document.body.scrollHeight;
		var anchoInner = (ie5)?document.documentElement.clientWidth:window.innerWidth;
		var altoInner = (ie5)?document.documentElement.clientHeight:window.innerHeight;
		if(anchoCapa < anchoInner){
			anchoCapa = anchoInner;
		}
		if(altoCapa < altoInner){
			altoCapa = altoInner;
		}
		document.getElementById(capaBloqueo).style.width = anchoCapa +20 + 'px';
		document.getElementById(capaBloqueo).style.height = altoCapa + 200 + 'px';
		document.getElementById(capaBloqueo).className = cssBloqueo;
		document.getElementById(capaDatos).className = cssDatos;
	}
}

function formularioAutenticacion(capa){
  var capa = document.getElementById(capa);
  if (en_marcha) {
    return;
  }
  en_marcha = true;
  capa.innerHTML = '<br><br>Enviando peticion...'
  // Enviamos la peticion
  new Ajax.Request('acciones_ajx.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        capa.innerHTML = transport.responseText;
        en_marcha = false;
      }
    },
    parameters: {
      accion: 'AUTHFORM'
    },
    asynchronous: true
  });
}

function autenticarSesion(capa_datos){
  var capa_datos_obj = document.getElementById(capa_datos);
  var login = document.getElementById('login_registro').value;
  var passwd = document.getElementById('passwd_registro').value;
  
  if (en_marcha) {
    return;
  }
  en_marcha = true;
  capa_datos_obj.innerHTML = '<br><br>Enviando peticion...'
  // Enviamos la peticion
  new Ajax.Request('acciones_ajx.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        var stringRespuesta = transport.responseText
        if (transport.responseText == 'OK') {
          location.reload();
        } else {
          capa_datos_obj.innerHTML = transport.responseText;
        }
        en_marcha = false;
      }
    },
    parameters: {
      accion: 'AUTHUSU',
      login: login,
      passwd: passwd
    },
    asynchronous: true
  });
}

function cerrarSesion(capa_datos, seccion_id, tipoPlantilla){
  var capa_datos_obj = document.getElementById(capa_datos);
  
  if (en_marcha) {
    return;
  }
  en_marcha = true;
  capa_datos_obj.innerHTML = '<br><br>Cerrando sesion...'
  // Enviamos la peticion
  new Ajax.Request('acciones_ajx.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        if (tipoPlantilla != 'N') {
          location.href = 'seccion.php?seccion_id=' + seccion_id;
        }else{
          location.href = 'noticia.php?noticia_id=' + seccion_id;
        }
        en_marcha = false;
      }
    },
    parameters: {
      accion: 'CLOSES',
      tipoPlantilla: tipoPlantilla
    },
    asynchronous: true
  });
}

function formularioRegistro(capaDatos){
  var capa = document.getElementById(capaDatos);
  if (en_marcha) {
    return;
  }
  en_marcha = true;
  capa.innerHTML = '<br><br>Enviando peticion...'
  // Enviamos la peticion
  new Ajax.Request('acciones_ajx.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        capa.innerHTML = transport.responseText;
        en_marcha = false;
      }
    },
    parameters: {
      accion: 'FORMREG'
    },
    asynchronous: true
  });
}

function registrarUsuario(capa){
	if(!checkDataRegistro()){
		return false;
	}
	
	var nombre_registro = document.getElementById('nombre_registro').value;
	var email_registro = document.getElementById('email_registro').value;
	var web_registro = document.getElementById('web_registro').value;
	var edad_registro = document.getElementById('edad_registro').value;
	var sexo_registro = document.getElementById('sexo_registro').options[document.getElementById('sexo_registro').selectedIndex].value;
	var categoria_registro = document.getElementById('categoria_registro').options[document.getElementById('categoria_registro').selectedIndex].value;
	var login_registro = document.getElementById('login_registro').value;
	var passwd_registro = document.getElementById('passwd_registro').value;
	var repasswd_registro = document.getElementById('repasswd_registro').value;
	
  var capa = document.getElementById(capa);
  if (en_marcha) {
    return;
  }
  en_marcha = true;
  capa.innerHTML = '<br><br>Enviando peticion...'
  // Enviamos la peticion
  new Ajax.Request('acciones_ajx.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        capa.innerHTML = transport.responseText;
        en_marcha = false;
      }
    },
    parameters: {
      accion: 'REGUSU',
			nombre_registro: nombre_registro,
			email_registro: email_registro,
			web_registro: web_registro,
			edad_registro: edad_registro,
			sexo_registro: sexo_registro,
			categoria_registro: categoria_registro,
			login_registro: login_registro,
			passwd_registro: passwd_registro,
      repasswd_registro: repasswd_registro
    },
    asynchronous: true
  });
	
}

function checkDataRegistro(){
	var nombre_registro = document.getElementById('nombre_registro').value;
	var email_registro = document.getElementById('email_registro').value;
	var edad_registro = document.getElementById('edad_registro').value;
	var login_registro = document.getElementById('login_registro').value;
	var passwd_registro = document.getElementById('passwd_registro').value;
	var repasswd_registro = document.getElementById('repasswd_registro').value;
	
	// Nombre no vacio
	if (nombre_registro == '') {
		alert('Nombre vacio. Los datos marcados con * son obligatorios');
		return false;
	}
	
	// Email no vacio
	if (email_registro == '') {
		alert('Email vacio. Los datos marcados con * son obligatorios');
		return false;
	}
	
	// Edad numerico >18
	if (edad_registro == "") {
		alert("Tiene que introducir un número entero en su edad.")
		return false;
	}
	else {
		if (edad_registro < 18) {
			alert("Debe ser mayor de 18 años.")
			return false;
		}
	}
	
	// Login no vacio
	if(login_registro == ''){
		alert('Login vacio. Los datos marcados con * son obligatorios');
		return false;
	}
	
	// Passwd no vacio
	if(login_registro == ''){
		alert('Password vacio. Los datos marcados con * son obligatorios');
		return false;
	}else{
		if(passwd_registro != repasswd_registro){
			alert('No coinciden el password y su confirmacion.');
			return false;
		}
	}
	
	return true;
}

function despliegaServicios(estado, donde, quemenu){
  if (document.getElementById) {
    var boton = document.getElementById(quemenu);
    boton.setAttribute("title", "El Tiempo, Farmacias de Guardia...");
    var menuDiv = document.getElementById(donde).firstChild;
    while (menuDiv.nodeType != 1) {
      menuDiv = menuDiv.nextSibling;
    }
    var botonDiv = document.getElementById(quemenu).firstChild;
    while (botonDiv.nodeType != 1) {
      botonDiv = botonDiv.nextSibling;
    }
    ponClaseOS(botonDiv, estado);
    ponClaseOS(menuDiv, estado);
  }
}

function ponClaseOS(elemento, valorClase){
  if (elemento.setAttribute("class", valorClase)) {
    elemento.setAttribute("class", valorClase);
  } else if (elemento.setAttribute("className", valorClase)) {
    elemento.setAttribute("className", valorClase);
  }
}

function eliminarTusNoticias(capa, noticia_id){
  var respuestaBox = document.getElementById(capa);
  if (en_marcha) {
    respuestaBox.innerHTML = 'Hay un envio pendiente, espere a que termine porfavor.<br>Enviando peticion...'
    return;
  }
  en_marcha = true;
  respuestaBox.innerHTML = '<br><br>Eliminando noticia...'
  
  // Enviamos la peticion
  new Ajax.Request('acciones_ajx.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        location.reload();
        // Limpiamos el formulario
        en_marcha = false;
      }
    },
    parameters: {
      accion: 'DELTN',
      noticiaId: noticia_id
    },
    asynchronous: true
  });
}

function suscribirse(accionform){
  if (checkform('SUS')) {
    if (en_marcha) {
      document.getElementById('respuestaEnvio').innerHTML = 'Hay un envio pendiente, espere a que termine porfavor.<br>Enviando...'
      return;
    }
    en_marcha = true;
    document.getElementById('respuestaEnvio').innerHTML = '<br><br>Enviando...'
    new Ajax.Request('acciones_ajx.php', {
      method: 'post',
      onComplete: function(transport){
        if (200 == transport.status) {
          document.getElementById('respuestaEnvio').innerHTML = transport.responseText;
          // Limpiamos el formulario
          //document.getElementById('nombrer').value = '';
          //document.getElementById('emailr').value = '';
          en_marcha = false;
        }
      },
      parameters: {
        accion: accionform,
        rmt: document.getElementById('nombrer').value,
        ermt: document.getElementById('emailr').value
      },
      asynchronous: true
    });
    
  }
  return true;
  
}

function checkform(accion){
  // Comprobamos nombre del enviador
  if (document.getElementById('nombrer').value == '') {
    alert('Debe facilitar su nombre');
    return false;
  }
  
  // Comprobamos nombre del enviador
  if (document.getElementById('emailr').value == '' || !validarEmail(document.getElementById('emailr').value)) {
    alert('Debe facilitar su correo correctamente');
    return false;
  }
  
  if (accion != 'SUS') {
    // Comprobamos nombre del enviador
    if (document.getElementById('nombred').value == '') {
      alert('Debe facilitar el nombre del destinatario');
      return false;
    }
    
    // Comprobamos nombre del enviador
    if (document.getElementById('emaild').value == '' || !validarEmail(document.getElementById('emaild').value)) {
      alert('Debe facilitar un correo valido para el destinatario');
      return false;
    }
  }
  
  return true;
}

function validarEmail(valor){
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)) {
    return (true)
  } else {
    return (false);
  }
}

function control(varcontrol, varzona){
  if (varcontrol == "1") {
    var vzona = document.getElementById('vzona').options[document.getElementById('vzona').selectedIndex].value;
    var vprovincia = document.getElementById('vprovincia').value;
    var vfecha = document.getElementById('fecha').value;
    
    if (vzona == "") {
      alert("Seleccione Zona - Distrito");
      return false;
    }
    if (vprovincia == "") {
      alert("Seleccione Provincia");
      return false;
    }
    if (vfecha == "") {
      alert("Seleccione Fecha");
      return false;
    }
    var url = "http://pfarmals.portalfarma.com:8080/guard/web_guardias/Guardias.asp?date=" + vfecha + "&vzona=" + vzona + "&vmenu=1&provincia=" + vprovincia;
    stringiframe = "<iframe src=\"" + url + "\" width=\"600\" height=\"650\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    document.getElementById('resultadoFarmacia').innerHTML = stringiframe;
  }
}

function agregarComentario(noticiaId, capa_comentarios){
  var nombre = document.getElementById('nombre_coment');
  var email = document.getElementById('correo_coment');
  var texto = document.getElementById('texto_coment');
  var respuestaBox = document.getElementById(capa_comentarios);
  if (checkDataComentario(nombre.value, texto.value, email.value)) {
  	return true;
    if (en_marcha) {
      //respuestaBox.innerHTML = 'Hay un envio pendiente, espere a que termine porfavor.<br>Enviando peticion...'
      return;
    }
    en_marcha = true;
    respuestaBox.innerHTML = '<br><br>Enviando peticion...'
    // Enviamos la peticion
    new Ajax.Request('acciones_ajx.php', {
      method: 'post',
      onComplete: function(transport){
        if (200 == transport.status) {
          respuestaBox.innerHTML = transport.responseText;
          // Limpiamos el formulario
          nombre.value = '';
          web.value = '';
          texto.value = '';
          en_marcha = false;
        }
      },
	  encoding: 'ISO-8859-1',
      parameters: {
        accion: 'ENVCOM',
        noticiaId: noticiaId,
        nombre: nombre.value,
        email: email.value,
        texto: texto.value
      },
      asynchronous: true
    });
  }else{
    return false;
  }
  return false;
}

function changePageComment(capa_comentarios, paginaActual, noticiaId){
  var capa = document.getElementById(capa_comentarios);
  if (en_marcha) {
    return;
  }
  en_marcha = true;
  capa.innerHTML = '<br><br>Enviando peticion...'
  
  // Enviamos la peticion
  new Ajax.Request('acciones_ajx.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        capa.innerHTML = transport.responseText;
        en_marcha = false;
      }
    },
    parameters: {
      accion: 'COMNEWPAG',
      paginaSel: paginaActual,
      noticia_id: noticiaId
    },
    asynchronous: true
  });
}

function checkDataComentario(nombre, texto, email){
  if(nombre == ''){
    alert('Los datos marcados con * son obligatorios');
    return false;
  }
  if (texto == '') {
    alert('Los datos marcados con * son obligatorios');
    return false;
  }
  if (email != '' && !validarEmail(email)) {
    alert('La direccion de correo electronico no es correcta');
    return false;
  }
  if(texto.length >= 500){
    alert('Has superado los 500 caracteres permitidos. \nSu texto sera cortado a dicha cantidad de caracteres.\n Por favor vuelva a enviarlo.');
    document.getElementById('texto_coment').value = texto.substring(0,490);
    return false;
  }

  return true;
}







function addPregunta(capa, accionform){
  var mensaje = document.getElementById('mensajes');
  var padre = document.getElementById(capa);
  
  if (en_marcha) {
    mensaje.innerHTML = 'Hay un envio pendiente, espere a que termine porfavor.<br>Enviando peticion...'
    return;
  }
  en_marcha = true;
  mensaje.innerHTML = '<br><br>Enviando peticion...'
  totalPreguntas++;
  var stringid = '-'+totalPreguntas;
  totalRespuestas[stringid] = 0;
  new Ajax.Request('adm_sorteo.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        var pregunta = document.createElement('div');
        pregunta.setAttribute('id', stringid);
        pregunta.setAttribute('style', 'border: 5px solid black; margin-top: 15px;');
        pregunta.innerHTML = transport.responseText;
        padre.appendChild(pregunta);
        mensaje.innerHTML = '';
        en_marcha = false;
      }
    },
    parameters: {
      accion: accionform,
      sorteoId: document.getElementById('sorteoId').value,
      preguntaId: stringid
    },
    asynchronous: true
  });
  
}


function addRespuestaPregunta(capa_padre, accionform){
  var mensaje = document.getElementById('mensajes');
  var padre = document.getElementById(capa_padre);
  
  if (en_marcha) {
    mensaje.innerHTML = 'Hay un envio pendiente, espere a que termine porfavor.<br>Enviando peticion...'
    return;
  }
  en_marcha = true;
  mensaje.innerHTML = '<br><br>Enviando peticion...'
  //var stringid = '-'+totalPreguntas;
  var stringid = capa_padre;
  totalRespuestas[stringid]++;
  new Ajax.Request('adm_sorteo.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        var respuesta = document.createElement('div');
        var nombreidentificador = 'respuesta' + stringid + '_' + totalRespuestas[stringid];
        respuesta.setAttribute('id', nombreidentificador);
        respuesta.innerHTML = transport.responseText;
        padre.appendChild(respuesta);
        mensaje.innerHTML = '';
        en_marcha = false;
      }
    },
    parameters: {
      accion: accionform,
      sorteoId: document.getElementById('sorteoId').value,
      preguntaId: stringid,
      totalRespuesta: totalRespuestas[stringid]
    },
    asynchronous: true
  });
}

function eliminarRespuesta(preguntaId, respuestaId){
  var identificadorRespuesta = 'respuesta' + preguntaId + '_' +respuestaId;
  
  var hijo = document.getElementById(identificadorRespuesta);
  var padre = hijo.parentNode;
  var hijoBorrado = padre.removeChild(hijo);
}

function eliminarPregunta(preguntaId){
  var identificadorPregunta = preguntaId;
  
  var hijo = document.getElementById(identificadorPregunta);
  var padre = hijo.parentNode;
  var hijoBorrado = padre.removeChild(hijo);
  if (identificadorPregunta > 0) {
    document.getElementById('peliminadas').value += ',' + identificadorPregunta;
  }
}

function obtenerEnlaces(capaDatos, paginaSel, noticia_id, titulo_noticia){
  var capa = document.getElementById(capaDatos);
  var identificador = '';
  var titulo = '';
  if (noticia_id != '') {
    identificador = document.getElementById(noticia_id).value;
  }
  if(titulo_noticia != ''){
    titulo = document.getElementById(titulo_noticia).value;
  }
    
  if (en_marcha) {
    return;
  }
  en_marcha = true;
  capa.innerHTML = '<br><br>Enviando peticion...'
  
  // Enviamos la peticion
  new Ajax.Request('adm_acciones_ajx.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        capa.innerHTML = transport.responseText;
        en_marcha = false;
      }
    },
    parameters: {
      accion: 'ENLALIST',
      paginaSel: paginaSel,
      bus_titulo_not: titulo,
      bus_identificador: identificador
    },
    asynchronous: true
  });
}

function asignarEnlace(capa_enlaces, id_noticia, titulo_noticia){
  var capa = document.getElementById(capa_enlaces);
  if (en_marcha) {
    return;
  }
  en_marcha = true;
  
  // Enviamos la peticion
  new Ajax.Request('adm_acciones_ajx.php', {
    method: 'post',
    onComplete: function(transport){
      if (200 == transport.status) {
        //capa.innerHTML += transport.responseText;
        var nuevoenlace = document.createElement('div');
        nuevoenlace.innerHTML = transport.responseText;
        capa.appendChild(nuevoenlace);
        totalEnlaces++;
        en_marcha = false;
      }
    },
    parameters: {
      accion: 'ENLASIG',
      noticia_id: id_noticia,
      titulo: titulo_noticia,
      total_enlaces: totalEnlaces
    },
    asynchronous: true
  });
}

function eliminarEnlaceNoticia(identificadorHijo){
  var nodoHijoName = 'enlace' + identificadorHijo;
  
  var hijo = document.getElementById(nodoHijoName);
  var padre = hijo.parentNode;
  var hijoBorrado = padre.removeChild(hijo);
}

function checkDataComentarioTusNoticias(texto){
  if (texto == '') {
    alert('Los datos marcados con * son obligatorios');
    return false;
  }
  return true;
}

function agregarComentarioTusNoticias(noticiaId, capa_comentarios){
  var nombre = document.getElementById('nombre_coment');
  var web = document.getElementById('web_coment');
  var texto = document.getElementById('texto_coment');
  var respuestaBox = document.getElementById(capa_comentarios);
  if (checkDataComentarioTusNoticias(texto.value)) {
    if (en_marcha) {
      //respuestaBox.innerHTML = 'Hay un envio pendiente, espere a que termine porfavor.<br>Enviando peticion...'
      return;
    }
    en_marcha = true;
    respuestaBox.innerHTML = '<br><br>Enviando comentario...'
    
    // Enviamos la peticion
    new Ajax.Request('acciones_ajx.php', {
      method: 'post',
      onComplete: function(transport){
        if (200 == transport.status) {
          respuestaBox.innerHTML = transport.responseText;
          // Limpiamos el formulario
          en_marcha = false;
        }
      },
      parameters: {
        accion: 'ENVCOMTN',
        noticiaId: noticiaId,
        texto: texto.value
      },
      asynchronous: true
    });
  }
}

function enviarNoticia(idnoticia){
  if (checkform('ENV')) {
    if (en_marcha) {
      //document.getElementById('respuestaEnvio').innerHTML = 'Hay un envio pendiente, espere a que termine porfavor.<br>Enviando...'
      return;
    }
    en_marcha = true;
    document.getElementById('respuestaEnvio').innerHTML = 'Enviando...'
    new Ajax.Request('acciones_ajx.php', {
      method: 'post',
      onComplete: function(transport){
        if (200 == transport.status) {
          document.getElementById('respuestaEnvio').innerHTML = transport.responseText;
          en_marcha = false;
          // Limpiamos el formulario
          document.getElementById('nombrer').value = '';
          document.getElementById('emailr').value = '';
          document.getElementById('nombred').value = '';
          document.getElementById('emaild').value = '';
          document.getElementById('comentario').value = '';
        }
      },
      parameters: {
        accion: 'ENVNOT',
        idno: idnoticia,
        rmt: document.getElementById('nombrer').value,
        ermt: document.getElementById('emailr').value,
        dst: document.getElementById('nombred').value,
        edst: document.getElementById('emaild').value,
        coment: document.getElementById('comentario').value
      },
      asynchronous: true
    });
    
  }
  return true;
}

function enviarTusNoticias(idnoticia){
  if (checkform('ENV')) {
    if (en_marcha) {
      return;
    }
    en_marcha = true;
    document.getElementById('respuestaEnvio').innerHTML = 'Enviando...'
    new Ajax.Request('tusnoticias_ajx.php', {
      method: 'post',
      onComplete: function(transport){
        if (200 == transport.status) {
          document.getElementById('respuestaEnvio').innerHTML = transport.responseText;
          en_marcha = false;
          // Limpiamos el formulario
          document.getElementById('nombrer').value = '';
          document.getElementById('emailr').value = '';
          document.getElementById('nombred').value = '';
          document.getElementById('emaild').value = '';
          document.getElementById('comentario').value = '';
        }
      },
      parameters: {
        accion: 'ENVNOT',
        idno: idnoticia,
        rmt: document.getElementById('nombrer').value,
        ermt: document.getElementById('emailr').value,
        dst: document.getElementById('nombred').value,
        edst: document.getElementById('emaild').value,
        coment: document.getElementById('comentario').value
      },
      asynchronous: true
    });
    
  }
  return true;
}


function getVideos(capa_videos){
  var respuestaBox = document.getElementById(capa_videos);
    if (en_marcha) {
      return;
    }
    en_marcha = true;
    // Enviamos la peticion
    new Ajax.Request('acciones_ajx.php', {
      method: 'post',
      onComplete: function(transport){
        if (200 == transport.status) {
          respuestaBox.innerHTML = transport.responseText;
          // Limpiamos el formulario
          en_marcha = false;
        }
      },
      parameters: {
        accion: 'VIDEOSPORTADA'
      },
      asynchronous: true
    });
}

