msg = new Array(
"Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.",
"When war broke out between Spain and the United States, it was very necessary to communicate quickly with the leader of the Insurgents. Garcia was somewhere in the mountain fastnesses of Cuba - no one knew where. No mail or telegraph could reach him. The President must secure his co-operation, and quickly.",
"I know one man of really brilliant parts who has not the ability to manage a business of his own, and yet who is absolutely worthless to anyone else, because he carries with him constantly the insane suspicion that his employer is oppressing, or intending to oppress, him. He can not give orders, and he will not receive them.",
"And I will lay you ten to one that after you have answered the questions, and explained how to find the information, and why you want it, the clerk will go off and get one of the other clerks to help him find Garcia - and then come back and tell you there is no such man.",
"I have carried a dinner-pail and worked for a day's wages, and I have also been an employer of labor, and I know there is something to be said on both sides. There is no excellence, per se, in poverty; rags are no recommendation; and all employers are not rapacious and high-handed, any more than all poor men are virtuous."
)
var word = 10;
//var _resultsMessage = "1";

function wordCount(listing) {
return listing.replace(/^\s+/, '').replace(/\s$/, '').split(/\s+/).length
}

function beginIt() {
document.theForm.stop.style.visibility="visible";
document.theForm.start.style.visibility="hidden";
randNum = Math.floor((Math.random() * 10)) % 4;
msgType = msg[randNum];
day = new Date();
startType = day.getTime();
document.theForm.given.value = msgType;
document.theForm.typed.value = '';
document.theForm.typed.focus();
document.theForm.typed.select();
}
function tryA() {
document.theForm.start.style.visibility="visible";
lyrHide('typingResults');
lyrShow('typingTest');
document.theForm.given.value = '';
document.theForm.typed.value = ''
}
function cheat() {
alert("This is the typing test text, so you can not make changes here.");
document.theForm.typed.focus();
}
function stopIt() {
document.theForm.stop.style.visibility="hidden";
//document.theForm.start.style.visibility="visible";
lyrHide('typingTest');
lyrShow('typingResults');

word = wordCount(document.theForm.given.value);
wordsTyped = wordCount(document.theForm.typed.value);
dayTwo = new Date();
endType = dayTwo.getTime();
totalTime = ((endType - startType) / 1000);
spd = Math.round((word/totalTime) * 60);

if ((word - wordsTyped) > 5 ) {
//alert("You have made more than 5 errors so your typing speed can be averaged at 10 words per minute.\n\nWould you like to increase your typing speed?\n\nSee below for details on the KeyRight Look & Learn Typing Solution.");
document.getElementById('resultsText').innerHTML = "You have made more than 5 errors so your typing speed can be averaged at 10 words per minute.";
}
else if (document.theForm.typed.value == document.theForm.given.value) {
//alert("You typed a " + word + " word sentence in " 
//+ totalTime + " seconds, a speed of about " + spd + " words per minute.\n\nWould you like to increase your typing speed?\n\nSee below for details on the KeyRight Look & Learn Typing Solution.");
document.getElementById('resultsText').innerHTML = "You typed a " + word + " word sentence in " + totalTime + " seconds, a speed of about " + spd + " words per minute.";
//lyrHide('typingTest');
//lyrShow('typingResults');
document.theForm.given.value = '';
document.theForm.typed.value = '';
}
else {
//alert("You made an error, but typed at a speed of " + spd + " words per minute.\n\nWould you like to increase your typing speed?\n\nSee below for details on the KeyRight Look & Learn Typing Solution.");
document.getElementById('resultsText').innerHTML = "You made an error, but typed at a speed of " + spd + " words per minute.";
//lyrHide('typingTest');
//lyrShow('typingResults');
document.theForm.given.value = '';
document.theForm.typed.value = '';
   }
}
