var priceDozen = 89.00;
var price_2_4_Dozen = 77.00;
var price_5_plus_Dozen = 70.00;
var priceSingle = 7.42;
var price_celebration_release_box = 17.00;
var price_jubilee_release_box = 35.00;
var price_gala_release_box_large = 25.00;
var price_gala_release_box_small = 20.00;
var price_polular_accordian_box_large = 25.00;
var price_polular_accordian_box_small = 20.00;

var priceSalesTax = 8.25;
var priceShipping = 43.00;

function calcPrice(){
	var dozens = 0;
	var dozens_2_4 = 0;
	var dozens_5_plus = 0;
	var singles = 0;
	var subtotal = 0;
	var salestax = 0;
	var total = 0;
	var shipping = 43.0;

	var celebration_release_boxes = 0;
	var jubilee_release_boxes = 0;
	var gala_release_box_larges = 0;
	var gala_release_box_smalls = 0;
	var polular_accordian_box_larges = 0;
	var polular_accordian_box_smalls = 0;

	//calculate 1 Dozen Monarch Butterflies
	dozens = document.frmOrder.product_11.value * priceDozen;
	subtotal = subtotal + dozens;
	document.getElementById("product_11_amount").innerHTML = formatCurrency(dozens);
	

	//calculate 2-4 Dozen Monarch Butterflies
	dozens_2_4 = document.frmOrder.product_12.value * price_2_4_Dozen;
	subtotal = subtotal + dozens_2_4;
	document.getElementById("product_12_amount").innerHTML = formatCurrency(dozens_2_4);


	//calculate 5+ Dozen Monarch Butterflies
	dozens_5_plus = document.frmOrder.product_13.value * price_5_plus_Dozen;
	subtotal = subtotal + dozens_5_plus;
	document.getElementById("product_13_amount").innerHTML = formatCurrency(dozens_5_plus);


	//calculate and display singles
	if(!document.frmOrder.product_14.value ==''){
		singles = document.frmOrder.product_14.value * priceSingle;
		document.getElementById("product_14_amount").innerHTML = formatCurrency(singles);
		subtotal = subtotal + singles;
	}


	//calculate and display Celebration Release Box
	if(document.frmOrder.product_15.value > 0 ){
		celebration_release_boxes = (document.frmOrder.product_15.value-1) * price_celebration_release_box;
		document.getElementById("product_15_amount").innerHTML = formatCurrency(celebration_release_boxes);
		subtotal = subtotal + celebration_release_boxes;
	}

	//calculate and display Jubilee release Box
	if(!document.frmOrder.product_16.value ==''){
		jubilee_release_boxes = document.frmOrder.product_16.value * price_jubilee_release_box;
		document.getElementById("product_16_amount").innerHTML = formatCurrency(jubilee_release_boxes);
		subtotal = subtotal + jubilee_release_boxes;
	}

	//calculate and display Gala Release Box - Large
	if(!document.frmOrder.product_17.value ==''){
		gala_release_box_larges = document.frmOrder.product_17.value * price_gala_release_box_large;
		document.getElementById("product_17_amount").innerHTML = formatCurrency(gala_release_box_larges);
		subtotal = subtotal + gala_release_box_larges;
	}

	//calculate and display Gala Release Box - Small
	if(!document.frmOrder.product_18.value ==''){
		gala_release_box_smalls = document.frmOrder.product_18.value * price_gala_release_box_small;
		document.getElementById("product_18_amount").innerHTML = formatCurrency(gala_release_box_smalls);
		subtotal = subtotal + gala_release_box_smalls;
	}

	//calculate and display Popular Accordion Box - Large
	if(!document.frmOrder.product_19.value ==''){
		polular_accordian_box_larges = document.frmOrder.product_19.value * price_polular_accordian_box_large;
		document.getElementById("product_19_amount").innerHTML = formatCurrency(polular_accordian_box_larges);
		subtotal = subtotal + polular_accordian_box_larges;
	}

	//calculate and display Popular Accordion Box - Small
	if(!document.frmOrder.product_20.value ==''){
		polular_accordian_box_smalls = document.frmOrder.product_20.value * price_polular_accordian_box_small;
		document.getElementById("product_20_amount").innerHTML = formatCurrency(polular_accordian_box_smalls);
		subtotal = subtotal + polular_accordian_box_smalls;
	}

	//display subtotal
	document.getElementById("ot_subtotal").innerHTML = formatCurrency(subtotal);

	//calculate and display sales tax
	if(document.frmOrder.order_from_ca.checked){
		salestax =  subtotal * priceSalesTax / 100;
		document.getElementById("ot_sales_tax").innerHTML = formatCurrency(salestax);
	}
	else{
		document.getElementById("ot_sales_tax").innerHTML = 0;
	}


	//check if delivery day is saturday
	if(document.frmOrder.event_date_w.value=="Sunday"){
		saturday_delivery = 12.50
		document.getElementById("saturday_delivery_amount").innerHTML = formatCurrency(saturday_delivery);
	}
	else{
		saturday_delivery = 0
		document.getElementById("saturday_delivery_amount").innerHTML = 0;
	}


	//calculate and display total
	total = subtotal + salestax + shipping + saturday_delivery;
	document.getElementById("ot_total").innerHTML = formatCurrency(total);

}

