var conexionAjax;

//////////////////////////////////////////////////////////////////////////
//////////////////////////COMIENZA FUNCIONES BASICAS DE AJAX//////////////
//////////////////////////////////////////////////////////////////////////

function iniciarAjax(url, metodo, params){
	var datos;
	var fecha = new Date();
  	var evitarCache = fecha.getMinutes()+''+fecha.getSeconds();
	url += '?evitarCache='+evitarCache;
	if(params.length>0){
		url += '&'+params;
	}
	conexionAjax=crearObjetoXMLHttpRequest();
	conexionAjax.onreadystatechange = escucharEstado;
	conexionAjax.open(metodo,url, true);
	if(metodo == 'post'){
		conexionAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		datos = prepararDatos();
	}else{
		datos = null;
	}
	conexionAjax.send(datos);
}

function crearObjetoXMLHttpRequest(){
	var xmlHttp=null;
	if (window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		if (window.XMLHttpRequest){
	      xmlHttp = new XMLHttpRequest();
		}
	}
	return xmlHttp;
}

function escucharEstado(){
	if(conexionAjax.readyState == 4){
		dato=conexionAjax.responseText;
		mostrarMensaje(dato,'descrip');
	}
}

function prepararDatos(){
	var textoIngresado = 'textoIngresado='+encodeURIComponent(document.getElementById('texto').value);
	return textoIngresado;
}


//////////////////////////////////////////////////////////////////////////
//////////////////////////TERMINA FUNCIONES BASICAS DE AJAX//////////////
//////////////////////////////////////////////////////////////////////////

function mostrarMensaje(mensaje, contenedorMensaje){
	document.getElementById(contenedorMensaje).style.display = 'block';
	document.getElementById(contenedorMensaje).innerHTML = mensaje;
}

