// CLASS ajax , constructor
/*
*
*
*	urlComponents 	: assoc array with the index beeing the name of the url variable
*					and the value as the variables value
*
*/
function _aim_Ajax(baseUrl,urlComponents,method_) {
	this.xmlHttp = null;			// the xmlhttp object
	this.url = baseUrl;			// url send by ajax
	this.method = method_;			// post or get
	this.components = urlComponents;	// array of name and value pair
	this.valueSTR = "";			// string url encoded for sending through ajax
	/*
		build url
	*/

	switch(this.method) {
		case "GET":					// get method
			var counter=0;
			for(i in this.components) {	// build componets string
				this.valueSTR += counter == 0 ?
									(i+"="+encodeURIComponent(urlComponents[i]))
											  :
									("&"+i+"="+encodeURIComponent(urlComponents[i]));
				counter++;
			}
			counter=null;
			this.url += "?"+this.valueSTR;	// build whole url that will be sent
		break;

		case "POST":				// post method
			var counter=0;
			for(i in this.components) {	// build components string
				this.valueSTR += counter == 0 ?
									(i+"="+encodeURIComponent(urlComponents[i]))
									:
									("&"+i+"="+encodeURIComponent(urlComponents[i]));
				counter++;
			}
			counter=null;
		break;
	}


	//	end build url
}
// create xml http req
_aim_Ajax.prototype.createRequest = function () {
	try {
		this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		} catch (oc) {
			this.xmlHttp=null;
		}
	}
	if(!this.xmlHttp && typeof XMLHttpRequest != "undefined")
		this.xmlHttp = new XMLHttpRequest();

	if (this.xmlHttp)
		return this.xmlHttp;
}

_aim_Ajax.prototype.openConnection = function () {
	// just to be cautious , neved really used
		this.xmlHttp.onreadystatechange = function () {} // clear any previous set handlers
	this.xmlHttp.abort();					 // close any previous connections

	// open connection
	this.xmlHttp.open(this.method, this.url, true);

	// if post is beeing used to send data to php
	if(this.method == "POST") {
		this.xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		this.xmlHttp.setRequestHeader("Content-length",this.valueSTR.length);
		this.xmlHttp.setRequestHeader("Connection","close");
	}
}


_aim_Ajax.prototype.sendRequest = function () {

	if(this.method == "POST") { 	// if post
		this.xmlHttp.send(this.valueSTR); // send post data
	} else {						// if get , no data needed , its all in the url
		this.xmlHttp.send(null);
	}
		// force xml response , pass 4096 ff or netscape limit
		if (this.xmlHttp.overrideMimeType) { // ie does not have this
		this.xmlHttp.overrideMimeType('text/xml');
	}
}