// Rollover Function
CSStopExecution = false;
CSInit = new Array;
function CSScriptInit() {
idxArray = new Array;
for(var i=0;i<CSInit.length;i++)
	idxArray[i] = i;
CSAction2(CSInit, idxArray);
}
CSAg = window.navigator.userAgent; CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);
function IsIE() { return CSAg.indexOf("MSIE") > 0;}
function CSIEStyl(s) { return document.all.tags("div")[s].style; }
function CSNSStyl(s) { return CSFindElement(s,0); }
function CSFindElement(n,ly) { if (CSBVers < 4) return document[n];
	var curDoc = ly ? ly.document : document; var elem = curDoc[n];
	if (!elem) { for (var i=0;i<curDoc.layers.length;i++) {
		elem = CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}
	return elem;
}
function CSButtonReturn () {
	var bAgent = window.navigator.userAgent; 
	var bAppName = window.navigator.appName;
	if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))
		return false; // follow link
	else return true; // follow link
}
CSIm = new Object();
function CSIShow(n,i) {
	if (document.images) {
		if (CSIm[n]) {
			var img = (!IsIE()) ? CSFindElement(n,0) : document[n];
			if (img && typeof(CSIm[n][i].src) != "undefined") {img.src = CSIm[n][i].src;}
			if(i != 0)
				self.status = CSIm[n][3];
			else
				self.status = " ";
			return true;
		}
	}
	return false;
}
function CSILoad(action) {
	im = action[1];
	if (document.images) {
		CSIm[im] = new Object();
		for (var i=2;i<5;i++) {
			if (action[i] != '') { CSIm[im][i-2] = new Image(); CSIm[im][i-2].src = action[i]; }
			else CSIm[im][i-2] = 0;
		}
		CSIm[im][3] = action[5];
	}
}
CSStopExecution = false;

function CSAction(array) { 
	return CSAction2(CSAct, array);
}
function CSAction2(fct, array) { 
	var result;
	for (var i=0;i<array.length;i++) {
		if(CSStopExecution) return false; 
		var actArray = fct[array[i]];
		var tempArray = new Array;
		for(var j=1;j<actArray.length;j++) {
			if((actArray[j] != null) && (typeof(actArray[j]) == "object") && (actArray[j].length == 2)) {
				if(actArray[j][0] == "VAR") {
					tempArray[j] = CSStateArray[actArray[j][1]];
				}
				else {
					if(actArray[j][0] == "ACT") {
						tempArray[j] = CSAction(new Array(new String(actArray[j][1])));
					}
				else
					tempArray[j] = actArray[j];
				}
			}
			else
				tempArray[j] = actArray[j];
		}			
		result = actArray[0](tempArray);
	}
	return result;
}
CSAct = new Object;

function CSGotoLink(action) {
	if (action[2].length) {
		var hasFrame=false;
		for(i=0;i<parent.frames.length;i++) { if (parent.frames[i].name==action[2]) { hasFrame=true; break;}}
		if (hasFrame==true)
			parent.frames[action[2]].location = action[1];
		else
			window.open (action[1],action[2],"");
	}
	else location = action[1];
}

// Pop-up Function 1
function CSOpenWindow(action) {
	var wf = "";	
	wf = wf + "width=" + action[3];
	wf = wf + ",height=" + action[4];
	wf = wf + ",resizable=" + (action[5] ? "yes" : "no");
	wf = wf + ",scrollbars=" + (action[6] ? "yes" : "no");
	wf = wf + ",menubar=" + (action[7] ? "yes" : "no");
	wf = wf + ",toolbar=" + (action[8] ? "yes" : "no");
	wf = wf + ",directories=" + (action[9] ? "yes" : "no");
	wf = wf + ",location=" + (action[10] ? "yes" : "no");
	wf = wf + ",status=" + (action[11] ? "yes" : "no");		
	window.open(action[1],action[2],wf);
}

// Pop-up function 2
function CSURLPopupShow(formName, popupName, target) {
	var form  = CSFindElement(formName);
	var popup = form.elements[popupName];
	window.open(popup.options[popup.selectedIndex].value, target);
	popup.selectedIndex = 0;
}

