/*
 * This file contains commonly used Javascript code for the online shopping cart.
 */

/*
 * Function:  CheckFabricAmt
 *
 * This function first creates the amount of fabric that the user entered by combining
 * the whole yardage with the fractional yardage.  It then ensures that the amount entered
 * meets the minimum yardage requirement.
 *
 * whole - the form field whose value contains the whole yardage amount that the user entered
 * fraction - the form field whose value contains the fractional amount that the user entered
 * amount - the form field whose value will contain the yardage amount
 */

function CheckFabricAmt(whole, fraction, amount)
{

	/* To change the minimum yardage that can be ordered, change the value of min_yardage */

	min_yardage = "1/2"

	amount.value = (whole.value * 1) + (eval(fraction.value) * 1)


	/* If the whole number is zero, don't print it.  Otherwise add a blank (to go between the whole number and the fraction). */

	if ( (whole.value * 1) == 0)
	{
		print_whole = ""
	}
	else
	{
		print_whole = whole.value + " "
	}

	if (amount.value < (eval(min_yardage) * 1))
	{
		alert("The yardage amount entered [" + print_whole + fraction.value + "] is less than the minimum [" + min_yardage + "] that can be ordered.")
		return false
	}


} /* End of CheckFabricAmt() */

/*
 * Function:  isDollarAmount
 *
 * Returns true if there is at least one character and all characters are 0-9.
 * Also verifies that if there is a decimal point, there is only one decimal point
 * and that there are exactly two digits after the decimal point.
 * Returns false otherwise.
 */

function isDollarAmount(Amount)
{
	/* Check if there is at least one character */
	
	if (Amount == "")
	{
		return false
	}

	decimal_point = 0
	decimal_point_location = 0
	
	/*
	 * Check each character in turn and verify it is 0-9.
	 * Also, make sure there is at most one decimal point.
	 */
	
	for (i=0; i < Amount.length; i++)
	{

		if (Amount.charAt(i) == '.')
		{

			if (decimal_point == 1)
			{
				return false
			}

			decimal_point_location = i
			decimal_point = 1
			continue
		}

		if (Amount.charAt(i) < '0')
		{
			return false
		}
		
		if (Amount.charAt(i) > '9')
		{
			return false
		}
	}

	/* Make sure there are exactly two digits after the decimal point if the decimal point exists */

	if (decimal_point == 1)
	{

		if ((decimal_point_location + 3) != Amount.length)
		{
			return false
		}
	}
		
	/* It's a valid number */
	
	return true

} /* End of isDollarAmount() */


/*
 * Function:  ValGiftCertificate()
 *
 * This function validates the user-entered gift certificate parameters and creates the product description to be used by the shopping cart
 * using the user-entered From and To names.
 *
 * FromName - the name of the person who is giving the gift certificate
 * ToName - the name of the person who is receiving the gift certificate
 * Amount - the amount of the gift certificate
 * Description - this is the customized description that appears in the description.  Note that if you want the description created here to be the complete description,
 * then the description in the "item" hidden variable must be blank.  If you include text in that variable, the description created here will be appended to it.
 */

function ValGiftCertificate(From, To, Amount, Description)
{

	/*
	 * First check to see if the entered dollar amount is valid.
	 */

	if (!isDollarAmount(Amount))
	{
		alert("Invalid dollar amount entered.  Enter at least one digit, all digits must be 0-9, and there can be at most one decimal point.  If a decimal point is used, ensure there are two digits after it.")
		return false
	}

	/*
	 * Ensure the amount is non-zero.
	 */

	if (Amount == 0)
	{
		alert("The dollar amount entered is zero.")
		return false
	}

	/*
	 * Ensure From and To are not blank.  No checking is done on the characters entered.
	 */

	if (From == "")
	{
		alert("The name of the party who is giving the gift certificate must be entered.")
		return false
	}

	if (To == "")
	{
		alert("The name of the party who is receiving the gift certificate must be entered.")
		return false
	}

	/* Create the description of the product */

	Description.value = "Gift Certificate from " + From + " to " + To

	return true

} /* End of ValGiftCertificate() */


/*
 * Function:  ValQuiltersSignCustom()
 *
 * This function simply checks that the custom text has a non-blank value.  The form enforces a maximum length and there is
 * no restriction on what characters are entered.
 *
 */

function ValQuiltersSignCustom(Text)
{

	/* First check to see if there is text entered. */

	if (Text.value == "")
	{
		alert("Text must be entered.")
		return false
	}

	/* Ensure that there is at least one non-blank character. */

	for ( i = 0; i < Text.value.length; i++ )
	{
		if (Text.value[i] != ' ')
		{
			return true
		}
	}

	/* Only blank characters were found. */

	return false

} /* End of ValQuiltersSignCustom() */

/*
 * Function:  ValLeader()
 *
 * This function calculates the number of 18" and number of 24" sections needed given the number of leaders the customer wants
 * and the length of each leader.
 *
 * NumRollers - the number of rollers on the Longarm/Midarm frame.  It's the same as the number of leaders that will be required.
 *
 * LeaderLength - the length of the leader.  Each leader is the same length.
 *
 */

