/*
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) {
			txtPaymentFirst²ìÿ.value  = txtShippingFirst²ìÿ.value;
			txtPaymentLast²ìÿ.value   = txtShippingLast²ìÿ.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;
			
			txtPaymentFirst²ìÿ.readOnly  = true;
			txtPaymentLast²ìÿ.readOnly   = true;
			txtPaymentAddress1.readOnly   = true;
			txtPaymentAddress2.readOnly   = true;
			txtPaymentPhone.readOnly      = true;
			txtPaymentState.readOnly      = true;			
			txtPaymentCity.readOnly       = true;
			txtPaymentPostalCode.readOnly = true;			
		} else {
			txtPaymentFirst²ìÿ.readOnly  = false;
			txtPaymentLast²ìÿ.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(name, 'Ââåä³òü ³ìÿ êîíòàêòíî¿ îñîáè')) {
			return false;
		} else
		if (isEmpty(city, 'Ââåä³òü ì³ñòî')) {
			return false;
		} else  			
		if (isEmpty(adresa, 'Ââåä³òü àäðåñó')) {
			return false;
		} else  
		if (isEmpty(tel, 'Ââåä³òü òåëåôîí')) {
			return false;
		}
		if (isEmpty(email, 'Ââåä³òü email')) {
			return false;
		} else  
		{
			return true;
		}
	}
}

function checkInfo()
{
/* 
Ëîã³í 
Ïàðîëü 
Êîíòàêòíà îñîáà 
Òåëåôîí
*/
	with (window.document.frmCheckout) {
		if (isEmpty(login, 'Ââåä³òü ëîã³í')) {
			return false;
		}
		else
		if (isEmpty(passw, 'Ââåä³òü ïàðîëü')) {
			return false;
		}
		else
		if (isEmpty(name, 'Ââåä³òü ³ìÿ êîíòàêòíî¿ îñîáè')) {
			return false;
		} else  
		if (isEmpty(email, 'Ââåä³òü email')) {
			return false;
		} else  
		if (isEmpty(tel, 'Ââåä³òü òåëåôîí')) {
			return false;
		} else	{
			return true;
		}
	}
}
