function someFunction() {
	// this function just displays a message to say it worked
	alert("This worked!");
	}

function XHR() {
	try {
		return new XMLHttpRequest();
	}
	catch(e) {
		try {
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e) {
		return false;
			}
		}
	}

function writeQuote() {
	getText("quotes.txt");
	}
	
function getText(textFile) {
	var request = XHR();
	var paragraph = document.getElementById('randomQuote');
	if (!request) { alert("No XMLHttpRequest object!"); return; }
	request.open('get',textFile);
	// get the file you want
	request.onreadystatechange=function() {
		if(request.readyState == 1){
		// what to do while waiting
        paragraph.firstChild.nodeValue = "loading...";
      }
		if(request.readyState == 4) {
			if (request.status && /200|304/.test(request.status)) {
				// what to do when you get the response
				var quotes = new Array();
				quotes = request.responseText.split(/\r?\n/);
				var quoteNumber = Math.floor(Math.random()*(quotes.length));
				var quote = quotes[quoteNumber];
				paragraph.firstChild.nodeValue = quote;
				} else { 
				// what to do when the response is an error
				alert("XMLHttpRequest failed with status " + request.status);
				}
			}
		}
	request.setRequestHeader('If-Modified-Since','Wed, 05 Apr 2006 00:00:00 GMT');
	request.send(null);
	return;
	}

function addJSLink(elementId, onClickFunction, linkText) {
	// check for DOM support
	if (!document.getElementById(elementId)) { return; }
	// get the element we want to add the link to
	var element = document.getElementById(elementId);
	// create the link
	var link = document.createElement("a");
	// create the text for the link
	var linkTextNode = document.createTextNode(linkText);
	// add the text to the link
	link.appendChild(linkTextNode);
	// add the function to the onClick method of the link
	link.onclick = onClickFunction;
	// make the href of the link the element we are using
	link.href="#"+elementId;
	// add a space to the end of the quote containing element
	var space = document.createTextNode(" ");
	element.appendChild(space);
	// add the link to the end of the quote containing element
	element.appendChild(link);
	}

// load the function when the DOM has loaded
window.onload = load;

function load()
{
	// when the window loads we call the above function
	// with the parameters randomQuote, the id of the 
	// paragraph we have the quotes in, someFunction
	// which is the function you can see at the top, and "New Quote!"
	// the link text that will be displayed.
	addJSLink('randomQuote',writeQuote,'New Quote!');
}
