Source: FileReader.js

/**
 * reads the given text file into a string and stores it in globalText. The text is also split into words and stored in the globalTextArray
 * 
 * @param {File} file A text file
 */
function parseFile(file)
{
	document.getElementById("status_icon").src = "images/yellow.png";
	
	// check if the file exists and has the correct extension
	if (!file || !file.type.match(/text.*/)) {
		document.getElementById("status_icon").src = "images/red.png";
		return;
	}
    
	var reader = new FileReader();
	
	// read the file
	reader.onloadend = function(e) {
        globalText = reader.result;
        globalTextArray = globalText.match(/\w+/g);

        for (var i = 0; i < globalTextArray.length; i++) {
        	globalTextArray[i] = globalTextArray[i].toLowerCase();
        }
        
        document.getElementById("status_icon").src = "images/green.png";
    };
    
    reader.readAsText(file);
}