/*
  jsSubmitValidator.  Written by Joe McCormack, virtualsecrets.com.
  This script prevents a web from from being accidentally submitted when the 'enter' key is pressed at the focus of a form element or dialog box.
*/
var targetFieldID = "", validationWatch = 0, validationTrigger = 0;
function validationPrompt(target, msg) {
if (validationWatch == 0) {
validationWatch = 1;
if (confirm(msg) == true || confirm(msg) == false) {
						    targetFieldID = target;
						    if (navigator.userAgent.toLowerCase().indexOf("msie") > -1) { validationFocus(); }
						    else { setTimeout("validationFocus()", 100); }
			  			   }
			  }
}
function validationFocus() {
var targetTxtFieldContent = document.getElementById(targetFieldID).value;
var oRange; var iStart = 0, iEnd = 0;
iEnd = targetTxtFieldContent.length;
if (navigator.userAgent.toLowerCase().indexOf("msie") > -1) {
							     oRange = document.getElementById(targetFieldID).createTextRange();
							     oRange.moveStart("character", iEnd); oRange.moveEnd("character", iEnd);
							     oRange.select();
							    }
else {
      oRange = document.getElementById(targetFieldID).setSelectionRange(iEnd, iEnd);
     }
validationWatch = 0; validationTrigger = 0;
document.getElementById(targetFieldID).focus();
}
/*
  FORM ELEMENT VALIDATION
*/
function straightStringPattern(data) {
/* Returns false if string has more than a-z, A-Z and whitespace */
var result = true;
var accuratePattern = /[^a-zA-Z\s]/;
if (accuratePattern.test(data) == true)  { result = false; }
return result;
}
function validationCheck(target) {
/* This is used to validate a single element and is triggered when focus is lost from the element */
validationTrigger = 1;
if (straightStringPattern(document.getElementById(target).value) == false) { validationPrompt(target, "Only alphabetic characters are allowed."); }
else { validationTrigger = 0; }
}
function validationCheckGroup() {
/* This is used to validate all applicable elements in the form when the enter key is pressed */
var result = true, msg = "";
if (straightStringPattern(document.getElementById("test").value) == false) {
									    msg = "Only alphabetic characters are allowed.";
									    targetFieldID = "test";
									    result = false;
									   }
/* Put another statement here to test the validity of another element, if any */

/* Show validation failure message */
if (msg.length > 0) { validationPrompt(targetFieldID, msg); }
return result;
}