function ValLeader(NumRollers, LeaderLength)
{

	/*
	 * Determine number of 18" and 24" sections for a single leader given its length.
	 */

	switch (LeaderLength * 1)
	{

		case 60:
			Num18Inch = 2
			Num24Inch = 1
			break;

		case 66:
			Num18Inch = 1
			Num24Inch = 2
			break;

		case 72:
			Num18Inch = 0
			Num24Inch = 3
			break;

		case 78:
			Num18Inch = 3
			Num24Inch = 1
			break;

		case 84:
			Num18Inch = 2
			Num24Inch = 2
			break;

		case 90:
			Num18Inch = 1
			Num24Inch = 3
			break;

		case 96:
			Num18Inch = 0
			Num24Inch = 4
			break;

		case 102:
			Num18Inch = 3
			Num24Inch = 2
			break;

		case 108:
			Num18Inch = 2
			Num24Inch = 3
			break;

		case 114:
			Num18Inch = 1
			Num24Inch = 4
			break;

		case 120:
			Num18Inch = 0
			Num24Inch = 5
			break;

		case 126:
			Num18Inch = 3
			Num24Inch = 3
			break;

		case 132:
			Num18Inch = 2
			Num24Inch = 4
			break;

		case 138:
			Num18Inch = 1
			Num24Inch = 5
			break;

		case 144:
			Num18Inch = 0
			Num24Inch = 6
			break;

		case 150:
			Num18Inch = 3
			Num24Inch = 4
			break;

		case 156:
			Num18Inch = 2
			Num24Inch = 5
			break;

		case 162:
			Num18Inch = 1
			Num24Inch = 6
			break;

		default:
			break;

	}

	/*
	 * Calculate the total number of sections needed.
	 */

	TotalNum18Inch = Num18Inch * NumRollers
	TotalNum24Inch = Num24Inch * NumRollers

	x = document.getElementById('Num18InchSections')
 	if (x.firstChild)
 	{
 		x.removeChild(x.firstChild)
	}

	y=document.createTextNode(Num18Inch)
 	x.appendChild(y)

	x = document.getElementById('Num24InchSections')
 	if (x.firstChild)
 	{
 		x.removeChild(x.firstChild)
	}

	y=document.createTextNode(Num24Inch)
 	x.appendChild(y)

	return false

} /* End of ValLeader() */


/*
 * Function:  showbatik()
 *
 * This function takes, as input, two parameters:
 *
 * Parameter 1:  color
 * Parameter 2:  the id of an image
 *
 * The color is the color of the fabric (a Hoffman Batik) and the image is of the fabric for that color.
 * When a color is selected from a drop-down menu, this function gets called to change the image to the image
 * of the Batik for that fabric.
 */

