// JavaScript Document

/**
** Strip whitespace from the beginning and end of a string
*/
function shopping_trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}
/**
** Check if a form element is empty and bring it into focus if it is.
*/
function shopping_is_empty(form_element, message) {
	form_element.value = shopping_trim(form_element.value);
	_is_empty = false;
	if (form_element.value == '') {
		_is_empty = true;
		alert(message);
		form_element.focus();
	}
	return _is_empty;
}

function shopping_set_payment_info(is_checked)
{
	with (window.document.frm_checkout) {
		if (is_checked) {
			txt_payment_first_name.value  = txt_shipping_first_name.value;
			txt_payment_last_name.value   = txt_shipping_last_name.value;
			txt_payment_address1.value    = txt_shipping_address1.value;
			txt_payment_address2.value    = txt_shipping_address2.value;
			txt_payment_phone.value       = txt_shipping_phone.value;
			txt_payment_email.value       = txt_shipping_email.value;
			txt_payment_state.value       = txt_shipping_state.value;
			txt_payment_city.value        = txt_shipping_city.value;
			txt_payment_country.value     = txt_shipping_country.value;
			txt_payment_postal_code.value = txt_shipping_postal_code.value;

			txt_payment_first_name.readOnly  = true;
			txt_payment_last_name.readOnly   = true;
			txt_payment_address1.readOnly    = true;
			txt_payment_address2.readOnly    = true;
			txt_payment_phone.readOnly       = true;
			txt_payment_email.readOnly       = true;
			txt_payment_state.readOnly       = true;
			txt_payment_city.readOnly        = true;
			txt_payment_country.readOnly     = true;
			txt_payment_postal_code.readOnly = true;
		} else {
			txt_payment_first_name.readOnly  = false;
			txt_payment_last_name.readOnly   = false;
			txt_payment_address1.readOnly    = false;
			txt_payment_address2.readOnly    = false;
			txt_payment_phone.readOnly       = false;
			txt_payment_email.readOnly       = false;
			txt_payment_state.readOnly       = false;
			txt_payment_city.readOnly        = false;
			txt_payment_country.readOnly     = false;
			txt_payment_postal_code.readOnly = false;
		}
	}
}


function shopping_check_shipping_and_payment_info()
{
	with (window.document.frm_checkout) {
		if (shopping_is_empty(txt_shipping_first_name, 'Enter first name')) {
			return false;
		} else if (shopping_is_empty(txt_shipping_last_name, 'Enter last name')) {
			return false;
		} else if (shopping_is_empty(txt_shipping_address1, 'Enter shipping address')) {
			return false;
		} else if (shopping_is_empty(txt_shipping_phone, 'Enter phone number')) {
			return false;
		} else if (shopping_is_empty(txt_shipping_state, 'Enter shipping address state')) {
			return false;
		} else if (shopping_is_empty(txt_shipping_city, 'Enter shipping address city')) {
			return false;
		} else if (shopping_is_empty(txt_shipping_postal_code, 'Enter the shipping address postal/zip code')) {
			return false;
		} else if (shopping_is_empty(txt_payment_first_name, 'Enter first name')) {
			return false;
		} else if (shopping_is_empty(txt_payment_last_name, 'Enter last name')) {
			return false;
		} else if (shopping_is_empty(txt_payment_address1, 'Enter Payment address')) {
			return false;
		} else if (shopping_is_empty(txt_payment_phone, 'Enter phone number')) {
			return false;
		} else if (shopping_is_empty(txt_payment_email, 'Enter e-mail address')) {
			return false;
		} else if (shopping_is_empty(txt_payment_state, 'Enter Payment address state')) {
			return false;
		} else if (shopping_is_empty(txt_payment_city, 'Enter Payment address city')) {
			return false;
		} else if (shopping_is_empty(txt_payment_country, 'Enter Payment address country')) {
			return false;
		} else if (shopping_is_empty(txt_payment_postal_code, 'Enter the Payment address postal/zip code')) {
			return false;
		} else {
			return true;
		}
	}
}

function shopAdminChangePage(obj) {
	var pagelist = document.getElementById(obj);
	window.location.href = pagelist.options[pagelist.selectedIndex].value;
}



