
var xmlHttp;
var ref;

function CreateXmlHttp()
{
    
    // Probamos con IE
    try
    {
        // Funcionará para JavaScript 5.0
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc)
        {   
            xmlHttp = null;
        }
    }

    // Si no se trataba de un IE, probamos con esto
    if(!xmlHttp && typeof XMLHttpRequest != "undefined")
    {
        xmlHttp = new XMLHttpRequest();
    }

    return xmlHttp;
}

function envioInfoGet(obj, accion, txt, sec, fnc)
{
	ref=obj;
	ref2=txt;
    // 1.- Creamos el objeto xmlHttpRequest
    xmlHttp = CreateXmlHttp();
    
    // 2.- Definimos la llamada para hacer un simple GET. 
    var ajaxRequest = 'gwEstrucRequest.php?accion=' + accion + '&info=' + txt.value + '&sec=' + sec + '&fnc=' + fnc;

    // 3.- Marcar qué función manejará la respuesta
    xmlHttp.onreadystatechange = recogeInfo;
   
    // 4.- Enviar
    xmlHttp.open("GET", ajaxRequest, true);
    xmlHttp.send("");
}

function envioInfoPost(XML)
{
    // 1.- Creamos el objeto xmlHttpRequest
    xmlHttp = CreateXmlHttp();
    
    // 2.- Definimos la llamada. 
    var ajaxRequest = 'gwEstrucRequest.php';

    // 3.- Marcar qué función manejará la respuesta
    xmlHttp.onreadystatechange = recogeInfo;
   
    // 4.- Enviar
    xmlHttp.open("POST", ajaxRequest, true);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
    xmlHttp.send(XML);
}

function recogeInfo()
{
    if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
    {
		var partes;

		partes=xmlHttp.responseText.split('|');
		switch(parseInt(partes[0])){			
			case 1: //El resultado se añade a un select
				addRowSelect(ref,partes[1], ref2.value);
				ref2.value='';
				ref2.focus();
				break;
			case 2: //El resultado se añade un text
				ref.value=partes[1];
				break;
			case -1:
				alert(partes[1]);
				ref2.value='';
				ref2.focus();
				break;
			case -2:
				alert(partes[1]);
				ref.value='';
				ref2.value='';
				ref2.focus();
				break;

			default:
				alert('Operación incorrecta');
				ref2.value='';
				ref2.focus();
		}
		//alert('Añadido correctamente: ' + partes[1]);
   }
}

