/*
	All the files here are used for ajax control and initialisation
*/

// used to hold xml arrays
var XMLarray;
var SEARCHFOCUS = 0;

// instantiate the ajax class
function newAjax() {
	var Ajax;	// used to hold the instance for this class
	// test to see if this is FF family and instantiate the xml http request class
	try {
		// Firefox, Opera 8.0+, Safari
		Ajax = new XMLHttpRequest();
	}
	// catch an error and react
	catch (e) {
		// test to see if this is IE family and instantiate the xml http request class
		try {
			Ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			// test to see if this is old IE family and instantiate the xml http request class
			try {
				Ajax = new ActiveXObject("Microsoft.XMLHTTP");
			}
			// alert to the user this is not a ajax viable option
			catch (e) {
				alert("AJAX Sams4 application could not be instantiated, ERROR #001");
				return false;
			}
		}
	}
	return Ajax;	// return this instance
}

// instantiate a generic ajax class
var Ajax = newAjax();

function url_encode(text) {
		text = text.replace(/\+/g, "%2B");
		text = text.replace(/#/g, "%23");
		
		return text;
}

// send the message to irc
function populate_element(id, url) {
	var element = document.getElementById(id);
	
	if (element) {	// make sure the elements exist
		// send this to irc pm
		Ajax.open("GET", url_encode(url), false);
		// send null as a touch
		Ajax.send(null);

		// apply to chat window
		element.innerHTML = Ajax.responseText;
	}
}