/******************************************************************************
Function name:	fnIsNumericWithoutSign(strInteger)
Description  :  This  function is used to check whether input parameter is a valid numeric 
				value or not?
				function used : 1) fnTrim(strValue) 
								
Assumption	 :  1)There should be no space between sign and digit
				2)2. is not a valid number
				3 .2 is a valid number
				
Input		 :	1) Pass any real number as a parameter

Output       :	If Valid Number 
					Return True
				Else
					Return False
*******************************************************************************/
function fnIsNumericWithoutSign(strInteger)
{
	/*Generate Regular expression which will check 
	1) If (+,-) sign exist then  it must be the first character.
	2) Input value is a valid real number
	*/
	
	//var regExp = /^[\-\+]{0,1}\d{0,100}\.{0,1}\d{1,100}$/
	var regExp = /\D/
	strInteger = fnTrim(strInteger); //Remove leading and trailing spaces
	if (regExp.test(strInteger)) //Validate Integer
	{
		return false;
	}
	return true; //Not a valid integer
}


/******************************************************************************
Function name:	fnIsNumeric(strInteger)
Description  :  This  function is used to check whether input parameter is a valid numeric 
				value or not?
				function used : 1) fnTrim(strValue) 
								
Assumption	 :  1)There should be no space between sign and digit
				2)2. is not a valid number
				3 .2 is a valid number
				
Input		 :	1) Pass any real number as a parameter

Output       :	If Valid Number 
					Return True
				Else
					Return False
*******************************************************************************/
function fnIsNumeric(strInteger)
{
	/*Generate Regular expression which will check 
	1) If (+,-) sign exist then  it must be the first character.
	2) Input value is a valid real number
	*/
	var regExp = /^[\-\+]{0,1}\d{0,100}\.{0,1}\d{1,100}$/
	strInteger = fnTrim(strInteger); //Remove leading and trailing spaces
	if (regExp.test(strInteger)) //Validate Integer
	{
		return true;
	}
	return false; //Not a valid integer
}



/******************************************************************************
Function name:	fnIsInteger(strInteger,intRange)
Description  :  This  function is used for validating integer under given parameters.
				Maximum digit in the integer must be less than max length passed as 
				parameter and integer must lie between the range specified in Third parameter.
				function used : 1) fnTrim(strValue) 
								
Assumption	 :  1)There should be no space between sign and digit
				2)intRange should contain permissible value given below
				3)4.0 is not treated as interger with value 4

Input		 :	1) Pass value to be validated
				2) Pass valid range
					Valid Range are :
						1)	0  -> Any Input
						2)	2  -> only +ve ( *zero not included)
						3)	8  -> only  -ve ( * zero not included)
						4)	16 -> >= 0
						5)  32 -> <= 0
						6)  64 -> only 0 

Output       :	If Valid Integer (Check Against each parameter)
					Return True
				Else
					Return False
*******************************************************************************/
function fnIsInteger(strInteger,intRange)
{
	
	if (strInteger=="")
	return true;
	/*Generate Regular expression which will check 
	1) First character must be (+,- or any valid digit)
	2) Input value is a valid interger
	*/
	var regExp = new RegExp("\^\[\+\-\]\\d{1,999}\$\|\^\\d{1,999}\$");
	strInteger = fnTrim(strInteger); //Remove leading and trailing spaces
	if (regExp.test(strInteger)) //Validate Integer
	{
		strInteger = strInteger.valueOf(Number)//Convert to numeric value
		switch (parseInt(intRange,10)) //Match Range passed as Third parameter
		{
			case 0:
				return true;
			case 2:
				if (strInteger > 0)
				{
					return true;
				}
				return false;
			case 8:
				if (strInteger < 0)
				{
					return true;
				}
				return false;
			case 16:
				if (strInteger >= 0)
				{
					return true;
				}
				return false;
			case 32:
				if (strInteger <= 0)
				{
					return true;
				}
				return false;
			case 64:
				if (strInteger == 0)
				{
					return true;
				}
				return false;
			default:
				return false;	// Not a Valid Range
		}
	}
	return false; //Not a valid integer
}




