var phone_exp=/^\d{10}$/g
var reWhitespace = /^\s+$/
var email_exp = /^[\w-\.]{1,}\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
var zip_exp = /^\d{5}$|^\d{5}[\-\s]?\d{4}$/
var letter_exp = /[a-z'-]/ig
var noDBQuote_exp = /[a-z'-.,d]/ig
var digits_exp = /\d/ig
var date_exp = /^0?(\d{1,2})\D+0?(\d{1,2})\D+(\d{2}|\d{4})$/;
var date_out = "$1/$2/$3";

var simple_char=/\^w|\^W[^\,\!\?\|\\]/ig;
var single_exp1 = /[\’]/ig
var single_exp2 = /[\‘]/ig
var single_exp3 = /[\”]/ig
var single_exp4 = /[\“]/ig
var single_exp5 = /[\—]/ig
var single_exp6 = /[\…]/ig
var single_exp7 = /[\"]/ig

// -------
function validate_password(inputValue, fieldName)
{
   var ERRORS = "";
   if((inputValue.value=="") || (isWhitespace (inputValue.value)))
   {
      return ERRORS+=fieldName;
   }
   else 
   { 	
   	  //value=inputValue.value.replace(/\s/g, "")			  					
      if  ((inputValue.value.search(/\s/gi)) !=-1)
          return ERRORS+=fieldName; 			  					
      if  ((inputValue.value.search(single_exp7)) !=-1)
          return ERRORS+=fieldName;			  
      if ( (inputValue.value.length < 4) || (inputValue.value.length > 10) )        
          return ERRORS+=fieldName;           
   }   
}

// -------
function validate_zip(inputValue, fieldName )
{	
/*
	if((inputValue.value=='')||(isWhitespace (inputValue.value)))
                 return ERRORS+=fieldName;
        else {   
        
                             
            if (!isValid(zip_exp,trimLeadSpace(inputValue.value))) 
            return ERRORS+=fieldName;
            }               
*/
	return ERRORS;
}                        

// validate e-mail 
// -------
function validate_email(inputValue, fieldName)
{
    var ERRORS = "";
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	var addr = inputValue.value;
	
	if((inputValue.value=='') ||(isWhitespace(inputValue.value)))
	{
       return ERRORS+=fieldName;
    }
    else 
    {
        for (i=0; i<invalidChars.length; i++) 
        {
			 if (addr.indexOf(invalidChars.charAt(i),0) > -1) 
			     return ERRORS+=fieldName;
		}
		
		for (i=0; i<addr.length; i++) 
		{
		   if (addr.charCodeAt(i)>127) 
				 return ERRORS+=fieldName;
		}
		
		var atPos = addr.indexOf('@',0);
		if (atPos == -1) 
		    return ERRORS+=fieldName;
		
		if (atPos == 0) 
		    return ERRORS+=fieldName;
		    
		if (addr.indexOf('@', atPos + 1) > - 1)
		    return ERRORS+=fieldName;
		    
		if (addr.indexOf('.', atPos) == -1) 
		    return ERRORS+=fieldName;
		
		if (addr.indexOf('@.',0) != -1)
		    return ERRORS+=fieldName;
		    
		if (addr.indexOf('.@',0) != -1)
		    return ERRORS+=fieldName;
		
		if (addr.indexOf('..',0) != -1) 
		    return ERRORS+=fieldName;
		    
		var suffix = addr.substring(addr.lastIndexOf('.')+1);
		if (suffix.length < 2)
		    return ERRORS+=fieldName;
	}    
}
       		
// validate required fields	
// -------	        
function validate_required(inputValue, fieldName)
{
   if((inputValue.value=='') ||(isWhitespace(inputValue.value)))
      return ERRORS+=fieldName;
}

// validate required fields	
// -------	        
function validate_confirmation(inputValue1,inputValue2, fieldName)
{
   if(inputValue1.value != inputValue2.value)
      return ERRORS+=fieldName;
}
	
// -------	
function WriteRequired(id,text) 
{
   if( document.getElementById("ErrorTbl") != null ) 
   {
      document.getElementById("ErrorTbl").style.display = "block";			
   }
   
//   document.getElementById(id).style.backgroundColor = "#FF5400";
//   document.getElementById(id).style.color = "#FFFFFF";
   document.getElementById(id).innerHTML = text;		
}

// Check whether string s is empty
// -------	
function isEmpty(str)
{   
   return ((str == null) || (str.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only
// -------	
function isWhitespace (str)
{   
   // Is s empty?
   return (isEmpty(str) || reWhitespace.test(str));
}

// -------
function flagField( fieldName )
{
	var obj = GetDocElement( fieldName );
	if( obj != null
	    && ( obj.type == "text" || obj.type == "select-one" || obj.type == "password" )) 
	{
	    obj.style.backgroundColor = "#FDFEA4";	
	}       
}
   
// -------
function unflagInputField( fieldName )
{
	var obj = GetDocElement( fieldName );
	if( obj != null ) 
	{
    	document.getElementById( fieldName ).style.backgroundColor = "#ffffff";	
    }
}

// validate email address using regex
function isValidEmailAddress (emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function isValidUKMobileNo (mobileNo) {
	var pattern = new RegExp(/^\+?(?:44|0|44 0)\s?7[5789][\s\d]{8}$/);
	return pattern.test(mobileNo);
}