/*
TEES:         S  M  L  XL

HOODIES:      S  M  L  XL

SHORTS:        XS  S  M  L

CAMIS:            S  M  L

DOGGIES:    M  L  XL  2XL 

LOAD DATA INFILE '/var/tmp/php3aAWLf' REPLACE INTO TABLE `products`
FIELDS TERMINATED BY ';'
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n' 

*/
var nVer = navigator.appVersion;
var nUser = navigator.userAgent;
var win = ( nVer.indexOf( 'Win' ) != -1 );
var mac = ( nVer.indexOf( 'Mac' ) != -1 );
var linux = ( nUser.indexOf( 'Linux' ) != -1 );
var dom = (document.getElementById);
if (!dom) dom = false; else dom = true;
var opera = (nUser.indexOf ('Opera') != -1);
var konq = (nUser.indexOf ('Konqueror') != -1);
var safari = (nUser.indexOf ('Safari') != -1);
var mozilla = (nUser.indexOf ('Gecko') != -1 && !safari && !konq);
var ie = (document.all && !opera);
if (!ie) ie = false; else ie = true;
var ie4 = (ie && !dom);
var ie5x = (document.all && dom);
if (!ie5x) ie5x = false; else ie5x = true;
var ie5mac = (mac && ie5x);
var ie5xwin = (win && ie5x);

var state = "visible";
var dispControl;
if (!ie)
{
	dispControl = "table-row";
	cellMode = "table-cell";
}
else 
{
	dispControl = "block";
	cellMode = "inline";
}
var selectedObject = "";
var cartMode = true;
var dispMode = dispControl;
var numImages = 9;
var nStores = 9;
var storeImages = new Array (numImages);
var miniImages = new Array (numImages);
var pageHistory = new Array ();
var historyIndex;
var tBrowsing = false;
var iBrowsing = false;
var pBrowsing = false;
var storeIndex = -1;
var currCartMode = "cat";
var transQty = 0;
var transID = "";
var transMode = "";
//var NYTax = .0975;
//var FLTax = .07;
var thumbs = new Array ("/images/Hoody.gif",
						"/images/teeBack.gif",
						"/images/LSBackMini.gif",
						"/images/Cami.gif",
						"/images/blueshortsFixed.gif",
						"/images/BBQApron.gif",
						"/images/blkbag.gif",
						"/images/doggytee.gif",
						"/images/Mug.gif");
var divID = new Array ("hoody", "teeshirt", "shirts", "camis", "shorts",
					   "aprons", "bags", "dogs", "mugs");
var spanID = new Array ("hoodyLabel", "teeshirtLabel", "shirtsLabel", "camisLabel", 
						"shortsLabel", "apronsLabel", "bagsLabel", "dogsLabel", "mugsLabel");
var storePic = new Array ("nHoody.gif", "nTee.gif",  "nShirt.gif",  "nCami.gif", 
				"nShorts.gif",  "nApron.gif",  "nBags.gif",  
				"nDog.gif", "nMugs.gif");
//var storePrice = new Array ("$39.99", "$19.99", "$23.99", 
//							"$12.99", "$12.99", "$18.99", "$19.99", "$21.99", "$18.99");
var content = new Array ("Hooded Sweatshirt", "Teeshirt", "Longsleeve Shirt",
						 "Ladies' Camis", "Ladies' Shorts", "BBQ Apron", 
						 "Beach Bag", "Doggy Tee", "Beer Mug");
var active = new Array (true,true,false,false,false,true,true,true,true);
var mItemsIdx = new Array (thumbs, divID, spanID, storePic, content, active);
var mContentAssoc = new Array;
mContentAssoc ["hoody"] = "Hooded Sweatshirt";
mContentAssoc ["teeshirt"] = "Teeshirt";
mContentAssoc ["shirts"] = "Longsleeve Shirt";
mContentAssoc ["camis"] = "Ladies' Cami";
mContentAssoc ["shorts"] = "Ladies' Shorts";
mContentAssoc ["aprons"] = "BBQ Apron";
mContentAssoc ["bags"] = "Beach Bag";
mContentAssoc ["dogs"] = "Doggy Tee";
mContentAssoc ["mugs"] = "Beer Mug";

var mPendingAssoc = new Array;
mPendingAssoc ["hoody"] = false;
mPendingAssoc ["teeshirt"] = false;
mPendingAssoc ["shirts"] = false;
mPendingAssoc ["camis"] = false;
mPendingAssoc ["shorts"] = false;
mPendingAssoc ["aprons"] = false;
mPendingAssoc ["bags"] = false;
mPendingAssoc ["dogs"] = false;
mPendingAssoc ["mugs"] = false;

var mItemsAssoc = new Array;
mItemsAssoc ["thumbs"] = thumbs;
mItemsAssoc ["divID"] = divID;
mItemsAssoc ["spanID"] = spanID;
mItemsAssoc ["storePic"] = storePic;
mItemsAssoc ["content"] = content;
mItemsAssoc ["active"] = active;

var sizeCode = new Array;
sizeCode ["XX-Small"] = "A";
sizeCode ["X-Small"] = "B";
sizeCode ["Small"] = "C";
sizeCode ["Medium"] = "D";
sizeCode ["Large"] = "E";
sizeCode ["X-Large"] = "F";
sizeCode ["XX-Large"] = "G";
sizeCode ["One Size"] = "Z";

var mEntry1 = new Entry ("orders", "Orders", "cgi-bin/query.php", null);
var mEntry2 = new Entry ("products", "Products", "productquery.php", null);
var mEntry3 = new Entry ("upsentry", "Enter Ups Data", "ups.php", null);
var mEntry4 = new Entry ("cust", "Customer Report", "customer.php", null);
var mEntry5 = new Entry ("city", "Sales by City", "SalesWork.php", null);
var mEntry6 = new Entry ("map", "State Sales Map", "pending.htm", null);

var mainEntries = new Array (mEntry1, mEntry2);

function testblargh (min, max)
{
	if (min < 10) alert ("huhuh");
}
function Menu (id, title, entries)
{
	this.id = id;
	this.title = title;
	this.entries = entries;
	this.Create = Create;
	this.Place = Place;
	this.ShowTitle = ShowTitle;
}
function Create ()
{
	alert ("Create method");
}
function Place ()
{
	document.write ('<div class="drop"><div class="contents" id="' + this.id + '">');
	for (i = 0; i < this.entries.length; i++)
	{
		if (this.entries [i].eType == "page")
		{
			//alert (' onclick="Click \(\"' + this.entries [i].eType + '\")";>');
			document.write ('<div class="section" id="' + this.id + '-' + i + '"' +
						' onclick="Click (' + i + ')";>');
			document.write (this.entries [i].text);
			document.write ('</div>');
		}
		else
		{
			placeSub (this.entries [i]);
		}
							
	}
	document.write ('</div></div>');
}

function placeSub (subMenu)
{
	alert (subMenu.title);
}

