var yh_ajax_peticion	= YH_ajax_crear ();
var yh_ajax_procesado	= true;
var yh_ajax_f_retorno;
var yh_ajax_f_mensaje;

var yh_ajax_bien	= 'bien';
var yh_ajax_mal		= 'mal';
var yh_ajax_regular	= 'regular';

function YH_ajax_crear ()
{
	var e;
	
	if		( window.XMLHttpRequest )
		try				{ return new XMLHttpRequest();					}
		catch (e)		{ return false;									}
	else if	( window.ActiveXObject )
		try				{ return new ActiveXObject("Msxml2.XMLHTTP");	}
		catch (e)		{
			try			{ return new ActiveXObject("Microsoft.XMLHTTP");}
			catch (e)	{ return false;						        	}
						}
	return false;
}

function YH_ajax_procesar ()
{
	if ( yh_ajax_peticion.readyState == 4 )
		if ( yh_ajax_peticion.status == 200 )
		{
//alert(yh_ajax_peticion.responseText);
			var aux = eval ( '(' + yh_ajax_peticion.responseText + ')' );
			yh_ajax_procesado = true;
			yh_ajax_f_retorno ( aux.datos, aux.estado );
			if ( yh_ajax_f_mensaje ) yh_ajax_f_mensaje ( aux.estado, aux.mensaje );
		}
		else yh_ajax_procesado = true;
}

function YH_ajax_enviar ( url, valores, retorno )
{
	if ( !yh_ajax_procesado ) return;
	
	yh_ajax_procesado = false;
	
	yh_ajax_f_retorno = retorno;
	yh_ajax_peticion.open ( 'post', url );
	yh_ajax_peticion.onreadystatechange = YH_ajax_procesar;
	yh_ajax_peticion.setRequestHeader ( 'Content-Type', 'application/x-www-form-urlencoded' );
	yh_ajax_peticion.send ( valores );
}