function is_blank (strFieldName) 
{ 
  
  var li_counter, i

  li_counter = 0; 

  for (i=0 ; i < strFieldName.value.length; i++) 
  { 
     if ( strFieldName.value.charAt(i) == " " ) 
         li_counter ++ 
  } 
  if ( (li_counter == strFieldName.value.length)  ||  (strFieldName.value == "")) 
  { 
  	
     return false
  } 
  else 
     return true
} 


function selected_index ( strFieldName) 
		{ 
		 
		  var li_counter 

		 if ( strFieldName.selectedIndex < 0 ||  strFieldName.value == "") 
		  { 
			
		     	return false
		  } 
		  else 
		     return true
		} 
//**********************************************************************************************
//* Name     : CheckMaxLength(field, maxlength)
//*
//* Purpose  : Checks the field passed as a parameter for its length, if the length of the field
//*            exceeds maxlength parameter, it will restrict further data-entry
//*
//* Parameter: field, maxlength
//*
//**********************************************************************************************

function CheckMaxLength(field, maxlength) 
{
    if (field.value.length > maxlength)
        field.value = field.value.substring(0, maxlength);
}

//***************************************************************************************
//* function: isProperDate
//*           Function to tell whether the given date is valid or not
//*           This function expects date in the format of mm/dd/yyyy
//***************************************************************************************

function isProperDate(argDate) 
{
	var tmpDay  = getDay(argDate);
	var tmpMon  = getMonth(argDate);
	var tmpYear = getYear(argDate);

	return isProperDay(tmpDay, tmpMon, tmpYear) && isProperMonth(tmpMon) && isProperYear(tmpYear);
}

//**************************************************************************************
//* function: getMonth
//*           Function to return the month part of the given date.
//*           This function expects date in the format of mm/dd/yyyy 
//**************************************************************************************

function getMonth(argDate) 
{
	var dateSep = getDateSeparator(argDate);
	
	if (dateSep == ' ')
		return 0;

	if(argDate.split(dateSep).length == 3)
		return argDate.split(dateSep)[0];
	else
		return 0;
}

//**************************************************************************************
//* function: getDay
//*           Function to return the day part of the given date.
//*          This function expects date in the format of mm/dd/yyyy
//**************************************************************************************

function getDay(argDate) 
{
	var dateSep = getDateSeparator(argDate);
	
	if (dateSep == ' ')
		return 0;

	if(argDate.split(dateSep).length == 3)
		return argDate.split(dateSep)[1];
	else
		return 0;
}


//**************************************************************************************
//* function: getYear
//*           Function to return the year part of the given date.
//*           This function expects date in the format of mm/dd/yyyy
//**************************************************************************************

function getYear(argDate) 
{
	var dateSep = getDateSeparator(argDate);
	
	if (dateSep == ' ')
		return 0;

	if(argDate.split(dateSep).length == 3)
		return argDate.split(dateSep)[2];
	else
		return 0;
}

//**************************************************************************************
//* function: isProperMonth
// *          Function to tell whether the given month is a valid one
//**************************************************************************************

function isProperMonth(argMonth) 
{
	if ((isWhiteSpace(argMonth)) || (argMonth == 0))
		return false;
	
	if ((argMonth > 0) && (argMonth < 13))
		return true;
	else
		return false;
}

//**************************************************************************************
//* function: isProperDay
//*           Function to tell whether the given day of the given month is valid
//**************************************************************************************

function isProperDay(argDay, argMonth, argYear) 
{
	if ((isWhiteSpace(argDay)) || (argDay == 0))
		return false;

	if ((argDay > 0) && (argDay < daysInMonth(argMonth, argYear) + 1))
		return true;
	else 
		return false;
}

//**************************************************************************************
//* function: isWhiteSpace(argWhiteSpace) 
//*           Function to check whether the given argument consists of charactes other
//*           than a space and \t
//**************************************************************************************

function isWhiteSpace(argWhiteSpace) 
{
	argWs = argWhiteSpace.toString();
	
	for (var intI=0; intI < argWs.length; intI++)
		if (argWs.charAt(intI) != ' ' && argWs.charAt(intI) != '\t')
			return false;
	
	return true;
}

//**************************************************************************************
//* function: daysInMonth(argMonth, argYear)
//*           Function to return the maximum number of days in a given month of a
//*           given year
//**************************************************************************************

function daysInMonth(argMonth, argYear) 
{
	switch (Number(argMonth)) 
	{
		case 1:		// Jan
		case 3:		// Mar
		case 5:		// May
		case 7:		// Jul
		case 8:		// Aug
		case 10:	// Oct
		case 12:	// Dec
				return 31;
				break;
		
		case 4:		// Apr
		case 6:		// Jun
		case 9:		// Sep
		case 11:		// Nov
				return 30;
				break;
		
		case 2:		// Feb
				if (isLeapYear(argYear))
					return 29;
				else
					return 28;
				break;
		
		default:
				return 0;
	}
}

