// modified by Simon Lau Kian Lye 12 Mar 2001

// Functions available :
// ----------------------------------------------------------------------
// -----> validateMultiEmails // semi-colon separated
// -----> validateNRIC(myfield,name)
// -----> validateCfrmPswd(myfield,myfield1)
// -----> compareDates(date1,date2) // equal=0 date1<date2=-1 date1>date2=1
// -----> validateMulipleSel(myfield,name)
// -----> validateImgFile(myfield,name)
// -----> validateUserName(myfield,name,min,max) 24 Jul 2000
// -----> validateRadio_Check(myfield,name) 19 Jul 2000
// -----> validateDropDown(myfield,name) 19 Jul 2000
// -----> textareaMax(myfield) 19 Jul 2000
// -----> RemoveBad(InStr)
// -----> validateString(myfield,name)
// -----> validateEmail(myfield,name)
// -----> validateNum(myfield,name)
// -----> validateFloat(myfield,name)
// -----> validateDate(myfield,name)
// -----> validateRange1_99(myfield,name)
// -----> validateRange1_9999(myfield,name)
// -----> validateRange0_99(myfield,name)
// -----> validateMoney(myfield,name)
// ----------------------------------------------------------------------

function validateMultiEmails(myfield,name)
{
	var id=myfield.value
	if (!(notNull(id)&& notBlank(id)))
	{
		return (name+"\n");
	}
	else
	{
		id = id.split(";");

		for (var i = 0; i < id.length; i++)
		{
			varTemp = id[i];
			//alert(varTemp);
			if (!(isEmail(varTemp)))
				return (name+"\n");
		}
	}
	return "";
}


//checking for Singaporean NRIC,FIN input
function validateNRIC(myfield,name){
  var passport_ref = new Array ("","A","B","C","D","E","F","G","H","I","Z","J");
  var FIN_passport_ref = new Array ("","K","L","M","N","P","Q","R","T","U","W","X");

    //myfield.value.toUpperCase();
    passportnum =  myfield.value.toUpperCase();
    if (passportnum.substring(0,1)!='T' && passportnum.substring(0,1)!='G' && passportnum.substring(0,1)!='S')
    	passportnum = 'S' + passportnum;
    total= passportnum.substring(1,2) * 2  +
    passportnum.substring(2,3) * 7 +
    passportnum.substring(3,4) * 6 +
    passportnum.substring(4,5) * 5 +
    passportnum.substring(5,6) * 4 +
    passportnum.substring(6,7) * 3 +
    passportnum.substring(7,8) * 2 ;

    if (passportnum.substring(0,1)=='T' || passportnum.substring(0,1)=='G') total = total + 4;

     if (passportnum.substring(0,1)=='S' || passportnum.substring(0,1)=='T')
           checkdigit = passport_ref[11 - total%11] ;
     else
          checkdigit = FIN_passport_ref[11 - total%11] ;
     if (passportnum.substring(8,9)==checkdigit) return "";
     return (name+"\n");
}

Date.prototype.getDateString = getDateString;
Date.prototype.getFullYear = getFullYear;

function validateCfrmPswd(myfield,myfield1)
{
	if ((myfield.value=='')||(myfield1.value==''))
		return "";
	else
	{
		if (myfield.value==myfield1.value)
			return "";
		else
			return ('\n* Confirmation password differ from the new password\n');
	}
}

function compareDates(date1,date2){

	if ((isDate(date1.value)) && (isDate(date2.value)))
	{
		vardate1 = new Date(date1.value);
	   	vardate2 = new Date(date2.value);
	  	if(vardate1.getDateString() == vardate2.getDateString())
	    		return(0);
	 	else if(vardate1.getDateString() < vardate2.getDateString())
	  		return(-1);
	  	else
	   		return(1);
	}
	else
		return (2);
}

function getDateString(){
   var dateStr;
   dateStr = "" + this.getFullYear();
   if (this.getMonth() < 9)
      dateStr += "0";
   dateStr +=  (this.getMonth() + 1);
   if (this.getDate() < 10)
      dateStr += "0";
   dateStr += this.getDate();
   return dateStr;
}

function getFullYear(){
   var year = this.getYear();
   if(year < 1000){
      year += 1900;}
   return year
}

function validateMulipleSel(myfield,name)
{	count=myfield.length;
	allValid=false;
	for (ic=0;ic<count;ic++)
	{
		if (myfield[ic].selected)
		{	allValid=true;
			break;
		}
	}
	if (!allValid)
		return (name+"\n");
	else
		return "";
}

