var oXMLHTTP;

function AJAX_ConectorChange()
{
	if (oXMLHTTP.xmlhttp.readyState==4)
	{
		if (oXMLHTTP.xmlhttp.status==200)
		{
			oXMLHTTP.Source.resultado = oXMLHTTP.xmlhttp.responseText;
			oXMLHTTP.Source.Text = oXMLHTTP.xmlhttp.responseText;
			oXMLHTTP.Source.Xml = oXMLHTTP.xmlhttp.responseXML;
		}
		else
			oXMLHTTP.Source.resultado = -1;
	}
}
	
function AJAX_Conector(urlCmd)
{
	this.urlCmd = urlCmd;
	this.resultado = null;
	this.Xml = null;
	this.Text = null;
	this.Params = null;
	this.Post = true;

	this.Request = function()
	{
		try
		{
		alert("Entro por aquí");
			if (window.ActiveXObject)
			{
				oXMLHTTP=new Object();
				oXMLHTTP.Source=this;
				
				try { oXMLHTTP.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");}//Msxml2.XMLHTTP");}//Msxml2.XMLHTTP.5.0"); }
				catch(ex) {oXMLHTTP.xmlhttp = false}
				
				var ids = ["Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
				for(var i=0; !oXMLHTTP.xmlhttp && i<ids.length; i++) 
				{
					try { oXMLHTTP.xmlhttp = new ActiveXObject(ids[i]); }
				    catch(ex) {oXMLHTTP.xmlhttp = false }
				}
				//oXMLHTTP.xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
							
				oXMLHTTP.xmlhttp.onreadystatechange = AJAX_ConectorChange;
				oXMLHTTP.xmlhttp.open("POST",urlCmd,false);
				
				if (this.Post)
					oXMLHTTP.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				
				if (this.Params)
					oXMLHTTP.xmlhttp.send(this.Params);
				else
					oXMLHTTP.xmlhttp.send();
					
				                //Para Firefox
				if (!document.all && oXMLHTTP.xmlhttp.responseText)
				{
				    oXMLHTTP.Source.resultado = oXMLHTTP.xmlhttp.responseText;
			        oXMLHTTP.Source.Text = oXMLHTTP.xmlhttp.responseText;
                    oXMLHTTP.Source.Xml = oXMLHTTP.xmlhttp.responseXML;
			    }
			}
		
			delete oXMLHTTP;
		
			return this;
		
		}
		catch (e)
		{
			alert ("Error: " + e.message);
		}
	
	}
	
	this.Requery = function()
	{
		this.Request();
	}
		
	this.Ejecutar = function()
	{
		try
		{
			if (window.ActiveXObject)
			{
				oXMLHTTP=new Object();
				oXMLHTTP.Source=this;
				
				try
				{
				try { oXMLHTTP.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");}//Msxml2.XMLHTTP");}//Msxml2.XMLHTTP.5.0"); }
				catch(ex) {oXMLHTTP.xmlhttp = false}
				
				var ids = ["Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
				for(var i=0; !oXMLHTTP.xmlhttp && i<ids.length; i++) 
				{
					try { oXMLHTTP.xmlhttp = new ActiveXObject(ids[i]); }
				    catch(ex) {oXMLHTTP.xmlhttp = false }
				}
				//oXMLHTTP.xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
				}
				catch(e){}
				
				 if (!oXMLHTTP.xmlhttp && typeof XMLHttpRequest!='undefined') 
				    oXMLHTTP.xmlhttp = new XMLHttpRequest();

				oXMLHTTP.xmlhttp.onreadystatechange = AJAX_ConectorChange;
				oXMLHTTP.xmlhttp.open("POST",urlCmd,false);
				
				if (this.Ejecutar.arguments.length > 0)
				{
					oXMLHTTP.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
//					oXMLHTTP.xmlhttp.setRequestHeader("charset", "iso-8859-1");
//					oXMLHTTP.xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=iso-8859-9");
//                    oXMLHTTP.xmlhttp.setRequestHeader("Content-Type", "text/xml");
//                    oXMLHTTP.xmlhttp.setRequestHeader("charset", "utf-8");
					oXMLHTTP.xmlhttp.send(this.Ejecutar.arguments[0]);
				}
				else
					oXMLHTTP.xmlhttp.send();
				
                //Para Firefox
				if (!document.all && oXMLHTTP.xmlhttp.responseText)
				{
				    oXMLHTTP.Source.resultado = oXMLHTTP.xmlhttp.responseText;
			        oXMLHTTP.Source.Text = oXMLHTTP.xmlhttp.responseText;
                    oXMLHTTP.Source.Xml = oXMLHTTP.xmlhttp.responseXML;
			    }
			}
		    else
		    {
                oXMLHTTP=new Object();
				oXMLHTTP.Source=this;

                if (!oXMLHTTP.xmlhttp && typeof XMLHttpRequest!='undefined') 
				    oXMLHTTP.xmlhttp = new XMLHttpRequest();

				oXMLHTTP.xmlhttp.onreadystatechange = AJAX_ConectorChange;
				oXMLHTTP.xmlhttp.open("POST",urlCmd,false);
				
				if (this.Ejecutar.arguments.length > 0)
				{
				oXMLHTTP.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
//					oXMLHTTP.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//	                oXMLHTTP.xmlhttp.setRequestHeader("charset", "iso-8859-1");	
	               // oXMLHTTP.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");		
	             //oXMLHTTP.xmlhttp.setRequestHeader("Content-Type", "text/xml");
                   // oXMLHTTP.xmlhttp.setRequestHeader("charset", "utf-8");   	
					oXMLHTTP.xmlhttp.send(this.Ejecutar.arguments[0]);
				}
				else
					oXMLHTTP.xmlhttp.send('');
				
                //Para Firefox
				if (!document.all && oXMLHTTP.xmlhttp.responseText)
				{
				    oXMLHTTP.Source.resultado = oXMLHTTP.xmlhttp.responseText;
			        oXMLHTTP.Source.Text = oXMLHTTP.xmlhttp.responseText;
                    oXMLHTTP.Source.Xml = oXMLHTTP.xmlhttp.responseXML;
			    }
            }
			delete oXMLHTTP;
		
			return this.resultado;
		}
		catch (e)
		{
			alert ("Error: " + e.message);
		}
	}
	
	this.ReadFile = function()
	{
		try
		{
			if (window.ActiveXObject)
			{
				oXMLHTTP=new Object();
				oXMLHTTP.Source=this;
				
				try
				{
				try { oXMLHTTP.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");}//Msxml2.XMLHTTP");}//Msxml2.XMLHTTP.5.0"); }
				catch(ex) {oXMLHTTP.xmlhttp = false}
				
				var ids = ["Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
				for(var i=0; !oXMLHTTP.xmlhttp && i<ids.length; i++) 
				{
					try { oXMLHTTP.xmlhttp = new ActiveXObject(ids[i]); }
				    catch(ex) {oXMLHTTP.xmlhttp = false }
				}
				//oXMLHTTP.xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
				}
				catch(e){}
				
				 if (!oXMLHTTP.xmlhttp && typeof XMLHttpRequest!='undefined') 
				    oXMLHTTP.xmlhttp = new XMLHttpRequest();

				oXMLHTTP.xmlhttp.onreadystatechange = AJAX_ConectorChange;
				oXMLHTTP.xmlhttp.open("GET",urlCmd,false);
				
				if (this.ReadFile.arguments.length > 0)
				{
					oXMLHTTP.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					oXMLHTTP.xmlhttp.send(this.ReadFile.arguments[0]);
				}
				else
					oXMLHTTP.xmlhttp.send();
				
                //Para Firefox
				if (!document.all && oXMLHTTP.xmlhttp.responseText)
				{
				    oXMLHTTP.Source.resultado = oXMLHTTP.xmlhttp.responseText;
			        oXMLHTTP.Source.Text = oXMLHTTP.xmlhttp.responseText;
                    oXMLHTTP.Source.Xml = oXMLHTTP.xmlhttp.responseXML;
			    }
			}
		    else
		    {
                oXMLHTTP=new Object();
				oXMLHTTP.Source=this;

                if (!oXMLHTTP.xmlhttp && typeof XMLHttpRequest!='undefined') 
				    oXMLHTTP.xmlhttp = new XMLHttpRequest();

				oXMLHTTP.xmlhttp.onreadystatechange = AJAX_ConectorChange;
				oXMLHTTP.xmlhttp.open("GET",urlCmd,false);
				
				if (this.ReadFile.arguments.length > 0)
				{
					oXMLHTTP.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					oXMLHTTP.xmlhttp.send(this.ReadFile.arguments[0]);
				}
				else
					oXMLHTTP.xmlhttp.send('');
				
                //Para Firefox
				if (!document.all && oXMLHTTP.xmlhttp.responseText)
				{
				    oXMLHTTP.Source.resultado = oXMLHTTP.xmlhttp.responseText;
			        oXMLHTTP.Source.Text = oXMLHTTP.xmlhttp.responseText;
                    oXMLHTTP.Source.Xml = oXMLHTTP.xmlhttp.responseXML;
			    }
            }
			delete oXMLHTTP;
		
			return this.resultado;
		}
		catch (e)
		{
			alert ("Error: " + e.message);
		}
	}
}


