addEventListener("load", function()
{
		setTimeout(updateLayout, 0);
}, false);

var currentWidth = 0;

function updateLayout()
{
		if (window.innerWidth != currentWidth)
		{
				currentWidth = window.innerWidth;

				var orient = currentWidth == 320 ? "profile" : "landscape";
				document.body.setAttribute("orient", orient);
				setTimeout(function()
				{
						window.scrollTo(0, 1);
				}, 100);            
		}
}

setInterval(updateLayout, 400);

function showtext(){

msg = new Array(
"iPhone is the phone of the future.",
"Can you type this phrase rather quickly?",
"I will never ever use an iPhone.",
"I like the iPhone user interface",
"Palm totally kicks iPhone's butt.",
"Typing is sort of hard on this thing.",
"Treo has a full keyboard for typing.",
"I have several issues including iPhone envy.",
"I will type circles around your iPhone.",
"My phone will totally school your iPhone!",
"iPhone is pretty much the best of all.",
"Windows mobile is your friend.",
"I like Blackberry the best of all",
"I like Nokia the best of all",
"iPhone can not play flash videos."

)

now = new Date();
seed = now.getSeconds();

var random_number = Math.random(seed);
var range = random_number*msg.length;
var rounded_number = Math.round(range);
if (rounded_number == msg.length){rounded_number = 0}
randSentence = rounded_number;
msgToType = msg[randSentence];
word = (msgToType.length/5);
document.getElementById('test').innerHTML = msgToType;

}

function beginIt() {



document.getElementById('reddot').innerHTML = 'go!';

day = new Date();
startType = day.getTime();
document.thisForm.typed.focus();
}

function monitor(){

	var testStr = document.getElementById('test').innerHTML;
	var uiStr = document.getElementById('ui').value;

          //  theRegEx = /^[^@]+@[^@]+.[a-z]{2,}$/i
          
          var testRegExp = RegExp('^.*' + uiStr + '.*')
          
		//var	testRegExp = /^uiStr/i

            if(testStr.search(testRegExp) == -1){

                        document.getElementById('isok').innerHTML = "<span style=\"color:red;\">Wrong! Correct your error!<\/a>";

            }else{
                        document.getElementById('isok').innerHTML = "<span style=\"color:#c5dd87;\">OK. Keep Going!<\/a>";;

            }
            
//YourString.replace(regularExpression, newSubString)

}

function stopIt() {
dayTwo = new Date();
endType = dayTwo.getTime();
totalTime = ((endType - startType) / 1000)
typedWord = ((document.thisForm.typed.value).length / 5);
spd = Math.round((typedWord/totalTime) * 60);
if (typedWord == 0) {
	alert("You didn't type anything")
}
else if (typedWord < (word - 1)) {
	document.getElementById('reddot').innerHTML = 'Oops. Try again!';

	alert("You didn't finish the sentence but you typed approximately " + typedWord + " words at a rate of " + spd + " words per minute.")
	document.getElementById('ui').value = '';
    showtext();

}
else {
	if (document.thisForm.typed.value  == document.getElementById('test').innerHTML) {
	
	document.getElementById('reddot').innerHTML = 'done!';
	
	alert("You perfectly typed " + typedWord + " words in " + totalTime + " seconds, a speed of about " + spd + " words per minute! Great job!!!!!");
	
	document.getElementById('ui').value = '';

    showtext();

	
	document.getElementById('score').innerHTML = '<p>You Typed '+ spd + ' WPM!<br><b>Save your Score?</b>';
	
	document.getElementById('rstform').innerHTML = '<input type="hidden" name="wpm" value="'+ spd +'"><p>Enter your Name <input type="text" name="name" value=""><br><input type="submit" value="submit"></p>';

	
	
	





	}
	else {
	alert("You made error(s) but you typed " + typedWord + " words in " + totalTime + " seconds, a speed of about " + spd + " words per minute!")
		 }
	}
}