function checkPayment(){
	if(document.frmPayment.cc_number.value==""){
		alert("Please enter credit card number!")
		document.frmPayment.cc_number.focus();
		return false;
	}

	if(document.frmPayment.cc_expiry.value==""){
		alert("Please enter credit card expiration!")
		document.frmPayment.cc_expiry.focus();
		return false;
	}

	if(document.frmPayment.cc_type.options[document.frmPayment.cc_type.selectedIndex].value==""){
		alert("Please select credit card Type!")
		document.frmPayment.cc_type.focus();
		return false;
	}

	if(document.frmPayment.cc_owner.value==""){
		alert("Please enter name on the credit card!")
		document.frmPayment.cc_owner.focus();
		return false;
	}

	if(document.frmPayment.billing_address1.value==""){
		alert("Please enter billing address!")
		document.frmPayment.billing_address1.focus();
		return false;
	}

	if(document.frmPayment.billing_city.value==""){
		alert("Please enter billing city!")
		document.frmPayment.billing_city.focus();
		return false;
	}

	if(document.frmPayment.billing_state.options[document.frmPayment.billing_state.selectedIndex].value==""){
		alert("Please select billing state!")
		document.frmPayment.billing_state.focus();
		return false;
	}

	if(document.frmPayment.billing_zip.value==""){
		alert("Please enter billing zip!")
		document.frmPayment.billing_zip.focus();
		return false;
	}

	if(document.frmPayment.billing_phone.value==""){
		alert("Please enter billing phone!")
		document.frmPayment.billing_phone.focus();
		return false;
	}

	if(document.frmPayment.shipping_address1.value==""){
		alert("Please enter shipping address!")
		document.frmPayment.shipping_address1.focus();
		return false;
	}

	if(document.frmPayment.shipping_city.value==""){
		alert("Please enter shipping city!")
		document.frmPayment.shipping_city.focus();
		return false;
	}

	if(document.frmPayment.shipping_state.options[document.frmPayment.shipping_state.selectedIndex].value==""){
		alert("Please select shipping state!")
		document.frmPayment.shipping_state.focus();
		return false;
	}

	if(document.frmPayment.shipping_zip.value==""){
		alert("Please enter shipping zip!")
		document.frmPayment.shipping_zip.focus();
		return false;
	}

	if(document.frmPayment.shipping_phone.value==""){
		alert("Please enter shipping phone!")
		document.frmPayment.shipping_phone.focus();
		return false;
	}

	if(document.frmPayment.email.value==""){
		alert("Please Enter the email address!");
		document.frmPayment.email.focus();
		return false;
	}else{
		var email= new  String(document.frmPayment.email.value);
		var val1=email.indexOf("@");
		var val2=email.indexOf(".");
		if((val1==-1) || (val2==-1)){
			alert("Please Enter a valid email address!");
			document.frmPayment.email.focus();
			return false;
		}
	}
}

function sameAsBilling(){
	if(document.frmPayment.sameasbilling.checked){
		document.frmPayment.shipping_first_name.value=document.frmPayment.billing_first_name.value;
		document.frmPayment.shipping_last_name.value=document.frmPayment.billing_last_name.value;
		document.frmPayment.shipping_address1.value=document.frmPayment.billing_address1.value;
		document.frmPayment.shipping_address2.value=document.frmPayment.billing_address2.value;
		document.frmPayment.shipping_city.value=document.frmPayment.billing_city.value;
		document.frmPayment.shipping_state.value=document.frmPayment.billing_state.value;
		document.frmPayment.shipping_zip.value=document.frmPayment.billing_zip.value;
		document.frmPayment.shipping_phone.value=document.frmPayment.billing_phone.value;
	}
	else{
		document.frmPayment.shipping_first_name.value="";
		document.frmPayment.shipping_last_name.value="";
		document.frmPayment.shipping_address1.value="";
		document.frmPayment.shipping_address2.value="";
		document.frmPayment.shipping_city.value="";
		document.frmPayment.shipping_state.value="";
		document.frmPayment.shipping_zip.value="";
		document.frmPayment.shipping_phone.value="";
	}
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}