
window.onload = function () {
	
	var SecImgNum=new Array("9372.gif","8608.gif","4321.gif","3543.gif","2500.gif");
	var len = SecImgNum.length;
	var rndImgIs = Math.round((len-1)*Math.random());
	var theNumis=SecImgNum[rndImgIs];
	document.getElementById('SecImg').src="images/"+theNumis;
	
// Activate when user clicks the submit button on the form.
document.getElementById("form1").onsubmit = function() {
	errors = 0;		
	
	story = document.getElementById("story").value;
	secureImg = document.getElementById("securityImg").value;
	
	if (story == "") {
		document.getElementById("story_error").innerHTML = "Please enter a story prior to submitting the form.";
		document.getElementById("story").style.borderColor = "#ff0000";
		errors++;
	} else {;
		document.getElementById("story_error").innerHTML = "";
		document.getElementById("story").style.borderColor = "#6f4242";
	}
	
	
	theNumis=theNumis.split(".");
	theNumis=theNumis[0];
	
	if (secureImg.length < 1) {
		document.getElementById("secimg_error").innerHTML = "Please enter the value shown on the image.";
		document.getElementById("securityImg").borderColor = "#ff0000";
		errors++;
	} else if (secureImg != theNumis) {
		document.getElementById("secimg_error").innerHTML = "The values on the image does not match the values you entered.";
		document.getElementById("securityImg").borderColor = "#ff0000";
		errors++;
	} else {
		document.getElementById("secimg_error").innerHTML = "";
		document.getElementById("securityImg").style.borderColor = "#6f4242";
	}
	
	document.getElementById("error_message").innerHTML = "";		
	if (errors > 0) {
		document.getElementById("error_message").innerHTML = "The form will not submit.<br /> You have missing or invalid entries.";
		return false;
	}

}

}
