//FUNCTION:	to trim spaces from right side of the string if any
//	 INPUT: 
//			strVal		-	parameter containing the string to be trimed
//	OUTPUT: 
//			1			-	if	parameter is not supplied 
//							else
//			substring	-	string	without spaces on right side			   
//

function rTrim(strVal)
{	
	nNoOfArguments = rTrim.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return 1;
	}
	
	strVal = new String(strVal);	//convert the string to string object
	
	var nLen = strVal.length;
	var nIndex = 0;
	for (nIndex = nLen-1; nIndex >=0; nIndex--)
	{
		if (strVal.charAt(nIndex) ==  " ")
		{
			nLen--;
		}
		else
		{
			break;
		}
	}
	//return substring starting between 0 as starting index to nLen as ending index
	return strVal.substring(0,nLen)
}
				
//FUNCTION:	to trim spaces from left side of the string if any
//	 INPUT: 
//			strVal		-	parameter containing the string to be trimed
//	OUTPUT: 
//			1			-	if	parameter is not supplied 
//							else
//			substring	-	string without spaces on left side

function lTrim(strVal)
{
	nNoOfArguments = lTrim.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return 1;
	}
	
	strVal = new String(strVal);	//convert the value to a string object

	var nLen = strVal.length // get the length of string
	var nIndex = 0;
	for (nIndex = 0; nIndex < nLen-1; nIndex++)
	{
		if (strVal.charAt(nIndex) !=  " ")
		{
			break;
		}
	}
	//return substring starting between nIndex as starting index to nLen as ending index
	return strVal.substring(nIndex,nLen) 
}

//FUNCTION:		to check whether the string contains any value
//	 INPUT: 
//			strVal	-	parameter to be checked
//	OUTPUT: 
//			true	-	if the string contains characters
//			false	-	if the string contains no characters or no parameter is supplied

function IsValueExist(strVal)
{
	nNoOfArguments = IsValueExist.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return false;
	}
	
	
	
	strVal = new String(strVal);	//convert the value to a string object
	
	// if string contains no character
	if(strVal.length == 0) 
	{
		return false;
	}
	return true;
}

//FUNCTION:	to check whether the first character of the string is space or not
//			this function is for internal use only. Call- checkFirstCharBlank(strVal)
//			to use it externally.
//	 INPUT: 
//			strVal	-	parameter to be checked
//	OUTPUT: 
//			true	-	if the first character is blank or no parameter is supplied
//			false	-	if the first character is not blank  

function IsFirstCharBlank(strVal)
{
	nNoOfArguments = IsFirstCharBlank.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return true;
	}
		
	strVal = new String(strVal);	//convert the value to a string object
	
	// if first character is blank
	if (strVal.charAt(0) == " ") 
	{
		return true;
	}
	return false;
}

//FUNCTION:	to check whether the string supplied is without spaces
//			this function is for internal use only. Call- checkStringForSpaces(strVal)
//			to use it externally.
//	 INPUT:  
//			strVal	-	parameter to be checked
//	OUTPUT: 
//			true	-	if the string contains spaces
//			false	-	if the string is without spaces

function IsStringWithSpaces(strVal)
{
	nNoOfArguments = IsStringWithSpaces.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return false;
	}	
	
	var strInValidChars = ' '; //invalid charaters i.e. space in this case
	
	bReturn = strVal.indexOf(strInValidChars);	//check for invalid characters in string
	
	if(bReturn != -1)//if any invalid character found
	{
		return true;
	}
	return false;
}

//FUNCTION:	to check whether the two string supplied are identical
//	 INPUT:   
//			strVal1	-	 1st string
//			strVal2	-	 2nd string	
//	OUTPUT: 
//			true	-	if the both string are identical
//			false	-	if both string are not identical or any of the string is not supplied

function IsIdentical(strVal1, strVal2)
{	
	nNoOfArguments = IsIdentical.arguments.length;
	
	//if any of the parameter is not supplied
	if(nNoOfArguments < 2)
	{
		return false;
	}	

	if(strVal1 == strVal2) //if both string are equal
	{
		return true;
	}	
	return false;	
} 

//FUNCTION:	to check whether the string supplied is a valid alpha-numeric value
//	 INPUT:  
//			strVal	-	parameter to be checked
//	OUTPUT: 
//			true	-	if the parameter contain valid alphanumeric value
//			false	-	if the parameter is a invalid field or string value is not supplied

function IsValidAlphaNumValue(strVal)
{
	nNoOfArguments = IsValidAlphaNumValue.arguments.length;

	//if parameter is not supplied
	if(nNoOfArguments < 1)
	{
		return false;
	}
		
	//valid characters a supplied string value can have
	var sValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	strVal = new String(strVal);	//convert the value to a string object
	
	var bReturn = true	
	var i = new Number(0);
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn)	
}

//FUNCTION:	to check whether the string supplied is a valid alphabet value
//	 INPUT:  
//			strVal	-	parameter to be checked
//	OUTPUT: 
//			true	-	if the parameter contain valid alphabet value
//			false	-	if the parameter is a invalid field or no parameter is supplied

function IsValidAlphabetValue(strVal)
{
	nNoOfArguments = IsValidAlphabetValue.arguments.length;

	//if no parameter is supplied
	if(nNoOfArguments < 1)
	{
		return false;
	}	

	//valid characters a supplied string can have
	var sValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	strVal = new String(strVal);	//convert the value to a string object
	
	var bReturn = true
	var i = new Number(0);
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn)
}

//FUNCTION:	to check whether the string supplied is a valid numeric value
//	 INPUT:  
//			strVal	-	parameter to be checked
//	OUTPUT: 
//			true	-	if the parameter contain valid numeric value
//			false	-	if the parameter is a invalid field or no parameter is supplied

function IsValidNumericValue(strVal)
{
	nNoOfArguments = IsValidNumericValue.arguments.length;
	
	//if any of the three parameter is not supplied
	if(nNoOfArguments < 1)
	{
		return false;
	}	
	
	//valid characters a supplied string can have
	var sValidChars = "0123456789";
	
	strVal = new String(strVal);	//convert the value to a string object
	
	var bReturn = true
	var i = new Number(0);
	
	//if number is 0
	if(0 == parseInt(strVal,10))
	return true;
	
	//if first character is 0
	if(0 == strVal.charAt(0))
	return false;
	
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn)
}

//FUNCTION: to check whether the string supplied is a valid Float value
//	 INPUT:  
//			strVal	-	parameter to be checked
//	OUTPUT: 
//			true	-	if the parameter contain valid float value
//			false	-	if the parameter is a invalid float value or no parameter is supplied

function IsValidFloatValue(strVal)
{
	nNoOfArguments = IsValidFloatValue.arguments.length;
	
	//if no parameter is supplied
	if(nNoOfArguments < 1)
	{
		return false;
	}
		
	//valid characters a supplied string can have
	var sValidChars = "0123456789.";
	
	strVal = new String(strVal);	//convert the value to a string object
	
	var bReturn = true;	
	var i = new Number(0);
	
	//if more than one decimal exist in value
	if(strVal.indexOf(".") != strVal.lastIndexOf("."))
	return false;
	
	
	//if first character is 0 
	if(('0' == strVal.charAt(0)))
	{
		//if next is not decimal
		if (!('.' == strVal.charAt(1)))
		{
			return false;
		}
	}	
	
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++;
    }
	return (bReturn)
}

//FUNCTION: to check whether the string supplied is a valid Float value greater then equal to 0
//	 INPUT:  
//			strVal	-	parameter to be checked
//	OUTPUT: 
//			true	-	if the parameter contain valid float value
//			false	-	if the parameter is a invalid float value or no parameter is supplied

function IsValidFloatValueWithZero(strVal)
{
	nNoOfArguments = IsValidFloatValueWithZero.arguments.length;
	
	//if no parameter is supplied
	if(nNoOfArguments < 1)
	{
		return false;
	}
		
	//valid characters a supplied string can have
	var sValidChars = "0123456789.";
	
	strVal = new String(strVal);	//convert the value to a string object
	
	var bReturn = true;	
	var i = new Number(0);
	
	//if more than one decimal exist in value
	if(strVal.indexOf(".") != strVal.lastIndexOf("."))
	return false;
	
	
	if(strVal.length == 0)
	return false;	
	
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++;
    }
	return (bReturn)
}

//FUNCTION: to check whether the string supplied is a valid Phone or Fax value
//			Second parameter(IsSpecialChar) to this function is by default 'true' 
//			i.e. a phone or fax number can have SpecialChar - '+' and '-'.
//			if you don't want to have special characters in number and want it 
//			to be pure numeric supply 'false' as second parameter
//			if you have three seperate fields for phone or fax number call this function
//			seperatly for each field value 	
//	 INPUT:  
//			strVal			-	parameter to be checked
//			IsSpecialChar	-	this parameter can have either of two values, 
//								't'	- this is default parameter it will check for 
//									  special characters i.e. '+' and '-' only
//								'f'	- if this value is passed then phone or fax 
//									  number will be checked for only numbers  	
//	OUTPUT: 
//			true			-	if the parameter contains valid phone or fax number
//			false			-	if the parameter contains invalid phone or fax number

function IsValidPhoneFaxNumber(strVal,IsSpecialChar)
{
	nNoOfArguments = IsValidPhoneFaxNumber.arguments.length;
	//if no parameter is supplied
	if(nNoOfArguments < 1)
	{
		return false;
	}		
	
	//if no IsSpecialChar value is supplied then set it to 't'
	if((nNoOfArguments == 1) && (nNoOfArguments < 2))
	{
		IsSpecialChar = 't';
	}
	
	if('f' == IsSpecialChar)
	{
		//valid characters if IsSpecialChar is false
		var sValidChars = "0123456789";
	}
	
	if('t' == IsSpecialChar)
	{
		//valid characters if IsSpecialChar is true
		var sValidChars = "0123456789+-";
	}	
	
	
	var bReturn = true;	
	var i = new Number(0);
	
	strVal = new String(strVal);
	
	if(strVal.indexOf("+") != strVal.lastIndexOf("+"))//if more than one + exist in value
	return false;
	
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn)
}


//FUNCTION:	to check whether the string supplied is a valid name value
//	 INPUT:  
//			strVal	-	parameter to be checked
//	OUTPUT: 
//			true	-	if the parameter is a valid name value
//			false	-	if the parameter is a invalid name value or parameter is not supplied

function IsValidNameValue(strVal)
{
	nNoOfArguments = IsValidNameValue.arguments.length;
	//if no parameter is supplied
	if(nNoOfArguments < 1)
	{
		return false;
	}
		
	//valid character a supplied string can have
	var sValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. ";
	
	var strVal = new String(strVal);
	var bReturn = true
	var i = new Number(0);
	while ((bReturn) && (i < strVal.length))
    {
		bReturn = (sValidChars.indexOf(strVal.charAt(i)) >= 0)
		i++
    }
	return (bReturn)
}


