/*
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)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

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

function checkFeedbackInfo()
{
	with (window.document.sales) {
		if (isEmpty(name, 'Enter your name')) {
			return false;
		} else if (isEmpty(email, 'Enter your email')) {
			return false;
		} else if (isEmpty(phone, 'Enter your correct phone number') && checkNumber(phone)) {
			return false;
		} else if (isEmpty(address, 'Enter your address')) {
			return false;
		} else if (isEmpty(feedback, 'Please, enter your feedback')) {
			return false;
		}  else {
			return true;
		}
	}
}


