/*
This function allows to change the selection of a selectbox
using javascript.
*/

function dropdownSelection(id, code) {
	var options = document.getElementById(id).options;
	var index = 0;
	for (i=0;i<options.length;i++) {
		if (options[i].value == code) index = options[i].index;
	}
	document.getElementById(id).selectedIndex = index;
}



/*
This function copies the billing information to the shipping information
if the checkbox is true. If it's false, it clears the form
*/

function copy_address(is_checked) {
	if (is_checked) {
		document.getElementById('shipping_title').selectedIndex = document.getElementById('billing_title').selectedIndex;
		document.getElementById('shipping_first_name').value = document.getElementById('billing_first_name').value;
		document.getElementById('shipping_last_name').value = document.getElementById('billing_last_name').value;
		document.getElementById('shipping_address1').value = document.getElementById('billing_address1').value;
		document.getElementById('shipping_city').value = document.getElementById('billing_city').value;
		document.getElementById('shipping_postal_code').value = document.getElementById('billing_postal_code').value;
		document.getElementById('shipping_phone').value = document.getElementById('billing_phone').value;
		document.getElementById('shipping_country').selectedIndex = document.getElementById('billing_country').selectedIndex;
		create_provstate('shipping_country', 'shipping_state_prov');
		document.getElementById('shipping_state_prov').selectedIndex = document.getElementById('billing_state_prov').selectedIndex;
	}
	else {
		document.getElementById('shipping_state_prov').selectedIndex = 0;
		document.getElementById('shipping_first_name').value = '';
		document.getElementById('shipping_last_name').value = '';
		document.getElementById('shipping_address1').value = '';
		document.getElementById('shipping_city').value = '';
		document.getElementById('shipping_postal_code').value = '';
		document.getElementById('shipping_phone').value = '';
		document.getElementById('shipping_country').selectedIndex = 0;
		create_provstate('shipping_country', 'shipping_state_prov');
	}
}


/*
This function opens an url in a popup (pop ups are evil!)
*/

function open_popup(url, width, height) {
	window.open(url, "ouverture", "toolbar=no, status=no, scrollbars=yes, resizable=yes, width=" + width + ", height=" + height);
}