function ShowTitle ()
{
	document.getElementById (this.id).innerHTML = "<center><b>" + this.title + "</b></center>";
}
function Click (index)
{
	//alert (index);
	location = mainMenu.entries [index].page;
}
function Entry (id, text, page, menu)
{
	this.id = id;
	this.text = text;
	if (page != null) 
	{
		this.eType = "page";
		this.page = page;
	}else{
		this.eType = "menu";
		this.menu = menu;
	}
	/*
	alert (page);
	this.Click = function (page)
	{
		alert (page);
	}
	*/
}
function goPage (page)
{
	switch (page)
	{
		case "home": location.href = "SalesData.php"; break;
		case "sales": location.href = "SalesWork.php"; break;
		case "ups": location.href = "ups.php"; break;
		case "cust": location.href = "customer.php"; break;
		case "upsreport": location.href = "upsreport.php"; break;
		case "ifhelp": location.href = "ifhelp.php"; break;
	}
}
function buildStore (store)
{
//	document.write (eval (store + "Page"));
}
function loadImages ()
{
	var i;
//	alert ("load images");
	for (i = 0; i < numImages; i++)
	{
		miniImages [i] = new Image ();
		miniImages [i].src = thumbs [i];
		storeImages [i] = new Image ();
		storeImages [i].src = "/images/" + storePic [i];
//		alert (miniImages [i].src);
	}
	selectImage = new Image ();
	happyImage = new Image ();
	selectImage.src = "/images/selectClam.gif";
	happyImage.src = "/images/happyClam.gif";
}
function makeMenu ()
{
	var i;
	var nItems = 0;
	document.write ('<table id="Frame" border="0" align="center" ' +
					'onMouseOver="tBrowse (\'on\');" ' +
				 	'onMouseOut="tBrowse (\'off\');"><tr><td align="center">');
	for (i = 0; i < numImages; i++) active [i] = false;
	for (i = 0; i < products.length; i++)
	{
		active [parseInt (products [i][1].substr (4, 1))-1] = true;
	}
	for (i = 0; i < numImages; i++) if (active [i] == true) nItems++;
	var ratio = numImages/nItems;
	
	for (i = 0; i < numImages; i++)
	{
		if (active [i] == false) continue;
		document.write ('<div align="center" class="Goodies" id="' + divID [i] + '">' +
						'<span id="' + spanID [i] + '" style="cursor: pointer; ' +
						'font-weight: bold;" ' +
						'onClick="changePage (' + i + ', 0);" ' +
						'onmouseover="showMiniItem (\'' + divID [i] + '\', ' +
						'miniImages [' + i + '], \'over\');" ' +
						'onmouseout="showMiniItem (\'' + divID [i] + '\', ' +
						'\'\', \'out\');"> ' + content [i] + '</span></div>');
		document.getElementById (divID [i]).style.lineHeight = 1.5 * ratio;
	}
	document.write ('</td></tr></table>');
	//document.getElementById ("
}
function changePage (index, source)
{
	//alert ("change page");
	var tTitle = "Cop-A-Clam-a-tude";
	var oObj;
	var cObj;
	var hObj = document.getElementById ("leftPane");
	var tObj = document.getElementById ("tablebody");
	var pObj = document.getElementById ("price");
	hideCart ();
	if (storeIndex >= 0)
	{
		// Currently showing another store
		// Hide the current store image
		oObj = document.getElementById ("store");
		oObj.style.visibility = "hidden";
		oObj.style.display = "none";
		tTitle += " -- " + mContentAssoc [divID [index]];
	}
	if (index >= 0)
	{
		// Store, not home
		// Put the store image in the entire left pane
		hObj.style.backgroundImage = "url('" + "/images/" + storePic [index] + "')";
//		alert (hObj.style.backgroundImage);
		hObj.style.backgroundPosition = "left";
		// Put in the watermark in the page-wide pane
		tObj.style.backgroundImage = "url('/images/NewWater.jpg')";
		tObj.style.backgroundRepeat = "no-repeat";
		tObj.style.backgroundPosition = "center";
		pObj.innerHTML = storePrice [index];
		// Show the new store image
		cObj = document.getElementById ("store");
		cObj.style.visibility = "visible";
		cObj.style.display = "block";
	}
	else
	{
		// Home -- put in the bright logo
		hObj.style.backgroundImage = "url('/images/defaultClam.png')";
		hObj.style.backgroundPosition = "center";
		// Remove the watermark
		tObj.style.backgroundImage = "url('')";
	}
	document.title = tTitle;
	storeIndex = index;
	if (source == 0)
	{
		// Unilateral page selection.  Add to history at current position.
		if (historyIndex == pageHistory.length - 1)
		{
			if (pageHistory [historyIndex] != index) 
			{
				pageHistory.push (index);
				historyIndex++;
			}
		}
		else 
		{
			if ((pageHistory [historyIndex] != index) && 
				(pageHistory [historyIndex+1] != index))
			{
				pageHistory.splice ([historyIndex+1], 0, index);
				historyIndex++;
			}
		}
	}
	//alert (historyIndex + ' of ' + pageHistory.length);
	if (historyIndex > 0) switchArrows ('left', 'on');
	if (historyIndex < pageHistory.length - 1) switchArrows ('right', 'on');
}
function gohome ()
{
	changePage (-1, 0);
}

function showStore (dest)
{
	hideCart ();
	checkOut ('off', -1);
	if (dest == 1)
	{
		gohome ();
	}
	else
	{
		for (i = historyIndex; i > 0; i--)
		{
			if (pageHistory [i] < 100)
			{
				// Store found
				changePage (pageHistory [i], 1);
				historyIndex = i;
				return;
			}
		}
	}
	gohome ();
	return;
	var pObj = document.getElementById ("homePage");
	pObj.style.visibility = "visible";
	pObj.style.display = "block";
	pObj = document.getElementById ("catalog");
	pObj.style.visibility = "hidden";
	pObj.style.display = "none";
	if (dest == 1) gohome ();
}
function hideCart ()
{
	var pObj = document.getElementById ("homePage");
	pObj.style.visibility = "visible";
	pObj.style.display = "block";
	pObj = document.getElementById ("catalog");
	pObj.style.visibility = "hidden";
	pObj.style.display = "none";
}