// Macromedia Functions
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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;
}

function MM_findObj(n, d) { //v4.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);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,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];}
}

// onLoad="MM_preloadImages('Images/entersite2.gif')"
// <a href="/fordgt/home.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('enter','','Images/entersite2.gif',1)"><img src="Images/entersite.gif" width="123" height="22" alt="ENTER SITE  &gt;&gt;" name="enter" border="0"></a>

// Confirm Delete Order
function askDelete(idOrder) {
  if(!window.confirm("Are you sure you want to delete Order " + idOrder + "?")) 
	return false;
  return true;	
}
function checkDeleteOrder(idOrder) {
	if (askDelete(idOrder)) {
		document['delform'].idOrder.value = idOrder;
		document['delform'].submit();
	}
}
function checkAllBoxes(fm) {
	cbs = fm.elements;
	allchecked = true;
	for (i = 0; i < cbs.length; i++) {
		if (cbs[i].name == "idOrder")
			allchecked = allchecked && cbs[i].checked;
	}
	for (i = 0; i < cbs.length; i++) {
		if (cbs[i].name == "idOrder")
			cbs[i].checked = ! allchecked;
	}
}
function findChecked(fm) {
	cbs = fm.elements;
	for (i = 0; i < cbs.length; i++) {
		if (cbs[i].name == "idOrder")
			if (cbs[i].checked)
				return true;
	}
	return false;
}

function askDeleteBasketItem(Item) {
  if(!window.confirm("Are you sure you want to delete " + Item + " from this order?")) 
	return false;
  return true;	
}

// Confirm Delete User
function askDeleteUser(idUser) {
  if(!window.confirm("Are you sure you want to delete User " + idUser + "?")) 
	return false;
  return true;	
}

// Confirm Delete Order
function askDeleteAddress(idAddress) {
  if(!window.confirm("Are you sure you want to delete User Address " + idAddress + "?")) 
	return false;
  return true;	
}

// Confirm Delete Cat
function askDeleteCat(CatTitle) {
  if(!window.confirm("Are you sure you want to delete the " + CatTitle + " category?")) 
	return false;
  return true;	
}

// Confirm Delete WS
function askDeleteWS(Title) {
  if(!window.confirm("Are you sure you want to delete the " + CatTitle + " wholesale pricing?")) 
	return false;
  return true;	
}

// Menu Items Rollover
function showItem(title,text,image,evt){

	with (document.getElementById('Item').style){
		
		str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"320\">";
		str +=	"<tr>";
		str +=	"		<td bgcolor=\"#528318\">";
		str +=	"			<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"318\">";
		str +=	"				<tr>";
		str +=	"					<td bgcolor=\"#FFFFFF\" align=\"center\">";
		str +=	"						<table border=\"0\" cellspacing=\"6\" cellpadding=\"0\" width=\"314\">";
		str +=	"							<tr>";
		if (image){
			str +=	"							<td width=\"120\">";
			str +=	"								<div class=\"small\">";
			str +=	"									<img src=\"/images/food/small/" + image + "\" width=\"120\">";
			str +=	"								</div>";
			str +=	"							</td>";
		}
		str +=	"								<td valign=\"top\">";
		str +=	"									<div class=\"small\">";
		if (text) {
			str +=	"										<font color=\"#999966\"><b>" + title + "</b></font><br>";
			str +=	"										<font color=\"#999966\">" + text + "</font></div>";
		}
		else {
			str +=	"										<font color=\"#999966\"><b>NO TEXT</b></font></div>";
		}
		str +=	"								</td>";
		str +=	"							</tr>";
		str +=	"						</table>";
		str +=	"					</td>";
		str +=	"				</tr>";
		str +=	"			</table>";
		str +=	"		</td>";
		str +=	"	</tr>";
		str +=	"</table>";
		str += "<br>";
	
		
		visibility = 'visible';
		document.getElementById('Item').innerHTML = str;
		
		if (document.all){

			left = evt.x;
			top = evt.y + (document.body.scrollTop + 10);

		}

		else{

			left = evt.pageX;
			top = evt.pageY;

		}
		
	}

}
		