function showbatik(color, imageid)
{

	/*
	 * Where to find the image files.
	 */

	basedir = "http://www.quiltersparadiseesc.com/Online Shopping/Fabrics/Hoffman Batik 1895/"

	/*
	 * Find the image to be changed.
	 */

	x = document.getElementById(imageid)

	/*
	 * There is a case statement for every 1895 fabric.
	 */

	filename = ""

	switch (color)
	{

	case "Acapulco":  filename = "1895-370-Acapulco.jpg";  break;
	case "Adobe":  filename = "1895-100-Adobe.jpg";  break;
	case "Agate":  filename = "1895-235-Agate.jpg";  break;
	case "Amber":  filename = "1895-36-Amber.jpg";  break;
	case "Amethist":  filename = "1895-91-Amethist.jpg";  break;
	case "Apricot":  filename = "1895-198-Apricot.jpg";  break;
	case "Aruba":  filename = "1895-371-Aruba.jpg";  break;
	case "Aspen":  filename = "1895-367-Aspen.jpg";  break;
	case "Aventurine":  filename = "1895-237-Aventurine.jpg";  break;
	case "Azure":  filename = "1895-1-Azure.jpg";  break;
	case "Bamboo":  filename = "1895-495-Bamboo.jpg";  break;
	case "Barbados":  filename = "1895-506-Barbados.jpg";  break;
	case "Barbie":  filename = "1895-326-Barbie.jpg";  break;
	case "Barn Red":  filename = "1895-83-Barn Red.jpg";  break;
	case "Belize":  filename = "1895-362-Belize.jpg";  break;
	case "Bergen":  filename = "1895-328-Bergen.jpg";  break;
	case "Bettafish":  filename = "1895-322-Bettafish.jpg";  break;
	case "Biscotti":  filename = "1895-414-Biscotti.jpg";  break;
	case "Black":  filename = "1895-4-Black.jpg";  break;
	case "Blonde Ale":  filename = "1895-199-Blonde Ale.jpg";  break;
	case "Blossom":  filename = "1895-448-Blossom.jpg";  break;
	case "Blue Jay":  filename = "1895-261-Blue Jay.jpg";  break;
	case "Bluebird":  filename = "1895-301-Bluebird.jpg";  break;
	case "Bluff":  filename = "1895-511-Bluff.jpg";  break;
	case "Blush":  filename = "1895-391-Blush.jpg";  break;
	case "Boardwalk":  filename = "1895-487-Boardwalk.jpg";  break;
	case "Bonsai":  filename = "1895-433-Bonsai.jpg";  break;
	case "Breeze":  filename = "1895-492-Breeze.jpg";  break;
	case "Brooke":  filename = "1895-329-Brooke.jpg";  break;
	case "Brownie":  filename = "1895-386-Brownie.jpg";  break;
	case "Bubblegum":  filename = "1895-404-Bubblegum.jpg";  break;
	case "Burgundy":  filename = "1895-38-Burgundy.jpg";  break;
	case "Buttercream":  filename = "1895-412-Buttercream.jpg";  break;
	case "Buttercup":  filename = "1895-471-Buttercup.jpg";  break;
	case "Cabana":  filename = "1895-490-Cabana.jpg";  break;
	case "Cabo":  filename = "1895-361-Cabo.jpg";  break;
	case "Cairo":  filename = "1895-357-Cairo.jpg";  break;
	case "Camellia":  filename = "1895-218-Camellia.jpg";  break;
	case "Cancun":  filename = "1895-248-Cancun.jpg";  break;
	case "Cardinal":  filename = "1895-292-Cardinal.jpg";  break;
	case "Caterpillar":  filename = "1895-269-Caterpillar.jpg";  break;
	case "Cayenne":  filename = "1895-431-Cayenne.jpg";  break;
	case "Celadon":  filename = "1895-105-Celadon.jpg";  break;
	case "Ceylon":  filename = "1895-421-Ceylon.jpg";  break;
	case "Chai Tea":  filename = "1895-415-Chai Tea.jpg";  break;
	case "Chameleon":  filename = "1895-315-Chameleon.jpg";  break;
	case "Chamomile":  filename = "1895-418-Chamomile.jpg";  break;
	case "Champagne":  filename = "1895-385-Champagne.jpg";  break;
	case "Charcoal":  filename = "1895-55-Charcoal.jpg";  break;
	case "Cheddar":  filename = "1895-177-Cheddar.jpg";  break;
	case "Chestnut":  filename = "1895-51-Chestnut.jpg";  break;
	case "Chilies":  filename = "1895-444-Chilies.jpg";  break;
	case "Christmas Green":  filename = "1895-189-Christmas Green.jpg";  break;
	case "Citrine":  filename = "1895-232-Citrine.jpg";  break;
	case "Clove":  filename = "1895-430-Clove.jpg";  break;
	case "Clownfish":  filename = "1895-316-Clownfish.jpg";  break;
	case "Cobalt":  filename = "1895-17-Cobalt.jpg";  break;
	case "Coconut":  filename = "1895-502-Coconut.jpg";  break;
	case "Copacabana":  filename = "1895-509-Copacabana.jpg";  break;
	case "Coral Gables":  filename = "1895-368-Coral Gables.jpg";  break;
	case "Cornflower":  filename = "1895-451-Cornflower.jpg";  break;
	case "Cotton Candy":  filename = "1895-482-Cotton Candy.jpg";  break;
	case "Cream":  filename = "1895-33-Cream.jpg";  break;
	case "Creamsicle":  filename = "1895-480-Creamsicle.jpg";  break;
	case "Crocodile":  filename = "1895-279-Crocodile.jpg";  break;
	case "Crocus":  filename = "1895-438-Crocus.jpg";  break;
	case "Crystal":  filename = "1895-330-Crystal.jpg";  break;
	case "Curry":  filename = "1895-26-Curry.jpg";  break;
	case "Daffodil":  filename = "1895-110-Daffodil.jpg";  break;
	case "Delft":  filename = "1895-243-Delft.jpg";  break;
	case "Dewdrop":  filename = "1895-462-Dewdrop.jpg";  break;
	case "Dijon":  filename = "1895-432-Dijon.jpg";  break;
	case "Dragonfly":  filename = "1895-324-Dragonfly.jpg";  break;
	case "Dublin":  filename = "1895-252-Dublin.jpg";  break;
	case "Dune":  filename = "1895-454-Dune.jpg";  break;
	case "Dusty Pink":  filename = "1895-D12-Dusty Pink.jpg";  break;
	case "EarlGrey":  filename = "1895-410-EarlGrey.jpg";  break;
	case "Earth":  filename = "1895-58-Earth.jpg";  break;
	case "Eggplant":  filename = "1895-34-Eggplant.jpg";  break;
	case "Evergreen":  filename = "1895-166-Evergreen.jpg";  break;
	case "Fern":  filename = "1895-220-Fern.jpg";  break;
	case "Flame":  filename = "1895-67-Flame.jpg";  break;
	case "Flamingo":  filename = "1895-264-Flamingo.jpg";  break;
	case "Flax":  filename = "1895-442-Flax.jpg";  break;
	case "Fog":  filename = "1895-483-Fog.jpg";  break;
	case "Fox":  filename = "1895-293-Fox.jpg";  break;
	case "Frank":  filename = "1895-349-Frank.jpg";  break;
	case "Frog":  filename = "1895-303-Frog.jpg";  break;
	case "Funnel Cake":  filename = "1895-485-Funnel Cake.jpg";  break;
	case "Gardenia":  filename = "1895-500-Gardenia.jpg";  break;
	case "Garlic":  filename = "1895-435-Garlic.jpg";  break;
	case "Garnet":  filename = "1895-231-Garnet.jpg";  break;
	case "Gecko":  filename = "1895-321-Gecko.jpg";  break;
	case "Grape":  filename = "1895-N45-Grape.jpg";  break;
	case "Grape Juice":  filename = "1895-382-Grape Juice.jpg";  break;
	case "Grasshopper":  filename = "1895-202-Grasshopper.jpg";  break;
	case "Grizzly":  filename = "1895-260-Grizzly.jpg";  break;
	case "Guava":  filename = "1895-497-Guava.jpg";  break;
	case "H2O":  filename = "1895-203-H20.jpg";  break;
	case "Hamster":  filename = "1895-281-Hamster.jpg";  break;
	case "Harvest":  filename = "1895-116-Harvest.jpg";  break;
	case "Havana":  filename = "1895-253-Havana.jpg";  break;
	case "Herb":  filename = "1895-331-Herb.jpg";  break;
	case "Hibiscus":  filename = "1895-519-Hibiscus.jpg";  break;
	case "Hippo":  filename = "1895-270-Hippo.jpg";  break;
	case "Hollyhock":  filename = "1895-465-Hollyhock.jpg";  break;
	case "Hollywood":  filename = "1895-363-Hollywood.jpg";  break;
	case "Honey":  filename = "1895-118-Honey.jpg";  break;
	case "Honeysuckle":  filename = "1895-221-Honeysuckle.jpg";  break;
	case "Hunter":  filename = "1895-60-Hunter.jpg";  break;
	case "Hyacinth":  filename = "1895-120-Hyacinth.jpg";  break;
	case "Hydrangea":  filename = "1895-222-Hydrangea.jpg";  break;
	case "Ice":  filename = "1895-176-Ice.jpg";  break;
	case "Iced Tea":  filename = "1895-420-Iced Tea.jpg";  break;
	case "Iguana":  filename = "1895-273-Iguana.jpg";  break;
	case "Iris":  filename = "1895-40-Iris.jpg";  break;
	case "Jade":  filename = "1895-29-Jade.jpg";  break;
	case "Jelly":  filename = "1895-378-Jelly.jpg";  break;
	case "Julie":  filename = "1895-332-Julie.jpg";  break;
	case "Juneau":  filename = "1895-247-Juneau.jpg";  break;
	case "Jungle":  filename = "1895-69-Jungle.jpg";  break;
	case "Jute":  filename = "1895-517-Jute.jpg";  break;
	case "Kashmir":  filename = "1895-251-Kashmir.jpg";  break;
	case "Kelly":  filename = "1895-354-Kelly.jpg";  break;
	case "Key Lime":  filename = "1895-481-Key Lime.jpg";  break;
	case "Khaki":  filename = "1895-49-Khaki.jpg";  break;
	case "Koi":  filename = "1895-277-Koi.jpg";  break;
	case "Lagoon":  filename = "1895-503-Lagoon.jpg";  break;
	case "Lapis":  filename = "1895-123-Lapis.jpg";  break;
	case "Latte":  filename = "1895-205-Latte.jpg";  break;
	case "Lavender":  filename = "1895-70-Lavender.jpg";  break;
	case "Leaf":  filename = "1895-178-Leaf.jpg";  break;
	case "Lilac":  filename = "1895-30-Lilac.jpg";  break;
	case "Lilikoi":  filename = "1895-505-Lilikoi.jpg";  break;
	case "Lilly":  filename = "1895-352-Lilly.jpg";  break;
	case "Lime":  filename = "1895-71-Lime.jpg";  break;
	case "Lion":  filename = "1895-259-Lion.jpg";  break;
	case "Liquorice":  filename = "1895-440-Liquorice.jpg";  break;
	case "Lizard":  filename = "1895-282-Lizard.jpg";  break;
	case "London":  filename = "1895-242-London.jpg";  break;
	case "Lotus":  filename = "1895-459-Lotus.jpg";  break;
	case "Lucy":  filename = "1895-348-Lucy.jpg";  break;
	case "Macaw":  filename = "1895-31-Macaw.jpg";  break;
	case "Magenta":  filename = "1895-72-Magenta.jpg";  break;
	case "Mallard":  filename = "1895-272-Mallard.jpg";  break;
	case "Manatee":  filename = "1895-320-Manatee.jpg";  break;
	case "Marlin":  filename = "1895-27-Marlin.jpg";  break;
	case "Marmalade":  filename = "1895-416-Marmalade.jpg";  break;
	case "Marsala":  filename = "1895-423-Marsala.jpg";  break;
	case "Merlot":  filename = "1895-394-Merlot.jpg";  break;
	case "Midnight":  filename = "1895-128-Midnight.jpg";  break;
	case "Mimosa":  filename = "1895-384-Mimosa.jpg";  break;
	case "Mink":  filename = "1895-308-Mink.jpg";  break;
	case "Mint":  filename = "1895-74-Mint.jpg";  break;
	case "Mocha":  filename = "1895-171-Mocha.jpg";  break;
	case "Monaco":  filename = "1895-369-Monaco.jpg";  break;
	case "Monstera":  filename = "1895-498-Monstera.jpg";  break;
	case "Montego":  filename = "1895-504-Montego.jpg";  break;
	case "Mulberry":  filename = "1895-428-Mulberry.jpg";  break;
	case "Nasturium":  filename = "1895-469-Nasturium.jpg";  break;
	case "Navy":  filename = "1895-19-Navy.jpg";  break;
	case "New Grass":  filename = "1895-N115-New Grass.jpg";  break;
	case "Nutmeg":  filename = "1895-168-Nutmeg.jpg";  break;
	case "Oprah":  filename = "1895-333-Oprah.jpg";  break;
	case "Orange":  filename = "1895-13-Orange.jpg";  break;
	case "Orchid":  filename = "1895-223-Orchid.jpg";  break;
	case "Oregano":  filename = "1895-426-Oregano.jpg";  break;
	case "Palomino":  filename = "1895-267-Palomino.jpg";  break;
	case "Paprika":  filename = "1895-389-Paprika.jpg";  break;
	case "Paradise":  filename = "1895-512-Paradise.jpg";  break;
	case "Parakeet":  filename = "1895-271-Parakeet.jpg";  break;
	case "Parchment":  filename = "1895-134-Parchment.jpg";  break;
	case "Paris":  filename = "1895-244-Paris.jpg";  break;
	case "Passion Tea":  filename = "1895-419-Passion Tea.jpg";  break;
	case "Patty":  filename = "1895-355-Patty.jpg";  break;
	case "Peacock":  filename = "1895-136-Peacock.jpg";  break;
	case "Pearl":  filename = "1895-137-Pearl.jpg";  break;
	case "Pebble":  filename = "1895-472-Pebble.jpg";  break;
	case "Peridot":  filename = "1895-234-Peridot.jpg";  break;
	case "Persia":  filename = "1895-239-Persia.jpg";  break;
	case "Pesto":  filename = "1895-383-Pesto.jpg";  break;
	case "Peter":  filename = "1895-334-Peter.jpg";  break;
	case "Pine":  filename = "1895-141-Pine.jpg";  break;
	case "Pineapple":  filename = "1895-496-Pineapple.jpg";  break;
	case "Pink":  filename = "1895-12-Pink.jpg";  break;
	case "Pink Lemonade":  filename = "1895-493-Pink Lemonade.jpg";  break;
	case "Plum":  filename = "1895-143-Plum.jpg";  break;
	case "Plum":  filename = "1895-46-Plum.jpg";  break;
	case "Plumeria":  filename = "1895-510-Plumeria.jpg";  break;
	case "Pomegranate":  filename = "1895-381-Pomegranate.jpg";  break;
	case "Poppy":  filename = "1895-224-Poppy.jpg";  break;
	case "Pretzel":  filename = "1895-486-Pretzel.jpg";  break;
	case "Primrose":  filename = "1895-42-Primrose.jpg";  break;
	case "Pumpkin":  filename = "1895-192-Pumpkin.jpg";  break;
	case "Punch":  filename = "1895-474-Punch.jpg";  break;
	case "Purple":  filename = "1895-14-Purple.jpg";  break;
	case "Radish":  filename = "1895-434-Radish.jpg";  break;
	case "Raspberry":  filename = "1895-97-Raspberry.jpg";  break;
	case "Rattan":  filename = "1895-516-Rattan.jpg";  break;
	case "Raven":  filename = "1895-494-Raven.jpg";  break;
	case "Red":  filename = "1895-5-Red.jpg";  break;
	case "Refried Beans":  filename = "1895-398-Refried Beans.jpg";  break;
	case "Robin":  filename = "1895-318-Robin.jpg";  break;
	case "Rocky":  filename = "1895-335-Rocky.jpg";  break;
	case "Rose":  filename = "1895-63-Rose.jpg";  break;
	case "Rosehips":  filename = "1895-417-Rosehips.jpg";  break;
	case "Rosemary":  filename = "1895-225-Rosemary.jpg";  break;
	case "Ruby":  filename = "1895-143-Ruby.jpg";  break;
	case "Rust":  filename = "1895-39-Rust.jpg";  break;
	case "Sage":  filename = "1895-77-Sage.jpg";  break;
	case "Sahara":  filename = "1895-250-Sahara.jpg";  break;
	case "Salmon":  filename = "1895-323-Salmon.jpg";  break;
	case "Salvia":  filename = "1895-424-Salvia.jpg";  break;
	case "Sandcastle":  filename = "1895-488-Sandcastle.jpg";  break;
	case "Sandollar":  filename = "1895-501-Sandollar.jpg";  break;
	case "Sandy":  filename = "1895-336-Sandy.jpg";  break;
	case "Sapphire":  filename = "1895-230-Sapphire.jpg";  break;
	case "Scones":  filename = "1895-411-Scones.jpg";  break;
	case "Scrambled Eggs":  filename = "1895-392-Scrambled Eggs.jpg";  break;
	case "Sea Salt":  filename = "1895-443-Sea Salt.jpg";  break;
	case "Sea Urchin":  filename = "1895-276-Sea Urchin.jpg";  break;
	case "Seacliff":  filename = "1895-467-Seacliff.jpg";  break;
	case "Seagrass":  filename = "1895-522-Seagrass.jpg";  break;
	case "Seahorse":  filename = "1895-290-Seahorse.jpg";  break;
	case "Seamist":  filename = "1895-174-Seamist.jpg";  break;
	case "Seaside":  filename = "1895-484-Seaside.jpg";  break;
	case "Shaved Ice":  filename = "1895-477-Shaved Ice.jpg";  break;
	case "Shellie":  filename = "1895-350-Shellie.jpg";  break;
	case "Shirley":  filename = "1895-337-Shirley.jpg";  break;
	case "Shrimp":  filename = "1895-263-Shrimp.jpg";  break;
	case "Silver":  filename = "1895-28-Silver.jpg";  break;
	case "Singapore":  filename = "1895-240-Singapore.jpg";  break;
	case "Skipper":  filename = "1895-338-Skipper.jpg";  break;
	case "Sky":  filename = "1895-16-Sky.jpg";  break;
	case "Slate":  filename = "1895-92-Slate.jpg";  break;
	case "Smoke":  filename = "1895-173-Smoke.jpg";  break;
	case "Snake":  filename = "1895-319-Snake.jpg";  break;
	case "Sonoma":  filename = "1895-241-Sonoma.jpg";  break;
	case "Spearmint":  filename = "1895-445-Spearmint.jpg";  break;
	case "Spinach":  filename = "1895-377-Spinach.jpg";  break;
	case "Sprout":  filename = "1895-227-Sprout.jpg";  break;
	case "Squash":  filename = "1895-460-Squash.jpg";  break;
	case "Squid":  filename = "1895-266-Squid.jpg";  break;
	case "Starfish":  filename = "1895-300-Starfish.jpg";  break;
	case "Stonegreen":  filename = "1895-146-Stonegreen.jpg";  break;
	case "Strawberry Daiquiri":  filename = "1895-208-Strawberry Daiquiri.jpg";  break;
	case "Summer":  filename = "1895-339-Summer.jpg";  break;
	case "Sun":  filename = "1895-149-Sun.jpg";  break;
	case "Sunny":  filename = "1895-351-Sunny.jpg";  break;
	case "Sweetpea":  filename = "1895-447-Sweetpea.jpg";  break;
	case "Swordfish":  filename = "1895-306-Swordfish.jpg";  break;
	case "Tad":  filename = "1895-356-Tad.jpg";  break;
	case "Taffy":  filename = "1895-491-Taffy.jpg";  break;
	case "Tahiti":  filename = "1895-254-Tahiti.jpg";  break;
	case "Tan":  filename = "1895-64-Tan.jpg";  break;
	case "Tanzanite":  filename = "1895-236-Tanzanite.jpg";  break;
	case "Tara":  filename = "1895-340-Tara.jpg";  break;
	case "Taupe":  filename = "1895-80-Taupe.jpg";  break;
	case "Tavarua":  filename = "1895-365-Tavarua.jpg";  break;
	case "Tea Rose":  filename = "1895-153-Tea Rose.jpg";  break;
	case "Teal":  filename = "1895-21-Teal.jpg";  break;
	case "Teddy":  filename = "1895-353-Teddy.jpg";  break;
	case "The OC":  filename = "1895-359-The OC.jpg";  break;
	case "Toast":  filename = "1895-179-Toast.jpg";  break;
	case "Tokyo":  filename = "1895-364-Tokyo.jpg";  break;
	case "Topaz":  filename = "1895-238-Topaz.jpg";  break;
	case "Tortilla":  filename = "1895-401-Tortilla.jpg";  break;
	case "Turquoise":  filename = "1895-61-Turquoise.jpg";  break;
	case "Tutti Fruitti":  filename = "1895-479-Tutti Fruitti.jpg";  break;
	case "Vegas":  filename = "1895-358-Vegas.jpg";  break;
	case "Victoria":  filename = "1895-245-Victoria.jpg";  break;
	case "Vienna":  filename = "1895-366-Vienna.jpg";  break;
	case "Viola":  filename = "1895-228-Viola.jpg";  break;
	case "Violet":  filename = "1895-81-Violet.jpg";  break;
	case "Volcano":  filename = "1895-513-Volcano.jpg";  break;
	case "Wade":  filename = "1895-341-Wade.jpg";  break;
	case "Wakiki":  filename = "1895-360-Wakiki.jpg";  break;
	case "Walnut":  filename = "1895-180-Walnut.jpg";  break;
	case "Watercress":  filename = "1895-413-Watercress.jpg";  break;
	case "Wheat":  filename = "1895-84-Wheat.jpg";  break;
	case "Wine":  filename = "1895-50-Wine.jpg";  break;
	case "Winter Cherry":  filename = "1895-441-Winter Cherry.jpg";  break;
	case "Wisteria":  filename = "1895-229-Wisteria.jpg";  break;
	case "Woody":  filename = "1895-342-Woody.jpg";  break;
	case "Zinfandel":  filename = "1895-390-Zinfandel.jpg";  break;
	default:  filename = ""; break;

	}

	/*
	 * If the filename is not blank (meaning the color was found), then change the image source to the
	 * filename for the color.
	 */

	if ( filename != "" )
	{
		x.src = basedir + filename
		return false
	}


} /* End of showbatik() */

