addEvent(window,'load',inicializarEventos,false);
function inicializarEventos()
{
  var ref=document.getElementById('formulario');
  addEvent(ref,'submit',enviarDatos,false);
}

function enviarDatos(e)
{
if (window.event)
    window.event.returnValue=false;
  else
    if (e)
      e.preventDefault();
  enviarFormulario();
}


function retornarDatos()
{
  var cad='';
  var id=document.getElementById('id').value;
  var nombre=encodeMyHtml(document.getElementById('nombre').value);
  var email=document.getElementById('email').value;
  var comentario=encodeMyHtml(document.getElementById('comentario_txt').value);
  cad='id='+encodeURIComponent(id)+'&nombre='+encodeURIComponent(nombre)+'&email='+encodeURIComponent(email)+'&comentario='+encodeURIComponent(comentario);
  return cad;
}

var conexion1;
function enviarFormulario() 
{
  conexion1=crearXMLHttpRequest();
  conexion1.onreadystatechange = procesarEventos;
  conexion1.open('POST','/comentario_save.asp', true);
  conexion1.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  conexion1.send(retornarDatos());  
}

function procesarEventos()
{
  var resultados = document.getElementById("resultados");
  document.getElementById("comentario_form").style.visibility="hidden";
  document.getElementById("comentario_form").style.display = "none";
  
  if(conexion1.readyState == 4)
  {
	resultados.innerHTML = conexion1.responseText;
  } 
  else 
  {
    resultados.innerHTML = 'Procesando...';
  }
}

//***************************************
//Funciones comunes a todos los problemas
//***************************************
function addEvent(elemento,nomevento,funcion,captura)
{
  if (elemento.attachEvent)
  {
    elemento.attachEvent('on'+nomevento,funcion);
    return true;
  }
  else  
    if (elemento.addEventListener)
    {
      elemento.addEventListener(nomevento,funcion,captura);
      return true;
    }
    else
      return false;
}

function crearXMLHttpRequest() 
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}

function encodeMyHtml(text) {
	text = text.replace(/[á]/g,'&aacute;'); 
	text = text.replace(/[é]/g,'&eacute;'); 
	text = text.replace(/[í]/g,'&iacute;'); 
	text = text.replace(/[ó]/g,'&oacute;'); 
	text = text.replace(/[ú]/g,'&uacute;'); 
	text = special(text);
return text;
}

function special(source)
{
	var result = '';
	for (var i = 0; i < source.length; i++)
	{
		var c = source.charAt(i);
		if (c > '~')
		{
			c = '&#' + c.charCodeAt() + ';';
		}
		result += c;
	}
	return result;
}