//FUNCTION: to check whether the string supplied is a valid Email value
//	 INPUT:  
//			strVal	-	parameter to be checked for validity
//	OUTPUT: 
//			true	-	if the email is valid
//			false	-	if the email is invalid or no parameter is supplied

function IsValidEMail(strValue)
{
	nNoOfArguments = IsValidEMail.arguments.length;
	//if no parameter is supplied
	if(nNoOfArguments < 1)
	{
		return false;
	}	
	
	var strVal	= new String(strVal);
	var bReturn1 = false;
	var bReturn2 = false;
	var bReturn3 = false;
	var bReturn4 = false;
	var bReturn5 = false;
	var bReturn6 = false;
	var bReturn7 = true;
	
	//if '@' comes after first character then true
	bReturn1	=	(strValue.indexOf("@") > 0);							
	
	//if '.' comes after first character then true
	bReturn2	=	(strValue.indexOf(".") > 0);							
	
	//if single '@' exist in string then true
	bReturn3	=	(strValue.indexOf("@") == strValue.lastIndexOf("@"));	
	
	//if '.' exist after @ in string then true
	bReturn4	=	(strValue.indexOf(".",strValue.indexOf("@")) > (strValue.indexOf("@")));		
	
	//if '.' does not comes immediatly after @ then true
	bReturn5	=	(strValue.indexOf(".",strValue.indexOf("@")) != (strValue.indexOf("@")+1));		
	
	//if '.' does not comes immediatly before @ then true
	bReturn6	=	(strValue.lastIndexOf(".",strValue.indexOf("@")) != (strValue.indexOf("@")-1)); 
	
	//if two '.' occurs simultaneously then false
	bReturn7	=	!((strValue.indexOf(".",strValue)+1) == (strValue.lastIndexOf(".")));
	
	//if all values are true return true else false.
	return(bReturn1 && bReturn2 && bReturn3 && bReturn4 && bReturn5 && bReturn6)	
}


//FUNCTION: to check whether the string supplied is a valid Date value 
//			this function is for internal use only. Call- checkDate(strVal)
//			checkDate(strVal1,strVal2,strVal3) to use it externally.
//	 INPUT:  
//			nMonth	-	parameter contain month value to be checked
//			nDay	-	parameter contain day value to be checked
//			nYear	-	parameter contain year value to be checked
//	OUTPUT 
//			true	-	if the date is valid
//			false	-	if the date is invalid

function IsDateValid(nMonth, nDay, nYear)
{
	nNoOfArguments = IsDateValid.arguments.length;
	
	//if any of the three parameter is not supplied
	if(nNoOfArguments < 3)
	{
		return false;
	}	

	//if month value is not correct i.e. not between 0-11
	if ((nMonth > 11) || (nMonth < 0))
	{
		return false;
	}
	
	//if day value is not correct i.e. not between 1-31
	if ((nDay > 31) || (nDay < 1))
	{
		return false;
	}
	
	//if month value is 0,2,4,6,7,9,11 i.e. January,March,May,July,August,October,December
	//and days are 31 return true.
	//if month value is 3,5,8,10 i.e. April,June,September,November
	// and days are greater then 30 return false.
	//if month value is 1 i.e. February and days are 29 check for leap year,
	//if not a leap year return false. else if days are greater then 28 return false. 	
	
	switch (nMonth)
	{				
		case 0:
		case 2:
		case 4:
		
		case 6:
		case 7:
		case 9:
		case 11:			
			return (true);
			break;
						
		case 3:
		case 5:
		case 8:
		case 10:
			if (nDay > 30)
			{
				return (false);
			}
			return (true);
			break;
						
		case 1 :
			if (nDay <= 28)
			{
				return true;
			}
			if (nDay > 29)
			{
				return false;
			}
			if (nYear % 4 != 0)
			{
				return false;
			}
			else
			{
				if (nYear%100 == 0)
				{
					if (nYear % 400 == 0)
					{
						return true;
					}
					else
					{
						return false;
					}
				}
				else
				{
					return true;
				}
			}
			break;
	}
}

//FUNCTION:	to check whether the string supplied is a within Date from today and supplied dtWithin value
//			this is internal function to use this function you can refer to 
//			function checkWithinDate(dtWithin,strVall1,strVal2,strVal3); 
//	 INPUT:  
//			nDayWithin		-	parameter contain number of days which will be added to todays' day value
//			nMonth			-	parameter contain month value to be checked
//			nDay			-	parameter contain day value to be checked
//			nYear			-	parameter contain year value to be checked
//			nHr (optional)	-	parameter contain hours value
//			nMin(optional)	-	parameter contain minutes value
//			nSec(optional)	-	parameter contain seconds value
//	OUTPUT 
//			true			-	if the date is valid i.e. within supplied date range from today
//			false			-	if the date is invalid

