// JavaScript Document

function currency(value) {
  var currency_adjust = 1.0;    // CDN rate
	var result=Math.round(currency_adjust*value*100)/100
	return result;
}

function get_pocket_value()
{
	for (var i=0; i < document.order_form.pocket.length; i++)
	{
		if (document.order_form.pocket[i].checked)
		{
			return document.order_form.pocket[i].value;
		}
	}
}

var base_price = new Array();
var price_increment = new Array();
init_prices ();

function init_prices ()
{
	// main item prices
	base_price['signature'] = 100.00;
	base_price['contemporary'] = 75.00;
	base_price['inserts'] = 50.00;
	base_price['insert_rsvp'] = 35.00;
	base_price['insert_map'] = 35.00;
	base_price['acc_seating'] = 25.00;
	base_price['acc_table'] = 25.00;
	base_price['acc_menu'] = 25.00;
	base_price['acc_tag'] = 5.00;
	base_price['acc_advice'] = 15.00;
	base_price['acc_save_the_date'] = 35.00;  
	
	price_increment['signature'] = 4.00;
	price_increment['contemporary'] = 2.75;
	price_increment['inserts'] = 0.65;
	price_increment['insert_rsvp'] = 0.50;
	price_increment['insert_map'] = 0.40;
	price_increment['acc_seating'] = 1.00;
	price_increment['acc_table'] = 3.00;
	price_increment['acc_menu'] = 0.40;
	price_increment['acc_tag'] = 0.25;
	price_increment['acc_advice'] = 0.40;
	price_increment['acc_save_the_date'] = 0.65;  
}

function priceAdjust ()
{
	var quantity = document.order_form.invitation_count.value;
	var pocket_type = get_pocket_value();
	var total_price = (quantity > 0) ? base_price[pocket_type] + quantity * price_increment[pocket_type] : 0.00;
	if (document.order_form.insert_rsvp.checked && (quantity > 0)) 
	{
		total_price += base_price['insert_rsvp'] + quantity * price_increment['insert_rsvp'];
	}
	if (document.order_form.insert_map.checked && (quantity > 0))
	{
		total_price += base_price['insert_map'] + quantity * price_increment['insert_map'];
	}
	if (document.order_form.acc_seating.value > 0)
	{
		total_price += base_price['acc_seating'] + document.order_form.acc_seating.value * price_increment['acc_seating'];
	}
	if (document.order_form.acc_table.value > 0)
	{
		total_price += base_price['acc_table'] + document.order_form.acc_table.value * price_increment['acc_table'];
	}
	if (document.order_form.acc_menu.value > 0)
	{
		total_price += base_price['acc_menu'] + document.order_form.acc_menu.value * price_increment['acc_menu'];
	}
	if (document.order_form.acc_tag.value > 0)
	{
		total_price += base_price['acc_tag'] + document.order_form.acc_tag.value * price_increment['acc_tag'];
	}
	if (document.order_form.acc_advice.value > 0)
	{
		total_price += base_price['acc_advice'] + document.order_form.acc_advice.value * price_increment['acc_advice'];
	}
	if (document.order_form.acc_save_the_date.value > 0)
	{
		total_price += base_price['acc_save_the_date'] + document.order_form.acc_save_the_date.value * price_increment['acc_save_the_date'];
	}
		
	// round off the total price
	total_price = Math.round(total_price*100)/100;
	//setInnerText("price", total_price);
	var discounted_price = 0;
	if (sale & (sale_percentage[pocket_type] > 0))
	{
		discounted_price = Math.round ((100.0 - sale_percentage[pocket_type]) * total_price) / 100;
		document.getElementById("tot_price").innerHTML = "<strike>" + total_price + "</strike> <span class='discount'>" + discounted_price + "</span>"; 
		if (document.order_form.quoted_price)
		{
			document.order_form.quoted_price.value = discounted_price;
		}
	}
	else
	{
		document.getElementById("tot_price").innerHTML = total_price; 
		if (document.order_form.quoted_price)
		{
			document.order_form.quoted_price.value = total_price;
		}
	}
}
