function AjaxConnection(uri) 
{
   this.setOptions=setOptions;
   this.getOptions=getOptions;
   this.connect=connect;
   this.connect_response_is_text = connect_response_is_text;
   this.uri=uri;
}

function setOptions(opt)
{
   for(i=0;i<opt.length;i++)  
   {
      this.options += "&"+opt[i];
   }
}

function getOptions()
{
   return this.options;
}

function connect(return_func)
{
    with(this)
    {
        x=init_object();
        x.open("POST", uri,true);
        x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	    x.setRequestHeader("Content-length", options.length);
	    x.setRequestHeader("Connection", "close");
        x.onreadystatechange = function() {
                if (x.readyState != 4)
                        return;
                eval(return_func + '(x.responseXML)');
                delete x;
        }
        x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        x.send(options);
    }
}

function connect_response_is_text(return_func)
{
    with(this)
    {
        x=init_object();
        x.open("POST", uri,true);
        x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	    x.setRequestHeader("Content-length", options.length);
	    x.setRequestHeader("Connection", "close");
        x.onreadystatechange = function() {
                if (x.readyState != 4)
                        return;
                eval(return_func + '(x.responseText)');
                delete x;
        }
        x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        x.send(options);
    }
}

function init_object()
{
	var x;
	try {
	        x=new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	        try {
	                x=new ActiveXObject("Microsoft.XMLHTTP");
	        } catch (oc) {
	                x=null;
	        }
	}
	if(!x && typeof XMLHttpRequest != "undefined")
	        x = new XMLHttpRequest();
	        if(x.overrideMimeType) {
	        	x.overrideMimeType('text/xml; charset=ISO-8859-1');
	        }
	if (x)
	{
	    return x;
	}
}

function parseXML(xmlDoc)
{
	if(typeof(xmlDoc) != "undefined")
	{
		var x = xmlDoc.getElementsByTagName('item');
		arrOfObjects = new Array;
		
		for (i=0; i < x.length; i++)
		{
			tmpArray = new Array;
			itemCnt = 0;
			for (j=0; j < x[i].childNodes.length; j++)
			{
				if (x[i].childNodes[j].nodeType != 1) continue;
				
				tmpArray[itemCnt] = x[i].childNodes[j].firstChild.nodeValue;
				itemCnt ++;
			}
			
			arrOfObjects[i] = tmpArray;
		}
		
		return arrOfObjects;
	}
	
	return new Array();
}