/**
* $RCSfile: field.js,v $
* $Author: xujie $
* $Revision: 1.2 $
* $Date: 2005/09/22 17:02:12 $
* $Log: field.js,v $
* Revision 1.2  2005/09/22 17:02:12  xujie
* no message
*
* Revision 1.1  2005/09/22 13:04:26  shenyuan
* initial version for field validation
*
*
*/

/**********************************************************************
 * Component ID : isBlank
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                str           string
 * Output       : int
 * Description  : To check whether a string is blank.
 *                Return 0 - if str is blank.
 *                       1 - otherwise.
 **********************************************************************
 */
function isBlank(str) {
	// check if field string value is blank
	for (var i = 0; i < str.length; i++) {
		var c = str.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) {
			return 1;
		}
	}

	return 0;
}

/**********************************************************************
 * Component ID : isDate
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                str           string
 * Output       : int
 * Description  : To check whether a string conform to date format (d/m/yyyy, dd/m/yyyy, d/mm/yyyy, dd/mm/yyyy).
 *                Return 0 - if str is of valid date format...
 *                       1 - if str is blank.
 *                       2 - if str is not in valid date format.
 **********************************************************************
 */

function isDate(str) {
	if (isBlank(str) == 0) {
		return 1;
	}

	var firstIndex = 0;
	var lastIndex = 0;
	var middleLen = 0;
	var lastLen = 0;

	firstIndex = str.indexOf('/', 0);
	lastIndex = str.lastIndexOf('/');
	middleLen = lastIndex - firstIndex - 1;
	lastLen = str.length - lastIndex - 1;

	if (firstIndex != 1 && firstIndex != 2) {
		return 2;
	}

	if (middleLen != 1 && middleLen != 2) {
		return 2;
	}

	if (lastLen != 4) {
		return 2;
	}

	return 0;
}

/**********************************************************************
 * Component ID : isValidDate
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                str           string
 * Output       : int
 * Description  : To check whether a string represents a valid calendar date.
 *                Return 0 - if str represents a valid calendar date.
 *                       1 - if str is blank.
 *                       2 - if str contain a invalid 'day'.
 *                       3 - if str contain a invalid 'month'.
 *                       4 - if str contain a invalid 'year'.
 *                       5 - if str is not a date format.
 **********************************************************************
 */
function isValidDate(str) {
	// Example of invalid calendar date: 30/2/2001, 1/13/2001
	if (isBlank(str) == 0) {
		return 1;
	}

	if (isDate(str) == 2) {
		return 5;
	}

	var day = 0;
	var month = 0;
	var year = 0;
	day = str.substr(0, str.indexOf('/'));
	month = str.substr(str.indexOf('/') + 1, str.lastIndexOf('/') - str.indexOf('/') - 1);
	year = str.substr(str.lastIndexOf('/') + 1, 4);

	strMil = year.substr(0, 1);

	if (strMil == 0) {
		return 4;
	}

	if (year < 1900) {
		return 4;
	}

	if (isNaN(year) != 0 || year.indexOf('.') != -1 || year <= 0) {
		return 4;
	}

	if (isNaN(month) != 0 || month.indexOf('.') != -1 || month <= 0 || month > 12) {
		return 3;
	}

	if (isNaN(day) != 0 || day.indexOf('.') != -1 || day <= 0 || day > 31) {
		return 2;
	}

	//check this year is a leap year.
	var isLeap = false;
	var modulo4 = year % 4;
	var modulo100 = year % 100;
	var modulo400 = year % 400;

	if (modulo4 == 0) {
		if (modulo400 == 0 && modulo100 == 0) {
			isLeap = true;
		} else if (modulo100 != 0) {
			isLeap = true;
		}
	}

	if ((month == 1) || (month == 3) || (month == 5) || (month == 7) ||
			(month == 8) || (month == 10) || (month == 12)) {
			if (day > 31) return 2;
	} else if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) {
		if (day > 30) {
			return 2;
		}
	} else {
		if (isLeap) {
			if (day > 29) {
				return 2;
			}
		} else { // not leap year
			if (day > 28) {
				return 2;
			}
		}
	}

	return 0; //valid calendar.
}