/*
 * Function:  SetSoFineItem
 *
 * This function takes the information about an item when the user selects the item's color from a drop-down menu
 * and populates the web page with it so the user can see it as well as populating the online shopping cart's form.
 */

function SetSoFineItem(item_value)
{

	/*
	 * If a semicolon does NOT appear in the value, the user didn't choose anything or selected the first item in the drop-down menu
	 * which is the instruction to choose a color.  Reset the values of the item on the web page and the value of the shopping cart
	 * variable to their initial values.
	 */

	if (item_value.indexOf(";") == -1)
	{

		x = document.getElementById('Color')
 		if (x.firstChild)
 		{
 			x.removeChild(x.firstChild)
		}

		y=document.createTextNode("Color")
 		x.appendChild(y)

	
		x = document.getElementById('Item_Num')
 		if (x.firstChild)
 		{
 			x.removeChild(x.firstChild)
		}

		y=document.createTextNode("Item #")
 		x.appendChild(y)

		x = document.getElementById('Price')
 		if (x.firstChild)
 		{
 			x.removeChild(x.firstChild)
		}

		y=document.createTextNode("Price:")
 		x.appendChild(y)

		document.cartform.item_SoFine.value = ""
		return false
	}

	/*
	 * item_value is a string consisting of a number of values separated by semicolons.
	 * First, parse it to retrieve all the values.
	 */

	split_array = item_value.split(";")

	code = split_array[0]
	color = split_array[1]
	item_num = split_array[2]
	price = split_array[3]

	/*
	 * Display the values on the web page.
	 */

	x = document.getElementById('Color')
 	if (x.firstChild)
 	{
 		x.removeChild(x.firstChild)
	}

	y=document.createTextNode(color)
 	x.appendChild(y)

	
	x = document.getElementById('Item_Num')
 	if (x.firstChild)
 	{
 		x.removeChild(x.firstChild)
	}

	y=document.createTextNode("Item # " + item_num)
 	x.appendChild(y)

	x = document.getElementById('Price')
 	if (x.firstChild)
 	{
 		x.removeChild(x.firstChild)
	}

	y=document.createTextNode("Price:  $" + price)
 	x.appendChild(y)

	/*
	 * Set the shopping cart value.
	 */

	document.cartform.item_SoFine.value = "s-7249^" + item_num + "^So Fine! Thread - " + color + " - " + code + "^" + price + "^op1^^^^0.08"

	return false

} /* End of SetSoFineItem() */



