// ----------------------------------------------------------------------
// LOCATION CONTROL VARIABLES
// ----------------------------------------------------------------------
LOCATION_NAME = 0;
LOCATION_LISTNUMBER = 1;
LOCATION_HASTIPS = 2;
LOCATION_HASRECIPES = 3;
LOCATION_HASNEWS = 4;

gnLocMax = 0;
var gsLocMatrix = new Array(100);
//                              have their own:        tip? recipes? news?
gsLocMatrix[gnLocMax++] = new Array("middletown", "2", true, true, true);


// ----------------------------------------------------------------------
// NAVIGATION CONTROL VARIABLES
// ----------------------------------------------------------------------
gstTarget = "";
NAV_CATEGORY = 0;
NAV_PAGEHEAD = 1;
NAV_ALIAS = 2;
NAV_URL = 3;
NAV_WIDTH = 4;
NAV_IMGWIDTH = 5;
gnNavMax=0;
var gstNavMatrix = new Array(100);

//gstNavMatrix[gnNavMax++] = new Array("Ayuda Español? - ¿Necesita Ayuda?", "Ayuda Español?", "spanish", "../publish/spanish.shtml", "50%", "170");
//gstNavMatrix[gnNavMax++] = new Array("Ayuda Español? - Programas", "Ayuda Español?", "spanish_programs", "../publish/spanish_programs.shtml", "50%", "170");

//gstNavMatrix[gnNavMax++] = new Array("Our Ministry - Ministry", "Our Ministry", "ministry", "../publish/ministry.shtml", "25%", "120");
gstNavMatrix[gnNavMax++] = new Array("Worship - Worship", "Worship", "worship", "../publish/worship.shtml", "33%", "150");
gstNavMatrix[gnNavMax++] = new Array("Worship - Sermons", "Worship", "sermons", "../publish/sermons.shtml", "33%", "150");
gstNavMatrix[gnNavMax++] = new Array("Worship - Music", "Worship", "music", "../publish/music.shtml", "33%", "150");

gstNavMatrix[gnNavMax++] = new Array("News &amp; Events - Pressroom", "News &amp; Events", "pressroom", "../publish/pressroom.shtml", "33%", "150");
gstNavMatrix[gnNavMax++] = new Array("News &amp; Events - Events", "News &amp; Events", "events", "../publish/events.shtml", "33%", "150");
gstNavMatrix[gnNavMax++] = new Array("News &amp; Events - Newsletters", "News &amp; Events", "newsletters", "../publish/newsletters.shtml", "33%", "150");

gstNavMatrix[gnNavMax++] = new Array("Directions - Driving Instructions", "Directions", "driving", "../publish/driving.shtml", "33%", "150");
gstNavMatrix[gnNavMax++] = new Array("Directions - Area Map", "Directions", "areamap", "../publish/areamap.shtml", "33%", "150");
gstNavMatrix[gnNavMax++] = new Array("Directions - Zoom Map", "Directions", "mapzoom", "../publish/mapzoom.shtml", "33%", "150");

gstNavMatrix[gnNavMax++] = new Array("Christian Education - Sunday School", "Christian Education", "sundayschool", "../publish/sundayschool.shtml", "33%", "150");
gstNavMatrix[gnNavMax++] = new Array("Christian Education - Youth", "Christian Education", "youthed", "../publish/youthed.shtml", "33%", "150");
gstNavMatrix[gnNavMax++] = new Array("Christian Education - Adults", "Christian Education", "adulted", "../publish/adulted.shtml", "33%", "150");

//gstNavMatrix[gnNavMax++] = new Array("Make A Donation - Make A Difference", "Make A Donation", "donations", "../publish/donations.shtml", "33%", "150");
//gstNavMatrix[gnNavMax++] = new Array("Make A Donation - More Information", "Make A Donation", "donateinfo", "../publish/donateinfo.shtml", "33%", "150");
//gstNavMatrix[gnNavMax++] = new Array("Make A Donation - Gifts In Kind", "Make A Donation", "wishlist", "../publish/wishlist.shtml", "33%", "150");

//gstNavMatrix[gnNavMax++] = new Array("In Gratitude - Letters from Clients", "In Gratitude", "letters", "../publish/gratitude_letters.shtml", "50%", "170");
//gstNavMatrix[gnNavMax++] = new Array("In Gratitude - To Our Volunteers", "In Gratitude", "thanks", "../publish/gratitude_thanks.shtml", "50%", "180");

//gstNavMatrix[gnNavMax++] = new Array("Corporate Giving - Corporate Partnership", "Corporate Giving", "corporations", "../publish/corporations.shtml", "33%", "150");
//gstNavMatrix[gnNavMax++] = new Array("Corporate Giving - Employee Giving", "Corporate Giving", "matching", "../publish/matching.shtml", "33%", "150");
//gstNavMatrix[gnNavMax++] = new Array("Corporate Giving - For More Information", "Corporate Giving", "corpinfo", "../publish/corpinfo.shtml", "33%", "150");

//gstNavMatrix[gnNavMax++] = new Array("Daily Update - Session 1", "Daily Update", "session1", "../publish/session1.shtml", "20%", "90");
//gstNavMatrix[gnNavMax++] = new Array("Daily Update - Session 2", "Daily Update", "session2", "../publish/session2.shtml", "20%", "90");
//gstNavMatrix[gnNavMax++] = new Array("Daily Update - Session 3", "Daily Update", "session3", "../publish/session3.shtml", "20%", "90");
//gstNavMatrix[gnNavMax++] = new Array("Daily Update - Session 4", "Daily Update", "session4", "../publish/session4.shtml", "20%", "90");
//gstNavMatrix[gnNavMax++] = new Array("Daily Update - Special Events", "Daily Update", "special", "../publish/special.shtml", "20%", "90");



