/*
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;
}

/*
	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;
		}
	}	
}

function setPaymentInfo(isChecked)
{
	with (window.document.frmCheckout) 
	{
		if (isChecked) 
		{
			txtAfl_vnaam.value  = txt_vnaam.value;
			txtAfl_anaam.value   = txt_anaam.value;
			txtAfl_straat_huisnummer.value   = txt_straat_huisnummer.value;
			txtAfl_woonplaats.value   = txt_woonplaats.value;
			txtAfl_postcode.value      = txt_postcode.value;
			
			txtAfl_vnaam.readOnly  = true;
			txtAfl_anaam.readOnly   = true;
			txtAfl_straat_huisnummer.readOnly   = true;
			txtAfl_woonplaats.readOnly   = true;
			txtAfl_postcode.readOnly      = true;
		} else 
		{
			txtAfl_vnaam.readOnly  = false;
			txtAfl_anaam.readOnly   = false;
			txtAfl_straat_huisnummer.readOnly   = false;
			txtAfl_woonplaats.readOnly   = false;
			txtAfl_postcode.readOnly      = false;
		}
	}
}

function checkemail()
{
	var str=document.frmCheckout.txt_email.value
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	testresults=true
	else
	{
		alert("Vul AUB een geldit Email adres in!")
		testresults=false
	}
		return (testresults)
}

function checkShippingAndPaymentInfo()
{
	with (window.document.frmCheckout) 
	{
		if (isEmpty(txt_vnaam, 'U bent Voornaam vergeten in te vullen')) {
			return false;
		} else if (isEmpty(txt_anaam, 'U bent Achternaam vergeten in te vullen')) {
			return false;
		} else if (isEmpty(txt_straat_huisnummer, 'U bent Straat + Huisnummer vergeten in te vullen')) {
			return false;
		} else if (isEmpty(txt_postcode, 'U bent Postcode vergeten in te vullen')) {
			return false;
		}  else if (isEmpty(txt_woonplaats, 'U bent Woonplaats vergeten in te vullen')) {
			return false;
		} else if (isEmpty(txt_telefoon, 'U bent Telefoon vergeten in te vullen')) {
			return false;
		} else if (document.layers||document.getElementById||document.all){
			return checkemail()
		} else if (isEmpty(txtAfl_vnaam, 'U bent Voornaam vergeten in te vullen')) {
			return false;
		} else if (isEmpty(txtAfl_anaam, 'U bent Achternaam vergeten in te vullen')) {
			return false;
		} else if (isEmpty(txtAfl_straat_huisnummer, 'U bent Straat + Huisnummer vergeten in te vullen')) {
			return false;
		} else if (isEmpty(txtAfl_postcode, 'U bent Postcode vergeten in te vullen')) {
			return false;
		} else {
			return true;
		}
	}
}
