var receta = new Array();
var nombres = new Array();
var comentario = new Array();
var cantRecetas = 0;
function procesaXml(xml){
    
    var i;
    
    var comando = xml.getElementsByTagName("comando")[0].firstChild.nodeValue;
        
    if (comando == "nombres"){
        nombres = null;
        nombres = new Array();
        var cantidad = xml.getElementsByTagName("comando").length;
        cantRecetas = xml.getElementsByTagName("cantRecetas")[0].firstChild.nodeValue;
        //alert(cantRecetas);
        for (i = 0; i < cantidad; i++){
            nombres[i] = new Array();
            nombres[i].IDreceta = xml.getElementsByTagName("IDreceta")[i].firstChild.nodeValue;
            nombres[i].nombre = xml.getElementsByTagName("nombre")[i].firstChild.nodeValue;
            nombres[i].fecha = xml.getElementsByTagName("fecha")[i].firstChild.nodeValue;
            nombres[i].visitas = xml.getElementsByTagName("visitas")[i].firstChild.nodeValue;
            nombres[i].puntos = xml.getElementsByTagName("puntos")[i].firstChild.nodeValue;
            nombres[i].autor = xml.getElementsByTagName("autor")[i].firstChild.nodeValue;
        }
    }
    else if (comando == "receta"){
        var IDreceta = xml.getElementsByTagName("IDreceta")[0].firstChild.nodeValue;
        if (!receta[IDreceta]){ //Si la receta es nueva, la cargo
            receta[IDreceta] = new Array();
            receta[IDreceta].nombre = xml.getElementsByTagName("nombre")[0].firstChild.nodeValue;
            receta[IDreceta].descripcion = xml.getElementsByTagName("descripcion")[0].firstChild.nodeValue;
            receta[IDreceta].foto = xml.getElementsByTagName("foto")[0].firstChild.nodeValue;
            receta[IDreceta].prioridad = xml.getElementsByTagName("prioridad")[0].firstChild.nodeValue;
            receta[IDreceta].tipo = xml.getElementsByTagName("tipo")[0].firstChild.nodeValue;
            receta[IDreceta].origen = xml.getElementsByTagName("origen")[0].firstChild.nodeValue;
            receta[IDreceta].sal_dul = xml.getElementsByTagName("sal_dul")[0].firstChild.nodeValue;
            receta[IDreceta].temp = xml.getElementsByTagName("temp")[0].firstChild.nodeValue;
            receta[IDreceta].coccion = xml.getElementsByTagName("coccion")[0].firstChild.nodeValue;
            receta[IDreceta].porciones = xml.getElementsByTagName("porciones")[0].firstChild.nodeValue;
            receta[IDreceta].tiempo = xml.getElementsByTagName("tiempo")[0].firstChild.nodeValue;
            receta[IDreceta].fecha = xml.getElementsByTagName("fecha")[0].firstChild.nodeValue;
            receta[IDreceta].visitas = xml.getElementsByTagName("visitas")[0].firstChild.nodeValue;
            receta[IDreceta].votos = xml.getElementsByTagName("votos")[0].firstChild.nodeValue;
            receta[IDreceta].puntos = xml.getElementsByTagName("puntos")[0].firstChild.nodeValue;
            receta[IDreceta].autor = xml.getElementsByTagName("autor")[0].firstChild.nodeValue;
            receta[IDreceta].ingre = xml.getElementsByTagName("ingre")[0].firstChild.nodeValue;
            receta[IDreceta].cantComent = xml.getElementsByTagName("cantComent")[0].firstChild.nodeValue;
            
            
            receta[IDreceta].ingrediente = new Array();
            receta[IDreceta].cantidad = new Array();
            receta[IDreceta].unidad = new Array();
            
            ing = xml.getElementsByTagName("ingrediente");
            cant = xml.getElementsByTagName("cantidad");
            uni = xml.getElementsByTagName("unidad");
            for (i = 0; i < ing.length; i++){
                receta[IDreceta].ingrediente[i] = ing[i].firstChild.nodeValue;
                receta[IDreceta].cantidad[i] = cant[i].firstChild.nodeValue;
                if (receta[IDreceta].cantidad[i] == "0") receta[IDreceta].cantidad[i] = "";
                receta[IDreceta].unidad[i] = uni[i].firstChild.nodeValue;
            }
        }
    }
    else if (comando == "comentario"){
        comentario = null;
        comentario = new Array();
        var cantidad = xml.getElementsByTagName("comando").length;
        for (i = 0; i < cantidad; i++){
            comentario[i] = new Array();
            comentario[i].comentario = xml.getElementsByTagName("comentario")[i].firstChild.nodeValue;
            comentario[i].autor = xml.getElementsByTagName("autor")[i].firstChild.nodeValue;
            comentario[i].fecha = xml.getElementsByTagName("fecha")[i].firstChild.nodeValue;
        }
    }
    
    return(comando);
}