function isValidPhone(elem, helperMsg)
{
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.length >= 10)// && elem.value.match(alphaExp))
	{
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isValidZip(elem, helperMsg)
{
	var numericExpression = /^[0-9]+$/;
	if(elem.value.length == 5 && elem.value.match(numericExpression))
	{
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isEmpty(elem, helperMsg)
{
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}

function isNumeric(elem, helperMsg)
{
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression))
	{
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg)
{
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp))
	{
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg)
{
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp))
	{
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max)
{
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max)
	{
		return true;
	}
	else
	{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg)
{
	if(elem.value == "Please Choose")
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function emailValidator(elem, helperMsg)
{
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp))
	{
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

// trim() function definition
// trims string
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

// checks if value entered into current field is a valid currency value
function CheckIfCurrency(sField)
{
	// declare and initialize variables
	var sValidValues = "0123456789."
	var sIsValid = "yes";
	var sCurrentCharacter = "";
	var nPeriodCount = 0;
 
	// check if each character in the field is valid
	for (var i = 0; i < sField.value.length; i++) 
	{
			sCurrentCharacter = "" + sField.value.substring(i, i+1);
	
			//check if there is more than one "."	
		if (sCurrentCharacter == ".")
			{
				nPeriodCount++;
			} // end if
	
			// if there is an invalid character or more than one "." than the user input is not valid
		if (sValidValues.indexOf(sCurrentCharacter) == "-1" || nPeriodCount > 1) 
			{
				sIsValid = "no";
			} // end if
	} // end for
	
	// if the user entered an invalid currency value than show error message and return focus to that field
	if (sIsValid == "no") 
	{
			alert("Must be a valid US Dollar amount!");
			sField.focus();
			sField.select();
	} // end if

} // end CheckIfCurrency()

// CheckIfValidPassword() function definition
// checks if value entered into current field is a valid password value
function CheckIfValidPassword(sField)
{
	// declare and initialize variables
	var sValidValues = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-!@#$%";
 	var sIsValid = "yes";
 	var sCurrentCharacter = "";
 
 	// check if each character in the field is valid
 	for (var i = 0; i < sField.value.length; i++) 
 	{
  		sCurrentCharacter = "" + sField.value.substring(i, i+1);
		
  		// if there is an invalid character input is not valid
		if (sValidValues.indexOf(sCurrentCharacter) == "-1") 
  		{
   			sIsValid = "no";
  		} // end if
 	} // end for
	
	if (!(sField.value.length >= 8 || sField.value.length == 0))
	{
		sIsValid = "no";
	} // end if
	
	// if the user entered an invalid number value than show error message and return focus to that field
 	if (sIsValid == "no") 
 	{
  		alert("Password must be 8 or more characters long and cannot contain special characters!");
  		setTimeout("document.forms[0]."+sField.name+".focus();",0);
  		setTimeout("document.forms[0]."+sField.name+".select();",0);
		return false;
	} // end if
	else
	{
		return true;
	} // end else
	
} // end CheckIfValidPassword()

// CheckIfValidEmail() function definition
// checks if value entered into current field has a valid eMail syntax
function CheckIfValidEmail(sField)
{
	if ((sField.value.search( /\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,5}/ ) != -1) || (sField.value.length == 0))
	{
		return true;
	} // end if
	else
	{
		alert("Must be a valid e-mail entry!");
  		setTimeout("document.forms[0]."+sField.name+".focus();",0);
  		setTimeout("document.forms[0]."+sField.name+".select();",0);
	} // end else	
} // end CheckIfValidEmail()

// GetObj() function definition
// Get object from form
function GetObj(id,d)
{
	var i,x; if(!d) d=document;
	if(!(x=d[id])&&d.all) x=d.all[id];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][id];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=ylib_getObj(id,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(id);
	return x;
}