/**********************************************************************
 * Component ID : isValidDateOfBirth
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                str           string
 * Output       : int
 * Description  : To check whether a string represents a valid calendar date.
 *                Return 0 - if str represents a valid calendar date.
 *                       1 - if str is not a date format.

 **********************************************************************
 */
function isValidDateOfBirth(str) {
	var d;
	var today;

	d = new Date();
	today = d.getDate() + '/';
	today += (d.getMonth() + 1) + '/';
	today += d.getFullYear();

	if (isBlank(str) == 0) {
		return 1;
	}

	if (str.length != 10) {
		return 1;
	}

	if (str.indexOf("/") != 2 || str.lastIndexOf("/") != 5) {
		return 1;
	}
	if (str=="00/00/0000") {
		return 1;
	}

	// Example of invalid calendar date: 30/12/1977 or 00/12/1977 or 00/00/1977 or 00/00/0000
	var tempStr = str.split("/");
	var day = tempStr[0];
	var month = tempStr[1];
	var year = tempStr[2];

	if (day == "00" && month == "00" && year != "0000") {
		if (isNaN(year) != 0 || year.indexOf('.') != -1 || year <= 0) {
			return 1;
		}
	}

	if (day == "00" && month != "00" && year != "0000") {
		if (isNaN(year) != 0 || year.indexOf('.') != -1 || year <= 0) {
			return 1;
		}

		if (isNaN(month) != 0 || month.indexOf('.') != -1 || month <= 0 || month > 12) {
			return 1;
		}
	}

	if (day != "00" && month != "00" && year != "0000") {
		if (isNaN(year) != 0 || year.indexOf('.') != -1 || year <= 0) {
			return 1;
		}

		if (isNaN(month) != 0 || month.indexOf('.') != -1 || month <= 0 || month > 12) {
			return 1;
		}

		if (isNaN(day) != 0 || day.indexOf('.') != -1 || day <= 0 || day > 31) {
			return 1;
		}
	}

	if (day != "00" || month != "00") {
		if (year == "0000") return 1;
	}

	// check for leap year.
	if (day != "00") {
		if ((month == 1) || (month == 3) || (month == 5) ||
				(month == 7) || (month == 8) || (month == 10) || (month == 12)) {
			if (day > 31) {
				return 1;
			}
		} else if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) {
			if (day > 30) {
				return 1;
			}
		} else  {
			if (day > 29) {
				return 1;
			}

			if (!isLeap(str) && day > 28) {
				return 1;
			}
		}

		// check if the date of birth is later than today
		if (after(str, today) != 0) {
			return 1;
		}
	}

	// if day = "00", set day of str and today to "01" , then call after method to compare.
	if (day == "00" && month != "00") {
		str = "01/" + month + "/" + year;

		today = "01/";
		today += (d.getMonth() + 1) + '/';
		today += d.getFullYear();

		// check if the date of birth is later than today
		if (after(str, today) != 0) {
			return 1;
		}
	}

	if (day == "00" && month == "00" && year != "0000") {
		str = "01/01/" + year;

		today = "01/01/";
		today += d.getFullYear();

		// check if the date of birth is later than today
		if (after(str,today) != 0) {
			return 1;
		}
	}

	return 0; //valid calendar day.
}

/**********************************************************************
 * Component ID : isLeap
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                str           string
 * Output       : boolean
 * Description  : To check whether a string is a leap year.
 *                Return true - if str represents a leap year.
 *                       false - otherwise.
 **********************************************************************
 */
function isLeap(str) {
	//check this year is a leap year.
	var modulo4 = str % 4;
	var modulo100 = str % 100;
	var modulo400 = str % 400;

	if (modulo4 == 0) {
		if (modulo400 == 0 && modulo100 == 0) {
			return true;
		} else if (modulo100 != 0) {
			return true;
		}
	}

	return false;
}

/**********************************************************************
 * Component ID : isCurrency
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                str           string
 * Output       : int
 * Description  : To check whether a string is a valid currency format (numeric with/without decimal place, up to 2 decimal place).
 *                Return 0 - if str represents a valid currency.
 *                       1 - if str is blank.
 *                       2 - if str is not a valid currency format.
 *                       3 - etc.
 **********************************************************************
 */
