var http;
var elementContainer;

function createRequestObject() {
	var ro;

	// First, try to create an XMLHttpRequest object for most modern browsers.
	try { ro = new XMLHttpRequest(); }
	catch (error) {
		/* If the default method didn't work, try to create the object for Microsoft IE 5/6 using an ActiveX Object. */
		try { ro = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (error) { return false; }
	}
	return ro;
}

// retrieve a page using the XMLHttpRequest object.
function http_getPage(url,qs,post,callFunc) {
/* @param url			- URL to retrieve
	@param qs			- query string portion (GET or POST)
	@param post			- if 1, POST operation used (response is returned)
	@param callFunc	- function to call when done (if GET used)
*/
	http = createRequestObject();
	if (http) {
		if (post) {
		// POST operation...
			http.open("POST",url,false);
			http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			http.setRequestHeader("Content-length",qs.length);
			http.setRequestHeader("Connection","close");
			http.send(qs);
			return http.responseText;
		}
		else {
		// GET operation...
			//alert(url+((qs.length>0)?("?"+qs):""));
			
			http.open("GET",url+((qs.length>0)?("?"+qs):""));
			http.onreadystatechange=callFunc;
			http.send(null);
		}
	}
}


function util_hexnib(d) { if (d<10) return d; return String.fromCharCode(65+d-10); }
function util_hexbyte(d) { return "%"+util_hexnib((d&240)>>4)+""+util_hexnib(d&15); }

function URLEncode(value) {
	value=value.toString();
	var result="";
	var hex="";
	for(var i=0;i<value.length; i++) {
		var cc=value.charCodeAt(i);
		if (cc<128) { result+=util_hexbyte(cc); }
		else if((cc>127) && (cc<2048)) result += util_hexbyte((cc>>6)|192) + util_hexbyte((cc&63)|128);
		else result+= util_hexbyte((cc>>12)|224) + util_hexbyte(((cc>>6)&63)|128) + util_hexbyte((cc&63)|128);
	}
   return result;
}


