/*
* check the field is empty or not
* @param field the field
* @return true if spaces is inputted, or has nothing
*/
function isEmpty(field) {
	return checkEmpty(field.value);
}
/*
* check the field is empty or not
* @param field the field
* @return true if spaces is inputted, or has nothing
*/
function checkEmpty(v) {
	var reg=/^[\s]*$/;
	return reg.test(v);
}
/*
* check the field is empty or not.if is empty, alert missing something, and focus the cursor to that field
* @param field the field's name
* @param title the title of the field
* @return true if spaces is inputted, or has nothing
*/
function isEmpty2(field, title) {
	if(isEmpty(field)) {
		alert("Missing "+title);
		field.focus();
		return true;
	}
	return false;
}
/*
* check the field's value is an integer or not
* @param field the field
* @return true if the field's value is an integer
*/
function isInt(field) {
	var reg=/^[\x2B\x2D]{0,1}[\d]+$/;			// only number
	return reg.test(field.value);
}
/*
* check the field's value is an integer or not
* @param field the field
* @return true if the field's value is an integer
*/
function checkInt(field) {
	return isInt(field);
}
/*
* check the field's value is an float or not
* @param field the field
* @return true if the field's value is an float
*/
function isFloat(field) {
	var reg=/^[\x2B\x2D]{0,1}[\d]+[\x2E]{0,1}[\d]*$/;		// number[.]number
	return reg.test(field.value);
}
/*
* check the field's value is an float or not
* @param field the field
* @return true if the field's value is an float
*/
function checkFloat(field) {
	return isFloat(field);
}
/*
* check the value is contained in options
* @param field the field contains options
* @param v the value to check
* @return if v is in the options, return true, or return false;
*/
function checkPredefined(field, v) {
	for(var i=0; i<field.options.length; i++) {
		if(field.options[i].value==v) {
			return true;
		}
	}
	return false;
}
/*
* check the radio or checkbox is checked or not
* @param field the field to check
* @param itmCount the count of the field
* @return false when: non field exists(itmCount<1), non of the fields is checked(itmCount>0)
*/
function checkChecked(field, itmCount) {
	if(itmCount<1) {
		return false;
	}
	if(itmCount==1) {
		return field.checked;
	}
	for(var i=0; i<itmCount; i++) {
		if(field[i].checked) {
			return true;
		}
	}
	return false;
}
function getCheckedCount(field, itmCount) {
	if(itmCount<1) {
		return 0;
	}
	if(itmCount==1) {
		if(field.checked) {
			return 1;
		}
		return 0;
	}
	var iCount=0;
	for(var i=0; i<itmCount; i++) {
		if(field[i].checked) {
			iCount++;
		}
	}
	return iCount;
}
function doSetAllSelection(field, itmCount,checked){
	if(itmCount<1) {
		return false;
	}
	if(itmCount==1) {
		field.checked=checked;
	}
	var iCount=0;
	for(var i=0; i<itmCount; i++) {
		field[i].checked=checked;
			
	}
	return false;
}
function doReverseSelection(field, itmCount){
	if(itmCount<1) {
		return false;
	}
	if(itmCount==1) {
		field.checked=!field.checked;
	}
	var iCount=0;
	for(var i=0; i<itmCount; i++) {
		field[i].checked=!field[i].checked;
			
	}
	return false;
}

/*
* check the email is correct or not
* @param field the field contains email
*/
function checkEmail(field) {
	// such as: java.ning43-fan_43@syne-tech.com
	var reg=/^[a-zA-Z_]([\x2D\x2E]?\w{0,20}){1,3}\x40[\w]{1,20}(\x2D?[\w]{0,20}){1,3}(\x2E[\w]{1,20}(\x2D?[\w]{0,20}){1,3}){1,4}$/;
	return reg.test(field.value);
}

function checkUsername(field) {
	// such as: a, ab, a43_fsd, and the length is : 1-32 characters
	//var reg=/^[a-zA-Z\x5f]([\x2E]{0,1}[\w]{0,30})$/;
	var reg=/^[a-zA-Z\u007f-\ufffe]([\x2D\x2E]{0,1}[\w\u007f-\ufffe]{1,10}){1,3}$/;
	return reg.test(field.value);

}

function ltrim(str) { 
	return str.replace(/^[\s]+/g, "");
}

function rtrim(str) {
	return str.replace(/[\s]+$/g, "");
}

function trim(str) {
    return rtrim(ltrim(str));
}

function clearSpaces(str) {
    return str.replace(/[\s]+/g, "");
}