// Hide Menu Items Rollover
function hideItem(){

		document.getElementById('Item').style.visibility='hidden';

}

// Hide Div Pass - Replace top if neccessary
function hideDiv(idDiv){
		document.getElementById(idDiv).style.visibility='hidden';
}
function showDiv(idDiv){
		document.getElementById(idDiv).style.visibility='visible';
}

// ValidateField
// Use this onBlur="checkInput(this)" in input tag
function checkInput(element) {
  if (element.value == "")
    alert("Please enter a value!");
}

function IsANumber(formField)
{
var valid = "0123456789."
var ok = "yes";
var temp;

	for (var i=0; i < formField.value.length; i++)
	{
		temp = "" + formField.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
		return false;
	}
}


function ValidateOnBlur(formField, minimumAllowed)
{
	if (IsANumber(formField) == false)
	{
		//alert("Please enter a number.");
		formField.focus();
		formField.select();
		return;
	}
	if (formField.value < minimumAllowed && formField.value != 0)
	{
		{
			alert("There is a minimum order of " + minimumAllowed + " for this item.");
		}
		formField.focus();
		formField.select();
		return;
	}
}

function add_ItemTotal(fldQty,fldPrice,fldSPrice,fldITotal) {
	var iTotal;
	var q = fldQty.value;
	var op = fldPrice.value;
	var sp = fldSPrice.value;
	
	if (sp > 0){
		iTotal = parseFloat(Math.round((q * sp)*100)/100)
	}
	else {
		iTotal = Math.round((q * op)*100)/100
	}
	
	fldITotal.value = iTotal;
	document.forms.frmModify.txtOrderSubTotal.focus();
	return iTotal;
}

function add_Weight(fldQty,fldWeight,fldTWeight) {
	var iTotal;
	var q = fldQty.value;
	var w = fldWeight.value;
	
	iTotal = Math.round((q * w)*100)/100
	
	fldTWeight.value = iTotal;
	return;
}

function add_SubTotal() {
	var loop=0, sum=0;
	for (loop = arguments.length-1; loop>=0; loop--)
		sum += parseFloat(arguments[loop]);
	if (document.forms.frmModify.AddProductName.value != "")
		sum += parseFloat(document.forms.frmModify.AddProductTotalPrice.value);
	
	document.forms.frmModify.txtOrderSubTotal.value = Math.round(sum*100)/100;
	document.forms.frmModify.txtOrderTotal.focus();
	return;
}

function add_Total() {
	var loop=0, sum=0;
	for (loop = arguments.length-1; loop>=0; loop--)
		sum += parseFloat(arguments[loop]);
	
	document.forms.frmModify.txtOrderTotal.value = Math.round(sum*100)/100;
	return;
}

function delaySubmit() {
	document.getElementById("itemssubmit").focus();
	setTimeout("document.forms[0].submit();", 100);
}

function finalCheck(formField) {
    var proceed = true
    proceed = IsANumber(formField)
    if (!proceed)
		formField.focus();
		formField.select();
		return false;
		return proceed;
}