function IsWithinDateValid(nDayWithin, nMonth, nDay, nYear, nHr, nMin, nSec)
{
	nNoOfArguments = IsWithinDateValid.arguments.length;
	
	//if compulsory parameters are not supplied
	if(nNoOfArguments < 4)
	{
		return false;
	}
	
	//if any of optional parameter is supplied
	if(nHr || nMin || nSec)
	{
		//if not all the optional parameters are not supplied
		if(nNoOfArguments < 7)
		{
			return false;
		}
	}	
		
	//create Date objects which contain todays date by default
	dtToday		= new Date();	
	dtValid		= new Date();	
	dtSupplied	= new Date();
	
	nDayCurr	= dtToday.getDate();
	nMonthCurr	= dtToday.getMonth();
	nYearCurr	= dtToday.getFullYear();
	
	//add nDayWithin value to todays' day value
	nValidDay	= nDayCurr + (nDayWithin); 
	nValidMonth	= nMonthCurr;
	nValidYear	= nYearCurr;
	
	//date till which supplied date can be valid
	dtValid.setFullYear(nValidYear,nValidMonth,nValidDay)
	
	nDayWithin	= new Number(nDayWithin);
	nMonth		= new Number(nMonth);
	nDay		= new Number(nDay);
	nYear		= new Number(nYear);
	
	
	//if all sub fields of time i.e. nHr, nMin, nSec are supplied
	if(nNoOfArguments == 7)
	{
		nHr			= new Number(nHr);
		nMin		= new Number(nMin);
		nSec		= new Number(nSec);

		//date supplied to function is
		dtSupplied = new Date(nYear,nMonth,nDay,nHr,nMin,nSec)		
	}	
	else
	{
		//date supplied to function is
		dtSupplied.setFullYear(nYear,nMonth,nDay)
	}
	
	//if nDayWithin is less then 0 i.e. valid date is past date
	if(nDayWithin < 0)
	{
		dtDiff	= dtSupplied - dtValid;
		
		//if supplied date is greater then or equal to valid date and less then or equal to todays date 
		if((dtDiff >= 0) && (dtSupplied <= dtToday))
		{
			return true;
		}
		return false;
	}
	
	//if nDayWithin is equal to 0 i.e. valid date is todays date only
	if(nDayWithin == 0)
	{
		if((nDayCurr == nDay) && (nMonthCurr == nMonth) && (nYearCurr == dtSupplied.getFullYear()))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	//if nDayWithin is greater than 0 i.e. valid date is future date
	if(nDayWithin > 0)
	{
		dtDiff = dtSupplied - dtValid;
		
		//if supplied date is less then or equal to valid date and greater then equal to todays' date
		if((dtDiff <= 0) && (dtSupplied >= dtToday))
		{
			return true;
		}
		return false;
		
	}	
	return false;
}

//FUNCTION:	to check whether the string supplied is a valid future Date greater then or equal today
//			this is internal function to use this funciton call funciton: 
//			checkFuturePastDate(strVal1,strVal2,strVal3)
//	 INPUT:  
//			nMonth			-	parameter contain month value to be checked
//			nDay			-	parameter contain day value to be checked
//			nYear			-	parameter contain year value to be checked
//			nHr (optional)	-	parameter contain hours value
//			nMin(optional)	-	parameter contain minutes value
//			nSec(optional)	-	parameter contain seconds value
//	OUTPUT 
//			true			-	if the date is valid i.e. date is greater then or equal to todays date
//			false			-	if the date is invalid

function IsFutureDateValid(nMonth, nDay, nYear, nHr, nMin, nSec)
{
	nNoOfArguments = IsFutureDateValid.arguments.length;
	
	
	//if any of the three parameter is not supplied
	if(nNoOfArguments < 3)
	{
		return false;
	}	
	

	
	//if any of optional parameter is supplied
	if(nHr || nMin || nSec)
	{
		//if not all the optional parameters are not supplied
		if(nNoOfArguments < 6)
		{
			return false;
		}
	}
	
	//create Date objects which contain todays date by default
	dtToday		= new Date();	
	dtSupplied	= new Date();
		
	nMonth		= new Number(nMonth);
	nDay		= new Number(nDay);
	nYear		= new Number(nYear);
	
	//if all sub fields of time i.e. nHr, nMin, nSec are supplied
	if( nNoOfArguments == 6)
	{
		nHr			= new Number(nHr);
		nMin		= new Number(nMin);
		nSec		= new Number(nSec);
		
		//date supplied to function is
		dtSupplied = new Date(nYear,nMonth,nDay,nHr,nMin,nSec)		
	}	
	else
	{
		//date supplied to function is
		dtSupplied.setFullYear(nYear,nMonth,nDay)
		
	}
	
	
	//if supplied date is greater then or equal to todays' date
	if(dtSupplied >= dtToday)
	{
		
		return true;
	}

	return false;
}


//FUNCTION:	to check whether the string supplied is a valid past Date less then or equal today
//			this is internal function to use this funciton call funciton: 
//			checkFuturePastDate(strVal1,strVal2,strVal3)
//	 INPUT:  
//			nMonth			-	parameter contain month value to be checked
//			nDay			-	parameter contain day value to be checked
//			nYear			-	parameter contain year value to be checked
//			nHr (optional)	-	parameter contain hours value
//			nMin(optional)	-	parameter contain minutes value
//			nSec(optional)	-	parameter contain seconds value
//	OUTPUT 
//			true			-	if the date is valid i.e. date is less then or equal to todays date
//			false			-	if the date is invalid

function IsPastDateValid(nMonth, nDay, nYear, nHr, nMin, nSec)
{
	nNoOfArguments = IsPastDateValid.arguments.length;
	
	
	//if any of the three parameter is not supplied
	if(nNoOfArguments < 3)
	{
		return false;
	}	
	

	
	//if any of optional parameter is supplied
	if(nHr || nMin || nSec)
	{
		//if not all the optional parameters are not supplied
		if(nNoOfArguments < 6)
		{
			return false;
		}
	}	
	
	//create Date objects which contain todays date by default
	dtToday		= new Date();	
	dtSupplied	= new Date();
		
	nMonth		= new Number(nMonth);
	nDay		= new Number(nDay);
	nYear		= new Number(nYear);
	//if all sub fields of time i.e. nHr, nMin, nSec are supplied
	if( nNoOfArguments == 6)
	{
		nHr			= new Number(nHr);
		nMin		= new Number(nMin);
		nSec		= new Number(nSec);
		
		//date supplied to function is
		dtSupplied = new Date(nYear,nMonth,nDay,nHr,nMin,nSec)		
	}	
	else
	{
		//date supplied to function is
		dtSupplied.setFullYear(nYear,nMonth,nDay)
	}
		
	//if supplied date is less then or equal to todays' date
	if(dtSupplied <= dtToday)
	{
		return true;
	}
	return false;
}

//FUNCTION:	to seperate day,month and year from string and return day or month or year value
//			date format can be:
//			i.		m/d/yy or m:d:yy or m-d-yy				e.g. 2/4/99
//			ii.		mm/dd/yy or mm:dd:yy or mm-dd-yy		e.g. 11/08/99 
//			iii.	mm/dd/yyyy or mm:dd:yyyy or mm-dd-yyyy	e.g. 11/23/2002
//			Note:	You can supply year as two character value it will be a valid year but
//					two character year value will be considered as it is. 
//					i.e. 99 will be treated  as 99 not 1999
//
//			Third parameter will be suppllied as integer to this function indicating date format 
//			if no parameter is supplied default value will be supplied to parameter internally 
//			whereas
//			1	-	stands for default format i.e. mm/dd/yy or mm/dd/yyyy 
//			2	-	stands for format	dd/mm/yy or dd/mm/yyyy
//			3	-	stands for format	yy/dd/mm or yyyy/dd/mm
//			4	-	stands for format	yy/mm/dd or yyyy/mm/dd
//	
//	 INPUT:  
//			strVal				-	parameter contain date value as string 
//			chParam				-   this is character parameter specifying the portion 
//									of date to be returned valid chParam values are as under
//						'd'		-	stands for day
//						'm'		-	stands for month
//						'y'		-	stands for year
//			nFormat(optional)	-	this is integer value specifying format of date. specified above.
//			
//			Valid Date seperators are :
//									'/'		e.g. 1/3/2003
//									':'		e.g. 2:12:2003
//									'-'		e.g. 3-5-2004									
//	OUTPUT: 
//			day	from Date value		-	if chParam == 'd'	
//			month from Date value	-	if chParam == 'm'
//			year from Date value	-	if chParam == 'y'
//			-1						-	if chParam and strVal is not supplied or any invalid 
//										value is supplied as parameter
 
function seprateDateString(strVal,chParam,nFormat)
{
	nNoOfArguments = seprateDateString.arguments.length;
	
	if(nNoOfArguments < 2)
	{
		return false;
	}	
	
	//if no format is supplied initialized it with default value 
	if(!nFormat)
	{
		nFormat = 1;
	}	
	
	//if not a valid character supplied to chParam return error
	if(!((chParam == 'd') || (chParam == 'm') || (chParam == 'y')))
	{
		return (1);
	} 
	
	subStr	= null;	
	strDt	= new String(strVal);
	nFormat	= new Number(nFormat);
	
	//if invalid format is supplied return false
	if((nFormat <= 0) || (nFormat > 4))
	{
		return (-1); 
	}
	//check which seperator is used in the date string
	if(strDt.indexOf("/",0) > -1)
	{
		subStr = '/';
	}
	else 
	if(strDt.indexOf(":",0) > -1)
	{
		subStr = ':';
	}
	else 
	if(strDt.indexOf("-",0) > -1)
	{
		subStr = '-';
	}
	
	if(subStr != null)
	{
		if(1 == nFormat)	//if default format i.e. mm/dd/yyyy
		{
			//if chParam is 'm' return month portion from date string
			if(chParam == 'm')
			{
				
				return(strDt.slice(0,strDt.indexOf(subStr)));
			}
		
			//if chParam is 'd' return day portion from date string
			if(chParam == 'd')
			{
				return(strDt.slice(strDt.indexOf(subStr)+1,strDt.lastIndexOf(subStr)));
			}
		
			//if chParam is 'y' return year portion from date string
			if(chParam == 'y')
			{
				return(strDt.slice(strDt.lastIndexOf(subStr)+1,strDt.length));
			}	
		}
		if(2 == nFormat)	//if nFormat is 2 i.e. dd/mm/yyyy
		{
			//if chParam is 'd return date portion from date string
			if(chParam == 'd')
			{
				return(strDt.slice(0,strDt.indexOf(subStr)));
			}
		
			//if chParam is 'm' return month portion from date string
			if(chParam == 'm')
			{
				return(strDt.slice(strDt.indexOf(subStr)+1,strDt.lastIndexOf(subStr)));
			}
		
			//if chParam is 'y' return year portion from date string
			if(chParam == 'y')
			{
				return(strDt.slice(strDt.lastIndexOf(subStr)+1,strDt.length));
			}
		}	
		if(3 == nFormat)	//if nFormat is 3 i.e. yyyy/dd/mm
		{
			//if chParam is 'y' return year portion from date string
			if(chParam == 'y')
			{
				return(strDt.slice(0,strDt.indexOf(subStr)));
			}
		
			//if chParam is 'd' return day portion from date string
			if(chParam == 'd')
			{
				return(strDt.slice(strDt.indexOf(subStr)+1,strDt.lastIndexOf(subStr)));
			}
		
			//if chParam is 'm' return mont portion from date string
			if(chParam == 'm')
			{
				return(strDt.slice(strDt.lastIndexOf(subStr)+1,strDt.length));
			}	
		}
		if(4 == nFormat)	//if nFormat is 4 i.e. yyyy/mm/dd
		{
			//if chParam is 'y' return year portion from date string
			if(chParam == 'y')
			{
				return(strDt.slice(0,strDt.indexOf(subStr)));
			}
		
			//if chParam is 'm' return month portion from date string
			if(chParam == 'm')
			{
				return(strDt.slice(strDt.indexOf(subStr)+1,strDt.lastIndexOf(subStr)));
			}
		
			//if chParam is 'd' return day portion from date string
			if(chParam == 'd')
			{
				return(strDt.slice(strDt.lastIndexOf(subStr)+1,strDt.length));
			}
		}
		
	}	
	else
	return (-1)		
}

//FUNCTION:	to check whether the string supplied is a valid Time value this is 
//			internal function to use this function call 
//			function checkTime(strVal1,strVal2,strVal3)
//	 INPUT:  
//			nHr		-	parameter contain hour value to be checked
//			nMin	-	parameter contain minute value to be checked
//			nSec	-	parameter contain second value to be checked
//	OUTPUT: 
//			true	-	if the time is valid
//			false	-	if the time is invalid or no parameter is supplied

function IsTimeValid(nHr,nMin,nSec)
{
	nNoOfArguments = IsTimeValid.arguments.length;
	
	//if if any of the parameter is not supplied
	if(nNoOfArguments < 3)
	{
		return false;
	}
	
	nHr		= new Number(nHr);
	nMin	= new Number(nMin);
	nSec	= new Number(nSec);
	
	if(isNaN(nHr))
	{
		return false;
	}
	
	if(isNaN(nMin))
	{
		return false;
	}

	if(isNaN(nSec))
	{
		return false;
	}

	//if hour is invalid i.e. out of 0-23 range
	if ((nHr > 23) || (nHr < 0))
	{
		return false;
	}
	
	//if minute is invalid i.e. out of 0-59 range
	if ((nMin > 59) || (nMin < 0))
	{
		return false;
	}
	
	//if second is invalid i.e. out of 0-59 range
	if ((nSec > 59) || (nSec < 0))
	{
		return false;
	}
	return true;

}

//FUNCTION: to seperate hr,min and sec from string and return hr or min or sec
//	 INPUT:  
//			strVal	-	parameter contain date value as string 
//			chParam	-   this is character parameter specifying the portion of time to be returned
//			valid chParam values are as under
//			'h'		-	stands for hour
//			'm'		-	stands for minute
//			's'		-	stands for second
//			Valid Time seperators are :
//									'/'		e.g. 12/12/03
//									':'		e.g. 2:12:20
//									'-'		e.g. 3-5-24									

//	OUTPUT 
//			hour from Time value	-	if chParam == 'h'	
//			minute from Time value	-	if chParam == 'm'
//			Second from Time value	-	if chParam == 's'
//			-1						-	if chParam and strVal is not supplied or invalid 
//										value is supplied in chParam parameter

function seprateTimeString(strVal,chParam)
{	
	nNoOfArguments = seprateTimeString.arguments.length;
	
	//if if any of the parameter is not supplied
	if(nNoOfArguments < 2)
	{
		return false;
	}	
	
	//if not a valid chParam character is supplied
	if(!((chParam == 'h') || (chParam == 'm') || (chParam == 's')))
	{
		return (-1);
	} 

	subStr = null;	
	strTm = new String(strVal)
	
	//check which seperator is used in time string
	if(strTm.indexOf("/",0) > -1)
	{
		subStr = '/';
	}
	else 
	if(strTm.indexOf(":",0) > -1)
	{
		subStr = ':';
	}
	else 
	if(strTm.indexOf("-",0) > -1)
	{
		subStr = '-';
	}
	
	if(subStr != null)
	{
		//if chParam is 'h' return hour portion from time string
		if(chParam == 'h')
		{
			return(strTm.slice(0,strTm.indexOf(subStr)));
		}
		
		//if chParam is 'm' return minute portion from time string
		if(chParam == 'm')
		{
			return(strTm.slice(strTm.indexOf(subStr)+1,strTm.lastIndexOf(subStr)));
		}
		
		//if chParam is 's' return second portion from time string
		if(chParam == 's')
		{
			return(strTm.slice(strTm.lastIndexOf(subStr)+1,strTm.length));
		}	
	}	
	else
	return (-1)		
}

//FUNCTION: to seperate a single string containing two substring seperated by space 
//			and return one substring depending on chParam value
//	 INPUT:  
//			strVal	-	parameter contain string value contains two substrings seperated by space 
//			chParam	-   this is character parameter specifying the portion of String to be returned
//			valid chParam values are as under
//			'1'		-	stands for first substring
//			'2'		-	stands for second substring
//	OUTPUT: 
//			First substring from String value(strVal)	-	if chParam == '1'	
//			Second substring from String value(strVal)	-	if chParam == '2'
//			-1											-	if chParam and strVal is not supplied 
//															or invalid value is supplied in chParam 
//															parameter

function getSubstring(strVal,chParam)
{	
	nNoOfArguments = getSubstring.arguments.length;
	
	//if if any of the parameter is not supplied
	if(nNoOfArguments < 2)
	{
		return false;
	}		

	subStr = ' ';	
	
	strVal = lTrim(rTrim(strVal)); //trim spaces from left and right of the string
	
	chParam			= new String(chParam);
	strMainString	= new String(strVal);	
	
	//get the position of space in the supplied string as string should be seperated by space
	nPos = strMainString.indexOf(subStr,0) 
		
	//if chParam is '1' return first substring from string
	if(chParam == '1')
	{
		return(strMainString.slice(0,strMainString.indexOf(subStr)));
	}
		
	//if chParam is '2' return second substring from string
	if(chParam == '2')
	{
		return(strMainString.slice(strMainString.lastIndexOf(subStr)+1,strMainString.length));
	}			
	return (-1)
}





/*
FUNCTION checkUsername: checks the username for all possible cases
INPUT 
		strValue			-  is username supplied as string.
		nMaxlen (optional)	-  is the maximum length a username field can have, supplied as integer.
		nMinlen (optional)	-  is the minimum length a username field can have, supplied as integer.

OUTPUT
		0 if "No Error"
		1 if "User name is blank or value is not supplied"
		2 if "User name started with blank space"
		3 if "User name is invalid i.e. it contain spaces"
		4 if "User name characters length is below prescribed length"
		5 if "User name characters length is above prescribed length"
		6 if "nMaxlen or nMinlen are invalid or equal to 0 or less then 0 in function parameters"
		
*/

function checkUsername(strValue,nMaxlen,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//if string value supplied is empty or contains nothing
	if(!IsValueExist(strValue))
	{
		return (1);
	}

	//if the first character of the string value supplied is space
	if(IsFirstCharBlank(strValue))
	{
		return (2);
	}
	
	//if string value supplied contain spaces
	if(IsStringWithSpaces(strValue))
	{
		return (3);
	}
	
	//if nMinlen value supplied then
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) <= 0)
		{		
			return (6);
		}		
		//if valid length supplied but string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{	
			return (4);
		}		
		
	}	
	
	//if nMaxlen value supplied then
	if(nMaxlen)
	{
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) <= 0)
		{	
			return (6);	
		} 
		//if valid length supplied but string length is greater then nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{		
			return (5);
		}
	}	
	return (0);
}