// ----------------------------------------------------------------------
// LOCATION CONTROL VARIABLES
// ----------------------------------------------------------------------
SHIPPING_NAME = 0;
SHIPPING_FEE = 1;

gnShipMax = 0;
var gstShipMatrix = new Array(10);
//                              
gstShipMatrix[gnShipMax++] = new Array("Standard Ground", "7.00");
gstShipMatrix[gnShipMax++] = new Array("Two Day Express", "12.00");
gstShipMatrix[gnShipMax++] = new Array("Overnight", "24.00");
gstShopCat="Online Store - ORDER ITEMS";
gstOrderForm="https://www42.fatcow.com/springglenchurch/content/publish/order_checkout.shtml";


gstCheckoutRecipient = "orders@springglenchurchelo.com";
gstCheckoutEmailCopies = "";
gstCheckoutSubject = "springglenchurchelo Online Order";
gstCheckoutConfirmScript ="https://www42.fatcow.com/springglenchurch/ordersys/order_confirm.php";


// DO NOT AUTO-AUTHORIZE YET
gbAllowShipAddress = true;
gbAllowDiscount = true;
gbCalcShip = true;
gstAuthNet = "FALSE"


// ----------------------------------------------------------------------
// Recalc
// ----------------------------------------------------------------------
function Recalc(myFormCtrl) {
	stQty = new String();
	stTot = new String();
	stShip = new String();
	stSalesTax = new String();
	
	nQty = new Number();
	nTot = new Number();

	gQty = new Number();
	nShip = new Number();	
	gTot = new Number();
	nSalesTax = new Number();	
	nTemp = new Number();	
	
	
	jewerlyTot = new Number();	
	otherTot = new Number();	
	jewerlyTot = 0;	
	otherTot = 0;	

	nDiscount = new Number();	
	nDiscount = 0;	

	/* m_discount_code
	   m_discount_amount */
	nDiscMult = 1;
	if (gbAllowDiscount) {
		stDiscountCode = myFormCtrl.document.getElementById("m_discount_code").value;
		if (stDiscountCode=="DISC1204"){
			nDiscMult = .9;
		}
		else {
			if (stDiscountCode!="") { 
				myFormCtrl.document.getElementById("m_discount_code").value = "";
				alert('Sorry, Invalid Discount Code');
			}
		}
	}
	
	gQty=0;
	gTot=0;
	stShip = "0.00";
	stSalesTax = "0.00"; 
	for (n = 0; n<nCnt; n++) {
		nQty = 1 * myFormCtrl.document.getElementById("item_quantity_"+n).value;
		stItemName = myFormCtrl.document.getElementById("item_name_"+n).value;
		
		if (nQty.toString()=="NaN"){ 
			nQty=0; 
		}
		stQty = nQty.toFixed(0);

		nQty = 1 * stQty;
		nTot = nQty * myFormCtrl.document.getElementById("item_price_"+n).value * nDiscMult;
		stTot = nTot.toFixed(2);

		myFormCtrl.document.getElementById("item_quantity_"+n).value = stQty;
		myFormCtrl.document.getElementById("item_total_"+n).value = stTot;
		gQty=gQty+nQty;
		gTot=gTot+nTot;
		
		// test if this item is Jewelery
		if (stItemName.indexOf("(JY")>=0) {
			jewerlyTot = jewerlyTot + nTot;
		}
		else {
			otherTot = otherTot + nTot;		
		}
	}	

	//Calc SALES based on STATE
	var list = myFormCtrl.document.getElementById("x_ship_to_state")
	stState = list.options[list.selectedIndex].value;
	//alert("["+stState+"]");
	if (stState=="CT"){
		nSalesTax = gTot*.06;
	}	
	stSalesTax = nSalesTax.toFixed(2);
	myFormCtrl.document.getElementById("salestax").value = stSalesTax;
	nTot = gTot + nSalesTax;
	gTot = nTot;

	//Calc Shipping based on dropdown
	nMethod = myFormCtrl.document.getElementById("m_ship_method").selectedIndex;
	// nShip  = parseFloat(gstShipMatrix[nMethod][SHIPPING_FEE]);
	
	if (gTot<=0){
		nShip = 0;
	}
	else {
		if (otherTot==0){
			nShip = 6;
		}
		else {
			if (otherTot<=30){
				nShip = 8;
			}
			else {
				if (otherTot<=50){
					nShip = 11;
				}
				else {
					if (otherTot<=90){
						nShip = 15;
					}
					else {
						if (otherTot<=125){
							nShip = 18;
						}
						else {
							if (otherTot<=200){
								nShip = 21;
							}
							else {
								if (otherTot<=300){
									nShip = 32;
								}
								else {
									nShip = 45;
								}	
							}	
						}	
					}	
				}	
			}			
		}	
	}
	
	if (gTot>0 && nMethod==1) {
		// express
		nShip = nShip + 15;
	}
	if (gTot>0 && nMethod==2) {
		// overnight
		nShip = nShip + 20;
	}	
	
	
	stShip = nShip.toFixed(2);
	myFormCtrl.document.getElementById("shipping").value= stShip;
	
	nTot = gTot + parseFloat(myFormCtrl.document.getElementById("shipping").value);
	stTot = nTot.toFixed(2);

	myFormCtrl.document.getElementById("x_amount").value = stTot;
	myFormCtrl.document.getElementById("total_amount").value = stTot;
}