// original javascript by max hoy (maxhoy.co.uk) //

//field tester
function checkIncluded(textField,title) {
var msg = "\n Please enter your ";
var msg2 = title;
	if(document.getElementById(textField).value==''){
	FCRes = 1;
	alertMsg = (msg+msg2);
	alertTxt = (alertTxt + alertMsg);
		if (FocusEl == "") {
			FocusEl = textField;
		}
	}
}

// email address tester
function checkEmail(emailField) {
	if (document.getElementById(emailField).value=='') {
		FCRes = 1;
		alertMsg = "\n Please enter your email address ";
		alertTxt = (alertTxt + alertMsg);
				if (FocusEl == "") {
					FocusEl = emailField;
				}
	} else {
		// check character positions
		var locationOfAt = document.getElementById(emailField).value.indexOf("@");
		var locationOfDot = document.getElementById(emailField).value.indexOf(".");
		//alert ("at "+locationOfAt);
		//alert ("dot "+locationOfDot);
		
			if ((locationOfAt < 0) || (locationOfDot < 0)) {
			FCRes = 1;
			alertMsg = "\n Please enter a valid email address";
			alertTxt = (alertTxt + alertMsg);
				if (FocusEl == "") {
					FocusEl = emailField;
				}
			} else {
			// check first dot position
				if (locationOfDot < locationOfAt) {
				var field_array=document.getElementById(emailField).value.split("@");
				//alert(field_array[0]);
				//alert(field_array[1]);
				var locationOfDot2 = field_array[1].indexOf(".");
				//alert("dot2 "+locationOfDot2);
				var locationOfDot3 = (locationOfDot2+locationOfAt);
				//alert(locationOfDot3);
				}
				// check second dot position
				if (locationOfDot3 < locationOfAt) { 
				FCRes = 1;
				alertMsg = "\n Please enter a valid email address";
				alertTxt = (alertTxt + alertMsg);
				if (FocusEl == "") {
					FocusEl = emailField;
				}
				}
			}
	}
}

// check field is numeric
function checkNumber(numberField, title) {
fieldValue = document.getElementById(numberField).value;

// removes spaces from number before validation
//spaceIndex = fieldValue.indexOf(" ");
//while (spaceIndex > -1) {
//	spaceIndex = fieldValue.indexOf(" ");
//	fieldValue = fieldValue.replace(" ","");
//}

if (fieldValue=='') {
		FCRes = 1;
		var msg = "\n Please enter your ";
		var msg2 = title;
		var msg3 = " number";
		alertMsg = (msg+msg2+msg3);
		alertTxt = (alertTxt + alertMsg);
				if (FocusEl == "") {
					FocusEl = numberField;
				}
	} else {
		NoRes = 0;
		//character checker
			for(i=0; i<fieldValue.length; i++) {
				if ((fieldValue.charAt(i) < "0") || (fieldValue.charAt(i) > "9" )) {
					// allow spaces
					if (fieldValue.charAt(i) != " ") { NoRes = 1; }
   				}
  			}
			if (NoRes != 0) {
				document.getElementById(numberField).focus();
				FCRes = 1;
				alertMsg = "\n Your phone number is not numeric";
				alertTxt = (alertTxt + alertMsg);
				if (FocusEl == "") {
					FocusEl = numberField;
				}
			}
	}
}