function isGraphic(text)
{
	if (text == "")
	{
		return true;
	}
	else
	{
		ext = text.substring(text.length-4);
		ext = ext.toLowerCase();
		if ((ext == ".gif") || (ext == ".jpg") || (ext == "jpeg"))
		{
			return true;
		}

		return false;
	}
}

function validateUserName(myfield,name,min,max)
{
  	var allValid = true;

	if (!notNull(myfield.value)||! notBlank(myfield.value))
		allValid = false;

	if (min!="")
	{
		if (myfield.value.length<min)
			allValid = false;
	}

	if (max!="")
	{
		if (myfield.value.length>max)
			allvalid = false;
	}

	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
  	var checkStr = myfield.value;

  	for (i = 0;  i < checkStr.length;  i++)
  	{
    		ch = checkStr.charAt(i);
    		for (j = 0;  j < checkOK.length;  j++)
      			if (ch == checkOK.charAt(j))
				break;
    		if (j == checkOK.length)
    		{
      			allValid = false;
      			break;
    		}
  	}

  	var checkNotOK = "1234567890";
  	var ch = checkStr.charAt(0);
  	for (i=0; i < checkNotOK.length; i++)
  	{
    		if (ch == checkNotOK.charAt(i))
    		{
    			allValid = false;
       			break;
    		}
  	}
	if (!allValid)
  		return (name+"\n");
  	else
  		return "";
}

function validatePassword(myfield,name)
{
  	var allValid = true;

	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  	var checkStr = myfield.value;

  	for (i = 0;  i < checkStr.length;  i++)
  	{
    		ch = checkStr.charAt(i);
    		for (j = 0;  j < checkOK.length;  j++)
      			if (ch == checkOK.charAt(j))
				break;
    		if (j == checkOK.length)
    		{
      			allValid = false;
      			break;
  		}
  	}

	if (!allValid)
  		return (name+"\n");
  	else
  		return "";
}

function validateMulipleSel(myfield,name)
{	count=myfield.length;
	allValid=false;
	for (ic=0;ic<count;ic++)
	{
		if (myfield[ic].selected)
		{	allValid=true;
			break;
		}
	}
	if (!allValid)
		return (name+"\n");
	else
		return "";
}
function validateRadio_Check(myfield,name)
{	count=myfield.length;
	allValid=false;
	for (ic=0;ic<count;ic++)
	{
		if (myfield[ic].checked)
		{	allValid=true;
			break;
		}
	}
	if (!allValid)
		return (name+"\n");
	else
		return "";
}

function validateDropDown(myfield,name)
{
	if ((myfield.options[myfield.selectedIndex].value) == '')
		return (name+"\n");
	else
		return "";
}


function textareaMax(myfield, maxlimit)
{
	if (myfield.value.length > maxlimit) // if too long...trim it!
		myfield.value = myfield.value.substring(0, maxlimit);
}
// eg. <textarea name="" wrap="physical" cols="45" rows="5" onKeyDown="textareaMax(this.form.txtContent,255);" onKeyUp="textareaMax(this.form.txtContent,255);"></textarea>