function showCart (source)
{
//	alert ("show cart");
	var pObj = document.getElementById ("homePage");
	pObj.style.visibility = "hidden";
	pObj.style.display = "none";
	pObj = document.getElementById ("catalog");
	pObj.style.visibility = "visible";
	pObj.style.display = "block";
	pObj = document.getElementById ("cartString");
//	mPendingAssoc [storeIndex] = true;
	if (source == 0)
	{
		// Unilateral page selection.  Add to history at current position.
		if (historyIndex == pageHistory.length - 1)
		{
			if (pageHistory [historyIndex] != 100) 
			{
				pageHistory.push (100);
				historyIndex++;
			}
		}
		else 
		{
			if ((pageHistory [historyIndex] != 100) && 
				(pageHistory [historyIndex+1] != 100))
			{
				pageHistory.splice ([historyIndex+1], 0, 100);
				historyIndex++;
			}
		}
	}
	if (historyIndex > 0) switchArrows ('left', 'on');
	if (historyIndex < pageHistory.length - 1) switchArrows ('right', 'on');
//	alert (countProducts ());
	if (countProducts () == 0) 
	{
		switchCart ("cat");
		currCartMode = "cat";
		pObj.innerHTML = "<strong>Your Shopping Cart is Empty</strong>";
	}
	else 
	{
		//if (mPendingAssoc [storeIndex] == true) switchCart (storeIndex);
		//else switchCart (currCartMode);
		pObj.innerHTML = "<strong>Your Shopping Cart</strong>";	
	}
	pObj = document.getElementById ("gTotals");
	pObj.style.visibility = "hidden";
	pObj.style.display = "none";
	pObj = document.getElementById ("tTotals");
	pObj.style.visibility = "visible";
	pObj.style.display = "block";
	
	pObj = document.getElementById ("orderCrumbs");
	pObj.style.visibility = "hidden";
	pObj.style.display = "none";
	pObj = document.getElementById ("cartCrumbs");
	pObj.style.visibility = "visible";
	pObj.style.display = "block";
	pObj = document.getElementById ("carthead");
	pObj.style.visibility = "visible";
	pObj.style.display = "block";
	/*
	pObj = document.getElementById ("shipForm");
	pObj.style.visibility = "hidden";
	pObj.style.display = "none";
	*/
}
function countProducts ()
{
	var i;
	var count = 0;
	for (i = 0; i < nRows; i++)
	{
		count += parseInt (products [i][5]);
//		alert (parseInt (products [i][5]));
	}
	return count;
}
function goBack ()
{
	if (historyIndex == 0) return;
	historyIndex--;
	
	if (pageHistory [historyIndex] == 100) checkOut ('off', -1);
	else if (pageHistory [historyIndex] == 200) checkOut ('on', -1);
	else if (pageHistory [historyIndex] < 100) changePage (pageHistory [historyIndex], 1);
	if (historyIndex == 0) switchArrows ('left', 'off');
}
function goForward ()
{
	if (historyIndex == pageHistory.length - 1) return;
	historyIndex++;
	if (pageHistory [historyIndex] == 100) checkOut ('off', -1);
	else if (pageHistory [historyIndex] == 200) checkOut ('on', -1);
	else if (pageHistory [historyIndex] < 100) changePage (pageHistory [historyIndex], 1);
	if (historyIndex == pageHistory.length - 1) switchArrows ('right', 'off');
}
function switchArrows (dir, state)
{
	var aBase;
	var theImage = "/images/";
	if (dir == 'left')
	{
		aBase = 0; 
		theImage += "left";
	}
	else 
	{
		aBase = 1;
		theImage += "right";
	}
	if (state == 'on') theImage += "On.gif"; else theImage += "Off.gif";
	//alert (theImage);
	for (i = 0; i < 6; i += 2)
	{
		//alert ("arrow" + (parseInt (aBase) + i));
		document.getElementById ("arrow" + (parseInt (aBase) + i)).src = theImage;
	}
}
function switchCart (val)
{
	var showBooger = 0;
	var cObj = document.forms ["headForm"].checklist;
//	alert ("switchcart to " + val);
	if (selectedObject) 
	{
		selectedObject.style.background = "#ffffff";
		selectedObject.style.color = "#000000";
		selectedObject = "";
	}
	if (val != "") 
	{
		if (val == "cat") cObj [0].checked = true;
		else 
		{
			cObj [1].checked = true;
			if ( val != "cart") showBooger = parseInt (val);
		}
	}
	if (cObj [0].checked)
	{
//		alert ("catalog mode");
		// Catalog mode
		showPurchases (cartMode);
		showGeneric (100);
	}
	else 
	{
//		alert ("cart mode " + showBooger);
		// Cart mode
		showGeneric (showBooger);
		showPurchases (cartMode);
	}
}
function showPurchases (mode)
{
	var objRow;
	var objCol;
	dispMode = "none";
//	alert ("show purchases");
	for (i = 0; i < nRows; i++)
	{
		if (mode)
		{
			// Cart mode
			objCol = document.getElementById ("CF-"+i+"-4"); // Qty
			if (products [i][5] > 0) objCol.value = products [i][5];
			else objCol.value = "";
		}
		else
		{
			//Order mode
			objCol = document.getElementById ("C-"+i+"-4"); // Qty
			if (products [i][5] > 0) objCol.innerHTML = products [i][5];
			else objCol.value = "&nbsp;";
		}
		objCol = document.getElementById ("C-"+i+"-6"); // Total
		if (products [i][7] > 0) objCol.innerHTML = products [i][7];
		else objCol.innerHTML = "&nbsp;";
		objRow = document.getElementById ("R-c" + i);
		if (products [i][5] == 0)
		{
			objRow.style.visibility = "hidden";
			objRow.style.display = "none";
		}
		else
		{
//			alert ("make visible");
			objRow.style.visibility = "visible";
			objRow.style.display = dispControl;
		}
	}
}
function colorSel (sel)
{
	var sizeSel;
	var oParent = sel.parentNode;
	var pieces = oParent.id.split ('-');
	var prodQty = document.forms.catalog ["GF-" + pieces [1] + "-4"];
	var prodSize = document.getElementById (pieces [0] + '-' + pieces [1] + '-3');
	var prodID = document.getElementById (pieces [0] + '-' + pieces [1] + '-0');
	var cartID = prodID.innerHTML;
	if (sel.value)
	{
		// Color selected
		sel.style.background = "#ffffff";
		sizeSel = true;
		if (prodSize.firstChild.nodeType == 1)
		{
			// Size selector
			sizeVal = prodSize.firstChild.value;
			if (!sizeVal) sizeSel = false;
		}
		else //sizeCode
		{
			sizeVal = sizeCode [prodSize.innerHTML];
		}
		if (sizeSel && (prodQty.value > 0))
		{
			// Submit for validation
			cartID += sel.value;
			cartID += sizeVal;
			if (prodQty.value == "") qty = 0;
			else qty = parseInt (prodQty.value);
			if (cartID.length == 7) fValidate (qty, cartID, 'add');
		}
	}
}
function sizeSel (sel)
{
	var colorSel;
	var oParent = sel.parentNode;
	var pieces = oParent.id.split ('-');
	var prodQty = document.forms.catalog ["GF-" + pieces [1] + "-4"];
	var prodColor = document.getElementById (pieces [0] + '-' + pieces [1] + '-2');
	var prodID = document.getElementById (pieces [0] + '-' + pieces [1] + '-0');
	var cartID = prodID.innerHTML;
	if (sel.value)
	{
		// Color selected
		sel.style.background = "#ffffff";
		colorSel = true;
		if (prodColor.firstChild.nodeType == 1)
		{
			// Color selector
			colorVal = prodColor.firstChild.value;
			if (!colorVal) colorSel = false;
		}
		else
		{
			colorVal = colorCode [prodColor.innerHTML];
		}
		if (colorSel && (prodQty.value > 0))
		{
			// Submit for validation
			cartID += colorVal;
			cartID += sel.value;
//			alert (cartID);
			if (prodQty.value == "") qty = 0;
			else qty = parseInt (prodQty.value);
			if (cartID.length == 7) fValidate (qty, cartID, 'add');
		}
	}
}
function clearGenerics (exclude)
{
	for (i = 0; i < nGroups; i++)
	{
		var tQty = document.forms.catalog ['GF-' + i + '-4'];
		var tColor = document.getElementById ('G-' + i + '-2');
		var tSize = document.getElementById ('G-' + i + '-3');
		var tID = document.getElementById ('G-' + i + '-0');
		var tTot = document.getElementById ('G-' + i + '-6');
		var tCSelect = document.getElementById (tID.innerHTML + '-C');
		var tSSelect = document.getElementById (tID.innerHTML + '-S');
		if (i != exclude)
		{
//			alert ("i: " + i + ", " + tQty.value);
			tQty.value = "";
			tTot.innerHTML = "&nbsp;";
			if (tCSelect)
			{
				tCSelect.style.background = "#ffffff";
				tCSelect.value = "";
			}
			if (tSSelect)
			{
				tSSelect.style.background = "#ffffff";
				tSSelect.value = "";
			}
		}
	}
	
}
function qtyAdjust (button)
{
	// Button like "G-0-7"
	var pieces = button.split ('-');
	var prodID = document.getElementById (pieces [0] + '-' + pieces [1] + '-0');
	var prodQty = document.forms.catalog [pieces [0] + 'F-' + pieces [1] + '-4'];
	var prodColor = document.getElementById (pieces [0] + '-' + pieces [1] + '-2');
	var prodSize = document.getElementById (pieces [0] + '-' + pieces [1] + '-3');
	var prodCSelect;
	var prodSSelect;
	var cSelect;
	var sSelect;
	var qty;
	var i;
	var currQty;
	var cartID = prodID.innerHTML;
	var qMode = "replace";

	if (selectedObject) 
	{
		selectedObject.style.background = "#ffffff";
		selectedObject.style.color = "#000000";
		selectedObject = "";
	}
	clearGenerics (pieces [1]);
	if (prodQty.value == "") qty = 0;
	else qty = parseInt (prodQty.value);
	if (pieces [2] == "7") qty += 1;
	else if (pieces [2] == "8" && qty > 0) qty -= 1;
	else if (pieces [2] == "9") qty = 0;
//	alert ("qty: " + qty);
	prodQty.value = qty;
	prodCSelect = document.getElementById (cartID + '-C');
	prodSSelect = document.getElementById (cartID + '-S');
	//prodID.style.background = "#0000ff";
	if (pieces [0] == 'G')
	{
		// Generic
		if (qty > 0)  // Item selected
		{
			qMode = "add";
			cSelect = sSelect = true;
			if (prodCSelect) // Color selector present
			{
				if (prodCSelect.value == "") // No color selected
				{
					cSelect = false; 
					prodCSelect.style.background = "#ff0000";
				}
				else 
				{
					prodCSelect.style.background = "#ffffff";
					cartID += prodCSelect.value;
				}
			}
			else
			{
				// Add single color available
				cartID += colorCode [prodColor.innerHTML];
			} // End if color selector
			if (prodSSelect) // Size selector present
			{
				if (prodSSelect.value == "") // No size selected
				{
					sSelect = false; 
					prodSSelect.style.background = "#ff0000";
				}
				else 
				{
					prodSSelect.style.background = "#ffffff";
					cartID += prodSSelect.value;
				}
			} // End if size selector
			else
			{
				cartID += sizeCode [prodSize.innerHTML];
			}
		}
		else // Item not selected
		{
			if (prodCSelect) prodCSelect.style.background = "#ffffff";
			if (prodSSelect) prodSSelect.style.background = "#ffffff";
			prodQty.value = "";
		} // End if item selected
	} // End if generic
//	alert (cartID);
	if (cartID.length == 7) fValidate (qty, cartID, qMode);
}
function valError (str)
{
	alert (str);
	return -1;
}
function cartIndex (ID)
{
	for (i = 0; i < nRows; i++) if (products [i][1] == ID) break;
	if (i >= nRows)
	{
		msgBox ("Product not available in specified size or color", "", 0);
		return;
	}
	return i;
}
function lfValidate (fObj, ID)
{
	var pieces = fObj.id.split ('-');
	var sType = pieces [0][0];
	var prodID = document.getElementById (sType + '-' + pieces [1] + '-0');
//	alert ("pID: " + prodID + ", " + fObj.id + ", " + sType + '-' + pieces [1] + '-0');
	var cartID = prodID.innerHTML;
	var prodColor = document.getElementById (pieces [0] + '-' + pieces [1] + '-2');
	var prodSize = document.getElementById (pieces [0] + '-' + pieces [1] + '-3');
	var prodCSelect;
	var prodSSelect;
	var qMode;
//	alert ("lfvalidate!");
	if (selectedObject) 
	{
		selectedObject.style.background = "#ffffff";
		selectedObject.style.color = "#000000";
		selectedObject = "";
	}
	var qty = parseInt (fObj.value);
	if (isNaN (qty)) return valError ("Validity error: quantity, in lfValidate");
	if (sType == "G")
	{
		qMode = "add";
		prodCSelect = document.getElementById (cartID + '-C');
		prodSSelect = document.getElementById (cartID + '-S');
		if (qty > 0)  // Item selected
		{
			cSelect = sSelect = true;
			if (prodCSelect) // Color selector present
			{
				if (prodCSelect.value == "") // No color selected
				{
					cSelect = false; 
					prodCSelect.style.background = "#ff0000";
				}
				else 
				{
					prodCSelect.style.background = "#ffffff";
					cartID += prodCSelect.value;
				}
			}
			else
			{
				// Add single color available
				cartID += colorCode [prodColor.innerHTML];
			} // End if color selector
			if (prodSSelect) // Size selector present
			{
				if (prodSSelect.value == "") // No size selected
				{
					sSelect = false; 
					prodSSelect.style.background = "#ff0000";
				}
				else 
				{
					prodSSelect.style.background = "#ffffff";
					cartID += prodSSelect.value;
				}
			} // End if size selector
			else
			{
				cartID += sizeCode [prodSize.innerHTML];
			}
			if (prodCSelect) prodCSelect.focus ();
			else if (prodSSelect) prodSSelect.focus ();
		}
		else // Item not selected
		{
			if (prodCSelect) prodCSelect.style.background = "#ffffff";
			if (prodSSelect) prodSSelect.style.background = "#ffffff";
			prodQty.value = "";
		} // End if item selected
	} // End if generic
//	alert (cartID);
	if (cartID.length == 7)
	{
		fValidate (qty, cartID, qMode);
	}
	
}
function fValidate (qty, ID, mode)
{
	// Locate cart entry
	if ((i = cartIndex (ID)) < 0) return;
	// Validate quantity
	qty = parseInt (qty);
//	alert (qty + ", " + ID);
	if (isNaN (qty)) return valError ("Validity error: quantity, in fValidate");
	updateCart (i, qty, mode);
	switchCart ("");
	refreshTotals ();
}
function refreshTotals ()
{
	var tot;
	var tax;
	var shipping;
	var grand;
	tot = calcTotal ();
	shipping = parseFloat (shippingCharge ());
	tax = parseFloat (calcTax (tot + shipping));
	grand = parseFloat (tot + tax + shipping);
	//alert (shipping);
	if (tax == 0) tax = "&nbsp;"; else tax = tax.toFixed (2);
	if (shipping == 0) shipping = "&nbsp;"; else shipping = shipping.toFixed (2);
	if (grand == 0) grand = "&nbsp;"; else grand = grand.toFixed (2);	
	var tT = document.getElementById ("ptotal");
	if (tot == 0) tot = "&nbsp;"; else tot = tot.toFixed (2);
	tT.innerHTML = "<strong>" + tot + "</strong>";
	tT = document.getElementById ("ptotalg");
	tT.innerHTML = "<strong>" + tot + "</strong>";
	//alert ("total: " + tot + ", " + tT);
	tT = document.getElementById ("ptaxg");
	tT.innerHTML = "<strong>" + tax + "</strong>";
	tT = document.getElementById ("pshippingg");
	tT.innerHTML = "<strong>" + shipping + "</strong>";
	tT = document.getElementById ("gtotal");
	tT.innerHTML = "<strong>" + grand + "</strong>";
	tT = document.getElementById ("cartString");
	if (countProducts ()) tT.innerHTML = "<strong>Your Shopping Cart</strong>";
	else tT.innerHTML = "<strong>Your Shopping Cart is Empty</strong>";
	return grand;
}
function calcTotal ()
{
	var i;
	var j;
	var qty;
	var price;
	var total = 0;
	for (i = 0; i < nRows; i++)
	{
		price = parseFloat (products [i][6]);
		qty = parseInt (products [i][5]);
		total += qty * price;
	}
	total = parseFloat (total);
	return total;
}
function calcTax (tot)
{
	var tObj = document.forms ["taxform"];
	var rObj = document.getElementById ("trate");
	var pct;
	//alert (NYTax);
//	alert ("NY tax status: " + tObj.nytax.checked + " FL tax status: " + tObj.fltax.checked);
	tT = document.getElementById ("taxrate");
	
	if (tObj.nytax.checked)
	{
		tax = parseFloat (tot * NYTax);
		pct = NYTax*100;
		pct = pct.toFixed (2);
		rObj.innerHTML = "&nbsp;&nbsp;<strong>" + pct + "%</strong>";
		tT.value = NYTax;
	}
	else if (tObj.fltax.checked)
	{
		tax = parseFloat (tot * FLTax);
		pct = FLTax*100;
		pct = pct.toFixed (2);
		rObj.innerHTML = "&nbsp;&nbsp;<strong>" + pct + "%</strong>";
		tT.value = FLTax;
	}
	else 
	{
		tax = 0;
		rObj.innerHTML = "<strong>&nbsp;</strong>";
		tT.value = 0;
	}
	return tax;
}
function calcShipping ()
{
	var ship = 7.00;
	ship = ship.toFixed (2);
	return ship;
}
function calcOrder ()
{
}
function crossDescToID (desc)
{
	for (i = 0; i < nRows; i++) if (products [i][2] == desc) break;
	if (i < nRows) return products [i][1].substr (0, 5);
	else 
	{
		alert ("Fail to cross descriptor");
		return false;
	}
}
function changeCheck (box, fName, key, val)
{
	var i;
	var populated = false;
	var fObj = document.forms [fName];
	var pieces = fName.split ('-');
	var prodID;
	for (i = 0; i < fObj.length; i++)
	{
		if (fObj [i] != box) fObj [i].checked = false;
		if (fObj [i].checked)
		{
			populated = true;
			fObj.style.backgroundColor = "#ffffff";
		}
	}
	if (val == "stash")
	{
		var oStash = document.getElementById ("stash");
		val = oStash.value;
	}
	if (mPendingAssoc [pieces [0]] == true)
	{
		prodID = crossDescToID (mContentAssoc [pieces [0]]);
		if (key == "color") prodID += val;
		prodID += box.value;
		if (key == "size") prodID += val;

		if (prodID.length == 7)	
		{
			transQty = 1;
			transID = prodID;
			transMode = "add";
			addNotify (prodID);
			mPendingAssoc [pieces [0]] = false;
		}
	}
}

