function setPaymentInfo(isChecked)
{
	with (window.document.frmCheckout) {
		if (isChecked) {
			txtPaymentFirstName.value  = txtShippingFirstName.value;
			txtPaymentLastName.value   = txtShippingLastName.value;
			txtPaymentDni.value        = txtShippingDni.value;
			txtPaymentAddress1.value   = txtShippingAddress1.value;
			txtPaymentAddress2.value   = txtShippingAddress2.value;
			txtPaymentPhone.value      = txtShippingPhone.value;
			txtPaymentState.value      = txtShippingState.value;			
			txtPaymentCity.value       = txtShippingCity.value;
			txtPaymentPostalCode.value = txtShippingPostalCode.value;
			
			txtPaymentFirstName.readOnly  = true;
			txtPaymentLastName.readOnly   = true;
			txtPaymentAddress1.readOnly   = true;
			txtPaymentAddress2.readOnly   = true;
			txtPaymentPhone.readOnly      = true;
			txtPaymentState.readOnly      = true;			
			txtPaymentCity.readOnly       = true;
			txtPaymentPostalCode.readOnly = true;			
		} else {
			txtPaymentFirstName.readOnly  = false;
			txtPaymentLastName.readOnly   = false;
			txtPaymentAddress1.readOnly   = false;
			txtPaymentAddress2.readOnly   = false;
			txtPaymentPhone.readOnly      = false;
			txtPaymentState.readOnly      = false;			
			txtPaymentCity.readOnly       = false;
			txtPaymentPostalCode.readOnly = false;			
		}
	}
}


function checkShippingAndPaymentInfo()
{
	with (window.document.frmCheckout) {
		if (isEmpty(txtShippingFirstName, 'Rellene el campo de nombre')) {
			return false;
		} else if (isEmpty(txtShippingLastName, 'Rellene el campo de apellido')) {
			return false;
		} else if (isEmpty(txtShippingDni, 'Rellene el campo de DNI/NIF')) {
			return false;
		} else if (isEmpty(txtShippingAddress1, 'Rellene el campo de dirección')) {
			return false;
		} else if (isEmpty(txtShippingPhone, 'Rellene el campo de teléfono')) {
			return false;
		} else if (isEmpty(txtShippingState, 'Rellene el campo de provincia')) {
			return false;
		} else if (isEmpty(txtShippingCity, 'Rellene el campo de ciudad')) {
			return false;
		} else if (isEmpty(txtShippingPostalCode, 'Rellene el campo de codigo postal')) {
			return false;
		} else if (isEmpty(txtPaymentFirstName, 'Rellene el campo de nombre')) {
			return false;
		} else if (isEmpty(txtPaymentLastName, 'Rellene el campo de apellido')) {
			return false;
		} else if (isEmpty(txtPaymentDni, 'Rellene el campo de DNI/NIF')) {
			return false;
		} else if (isEmpty(txtPaymentAddress1, 'Rellene el campo de dirección')) {
			return false;
		} else if (isEmpty(txtPaymentPhone, 'Rellene el campo de ')) {
			return false;
		} else if (isEmpty(txtPaymentState, 'Rellene el campo de provincia')) {
			return false;
		} else if (isEmpty(txtPaymentCity, 'Rellene el campo de ciudad')) {
			return false;
		} else if (isEmpty(txtPaymentPostalCode, 'Rellene el campo de codigo postal')) {
			return false;
		} else if (acepto.checked == false) {
    		alert("Marca el campo de condiciones");
			return false;
		} else {
			return true;
		}
	}
}


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;
		}
	}	
}