function RemoveBad(InStr){
    InStr = InStr.replace(/\</g,"");
    InStr = InStr.replace(/\>/g,"");
    InStr = InStr.replace(/\"/g,"");
    InStr = InStr.replace(/\'/g,"");
    InStr = InStr.replace(/\%/g,"");
    InStr = InStr.replace(/\;/g,"");
    InStr = InStr.replace(/\(/g,"");
    InStr = InStr.replace(/\)/g,"");
    InStr = InStr.replace(/\&/g,"");
    InStr = InStr.replace(/\+/g,"");
    return InStr;
}

function validateString(myfield,name)
{
	if (notNull(myfield.value)&& notBlank(myfield.value))
		return "";
	else
		return (name+"\n");
}

function validateEmail(myfield,name)
{
	if (notNull(myfield.value)&& notBlank(myfield.value) && isEmail(myfield.value))
		return "";
	else
		return (name+"\n");
}

function validateNum(myfield,name)
{
	//alert("hello");
	if (notNull(myfield.value)&& notBlank(myfield.value)&&isDigits(myfield.value))
		return "";
	else
		return (name+"\n");
}

function validateFloat(myfield,name)
{
	if (notNull(myfield.value)&& notBlank(myfield.value)&&isNumber(myfield.value))
		return "";
	else
		return (name+"\n");
}

function validateDate(myfield,name)
{
	if (notNull(myfield.value)&& notBlank(myfield.value)&&isDate(myfield.value))
		return "";
	else
		return (name+"\n");
}

function validateTime(myfield,name)
{
	if (notNull(myfield.value)&& notBlank(myfield.value)&&isTime(myfield.value))
		return "";
	else
		return (name+"\n");
}

function validateAmountM(myfield, name)
{
	if (isAmtType('m', myfield.value))
		return "";
	else
		return (name+"\n");
}

function validateAmountL(myfield, name)
{
	if (isAmtType('l', myfield.value))
		return "";
	else
		return (name+"\n");
}

function validateRange1_9999(myfield,name)
{
	if (isDigits(myfield.value) && isInRange(myfield.value,1, 9999))
		return "";
	else
		return (name+"\n");
}

function validateRange1_99(myfield,name)
{
	if (isDigits(myfield.value) && isInRange(myfield.value,1, 99))
		return "";
	else
		return (name+"\n");
}

function validateRange0_99(myfield,name)
{
	if (isDigits(myfield.value) && isInRange(myfield.value,0, 99))
		return "";
	else
		return (name+"\n");
}

function validateMoney(myfield,name)
{
	if (notNull(myfield.value)&& notBlank(myfield.value))
	{
		if(isMoney(myfield.value))
			return "";
		else
			return (name+"\n");
	}
	else
		return (name+"\n");
}

// end of Functions


//======================================================================
// Begin String Validation
//======================================================================
function notNull(str) {
	if (str.length == 0 )
		return false
	else
		return true
}

function notBlank(str) {
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) != " ")
			return true
	}
	return false
}

function isSize(str, size) {
	if (str.length == size)
		return true
	else
		return false
}

function isBlank(formObj)
{
	var s=formObj.value;
	if ((s == null) || (s.length == 0))
		return true;
	else
		return false;
}
//======================================================================
// End String Validation
//======================================================================

//======================================================================
// Begin Numeric Validation
//======================================================================
function isDigits(str) {
	var i
	for (i = 0; i < str.length; i++) {
		mychar = str.charAt(i)
		if (mychar < "0" || mychar > "9")
			return false
	}
	return true
}

function isNumber(str) {
	numdecs = 0
	for (i = 0; i < str.length; i++) {
		mychar = str.charAt(i)
		if ((mychar >= "0" && mychar <= "9") || mychar
			== ".") {
			if (mychar == ".")
				numdecs++
		}
		else
			return false
	}
	if (numdecs > 1)
		return false
return true
}

function isInRange(str, num1, num2) {
	var i = parseInt(str)
	return((i >= num1) && (i <= num2))

}

function isMoney(str)
{
	var tempStr;

	tempStr = str;

	tempStr = stripChars(tempStr, '$');

	return isNumber(tempStr);
}
//======================================================================
// End Numeric Validation
//======================================================================

//======================================================================
// Begin Formatting
//======================================================================
function stripNonDigits(str) {
	var i
	var newstring = ""
	for (i = 0;  i < str.length; i++) {
		mychar = str.charAt(i)
		if (isDigits(mychar))
			newstring += mychar
	}
	return newstring
}

function stripChars(str, chars) {
	var i
	var newstring = ""
	for (i = 0;  i < str.length; i++) {
		mychar = str.charAt(i)
		if (chars.indexOf(mychar) == -1)
			newstring += mychar
	}
	return newstring
}

// Removes initial (leading) whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

function stripInitialWhitespace (s)
{   var i = 0;

    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;

    return s.substring (i, s.length);
}
function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

//======================================================================
// End Formatting
//======================================================================

//======================================================================
// Begin : Email Validation
//======================================================================
// isEmail (STRING s [, BOOLEAN emptyOK])
//
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s)
{   if (isEmpty(s))
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);

    // is s whitespace?
    if (isWhitespace(s)) return false;

    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
//======================================================================
// End : Email Validation
//======================================================================

//======================================================================
// Begin : Whitespace Validation
//======================================================================
var whitespace = " \t\n\r";
function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
//======================================================================
// End : Whitespace Validation
//======================================================================

//======================================================================
// Begin : Date Validation
//======================================================================
// isYear (STRING s [, BOOLEAN emptyOK])
//
// isYear returns true if string s is a valid
// Year number.  Must be 2 or 4 digits only.
//
// For Year 2000 compliance, you are advised
// to use 4-digit year numbers everywhere.
//
// And yes, this function is not Year 10000 compliant, but
// because I am giving you 8003 years of advance notice,
// I don't feel very guilty about this ...
//
// For B.C. compliance, write your own function. ;->
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isYear (s)
{   if (isEmpty(s))
       if (isYear.arguments.length == 1)
       		return false;
       else
       		return (isYear.arguments[1] == true);

    return ((s.length == 2) || (s.length == 4));
}