function prodSelect ()
{
	var prodID = crossDescToID (mContentAssoc [divID [storeIndex]]);
	var pType;
	var fID;
	var hID;
	var pRow = 0;
	gohappy (document.getElementById ('prodSelect'), "out");
	
	// Construct a generic catalog id
	//alert (prodID + ", " + catKey [prodID]);
	fID = catKey [prodID] + "-7";
	hID = document.getElementById (catKey [prodID] + "-0");
	/*
	if ((sizesPer [prodID] > 1) || (colorsPer [prodID] > 1))
	{
		// Generic entry
		pType = 'G';
		pRow = parseInt (prodID.substr (4, 1));
		if (pRow < 6) pRow -= 1; else pRow -= 2;
	}
	else 
	{
		pType = 'C';
		for (tID = 10001; tID < parseInt (prodID); tID++)
		{
			pRow += sizesPer [tID] * colorsPer [tID];
		}
	}
	fID = pType + '-' + pRow + '-' + 7;
	//alert (fID);
	*/
	showCart (0);
	qtyAdjust (fID);
	//hID = document.getElementById (pType + '-' + pRow + '-' + 0);
	// alert (hID);
	hID.style.background = "#0000ff";
	hID.style.color = "#ffffff";
	selectedObject = hID;
}
function commitTrans ()
{
	fValidate (transQty, transID, transMode);
}
function addNotify (pID)
{
	var i;
	for (i = 0; i < nRows; i++) if (products [i][1] == pID) break;
//	alert (pID + ", i: " + i);
	var mStr = products [i][2] + ": " + products [i][3] + ", " + products [i][4];
	msgBox (mStr, "", 1);
}
function CSelect (cDrop, shop, sDrop)
{
	var sVal;
	if (sDrop) sVal = document.getElementById (sDrop).value;
	else sVal = "Z";
	var prodID = mContentAssoc [shop];
	for (i = 0; i < nRows; i++) if (products [i][2] == prodID) break;
	prodID = products [i][1].substr (0, 5);
	if (cDrop.value)
	{
		cDrop.style.background = "#ffffff";
		prodID += cDrop.value;
		if (mPendingAssoc [shop] == true)
		{
			prodID += sVal;
			if (prodID.length == 7)	
			{
				transQty = 1;
				transID = prodID;
				transMode = "add";
				addNotify (prodID);
				mPendingAssoc [shop] = false;
			}

		}
	}
}
function SSelect (sDrop, shop, cDrop)
{
	var cObj = document.getElementById (cDrop);
	var prodID = mContentAssoc [shop];
	for (i = 0; i < nRows; i++) if (products [i][2] == prodID) break;
	prodID = products [i][1].substr (0, 5);
	if (sDrop.value)
	{
		sDrop.style.background = "#ffffff";
		if (cObj && mPendingAssoc [shop] == true)
		{
			prodID += cObj.value;
			prodID += sDrop.value;
			if (prodID.length == 7)	
			{
				transQty = 1;
				transID = prodID;
				transMode = "add";
				addNotify (prodID);
				mPendingAssoc [shop] = false;
			}
		}
	}
}
function updateCart (index, qty, mode)
{
	var price = parseFloat (products [index][6]);
	var currQty = parseInt (products [index][5]);
//	alert ("qty: " + qty + " curr: " + currQty);
	if (mode == "add") currQty += parseInt (qty);
	else currQty = qty;
	var total = price * currQty;
	products [index][5] = currQty;
	products [index][7] = total;
	products [index][7] = products [index][7].toFixed (2);
//	alert ("Total: " + products [index][7]);
//	switchCart ("");
}
function showGeneric (state)
{
	var currentID = "beadface";
	var groupID;
	var groupNo = -1;
	var gObj;

//	alert ("show generic " + state);
	if (state > 0)
	{
		vState = "visible";
		dState = dispControl;
		clearGenerics (-1);
	}
	else
	{
		vState = "hidden";
		dState = "none";
	}
	for (i = 0; i < nRows; i++)
	{
		//if (state < 100 && state != i) continue;
		groupID = products [i][1].substr (0, 5);
		if (groupID != currentID)
		{
			currentID = groupID;
			if ((colorsPer [groupID] > 1) || (sizesPer [groupID] > 1))
			{
				// Selectable variations
				groupNo++;
				gObj = document.getElementById ("R-g" + groupNo);
			}
			else
			{
				// Variations not applicable
				gObj = document.getElementById ("R-c" + i);
			}
			gObj.style.visibility = vState;
			gObj.style.display = dState;
		}
	}
}
		