/******************************************************************************
Function name:	function fnIsReal(strInteger,intScale,intPrecision,intRange)
Description  :  This  function is used for validating integer under given parameters.
				Maximum digit in the integer must be less than max length passed as 
				parameter and integer must lie between the range specified in Third parameter.
				function used : 1) fnTrim(strValue) 
								
Assumption	 :  1)There should be no space between sign and digit
				2)intRange should contain permissible value given below
				3)4.0 is not treated as interger with value 4

Input		 :	1) Pass value to be validated
				2) Pass integer value.
				3) Pass valid range
					Valid Range are :
						1)	0  -> Any Input
						2)	2  -> only +ve ( *zero not included)
						3)	8  -> only  -ve ( * zero not included)
						4)	16 -> >= 0
						5)  32 -> <= 0
						6)  64 -> only 0 

Output       :	If Valid Integer (Check Against each parameter)
					Return True
				Else
					Return False

*******************************************************************************/

function fnIsReal(strInteger,intScale,intPrecision,intRange)
{
	
	//Mandatory check for parameters
	if ((!fnMandatory(strInteger))||(!fnMandatory(intScale))||(!fnMandatory(intPrecision))) 
	{
		return false;
	}
	if (intPrecision == 0)
	{
		intPrecision = 999; //Assume that max. length of any number befor decimal is less than 999 digit
	}
	if (intScale == 0)
	{
		intScale = 999; //Assume that max. length of any number after decimal is less than 999 digit
	}
	/*Generate Regular expression which will check 
	1) First character must be (+,- or any valid digit)
	2) Input value is a valid interger
	3) Reg. Exp checks No. of digit before decimal in first parameter must be less than equal 
	to Scale
	4) Reg. Exp also checks No. of digit after decimal in first parameter must be less than equal 
	to the precision.
	*/
	var regExp = new RegExp("\^\[\\-\\+\]{0,1}\\d{0," + intScale+ "}$\|\^\[\\-\\+\]{0,1}\\d{0," + intScale+ "}\\.{1,1}\\d{1," + intPrecision+ "}$");
	strInteger = fnTrim(strInteger); //Remove leading and trailing spaces
	if (regExp.test(strInteger)) //Validate Integer
	{
		strInteger = strInteger.valueOf(Number)//Convert to numeric value
		switch (parseInt(intRange,10)) //Match Range 
		{
			case 0:
				return true;
			case 2:
				if (strInteger > 0)
				{
					return true;
				}
				return false;
			case 8:
				if (strInteger < 0)
				{
					return true;
				}
				return false;
			case 16:
				if (strInteger >= 0)
				{
					return true;
				}
				return false;
			case 32:
				if (strInteger <= 0)
				{
					return true;
				}
				return false;
			case 64:
				if (strInteger == 0)
				{
					return true;
				}
				return false;
			default:
				return false;	// Not a Valid Range
		}
	}
	return false; //Not a valid integer
}




/******************************************************************************
Function name:	function fnRound(intNumber)
Description  :  This  function is used for truncate real number upto 2 place
				of decimal.
								
Assumption	 :  1)Number should be valid real number

Input		 :	1) Pass Number

Output       :	Number rounded upto 2 place of decimal

*******************************************************************************/

function fnRound(intNumber)
{
	var arrSplitByDec;
	var intUptoTwoDec
	var intFinalNumber
	intFinalNumber = intNumber.toString();
	arrSplitByDec = intFinalNumber.split(".")
	if (arrSplitByDec.length == 2)
	{
		
		if (arrSplitByDec[1].length > 2) 
		{
			
			if (parseInt(arrSplitByDec[1].charAt(2)) >= 5)
			{
				intUptoTwoDec = eval(arrSplitByDec[1].substr(0,2)) + 1;
				intFinalNumber = arrSplitByDec[0] + "." + intUptoTwoDec;
			}
			else
			{
				intUptoTwoDec = arrSplitByDec[1].substr(0,2);
				intFinalNumber = arrSplitByDec[0] + "." + intUptoTwoDec;
			}
		}
	}
	return intFinalNumber;
}

/******************************************************************************
Function name:	function fnRound(intNumber)
Description  :  This  function is used for truncate real number upto 2 place
				of decimal.
								
Assumption	 :  1)Number should be valid real number

Input		 :	1) Pass Number

Output       :	Number rounded upto 2 place of decimal

*******************************************************************************/

function fnDecimalPointCheck(intNumber,intDecPoints)
{
	var arrSplitByDec;
	var intUptoTwoDec;
	var intFinalNumber;
	
	intFinalNumber = intNumber.toString();
	arrSplitByDec = intFinalNumber.split(".")
	if (arrSplitByDec.length == 2)
	{
		
		if (arrSplitByDec[1].length > intDecPoints) 
			{
				
				return false;
			}	
		else
			{
				return true;
			}
	}
	else
	{
		if(intFinalNumber.length > 4)
		{
			return false;
		}
	}
	
	return true;
}