/*
 * Function:  SetTableLength
 *
 * This function takes the information about an item when the user selects the item's color from a drop-down menu
 * and populates the web page with it so the user can see it as well as populating the online shopping cart's form.
 */

function SetTableLength(item_value)
{

	/*
	 * If a semicolon does NOT appear in the value, the user didn't choose anything or selected the first item in the drop-down menu
	 * which is the instruction to choose a table length.  Reset the values of the item on the web page and the value of the shopping cart
	 * variable to their initial values.
	 */

	if (item_value.indexOf(";") == -1)
	{

		x = document.getElementById('Table_Length')
 		if (x.firstChild)
 		{
 			x.removeChild(x.firstChild)
		}

		y=document.createTextNode("LeaderMate System for 1 Roller")
 		x.appendChild(y)

	
		x = document.getElementById('Item_Num')
 		if (x.firstChild)
 		{
 			x.removeChild(x.firstChild)
		}

		y=document.createTextNode("Item #")
 		x.appendChild(y)

		x = document.getElementById('Price')
 		if (x.firstChild)
 		{
 			x.removeChild(x.firstChild)
		}

		y=document.createTextNode("Price:")
 		x.appendChild(y)

		document.cartform.item_leadermate_system.value = ""
		return false
	}

	/*
	 * item_value is a string consisting of a number of values separated by semicolons.
	 * First, parse it to retrieve all the values.
	 */

	split_array = item_value.split(";")

	table_length = split_array[0]
	item_num = split_array[1]
	price = split_array[2]
	weight = split_array[3]

	/*
	 * Display the values on the web page.
	 */

	x = document.getElementById('Table_Length')
 	if (x.firstChild)
 	{
 		x.removeChild(x.firstChild)
	}

	y=document.createTextNode(table_length)
 	x.appendChild(y)

	
	x = document.getElementById('Item_Num')
 	if (x.firstChild)
 	{
 		x.removeChild(x.firstChild)
	}

	y=document.createTextNode("Item # " + item_num)
 	x.appendChild(y)

	x = document.getElementById('Price')
 	if (x.firstChild)
 	{
 		x.removeChild(x.firstChild)
	}

	y=document.createTextNode("Price:  $" + price)
 	x.appendChild(y)

	/*
	 * Set the shopping cart value.
	 */

	document.cartform.item_leadermate_system.value = "s-7249^" + item_num + "^" + table_length + "^" + price + "^op1^^^^" + weight

	return false

} /* End of SetTableLength() */

