/*************************************************************************
* Form validator - © nuSTUDIOS
* adapted from http://www.xs4all.nl/~sbpoley/webmatters/formval.html
*	and http://www.sitepoint.com/article/form-validation-client-side
*************************************************************************/

var globVar; // Global variable

function myFocus()
{
  globVar.focus();
  globVar.select();
}

function delayFocus(field)
{
  // save field in global variable
  globVar = field;
  setTimeout( 'myFocus()', 100 );
}

// Removes trailing and leading spaces
function trim(str) {
  return str.replace(/^\s+|\s+$/g, '');
}

function checkEmail(email) {

	var input = trim(email.value);
	var bool = 0;
	var mask = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/ ;
	//var mask = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
	
	// Check for valid email based on mask above
	if(!mask.test(input) ) { bool = 1;}

	if (bool == 1)
	{
		alert('Please enter a valid email');
		delayFocus(email);
	}
	
	return false;
}

function checkName(nField) {

	var input = trim(nField.value);

	var mask = /^([a-zA-Z]{2,}\s?)+$/ ;
	
	if(!mask.test(input) )
	{ 
		alert('Please enter your name (characters only. NO digits, symbols or punctuations)');
		delayFocus(nField);
	}
	
	return false;
}

function checkMsg(msg) {

	var input = trim(msg.value);
	var check = 0;

	if (input == "" ) { check = 1;}
	
	if(check == 1)
	{
		alert('Please enter your enquiry in the box provided');
		delayFocus(msg);
	}
	
	return false;
}

function checkSub(inField) {
	if (inField.value == "") {
    	alert("Please make a selection");
	}
    return false;
}