function isCurrency(str) {
	// Example of invalid currency format: 12e.0, 30.5%
	if (isBlank(str) == 0) {
		return 1;
	}

	if (isNaN(str) != 0) {
		return 2;
	}

	if (str.indexOf('.') != -1 && str.length-str.indexOf('.') - 1 > 2) {
		return 3;
	}

	return 0;
}

/**********************************************************************
 * Component ID : isValidLength
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                str           string
 *                min           int                     minimum length
 *                max           int                     maximum length
 * Output       : int
 * Description  : To check whether a string length falls within the required length.
 *                Return 0 - if str is of valid length.
 *                       1 - if str is blank.
 *                       2 - if str is longer than max.
 *                       3 - if str is shorter than min.
 **********************************************************************
 */
function isValidLength(str, min, max) {
	if (isBlank(str) == 0 ) {
		return 1;
	}

	if (str.length >= min && str.length <= max) {
		return 0;
	} else if (str.length > max) {
		return 2;
	} else if (str.length < min) {
		return 3;
	}
}

/**********************************************************************
 * Component ID : isNumeric
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                str           string
 * Output       : int
 * Description  : To check whether a string consists of all numeric characters.
 *                Return 0 - if str contains all numeric characters.
 *                       1 - if str is blank.
 *                       2 - otherwise.
 **********************************************************************
 */
function isNumeric(str) {
	if (isBlank(str) == 0) {
		return 1;
	}

	if (isNaN(str) != 0) {
		return 2;
	}

	if (str.indexOf('.') != -1) {
		return 2;
	}

	if (str.indexOf('-') != -1) {
		return 2;
	}

	return 0;
}

/**********************************************************************
 * Component ID : isOptionSelected
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                radio         radio button group obj
 * Output       : int
 * Description  : To check whether one of the radio button in the radio button group is checked.
 *                Return 0 - if one of the radio button is selected.
 *                       1 - otherwise.
 **********************************************************************
 */
function isOptionSelected(radio) {

	for (var i = 0; i < radio.length; i++) {
		if (radio[i].checked == true) {
			return 0;
		}
	}

	return 1;
}

/**********************************************************************
 * Component ID : isValidTime
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                str           string
 * Output       : int
 * Description  : To check whether a string represents a valid calendar time.
 *                Return 0 - if str represents a valid calendar time.
 *                       1 - if str is a blank string.
 *                       2 - if the delimiter between hours and minutes is not ":".
 *                       3 - if invalid hours.
 *                       4 - if invalid minutes.
 **********************************************************************
 */
function isValidTime(str) {
	if (isBlank(str)==0) {
		return 1;
	}

	var hour1 = str.charAt(0);
	var hour2 = str.charAt(1);
	var minute1 = str.charAt(2);
	var minute2 = str.charAt(3);

	if (isNaN(hour1) != 0 || hour1 > 2 || isNaN(hour2) != 0 || (hour1 == 2 && hour2 > 3)) {
		return 3;
	}

	if (isNaN(minute1) != 0 || minute1 >= 6 || isNaN(minute2) != 0) {
		return 4;
	}

	return 0;
}
/**********************************************************************
 * Component ID : equalOrAfter
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                date1          string                  -
 *                date2          string                  -
 * Output       : int
 * Description  : To check whether date2 is after or equal date1.
 *                Return 0 - if date2 is after or equal date1.
 *                Return 1 - if date1 is blank or is not a valid date.
 *                Return 2 - if date2 is blank or is not a valid date.
 *                Return 3 - if date2 is not after date1.
 **********************************************************************
 */
