<!--
//
// these functions are used to associate pricing with quantity.
// a table associating price to quantity is presented in comments
// in each function.  since the lists are small and pricing may change
// arrays were not selected.
//

// this tallys the final order cost
// (to reinstate shipping cost uncomment below)
function totalCost() {
var tdcost=document.getElementById('templtdgn');
var cdcost=document.getElementById('customdgn');
var plcost=document.getElementById('plcost');
var excost=document.getElementById('extrascost');
var ckcost=document.getElementById('cakecost');
var orderCost=document.getElementById('ordercost');
//var shipCost=document.getElementById('shipping');
var salesTax=document.getElementById('salestax');
var finalCost=document.getElementById('finalcost');
var c,t,sh;
	c = parseFloat(tdcost.value) +
			parseFloat(cdcost.value) +
				parseFloat(plcost.value) +
					parseFloat(excost.value) +
						parseFloat(ckcost.value);
	orderCost.value = c.toFixed(2);
	t = c * 0.085;
	salesTax.value = t.toFixed(2);
//	sh = 12.00;
//	shipCost.value = sh.toFixed(2);
	c = c + t; // + sh;
	finalCost.value = c.toFixed(2);
}

// this tallys the cost of the cake design chosen
// (template vs custom)
function design() {
var td=document.getElementById('templtdgn');
var cd=document.getElementById('customdgn');
var pl=document.getElementById('plcost');
var x;
	if(document.cakeform.designtype[0].checked) {
		x = 150;
		td.value = x.toFixed(2);
		x = 0;
		cd.value = x.toFixed(2);
	}
	if(document.cakeform.designtype[1].checked) {
		x = 0;
		td.value = x.toFixed(2);
		x = 250;
		cd.value = x.toFixed(2);
	}
	x = 50;
	pl.value = x.toFixed(2);
	totalCost();
}

// this tallys the Extras cost
function extrasCost() {
var c1=document.getElementById('inv1cost');
var c2=document.getElementById('inv2cost');
var c3=document.getElementById('gblocost');
var c4=document.getElementById('gblcost');
var c5=document.getElementById('tuccost');
var excost=document.getElementById('extrascost');
var c;
	c = parseFloat(c1.value) +
			parseFloat(c2.value) +
				parseFloat(c3.value) +
					parseFloat(c4.value) +
						parseFloat(c5.value);
	excost.value = c.toFixed(2);
	totalCost();
}

// this tallys cost of invitations selected
// One-Sided Invitation Price List:
//    0         $0.00/ea
//    10 - 25   $1.90/ea
//    26 - 99   $1.70/ea
//    100 - 250 $1.50/ea
// Two-Sided Invitation Price List:
//    0         $0.00/ea
//    10 - 25   $2.90/ea
//    26 - 99   $2.70/ea
//    100 - 250 $2.50/ea
function invites(sides) {
var qty1=document.getElementById('inv1qty');
var cost1=document.getElementById('inv1cost');
var qty2=document.getElementById('inv2qty');
var cost2=document.getElementById('inv2cost');
var c,q;
	if(sides == 1) {
		q = parseInt(qty1.value);
	} else {
		q = parseInt(qty2.value);
	}
	if(q == 0) {
		c = 0;
	} else
		if(q < 10) {
			alert("Must order at least 10 invitations");
			return false;
	} else
		if(q > 250) {
			alert("Can order no more than 250 invitations");
			return false;
	}
	if(sides == 1) {
		if((10 <= q) && (q <= 25))   c = q * 1.90;
		if((26 <= q) && (q <= 99))   c = q * 1.70;
		if((100 <= q) && (q <= 250)) c = q * 1.50;
		cost1.value = c.toFixed(2);
		c = 0;
		cost2.value = c.toFixed(2);
		qty2.value = c.toFixed(0);
	} else {
		if((10 <= q) && (q <= 25))   c = q * 2.90;
		if((26 <= q) && (q <= 99))   c = q * 2.70;
		if((100 <= q) && (q <= 250)) c = q * 2.50;
		cost2.value = c.toFixed(2);
		c = 0;
		cost1.value = c.toFixed(2);
		qty1.value = c.toFixed(0);
	}
	extrasCost();
}