// Beginning of Address Script

    function Location(pId, pLabel, pCompany, pAddress, pCity, pState, pZip, pResidence, pPhone, pFax, pCountry) {
        this.pId = pId;
        this.pLabel = pLabel;
        this.pCompany = pCompany;
        this.pAddress = pAddress;
        this.pCity = pCity;
        this.pState = pState;
        this.pZip = pZip;
        this.pResidence = pResidence;
        this.pPhone = pPhone;
        this.pFax = pFax;
        this.pCountry = pCountry;
    }

    //function sets APARTMENT field to null if NONE is checked
    function pj_set_APARTMENT() {
        if (document.form1.apt_code[3].checked) {
            document.form1.apt_code_ext.value = "";
            document.form1.city.focus();
        }
    }

    function changeAddress() {
        var f = document.forms[0];
        var i;
        var val = f.location_id.options[f.location_id.selectedIndex].value;

        var cnt;
        var found = false;
        for (cnt = 0; !found && cnt < locations.length; cnt++) {
            if (locations[cnt].pId == val) {
              found = true;
            }
        }
        cnt = cnt - 1;
        if (found) {
            populateScreen(cnt);
        }
        else {
            clearScreen();
        }
    }

    function clearScreen() {
        var f = document.forms[0];
        document.form1.txtShipCompany.value     = "";
        document.form1.txtShipAddress.value     = "";
        document.form1.txtShipCity.value        = "";
        document.form1.txtShipState.value       = "";
        document.form1.txtShipZip.value			= "";
        document.form1.txtShipPhone.value       = "";
        document.form1.txtShipFax.value         = "";
        document.form1.txtShipCountry.value     = "";
        document.form1.txtLocationTitle.value   = "";

        for (i = 0; i < f.rbHomeDelivery.length; i++) {
            f.rbHomeDelivery[i].checked = false;
        }
        //document.getElementById('lTitle').style.visibility='visible';
        //document.getElementById('lField').style.visibility='visible';
    }

    function populateScreen(cnt) {
        var f = document.forms[0];
        document.form1.txtShipCompany.value     = locations[cnt].pCompany;
        document.form1.txtShipAddress.value     = locations[cnt].pAddress;
        document.form1.txtShipCity.value        = locations[cnt].pCity;
        document.form1.txtShipState.value       = locations[cnt].pState;
        document.form1.txtShipZip.value			= locations[cnt].pZip;
        document.form1.txtShipPhone.value       = locations[cnt].pPhone;
        document.form1.txtShipFax.value         = locations[cnt].pFax;
        document.form1.txtShipCountry.value     = locations[cnt].pCountry;
        document.form1.txtLocationTitle.value   = locations[cnt].pLabel;
		
        //document.getElementById('lTitle').style.visibility='hidden';
        //document.getElementById('lField').style.visibility='hidden';
		
        // set rbHomeDelivery/TRUE/FALSE
        for (i=0; i< f.rbHomeDelivery.length; i++) {
            f.rbHomeDelivery[i].checked = (f.rbHomeDelivery[i].value == locations[cnt].pResidence);
        }
    }
// End of Address Script


// Array for Rollovers
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_home',/*URL*/'/images/nav/btn_home_off.gif',/*URL*/'/images/nav/btn_home_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_products',/*URL*/'/images/nav/btn_products_off.gif',/*URL*/'/images/nav/btn_products_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_saltinfo',/*URL*/'/images/nav/btn_saltinfo_off.gif',/*URL*/'/images/nav/btn_saltinfo_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_wholesale',/*URL*/'/images/nav/btn_wholesale_off.gif',/*URL*/'/images/nav/btn_wholesale_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_news',/*URL*/'/images/nav/btn_news_off.gif',/*URL*/'/images/nav/btn_news_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_aboutus',/*URL*/'/images/nav/btn_about_off.gif',/*URL*/'/images/nav/btn_about_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_contact',/*URL*/'/images/nav/btn_contact_off.gif',/*URL*/'/images/nav/btn_contact_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_customers',/*URL*/'/images/nav/btn_customers_off.gif',/*URL*/'/images/nav/btn_customers_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_viewcart',/*URL*/'/images/nav/btn_viewcart_off.gif',/*URL*/'/images/nav/btn_viewcart_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_gourmet',/*URL*/'/images/home/home_gourmet_off.gif',/*URL*/'/images/home/home_gourmet_on.gif',/*URL*/'','Gourmet Salts');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_bathspa_home',/*URL*/'/images/home/home_bathspa_off.gif',/*URL*/'/images/home/home_bathspa_on.gif',/*URL*/'','Bath & Spa Salts');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_g_retail',/*URL*/'/images/home/g_retail.gif',/*URL*/'/images/home/g_retail_on.gif',/*URL*/'','Retail Gourmet Salts');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_g_bulk',/*URL*/'/images/home/g_bulk.gif',/*URL*/'/images/home/g_bulk_on.gif',/*URL*/'','Bulk Gourmet Salts');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_HD',/*URL*/'/images/frames/hd_logo_off.gif',/*URL*/'/images/frames/hd_logo_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_gourmet',/*URL*/'/images/home/btn_gourmet_off.gif',/*URL*/'/images/home/btn_gourmet_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_gourmetsalts',/*URL*/'/images/home/btn_gourmetsalts_off.gif',/*URL*/'/images/home/btn_gourmetsalts_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_bathspasalts',/*URL*/'/images/home/btn_bathspasalts_off.gif',/*URL*/'/images/home/btn_bathspasalts_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_enterresource',/*URL*/'/images/home/btn_enterresource_off.gif',/*URL*/'/images/home/btn_enterresource_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_bathspa',/*URL*/'/images/home/btn_bathspa_off.gif',/*URL*/'/images/home/btn_bathspa_on.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'btn_Inc500Rank',/*URL*/'/images/home/btn_Inc500Rank_off.gif',/*URL*/'/images/home/btn_Inc500Rank_on.gif',/*URL*/'','');

