function nuevoAjax(){
var xmlhttp=false;
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

function cambiar_select(valor_select, id_input)//funcion para el select de indexP
{
       var input = document.getElementById(id_input);
       input.value = valor_campo
}


	

	function cambiar_titulo2(valor)
{	
	c1 = document.getElementById('uno');
	ajax=nuevoAjax();
	ajax.open("POST", "8cambiarTitulo.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			//mostrar resultados en esta capa
			c1.innerHTML = ajax.responseText
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valores
	ajax.send("valor="+valor)
	
	
	}
	function comentar(id ){
		nombre=document.frm.nombref.value;
		correo=document.frm.correof.value;
		titulo=document.frm.titulof.value;
		contenido=document.frm.contenidof.value;
		if (id.length==0){alert("WWW");
			document.frm.boton.disabled=true;
			return 0;
		}
		if (nombre.length==0){
			alert("Proporcionar su Nombre.")
			document.frm.nombref.focus()
			return 0;
		}
		if (correo.length==0){
			alert("Proporcionar su e-mail.")
			document.frm.correof.focus()
			return 0;
		}
		if (titulo.length==0){
			alert("Proporcionar su el título de su comentario.")
			document.frm.titulof.focus()
			return 0;
		}
		if (correo.length==0){
			alert("Proporcionar su e-mail.")
			document.frm.correof.focus()
			return 0;
		}
		if (validaTexto(document.frm.nombref.value, 'Nombre')==false){return 0;}
		if (validaTexto(document.frm.correof.value, 'E-mail')==false){return 0;}
		if (validaTexto(document.frm.titulof.value, 'Título')==false){return 0;}
		if (validaTexto(document.frm.contenidof.value, 'Comentario')==false){return 0;}
		
		c = document.getElementById('foro');
		ajax=nuevoAjax();
		ajax.open("POST", "8agregaOpinion.php",true);
		ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			//mostrar resultados en esta capa
			c.innerHTML = ajax.responseText
			}
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("id="+id+"&nombre="+nombre+"&correo="+correo+"&titulo="+titulo+"&contenido="+contenido)
		
	document.frm.boton.disabled=true;
	
	document.frm.contenidof.value="Apreciable "+nombre+" su mensaje ha sido enviado. Gracias.";
	document.frm.contenidof.disabled=true;
	alert("Apreciable "+nombre+" su mensaje ha sido enviado. Gracias.");
	}
	
	function validarAlMomento(e) { // 1
    tecla = (document.all) ? e.keyCode : e.which; // 2
    if (tecla==8) return true; // 3
    /*patron =/[A-Za-z\s]/; // 4
    te = String.fromCharCode(tecla); // 5
    return patron.test(te); // 6*/
	patron =/[<>/_#--$%&/()=""]/; // 4
te = String.fromCharCode(tecla); // 5
return !patron.test(te); // 6
} 

function validaTexto(campo,nombreCampo){
  var ubicacion
  var enter = "\n"   //Los caracteres válidos son:
  var caracteres = "abcdefghijklmnopqrstuvwxyzñ1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZÑáéíóúÁÉÍÓÚº¿?@()%'!¡-+*.,:" + String.fromCharCode(13) + enter

  var contador = 0
  for (var i=0; i < campo.length; i++) {
    ubicacion = campo.substring(i, i + 1)
    if (caracteres.indexOf(ubicacion) != -1) {
      contador++
    } else {
      alert("ERROR en el "+nombreCampo+": No se acepta el caracter '" + ubicacion + "'.")
      return false
    }
  }
}