function equalOrAfter(date1, date2) {

		if (isBlank(date1) == 0 || isValidDate(date1) != 0) {
			return 1;
		}

		if (isBlank(date2) == 0 || isValidDate(date2) != 0) {
			return 2;
		}

		arrTmp = date2.split ("/");

		date2 = new Date();
		date2.setFullYear(arrTmp[2]);
		date2.setMonth(arrTmp[1]-1);
		date2.setDate(arrTmp[0]);

		arrTmp = date1.split ("/");

		date1 = new Date();
		date1.setFullYear(arrTmp[2]);
		date1.setMonth(arrTmp[1]-1); // January = 0
		date1.setDate(arrTmp[0]);

		if (date2 >= date1) {
			return 0;
		} else {
			return 3;
		}
}
/**********************************************************************
 * Component ID : after
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                date1          string                  -
 *                date2          string                  -
 * Output       : int
 * Description  : To check whether date2 is after date1.
 *                Return 0 - if date2 is after date1.
 *                Return 1 - if date1 is blank or is not a valid date.
 *                Return 2 - if date2 is blank or is not a valid date.
 *                Return 3 - if date2 is not after date1.
 **********************************************************************
 */
function after(date1, date2) {
	if (date1.length == 8 || date1.length == 9 || date1.length == 10) {
		if (isBlank(date1) == 0 || isValidDate(date1) != 0) {
			return 1;
		}

		if (isBlank(date2) == 0 || isValidDate(date2) != 0) {
			return 2;
		}

		arrTmp = date2.split ("/");

		date2 = new Date();
		date2.setFullYear(arrTmp[2]);
		date2.setMonth(arrTmp[1]-1);
		date2.setDate(arrTmp[0]);

		arrTmp = date1.split ("/");

		date1 = new Date();
		date1.setFullYear(arrTmp[2]);
		date1.setMonth(arrTmp[1]-1); // January = 0
		date1.setDate(arrTmp[0]);

		if (date2 > date1) {
			return 0;
		} else {
			return 3;
		}
	}

	if (date1.length == 6 || date1.length == 7) {
		arrTmp = date2.split ("/");

		date2 = new Date();
		date2.setFullYear(arrTmp[2]);
		date2.setMonth(arrTmp[1]-1);
		date2.setDate(arrTmp[0]);

		arrTmp = date1.split ("/");

		date1 = new Date();
		date1.setFullYear(arrTmp[1]);
		date1.setMonth(arrTmp[0]-1); // January = 0
		date1.setDate("1");

		if (date2 > date1) {
			return 0;
		} else {
			return 3;
		}
	}

	if (date1.length == 4) {
		arrTmp = date2.split ("/");

		date2 = new Date();
		date2.setFullYear(arrTmp[2]);
		date2.setMonth(arrTmp[1]-1);
		date2.setDate(arrTmp[0]);

		date1 = new Date();
		date1.setFullYear(date1);
		date1.setMonth("0");
		date1.setDate("1");

		if (date2 > date1) {
			return 0;
		} else {
			return 3;
		}
	}

	return 3;
}

/**********************************************************************
 * Component ID : afterTime
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                time1          string                  -
 *                time2          string                  -
 * Output       : int
 * Description  : To check whether time2 is after time1.
 *                Return 0 - if time2 is after time1.
 *                Return 1 - if time1 is blank or is not a valid time.
 *                Return 2 - if time2 is blank or is not a valid time.
 *                Return 3 - if time1 is after time2.
 **********************************************************************
 */
function afterTime(time1, time2) {
	if (isBlank(time1) == 0 || isValidTime(time1) != 0) {
		return 1;
	}

	if (isBlank(time2) == 0 || isValidTime(time2) != 0) {
		return 2;
	}

/*
	arrTmp = time1.split (":");

	time1 = new Date();
	time1.setMinutes(arrTmp[1]);
	time1.setHours(arrTmp[0]);

	arrTmp = time2.split (":");

	time2 = new Date();
	time2.setMinutes(arrTmp[1]);
	time2.setHours(arrTmp[0]);
*/

    minutes1 = time1.substring(2,4);
    hours1 = time1.substring(0,2);

    minutes2 = time2.substring(2,4);
    hours2 = time2.substring(0,2);

	time1 = new Date();
	time1.setMinutes(minutes1);
	time1.setHours(hours1);

	time2 = new Date();
	time2.setMinutes(minutes2);
	time2.setHours(hours2);

	if (time1 > time2) {
		return 3;
	} else {
		return 0;
	}
}