// Array for button controls
CSAct[/*CMP*/ 'EmptyBasket'] = new Array(CSGotoLink,/*URL*/ '/shop/emptybasket.asp','');
CSAct[/*CMP*/ 'CheckOut'] = new Array(CSGotoLink,/*URL*/ '/shop/SignIn.asp?action=shipping','');

// Popup Arrays
CSAct['HOWTOORDER'] = new Array(CSOpenWindow,'/shop/p_HowToOrder.html','',470,400,false,true,false,false,false,false,false);


function setPresetDate(fm, val) {
	today = new Date();
	if (val == "Today") {
		sdate = today;
		edate = sdate;
	} else if (val == "Yesterday") {
		sdate = new Date(today.getTime() - 86400000);
		edate = sdate;
	} else if (val == "3Days") {
		sdate = new Date(today.getTime() - 86400000 * 2);
		edate = today;									
	} else if (val == "7Days") {
		sdate = new Date(today.getTime() - 86400000 * 6);
		edate = today;
	} else if (val == "Month") {
		sdate = new Date(today.getFullYear(), today.getMonth());
		edate = today;
	} else if (val == "Year") {
		sdate = new Date(today.getFullYear(), 0);
		edate = today;
	} else if (val == "All") {
		sdate = new Date(2002, 0);
		edate = today;
	}
	fm.sMonth.value = sdate.getMonth() + 1;
	fm.sDay.value = sdate.getDate();
	fm.sYear.value = sdate.getFullYear();
	fm.eMonth.value = edate.getMonth() + 1;
	fm.eDay.value = edate.getDate();
	fm.eYear.value = edate.getFullYear();
}

function resetDatePreset(fm) {
	fm.DatePreset[0].selected = true;
}

maskfocus = false;

function repeat(str, i) {
	r = "";
	for (n = 0; n < i; n++)
		r += str;
	return r;
}

function popAddress(fm, pre, id) {
	address = addresses[id].split(",");
	eval("fm.txt" + pre + "Address1.value = address[0];");
	eval("fm.txt" + pre + "City.value = address[1];");
	eval("fm.dd" + pre + "State.value = address[2];");
	eval("fm.txt" + pre + "Zip.value = address[3];");
	eval("fm.txt" + pre + "Country.value = address[4];");
}

