// JavaScript calculator for handling price updates in LaVie order form

var cleanser_price = 45;
var toner_price = 45;
var mask_price = 100;
var serum_price = 90;
var eyecream_price = 100;
var facecream_price = 95;
var daycream_price = 85;
var candles_price = 45;

var cleanser_subtotal = 0;
var toner_subtotal = 0;
var mask_subtotal = 0;
var serum_subtotal = 0;
var eyecream_subtotal = 0;
var facecream_subtotal = 0;
var daycream_subtotal = 0;
var candles_subtotal = 0;

var form;

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != "function") {
		window.onload = func;
	}
	else {
		window.onload = function() {
			if (oldonload) { oldonload(); }
			func();
		}
	}
}


function setFormElement() {
	form = document.getElementById('order_form');
}


addLoadEvent(setFormElement);


function updateTotal() {
	form.total.value = cleanser_subtotal + toner_subtotal + mask_subtotal + serum_subtotal + eyecream_subtotal + facecream_subtotal + daycream_subtotal + candles_subtotal;
	
}

function updateCleanser() {
	cleanser_subtotal = form.cleanser_quantity.value * cleanser_price;
	form.cleanser_subtotal.value = cleanser_subtotal;
}

function updateToner() {
	toner_subtotal = form.toner_quantity.value * toner_price;
	document.getElementById('toner_subtotal').value = toner_subtotal;
}

function updateMask() {
	mask_subtotal = form.mask_quantity.value * mask_price;
	document.getElementById('mask_subtotal').value = mask_subtotal;
}

function updateSerum() {
	serum_subtotal = form.serum_quantity.value * serum_price;
	document.getElementById('serum_subtotal').value = serum_subtotal;
}

function updateEyecream() {
	eyecream_subtotal = form.eyecream_quantity.value * eyecream_price;
	document.getElementById('eyecream_subtotal').value = eyecream_subtotal;
}
	
function updateFacecream() {
	facecream_subtotal = form.facecream_quantity.value * facecream_price;
	document.getElementById('facecream_subtotal').value = facecream_subtotal;
}

function updateDaycream() {
	daycream_subtotal = form.daycream_quantity.value * daycream_price;
	document.getElementById('daycream_subtotal').value = daycream_subtotal;
}

function updateCandles() {
	candles_subtotal = form.candles_quantity.value * candles_price;
	document.getElementById('candles_subtotal').value = candles_subtotal;
}