	function isFormNumeric(formElem,isInteger){
		if (!isNumeric(formElem.value,isInteger)) {
			alert("Please enter a numeric");
			formElem.value = "0";
			formElem.select();
			formElem.focus();
			return false;
		} else if (formElem.value == "") {
			formElem.value = "0";
		}
		return true;
	}
	
	function isNumeric(num,isInteger) {
		if (isNaN(num)) {
			return false;
		} else {
			if (isInteger) {
				return (num.toString().indexOf(".")==-1 && num.toString().indexOf("-")==-1);
			} else {
				return true;
			}
		}
	}
	
	function isNaD(year,month,day) {
		if (year<1||month<1||month>12||day<1||day>31) {
			return false;
		}
		else {
			if (month==4||month==6||month==9||month==11) {
				if (day==31) {
					return false;
				}
			} else if (month==2) {
				if ((isNumeric(year/4,true) && !isNumeric(year/100,true)) || isNumeric(year/400,true)) {
					if (day>29) {
						return false;
					}
				} else {
					if (day>28) {
						return false;
					}
				}
			}
		}
		return true;
	}
	
	function adjustDate(yearForm,monthForm,dayForm) {
		var maxDay = 31;
		var year = yearForm.selectedIndex+parseInt(yearForm.options[0].value);
		var month = monthForm.selectedIndex+1;
		var day = dayForm.selectedIndex+1;

		if (month==4||month==6||month==9||month==11) {
			maxDay = 30;
		} else if (month==2) {
			if ((isNumeric(year/4,true) && !isNumeric(year/100,true)) || isNumeric(year/400,true)) {
				maxDay = 29;
			} else {
				maxDay = 28;
			}
		}
		setDay(dayForm,maxDay);
		return;
	}
	
	function setDay(dayForm,dayNum) {
		var restoreIndex = 0;
		if (dayForm.selectedIndex < dayNum) {
			restoreIndex = dayForm.selectedIndex;
		} else {
			restoreIndex = dayNum-1;
		}
		dayForm.length = dayNum;
		for (i=0;i<dayNum;i++) {
			dayForm.options[i].index = i+1;
			dayForm.options[i].value = i+1;
			dayForm.options[i].text = i+1;
		}
		dayForm.selectedIndex = restoreIndex;
		return;
	}
	
	function checkMaxSize(formElem,maxSize){
		if (trim(formElem.value).length > maxSize) {
			alert("The message can not longer than 8000 characters");
			formElem.focus();
		}		
	}
	
	function trim(field) {
		var retval = "";
		retval = field.replace(/^\s+/g, "");	// (\s+) means all white space, (^) means after the start of the line
		retval = retval.replace(/\s+$/g, "");	// ($) means before the end of line
		return retval;
	}	
	
	function validateEmail(email) {
		if(email.length < 5) {
			return false;
		} else {
			if(email.lastIndexOf("@")==email.indexOf("@") && email.indexOf("@")>0
				&& email.lastIndexOf(".")>email.indexOf("@")+1 && email.indexOf(".")>-1) {
				return true;
			} else {
				return false;
			}
		}
	}
	
	function fileExtention(filepath) {
		var dotIndex = filepath.lastIndexOf(".");
		if(dotIndex==-1) {
			return "";
		} else {
			return filepath.substring(dotIndex+1,filepath.length);
		}
	}
	
	function isImageFile(filepath) {
		var image_ext = fileExtention(filepath);
		return image_ext=="jpg" || image_ext=="jpeg" || image_ext=="gif";
	}
	
	function isEmpty(s)	{
		return ((s == null) || (s.length == 0));
	}
	
    //space character, including space, tab, form feed, line feed.
	function hasOnlyWhitespace(s){
		return (/^\s+$/.test(s));
	}
	
	function isPositiveInteger(s){
		return (/^\d*$/.test(s));
	}
	
	function isPositiveNumber(s){
		return (/^(\d*\.?\d*|\.\d+)$/.test(s));
	}
	
	function isNumber(s){
		return (/^-?(\d*\.?\d*|\.\d+)$/.test(s));
	}
	
	function isChinese(s){
		return (/^[\u0391-\uFFE5]+$/.test(s));
	}
	
	function isAlphanumeric(s){
		return (/^\w*$/.test(s));
	}
		
	function isAlphabet(s){
		return (/^[a-zA-Z]*$/.test(s));
	}
	
	function isAlphanumericSpc(s){
		return (/^[\w\s]*$/.test(s));
	}
	
	function isEmailAddress(s){
		return (/^[^\s\,\;\'\"]+@[^\s\,\;\'\"]+\.[^\s\,\;\'\"]+$|^$/.test(s));
	}
	
	function isPersent(s){
		return (/^-?(\d*\.?\d*|\.\d+)%?$/.test(s));
	}
	
	function trimAllFields(thisform) {
		var formlen = thisform.elements.length;
		for (i=0; i<formlen; i++){
			if(thisform.elements[i].type == "text" || thisform.elements[i].type == "textarea"){
				thisform.elements[i].value = trim(thisform.elements[i].value);
			}
		}
	}
	
	// Check the date range input by user is valid or not
	// the parameter is the form element object(i.e. <SELECT> ojbect), NOT integer
	
	function validDateRange(from_year,from_month,from_day,to_year,to_month,to_day) {
		var int_from_year = parseInt(from_year.options[from_year.selectedIndex].value);
		var int_from_month = parseInt(from_month.options[from_month.selectedIndex].value);
		var int_from_day = parseInt(from_day.options[from_day.selectedIndex].value);
		var int_to_year = parseInt(to_year.options[to_year.selectedIndex].value);
		var int_to_month = parseInt(to_month.options[to_month.selectedIndex].value);
		var int_to_day = parseInt(to_day.options[to_day.selectedIndex].value);
		return !(int_from_year>int_to_year || (int_from_year==int_to_year && int_from_month>int_to_month) ||
				(int_from_year==int_to_year && int_from_month==int_to_month && int_from_day>int_to_day));
	}