/*
FUNCTION checkPassword: checks the password for all possible cases
INPUT 
	strValue			-  is password supplied as string
	nMaxlen(optional)	-  is the maximum length a password field can have, supplied as integer
	nMinlen(optional)	-  is the minimum lenght a password field can have, supplied as integer

OUTPUT
	0 if "No Error"
	1 if "Password field is blank or value is not supplied"
	2 if "Password started with blank space"
	3 if "Password is invalid it contain spaces"
	4 if "Password characters length is below prescribed length"
	5 if "Password characters length is above prescribed length"
	6 if "nMaxlen or nMinlen are invalid or equal to 0 or less then 0, in function parameters"
*/

function checkPassword(strValue, nMaxlen,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//If string value supplied is empty or contains nothing
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
	
	//If the first character of the string value supplied is space
	if(IsFirstCharBlank(strValue))
	{
		return (2);
	}	
	
	//if string value supplied contain spaces
	if(IsStringWithSpaces(strValue))
	{	
		return (3);
	}
		
	//if nMinlen value supplied then
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) <= 0)
		{		
			return (6);
		}		
		//if valid length supplied but string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{
			return (4);
		}		
		
	}
	
	//if nMaxlen value supplied then	
	if(nMaxlen)
	{ 
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) <= 0)
		{	
			return (6);	
		}
		//if valid length supplied but string length is greater then nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{
			return (5);
		}
	}
	return (0);
}

/*
FUNCTION IsIdenticalPassword: checks if the two passwords are identical
INPUT 
		strVal1 -  is first value, supplied as string
		strVal2 -  is second value, supplied as string

OUTPUT
		true   if "No Error"
		false  if "Confirm Password is not identical to Password or either of the value is not supplied"
*/

function IsIdenticalPassword(strVal1, strVal2)
{	
	//if the two string value supplied are not identical or either of the value is not supplied
	if(!IsIdentical(strVal1,strVal2))
	{	
		return (false);
	}
	return (true);	
} 

/*
FUNCTION checkNameField: checks any name value for various possible cases
INPUT 
		strValue			-  is name value, supplied as string
		nMaxlen (optional)	-  is the maximum length a input field can have, supplied as integer
		nMinlen (optional)	-  is the minimum length a input field can have, supplied as integer

OUTPUT
		0 if "No Error"
		1 if "Name field is blank or value is not supplied"		
		2 if "First character is space in Value supplied"
		3 if "Name field contain invalid characters"
		4 if "Name field's characters length is below prescribed length"
		5 if "Name field's characters length is above prescribed length"
		6 if "nMaxlen or nMinlen are invalid or equal to 0 or less then 0, in function parameters"
		
		
*/

function checkNameField(strValue,nMaxlen,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//if String value supplied is empty or contains nothing	
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
	
	//if the first character of the string value supplied is space
	if(IsFirstCharBlank(strValue))
	{
		return (2);
	}
	
	//if the string value supplied is not a valid Name i.e. it should be of pure alphabets etc.
	if(!IsValidNameValue(strValue))
	{
		return (3);
	}	
	
	//if nMinlen value supplied then
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) < 0)
		{		
			return (6);
		}		
		//if valid length supplied but string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{
			return (4);
		}		
		
	}
	
	//if nMaxlen value supplied then	
	if(nMaxlen)
	{ 
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) <= 0)
		{	
			return (6);	
		}
		//if valid length supplied but string length is greater than nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{
			return (5);
		}
	}
	return (0);
}


/*
FUNCTION checkNumericField: checks any numeric value for various possible cases
INPUT 
		strValue			-  is input field value supplied as string.
		nMaxlen (optional)	-  is the maximum length a input field can have, supplied as integer.
		nMinlen (optional)	-  is the minimum length a input field can have, supplied as integer.

OUTPUT
		0 if "No Error"
		1 if "numeric value supplied is blank or not supplied"
		2 if "numeric value contain invalid characters"
		3 if "numeric value's characters length is below prescribed length"
		4 if "numeric value's characters length is above prescribed length"
		5 if "nMaxlen or nMinlen are invalid or less then 0 in, function parameter"
		
*/

function checkNumericField(strValue,nMaxlen,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//if strValue supplied is empty or contains nothing	
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
		
	//if strValue supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValue))
	{
		return (2);
	}	
	//if nMinlen value supplied then
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) < 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{
			return (3);
		}		
		
	}
	
	//if nMaxlen value supplied then	
	if(nMaxlen)
	{ 
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) < 0)
		{	
			return (5);	
		}
		//if valid length supplied but string length is greater then nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{
			return (4);
		}
	}
	return (0);
}


/*
FUNCTION checkStringField: checks any string value for various possible cases
INPUT 
		strValue			-  is input field value supplied as string.
		nMaxlen (optional)	-  is the maximum length a input field can have, supplied as integer.
		nMinlen (optional)	-  is the minimum length a input field can have, supplied as integer.

OUTPUT
		0 if "No Error"
		1 if "string value is blank or value is not supplied"
		2 if "string value started with blank space"
		3 if "string value's characters length is below prescribed length"
		4 if "string value's characters length is above prescribed length"
		5 if "nMinlen or nMaxlen are invalid or less then 0 in Input field"
		
*/

function checkStringField(strValue,nMaxlen,nMinlen)
{

	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//if string value supplied is empty or contains nothing
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
	
	//if the first character of the string value supplied is space
	if(IsFirstCharBlank(strValue))
	{
		return (2);
	}			
		
	//if nMinlen value supplied then
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) < 0)
		{		
			return (5);
		}		
		//if valid length supplied but the string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{
			return (3);
		}		
		
	}
	
	//if nMaxlen value supplied then	
	if(nMaxlen)
	{ 
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) <= 0)
		{	
			return (5);	
		}
		//if valid length supplied but the string length is greater then nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{
			return (4);
		}
	}
	return (0);
}

/*
FUNCTION checkEmail: checks email value for various possible cases
INPUT 
		strValue			-	is email input field value supplied as string.
		nMinlen(Optional)	-	supply value 0 if you if email field is optional or don't supply this parameter	
		
OUTPUT
		0 if "No Error"
		1 if "Input field is blank or parameter is supplied"
		2 if "Input field contain spaces"
		3 if "Invalid Email value is supplied"
		
*/

function checkEmail(strValue,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//if email value supplied is emtpy or contains nothing	
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
	
	//if email value supplied contain spaces
	if(IsStringWithSpaces(strValue))
	{
		return (2);
	}	
	
	//if not a valid email value supplied	
	if(!IsValidEMail(strValue))
	{
		return (3)
	}
	return (0);
}


/*
FUNCTION checkPhoneFaxNumber: check any Phone and Fax Number value for various possible cases
INPUT 
		strVal1			-	1st subfield of phone or fax.
		strVal2			-	2nd subfield of phone or fax.
		strVal3			-	3rd subfield of phone or fax.
		
		nLen1(optional)	-	length of 1st subfield
		nLen2(optional)	-	length of 2nd subfield
		nLen3(optional)	-	length of 3rd subfield

OUTPUT
		0 if "No Error"
		1 if "Phone or Fax number is blank or compulsory parameters are not supplied"
		2 if "Phone or Fax number field contains invalid characters"		
		3 if "Phone or Fax number field contain blank space"
		4 if "Phone or Fax number field's characters length is invalid"		
		5 if "nLen1 or nLen2 or nLen3 value is invalid or less then 0 in function parameter"
		6 if "Either supply all optional parameters or none"
		
*/

