

function TrimTheString ( pszStringtoTrim )
{
	var bflag = true;
	var i = 0;
	if ( IsWhitespace ( pszStringtoTrim ) == true )
		return "";
	while ( ( i < pszStringtoTrim.length ) && ( bflag ) )
	{
		retChar = pszStringtoTrim.charAt ( i++ );
		if ( retChar != " " ) bflag = false;
	}
	if ( bflag ) return "";
	var j = pszStringtoTrim.length-1;
	bflag = true;
	while ( ( j >= 0 ) && ( bflag ) ) 
	{
		retChar = pszStringtoTrim.charAt ( j-- );
		if ( retChar != " " ) bflag = false;
	}
	if ( bflag ) return "";
	pszStringtoTrim = pszStringtoTrim.substring ( i-1 ,j+2 );
	return pszStringtoTrim;
}

/*----------------------------------------------------------------------------------------
	Function Name		: IsWhitespace 
	Parameters			: pszStringtoCheck
	Purpose				: Checks for white spaces
	Creation Date		: June 12, 2002
	Last Modified Date	: June 12, 2002
	-------------------------------------------------------------------------------------------*/
function IsWhitespace ( pszStringtoCheck )
{
	var reWhitespace = /^\s+$/
	return ( IsEmpty ( pszStringtoCheck ) || reWhitespace.test ( pszStringtoCheck ) );
}
	
/*----------------------------------------------------------------------------------------
	Function Name		: IsEmpty 
	Parameters			: pszStringtoCheck
	Purpose				: Checks for empty string
	Creation Date		: June 12, 2002
	Last Modified Date	: June 12, 2002
	-------------------------------------------------------------------------------------------*/

function IsEmpty ( pszStringtoCheck ) {
	return ( ( pszStringtoCheck == null ) || ( pszStringtoCheck.length == 0 ) )
}

 /*----------------------------------------------------------------------------------------
	Function Name       : IsValidPhoneNo
	Parameters			: fieldName - The field to be validated. Eg. "document.frmTest.txtTheField"
	Purpose				: Validates Phone No
	Creation Date		: June 12, 2002
	Last Modified Date	: June 12, 2002
	-------------------------------------------------------------------------------------------*/
	
function IsValidPhoneNo ( TheNumber) {
	var valid = true
//Please add the character which should be allowed
	var GoodChars = "0123456789()-+ "
	var i = 0
	if (TrimTheString(TheNumber)=="") {
		// Return false if number is empty
		valid = false
	}
	for (i =0; i <= TheNumber.length -1; i++) {
		if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
// alert(TheNumber.charAt(i) + " is no good.")
			valid = false
		} // End if statement
	} // End for loop
	return valid
}



	/*----------------------------------------------------------------------------------------
	Function Name       : IsCurrencyFloatSign
	Parameters			: pszFieldObj - The field to be validated. Eg. "document.frmTest.txtTheField"
						  pnPrecision - An integer for the precision of the decimal digits.
	Purpose				: Checks for numeric value and allows decimal depending on the 'pnPrecision' 
						  parameter. Also allows + or - sign at the beginning depending on the 
						  second parameter, 'pbAllowSign'.
	Creation Date		: June 12, 2002
	Last Modified Date	: June 12, 2002
	-------------------------------------------------------------------------------------------*/
function IsCurrencyFloatSign ( pszFieldObj ) 
{
		var szFieldValue = eval( pszFieldObj ).value
		var reTheRegExp = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
		var pnPrecision = 2
		if ( reTheRegExp.test( TrimTheString ( szFieldValue ) ) == false ) {
				return -1111; //Please enter numeric value.
		}
		if ( ( pnPrecision >= ( ( TrimTheString ( szFieldValue ).length - 1 ) - TrimTheString ( szFieldValue ).indexOf ( "." ) ) ) || ( TrimTheString ( szFieldValue ).indexOf ( "." ) == -1 ) ) 
			return 0;
		else 
		{
			return -1112; //Field should contain only 2 decimal places
		}

	}
	
/*----------------------------------------------------------------------------------------
	Author				: SomRaj
	Function Name		: MoveNextPrev
	Parameters			: objPageNumber	- Hidden Object of Page Number
						  nextPrevAddValue	- (1 for Next) & (-1 for Previous)
	Purpose				: to be called when the next or previous button is clicked
	Creation Date		: 9th July 2003
	Last Modified Date	: 9th July 2003
	-------------------------------------------------------------------------------------------*/
function MoveNextPrev(objPageNumber, nextPrevAddValue)
{
	document.forms[0].reset()
	objPageNumber.value = parseInt(objPageNumber.value) + parseInt(nextPrevAddValue)
	document.forms[0].submit()
}

/*----------------------------------------------------------------------------------------
	Author				: Manish Tiwari
	Function Name		: SortOrderClicked
	Parameters			: objSortColumn	- Hidden Object of Sort Column
						  objSortOrder	- Hidden Object of Sort Order
						  objPageNumber	- Hidden Object of Page Number
						  ClickedSortID	- the row of the database column on which to sort.
	Purpose				: to be called with appropriate params when a sort button is clicked.
	Creation Date		: 9th July 2003
	Last Modified Date	: 9th July 2003
	-------------------------------------------------------------------------------------------*/
