// JavaScript Document
var opendiv = 'none';
var copied = false;

function toggleDesc(theDiv)
	{
	if (opendiv == 'none')
		{
		toggle('block', theDiv);
		opendiv = theDiv;
		}
	else if (theDiv == opendiv)
		{
		toggle('none', theDiv);
		opendiv = 'none';
		}
	else
		{
		toggle('none', opendiv);
		toggle('block', theDiv);
		opendiv = theDiv;
		}
	}

function toggle(mode, theDiv)
	{
	if (document.getElementById)
		{
		// this is the way the standards work
		var style2 = document.getElementById(theDiv).style;
		style2.display = mode;
		}
	else if (document.all)
		{
		// this is the way old msie versions work
		var style2 = document.all[theDiv].style;
		style2.display = mode;
		}
	else if (document.layers)
		{
		// this is the way nn4 works
		var style2 = document.layers[theDiv].style;
		style2.display = mode;
		}
	}
	
function loadToggle()
	{
	toggle('none', 'content');
	toggle('block', 'content');
	}

function setItem(whichItem)
	{
	document.cartUpdate.removeID.value = whichItem;
	}
	
function pop(photo,name)
	{
	URL = "enlargement.php?photo=" + photo + "&name=" + name;
	var windowprops = "location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes" + ",left=" + 25 + ",top=" + 50 + ",width=" + 640 + ",height=" + 440;
	popup = window.open(URL,"",windowprops);
	}
	
function doNothing()
	{
	var a = 1;
	}
	
function nextScreen(which)
	{
	var theForm = document.checkOut;
	switch(which)
		{
		case 1:
			if (theForm.State.selectedIndex == 0)
				{
				alert("Please enter your State");
				lastScreen(3);
				theForm.State.focus();
				return false;
				}
			else
				{
				toggle('none', 'custForm0');
				toggle('block', 'custForm1');
				if(!copied)
					{
					transferIn();
					copied = true;
					}
				showShipAddress();
				}
			break;
		case 2:
			toggle('none', 'custForm1');
			toggle('block', 'custForm2');
			break;
		}
	}
	
function lastScreen(which)
	{
	switch(which)
		{
		case 1:
			toggle('none', 'custForm1');
			toggle('block', 'custForm0');
			break;
		case 2:
			toggle('none', 'custForm2');
			toggle('block', 'custForm1');
			break;
		case 3:
			toggle('none', 'custForm2');
			toggle('block', 'custForm0');
			break;
		}
	}

function showOptions()
	{
	toggle('block', 'addSelect');
	calculateTotals();
	if(document.checkOut.ShipSelect[1].checked)
		{
		toggle('block', 'addShip');
		}
	}

function toggleShip(flag)
	{
	if(flag==1)
		{
		toggle('block', 'addShip');
		}
	else
		{
		toggle('none', 'addShip');
		}
	calculateTotals();
	}

function transferIn()
	{
	var theForm = document.checkOut;
	//theForm.FirstNameShip.value = theForm.FirstName.value;
	//theForm.LastNameShip.value = theForm.LastName.value;
	theForm.AddressShip.value = theForm.Address.value;
	theForm.CityShip.value = theForm.City.value;
	theForm.StateShip.selectedIndex = theForm.State.selectedIndex;
	theForm.ZipShip.value = theForm.Zip.value;
	calculateTotals();
	}

function  hideShip()
	{
	toggle('none', 'addShip');
	toggle('none', 'addSelect');
	calculateTotals();
	}

function  clearShip()
	{
	var theForm = document.checkOut;
	//theForm.FirstNameShip.value = '';
	//theForm.LastNameShip.value = '';
	theForm.AddressShip.value = '';
	theForm.CityShip.value = '';
	theForm.StateShip.selectedIndex = 0;
	theForm.ZipShip.value = '';
	calculateTotals();
	}
	
