
// Module version: 1.01.01



function showError(ErrorMess) {
 alert( ErrorMess );
}



function checkNotBlank( val ) {

 var valCk = new String( val );

 if ( valCk.length <= 0 ) { 
  return false;
 } else { return true; }


}




////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function IsEmailValid(checkThisEmail) {
var myEMailIsValid = true
var myAtSymbolAt = checkThisEmail.indexOf('@')
var myLastDotAt = checkThisEmail.lastIndexOf('.')
var mySpaceAt = checkThisEmail.indexOf(' ')
var myLength = checkThisEmail.length


// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID

if (myAtSymbolAt < 1 ) 
{myEMailIsValid = false}


// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID

if (myLastDotAt < myAtSymbolAt) 
{myEMailIsValid = false}

// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID

if (myLength - myLastDotAt <= 2) 
{myEMailIsValid = false}


// no empt<y space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid

 if (mySpaceAt != -1) 
 {myEMailIsValid = false}

 

 return myEMailIsValid
}





function checkEnqDetails() {


 // Name and Surname
 if ( ! checkNotBlank( document.frm.name.value ) ) {
  showError( 'You have not entered your name. Please enter your Name in the Name box.' );
  document.frm.name.focus(); 
  return false;
 }


if ( ( ! checkNotBlank( document.frm.email.value ) ) && ( ! checkNotBlank( document.frm.telno.value ) ) ) 
{
	showError( 'You have left both the Telephone Number and your E-mail Address entries blank. Please enter at least one of them.' );
	document.frm.email.focus(); 
    return false;
}


 // Enquiry Box
 if ( ! checkNotBlank( document.frm.suggestion.value ) ) {
  showError( 'You have not entered anything relating to your enquiry. Please fill in the Enquiry box.' );
  document.frm.suggestion.focus(); 
  return false;
 }



 // EMAIL
 if ( ! checkNotBlank( document.frm.email.value ) ) {

	// Allow blank email
	
 }
 else
 {

 	  // Not blank - is it valid?
	  if ( ! IsEmailValid( document.frm.email.value ) ) 
	  {
		 showError( 'You must supply a valid E-Mail address.' );
		 document.frm.email.focus(); 
		 return false;
	  }
	
 }





 
return true;

}



