// -- Counter for field
// -- Angie 07 Nov 06
function textCounter(field,cntfield,maxlimit)
{
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
	else
		cntfield.value = maxlimit - field.value.length;
}

// -- To check if input box is empty, true when empty
// -- Angie 07 Nov 06
function isEmpty(str)
{
    strRE = new RegExp(/^[\s]*$/);
	return strRE.test(str.value);
}

// -- To check if email is valid, true when invalid
// -- Angie 07 Nov 06
function notValidEmail(str)
{
    mailRE = new RegExp(/^[\._a-zA-Z0-9-]+@[\.a-zA-Z0-9-]+[\.]{1}[a-zA-Z]{2,4}$/);
    return !(mailRE.test(str.value));
}

// -- To check if string is number (without decimal point), true when not number
// -- Angie 07 Nov 06
function notNumber(str)
{
    strRE = new RegExp(/^[\d]*$/);
    return !(strRE.test(str.value));
}

// -- To check if string is minimum 8 digit number, true when at least 8 digits
// -- Angie 07 Nov 06
function min8Digits(str)
{
    strRE = new RegExp(/^\d{8,}/);
    return (strRE.test(str.value));
}


// -- To check if string is 8 digit number, true when not 8 digits
// -- Angie 07 Nov 06
function not8Digits(str)
{
    strRE = new RegExp(/^\d{8}$/);
    return !(strRE.test(str.value));
}

// -- To check if string is 6 digit number, true when not 6 digits
// -- Angie 07 Nov 06
function not6Digits(str)
{
    strRE = new RegExp(/^\d{6}$/);
    return !(strRE.test(str.value));
}

// -- To check if string is 4 digit number, true when not 4 digits
// -- Angie 07 Nov 06
function not4Digits(str)
{
    strRE = new RegExp(/^\d{4}$/);
    return !(strRE.test(str.value));
}

// -- To check if string contains all alphabets, true when not all are alphabets
// -- Angie 07 Nov 06
function notAlpha(str)
{
    strRE = new RegExp(/^[a-zA-Z ]*$/);
    return !(strRE.test(str.value));
}

// -- To prompt user to confirm delete, true when clicked OK.
// -- Angie 07 Nov 06
function ConfirmDel()
{return confirm("Are you sure?")}


// -- To check if string contains at least 8 char, true when not less than 8 char.
// -- Angie 15 Jan 07
function min8Char(str)
{
	if (parseInt((str.value).length) < 8)
		return false;
	else
		return true;
}

// -- To check whether the length is not less than min length, true when not less than min length.
// -- Angie 07 Nov 06
function CheckMinLen(strValue,nLen)
{
   if (parseInt(strValue.length) < parseInt(nLen))
      return false;
   else 
      return true;
}

// -- To check whether the length is not more than max length, true when not more than max length.
// -- Angie 07 Nov 06
function CheckMaxLen(strValue,nLen)
{
	if (parseInt(strValue.length) > parseInt(nLen))
      return false;
	else 
	  return true;
}

// -- To make days array
// -- Angie 15 Jan 07
function makeArray() 
{
 	this[0] = makeArray.arguments.length;
	for (i = 0; i<makeArray.arguments.length; i++)
        this[i+1] = makeArray.arguments[i];
}
	
var daysofmonth    = new makeArray( 31, 28, 31, 30, 31, 30,
                                    31, 31, 30, 31, 30, 31);
var daysofmonthLY  = new makeArray( 31, 29, 31, 30, 31, 30,
                                    31, 31, 30, 31, 30, 31);


// -- To check whether the Date format is DD/MM/YYYY
// -- Angie 15 Jan 07
function ValidDateFormat(str)
{
	strRE = new RegExp(/^\d{2}\/\d{2}\/\d{4}$/); 
    if (!strRE.test(str.value))
	{
		alert("Date Format is invalid.");
		return false;
	}
	return true;
}

// -- To check whether the Year is a leap year
// -- Angie 15 Jan 07
function LeapYear(year) {
    if ((year/4)   != Math.floor(year/4))   return false;
    if ((year/100) != Math.floor(year/100)) return true;
    if ((year/400) != Math.floor(year/400)) return false;
    return true;
}

// -- To check whether the Date is valid with Leap year check.
// -- Angie 15 Jan 07
function ValidDate(day,month,year) {
    
    if ( (day < 1) || (LeapYear(year) && (day > daysofmonthLY[month]))
		|| (!LeapYear(year) && (day > daysofmonth[month])) )
	{
		alert("Date is invalid.");
		return false;
	}
	return true;
}

// -- To check whether string is valid date.
// -- Angie 15 Jan 07
function IsValidDate(str)
{
    if (ValidDateFormat(str))
	{
		var strdate=new String(str.value);
		var arrdate = strdate.split("/");
		var DD = parseInt(arrdate[0]);
		var MM = parseInt(arrdate[1]);
		var YYYY = parseInt(arrdate[2]);
		return ValidDate(DD,MM,YYYY);
	}
}



