function openImage (imgName, imgHeight, imgWidth) {
	winHeight = parseInt(imgHeight) + 60;
	winWidth = parseInt(imgWidth) + 30;
	imgTag = "images\/" + imgName;
	winParms = "height=" + winHeight + ",width=" + winWidth + ",toolbar=false,scrollbar=false"

	imgWin = window.open ('','',winParms);

	imgWin.document.write('<html>');
	imgWin.document.write('<head>');
	imgWin.document.write('<title>The Pendulator</title>');
	imgWin.document.write('<link href="main_ie.css" rel="stylesheet" type="text/css">');
	imgWin.document.write('</head>');

	imgWin.document.write('<body class="basefont">');

	imgSize = 'width="' + imgWidth + '" height="' + imgHeight + '"';

	imgWin.document.write('<div align="center">');
	imgWin.document.write('<img src="' + imgTag + '" ');
	imgWin.document.write('alt="***" ');
	imgWin.document.write(imgSize + ' border="0">');
	imgWin.document.write('</div>');
	imgWin.document.write('<p align="center" class="basefont">');
	imgWin.document.write('<a href="javascript: self.close();">Close</a>');
	imgWin.document.write('</p>');
	imgWin.document.write('</body></html>');
	imgWin.document.close();
}

function openLarge (imgName, imgNumber) {
imgName = imgName + "-" + imgNumber + ".gif";
openImage(imgName, '210', '210')
}
// line 37 
// *** Calculate sales tax and S&H charges

// global arrays and variables
var unitPrice = 19.95;
var theQuantity = 0

var idxMatch = 0;
var stateList = new Array();
var taxList = new Array();
var sandhList = new Array();
stateList[1] = "AL"
taxList[1] = 0.065
sandhList[1] = 5.95
stateList[2] = "DE"
taxList[2] = 0.07
sandhList[2] = 3.95
stateList[3] = "LA"
taxList[3] = 0.06
sandhList[3] = 4.95
stateList[4] = "OH"
taxList[4] = 0.075
sandhList[4] = 1.95
stateList[5] = "TN"
taxList[5] = 0.07
sandhList[5] = 2.95

// main function
function calcCharges() {

	// These elements will be validated before continuing
	theStates = document.getElementById("State");				// select list
		selectedState = theStates.selectedIndex;					//		selected index
	qtyOrdered = document.getElementById("Quantity");	// text box
	thePayType = document.getElementById("PayType");		// radio buttons
	
	// Validations
	//	 test state select list	
	//	 test quantity text box	
	//	 test payment type radio buttons	

	// If everything is valid, calculate the costs
				
		selectedAbbrev = theStates[selectedState].value;
		
		idx = document.getElementById("rowCount");
		idx = stateList.length;
		
		theQuantity = qtyOrdered.value;
		
		unfmtTax = calcTax(selectedAbbrev, idx);
		taxAmt = document.getElementById("SalesTax");
		taxAmt.value = formatCents(unfmtTax);
	
		unfmtSandH = calcSandH(selectedAbbrev, idx);
		sandhAmt = document.getElementById("SandH");
		sandhAmt.value = formatCents(unfmtSandH);
	
		unfmtTotal =  calcTotal(unfmtTax, unfmtSandH);
		totalAmt = document.getElementById("TotalAmount");
		totalAmt.value = formatCents(unfmtTotal);

}

// tax calcs
function calcTax(selectedAbbrev, idx) {
	for (i=1; i<idx; i++) {
		if (stateList[i] = selectedAbbrev) {
			taxAmount = taxList[i] * unitPrice * theQuantity;
			taxAmount = Math.round(taxAmount*100)/100;
			idxMatch = i;
		}
	}
	return taxAmount;
}

// S&H calcs
function calcSandH(selectedAbbrev, idx) {
	for (i=1; i<idx; i++) {
		if (stateList[i] = selectedAbbrev) {
			sandhAmount = sandhList[i] * theQuantity;
			sandhAmount = Math.round(sandhAmount*100)/100;
			idxMatch = i;
		}
	}
	return sandhAmount;
}

// Total calcs
function calcTotal(taxAmt, sandhAmt) {
	totalAmt =  (unitPrice * theQuantity) + taxAmt + sandhAmt;
	totalAmount = Math.round(totalAmt*100)/100;
	return totalAmount;
}

// Format costs with two decimals
function formatCents(amount) {
	if (amount == Math.floor(amount)) {amt = amount + '.00';}
	else {
		if (amount*10 == Math.floor(amount*10)) {amt = amount + '0';}
		else {amt = amount};
	}
	amt = "$" + amt;
	return amt;
}