// this tallys cost of Goody Bag Labels only
// Goody Bag Label-Only Price List:
//    0         $0.00/ea
//    10 - 25   $1.50/ea
//    26 - 99   $1.40/ea
//    100 - 250 $1.30/ea
// Goody Bag w/Labels Price List:
//    0         $0.00/ea
//    10 - 25   $4.50/ea
//    26 - 99   $4.40/ea
//    100 - 250 $4.30/ea
function goodybag() {
var gbloq=document.getElementById('gbloqty');
var gbloc=document.getElementById('gblocost');
var gblq=document.getElementById('gblqty');
var gblc=document.getElementById('gblcost');
var c,q;
	q = parseInt(gbloq.value);
	if(q == 0) c = 0;
	if(q > 0) {
		if(q < 10) {
			alert("Must order at least 10 Goody Bag labels");
		}
		if(q > 250) {
			alert("Can order no more than 250 Goody Bag labels");
		}
		if((10 <= q) && (q <= 25))   c = q * 1.50;
		if((26 <= q) && (q <= 99))   c = q * 1.40;
		if((100 <= q) && (q <= 250)) c = q * 1.30;
	}
	gbloc.value = c.toFixed(2);
	q = parseInt(gblq.value);
	if(q == 0) c = 0;
	if(q > 0) {
		if(q < 10) {
			alert("Must order at least 10 Goody Bags");
		}
		if(q > 250) {
			alert("Can order no more than 250 Goody Bags");
		}
		if((10 <= q) && (q <= 25))   c = q * 4.50;
		if((26 <= q) && (q <= 99))   c = q * 4.40;
		if((100 <= q) && (q <= 250)) c = q * 4.30;
	}
	gblc.value = c.toFixed(2);
	extrasCost();
}

// this tallys cost of Thank You cards selected
// Thank You Card Price List:
//    0         $0.00/ea
//    10 - 25   $1.80/ea
//    26 - 99   $1.70/ea
//    100 - 250 $1.60/ea
function tucards() {
var qty=document.getElementById('tucqty');
var cost=document.getElementById('tuccost');
var c,q;
	q = parseInt(qty.value);
	if(q == 0) c = 0;
	if(q > 0) {
		if(q < 10) {
			alert("Must order at least 10 Thank You cards");
		}
		if(q > 250) {
			alert("Can order no more than 250 Thank You cards");
		}
		if((10 <= q) && (q <= 25))   c = q * 1.80;
		if((26 <= q) && (q <= 99))   c = q * 1.70;
		if((100 <= q) && (q <= 250)) c = q * 1.60;
	}
	cost.value = c.toFixed(2);
	extrasCost();
}

// this tallys cost of cake size selected
function cakesz() {
// Personalized Birthday Cake Price List:
//  Round Cake  $49.75
//  1/4 Sheet   $70.00
//  1/2 Sheet  $105.00
//  3/4 Sheet  $130.50
//  Full Sheet $160.50
var list=document.getElementById('cakesize');
var s=list.options[list.selectedIndex];
var cost=document.getElementById('cakecost');
var c;
	if(s.value == 'Select Cake Size') c = 0.00;
	if(s.value == 'Round Cake (8 - 12 slices)')  c = 49.75;
	if(s.value == '1/4 sheet (20 - 24 slices)')  c = 70.00;
	if(s.value == '1/2 sheet (40 - 48 slices)')  c = 105.00;
	if(s.value == '3/4 sheet (60 - 72 slices)')  c = 130.50;
	if(s.value == 'Full sheet (80 - 98 slices)') c = 160.50;
	cost.value = c.toFixed(2);
	totalCost();
}

