function dollarfy(show) {
	if ((isNaN(show)) || (show < 0)) return "";
	if (show == 0) return "0.00";
	show = " " + (Math.round(show * 100));
	if (show.indexOf(".") >= 0) show = show.substring(0, show.indexOf("."));
	show = show.substring(1, show.length - 2) + "." + show.substring(show.length - 2, show.length);
	return show;
}
				
function calculate(form) {
	
 	var province = form.province.value;
	var price = form.amount.value;
 
	var tax = 0;
	//var gstRate = 0.07;
	var gstRate = 0.05; // Changed on December 31st, 2007
	var pstRate = 0;
	var hstRate = 0;
	var shippingRate = 9.5;
	
	var note = "Les frais d’expedition incluent 5% TPS";
	
	if (province == "Nouveau-Brunswick") { hstRate = .14; gstRate = 0; note = "Les frais d’expedition incluent 14% TVH"; }
	if (province == "Nouvelle-Écosse") { hstRate = .14; gstRate = 0; note = "Les frais d’expedition incluent 14% TVH"; }
	if (province == "Terre-Neuve") { hstRate = .14; gstRate = 0; note = "Les frais d’expedition incluent 14% TVH"; }
	if (province == "Québec") { shippingRate = 8.5; pstRate = .075; note = "Les frais d’expedition incluent 5% TPS & 7.5% TVQ"; }
	if (province == "Yukon") shippingRate = 11.5;
	if (province == "Territoires du Nord-Ouest") shippingRate = 11.5;
	if (province == "Nunavut") shippingRate = 11.5;
	
	province == "Québec" ? tax = ((((price*gstRate) + (1*price)) * pstRate) + (price*gstRate)) : tax = (price * (gstRate + hstRate +  pstRate));

	form.tax.value = dollarfy(tax);
	form.shipping.value = dollarfy(shippingRate);
	//form.item_name.value = form.item_name_root.value + " [" + note + "]";



}

function validate(form) {
	
	var valid = true;
	msg = "";
	
	if (form.province.value == "") {
		msg += "Veuillez sélectionner la province d'expédition.\n";
		valid = false;
	}
	if (form.os0.value == "" || form.os0.value == " " || form.os0.value == "  " || form.os0.value == "   " || form.os0.value == "    " || form.os0.value == "     " ) {
		msg += "Veuillez indiquer comment vous avez pris connaissance de notre produit.\n";
		valid = false;
	}
	
	if ((form.os1.value == "") && (form.item_name_root.value != "Bebe arrive a la maison - personnelle")) {
		msg += "Veuillez inscrire l'institution à laquelle vous êtes affiliés.\n";
		valid = false;
	}

	if (valid) {

		if (form.format[0].checked == true) { form.item_name.value = form.item_name_root.value + form.format[0].value; }
		if (form.format[1].checked == true) { form.item_name.value = form.item_name_root.value + form.format[1].value; }
	
		if (form.language[0].checked == true) { form.item_name.value += form.language[0].value; }
		if (form.language[1].checked == true) { form.item_name.value += form.language[1].value; }
		
		calculate(form);
	}
	
	if (!valid)	alert(msg);
	return valid;
}