//**************************************************************************************
//* function: isLeapYear
//*           Function to tell, whether the given year is leap year or not
//**************************************************************************************

function isLeapYear(argYear) 
{
	return ((argYear % 4 == 0) && (argYear % 100 != 0)) || (argYear % 400 == 0) ;
}

//**************************************************************************************
//* function: getDateSeparator
//*           Function to return the date separator
//*           This function expects date in the format of mm/dd/yyyy or mm/dd/yy
//*           or mm-dd-yyyy or mm-dd-yy
//**************************************************************************************

function getDateSeparator(argDate) 
{
	if (argDate.indexOf('/') > 0)
		return '/';
	else
		return ' ';
}


//**************************************************************************************
//* function: isProperYear
//*           Function to tell whether the given Year is a valid one
//**************************************************************************************

function isProperYear(argYear) 
{
	if ((isWhiteSpace(argYear)) || (argYear.toString().length != 4))
		return false;
	
	if (((argYear >=1900) || (argYear >=2000)) && ((argYear < 3000) || (argYear < 2000)))
		return true;
	else
		return false;
		
}

//**********************************************************************************************
//* Name     : isFloat(field)
//*
//* Purpose  : Verifies if the argument passed is a floating point value or not.
//*
//* Parameter: x : Field to check for floating-point value.
//*
//* Return Value: 'True'  if arg. is floating-point
//*               'False' if arg. is not floating-point 
//**********************************************************************************************

function isFloat(field)
{
	var i;
	var strValidChars = "0123456789.";

	if (isEmpty(field))
		return false;	

	for (i = 0; i < field.length; i++)
	{
	   strChar = field.charAt(i);
	   if (strValidChars.indexOf(strChar) == -1)
	   {
		  return false;
	   }
	}
		
	return true;	
}

//**********************************************************************************************
//* Name     : isInteger(field)
//*
//* Purpose  : Verifies if the argument passed is a Integer value or not.
//*
//* Parameter: x : Field to check for Integer value.
//*
//* Return Value: 'True'  if arg. is Integer
//*               'False' if arg. is not Integer
//**********************************************************************************************

function isInteger(field)
{
	var i;
	var strValidChars = "0123456789";

	if (isEmpty(field))
		return false;	

	for (i = 0; i < field.length; i++)
	{
	   strChar = field.charAt(i);
	   if (strValidChars.indexOf(strChar) == -1)
	   {
		  return false;
	   }
	}
		
	return true;	
}

//**********************************************************************************************
//* Name     : hasDecimal(field)
//*
//* Purpose  : Verifies if the argument passed has a decimal in it or not
//*
//* Parameter: field : Field to check for decimal.
//*
//* Return Value: 'True' if arg. has decimal point
//*               'False' if arf. does not have decimal point.
//**********************************************************************************************

function hasDecimal(field)
{
	if (field.indexOf(".") != -1)
		return true;
	else
		return false;
}

//**********************************************************************************************
//* Name     : getDecimalPart(field)
//*
//* Purpose  : Retrieves the decimal part from the
//*
//* Parameter: field : Field to extract decimal part from.
//*
//* Return Value: decimal part.
//**********************************************************************************************

function getDecimalPart(field)
{
	var startPos = field.indexOf(".");
	var decimalPart = field.substr(startPos + 1);
	
	return decimalPart;
}

/*---------------------------------------------------------*/
/* Function : hasWhiteSpace                                */
/*                                                         */
/* Purpose : Function to check for spaces in an argument   */
/*---------------------------------------------------------*/

function hasWhiteSpace(field)
{
	var i;
	
	for (var i=0; i < field.length; i++)
	{
		if (field.charAt(i) == ' ')
			return true;
	}
	
	return false;
}

/*---------------------------------------------------------*/
/* Function : ValidateTime                                 */
/*                                                         */
/* Purpose : To validate time                              */
/*---------------------------------------------------------*/

function ValidateTime(field)
{
	if (isEmpty(field) || (!isFloat(field)))
		return false;
	
	if (hasDecimal(field))
	{
		var decimalPart = getDecimalPart(field);
					
		if (!(decimalPart == "25" || decimalPart == "5" || decimalPart == "50" || decimalPart == "75"))
			return false;
	}
	
	return true;
}

/*---------------------------------------------------------*/
/* Function : isValidSSNumber                              */
/*                                                         */
/* Purpose : To validate Social Security Number            */
/*---------------------------------------------------------*/

function isValidSSNumber(field)
{
	var SSNumberRegExp = /\d\d\d[-]\d\d[-]\d\d\d\d/;
	var SSNumberResult = SSNumberRegExp.exec(field)
		
	if (!(SSNumberResult))
		return false;	
	else
		return true;
}
