// empty string check GC120500
function VF(f, msg){
	if (f.value == "" || f.value.length ==0){
		alert(msg);
		f.focus();
		return (false);
	}
	else {
		for (x=0;x<f.value.length;x++){
			if (f.value.charAt(x)!=" "){
				return (true);
			}
		}
	alert(msg);
	f.select();
	f.focus();
	return (false);
	}
	return (true);
}

//	Email Validation - Check for @ and .
function EC(e, message){
	var re = /^([A-Za-z0-9\_\-]+\.)*[A-Za-z0-9\_\-]+@[A-Za-z0-9\_\-]+(\.[A-Za-z0-9\_\-]+)+$/;
    var sEMail = e.value;
    if (sEMail.search(re) == -1){
		alert(message);
        e.select()
        e.focus()
        return (false);
    }
    else{
		return (true);
    }
    
}

function validateName(oName, sMessage){
	//\'\.
	var re = /^([A-Za-z]+)[\-\ ]?([A-Za-z]+)+$/;
	var sName = oName.value;
	var bPassed = true;
	
	sName = Trim(sName);
	//First let's check for length of string
	if (sName.length != 0){
		//Now let's check if it's alpha
		if (sName.search(re) == -1){
			bPassed = false;
		}
		else{
			//Now Let's check for duplicate hyphones 
			if (bPassed){
				//Now Let's check for duplicate apostrophes
				if (findDuplicateChar(sName,'-')){
					bPassed = false;
				}
			}
			if (bPassed){
				//Now let's check for duplicate spaces
				if (findDuplicateChar(sName,' ')){
					bPassed = false;
				}
			}
		}
	}
	else{
		bPassed = false;
	}
	
	if (!bPassed){
		//sMessage = 'The name you have entered may only contain letters, a signle hyphen,\na single space, a period or an apostrophe';
		if (sMessage.length == 0)
			sMessage = 'The name you have entered may only contain letters and a single space. \nPlease omit any periods, apostrophes or extra spaces.';
		alert(sMessage);
        oName.select();
        oName.focus();
        return(false);
	}
	else{
		return(true);
	}
}

function findDuplicateChar(sString, sFind){
	var arySplit = sString.split(sFind);
	if (arySplit.length > 2)
		return true;
	else
		return false;
}
/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str)
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...
      var i = s.length - 1;       // Get length of string
      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i=i-1;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

function Trim(str)
{
   return RTrim(LTrim(str));
}
//-->