function validate()
	{
	var theForm = document.checkOut;
	if (theForm.FirstName.value == '')
		{
		alert("Please enter your First Name");
		lastScreen(3);
		theForm.FirstName.focus();
		return false;
		}
	if (theForm.LastName.value == '')
		{
		alert("Please enter your Last Name");
		lastScreen(3);
		theForm.LastName.focus();
		return false;
		}
	if (theForm.Address.value == '')
		{
		alert("Please enter your Address");
		lastScreen(3);
		theForm.Address.focus();
		return false;
		}
	if (theForm.City.value == '')
		{
		alert("Please enter your City");
		lastScreen(3);
		theForm.City.focus();
		return false;
		}
	if (theForm.State.selectedIndex == 0)
		{
		alert("Please enter your State");
		lastScreen(3);
		theForm.State.focus();
		return false;
		}
	if (theForm.Zip.value == '')
		{
		alert("Please enter your Zip Code");
		lastScreen(3);
		theForm.Zip.focus();
		return false;
		}
	if (theForm.Phone.value == '')
		{
		alert("Please enter your Phone Number");
		lastScreen(3);
		theForm.Phone.focus();
		return false;
		}
	if (theForm.Email.value == '')
		{
		alert("Please enter your Email address");
		lastScreen(3);
		theForm.Email.focus();
		return false;
		}
	if (!theForm.ShipPref[0].checked && !theForm.ShipPref[1].checked && !theForm.ShipPref[2].checked)
		{
		alert("Please choose Shipping or Pickup for your order");
		lastScreen(2);
		return false;
		}
	if (!theForm.CardType[0].checked && !theForm.CardType[1].checked)
		{
		alert("Please select your Credit Card Type");
		return false;
		}
	if (theForm.CardNo.value.length < 16)
		{
		alert("Please enter your Credit Card Number");
		theForm.CardNo.focus();
		return false;
		}
	if (theForm.CardCode.value.length != 3)
		{
		alert("Please enter the 3 digit Security Code from your card's signature strip");
		theForm.CardCode.focus();
		return false;
		}
	if (theForm.CardExp.value.length < 4)
		{
		alert("Please enter your Credit Card Expiration Date as MM/YY");
		theForm.CardExp.focus();
		return false;
		}
	return true;
	}
	
function checkTotal()
	{
	if(document.checkout.totalPrice.value < 49.50)
		{
		alert("We're sorry, our minimum order is $49.50");
		return false;
		}
	else return true;
	}
	