function validateFields() {
  if (document.cakeform.first_name.value == '') {
    alert('A first name is required.\nPlease enter your first name.');
    return false;
  }
  x = /^[A-Za-z\-\ ]{1,}$/;
  if (!x.test(document.cakeform.first_name.value)) {
    alert('First name contains invalid characters.\nPlease re-enter your first name.');
    return false;
  }
  if (document.cakeform.last_name.value == '') {
    alert('A last name is required.\nPlease enter your last name.');
    return false;
  }
  x = /^[A-Za-z\-\ \.\,]{1,}$/;
  if (!x.test(document.cakeform.last_name.value)) {
    alert('Last name contains invalid characters.\nPlease re-enter your last name.');
    return false;
  }
  if (document.cakeform.street.value == '') {
    alert('A street address is required.\nPlease enter your street address.');
    return false;
  }
  if (document.cakeform.city.value == '') {
    alert('A city is required\nPlease enter your city');
    return false;
  }
  x = /^[A-Za-z\ ]{1,}$/;
  if (!x.test(document.cakeform.city.value)) {
    alert('City contains invalid characters\nPlease re-enter your city name');
    return false;
  }
  if (document.cakeform.state.options[0].selected) {
    alert('You must select a state\nPlease select your state from the list');
    return false;
  }
  if (document.cakeform.zipcode.value == '') {
    alert('We must have your zip code\nPlease enter your zip code');
    return false;
  }
  x = /^[\-\ \w]{1,}$/;
  if (!x.test(document.cakeform.zipcode.value)) {
    alert('Zip codes may contain letters, digits, and the - character\nPlease re-enter your zip code');
    return false;
  }
  if (document.cakeform.email.value == '') {
    alert('We need an email address.\nPlease enter your email address.');
    return false;
  }
  // the email filter below only confirms a '@' and a '.xxxxxx' TLD name.
  x = /^[\.\-\_\w]{1,}\@[\-\_\w]{1,}\.[A-Za-z]{2,6}$/;
  if (!x.test(document.cakeform.email.value)) {
    alert('Valid email addresses must contain an @ character.\nas well as a top-level domain name, such as .com, .net, ...\nPlease re-enter your email address.');
    return false;
  }
  if (document.cakeform.phone.value == '') {
    alert('We need a phone number for you.\nPlease enter your phone number.');
    return false;
  }
  // the phone number filter below accounts for international phone numbers in addition to
  // U.S. numbers, which range over several formats.  the filter confirms a number with only
  // '(', ')', '-', '+', and the digits 0 - 9.
  x = /^[\(\)\-\ \+\d]{1,}$/;
  if (!x.test(document.cakeform.phone.value)) {
    alert('A phone number can have (, ), -, +, and digits.\nand should include an area code, if applicable.\nPlease re-enter your phone number.');
    return false;
  }
  if (!document.cakeform.designtype[0].checked && 
      !document.cakeform.designtype[1].checked) {
	alert('We need to know what type of cake design you prefer.\nPlease select either a template or custom design.');
    return false;
  }
  if (document.cakeform.cakesize[0].selected) {
	alert('We need to know the size of cake you prefer.\nPlease select a cake size.');
    return false;
  }
  if (document.cakeform.cakeflavor[0].selected) {
	alert('We need to know the flavor of cake you prefer.\nPlease select a cake flavor.');
    return false;
  }
  if (document.cakeform.cakefilling[0].selected) {
	alert('We need to know the filling of cake you prefer.\nPlease select a cake filling.');
    return false;
  }
  inv1=document.getElementById('inv1qty');
  infr=document.getElementById('invitefront');
  inv2=document.getElementById('inv2qty');
  inba=document.getElementById('inviteback');
  if (document.cakeform.caketext.value == '') {
	alert('You have specified no text for the top of the cake.\nWe create no-text cakes but if this is an error\nplease contact us.');
  }
  if (parseInt(inv1.value) && (infr.value == '')) {
	alert('Since you ordered one-sided invitations we need to know what to put on them.\nPlease specify text for the front of the invitations.');
    return false;
  }
  if (parseInt(inv2.value) && (inba.value == '')) {
	alert('Since you ordered two-sided invitations we need to know what to put on them.\nPlease specify text for both the front and back of the invitations.');
    return false;
  }
  return true;
}
//-->