function SortOrderClicked(objSortColumn, objSortOrder, objPageNumber, ClickedSortID)
{
	document.forms[0].reset()		// reset all the changes made after clicking on the search button

	if ( TrimTheString(objSortColumn.value) == ClickedSortID)		// if the current search column and clicked are same
	{
		if ( TrimTheString(objSortOrder.value) == TrimTheString("Asc"))	// if currently order is "Asc"
			objSortOrder.value = "Desc"									// then change to "Desc"
		else
			objSortOrder.value = "Asc"									// Else change to "Asc"
	}
	else																// if both columns are not same
	{
		objSortOrder.value = "Asc"										// assign to the "Asc" Order
	}

    objSortColumn.value = ClickedSortID				// assign the current sort column to clicked column
    objPageNumber.value = 1							// set back the page number to 1
    document.forms[0].submit()						//	submit the page so that the desired result set is got.
}

// Check whether string s is empty.
// returns true if the string is empty
function IsEmpty(StringToCheck)
{   
	return ((StringToCheck == null) || (StringToCheck.length == 0))
}

 /*----------------------------------------------------------------------------------------
	Function Name		: ValidateEmail 
	Parameters			: field object
	Purpose				: Validates Email ID 
	Creation Date		: Aug 06, 2002
	Last Modified Date	: Aug 06, 2002
	Example				: ValidateEmail(document.forms[0].TxtEmail)
	-------------------------------------------------------------------------------------------*/
function ValidateEmail ( pszFieldObj )
{
	var reEmail = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/
	var szBadStrings = " ~`!#$%^&*()+=[{]}|\<>?,:';";
	var szCurrChar;

	szFieldValue = TrimTheString( eval ( pszFieldObj ).value );
	szFieldValue = szFieldValue.toLowerCase();
	for ( var i=0 ; i < szFieldValue.length ; i++)
	{
		j = i + 1;
		szCurrChar = szFieldValue.substring ( i , j );
		if ( szBadStrings.indexOf ( szCurrChar ) != -1 )
		{		
			return false;
		}
	}
	if ( reEmail.test ( szFieldValue ) == false )
	{
		return false;
	}
	return true;

}

 /*----------------------------------------------------------------------------------------
	Function Name		: IsValidDate
	Parameters			: pszFieldObj(Like document.formName.FieldName)
	Purpose				: The Function Checks the Valid Date. 
	Creation Date		: Oct 04, 2003
	Last Modified Date	: Oct 04, 2003
	-------------------------------------------------------------------------------------------*/
		
function IsValidDate ( pszFieldObj )
{
	var szTheDate = TrimTheString( eval ( pszFieldObj ).value )
	var reTheRegExp = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var aMatchArray = szTheDate.match(reTheRegExp); // is the format ok?

	if (aMatchArray == null) 
	{
		return 1453;
	}

	nMonth = aMatchArray[1]; // parse date into variables
	nDay = aMatchArray[3];
	nYear = aMatchArray[5];
	
	if ( nYear < 1900 )
	{
		//alert("Year must be greater than 1900.");
		return 1454;
	}

	if ( nMonth < 1 || nMonth > 12 ) // check month range
	{
	//	alert("Month must be between 1 and 12.");
		return 1453;
	}

	if ( nDay < 1 || nDay > 31 ) 
	{
	//	alert("Day must be between 1 and 31.");
		return 1453;
	}

	if ( ( nMonth == 4 || nMonth == 6 || nMonth == 9 || nMonth == 11) && nDay == 31 ) 
	{
	//	alert("Month " + nMonth + " does not have 31 days!")
		return 1453;
	}

	if ( parseInt ( nMonth ) == 2) // check for february 29th
	{
		var isleap = ( nYear % 4 == 0 && ( nYear % 100 != 0 || nYear % 400 == 0 ) );
		if ( parseInt ( nDay ) > 29 || ( parseInt ( nDay ) == 29 && !isleap ) ) 
		{
	//		alert("February " + nYear + " doesn't have " + nDay + " days!");
			return 1453;
		}
	}
	return 1; // date is valid
}


/******************************************************************************
DESCRIPTION: Validates that a string contains only numeric values.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
******************************************************************************/
 function CheckNumericValue(strValue)
{ 
	var objRegExp  = /^\d*$/;
	return objRegExp.test(strValue);
}
/**************************************************************************************/
function CheckAlphabet(strValue)
{
	var objRegExp = /^[a-zA-Z.\s']+$/;
	return objRegExp.test(strValue);
}

/**************************************************************************************/
function CheckAlphaNumeric(strValue)
{
	var objRegExp = /^[a-zA-Z0-9.\s']+$/;
	return objRegExp.test(strValue);
}

function CheckDateDiff(objStartDate, objEndDate)
{
	var _StartVal = new Date(eval(objStartDate).value);
	var _EndVal = new Date(eval(objEndDate).value);
	var _DaysDiff =  _EndVal - _StartVal
	_DaysDiff = Math.round(_DaysDiff/1000/60/60/24)
	
	return _DaysDiff;
}

/******************************************************************************/
 /*----------------------------------------------------------------------------------------
	Function Name		: CheckZipCode
	Parameters			: strValue
	Purpose				: The Function Checks the Valid Zip code ( or numbers), 
						  it should not include all zero's. 
	Creation Date		: 16-Feb-2005
	Last Modified Date	: 16-Feb-2005
	-------------------------------------------------------------------------------------------*/
 function CheckZipCode(strValue)
{  
	//if ( parseInt ( strValue ) == 0)
	//{
	//	return false;
	//} 
	var objRegExp  = /^\d*$/;
	return objRegExp.test(strValue);
	
}
/**************************************************************************************/