﻿
var xmlHttp;

function CreateXmlHttp()
{   
    try
    {    
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc)
        {  
            xmlHttp = null;
        }
    }

    if(!xmlHttp && typeof XMLHttpRequest != "undefined")
    {
        xmlHttp = new XMLHttpRequest();
    }

    return xmlHttp;
}


function getXml(texto){
    var indFin = texto.indexOf('%3C%2Fdatos%3E');
    if (indFin > -1)
    {
	    texto = texto.substring(texto.indexOf('%3Cdatos%3E'),indFin + 14);
	    return texto;
	}
	else {
	    return '';
	}
}

function getXmlNodoValue(textoXml,nombreNodo) {
     var ind = textoXml.indexOf('%3C%2F' + nombreNodo + '%3E');
        if (ind > -1) {
            textoXml = textoXml.substring(textoXml.indexOf('%3C' + nombreNodo + '%3E') + nombreNodo.length + 6,ind);
            ind = textoXml.indexOf('%2C');
            if (ind > -1){
                textoXml = textoXml.substring(0,ind);
            }
            return textoXml ;       
        }
        else {
            return '';
        }
}


function getEstado(texto){    
   return getXmlNodoValue(texto,"estado");
}

function obtieneTextoEstado(campoId){	
    var estadoTemp = getEstado(getXml(xmlHttp.responseText));
    var ajaxRequest = "Texto_Estado.aspx" ;
    xmlHttp.open("POST", ajaxRequest, false);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
    xmlHttp.send("estado=" + estadoTemp);
    var campo = document.getElementById(campoId);
    var nodoTexto = document.createTextNode(xmlHttp.responseText);
    campo.appendChild(nodoTexto);
}

function pideEstado(idPedido,campoId){
	if (idPedido != -1 && idPedido != "-1")
	{		
	    xmlHttp = CreateXmlHttp();           
	    var ajaxRequest = "proxccalgirest.php";
	    xmlHttp.open("POST", ajaxRequest, false);
	    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');   
		xmlHttp.send("idPedido=" + idPedido); 
	    obtieneTextoEstado(campoId);  
	}
	else
	{
		var campo = document.getElementById(campoId);
		var nodoTexto = document.createTextNode("-");
    	campo.appendChild(nodoTexto);
	}
}