function checkPhoneFaxNumber(strVal1,strVal2,strVal3,nLen1,nLen2,nLen3)
{

	//if nLen1 is equal to 0 and values i.e. strVal1, strVal2, strVal3 is not supplied return success code
	//else return error code
	if (0 == nLen1)
	{
		//check compulsory fields
		if(!(strVal1 && strVal2 && strVal3))
		{
			return(0);
		}
	}
	else
	{
		//check compulsory fields
		if(!(strVal1 && strVal2 && strVal3))
		{
			return(1);
		}
	}
	
	//check optional parameters
	if((nLen1 || nLen2 || nLen3))
	{
		if(!(nLen1 && nLen2 && nLen3))
		{
			return (6);
		}
	}
	
	//if any of the field value is not supplied or left blank
	if(!(IsValueExist(strVal1) && IsValueExist(strVal2) && IsValueExist(strVal3)))
	{	
		return (1);
	}
	
	//check if any of the value is not a valid numeric number
	if(!(IsValidPhoneFaxNumber(strVal1,'f') && IsValidPhoneFaxNumber(strVal2,'f') && IsValidPhoneFaxNumber(strVal3,'f')))
	{
		return (2);
	}

	//if nLen1 value supplied then
	if(nLen1)
	{
		//if invalid length supplied
		if(isNaN(nLen1) || parseInt(nLen1) < 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of the value is less then nLen1
		if(strVal1.length < parseInt(nLen1))	
		{
			return (4);
		}				
	}
	
	//if nLen2 value supplied then
	if(nLen2)
	{
		//if invalid length supplied
		if(isNaN(nLen2) || parseInt(nLen2) < 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of the value is less then nLen2
		if(strVal2.length < parseInt(nLen2))	
		{
			return (4);
		}				
	}
	
	//if nLen3 value supplied then
	if(nLen3)
	{
		//if invalid length supplied
		if(isNaN(nLen3) || parseInt(nLen3) < 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of the value is less then nLen3 
		if(strVal3.length < parseInt(nLen3))	
		{
			return (4);
		}				
	}
	return (0);
}

/*
FUNCTION checkPhoneFaxString: checks any Phone and Fax string value for various possible cases
INPUT 
		strVal				-	phone or fax string.
		nMinLen(optional)	-	minimum length phone or fax field can have
								if 0 is supplied as nMinLen filed will be considered as optional
								i.e. nothing is passed to function in strVal with nMinLen as 0 it 
								will return sucess code.	
		nMaxLen(optional)	-	minimum length phone or fax field can have
	
OUTPUT
		0 if "No Error"
		1 if "Phone or Fax number value is blank or compulsory parameters is not supplied"
		2 if "Phone or Fax number value contains invalid characters"		
		3 if "Phone or Fax number value contain blank space"
		4 if "Phone or Fax number value's characters length is invalid"		
		5 if "nMinLen or nMaxLen is invalid or less then 0 in function parameters"		
		
*/

function checkPhoneFaxString(strVal,nMinLen,nMaxLen)
{
	//if nMinLen is equal to 0 and value i.e. strVal is not supplied return success code
	//else return error code
	if (0 == nMinLen)
	{
		if(!strVal)
		{
			return(0);
		}
	}
	else
	{
		if(!strVal)
		{
			return(1);
		}
	}
	
	//if Phone or Fax number supplied is empty or contain nothing	
	if(!IsValueExist(strVal))
	{	
		return (1);
	}

	//check if not a valid phone or fax number
	if(!IsValidPhoneFaxNumber(strVal))
	{
		return (2);
	}
	
	//if nMinLen value supplied then
	if(nMinLen)
	{
		//if invalid length supplied
		if(isNaN(nMinLen) || parseInt(nMinLen) <= 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of the supplied value is less then nMinLen
		if(strVal.length < parseInt(nMinLen))	
		{
			return (4);
		}				
	}
	//if nMaxLen value supplied then
	if(nMaxLen)
	{
		//if invalid length supplied
		if(isNaN(nMaxLen) || parseInt(nMaxLen) <= 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of the supplied value is greater then nMaxLen
		if(strVal.length > parseInt(nMaxLen))	
		{
			return (4);
		}				
	}
	
	return (0);
}

/*
FUNCTION checkValidNumZipCode: checks if the value supplied is a valid Numeric zip code
INPUT 
		strVal				-	is zip code supplied as string/numeric
		nMinLen(optional)	-	is the minimum length of the zip code supplied as numeric
							 	if nMinLen is equal to 0 and value i.e. strVal is not supplied 
							 	field will be consider as optional and function will return 
							 	success code i.e. it will check filed only if strVal is supplied 
							 	with any value
		nMaxLen(optional)	-	is the maximum length of the zip code supplied as numeric
		
OUTPUT
		0 if "No Error"
		1 if "Zip code value is blank or parameter is not supplied"
		2 if "Zip code value contains invalid characters"
		3 if "Zip code value contain blank space"
		4 if "Zip code value's characters length is invalid"
		5 if "nMinLen or nMaxLen is invalid or less then 0 in function parameter"
*/

function checkValidNumZipCode(strVal, nMinLen,nMaxLen)
{	

	//if nMinLen is equal to 0 and value i.e. strVal is not supplied return success code
	//else return error code
	if (0 == nMinLen)
	{
		if(!strVal)
		{
			return(0);
		}
	}
	else
	{
		if(!strVal)
		{
			return(1);
		}
	}

	//if zip value supplied is empty or contains nothing		
	if(!IsValueExist(strVal))
	{	
		return (1);
	}
	
	//if not a valid numeric value
	if(!IsValidNumericValue(strVal))
	{	
		return (2);
	}
	
	//if zip code value contain spaces
	if(IsStringWithSpaces(strVal))
	{
		return (3);
	}
	
	//if nMinLen value supplied then
	if(nMinLen)
	{
		//if invalid length supplied
		if(isNaN(nMinLen) || parseInt(nMinLen) <= 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of zip code value is less then nMinLen
		if(strVal.length < parseInt(nMinLen))	
		{
			return (4);
		}				
	}
	//if nMaxLen value supplied then
	if(nMaxLen)
	{
		//if invalid length supplied
		if(isNaN(nMaxLen) || parseInt(nMaxLen) <= 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of zip code value is greater then nMaxLen
		if(strVal.length > parseInt(nMaxLen))	
		{
			return (4);
		}				
	}


	return (0);	
} 

/*
FUNCTION checkValidAlphNumZipCode: checks if the value supplied is a valid Alpha-Numeric zip code
INPUT 
		strVal				-  is zip code supplied as string
		nMinLen(optional)	-	is the minimum length of the zip code supplied as numeric
							 	if nMinLen is equal to 0 and value i.e. strVal is not supplied 
							 	field will be consider as optional and function will return 
							 	success code i.e. it will check filed only if strVal is supplied 
							 	with any value
		nMaxLen(optional)	-	is the maximum length of the zip code supplied as numeric

OUTPUT
		0 if "No Error"
		1 if "Zip code value is blank or compulsory parameter is not supplied"
		2 if "Zip code value contains invalid characters"
		3 if "Zip code value contain blank space"
		4 if "Zip code value's characters length is invalid"
		5 if "nMinLen or nMaxLen value is invalid or less then 0 in function parameter"
*/

function checkValidAlphNumZipCode(strVal, nMinLen,nMaxLen)
{	
	//if nMinLen is equal to 0 and value i.e. strVal is not supplied return success code
	//else return error code
	if (0 == nMinLen)
	{
		if(!strVal)
		{
			return(0);
		}
	}
	else
	{
		if(!strVal)
		{
			return(1);
		}
	}
	
	//if string value supplied is empty or contains nothing
	if(!IsValueExist(strVal))
	{	
		return (1);
	}
	
	//if zip code value is not a valid alpha numeric zip code
	if(!IsValidAlphNumValue(strVal))
	{	
		return (2);
	}
	
	//if zip code value contain spaces
	if(IsStringWithSpaces(strVal))
	{
		return (3);
	}
	
	//if nMinLen value supplied then
	if(nLen)
	{
		//if invalid length supplied
		if(isNaN(nMinLen) || parseInt(nMinLen) <= 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of zip code value is less then nMinLen
		if(strVal.length < parseInt(nMinLen))	
		{
			return (4);
		}				
	}
	//if nMaxLen value supplied then
	if(nMaxLen)
	{
		//if invalid length supplied
		if(isNaN(nMaxLen) || parseInt(nMaxLen) <= 0)
		{		
			return (5);
		}		
		//if valid length supplied but string length of zip code value is less then nMaxLen
		if(strVal.length > parseInt(nMaxLen))	
		{
			return (4);
		}				
	}
	
	return (0);	
} 


/*
FUNCTION checkDate: checks Date input field for various possible cases
			date format can be:
			1.	m/d/yy or m:d:yy or m-d-yy				e.g. 2/4/99
			2.	mm/dd/yy or mm:dd:yy or mm-dd-yy		e.g. 11/08/99 
			3.	mm/dd/yyyy or mm:dd:yyyy or mm-dd-yyyy	e.g. 11/23/2002
			Note:	You can supply year as two character value it will be a valid year but
					two character year value will be considered as it is. 
					i.e. 99 will be treated  as 99 not 1999
			Valid Date Formats are:
			1	-	stands for default format i.e. mm/dd/yy or mm/dd/yyyy 
			2	-	stands for format	dd/mm/yy or dd/mm/yyyy
			3	-	stands for format	yy/dd/mm or yyyy/dd/mm
			4	-	stands for format	yy/mm/dd or yyyy/mm/dd
	
INPUT 
		There will be two cases for input 
			case 1: supply two values i.e. date format and date string.
			case 2: supply all values i.e. date format day,month,year seperatly.
		
		if two fields are supplied as input arguments  i.e.			
			nFormat -	it is date format supplied as integer. Various date format 
						are described above.
			strVal1	-	is date string field value supplied as string.			
		else			
			nFormat -	is date format supplied as integer. Various date format are
						are described above.
			strVal1 -	is month input field value supplied as string.
			strVal2	-	is day input field value supplied as string.
			strVal3	-	is year input field value supplied as string.
		
OUTPUT
		0 if "No Error"		
		1 if "First field is blank or compulsory parameter is not supplied"		
		2 if "Invalid Date value is supplied"		
		3 if "Either supply only one full date string or supply all date parts i.e. substrings" 
*/

function checkDate(nFormat,strVal1, strVal2, strVal3)
{	
	strValm = 0;
	strVald = 0;
	strValy = 0;
	
	nFormat = new Number(nFormat);
	//if compulsory parameter is not supplied
	if(!((strVal1) && (nFormat)))
	{
		return (1);
	}
	
	//if value in first parameter supplied is blank or empty 
	if(!IsValueExist(strVal1))
	{
		return (1);
	}
		
	
	//if only first parameter is supplied
	if(!((strVal1) && (strVal2) && (strVal3)))
	{
		strVal1 = new String(strVal1);
				
		if(!(strValm = seprateDateString(strVal1,'m',nFormat))) //get month portion from date string i.e. from strVal1
		{
			return (2);
		}
	
		if(!(strVald = seprateDateString(strVal1,'d',nFormat))) //get day portion from date string i.e. from strVal1
		{
			return (2);
		}
	
		if(!(strValy = seprateDateString(strVal1,'y',nFormat))) //get year portion from date string i.e. from strVal1
		{
			return (2);
		}
	}	
	else
	{		
		//if all three parameters are supplied
		if((strVal1) && (strVal2) && (strVal3))
		{
			strValm = strVal1;
			strVald = strVal2;
			strValy = strVal3;
		}
		else
		{
			return (3);	
		}	
	}
	
	strValm = new String(strValm);
	strVald = new String(strVald);
	strValy = new String(strValy);
	
	if (0 == strValm.charAt(0)) 
	{
		strValm = strValm.slice(1,strValm.length);
	}
		
	if (0 == strVald.charAt(0)) 
	{
		strVald = strVald.slice(1,strVald.length);
	}
		
	if (0 == strValy.charAt(0)) 
	{
		strValy = strValy.slice(1,strValy.length);
	}
		
	//if strValm supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValm))
	{
		return (2);
	}
		
	//if strVald supplied is not a valid numeric value	
	if(!IsValidNumericValue(strVald))
	{
		return (2);
	}
		
	//if strValy supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValy))
	{
		return (2);
	}
	
	//as the month starts from 0
	strValm = strValm - 1;
	
	//if the date value supplied is not valid
	if(!IsDateValid(parseInt(strValm,10),parseInt(strVald,10),parseInt(strValy,10)))
	{
		return (2);
	}
	
	return (0);
}

/*
FUNCTION checkWithinDate: checks Date value if it is within specified date from today and a valid date 
			date format can be:
			1.	m/d/yy or m:d:yy or m-d-yy				e.g. 2/4/99
			2.	mm/dd/yy or mm:dd:yy or mm-dd-yy		e.g. 11/08/99 
			3.	mm/dd/yyyy or mm:dd:yyyy or mm-dd-yyyy	e.g. 11/23/2002
			Note:	You can supply year as two character value it will be a valid year but
					two character year value will be considered as it is. 
					i.e. 99 will be treated  as 99 not 1999

			Valid Date Formats are:
			1	-	stands for default format i.e. mm/dd/yy or mm/dd/yyyy 
			2	-	stands for format	dd/mm/yy or dd/mm/yyyy
			3	-	stands for format	yy/dd/mm or yyyy/dd/mm
			4	-	stands for format	yy/mm/dd or yyyy/mm/dd

INPUT 
		There will be two cases for input 
			case 1: two values supplied i.e. day's gap and date string
			case 2: four values supplied i.e. day's gap and day,month,year values
		
		if two values are supplied as input argument that will be considered as date string  and time gap i.e.			
			nFormat		-	supplied as integer value various date format are described above.
			nDayWithin	-	number of days an event can happen in past(-ve value) or future(+ve value) or 0 for today supplied as integer 
			strVal1		-	is date string field value supplied as string.
			
		else
			nFormat		-	supplied as integer value various date format are described above.			
			dtWithin	-	number of days an event can happen in past(-) or future(+) or 0 for today supplied as integer 
			strVal1		-	is month input field value supplied as string.
			strVal2		-	is day input field value supplied as string.
			strVal3		-	is year input field value supplied as string.
			
		
OUTPUT
		0 if "No Error"
		1 if "parameter supplied is blank or compulsory parameter are not supplied"
		2 if "Invalid Parameter value is supplied"
		3 if "Date value supplied is too old or new"		
		4 if "Either supply only one full date string or supply all date parts i.e. substrings" 
*/

function checkWithinDate(nFormat,nDayWithin,strVal1,strVal2,strVal3)
{
		
	//if nFormat,nDayWithin and strVal1 i.e. date format,time-gap and date string are 
	//not supplied return error code
	if(!((nDayWithin) && (strVal1) && (nFormat)))
	{
		return (1);
	}
	
	//if date string value is blank or left empty
	if(!IsValueExist(strVal1))
	{	
		return (1);
	}
	
	//if nFormat supplied is not a valid numeric value	
	if(!IsValidNumericValue(nFormat))
	{
		return (2);
	}
	
	//if nDayWithin supplied is not a valid numeric value	
	if(isNaN(nDayWithin))
	{
		return (2);
	}
	
	nFormat		= new Number(nFormat);
	nDayWithin	= new Number(nDayWithin);
	
	//if date string is supplied as single string
	if(!((strVal1) && (strVal2) && (strVal3)))
	{
		strVal1 = new String(strVal1);		
		
		if(!(strValm = seprateDateString(strVal1,'m',nFormat))) //get month portion from date string
		{
			return (2);
		}
	
		if(!(strVald = seprateDateString(strVal1,'d',nFormat))) //get day portion from date string
		{
			return (2);
		}
	
		if(!(strValy = seprateDateString(strVal1,'y',nFormat))) //get year portion from date string
		{
			return (2);
		}
	
		
	}	
	else
	{
		//if all fields of date are supplied seperately
		if(strVal1 && strVal2 && strVal3)
		{
			strValm = strVal1;
			strVald = strVal2;
			strValy = strVal3;
		}
		else
		{
			return (4);
		}	
	}

	strValm = new String(strValm);
	strVald = new String(strVald);
	strValy = new String(strValy);
	
	if (0 == strValm.charAt(0)) 
	{
		strValm = strValm.slice(1,strValm.length);
	}
		
	if (0 == strVald.charAt(0)) 
	{
		strVald = strVald.slice(1,strVald.length);
	}
		
	if (0 == strValy.charAt(0)) 
	{
		strValy = strValy.slice(1,strValy.length);
	}
		
	
	//if strValm supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValm))
	{
		return (2);
	}
		
	//if strVald supplied is not a valid numeric value	
	if(!IsValidNumericValue(strVald))
	{
		return (2);
	}
		
	//if strValy supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValy))
	{
		return (2);
	}
	
	strValm = strValm - 1 //as month always starts from 0
	
	//if date string value is not a valid date
	if(!(IsDateValid(parseInt(strValm,10),parseInt(strVald,10),parseInt(strValy,10))))
	{
		return (2)
	}
	
	//if date is not within specified time period from today
	if(!IsWithinDateValid(parseInt(nDayWithin),parseInt(strValm),parseInt(strVald),parseInt(strValy)))
	{
		return (3)
	}		
	return (0);
}

/*
FUNCTION checkFuturePastDate: checks Date value if it is valid past or future date
			date format can be:
			1.	m/d/yy or m:d:yy or m-d-yy				e.g. 2/4/99
			2.	mm/dd/yy or mm:dd:yy or mm-dd-yy		e.g. 11/08/99 
			3.	mm/dd/yyyy or mm:dd:yyyy or mm-dd-yyyy	e.g. 11/23/2002
			Note:	You can supply year as two character value it will be a valid year but
					two character year value will be considered as it is. 
					i.e. 99 will be treated  as 99 not 1999

			Valid Date Formats are:
			1	-	stands for default format i.e. mm/dd/yy or mm/dd/yyyy 
			2	-	stands for format	dd/mm/yy or dd/mm/yyyy
			3	-	stands for format	yy/dd/mm or yyyy/dd/mm
			4	-	stands for format	yy/mm/dd or yyyy/mm/dd

INPUT 
		There will be two cases for input 
			case 1: two values supplied i.e. day's gap and date string
			case 2: four values supplied i.e. day's gap and day,month,year values
		
		if two values are supplied as input argument that will be considered as date string  and time gap i.e.			
			nFormat		-	supplied as integer value various date format are described above.
			chFuturePast-	'f' for future date 'p' for past date 
			strVal1		-	is date string field value supplied as string.
			
		else
			nFormat		-	supplied as integer value various date format are described above.			
			chFuturePast-	'f' for future date 'p' for past date 
			strVal1		-	is month input field value supplied as string.
			strVal2		-	is day input field value supplied as string.
			strVal3		-	is year input field value supplied as string.
			
		
OUTPUT
		0 if "No Error"
		1 if "parameter supplied is blank or compulsory parameter are not supplied"
		2 if "Invalid Parameter value is supplied"
		3 if "Date value supplied is too old or new"		
		4 if "Either supply only one full date string or supply all date parts i.e. substrings" 
*/
function checkFuturePastDate(nFormat,chFuturePast,strVal1,strVal2,strVal3)
{
	//if nFormat,chFuturePast and strVal1 i.e. date formt,time-gap and date string are 
	//not supplied return error code
	if(!((nFormat) && (chFuturePast) && (strVal1)))
	{
		return (1);
	}
	
	//if date string value is blank or left empty
	if(!IsValueExist(strVal1))
	{	
		return (1);
	}
	
	//if nFormat supplied is not a valid numeric value	
	if(!IsValidNumericValue(nFormat))
	{
		return (2);
	}
	
	//if chFuturePast supplied is not a valid character value	
	if(!(('f' == chFuturePast) || ('p' == chFuturePast)))
	{
		return (2);
	}
	
	nFormat		= new Number(nFormat);
	
	//if date string is supplied as single string
	if(!((strVal1) && (strVal2) && (strVal3)))
	{
		strVal1 = new String(strVal1);		
		
		if(!(strValm = seprateDateString(strVal1,'m',nFormat))) //get month portion from date string
		{
			return (2);
		}
	
		if(!(strVald = seprateDateString(strVal1,'d',nFormat))) //get day portion from date string
		{
			return (2);
		}
	
		if(!(strValy = seprateDateString(strVal1,'y',nFormat))) //get year portion from date string
		{
			return (2);
		}
		
	}	
	else
	{
		//if all fields of date are supplied seperately
		if(strVal1 && strVal2 && strVal3)
		{
			strValm = strVal1;
			strVald = strVal2;
			strValy = strVal3;
		}
		else
		{
			return (4);
		}	
	}

	strValm = new String(strValm);
	strVald = new String(strVald);
	strValy = new String(strValy);
	
	if (0 == strValm.charAt(0)) 
	{
		strValm = strValm.slice(1,strValm.length);
	}
		
	if (0 == strVald.charAt(0)) 
	{
		strVald = strVald.slice(1,strVald.length);
	}
		
	if (0 == strValy.charAt(0)) 
	{
		strValy = strValy.slice(1,strValy.length);
	}
	
	//if strValm supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValm))
	{
		return (2);
	}
		
	//if strVald supplied is not a valid numeric value	
	if(!IsValidNumericValue(strVald))
	{
		return (2);
	}
		
	//if strValy supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValy))
	{
		return (2);
	}

	strValm = strValm - 1 //as month always starts from 0
	
	//if date string value is not a valid date
	if(!IsDateValid(parseInt(strValm,10),parseInt(strVald,10),parseInt(strValy,10)))
	{
		return (2);
	}
	
	//if chFuturePast == 'p' check if it is valid past date
	if('p' == chFuturePast)
	{ 
		alert(strValy)
		if(!IsPastDateValid(parseInt(strValm),parseInt(strVald),parseInt(strValy)))
		{
			return (3);
		}
		else
		return (0);		
	}
	//if chFuturePast == 'f' check if it is valid future date
	if('f' == chFuturePast)
	{ 
		if(!IsFutureDateValid(parseInt(strValm),parseInt(strVald),parseInt(strValy)))
		{						
			return (3);
		}
		else
		return (0);		
	}
	return (0);
}

/*
FUNCTION checkTime: checks Time value for various possible cases
INPUT 
		There will be two cases for input 
			case 1: supply only one value as time string i.e. 'hh:mm:ss'
			case 2: supply all three values seperatly i.e. hr,min,sec fields seperatly
		
		if only one field is supplied as input argument that will be considered as time string i.e.			
			strVal1	-	is time string field value supplied as string.
		else			
			strVal1 -	is hour input field value supplied as string.
			strVal2	-	is minute input field value supplied as string.
			strVal3	-	is second input field value supplied as string.
		
OUTPUT
		0 if "No Error"		
		1 if "First parameter is blank or compulsory parameter is not supplied"		
		2 if "Invalid Time value is supplied"		
		3 if "Either supply only one full time string or supply all time parts i.e. substrings" 
*/

function checkTime(strVal1, strVal2, strVal3)
{	
	//if strval1 i.e. first parameter is not supplied return error code
	if(!strVal1)
	{
		return (1);
	}
	
	//if first parameter is blank or contain nothing
	if(!IsValueExist(strVal1))
	{
		return (1);
	}
	
	//if only first substring is supplied i.e. time is supplied as single string
	if(!((strVal1) && (strVal2) && (strVal3)))
	{
		if(!(strValh = seprateTimeString(strVal1,'h'))) //get hour portion from time string
		{
			return (2);
		}
	
		if(!(strValm = seprateTimeString(strVal1,'m'))) //get minute portion from time string
		{
			return (2);
		}
	
		if(!(strVals = seprateTimeString(strVal1,'s'))) //get second portion from time string
		{
			return (2);
		}
	}	
	else
	{
		//if all substrings are supplied i.e. all sub-part of time are supplied
		if(strVal1 && strVal2 && strVal3)
		{
			strValh = strVal1;
			strValm = strVal2;
			strVals = strVal3;
		}
		else
		{
			return (3);
		}	
	}
	
	//if value supplied is not a valid time
	if(!IsTimeValid(strValh,strValm,strVals))
	{
		return (2);
	}
	
	return (0);
}

/*
FUNCTION checkDateTime: checks Date & Time value supplied as combined string for various possible cases
								valid format is 
									'Date Time' string date and time are seperated by space
			date format can be:
			1.	m/d/yy or m:d:yy or m-d-yy				e.g. 2/4/99
			2.	mm/dd/yy or mm:dd:yy or mm-dd-yy		e.g. 11/08/99 
			3.	mm/dd/yyyy or mm:dd:yyyy or mm-dd-yyyy	e.g. 11/23/2002
			Note:	You can supply year as two character value it will be a valid year but
					two character year value will be considered as it is. 
					i.e. 99 will be treated  as 99 not 1999

			Valid Date Formats are:
			1	-	stands for default format i.e. mm/dd/yy or mm/dd/yyyy 
			2	-	stands for format	dd/mm/yy or dd/mm/yyyy
			3	-	stands for format	yy/dd/mm or yyyy/dd/mm
			4	-	stands for format	yy/mm/dd or yyyy/mm/dd

INPUT 
			strVal				-	is Date & Time string field value supplied as string.			
			nFormat(optional)	-	date format supplied as integer. it is described above						
OUTPUT
		0 if "No Error"		
		1 if "Date-Time string is blank or compulsory parameters are not suplied"		
		2 if "Invalid DateTime string is supplied"
		3 if "Invalid Date value is supplied"
		4 if "Invalid Time value is supplied"
		
*/

function checkDateTime(strVal,nFormat)
{	
	//initialize variables
	strValdt	= 0;	//date
	strValtm	= 0;	//time
	strValmt	= 0;	//month
	strValdy	= 0;	//day
	strValyr	= 0;	//year
	strValhr	= 0;	//hour
	strValmin	= 0;	//minute
	strValsec	= 0;	//second
	
	//if compulsory parameters are not supplied
	if(!(strVal))
	{
		return (1);
	}
	
	if(!(nFormat))
	{
		nFormat = 1;
	}
	//if date-string field is left blank or does not contain any value
	if(!IsValueExist(strVal))
	{
		return (1);
	}
	
	//get date portion from datetime string
	if(!(strValdt = getSubstring(strVal,'1'))) 
	{
		return (2);
	}
	//get time portion from datetime string
	if(!(strValtm = getSubstring(strVal,'2'))) 
	{
		return (2);
	}
	
	////Get seprated month day and year value from date portion
	
	//get month portion from date string
	if(!(strValmt = seprateDateString(strValdt,'m',nFormat))) 
	{
		return (3);
	}
	
	//get day portion from date string
	if(!(strValdy = seprateDateString(strValdt,'d',nFormat))) 
	{
		return (3);
	}
	
	//get year portion from date string
	if(!(strValyr = seprateDateString(strValdt,'y',nFormat))) 
	{
		return (3);
	}

	////Get seprated hours minutes and seconds value from time portion
	
	//get hour portion from time string
	if(!(strValhr = seprateTimeString(strValtm,'h'))) 
	{
		return (4);
	}
	
	//get minute portion from time string
	if(!(strValmin = seprateTimeString(strValtm,'m'))) 
	{
		return (4);
	}
	
	//get second portion from time string
	if(!(strValsec = seprateTimeString(strValtm,'s'))) 
	{
		return (4);
	}
	
	strValmt	= new String(strValmt);	//month
	strValdy	= new String(strValdy);	//day
	strValyr	= new String(strValyr);	//year
	strValhr	= new String(strValhr);	//hour
	strValmin	= new String(strValmin);//minute
	strValsec	= new String(strValsec);//second
	
	//truncate if there exist any 0 in front of number and return a decimal number
	strValmt	= parseInt(strValmt,10);
	strValdy	= parseInt(strValdy,10);
	strValyr	= parseInt(strValyr,10);
	strValhr	= parseInt(strValhr,10);
	strValmin	= parseInt(strValmin,10);
	strValsec	= parseInt(strValsec,10);	

		
	//if strValmt supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValmt))
	{
		return (2);
	}
		
	//if strValdy supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValdy))
	{
		return (2);
	}
	
	//if strValyr supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValyr))
	{
		return (2);
	}
		
	//if strValdhr supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValhr))
	{
		return (2);
	}	
	
	//if strValmin supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValmin))
	{
		return (2);
	}
		
	//if strValsec supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValsec))
	{
		return (2);
	}
	
	strValmt = strValmt-1 //as month always starts from 0
	
	//if date is not a valid date
	if(!IsDateValid(strValmt,strValdy,strValyr))
	{
		return (3)
	}
	
	//if time is not a valid time
	if(!IsTimeValid(strValhr,strValmin,strValsec))
	{
		return (4);
	}	
	return (0);
}



/*
FUNCTION checkWithinDateTime: checks Date & Time value supplied as combined string for various possible cases
								valid format is 
									'Date Time' string date and time are seperated by space
			date format can be:
			1.	m/d/yy or m:d:yy or m-d-yy				e.g. 2/4/99
			2.	mm/dd/yy or mm:dd:yy or mm-dd-yy		e.g. 11/08/99 
			3.	mm/dd/yyyy or mm:dd:yyyy or mm-dd-yyyy	e.g. 11/23/2002
			Note:	You can supply year as two character value it will be a valid year but
					two character year value will be considered as it is. 
					i.e. 99 will be treated  as 99 not 1999

			Valid Date Formats are:
			1	-	stands for default format i.e. mm/dd/yy or mm/dd/yyyy 
			2	-	stands for format	dd/mm/yy or dd/mm/yyyy
			3	-	stands for format	yy/dd/mm or yyyy/dd/mm
			4	-	stands for format	yy/mm/dd or yyyy/mm/dd

INPUT 
			strVal				-	is Date & Time string field value supplied as string.			
			nDayWithin			-	number of days an event can happen in past(-ve value) or future(+ve value)
									valid inputs are
									+ve number	- specific future date gap
									-ve number	- specific past date gap
									0			- for today only
									'p'			- value can be any valid past date
									'f'			- value can be any valid future date
			nFormat(optional)	-	date format supplied as integer. it is described above						
OUTPUT
		0 if "No Error"		
		1 if "Date-Time string is blank or compulsory parameters are not suplied"		
		2 if "Invalid DateTime string is supplied"
		3 if "Invalid Date value is supplied"
		4 if "Invalid Time value is supplied"
		5 if "DateTime value supplied is too old or new"
		
*/

function checkWithinDateTime(strVal,nDayWithin,nFormat)
{	
	//initialize variables
	strValdt	= 0;	//date
	strValtm	= 0;	//time
	strValmt	= 0;	//month
	strValdy	= 0;	//day
	strValyr	= 0;	//year
	strValhr	= 0;	//hour
	strValmin	= 0;	//minute
	strValsec	= 0;	//second
	
	//if compulsory parameters are not supplied
	if(!(nDayWithin && strVal))
	{
		return (1);
	}
	
	if(!(nFormat))
	{
		nFormat = 1;
	}
	//if date-string field is left blank or does not contain any value
	if(!IsValueExist(strVal))
	{
		return (1);
	}
	
	//get date portion from datetime string
	if(!(strValdt = getSubstring(strVal,'1'))) 
	{
		return (2);
	}
	//get time portion from datetime string
	if(!(strValtm = getSubstring(strVal,'2'))) 
	{
		return (2);
	}
	
	////Get seprated month day and year value from date portion
	
	//get month portion from date string
	if(!(strValmt = seprateDateString(strValdt,'m',nFormat))) 
	{
		return (3);
	}
	
	//get day portion from date string
	if(!(strValdy = seprateDateString(strValdt,'d',nFormat))) 
	{
		return (3);
	}
	
	//get year portion from date string
	if(!(strValyr = seprateDateString(strValdt,'y',nFormat))) 
	{
		return (3);
	}

	////Get seprated hours minutes and seconds value from time portion
	
	//get hour portion from time string
	if(!(strValhr = seprateTimeString(strValtm,'h'))) 
	{
		return (4);
	}
	
	//get minute portion from time string
	if(!(strValmin = seprateTimeString(strValtm,'m'))) 
	{
		return (4);
	}
	
	//get second portion from time string
	if(!(strValsec = seprateTimeString(strValtm,'s'))) 
	{
		return (4);
	}
	
	strValmt	= new String(strValmt);	//month
	strValdy	= new String(strValdy);	//day
	strValyr	= new String(strValyr);	//year
	strValhr	= new String(strValhr);	//hour
	strValmin	= new String(strValmin);	//minute
	strValsec	= new String(strValsec);	//second
	//truncate if there exist any 0 in front of number and return a decimal number
	strValmt	= parseInt(strValmt,10);
	strValdy	= parseInt(strValdy,10);
	strValyr	= parseInt(strValyr,10);
	strValhr	= parseInt(strValhr,10);
	strValmin	= parseInt(strValmin,10);
	strValsec	= parseInt(strValsec,10);	

		
	//if strValmt supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValmt))
	{
		return (2);
	}
		
	//if strValdy supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValdy))
	{
		return (2);
	}
	
	//if strValyr supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValyr))
	{
		return (2);
	}
		
	//if strValdhr supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValhr))
	{
		return (2);
	}	
	
	//if strValmin supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValmin))
	{
		return (2);
	}
		
	//if strValsec supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValsec))
	{
		return (2);
	}
	
	strValmt = strValmt-1 //as month always starts from 0
	
	//if date is not a valid date
	if(!IsDateValid(strValmt,strValdy,strValyr))
	{
		return (3)
	}
	
	//if time is not a valid time
	if(!IsTimeValid(strValhr,strValmin,strValsec))
	{
		return (4);
	}
	//if date-time is not within a specified period
	if(!IsWithinDateValid(nDayWithin,strValmt,strValdy,strValyr,strValhr,strValmin,strValsec))
	{
		return (5)
	}
	return (0);
}

/*
FUNCTION checkFuturePastDateTime:	checks Date & Time value supplied as combined string for 
									various possible cases and check if wheter it is a valid 
									future or past date. valid format is 
									'Date Time' string date and time are seperated by space
			date format can be:
			1.	m/d/yy or m:d:yy or m-d-yy				e.g. 2/4/99
			2.	mm/dd/yy or mm:dd:yy or mm-dd-yy		e.g. 11/08/99 
			3.	mm/dd/yyyy or mm:dd:yyyy or mm-dd-yyyy	e.g. 11/23/2002
			Note:	You can supply year as two character value it will be a valid year but
					two character year value will be considered as it is. 
					i.e. 99 will be treated  as 99 not 1999

			Valid Date Formats are:
			1	-	stands for default format i.e. mm/dd/yy or mm/dd/yyyy 
			2	-	stands for format	dd/mm/yy or dd/mm/yyyy
			3	-	stands for format	yy/dd/mm or yyyy/dd/mm
			4	-	stands for format	yy/mm/dd or yyyy/mm/dd

INPUT 
			strVal				-	is Date & Time string field value supplied as string.			
			chDayWithin			-	character value where :									
									'p'			- value can be any valid past date
									'f'			- value can be any valid future date
			nFormat(optional)	-	date format supplied as integer. it is described above						
OUTPUT
		0 if "No Error"		
		1 if "Date-Time string is blank or compulsory parameters are not suplied"		
		2 if "Invalid DateTime string is supplied"
		3 if "Invalid Date value is supplied"
		4 if "Invalid Time value is supplied"
		5 if "DateTime value supplied is too old or new"
		
*/

function checkFuturePastDateTime(strVal,chDayWithin,nFormat)
{	
	//initialize variables
	strValdt	= 0;	//date
	strValtm	= 0;	//time
	strValmt	= 0;	//month
	strValdy	= 0;	//day
	strValyr	= 0;	//year
	strValhr	= 0;	//hour
	strValmin	= 0;	//minute
	strValsec	= 0;	//second
	
	//if compulsory parameters are not supplied
	if(!(chDayWithin && strVal))
	{
		return (1);
	}
	
	if(!(nFormat))
	{
		nFormat = 1;
	}
	//if date-string field is left blank or does not contain any value
	if(!IsValueExist(strVal))
	{
		return (1);
	}
	
	//get date portion from datetime string
	if(!(strValdt = getSubstring(strVal,'1'))) 
	{
		return (2);
	}
	//get time portion from datetime string
	if(!(strValtm = getSubstring(strVal,'2'))) 
	{
		return (2);
	}
	////Get seprated month day and year value from date portion
	
	//get month portion from date string
	if(!(strValmt = seprateDateString(strValdt,'m',nFormat))) 
	{
		return (3);
	}
	
	//get day portion from date string
	if(!(strValdy = seprateDateString(strValdt,'d',nFormat))) 
	{
		return (3);
	}
	
	//get year portion from date string
	if(!(strValyr = seprateDateString(strValdt,'y',nFormat))) 
	{
		return (3);
	}

	////Get seprated hours minutes and seconds value from time portion
	
	//get hour portion from time string
	if(!(strValhr = seprateTimeString(strValtm,'h'))) 
	{
		return (4);
	}
	
	//get minute portion from time string
	if(!(strValmin = seprateTimeString(strValtm,'m'))) 
	{
		return (4);
	}
	
	//get second portion from time string
	if(!(strValsec = seprateTimeString(strValtm,'s'))) 
	{
		return (4);
	}
	strValmt	= new String(strValmt);	//month
	strValdy	= new String(strValdy);	//day
	strValyr	= new String(strValyr);	//year
	strValhr	= new String(strValhr);	//hour
	strValmin	= new String(strValmin);	//minute
	strValsec	= new String(strValsec);	//second
	
	//truncate if there exist any 0 in front of number and return a decimal number
	strValmt	= parseInt(strValmt,10);
	strValdy	= parseInt(strValdy,10);
	strValyr	= parseInt(strValyr,10);
	strValhr	= parseInt(strValhr,10);
	strValmin	= parseInt(strValmin,10);
	strValsec	= parseInt(strValsec,10);	
		
	//if strValmt supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValmt))
	{
		return (2);
	}
		
	//if strValdy supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValdy))
	{
		return (2);
	}
	
	//if strValyr supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValyr))
	{
		return (2);
	}
		
	//if strValdhr supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValhr))
	{
		return (2);
	}	
	
	//if strValmin supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValmin))
	{
		return (2);
	}
		
	//if strValsec supplied is not a valid numeric value	
	if(!IsValidNumericValue(strValsec))
	{
		return (2);
	}
	
	strValmt = strValmt-1 //as month always starts from 0
	
	//if date is not a valid date
	if(!IsDateValid(strValmt,strValdy,strValyr))
	{
		return (3)
	}
	
	//if time is not a valid time
	if(!IsTimeValid(strValhr,strValmin,strValsec))
	{
		return (4);
	}
	
	if ('p' == chDayWithin)
	{
		//if date-time is not valid past date
		if(!IsPastDateValid(strValmt,strValdy,strValyr,strValhr,strValmin,strValsec))
		{
			return (5);
		}
		else
		return (0);
	}	
	if ('f' == chDayWithin)
	{
		//if date-time is not valid past date
		if(!IsFutureDateValid(strValmt,strValdy,strValyr,strValhr,strValmin,strValsec))
		{
			return (5);
		}
		else
		return (0);
	}		
	return (0);
}
//FUNCTION:to compare two dates i.e. if one is less than the other
//INPUT: 
//     two date fields and their format according to any one of the following:
//          1.	m/d/yy or m:d:yy or m-d-yy				e.g. 2/4/99
//			2.	mm/dd/yy or mm:dd:yy or mm-dd-yy		e.g. 11/08/99 
//			3.	mm/dd/yyyy or mm:dd:yyyy or mm-dd-yyyy	e.g. 11/23/2002
//			Note:	You can supply year as two character value it will be a valid year but
//					two character year value will be considered as it is. 
//					i.e. 99 will be treated  as 99 not 1999
//			Valid Date Formats are:
//			1	-	stands for default format i.e. mm/dd/yy or mm/dd/yyyy 
//			2	-	stands for format	dd/mm/yy or dd/mm/yyyy
//			3	-	stands for format	yy/dd/mm or yyyy/dd/mm
//			4	-	stands for format	yy/mm/dd or yyyy/mm/dd	
//OUTPUT:
//          OUTPUT
//         	0 if "No Errori.e first date is less than the second date"		
//		    1 if "supply  two full date string"  		
//		    2 if "Invalid Date is specified"		
//		    3 if "start date is greater than end date"
//         the fields will be--->
//           nformat  = format of the dates supplied
//           strval1  = first date supplied
//           strval2  = second date supplied
function comparedate(nFormat,strVal1,strVal2)
{
      /*bdate1=checkDate(2,strVal1)
	  bdate2=checkDate(2,strVal2) */
	  
	  strValm1 = 0;
	  strVald1 = 0;
	  strValy1 = 0;
	  strValm2 = 0;
	  strVald2 = 0;
	  strValy2 = 0;
	
	
        nFormat = new Number(nFormat);
	    
		strVal1 = new String(strVal1);
		strValm1 = seprateDateString(strVal1,'m',nFormat) //get month portion from date string i.e. from strVal1
		strVald1 = seprateDateString(strVal1,'d',nFormat) //get day portion from date string i.e. from strVal1
		strValy1 = seprateDateString(strVal1,'y',nFormat) //get year portion from date string i.e. from strVal1
		
		
		strValm1 = new String(strValm1);
	    strVald1 = new String(strVald1);
	    strValy1 = new String(strValy1);
		
		strVal2 = new String(strVal2);
				
		strValm2 = seprateDateString(strVal2,'m',nFormat) //get month portion from date string i.e. from strVal2
		strVald2 = seprateDateString(strVal2,'d',nFormat) //get day portion from date string i.e. from strVal2
		strValy2 = seprateDateString(strVal2,'y',nFormat) //get year portion from date string i.e. from strVal2
				
		strValm2 = new String(strValm2);
	    strVald2 = new String(strVald2);
	    strValy2 = new String(strValy2);
			
	    
		
		
		
		      nMonth1	= new Number(strValm1);
	          nDay1		= new Number(strVald1);
	          nYear1	= new Number(strValy1);
			  
		      firstdtSupplied	= new Date(nYear1,nMonth1-1,nDay1);
		      
			
			  nMonth2	= new Number(strValm2);
	          nDay2		= new Number(strVald2);
	          nYear2	= new Number(strValy2);  
	          
			  seconddtSupplied	= new Date(nYear2,nMonth2-1,nDay2);
		
			  //if supplied date is less then or equal to todays' date
	          if(firstdtSupplied <= seconddtSupplied)
	             {
		            return (0);
	             }
				 else
		          {	   
		            return (3);
		          } 
	   return (0);		      
}//END OF FUNCTION		 