/*
 * Function:  CheckAcrylicBottom
 *
 * This function 
 *
 * width_whole - the form field whose value contains the whole number width that the user entered
 * width_fraction - the form field whose value contains the fractional width amount that the user entered
 * length_whole - the form field whose value contains the whole number length that the user entered
 * length_fraction - the form field whose value contains the fractional length amount that the user entered
 * max_width - the maximum width
 * max_length - the maximum length
 * dimensions - the form field whose value will contain the user-entered dimensions
 * price_for_cart - the form field whose value will contain the price for the shopping cart
 * shipping_cost - the form field whose value will contain the shipping cost
 */

function CheckAcrylicBottom(width_whole, width_fraction, length_whole, length_fraction, max_width, max_length, dimensions, price_for_cart, shipping_cost)
{

	/* Call the calculate price function first */

	Calculate_Acrylic_Bottom_Price(width_whole, width_fraction, length_whole, length_fraction, max_width, max_length, price_for_cart, shipping_cost, 1)

	dimensions.value = " (" + width_whole.value

	if (width_fraction.value != 0)
	{
		dimensions.value = dimensions.value + " " + width_fraction.value
	}

	dimensions.value = dimensions.value + " in. x " + length_whole.value

	if (length_fraction.value != 0)
	{
		dimensions.value = dimensions.value + " " + length_fraction.value
	}

	dimensions.value = dimensions.value + " in.)"

} /* End of CheckAcrylicBottom() */


