var xmlreqs = new Array();

function CXMLReq(freed) 
{ 
    this.freed = freed; 
    this.xmlhttp = false; 
    if (window.XMLHttpRequest) 
    { 
        this.xmlhttp = new XMLHttpRequest(); 
    } 
    else if (window.ActiveXObject) 
    { 
        this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
} 


function xmlreqPOST(url,data) 
{ 
    var pos = -1; 
    for (var i=0; i<xmlreqs.length; i++) 
    { 
        if (xmlreqs[i].freed == 1) 
        { pos = i; break; } 
    } 
    if (pos == -1) 
    { 
        pos = xmlreqs.length; xmlreqs[pos] = new CXMLReq(1); 
    } 
    if (xmlreqs[pos].xmlhttp) 
    { 
        xmlreqs[pos].freed = 0; 
        xmlreqs[pos].xmlhttp.open("POST",url,true); 
        xmlreqs[pos].xmlhttp.onreadystatechange = function() 
                                                    { 
                                                        if (typeof(xmlhttpChange) != 'undefined') 
                                                        { 
                                                            xmlhttpChange(pos); 
                                                            
                                                        } 
                                                    } 
        xmlreqs[pos].xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
        xmlreqs[pos].xmlhttp.send(data); 
     } 
} 

function xmlhttpChange(pos) 
{ 
    if (typeof(xmlreqs[pos]) != 'undefined' && xmlreqs[pos].freed == 0 && xmlreqs[pos].xmlhttp.readyState == 4) 
    {      
            functionWhenDone(xmlreqs[pos].xmlhttp);
            xmlreqs[pos].freed = 1; 
    } 
}

function functionWhenDone(XML)
{
     document.getElementById(targetid).innerHTML=XML.responseText; 
}