var unreserved = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.~";
var hexchars   = "0123456789ABCDEFabcdef";

function gethex(decimal)
{
	return "%" + hexchars.charAt(decimal >> 4) + hexchars.charAt(decimal & 0xF);
}

function urlEncode( str )
{
	var decoded = str;
	var encoded = "";

	var notascii = "";

	for(var i = 0; i < decoded.length; i++)
	{
		var ch = decoded.charAt(i);

		if (unreserved.indexOf(ch) != -1)
		{
			encoded = encoded + ch;
		}
		else
		{
			var charcode = decoded.charCodeAt(i);
			encoded = encoded + gethex(charcode);
		}
	}

	return encoded;
}

function __nextChild()
{
	this.__current_child ++;
	while(this.__current_child < this.node.childNodes.length)
	{
		if(this.node.childNodes[this.__current_child].nodeName != '#text')
		{
			return this.node.childNodes[this.__current_child];
		}
		this.__current_child ++;
	}

	return false;
}

function NodeIterator( node )
{
	this.__current_child = -1;
	this.node            = node;
	this.nextChild       = __nextChild;
}

var xmlHttpReq = null;
var onXMLDone  = null;

function isXMLHTTPBusy()
{
	return null != xmlHttpReq;
}

function onReadyStateChanged()
{
	if(xmlHttpReq.readyState == 4)
	{
		if( onXMLDone )
		{
			onXMLDone( xmlHttpReq );
		}
		xmlHttpReq = null;
		onXMLDone  = null;
	}
}

function newXMLHTTP()
{
	if( window.XMLHttpRequest )
	{
		xmlHttpReq = new XMLHttpRequest();
	}
	else
	{
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	return xmlHttpReq;
}

function sendRequest(page, prm)
{
	var url = page;

	if( prm )
	{
		var isFirst = true;
		for(pKey in prm)
		{
			if( isFirst )
			{
				url += '?';
				isFirst = false;
			}
			else
			{
				url += '&';
			}
			url += urlEncode(pKey) + '=' + urlEncode(prm[pKey]);
		}
	}

//	window.location = url;
//	return;

	xmlHttpReq.open("GET", url, true);
	xmlHttpReq.onreadystatechange = onReadyStateChanged;
	xmlHttpReq.send('');
}