function dateField(formfield) {
	if (formfield.value != "") {
		s1 = formfield.value.indexOf(" ");
		if (s1 >= 0) {
			d = new Date(formfield.value.substring(0, s1));
			s2 = d.toString().indexOf(" ", 8)
			formfield.value = d.toString().substring(4, s2) + " " + d.getFullYear() + formfield.value.substring(s1);
		}
		d = new Date(formfield.value);
		if (d.getFullYear() >= 1900 && d.getFullYear() <= 1969)
			d.setYear(d.getFullYear() + 100);
		if (isNaN(d) || d.getFullYear() < 1970)
			formfield.value = "";
		else {
			hour = d.getHours();
			if (hour < 12) {
				hour_str = hour == 0 ? "12" : hour;
				ampm_str = "AM";
			} else {
				hour_str = hour == 12 ? "12" : hour - 12;
				ampm_str = "PM";
			}
			min_str = d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes();
			sec_str = d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds();
			if (d - new Date((d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getFullYear()) == 0)
				sec_str = "01";
			formfield.value = (d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getFullYear() + " " + hour_str + ":" + min_str + ":" + sec_str + " " + ampm_str;
		}
	}
}

function getWholesale(id, qty, wt) {
	for (i = qty; i > 0; --i) {
		if (wholesalearray[id][i])
			return wholesalearray[id][i] * wt;
	}
	return wholesalearray[id][0];
}
function setProduct(row, fm, prodchange, spchange) {
	infoarray = eval("fm.product_" + row).value.split("|");
	idfld = eval("fm.productid_" + row);
	nmfld = eval("fm.productname_" + row);
	qtyfld = eval("fm.qty_" + row);
	wtfld = eval("fm.weight_" + row);
	totwtfld = eval("fm.totalweight_" + row);
	prfld = eval("fm.price_" + row);
	salefld = eval("fm.saleprice_" + row);
	totprfld = eval("fm.totalprice_" + row);
	customname = eval("fm.productname_custom_" + row);
	customwt = eval("fm.weight_custom_" + row);
	custompr = eval("fm.price_custom_" + row);
	id = infoarray[0];
	iscustom = (id == "0");
	nm = infoarray[1];
	qt = new Number(qtyfld.value);
	pr = (iscustom && ! prodchange ? custompr.value : infoarray[2]);
	wt = (iscustom && ! prodchange ? customwt.value : infoarray[4]);
	sp = (wholesalearray[id] && ! spchange ? getWholesale(id, qt, wt) : (prodchange ? infoarray[3] : salefld.value));
	sp = (isNaN(sp) ? 0 : sp);
	if (qtyfld.value == "")
		qtyfld.value = "1";
	if (isNaN(qt))
		qt = 0;
	qtyfld.value = qt;
	document.getElementById("custom_" + row).style.display = (iscustom ? "block" : "none");
	document.getElementById("wt_" + row).style.display = (iscustom ? "none" : "block");
	document.getElementById("weight_custom_" + row).style.display = (iscustom ? "block" : "none");
	document.getElementById("pr_" + row).style.display = (iscustom ? "none" : "block");
	document.getElementById("price_custom_" + row).style.display = (iscustom ? "block" : "none");
	if (eval("fm.product_" + row).value != "") {
		idfld.value = id;
		if (row == "new")
			document.getElementById("id_" + row).innerHTML = id;
		nmfld.value = nm;
	//	alert(nm);
		customname.value = (! iscustom ? nm : customname.value);
		wtfld.value = numberFormat(wt);
		customwt.value = numberFormat(wt);
		document.getElementById("wt_" + row).innerHTML = numberFormat(wt);
		totwtfld.value = numberFormat(wt * qt);
		document.getElementById("totwt_" + row).innerHTML = numberFormat(wt * qt);
		prfld.value = dollarFormat(pr);
		custompr.value = dollarFormat(pr);
		document.getElementById("pr_" + row).innerHTML = dollarFormat(pr);
		salefld.value = dollarFormat(sp);
		document.getElementById("totpr_" + row).innerHTML = dollarFormat((sp == 0 ? pr : sp) * qt);
		totprfld.value = dollarFormat((sp == 0 ? pr : sp) * qt);
	} else {
		idfld.value = "";
		if (row == "new")
			document.getElementById("id_" + row).innerHTML = "";
		nmfld.value = "";
		customname.value = "";
		wtfld.value = "";
		customwt.value = "";
		document.getElementById("wt_" + row).innerHTML = "";
		totwtfld.value = "";
		document.getElementById("totwt_" + row).innerHTML = "";
		prfld.value = "";
		custompr.value = "";
		document.getElementById("pr_" + row).innerHTML = "";
		salefld.value = "";
		document.getElementById("totpr_" + row).innerHTML = "";
		totprfld.value = "";
	}
	doTotals(fm);
}
function doTotals(fm) {
	st = 0;
	wt = 0;
	newitem = new Number(fm.totalprice_new.value);
	if (! isNaN(newitem))
		st += newitem;
	newwt = new Number(fm.totalweight_new.value);
	if (! isNaN(newwt))
		wt += newwt;
	for (i = 0; i < itemarray.length; i++) {
		thisitem = new Number(eval("fm.totalprice_" + itemarray[i] + ".value"));
		if (! isNaN(thisitem))
			st += thisitem;
		thiswt = new Number(eval("fm.totalweight_" + itemarray[i] + ".value"));
		if (! isNaN(thiswt))
			wt += thiswt;
	}
	document.getElementById("subtotal").innerHTML = dollarFormat(st);
	fm.txtOrderSubTotal.value = dollarFormat(st);
	document.getElementById("tot_wt").innerHTML = numberFormat(wt);
	tot = st;
	ship = new Number(fm.txtOrderShipping.value);
	if (! isNaN(ship)) {
		tot += ship;
		fm.txtOrderShipping.value = dollarFormat(ship);
	} else fm.txtOrderShipping.value = dollarFormat(0);
	tax = new Number(fm.txtOrderTax.value);
	if (! isNaN(tax)) {
		tot += tax;
		fm.txtOrderTax.value = dollarFormat(tax);
	} else fm.txtOrderTax.value = dollarFormat(0);
	document.getElementById("grandtotal").innerHTML = dollarFormat(tot);
	fm.txtOrderTotal.value = dollarFormat(tot);
}
function dollarFormat(val) {
	val = (isNaN(val) ? 0 : val);
	val = new String(numberFormat(val));
	if (val.indexOf(".") < 0)
		return val + ".00";
	else return (val + "00").substring(0, val.indexOf(".") + 3);
}
function numberFormat(val) {
	val = (isNaN(val) ? 0 : val);
	return Math.round(val * 100) / 100;
}
function reAuthCheck(fm, fm2) {
	confmsg = "You are submitting a " + (fm.x_Test_Request.value == "True" ? "test " : "") + "transaction to Authorize.net for user '" + fm.x_First_Name.value + " " + fm.x_Last_Name.value + "'.\n";
	confmsg += "Please confirm the following:\n\n";	
	subtot = parseFloat(fm.x_Subtotal.value.replace(/,/g,""));	
	shipping = parseFloat(fm.x_Shipping.value.replace(/,/g,""));
	tax = parseFloat(fm.x_Tax.value.replace(/,/g,""));
	tot = parseFloat(fm.x_Amount.value.replace(/,/g,""));	
	confmsg += "\tSubtotal:\t$" + dollarFormat(subtot) + (dollarFormat(subtot) != dollarFormat(fm2.txtOrderSubTotal.value) ? "\t\tALERT: Does not match form subtotal value of $" + dollarFormat(fm2.txtOrderSubTotal.value) : "") + "\n";
	confmsg += "\tShipping:\t$" + dollarFormat(shipping) + (dollarFormat(shipping) != dollarFormat(fm2.txtOrderShipping.value) ? "\t\tALERT: Does not match form shipping value of $" + dollarFormat(fm2.txtOrderShipping.value) : "") + "\n";
	confmsg += "\tTax:\t$" + dollarFormat(tax) + (dollarFormat(tax) != dollarFormat(fm2.txtOrderTax.value) ? "\t\tALERT: Does not match form tax value of $" + dollarFormat(fm2.txtOrderTax.value) : "") + "\n";
	confmsg += "\tTotal:\t$" + dollarFormat(tot) + (dollarFormat(tot) != dollarFormat(fm2.txtOrderTotal.value) ? "\t\tALERT: Does not match form total value of $" + dollarFormat(fm2.txtOrderTotal.value) : "") + "\n\n";
	confmsg += "If this is not correct, or there are form discrepancies, please hit 'Cancel', fix the values and hit 'Submit' to \nsave the data, and then Re-Authorize this transaction.";
	return confirm(confmsg);
}