/*
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 isChecked(formElement, message) {
	_isEmpty = false;
	if (!formElement.checked) {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

function isNotChosen(methodA, methodC, methodD, message) {
	
	_isEmpty = false;
	if (!methodA.checked && !methodC.checked && !methodD.checked) {
		_isEmpty = true;
		alert(message);
		//formElement.focus();
	}
	
	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;
		}
	}	
}

/*
	Check the apply for login form
*/
function checkLoginAanvraagForm() 
{
	with (window.document.aanvraag) {
		if (cboCountry.selectedIndex == 0) {
			alert('Please select a country');
			cboCountry.focus();
			return;
		} else if (isEmpty(Bedrijfsnaam, 'Please enter a company name')) {
			return;
		} else if (isEmpty(Contactpersoon, 'Please enter a contact name')) {
			return;
		} else if (isEmpty(Adres, 'Please enter an address')) {
			return;
		} else if (isEmpty(Huisnummer, 'Please enter a house number')) {
			return;
		} else if (isEmpty(Postcode, 'Please enter a postal code')) {
			return;
		} else if (isEmpty(Plaats, 'Please enter a city')) {
			return;
		} else if (isEmpty(Telefoon, 'Please enter a telephone number')) {
			return;
		} else if (isEmpty(Email, 'Please enter your email address')) {
			return;
		} else if (isEmpty(KvK, 'Vul uw KvK-nummer in')) {
			return;
		} else if (isEmpty(Username, 'Please choose a username')) {
			return;
		} else if (isEmpty(Password, 'Please enter a password')) {
			return;
		} else {
			submit();
		}
	}	
}
