// ----------------------------------------------------------------------
// 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);

// ----------------------------------------------------------------------
// MATRIX IS USED FOR TABBED PAGES
// ----------------------------------------------------------------------
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");


// ----------------------------------------------------------
// IF SITE USES GRAPHICAL NAV IMAGES LOAD THEM HERE
// FUNCTION: Load_Pics()
// ----------------------------------------------------------
function Load_Pics(){
	
	if (document.images) {
  		home_f1 = new Image(180, 22); home_f1.src = "../images/client/link_home.gif";
		home_f2 = new Image(180, 22); home_f2.src = "../images/client/link_home_f2.gif";
		
		services_f1 = new Image(180, 22); services_f1.src = "../images/client/link_services.gif";
		services_f2 = new Image(180, 22); services_f2.src = "../images/client/link_services_f2.gif";
		
		yoga_studio_f1 = new Image(180, 22); yoga_studio_f1.src = "../images/client/link_yoga_studio.gif";
		yoga_studio_f2 = new Image(180, 22); yoga_studio_f2.src = "../images/client/link_yoga_studio_f2.gif";
		
		newsletters_f1 = new Image(180, 22); newsletters_f1.src = "../images/client/link_newsletters.gif";
		newsletters_f2 = new Image(180, 22); newsletters_f2.src = "../images/client/link_newsletters_f2.gif";
		
		contact_f1 = new Image(180, 22); contact_f1.src = "../images/client/link_contact.gif";
		contact_f2 = new Image(180, 22); contact_f2.src = "../images/client/link_contact_f2.gif";

		classes_f1 = new Image(180, 22); classes_f1.src = "../images/client/link_classes.gif";
		classes_f2 = new Image(180, 22); classes_f2.src = "../images/client/link_classes_f2.gif";
		
		links_f1 = new Image(180, 22); links_f1.src = "../images/client/link_links.gif";
		links_f2 = new Image(180, 22); links_f2.src = "../images/client/link_links_f2.gif";
		
	}	
}
	// -----------------------------------------------
	// GetLinkName
	// -----------------------------------------------
	function GetLinkName(stShowCategory) {
		var stLinkName = "home";
		
		if (stShowCategory == "Home") { 
			stLinkName = "home"; 
		}
		if (stShowCategory == "About Us") { 
			stLinkName = "about"; 
		}
		if (stShowCategory == "Pressroom") { 
			stLinkName = "pressroom"; 
		}
		if (stShowCategory == "Residential") { 
			stLinkName = "residential"; 
		}
		if (stShowCategory == "Commercial") { 
			stLinkName = "commercial"; 
		}
		if (stShowCategory == "Clients") { 
			stLinkName = "clients"; 
		}
		if (stShowCategory == "Testimonials") { 
			stLinkName = "testimonials"; 
		}
		if (stShowCategory == "Contact Us") { 
			stLinkName = "contact"; 
		}
		if (stShowCategory == "HVAC Links") { 
			stLinkName = "links"; 
		}

		return stLinkName;
	}

// ----------------------------------------------------------
// FUNCTION: MM_findObj(n, d)
// ----------------------------------------------------------
function MM_findObj(n, d) { //v3.0
  	var p,i,x;  
  	if(!d) {
		d=document; 
	}
  	if((p=n.indexOf("?"))>0&&parent.frames.length) {
    	d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
  	if(!(x=d[n])&&d.all) {
		x=d.all[n]; 
	}
	for (i=0;!x&&i<d.forms.length;i++) {
		x=d.forms[i][n];
	}
  	for(i=0;!x&&d.layers&&i<d.layers.length;i++) {
		x=MM_findObj(n,d.layers[i].document); 
	}
	return x;
}

// ----------------------------------------------------------
// FUNCTION: MM_swapImage()
// ----------------------------------------------------------
function MM_swapImage() { //v3.0
  var i,j=0,x;
  var a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3){
   	if ((x=MM_findObj(a[i]))!=null){
   	  document.MM_sr[j++]=x; 
	  if(!x.oSrc){
	    x.oSrc=x.src; 
	  }
	  x.src=a[i+2];
    }
  }	
}

// ----------------------------------------------------------
// FUNCTION: MM_swapImgRestore(
// ----------------------------------------------------------
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

// ----------------------------------------------------------------------
// 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/hspatent/content/publish/order_checkout.shtml";


gstCheckoutRecipient = "orders@hspatentelo.com";
gstCheckoutEmailCopies = "";
gstCheckoutSubject = "hspatentelo Online Order";
gstCheckoutConfirmScript ="https://www42.fatcow.com/hspatent/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;
}