function calculateTotals()
	{
	var theForm = document.checkOut;
	var nTotal = Number(theForm.PHCost.value);
	var nZip = theForm.ZipShip.value.slice(0,3);
	nZip = Number(nZip);
	var decIndex = 0;
	var smallOrder = (nTotal <= 100) ? true : false;
	var StateIndex = theForm.State.selectedIndex;
	var theState = theForm.State.options[StateIndex].value
	var shipStateIndex = theForm.StateShip.selectedIndex;
	var shipState = theForm.StateShip.options[shipStateIndex].value
	var workingState = (theForm.ShipSelect[1].checked) ? shipState : theState;
	var ahCount = theForm.PHAddlHand.value;
	var SandH = 0;
	var addlHand = 0;

// Calculate Shipping
	switch(workingState)
		{
		case 'CA':
			alert("We're sorry, we cannot ship our plants to California.");
			theForm.StateShip.selectedIndex = 0;
			theForm.State.selectedIndex = 0;
			break;
		case 'AZ':
			alert("We're sorry, we cannot ship our plants to Arizona.");
			theForm.StateShip.selectedIndex = 0;
			theForm.State.selectedIndex = 0;
			break;
		case 'ID':
			alert("We're sorry, we cannot ship our plants to Idaho.");
			theForm.StateShip.selectedIndex = 0;
			theForm.State.selectedIndex = 0;
			break;
		case 'NV':
			alert("We're sorry, we cannot ship our plants to Nevada.");
			theForm.StateShip.selectedIndex = 0;
			theForm.State.selectedIndex = 0;
			break;
		case 'OR':
			alert("We're sorry, we cannot ship our plants to Oregon.");
			theForm.StateShip.selectedIndex = 0;
			theForm.State.selectedIndex = 0;
			break;
		case 'UT':
			alert("We're sorry, we cannot ship our plants to Utah.");
			theForm.StateShip.selectedIndex = 0;
			theForm.State.selectedIndex = 0;
			break;
		case 'WA':
			alert("We're sorry, we cannot ship our plants to Washington.");
			theForm.StateShip.selectedIndex = 0;
			theForm.State.selectedIndex = 0;
			break;
		case 'AK':
			alert("We're sorry, we cannot ship our plants to Alaska.");
			theForm.StateShip.selectedIndex = 0;
			theForm.State.selectedIndex = 0;
			break;
		case 'HI':
			alert("We're sorry, we cannot ship our plants to Hawaii.");
			theForm.StateShip.selectedIndex = 0;
			theForm.State.selectedIndex = 0;
			break;
		case 'WY':
		case 'MT':
			alert("Please consult with us before placing an order for shipment to this state.");
			theForm.StateShip.selectedIndex = 0;
			theForm.State.selectedIndex = 0;
			break;
		case 'CT':
		case 'DC':
		case 'DE':
		case 'IN':
		case 'KY':
		case 'MA':
		case 'MD':
		case 'ME':
		case 'MI':
		case 'NC':
		case 'NH':
		case 'NJ':
		case 'NY':
		case 'OH':
		case 'PA':
		case 'RI':
		case 'SC':
		case 'VA':
		case 'VT':
		case 'WV':
			SandH = (smallOrder) ? 2500 : nTotal * 25;
			addlHand = ahCount * 15.00;
			break;
		case 'AL':
		case 'FL':
		case 'IA':
		case 'IL':
		case 'MN':
		case 'MS':
		case 'WI':
			SandH = (smallOrder) ? 2800 : nTotal * 28;
			addlHand = ahCount * 20.00;
			break;
		case 'KS':
		case 'LA':
		case 'ND':
		case 'NE':
		case 'OK':
		case 'SD':
		case 'TX':
			SandH = (smallOrder) ? 3200 : nTotal * 32;
			addlHand = ahCount * 20.00;
			break;
		case 'CO':
		case 'NM':
			SandH = (smallOrder) ? 3500 : nTotal * 35;
			addlHand = ahCount * 20.00;
			break;
		case 'AR':
			if((nZip == 716) || ((nZip >= 720) && (nZip <= 726))) SandH = (smallOrder) ? 2800 : nTotal * 28;
			else SandH = (smallOrder) ? 3200 : nTotal * 32;
			addlHand = ahCount * 20.00;
			break;
		case 'GA':
			if(((nZip >= 304) && (nZip <= 306)) || ((nZip >= 308) && (nZip <= 309)) || ((nZip >= 313) && (nZip <= 314))) SandH = (smallOrder) ? 2500 : nTotal * 25;
			else SandH = (smallOrder) ? 2800 : nTotal * 28;
			addlHand = ahCount * 20.00;
			break;
		case 'MO':
			if((nZip == 646) || ((nZip >= 630) && (nZip <= 639)) || ((nZip >= 650) && (nZip <= 658))) SandH = (smallOrder) ? 2800 : nTotal * 28;
			else SandH = (smallOrder) ? 3200 : nTotal * 32;
			addlHand = ahCount * 20.00;
			break;
		case 'TN':
			if((nZip >= 376) && (nZip <= 379)) SandH = (smallOrder) ? 2500 : nTotal * 25;
			else SandH = (smallOrder) ? 2800 : nTotal * 28;
			addlHand = ahCount * 20.00;
			break;
		default:
			SandH = 0;
			addlHand = 0;
			break;
		}
	
// Delete shipping for picked up orders

	SandH = (theForm.ShipPref[0].checked) ? SandH : 0;
	SandH = Math.round(SandH) /100;
	addlHand = (theForm.ShipPref[0].checked) ? addlHand : 0;

// Calculate Tax
	var taxState = workingState;
	if((theForm.ShipPref[1].checked) || (theForm.ShipPref[2].checked)) taxState = 'NJ';
	if(taxState == 'NJ')
		{
		var tempTax = (nTotal + SandH + addlHand) * 7;
		tempTax = Math.round(tempTax) /100;
		}
	else
		{
		tempTax = 0;
		}
	
// Calculate Total
	var theTotal = nTotal + tempTax + addlHand + SandH + Number(theForm.PHAddl.value);
	theTotal = Math.round(theTotal * 100) /100;
	
// Post the results to the form
	tempTax = padCents(tempTax);
	SandH = padCents(SandH);
	addlHand = padCents(addlHand);
	theTotal = padCents(theTotal);
	theForm.PHTax.value = tempTax;
	theForm.Tax.value = '$ ' + tempTax;
	theForm.PHShipping.value = SandH;
	theForm.PHAddHandTotal.value = addlHand;
	theForm.PlantAddl.value = '$ ' + addlHand;
	theForm.PlantShipping.value = '$ ' + SandH;
	theForm.PHTotal.value = theTotal;
	theForm.PlantTotal.value = '$ ' + theForm.PHTotal.value;
	}
	
function padCents(money)
	{
	money = String(money);
	var decIndex = money.indexOf('.');
	var monLength = money.length;
	if (decIndex == -1) money = money + '.00';
	else if(monLength - decIndex == 2) money = money + '0';
	var parts = money.split('.');
	if(parts[0].length > 3)
		{
		var l = parts[0].length;
		money = parts[0].substr(0, l-3) + ',' + parts[0].substr(l-3) + '.' + parts[1];
		}
	return money;
	}

function showForm()
	{
	toggle('block', 'fwg_sender')
	}
//Create an array  	
var allPageTags = new Array();
function ffk(theClass)
	{
	//Populate the array with all the page tags 
	var allPageTags=document.getElementsByTagName("*"); 
	//Cycle through the tags using a for loop 
	for (var i=0; i<allPageTags.length; i++)
		{ 
		//Pick out the tags with our class name 
		if (allPageTags[i].className==theClass)
			{ 
			//Manipulate this in whatever way you want 
			allPageTags[i].style.display='block'; 
			} 
		} 
	} 
	
function showShipAddress()
	{
	if(document.checkOut.ShipPref[0].checked)
		{
		showOptions();
		if(document.checkOut.ShipSelect[1].checked)
			{
			toggleShip(1);
			}
		}
	}
	