Saving XML Reply and request next
===

I am polling a device for names and it replys back with a XML reply and I'm doing this in JavaScript. (I can't use jQuery it has to be JavaScript)

Each XML reply comes back with 24 nodes that I need to save (as a cookie) but then I need to request the next 24 and need to do this 10 times.

If I send to the panel the following command:

    var url = "http://ip_address/SELECT FirstName, Surname FROM Card WHERE Card=1";

It will reply back with:

    <Card><Card1><FirstName></FirstName><Surname></Surname></Card1><Card2><FirstName></FirstName><Surname></Surname></Card2><Card3><FirstName></FirstName><Surname></Surname></Card3><Card4><FirstName></FirstName><Surname></Surname></Card4><Card5><FirstName></FirstName><Surname></Surname></Card5><Card6><FirstName></FirstName><Surname></Surname></Card6><Card7><FirstName></FirstName><Surname></Surname></Card7><Card8><FirstName></FirstName><Surname></Surname></Card8><Card9><FirstName></FirstName><Surname></Surname></Card9><Card10><FirstName></FirstName><Surname></Surname></Card10><Card11><FirstName></FirstName><Surname></Surname></Card11><Card12><FirstName></FirstName><Surname></Surname></Card12><Card13><FirstName></FirstName><Surname></Surname></Card13><Card14><FirstName></FirstName><Surname></Surname></Card14><Card15><FirstName></FirstName><Surname></Surname></Card15><Card16><FirstName></FirstName><Surname></Surname></Card16><Card17><FirstName></FirstName><Surname></Surname></Card17><Card18><FirstName></FirstName><Surname></Surname></Card18><Card19><FirstName></FirstName><Surname></Surname></Card19><Card20><FirstName></FirstName><Surname></Surname></Card20><Card21><FirstName></FirstName><Surname></Surname></Card21><Card22><FirstName></FirstName><Surname></Surname></Card22><Card23><FirstName></FirstName><Surname></Surname></Card23><Card24><FirstName></FirstName><Surname></Surname></Card24></Card>

however I need to request the next 24 so I need to work out what the last Cardxx is then I need to add 1 to it so it will become:

    var url = "http://ip_address/SELECT * FROM Card WHERE Card=25";

then the next 24 will be returned.

However I am trying to save each FirstName and Surname as a cookie.

I have code that sets the cookie:

    // set cookie
    function set_cookie(cookie_name, cookie_value)
    {
    	document.cookie=cookie_name + "=" + cookie_value
    }

So far I have the following code but need help selecting the all the getElementsByTagName and saving each as the cookie then polling for the next and saving them as a cookie:

    function CardName(num)
    {
    	if (num == ""){num = "1";}
    		
    	
    	if (window.XMLHttpRequest)
    	{// code for IE7+, Firefox, Chrome, Opera, Safari
    		xmlhttp=new XMLHttpRequest();
    	}
    		else
    	{	// code for IE6, IE5
    		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
    		// Query to send
    	if (num <= "1") 
    	{
    		var url = ip + "SELECT FirstName, Surname FROM Card WHERE Card=1";
    	}
    	else
    	{
    		var url = ip + "SELECT FirstName, Surname FROM Card WHERE Card=" + num; //next 24
    	}
    	
    	xmlhttp.onreadystatechange=function()
    	{
    		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
    			// Set XML feedback
    			xmlDoc=xmlhttp.responseXML; 
    			// Reply from panel		
    			var First = xmlDoc.getElementsByTagName("FirstName")[0]; 
    				First = First.childNodes.length ? First.childNodes[0].nodeValue : "" ;
    				
    			var Last = xmlDoc.getElementsByTagName("Surname")[0]; 
    				Last = Last.childNodes.length ? Last.childNodes[0].nodeValue : "" ;
    								  
    				set_cookie("CardFirst" + num, First) ;
    				set_cookie("CardLast" + num, Last) ;
    			
    			// check to request next Time Schedule
    			if (num == "240") // Max 24 (24 x 10 = 240 Users)
    			{
                     alert("done");
    			}
    			else
    			{
                                        // need to work out how to find out what the last Cardxx is
    				num = parseInt(num) + parseInt(1);
    				var temp = setTimeout("CardName(" + num + ")",1);
    					
    			}
    			} else
    			{
    				alert('Panel not communicating. Reason Code: '+xmlhttp.status);
    			}
    	}	
    	
    	xmlhttp.open("POST",url,false);
    	xmlhttp.send();			
    }