/**********************************************************************
 * Component ID : compareDate
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                strDateFrom      string
 *                strDateTo        string
 * Output       : int
 * Description  : To compare the dates.
 *                Return
 *                      -1 - if strDateFrom > strDateTo
 *                       0 - if strDateFrom = strDateTo
 *                       1 - if strDateTo   > dateFrom
 **********************************************************************
 */
function compareDate(strDateFrom,strDateTo){
	dateFrom= new Date(getYear(strDateFrom), getMonth(strDateFrom), getDay(strDateFrom));
	dateTo=new Date(getYear(strDateTo), getMonth(strDateTo), getDay(strDateTo));
	if(dateFrom == dateTo)
	  return 0;
	else if(dateFrom > dateTo)
	  return -1;
	else if(dateTo > dateFrom)
	  return 1;
}
function getDay(day){
	return day.substring(0,2);
}
function getMonth(month){
	mon=month.substring(3,5);
	mon-=1;
	return mon;
}
function getYear(year){
	return year.substring(6,10);
}

/**********************************************************************
 * Component ID : isCharacter
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                Str           string
 * Output       : int
 * Description  : To check whether the str consists of all characters.
 *                Return 0 - if true
 *                       1 - if false
 *********************************************************************
 */
function isCharacter(str,zeroAllowed) {
	for (i = 0; i < str.length; i++) {
		var cha = str.charAt(i);

		if (((cha >= 'A') && (cha <= 'Z')) ||
				((cha >= 'a') && (cha <= 'z')) ||
				((cha >= '0') && (cha <= '9'))) {
			continue;
		} else {
			return 1;
		}
	}

	return 0;
}

/**********************************************************************
 * Component ID : trim, ltrim, reverse
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                Str           string                  the string need to add
 * Output       : String - the trimmed string
 * Description  : To trim a string, and two other helper functions
 **********************************************************************
 */
function ltrim(str) {
	var first = true;
	var newStr = "";

	for (i = 0; i < str.length; i++) {
		var ch = str.charAt(i);

		if ((ch == " ") && (first)) {
			continue;
		} else {
			first = false;
			newStr += ch;
		}
	}

	return newStr;
}

function trim(str) {
	var t1 = ltrim(str);
	var t2 = reverse(t1);
	var t3 = ltrim(t2);
	var t4 = reverse(t3);

	return t4;
}

function reverse(str) {
	var newStr = "";

	for (i = str.length - 1; i >= 0; i--) {
		var ch = str.charAt(i);
		newStr += ch;
	}

	return newStr;
}

/**********************************************************************
 * Component ID : getIndexInList
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                listbox       Listbox object
 *                value         String                  value in the listbox
 * Output       : int - the corresponding index of the value in the listbox
 * Description  : To get a index of specified value in the list box
 **********************************************************************
 */
function getIndexInList(listbox, value) {
	for (i1 = 0; i1 < listbox.length; i1++) {
		var v = listbox.options[i1].value;

		if (v == value) {
			return i1;
		}
	}

	return 0;
}

/**********************************************************************
 * Component ID : isNumberBlank
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                Str           string                  one value need validation
 * Output       : int,0:true;1:false.
 * Description  : To check whether a string is blank or just 0
 * author   : YanFeng
 * date     : 2/11/2001
 **********************************************************************/
function isNumberBlank(numStr) {
	var newStr = numStr.replace(/0/g, " ");
	newStr = trim(newStr);

	if (newStr == "") {
		return 0;
	}

	return 1;
}

/**********************************************************************
 * Component ID : isDateBetween
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                myDate         string                  checked date
 *                from           string                  from date
 *                to             string                  to date
 * Output       : int,0:true;1:false.
 * Description  : To check whether a specified date is between the from date and to date
 *                or not,be aware that the checked date can equal any one of the two ends
 **********************************************************************
 */
function isDateBetween(myDate, from, to) {
	if (after(from, to) != 0) {
		return 1; //from must later or equal to to
	}

	if ((after(from, myDate) == 0) && (after(myDate, to) == 0)) {
		return 0;
	}

	return 1;
}