// isMonth (STRING s [, BOOLEAN emptyOK])
//
// isMonth returns true if string s is a valid
// month number between 1 and 12.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isMonth (s)
{   if (isEmpty(s))
       if (isMonth.arguments.length == 1) return false;
       else return (isMonth.arguments[1] == true);
    return isInRange (s, 1, 12);
}

// isDay (STRING s [, BOOLEAN emptyOK])
//
// isDay returns true if string s is a valid
// day number between 1 and 31.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isDay (s)
{   if (isEmpty(s))
       if (isDay.arguments.length == 1) return false;
       else return (isDay.arguments[1] == true);
    return isInRange (s, 1, 31);
}

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   }
   return this
}

var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

// daysInFebruary (INTEGER year)
//
// Given integer argument year,
// returns number of days in February of that year.

function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

// isDate (STRING year, STRING month, STRING day)
//
// isDate returns true if string arguments year, month, and day
// form a valid date.
//

function isDateCheck (year, month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
    // only accept years that are 4 digits in length
    if (year.length != 4) return false;
    if (parseInt(year) < 1900) return false;
    
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false;

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

//CONVERTS MM/DD/YYYY TO DD/MM/YYYY
function convertDate(DateStr)
{
	dateVal = DateStr;
	var firstSlash = dateVal.indexOf("/");
	var lastSlash = dateVal.lastIndexOf("/");
	if (firstSlash != lastSlash)
	{
		var day = dateVal.substring(0,firstSlash);
		var month = dateVal.substring(firstSlash+1,lastSlash);
		var year = dateVal.substring(lastSlash+1);

		newDate = month + "/" +  day + "/" + year;
		return newDate;
	}
	else
		return (-1);
}

function isDate(DateStr)
{
	dateVal = DateStr
	countSlash = 0
	var firstSlash = dateVal.indexOf("/")
	var lastSlash = dateVal.lastIndexOf("/")
	for (i=0; i<dateVal.length; i++) {
		if (dateVal.substring(i, i+1)=="/")
		{
			countSlash = countSlash + 1;
		}
	}
	if (countSlash > 2)
	{
		return false
	}
	else
	{
		if (firstSlash != lastSlash)
		{
			var day = dateVal.substring(0,firstSlash);
			var month = dateVal.substring(firstSlash+1,lastSlash);
			var year = dateVal.substring(lastSlash+1);

			if (month.substring(0,1) == '0')
				month = month.substring(1,2);
			if (day.substring(0,1) == '0')
				day = day.substring(1,2);
			if (((day=="")||(month=="")) || (year==""))
				return false;
			else
				return(isDateCheck(year,month,day))
		}
		else
			return false;
	}
}

function returnDatePart(DateStr, DatePart)
{
	dateVal = DateStr;
	var firstSlash = dateVal.indexOf("/");
	var lastSlash = dateVal.lastIndexOf("/");
	if (firstSlash != lastSlash)
	{
		var day = dateVal.substring(0,firstSlash);
		var month = dateVal.substring(firstSlash+1,lastSlash);
		var year = dateVal.substring(lastSlash+1);

		if (DatePart=="d")
			return day;
		else if (DatePart=="m")
			return month;
		else if (DatePart=="y")
			return year;
	}
	else
		return (-1);
}

function getLaterDate(AddDays, Year, Month, Day)
{
	// REMEMBER THAT THE MONTH STARTS FROM 0 TO 11, NOT 1 TO 12
	Month = Month - 1
	TDate = new Date(Year, Month, Day);
	MonthDays = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');

	CurYear = TDate.getYear();

	if (CurYear < 2000)       // Y2K Fix, Isaac Powell
		CurYear = CurYear + 1900; // http://onyx.idbsu.edu/~ipowell

	CurMonth = TDate.getMonth();
	CurDay = TDate.getDate();

	// if month is february in a leap year, change no. of days to 29
	if (CurMonth == '01')  {
		if (((CurYear % 4)==0) && ((CurYear % 100)!=0) || ((CurYear % 400)==0)) {
			MonthDays[1] = 29;
		}
		else {
			MonthDays[1] = 28;
	   	}
	}

	days = MonthDays[CurMonth];
	CurDay += AddDays;

	if (CurDay > days) {
		if (CurMonth == 11) {
			CurMonth = 0;
			CurYear = CurYear + 1
		}
		else {
			CurMonth = CurMonth+1;
		}
		CurDay = CurDay - days;
	}

	if (CurDay < 10)
		StrDay = '0' + CurDay;
	else
		StrDay = CurDay;

	CurMonth = CurMonth+1;
	if (CurMonth < 10)
		StrMonth = '0' + CurMonth;
	else
		StrMonth = CurMonth;

	TheDate = StrMonth + '/';
	TheDate += StrDay + '/';
	if (CurYear<100) CurYear="19" + CurYear;
	TheDate += CurYear;

	return TheDate;
}

function filterNonNumeric(fieldName) {
	var result = new String();
	var numbers = "123456789.0";
	var chars = fieldName.value.split(""); // create array
	for (i = 0; i < chars.length; i++) {
		if (numbers.indexOf(chars[i]) != -1) result += chars[i];
	}
	if (fieldName.value != result) {
		fieldName.value = result;
	}
}

function filterDateStr(fieldName) {
	var result = new String();
	var numbers = "1234567890/";
	var chars = fieldName.value.split(""); // create array
	for (i = 0; i < chars.length; i++) {
		if (numbers.indexOf(chars[i]) != -1) result += chars[i];
	}
	if (fieldName.value != result) {
		fieldName.value = result;
	}
}
//======================================================================
// End : Date Validation
//======================================================================


//======================================================================
// Begin : Time Validation
//======================================================================
function isTime(TimeStr)
{
	timeVal = TimeStr
    count = 0
	var colon = timeVal.indexOf(":")
	for (i=0; i<timeVal.length; i++)
    {
		if (timeVal.substring(i, i+1)==":")
			count = count + 1;
	}
	if (count > 1)
		return false
	else
	{
        if (colon != -1)
        {
            var hour = timeVal.substring(0,colon);
            var minute = timeVal.substring(colon+1);
            if (minute.length != 2)
                return false;

            var intHour = parseInt(hour);
            var intMinute = parseInt(minute);
            
            if ((intHour >= 0) && (intHour <= 23))
            {
                if ((intMinute >= 0) && (intMinute <= 59))
                    return true;
                else
                    return false;
            }
            else
                return false;
        }
        else
            return false;
	}
}
//======================================================================
// End : Time Validation
//======================================================================

//======================================================================
// Begin : Select an item from a drop down list
//======================================================================
function selectItem(formObj, selectObj, selectVal)
{
    this.formname = formObj;
    this.selectname = selectObj;
    var optionNum = -1;
    for(var i = 0; i < document.forms[this.formname][this.selectname].options.length; i++) {
        if (document.forms[this.formname][this.selectname].options[i].value == selectVal)
            optionNum = i;
   }
   document.forms[this.formname][this.selectname].options[optionNum].selected = true;
}
//======================================================================
// End : Select an item from a drop down list
//======================================================================


//======================================================================
// Begin : Ensure that at least one of the checkbox is checked.
//======================================================================
function atLeastOneChecked(thecheckbox)
{
    var status = false;

    // Check if there are multiple checkboxes
    if (thecheckbox.length)
    {
        // Multiple checkboxes
        var ii;
        for (ii=0; ii < thecheckbox.length; ii++)
        {
            status = status || thecheckbox[ii].checked;
        }
    }
    else
    {
        // Single checkbox
        status = thecheckbox.checked;
    }

    return status;
}
//======================================================================
// End : Ensure that at least one of the checkbox is checked.
//======================================================================

//======================================================================
// Begin : Amount Validation
// Medium Number: 8, 2
// Large Number: 11, 2
//======================================================================
function isAmtType(FieldType, AmtVal)
{
	amtVal = AmtVal;
    amtVal = stripChars(amtVal, ',');
    fieldType = FieldType;
    count = 0;
    maxLength = 0;
    
    if (fieldType=='m')
        maxLength = 6;
    else if (fieldType=='l')
        maxLength = 9;
        
	var point = amtVal.indexOf(".");
	for (i=0; i<amtVal.length; i++)
    {
		if (amtVal.substring(i, i+1)==".")
			count = count + 1;
	}
    
	if (count > 1)
		return false;
	else
	{
        if (point != -1)
        {
            var dollars = amtVal.substring(0,point);
            var cents = amtVal.substring(point+1);
            if (cents.length > 2)
                return false;

            if (dollars.length > maxLength)
                return false;
            else
                return true;
        }
        else
        {
            if (amtVal.length > maxLength)
                return false;
            else
                return true;
        }
	}
}
//======================================================================
// End : Amount Validation
//======================================================================
