/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox) {
    var isDecimal_re     = /^\s*(\+|-)?((\d+(\,\d\d)?)|(\,\d\d))\s*$/;
    return (String(textBox.value).search(isDecimal_re) != -1);
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	var v = trim(formElement.value);
	
	_isEmpty = false;
	if (v == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

function isEmptyFilename(formElement) {
	var v = trim(formElement.value);
	
	_isEmpty = false;
	if (v == '') {
		_isEmpty = true;
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}