function showMiniItem (choice, picture, state)
{
	var theThang;
	var pic = document.getElementById ("miniItem");
	var pos = document.getElementById (choice);
	var cont = document.getElementById (choice + "Label");
	if (picture != "") pic.src=picture.src;
	if (state == "over") 
	{
		iBrowsing = true;
//		cont.style.fontWeight = "bold";
		pos.style.color = "#0000ff";
	}
 	else 
	{
		iBrowsing = false;	
//		cont.style.fontWeight = "normal";
		pos.style.color = "#000000";
	}
	checkBrowsing (pos);
	return false;
}
function tBrowse (state)
{
	var bCheck = document.getElementById ('hoody');
	if (state == "on") tBrowsing = true;
	else tBrowsing = false;
	checkBrowsing ("");
}
function overThumb (state)
{
	var bCheck = document.getElementById ('hoody');
	if (state == "on") pBrowsing = true;
	else pBrowsing = false;
	checkBrowsing ("");
}
function checkBrowsing (pos)
{
	var x, y;
	var frame = document.getElementById ("miniChange");
	var dcap = document.getElementById ("dropcap");
	var scap = document.getElementById ("smallcaps");
	if (pos)
	{
		x = pos.offsetLeft - 100;
		y = pos.offsetTop;
	}
	if (tBrowsing || iBrowsing || pBrowsing)
	{
		if (pos)
		{
			frame.style.left = x;
			frame.style.top = y;
		}
		dcap.innerHTML = "C";
		scap.innerHTML = "LICK TO SHOP";
		frame.style.visibility = "visible";
	}
	else
	{
		frame.style.visibility = "hidden";
		dcap.innerHTML = "B";
		scap.innerHTML = "ROWSE HERE";
	}
}
var currPop;
function enlarge (wURL, sp)
{
	var specs = "width=800,height=600,top=30,left=30," +
	  			"screenx=30,screeny=30," +
			  	"resizable=yes,scrollbars=yes";
	if (sp) specs = sp;
	popWin = open (wURL, "popWindow", specs);
	popWin.focus ();
	currPop = popWin;
}
function gohelp ()
{
	var specs = "width=700,height=450,top=30,left=30," +
				"screenx=30,screeny=30," +
				"resizable=no,scrollbars=yes"
	enlarge ("/help.htm", specs);
}
function goabout ()
{
	var specs = "width=700,height=550,top=30,left=30," +
				"screenx=30,screeny=30," +
				"resizable=no,scrollbars=yes"
	enlarge ("/parabout.htm", specs);
}
function gohappy (o, state)
{
//	alert (o.style.backgroundImage);
	var pObj = document.getElementById ("price");
	if (state == "over")
	{
		o.style.backgroundImage = "url('/images/happyClam.gif')";
		pObj.style.visibility = "hidden";

	}
	else
	{
		o.style.backgroundImage = "url('/images/selectClam.gif')";
		if (storeIndex >= 0) pObj.innerHTML = storePrice [storeIndex];
		pObj.style.visibility = "visible";
	}
}
function linkTo (dest)
{
	if (dest=="gocart")
	{
		viewCart ();
	}
	else if (dest == "gohome")
	{
		backHome ();
	}
	else if (dest == "goform")
	{
		updateForm ();
	}
	else if (dest == "about")
	{
		msgBox ("Paradise Apparel", "", 0);
	}
	else if (dest == "gohelp")
	{
		var specs = "width=700,height=450,top=30,left=30," +
	  			"screenx=30,screeny=30," +
			  	"resizable=no,scrollbars=yes"
		enlarge ("/help.htm", specs);
	}
	else if (dest == "goprivacy")
	{
		var specs = "width=700,height=550,top=30,left=30," +
	  			"screenx=30,screeny=30," +
			  	"resizable=no,scrollbars=yes"
		enlarge ("/privacy.htm", specs);
	}
	else
	{
		alert ("Link to " + dest + " page");
	}
	return false;
}
function msgBox (msg1, msg2, box)
{
	var mb;
	var am;
	var am2;
	var wAvail = document.body.clientWidth;
	var hAvail = document.body.clientHeight;
	var wWidth = .4 * wAvail;
	var wHeight = .4 * wWidth;
	var wLeft = (wAvail - wWidth) / 2;
	var wTop = (hAvail - wHeight) / 3;
	var scrollAmt = document.body.scrollTop;
	wWidth = parseInt (wWidth);
	wHeight = parseInt (wHeight);
	if (box == 0) 
	{
		mb = document.getElementById ("theBox");
		am = document.getElementById ("alertMsg");
		am2 = document.getElementById ("alertTwo");
		if (msg2 == "")
		{
			am2.style.visibility = "hidden";
			am2.style.display = "none";
		}
		else
		{
			am2.style.visibility = "visible";
			am2.style.display = "block";
		}
	}
	else 
	{
		mb = document.getElementById ("theBoxTwo");
		am = document.getElementById ("alertMsgTwo");
	}
	mb.style.position = "absolute";
	mb.style.left = wLeft;
	mb.style.top = wTop + scrollAmt;
	mb.style.zIndex = "6";
	mb.style.width = wWidth;
	mb.style.backgroundColor = "#ffffee";
	am.innerHTML = "<strong>" + msg1 + "</strong>";
	am2.innerHTML = "<strong>" + msg2 + "</strong>";
	mb.style.visibility = "visible";
	mb.style.display = "block";
	mbState = 0;
}
function setState (state)
{
	if ((state == 1) || (state == 3)) commitTrans ();
	pendTransAmt = 0.0;
	pendTransItem = 0;
	pendTransQty = 0;
	dismissAlert (1);
	if (state == 3) 
	{
		checkOut ("off", 0);
		showCart (0);
	}
}
function dismissAlert (box)
{
	var mb;
	if (box == 0) mb = document.getElementById ("theBox");
	else mb = document.getElementById ("theBoxTwo");
	mb.style.visibility = "hidden";
	mb.style.display = "none";
	mb.zIndex = "0";
}
function checkOut (cState, source)
{
	var vState;
	var dState;
	var oAdj;
	var q1 = '<input name="';
	var q2 = '" id="';
	var q3 = '" type="text" onblur="lfValidate (this, id);" size="4" value=""/>';
	var moniker;
	var qty;
	var currID;
	
	if (cState == "on")
	{
		if (countProducts () == 0)
		{
			msgBox ("Please Select One or More Products", "", 0);
			return;
		}
		if (source == 0)
		{
			// Unilateral page selection.  Add to history at current position.
			if (historyIndex == pageHistory.length - 1)
			{
				if (pageHistory [historyIndex] != 200) 
				{
					pageHistory.push (200);
					historyIndex++;
				}
			}
			else 
			{
				if ((pageHistory [historyIndex] != 200) && 
					(pageHistory [historyIndex+1] != 200))
				{
					pageHistory.splice ([historyIndex+1], 0, 200);
					historyIndex++;
				}
			}
		}
		switchCart ("cart");
		currCartMode = "cart";
		vState = "hidden";
		dState = "none";
		cartMode = false;
		oAdj = document.getElementById ("homePage");
		oAdj.style.visibility = "hidden";
		oAdj.style.display = "none";
		oAdj = document.getElementById ("catalog");
		oAdj.style.visibility = "visible";
		oAdj.style.display = "block";
		oAdj = document.getElementById ("tTotals");
		oAdj.style.visibility = "hidden";
		oAdj.style.display = "none";
		oAdj = document.getElementById ("gTotals");
		oAdj.style.visibility = "visible";
		oAdj.style.display = "block";
		oAdj = document.getElementById ("cartCrumbs");
		oAdj.style.visibility = "hidden";
		oAdj.style.display = "none";
		oAdj = document.getElementById ("orderCrumbs");
		oAdj.style.visibility = "visible";
		oAdj.style.display = "block";
		oAdj = document.getElementById ("carthead");
		oAdj.style.visibility = "hidden";
		oAdj.style.display = "none";
		/*
		oAdj = document.getElementById ("shipForm");
		oAdj.style.visibility = "visible";
		oAdj.style.display = "block";
		*/
		oAdj = document.forms ['products'].order;
		oAdj.value = orderKey;
		oAdj = document.getElementById ("payment");
		oAdj.style.visibility = "visible";
		oAdj.style.display = "block";
//		alert (oAdj.value);
	}
	else
	{
		if (source == 0)
		{
			// Unilateral page selection.  Add to history at current position.
			if (historyIndex == pageHistory.length - 1)
			{
				if (pageHistory [historyIndex] != 100) 
				{
					pageHistory.push (100);
					historyIndex++;
				}
			}
			else 
			{
				if ((pageHistory [historyIndex] != 100) && 
					(pageHistory [historyIndex+1] != 100))
				{
					pageHistory.splice ([historyIndex+1], 0, 100);
					historyIndex++;
				}
			}
		}
		
		switchCart ("cat");
		currCartMode = "cat";
		vState = "visible";
		dState = cellMode;
		cartMode = true;
		oAdj = document.getElementById ("gTotals");
		oAdj.style.visibility = "hidden";
		oAdj.style.display = "none";
		oAdj = document.getElementById ("tTotals");
		oAdj.style.visibility = "visible";
		oAdj.style.display = "block";
		oAdj = document.getElementById ("orderCrumbs");
		oAdj.style.visibility = "hidden";
		oAdj.style.display = "none";
		oAdj = document.getElementById ("cartCrumbs");
		oAdj.style.visibility = "visible";
		oAdj.style.display = "block";
		oAdj = document.getElementById ("carthead");
		oAdj.style.visibility = "visible";
		oAdj.style.display = "block";
		oAdj = document.getElementById ("payment");
		oAdj.style.visibility = "hidden";
		oAdj.style.display = "none";
		/*
		oAdj = document.getElementById ("shipForm");
		oAdj.style.visibility = "hidden";
		oAdj.style.display = "none";
		*/
	}
	//alert ("vis: " + vState + ", dis: " + dState);
	for (i = 7; i < 10; i++)
	{
		oAdj = document.getElementById ('H-0-' + i);
		oAdj.style.visibility = vState;
		oAdj.style.display = dState;
	}
		
	for (i = 0; i < nRows; i++)
	{
		currID = 'C-' + i + '-4';
		moniker = 'CF-' + i + '-4';
		qty = products [i][5];
		oAdj = document.getElementById (currID);
		if (vState == "visible")
		{
			oAdj.innerHTML = q1 + moniker + q2 + moniker + q3;
			oAdj = document.getElementById (moniker);
			if (qty == 0) qty = "";
			oAdj.value = qty;
		}
		else
		{
			if (qty == 0) qty = "&nbsp;";
			oAdj.innerHTML = qty;
		}
			
		for (j = 7; j < 10; j++)
		{
//			alert (vState + ", " + dState + ", " + 'C-' + i + '-' + j);
			oAdj = document.getElementById ('C-' + i + '-' + j);
			oAdj.style.visibility = vState;
			oAdj.style.display = dState;
		}
	}
	if (historyIndex > 0) switchArrows ('left', 'on');
	if (historyIndex < pageHistory.length - 1) switchArrows ('right', 'on');
}
function taxChange (st)
{
	var tObj = document.forms ["taxform"];
	if (tObj.nytax.checked && st == "ny") 
	{
		tObj.nytax.value = true;
		tObj.fltax.value = false;
		tObj.fltax.checked = false;
	}
	else if (tObj.fltax.checked && st == "fl")
	{
		tObj.nytax.value = false;
		tObj.fltax.value = true;
		tObj.nytax.checked = false;
	}
	else
	{
		tObj.nytax.value = false;
		tObj.fltax.value = false;
		tObj.nytax.checked = false;
		tObj.fltax.checked = false;
	}
	refreshTotals ();
//	alert ("tax change");
//	refreshTable (2);
}
function buildForm ()
{
	var i;
	var j;
	for (i = 0; i < nRows; i++)
	{
		for (j = 0; j < nCols; j++)
		{
			// Put in the fields
			document.write ('<input name="' + products [i][1] + '-' + j + '" ' +
							'id="' + j + '-' + products [i][1] + '" ' +
							'value="' + products [i][j] + '" ' +
							'size="6" ' +
							'type="hidden">');
			/*
			alert ('<input name="' + products [i][1] + '-' + j + '" ' +
							'id="' + j + '-' + products [i][1] + '" ' +
							'value="' + products [i][j] + '" ' +
							'size="6" ' +
							'type="hidden">');
			*/
		}
	}
	// Close the form
}
function placeOrder ()
{
	//alert ("Place Order");
	updateForm ();
//	oAdj = document.forms ['products'].order;
	//alert ("Preubmission: " + oAdj.value);
//	if (oAdj.value == "old") return;
	if (checkForm ()) document.forms ["products"].submit ();
	//alert ("The order has been submitted. This is the final action of a dying page. By the time you click OK the new page should have arrived.  Check the address bar of your browser");
//	oAdj.value = 'old';
	//alert ("Submission: " + oAdj.value);
}
function updateForm ()
{
	var i;
	var j;
	var fObj;
	for (i = 0; i < nRows; i++)
	{
		for (j = 0; j < nCols; j++)
		{
//			if (i == 0) alert ("i: " + i + ", j: " + j + ", " + j + '-' + products [i][0]);
			fObj = document.getElementById (j + '-' + products [i][1]);
			fObj.value = products [i][j];
		}
	}
//	alert ("Updated");
}
function checkForm ()
{
	var i;
	var msg;
	var fNames = new Array;
	var vAddr = 0;
	if (!valName (document.forms ["products"]["fname"].value, 1)) fNames.push ("First Name");
	if (!valName (document.forms ["products"]["lname"].value, 1)) fNames.push ("Last Name");
//	if (!valName (document.forms ["products"]["mi"].value, 0)) fNames.push ("Middle Initial");
//	if (!valName (document.forms ["products"]["jr"].value, 0)) fNames.push ("Jr/Sr");
	if (valAddress (document.forms ["products"]["street"].value, 1)) vAddr++; 
//	if (!valAddress (document.forms ["products"]["apt"].value, 0)) fNames.push ("Apt");
	if (valAddress (document.forms ["products"]["addr"].value, 1)) vAddr++;
	if (vAddr == 0) fNames.push ("Address");
	if (!valName (document.forms ["products"]["city"].value, 1)) fNames.push ("City");
	if (!valName (document.forms ["products"]["state"].value, 1)) fNames.push ("State");
	if (!valZip (document.forms ["products"]["zip"].value, 1)) fNames.push ("Zip");
	if (!valName (document.forms ["products"]["country"].value, 1)) fNames.push ("Country");
	if (!valEmail (document.forms ["products"]["email"].value, 1)) fNames.push ("E-mail");
//	alert ("vAddr: " + vAddr);
	if (fNames.length == 0)
	{
		return true;
	}
	else
	{
		msg = "Fields marked with * are required.&nbsp;";
		msg += "Please check the following form fields for correctness:<br><center>";
		for (i = 0; i < fNames.length; i++) 
		{
			msg += fNames [i];
			if (i < fNames.length - 1) msg += ",<br>";
		}
		msg += "</center>";
		msgBox (msg, "", 0);
	}
	return false;
}
function isAlpha (ch)
{
	var c = ch.charAt (0);
	if (((c >= 'A') && (c <= 'Z')) ||
		((c >= 'a') && (c <= 'z'))) return true;
	return false;
}
function isNumeric (ch)
{
	var c = ch.charAt (0);
	if ((c >= '0') && (c <= '9')) return true;
	return false;
}
function isAlNum (ch)
{
	var c = ch.charAt (0);
	if (isAlpha (c) || isNumeric (c)) return true;
	return false;
}
// charCodeAt (position);
function isPrintable (c)
{
	var tC = c.charCodeAt (0) & 0xff;
	alert (c.charAt (0));
	alert (tC);
	if ((tC >= 0x20) && (tC <= 0xfe)) return true;
	return false;
}
function valEmail (str, flag)
{
	var ats = 0;
	var dots = 0;
	var valStr = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
	if ((flag == 0) && ((str == "") || (str.length ==0))) return true;
	if (!isAlpha (str.charAt (0).toLowerCase ())) return false;
	if (!valEntry (str, valStr)) return false;
	for (i = 0; i < str.length; i++)
	{
		if (str.charAt (i) == '@') ats++;
		if (str.charAt (i) == '.') dots++;
	}
	if ((ats != 1) || (dots < 1)) return false;
	return true;
}
function valName (str, flag)
{
	valStr = "abcdefghijklmnopqrstuvwxyz '-.,";
	if (str.length == 0) if (flag) return false;
	if (!valEntry (str, valStr)) return false; else return true;
}
function valAddress (str, flag)
{
	valStr = "abcdefghijklmnopqrstuvwxyz0123456789 '-#%(),.";
	if (str.length == 0)
	{
		if (flag)
		{
//			alert ("Returning empty invalid");
			return false;
		}
	}
	if (!valEntry (str, valStr)) return false; else return true;
}
function valZip (str, flag)
{
//	alert ("validate zip code: " + str);
	valStr = " 0123456789-";
	if (str.length == 0)
	{
		if (flag)
		{
//			alert ("Returning empty invalid");
			return false;
		}
	}
	if (!valEntry (str, valStr)) return false; else return true;
}
function valNumber (str, flag)
{
	valStr = "0123456789";
	if (str.length == 0)
	{
		if (flag)
		{
//			alert ("Returning empty invalid");
			return false;
		}
	}
	if (!valEntry (str, valStr)) return false; else return true;
}
function valEntry (str, vstr)
{
	var i;
	var c;
	for (i = 0; i < str.length; i++)
	{
		if (vstr.indexOf (str.charAt (i).toLowerCase ()) == -1)
			return false;
	}
	return true;
}
function contact ()
{
	location.href = 'mailto:mike@copaclamatude.com';
}
var currFont = "sans";
function flipFont ()
{
	var fObj = document.getElementById ("fontset");
	if (currFont == "sans")
	{
		fObj.style.fontFamily = '"Times New Roman", Times, serif';
		currFont = "serif";
	}
	else
	{
		fObj.style.fontFamily = 'Geneva, Arial, Helvetica, sans-serif';
		currFont = "sans";
	}
}
function makeHistory ()
{
	if (navigation == 0) location.href = "http://www.copaclamatude.com/cgi-bin/site.php?p=h";
}
/*
function enlarge (wURL, sp)
{
	var specs = "width=800,height=600,top=30,left=30," +
	  			"screenx=30,screeny=30," +
			  	"resizable=yes,scrollbars=yes";
	if (sp) specs = sp;
	popWin = open (wURL, "popWindow", specs);
	popWin.focus ();
}

*/
function payStd ()
{
	if (currPop) currPop.close ();
	var sp = "width=700,height=500,top=10,left=10," +
	  			"screenx=10,screeny=10," +
			  	"resizable=no,scrollbars=no";
	enlarge ("/approval.htm", sp);
	//alert ("Standard approval process");
}
function payPal ()
{
	if (currPop) currPop.close ();
	var sp = "width=900,height=600,top=10,left=10," +
	  			"screenx=10,screeny=10," +
			  	"resizable=yes,scrollbars=yes";
	enlarge ("/paypal.php", sp);
}
//"C-0-4"
//"CF-0-4"
//var qBlock = '<input name="' + moniker + '" id="' + moniker +
//			 ' type="text" onblur="lfValidate (this, id);" size="4" value=""/>';
//Corel Painter  	 v7.0  	 Serial : PF70CRD-2564458-SZH