/*
 * Function:  Calculate_Acrylic_Bottom_Price
 *
 * This function 
 *
 * width_whole - the form field whose value contains the whole number width that the user entered
 * width_fraction - the form field whose value contains the fractional width amount that the user entered
 * length_whole - the form field whose value contains the whole number length that the user entered
 * length_fraction - the form field whose value contains the fractional length amount that the user entered
 * max_width - the maximum width
 * max_length - the maximum length
 * price_for_cart - the form field whose value will contain the price for the shopping cart
 * shipping_cost - the form field whose value will contain the shipping cost
 * submitform - a value of zero if this function is being called strictly to calculate the price; non-zero if it's being called as part of submitting the form
 */

function Calculate_Acrylic_Bottom_Price(width_whole, width_fraction, length_whole, length_fraction, max_width, max_length, price_for_cart, shipping_cost, submitform)
{

	piece_width = (width_whole.value * 1) + (eval(width_fraction.value) * 1)
	piece_length = (length_whole.value * 1) + (eval(length_fraction.value) * 1)


	/* Range check the user-entered width and length values. */

	if ( piece_width > max_width )
	{
		alert ("The entered width is larger than " + max_width + ".")
		return false
	}

	if ( piece_length > max_length )
	{
		alert ("The entered length is larger than " + max_length + ".")
		return false
	}

	/*
	 * Calculate the price of the acrylic bottom.  Key variables are as follows ... change, as required.
	 *
	 * min_price - the minimum price for an acrylic bottom
	 * max_rate - the maximum price rate per square inch
	 * min_rate - the minimum price rate per square inch
	 * max_area - the maximum area (which is 12" x 24")
	 * round_to_nearest - what nearest increment to round the calculated price.  Rounding can be up or down.
	 */

	minimum = 6.50
	max_rate = 0.12
	min_rate = 0.07
	max_area = 288
	round_to_nearest = 0.25

	area = piece_width * piece_length

	/*
	 * If the area is greater than 100 square inches, then reduce the rate per square inch.  The amount to reduce it by
	 * increases as the area increases.
	 */

	if (area > 100)
	{
		rate = max_rate - ((max_rate - min_rate) * (area/max_area))
	}
	else
	{
		rate = max_rate
	}

	calc_price = area * rate

	if (calc_price < minimum)
	{
		calc_price = 6.50
	}

	/* Round the price to the nearest 25 cents */

	calc_price /= round_to_nearest
        calc_price = Math.round(calc_price);
        calc_price *= round_to_nearest;

	/*
	 * without this check, I'd get an error saying that the price_for_cart object was null when this function was called directly from the form.
	 * It worked just fine when submitting the form and this function was called by the function above.  Don't know why, but to work around the
	 * problem, I passed a parameter to this function telling it where it was called from.
	 *
	 * If the form is being submitted to the shopping cart, then submitform is non-zero and we need to set the form variable containing the price
	 * so it gets passed to the shopping cart.  Ditto for the shipping cost which is $1 for every 50 square inches.
	 */

	if (submitform != 0)
	{
		price_for_cart.value = calc_price

		shipping_cost.value = Math.floor(area/50)

		if (shipping_cost.value == 0)
		{
			shipping_cost.value = 1
		}
	}

	/* The following code is needed so 2 digits are output after the decimal point.  Note that it is specific to round_to_nearest being 25 cents. */

	suffix = ""

	/* First, see if the calculated price is a dollar amount plus 50 cents. */

	remainder = (calc_price * 100) % 50

	if (remainder == 0)
	{
		suffix = "0"
	}

	/* Now see if the calculated price is a whole dollar amount.  As the code is written, this test must follow the one above for 50 cents. */

	remainder = (calc_price * 100) % 100

	if (remainder == 0)
	{
		suffix = ".00"
	}

	/* Update the price on the shopping cart page */

	x = document.getElementById('Acrylic_Bottom_Price')
 	if (x.firstChild)
 	{
 		x.removeChild(x.firstChild)
	}

	y=document.createTextNode("$" + calc_price + suffix)
 	x.appendChild(y)
	

} /* End of Calculate_Acrylic_Bottom_Price() */

