// JavaScript Document
function alertMissing(x){
alert ("All the boxes marked with an asterisk (*) must be completed.\n\nPlease " + x );
}

function trim(str)
//removes white space from beginning and end of string
{  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
}

function ValidateTextArea(AddStr){ 
	EscString = escape(AddStr); // encode string's carriage returns and spaces
	while (EscString.indexOf("%20") > -1){ 
			EscString=EscString.replace("%20",'');
			}
	while (EscString.indexOf("%0A") > -1){ 
			EscString=EscString.replace("%0A",'');
			}
	while (EscString.indexOf("%0D") > -1){ 
			EscString=EscString.replace("%0D",'');
			}
		
	//alert(EscString);
return EscString; 
}

function validateString(TestStr)
//returns true if string contains anything other than digits, letters, spaces  or . - _'
{
  validPattern = /[^0-9a-zA-Z\s\.\-_'!?&,]/;
    if (TestStr.search(validPattern) == -1)
   {
     return false;
    } 
    return true; 
}

function validateEmail(TestStr)
//returns true if email is invalid pattern
{
  validPattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;
   // search email text for regular exp matches
    if (TestStr.search(validPattern) == -1) 
   {
     return true;
    } 
    return false; 

}

function validateDoB(TestStr)
//returns true if DoB is not DD/MM/YY
{
  validPattern = /^[0-9]{2}\/[0-9]{2}\/[0-9]{2}$/;
    if (TestStr.search(validPattern) == -1) 
   {
     return true;
    } 
    return false; 

}

function validateTelNo(TestStr)
//returns true if Telephone number contains anything other than digits or spaces
{
  validPattern = /[^0-9/\s]/;
    if (TestStr.search(validPattern) == -1) 
   {
     return false;
    } 
    return true; 

}

function validatePostCode(TestStr)
//returns true if Post Code contains anything other than digits, letters or spaces 
{
  validPattern = /[^0-9a-zA-Z\s]/;
    if (TestStr.search(validPattern) == -1)
   {
     return false;
    } 
    return true; 

}
