// JavaScript Document
<!--
/*=====================================================
/*************** The Forminator **********************
/* Form checking script by James Filby
/* (c)2011 James Filby
/* www.deadcowdesign.co.uk
/* jim@deadcowdesign.co.uk
/* Last revision: 19th August 2001
/* Version 1.0.1.0
/* This script is release under GNU license
/* You are free to use and distribute this script for
/* and purpose in any capacity, as long as this notice
/* remains in place.
=======================================================*/

/* Put the runCheck function in the body 'onload' event or
/* similar so that the input check runs when the page is
/* loaded. This will set up your initial 'required' tags
/* and also will check the input again if the page is
/* refreshed. 
/* You need to put all the form details in here for each 
/* field that you want to check.
*/

var falseRet;

function runCheck(){
	formulate('firstName','firstNameMess','firstName',true,true);
	formulate('email','emailMess','email',true,true);
	formulate('mobile','mobileMess','phone',true,true);
}

function subCheck(){
	falseRet = 0;
	formulate('firstName','firstNameMess','firstName',true,true);
	formulate('email','emailMess','email',true,true);
	formulate('mobile','mobileMess','phone',true,true);
	
	if(falseRet>0){
		alert ('Please check that all form fields are filled in correctly.');
		return false;
	}else{
		return true;
	}
}
/* The checkInput function is the alphanumeric input checking function. It has 
/* several parameters that need to be passed to it.
/* 1. inputFrom - this is the name of the input field's ID that you
/*    want to check. Make sure that each input field has a unique id.
/*
/* 2. messageDiv - this is the name of the div in which you want
/*    the output message to be displayed, I just put a SPAN with the id next to the
/*    INPUT field I want checking. Bear in mind that each messageDiv must have
/*	  a unique id.
/*
/* 3. type - this is the type of input that the field is sending. The
/*    system currently supports the following types of input:
/*	    First Name: pass 'firstName' to the parameter
/*		Last Name: pass 'lastName' to the parameter
/*		Email: pass 'email' to the parameter
/*
/* 4. required - this boolean parameter tells the script wether the
/*    field is a required field, and displays the 'required' message when the 
/*	  field is empty. Pass 'true' to make the field a required field, or pass
/*    'false' or leave blank to make field optional
/*
/* 5. strict - this boolean parameter turns on strict checking for
/*    fields that support it (currently only 'firstName' and 'lastName' support
/*    strict checking), with scrict checking enabled the system expects data in a 
/*    more precise format than with it off. For example, with strict checking set
/*	  to 'false' the firstName and lastName types will accept any value composed 
/*    of Upper and Lower case letters, and numbers spaces, tabs, the underscore 
/*    character and the dash character, allowing a more 'username' style input, with
/*	  strict set to 'true' the types adhere to much more stringent type-matching.
/*	  the typematching details are outlined below.
/*
/* Typematching: the email typematching field is relatively simple, as it has
/* no 'strict' mode, it simply checks the email address is valid. I didn't write
/* the RegExp for the email system (I got it from www.regular-expressions.info), but I
/* understand that it's good for about 99% of the email addresses out there.
/* The 'firstName' type when not in strict mode will accept all alphanumeric characters
/* in any order, as well as whitespace characters, the underscore character and the dash,
/* which makes it useful for doubling up as a 'username' field. In strict mode it will only
/* accept names which start with a capital letter, and are a least 2 letter characters long, so
/* for example 'Foo' is acceptable, but 'bar' is not (no capital letter), it will, however accept
/* single whitespace characters for users with multiple first names, so for example 'Foo Bar'
/* is acceptable. In strict mode firstName only takes letters and whitespace.
/* The 'lastName' field functions identically to the 'firstName' field with strict mode off. 
/* In strict mode the 'lastName' field will accept most common Western surnames, including those 
/* prefixed with O', like O'Reily, and also 'Mc' and 'Mac', it will also accept double barrel
/* surnames like 'Wothington-McAndrew', as long as the names are separated by either a dash or
/* a single whitespace character, and that is followed by another capital letter, so 
/* 'Wothington-smith' would not be acceptable.
*/
function formulate(inputFrom,messageDiv,type,required,strict){
	if (type=='firstName'){
		if (strict === true){
		var patt=/^(([A-Z]){1}([a-z]){1,}\s*?){1,}$/g;
		}else{
			var patt=/^[A-Z0-9_\-\s]{1,}$/gi;
		}
		var failMsg = 'Invalid';
		var okMsg = 'Ok';
		var reqMsg = 'Required';
	}
	
	if(type=='lastName'){
		if (strict === true){
		var patt=/^(([A-Z]{1}('|([a-z]{1,2}))){0,1}([A-Z]){1}([a-z]){1,}([\-\s](?=[A-Z]))*?){1,2}$/g;
		}else{
			var patt=/^[A-Z0-9_\-'\s]{1,}$/gi;
		}
		var failMsg = 'Invalid';
		var okMsg = 'Ok';
		var reqMsg = 'Required';
	}
	
	if(type=='email'){
			var patt=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/gi;
			var failMsg = 'Invalid';
			var okMsg = 'Ok';
			var reqMsg = 'Required';
	}
	
	
	if(type=='phone'){
			var patt=/^[0-9-+\s]{6,}$/gi;
			var failMsg = 'Invalid';
			var okMsg = 'Ok';
			var reqMsg = 'Required';
	}

	if((required== true)&&(document.getElementById(inputFrom).value == false)){
		falseRet ++;
		document.getElementById(messageDiv).innerHTML= '<img src="//www.deadcowdesign.co.uk/www/images/core/no-nose.png" class="formulatorTag"/><span class="fail">'+reqMsg+'</span><img src="//www.deadcowdesign.co.uk/www/images/core/no-tail.png"  class="formulatorTag" />';
	}else if((required== false)&&(document.getElementById(inputFrom).value == false)){
		document.getElementById(messageDiv).innerHTML= '';
	}else if(document.getElementById(inputFrom).value.match(patt)){
		document.getElementById(messageDiv).innerHTML= '<img src="//www.deadcowdesign.co.uk/www/images/core/yes-nose.png"  class="formulatorTag"/><span class="success">'+okMsg+'</span><img src="//www.deadcowdesign.co.uk/www/images/core/yes-tail.png" class="formulatorTag" />';
	}else{
		document.getElementById(messageDiv).innerHTML= '<img src="//www.deadcowdesign.co.uk/www/images/core/no-nose.png"  class="formulatorTag"/><span class="fail">'+failMsg+'</span><img src="//www.deadcowdesign.co.uk/www/images/core/no-tail.png"  class="formulatorTag" />';
		falseRet ++;

	}
}

																				   
//-->