/**********************************************************************
 * Component ID : isInArray
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                myData         string                 data need check
 *                arr            array                  the array
 * Output       : int
 * Description  : To check whether a data is in the list of array
 *                Return 0 - if true
 *                       1 - id false
 **********************************************************************
 */
function isInArray(str, arr) {
	for (var h = 0; h < arr.length; h++) {
		if (arr[h] == str) {
			return 0;
		}
	}

	return 1;
}

/**********************************************************************
 * Component ID : changeDateFormat
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                str           string
 * Output       : str
 * Description  : To convert a date string (ddmmyyyy) to (dd/mm/yyyy).
 *                Return a fomated string - if str is of valid date format.
 *                       str - if str is not in valid date format.
 **********************************************************************
 */
function changeDateFormat(str) {
	var firstIndex = 0;
	firstIndex = str.indexOf("/");

	if (firstIndex == -1) { //if '/' is not found
		if (isValidLength(str, 8, 8) == 0)  { //if the string is of 8 characters
			return str.substr(0, 2) + "/" + str.substr(2, 2) + "/" + str.substr(4, 4);
		}
	}

	return str;
}

/**********************************************************************
 * Component ID : isDouble
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                str           string
 *                max           maximum number
 * Output       : int
 * Description  : To check whether a string is numeric double type.
 *                Return 0 - true.
 *                       1 - false.
 **********************************************************************
 */
function isDouble(str, max) {
	if (!isNaN(str)) { //is Numeric
		if ((str > 0) && (str <= max)) { //maximum double
			return 0;
		}
	}

	return 1;
}

/**********************************************************************
 * Component ID : replaceSpace
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                str           string
 * Output       : String will all white space replaced with "%20"
 * Description  : To replace all white space in str with "%20".
 **********************************************************************
 */
function replaceSpace(str) {
	var start = 0;
	var index = 0;
	var converted = "";

	if (str == "") {
		return "";
	}

	while (index != -1) {
		if (start < str.length) {
			index = str.indexOf(' ', start);
		} else {
			break;
		}

		if (index != -1) {
			converted += str.substring(start, index);
			converted += "%20";
		} else {
			break;
		}

		start = index + 1;
	}

	converted += str.substring(start, str.length);

	return converted;
}

/**********************************************************************
 * Component ID : isFutureDate
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                dateStr       string
 * Output       : int
 * Description  : To check whether a dateStr is later than today.
 *                Return 0 - if dateStr is later than today.
 *                       1 - otherwise.
 **********************************************************************
 */
function isFutureDate(dateStr) {
	if (after(getTodayString(), dateStr) == 0) {
		return 0;
	} else {
		return 1;
	}
}

/**********************************************************************
 * Component ID : getTodayString
 * Input        : Name          Type                    Description
 *                ------------- ----------------------- ------------
 *                none
 * Output       : String
 * Description  : This function returns a String representation of today's
 *                date in DD/MM/YYYY format.
 **********************************************************************
 */
function getTodayString() {
	var today = new Date();

	var day = today.getDate().toString();
	var month = (today.getMonth() + 1).toString();
	var year = today.getFullYear().toString();

	var strToday = "";

	if (day.length == 1) {
		strToday += "0";
	}

	strToday += day + "/";

	if (month.length == 1) {
		strToday += "0";
	}

	strToday += month + "/" + year;

	return strToday;
}

function limitTextArea(formobj, e, size){
	returnvalue = true;

	if (!e.which && formobj.value.length >= size) {
		returnvalue = false;
	} else if (e.which && e.which != 8 && formobj.value.length >= size) {
		returnvalue = false;
	}

	return returnvalue;
}

function limitTextArea(obj, limit)
{
	if (obj.value.length > limit)
	{
		alert ('Remarks cannot exceed ' + limit + ' characters');
		obj.value = obj.value.substring(0, limit);
	}
}

function limitTextArea(obj, limit, fieldName)
{
	if (obj.value.length > limit)
	{
		alert (fieldName + ' cannot exceed ' + limit + ' characters');
		obj.value = obj.value.substring(0, limit);
	}
}