/*
 * Function:  Calculate_Acrylic_Square_Price
 *
 * This function determines the price of an acrylic square given the parameters passed.  What is passed is the input form in which
 * the user selects what they want.  The form elements are of the form opN_acrylic_square where N is a number.  The form elements are
 * as follows:
 *
 * op1 - the size of the square template
 * op2 - quantity (not used by this function)
 * op3 - price (this is calculated and, in effect, passed back as an output parameter destined for the shopping cart)
 * op4 - whether to cut a whole in the template and, if so, where to cut it
 * op5 - whether to etch crosshairs on the template
 * op6 - shipping weight of the item
 */

function Calculate_Acrylic_Square_Price(acrylic_square_form)
{

	/* Calculating the price is simply akin to a big table look-up. */

	var plain_square = new Array()

	plain_square["1-1/2"] = "2.00"
	plain_square["2"] = "2.00"
	plain_square["2-1/2"] = "2.50"
	plain_square["3"] = "3.00"
	plain_square["3-1/2"] = "3.25"
	plain_square["4"] = "3.75"
	plain_square["4-1/2"] = "4.50"
	plain_square["5"] = "5.25"
	plain_square["5-1/2"] = "5.75"
	plain_square["6"] = "6.00"
	plain_square["6-1/2"] = "6.5"
	plain_square["7"] = "7.00"
	plain_square["7-1/2"] = "7.5"
	plain_square["8"] = "9.00"
	plain_square["8-1/2"] = "10.25"
	plain_square["9"] = "11.50"
	plain_square["9-1/2"] = "12.75"
	plain_square["10"] = "14.00"
	plain_square["10-1/2"] = "14.75"
	plain_square["11"] = "15.25"
	plain_square["11-1/2"] = "16.00"
	plain_square["12"] = "16.75"
	plain_square["12-1/2"] = "17.75"
	plain_square["13"] = "18.75"
	plain_square["13-1/2"] = "19.75"
	plain_square["14"] = "21.00"
	plain_square["14-1/2"] = "21.75"
	plain_square["15"] = "22.75"
	plain_square["15-1/2"] = "23.75"
	plain_square["16"] = "24.50"
	plain_square["16-1/2"] = "25.25"
	plain_square["17"] = "26.50"
	plain_square["17-1/2"] = "28.00"

	var etched_square = new Array()

	etched_square["1-1/2"] = "2.50"
	etched_square["2"] = "2.50"
	etched_square["2-1/2"] = "3.50"
	etched_square["3"] = "4.00"
	etched_square["3-1/2"] = "4.50"
	etched_square["4"] = "5.00"
	etched_square["4-1/2"] = "6.00"
	etched_square["5"] = "7.00"
	etched_square["5-1/2"] = "7.50"
	etched_square["6"] = "8.00"
	etched_square["6-1/2"] = "8.50"
	etched_square["7"] = "9.00"
	etched_square["7-1/2"] = "10.00"
	etched_square["8"] = "11.25"
	etched_square["8-1/2"] = "12.75"
	etched_square["9"] = "14.50"
	etched_square["9-1/2"] = "16.00"
	etched_square["10"] = "17.50"
	etched_square["10-1/2"] = "18.50"
	etched_square["11"] = "19.25"
	etched_square["11-1/2"] = "20.25"
	etched_square["12"] = "21.00"
	etched_square["12-1/2"] = "22.00"
	etched_square["13"] = "23.50"
	etched_square["13-1/2"] = "24.75"
	etched_square["14"] = "26.25"
	etched_square["14-1/2"] = "27.25"
	etched_square["15"] = "28.50"
	etched_square["15-1/2"] = "29.50"
	etched_square["16"] = "30.75"
	etched_square["16-1/2"] = "31.75"
	etched_square["17"] = "33.00"
	etched_square["17-1/2"] = "34.50"

	/* Get the selected size.  This will be used to index the above arrays. */

	size = acrylic_square_form.op1_acrylic_square[acrylic_square_form.op1_acrylic_square.selectedIndex].value

	/*
	 * Convert the provided size into a decimal format.  This needs to be done for values that end with "-1/2".
	 */

	decimal_size = size.replace("-1/2", ".5")

	/*
	 * Determine the weight of the item.  Based on measurements, acrylic weighs about 0.005 pounds per square inch.
	 * Then double the weight to account for the packaging. 
	 *
	 */

	acrylic_square_form.op6_acrylic_square.value = decimal_size * decimal_size * 0.005 * 2

	/* Assume the price is for the plain square.  If an etching option is selected, then change the price. */

	acrylic_square_form.op3_acrylic_square.value = plain_square[size]

	/*
	 * Determine the hole option that was selected.  The first option (0) is "no hole".  If that option is selected,
	 * then the price is for the plain square; otherwise, it is for the etched square.
	 */

	for (i = 0; i < acrylic_square_form.op4_acrylic_square.length; i++)
	{
		if (acrylic_square_form.op4_acrylic_square[i].checked)
		{
			break
		}
	}

	if (i > 0)
	{
		acrylic_square_form.op3_acrylic_square.value = etched_square[size]
	}
		
	/*
	 * Determine if the user wants the crosshairs etched, then price accordingly.  The first option (0) is not to etch.
	 * If that option is selected, then the price is for the plain square; otherwise, it is for the etched square.
	 */

	for (i = 0; i < acrylic_square_form.op5_acrylic_square.length; i++)
	{
		if (acrylic_square_form.op5_acrylic_square[i].checked)
		{
			break
		}
	}

	if (i > 0)
	{
		acrylic_square_form.op3_acrylic_square.value = etched_square[size]
	}

	/* Update the price on the shopping cart page */

	x = document.getElementById('Acrylic_Square_Template_Price')
 	if (x.firstChild)
 	{
 		x.removeChild(x.firstChild)
	}

	y=document.createTextNode("$" + acrylic_square_form.op3_acrylic_square.value)
 	x.appendChild(y)

} /* End of Calculate_Acrylic_Square_Price() */
