//all the functions needed for the Event Listener
function eventListener() {}
eventListener.registerEvent = function(baseurl, theform){
	var theText = "<a href=\"http://lmgtfy.com/?q=" + theform.lmgtfy.value + "\">Let Me Google That For You</a>";
	var data = {Event:{Title:'Custom Event', Text: ''+theText, SiteUrl:'http://lmgtfy.com/', LogoUrl: 'http://community.bskyb.com/images/lmgtfy_logo.jpeg', Data:'A user custom event happened'}};
	var theurl = baseurl + Object.toJSON(data);
	
	//build AJAX XMLHttpRequest Object
	var xmlhttp = pluckUtils.getXMLHttpRequestObject();
	
	if (xmlhttp === null) {
		alert ("Your browser does not support AJAX. Upgrade your browser!");
		return;
	}
	
	//process AJAX request
	xmlhttp.open("GET", theurl, true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange = function() {
		//if server has completed processing
		if(xmlhttp.readyState === 4) {
			//if http response is OK
			if(xmlhttp.status >= 200 && xmlhttp.status < 300) {
				var data = xmlhttp.responseText.evalJSON();
				console.dir(data);
				alert("Response Message = " + data.Response.Message);
				theform.lmgtfy.value = "";
			} else if (request.status == 404) {
		        alert("Requested URL is not found.");
		    } else if (request.status == 403) {
		        alert("Access denied.");
		    } else {
				alert("HTTP status code returned is: " + xmlhttp.status); 
			}
		}
	}
	//stop the form submit - no need to refresh the page.
	return false;
}
