/*
 * This file contains some utility functions useful in many simple operations and validations
 */




/*
 * This function removes any leading spaces in the string.
 */
function lTrim(strSource)
{
	var strValue=strSource.replace(/^(\s*)/, "");
	return strValue;
}


/*
 * This function removes any trailing spaces in the string.
 */
function rTrim(strSource)
{
	strValue=strSource.replace(/(\s*)$/, "");
}


/*
 * This function removes leading and trailing spaces in the string.
 */
function trim(strSource)
{
	var strValue=strSource.replace(/^(\s*)/, "");
	strValue=strValue.replace(/(\s*)$/, "");
	return  strValue;

}


/*
 * Verifies whether the string is blank.(i.e. null/String of length '0')
 */
function isBlank(strSource)
{
	var strValue=strSource.replace(/^(\s*)/, "");
	strValue=strValue.replace(/(\s*)$/, "");
	if (strValue.length == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}


/*
 * Checks the string for digits.
 */
function isDigit(intSource)
{
	intSource=trim(intSource);
	var reg = /\D/;
	if (reg.test(intSource))
	{
		return false;
	}
	else
	{
		return true;
	}

}

/*
 * Checks the string for alphabets and digits.
 */
function isAplhanumeric(strSource)
{
	strSource=trim(strSource);
	var reg = /[^a-zA-Z0-9\s_]/
	if (reg.test(strSource))
	{
		return false;
	}
	else
	{
		return true;
	}

}

/*
 * Checks the string for alphabets.
 */
function isAlpha(strSource)
{
	strSource=trim(strSource);
	var reg = /[^a-zA-Z\s_]/
	if (reg.test(strSource))
	{
		return false;
	}
	else
	{
		return true;
	}

}

/*
 * This function verifies the string for a valid email address (i.e. the one containing '@/.' character).
 */
function isEmail(strSource)
{
	strSource=trim(strSource);
	var reg =/^(\w|-|.|_)*@(\w|-|.|_)*\.(\w*)$/;
	return reg.test(strSource)
}


/*
 * This function searches the string for special characters.
 */
function isContainsSpecialChar(strSource)
{
	strSource=trim(strSource);
	var reg =/!|@|#|\$|\%|\^|&|\*|\(|\)|-/
	return reg.test(strSource)

}


/*
 * This function searches the string for special characters.
 */
function isContainsSpecialChar(strSource)
{
	strSource=trim(strSource);
	var reg =/!|@|#|\$|\%|\^|&|\*|\(|\)|-/
	return reg.test(strSource)

}

/*
 * This function searches the string for special characters.
 */
function isContainsSpecialCharNum(strSource)
{
	strSource=trim(strSource);
	var reg =/!|@|#|\$|\%|\^|&|\*|\(|\)|0|1|2|3|4|5|6|7|8|9|-/
	return reg.test(strSource)

}

/*
 * This function validates a phone number (Blank and '-' is allowed)
 */
function validatePhoneNo(strSource)
{
	if (isBlank(trim(strSource)))
		return true;
	var reg =/!|@|#|\$|\%|\^|&|\*|\(|\)|[a-z]|[A-Z]/
	return reg.test(strSource)
}

/*
 * This function validates a US style zip code
 */
function validateUsZip(strSource)
{
	if (isBlank(trim(strSource)))
		return false;

	var reg =/^\d{5}$|^\d{5}-\d{4}$/

	return reg.test(strSource)
}

/*
 * This function validates a non-US style zip code
 * Don't validate a non-US zip code
 */
function validateNonUsZip(strSource)
{
	return true
}

