var gaCounty = new Array(" ", "Appling", "Atkinson", "Bacon", "Baker",
		"Baldwin", "Banks", "Barrow", "Bartow", "Ben Hill", "Berrien", " Bibb",
		"Bleckley", "Brantley", "Brooks", "Bryan", "Bulloch", "Burke", "Butts",
		"Calhoun", "Camden", "Candler", "Carroll", "Catoosa", "Charlton",
		"Chatham", "Chattahoochee", "Chattooga", "Cherokee", "Clarke", "Clay",
		"Clayton", "Clinch", "Cobb", "Coffee", "Colquitt", "Columbia", "Cook",
		"Coweta", "Crawford", "Crisp", "Dade", "Dawson", "Decatur", "Dekalb",
		"Dodge", "Dooly", "Dougherty", "Douglas", "Early", "Echols",
		"Effingham", "Elbert", "Evans", "Fannin", "Fayette", "Floyd",
		"Forsyth", "Franklin", "Fulton", "Gilmer", "Glascock", "Glynn",
		"Gordon", "Grady", "Greene", "Gwinnett", "Habersham", "Hall",
		"Hancock", "Haralson", "Harris", "Hart", "Heard", "Henry", "Houston",
		"Irwin", "Jackson", "Jasper", "Jeff Davis", "Jefferson", "Jenkins",
		"Johnson", "Jones", "Lamar", "Lanier", "Laurens", " Lee", "Liberty",
		"Lincoln", "Long", "Lowndes", "Lumpkin", "Macon", "Madison", "Marion",
		"McDuffie", "McIntosh", "Meriwether", "Miller", "Mitchell", "Monroe",
		"Montgomery", "Morgan", "Murray", "Newton", "Oconee", "Oglethorpe",
		"Paulding", "Peach", "Pickens", "Pierce", "Pike", "Polk", "Pulaski",
		"Putnam", "Quitman", "Rabun", "Randolph", "Richmond", "Rockdale",
		"Schley", "Screven", "Seminole", "Spalding", "Stephens", "Stewart",
		"Sumter", "Talbot", "Taliaferro", "Tattnall", "Taylor", "Telfair",
		"Terrell", "Thomas", "Tift", "Toombs", "Towns", "Treutlen", "Troup",
		"Turner", "Twiggs", "Union", "Upson", "Walker", "Walton", "Ware",
		"Warren", "Washington", "Wayne", "Webster", "Wheeler", "White",
		"Whitfield", "Wilcox", "Wilkes", "Wilkinson");
gaCountyTax = new Array(0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 2,
		3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3,
		3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
		2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
		3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
		3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
		3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3);
// var mediaName = new Array("Enhanced matte","Canvas","Hahnemuhle WT 310 Fine
// art",
// "Premium luster","Premium high gloss","Exhibition fiber","Enhanced matte
// poster board",
// "Satin cloth","Smooth vinyl banner","Adhesive vinyl","Back light film","Wall
// mural paper w/o glue","Wall mural fabric w/glue","High gloss poster
// paper","Double sided banner");
var barName = new Array("None", "Standard 3/4\"", "Gallery 1 1/2\"",
		"Heavy Duty 2 1/2\"");
var mountName = new Array("None", "3/16 Foam", "1/2 Foam", "3/4 Foam",
		"1/8 Sintra", "1/4 Sintra", "3/8 Sintra", "3/16 Gater", "1/2 Gater",
		"3/4 Gater");
var laminateName = new Array("None", "Luster", "High gloss");
var edgeTreatmentName = new Array("None", "Solid Color", "Mirrored Image");
var imageObj;
var isOrderPage = true;
var imageFits = true;
var isPriceOnly;
var ppi = 150;
var pixelWidth = 0;
var pixelHeight = 0;
var imageWidth = 0;
var imageHeight = 0;
var isEdgeTreat = false;
var widthRatio = 0;
var heightRatio = 0;
var numberPrints = 0;
var prevPrintWidth = 0;
var prevPrintHeight = 0;
var printWidth = 0;
var printHeight = 0;
var mediaCost = 0.00;
var printCost = 0.00;
var printArea = 0.00;
var borderWidth = 0;
var loopedEnd = 0;
var paperWidth = 0;
var paperHeight = 0;
var paperArea = 0;
var barHeight = 0;
var barWidth = 0;
var barIndex = 0;
var prevBarIdx = 0;
var printRoll = 0;
var borderCost = 0.00;
var digitalArtworkCost = 0.00;
var totalColorCorrectCost = 0.00;
var totalColorMatchCost = 0.00;
var trimCost = 0;
var trimPrice = 0.5;
var wastedPaperCost = 0.00;
var varnishCost = 0.00;
var mountingCost = 0.00;
var laminateCost = 0.00;
var stretcherBarCost = 0.00;
var completeRows = 0;
var completeRowPrints = 0;
var partialRowPrints = 0;
var printOrientation;
var edge = 0.00;
var edgeCost = 0.00;
var message = "";
var isPriceServices = false;
var priceBorderCnt = 0;
var isHandDelivery = false;
var notWholeNumAlert = 0;
var barChange = false;
var imageChange = false;
var barSizeChange = false;
var borderChange = false;
var edgeTreatChange = false;
var isInitial = true;
var constraintStmt = ""; /*
							 * The 'Scaling Tool' maintains the aspect ratio
							 * between the width and height of the displayed
							 * image. " + "It also helps you resize your image
							 * by automatially calculating and entering the
							 * other dimension from the one you enter. " + "This
							 * too is useful when 'Ratio Adjustment' is
							 * selected,";
							 */
// "Of course you can turn off this assistance at anytime by selecting a 'Ratio
// Adjustment'. "
// "Please try to adjust the image size you want printed to match the size in
// the scaling " +
// "tool as close as possible, a \"Ratio Adjustment\" may be necessary. This
// scaling tool is here to help you " +
// "determine what sizes are available from your uploaded image. Entering one
// dimension in decimal form, " +
// "the scaling tool will adjust to the same width in inches & then calculate "
// +
// "the corresponding height & vice versa."
// var constraintStmt = "The aspect ratio of the uploaded image constrains
// 'Image Size' width and height. " +
// "Select one dimension; the program calculates the other one using the ratio,
// then selects the other " +
// "dimension that is within 1/4\" of the calculation. Selecting a 'Ratio
// Adjustment' option stops the " +
// "automatic dimension selection.";
var offStmt = "NOTE: Width and Height in 'Enter Image Size' are unlocked from each other.";
var onStmt = "NOTE: Width and Height in 'Enter Image Size' are locked to each other until 'Ratio Adjustment' is used.";
var mbPrice = new Object();
mbPrice.mb20 = 38.5;
mbPrice.mb40 = 49.5;
mbPrice.mb80 = 60.5;
mbPrice.mb150 = 82.5;
mbPrice.mb300 = 137.5;
mbPrice.mb450 = 181.5;
var button = "";
// 0-20MG - $35
// 21 - 40 - $45
// 41 - 80 -$55
// 81 - 150 -$75
// 151 300 -$125
// 300 - 450 - $165
// var mediaList = new Array("Enhanced matter: Flat matte smooth finish, yields
// sharp high saturation results.",
// "Canvas: water resistant 21 mil 430 gram flat matter finish with a poly
// cotton blend.",
// "Hannemule: 310 Gram Highly textured 100% rag mould made premiere water color
// paper.",
// "Premium luster: The professional photographers paper with a lustrous
// finish.",
// "Premium high gloss paper: Smooth vivid high gloss color also great for black
// and whites.",
// "Exhibition fiber: 325 grams 13 mil wide color gamut, simulates revered
// silver halide paper the ultimate for black & whites.",
// "Poster board: comes in 24x30 sheets, 1.2 mm flat matte surface, great for
// signing boards and easel displays.",
// "Satin cloth: bright white cloth for retractable banner stands, artist
// reproductions, backlit displays, window shades, and table skirts.",
// "Smooth vinyl: Great for banners & displays can be print job with grommets or
// looped ends free of charge. Loops ends for 'Rods' to hold banner requires
// 5-inch print or border on top and bottom thus 10\" extra",
// "Adhesive Vinyl: Flat matte surface with peel off backing that exposes
// adhesive for direct wall mounting.",
// "Back lit film: used in light boxes and the retail industry requires lighting
// to shine thru back of media.",
// "Wall mural without adhesive: Used and hung like standard wall paper.",
// "Wall mural textured adhesive: Can be used as wall paper, as a slight texture
// and an adhesive backing.",
// "High gloss poster paper: Thin, super high gloss, and inexpensive making it
// great for high impact posters.",
// "Double Sided Banner: Heavy 19 mil opaque Vinyl that is printable on boths
// sides with no see through. Grommets or looped ends free of charge. Loops ends
// for 'Rods' to hold banner requires 5-inch print or border on top and bottom
// thus 10\" extra");
var boxSpecArray = new Array(new Object(), new Object(), new Object(),
		new Object(), new Object(), new Object());
boxSpecArray[0].width = 35;
boxSpecArray[0].length = 44;
boxSpecArray[0].depth = 6;
boxSpecArray[0].cost = 5.46;
boxSpecArray[0].weight = 5.40;
boxSpecArray[1].width = 24;
boxSpecArray[1].length = 36;
boxSpecArray[1].depth = 4;
boxSpecArray[1].cost = 2.83;
boxSpecArray[1].weight = 1.75;
boxSpecArray[2].width = 22;
boxSpecArray[2].length = 28;
boxSpecArray[2].depth = 4;
boxSpecArray[2].cost = 2.44;
boxSpecArray[2].weight = 1.6;
boxSpecArray[3].width = 11.25;
boxSpecArray[3].length = 15;
boxSpecArray[3].depth = 3;
boxSpecArray[3].cost = 1.42;
boxSpecArray[3].weight = 0.50;
boxSpecArray[4].width = 12.5;
boxSpecArray[4].length = 17.5;
boxSpecArray[4].cost = 1.73;
boxSpecArray[4].weight = .61;
boxSpecArray[5].width = 18;
boxSpecArray[5].length = 22;
boxSpecArray[5].depth = 4;
boxSpecArray[5].cost = 2.08;
boxSpecArray[5].weight = 1.15;
var isPriceImageCall = false;
function initImage(wantsPriceOnly, printJobPage, viewJobDetail) {
	isPriceOnly = wantsPriceOnly;
	isOrderPage = printJobPage;
	var image = document.getElementById("imageFile");
	if (image) {
		imageObj = new Image();
		imageObj.src = image.src;
	}
	if (!isPriceOnly) {
		pixelWidth = document.getElementById("imageWidth") ? new Number(document.getElementById("imageWidth").value) : 0;
		pixelHeight = document.getElementById("imageHeight") ? new Number(document.getElementById("imageHeight").value) : 0;
		ppi = new Number(document.getElementById("ppi").value);
		isHandDelivery = ((pixelWidth > 0) && (pixelHeight > 0));
		if (imageObj.height > 0 || imageObj.width > 0) {
			pixelHeight = new Number(imageObj.height);
			pixelWidth = new Number(imageObj.width);
			isHandDelivery = false;
		}
		if (pixelHeight != 0 && pixelWidth != 0) {
			widthRatio = (pixelWidth / pixelHeight);
			heightRatio = (pixelHeight / pixelWidth);
			if (ppi == 0) {
				ppi = 150;
			}
			if (viewJobDetail) {
				imageWidth = (pixelWidth / 150);
				imageHeight = (pixelHeight / 150);
			} else {
				imageWidth = (pixelWidth / ppi);
				imageHeight = (pixelHeight / ppi);
			}
			document.getElementById("imageWidth").value = roundNumber(
					imageWidth, 2);
			document.getElementById("imageHeight").value = roundNumber(
					imageHeight, 2);
			printWidth = new Number(document.getElementById("printWidth").value);
			printHeight = new Number(
					document.getElementById("printHeight").value);
			if (printWidth == 0 && printHeight == 0) {
				document.getElementById("printWidth").value = printWidth = imageWidth;
				document.getElementById("printHeight").value = printHeight = imageHeight;
				document.getElementById("ppi").value = roundNumber(ppi, 2);
			}
			if (mediaList[document.getElementById("media").selectedIndex][0] == "Canvas") {
				document.getElementById("treat").style.display = '';
			}	
			if (document.getElementById("stretcherBar")) {
				setBarLength();
				priceBar();
			}
			resolutionCheck();
		}
		if (isOrderPage) {
			checkFit();
		}
	} else {
		printHeight = new Number(document.getElementById("printHeight").value);
		printWidth = new Number(document.getElementById("printWidth").value);
		widthRatio = 0;
		heightRatio = 0;
	}
	prevPrintWidth = printWidth;
	prevPrintHeight = printHeight;
	priceImage();
	isInitial = false;
	// imageObj = null;
}

function resolutionCheck() {
	if (!isPriceOnly) {
		if (ppi < 150 && ppi >= 100) {
			message = "Image size selected decreases the print resolution to "
					+ document.getElementById("ppi").value
					+ " dpi, which is below generally acceptable print quality. \nImage File size will be increased with special image enlargement software to provide the minimum 150 dpi for acceptable print quality.";
			displayErrorMessage();
			document.getElementById("jobOrderAction").disabled = false;
		} else if (ppi < 100) {
			message = "Image size selected decreases the print resolution to "
					+ document.getElementById("ppi").value
					+ " dpi, which may be too far below acceptable quality to print. \nEven our special image enlargement software might not produce acceptable print quality for the uploaded image file size. \nTherefore, we advise that you adjust the image size so that the PPI is greater than 100 or upload a larger image file.";
			displayErrorMessage();
			document.getElementById("jobOrderAction").disabled = false;
		} else {
			testWidth = pixelWidth / ppi;
			testHeight = pixelHeight / ppi;
			if (testWidth != printWidth || testHeight != printHeight) {
				fileWidth = printWidth * 150;
				fileHeight = printHeight * 150;
				fileSize = fileWidth * fileHeight / (1024 * 1024);
				message = "The uploaded image will not produce a print with the entered 'Width', 'Height', and 'ppi'. \n\nPlease enter a 'Width' value near " + Math.ceil(pixelWidth / 150) + " and a 'Height' value near " + Math.ceil(pixelHeight / 150) + " for a good print quality. Or upload around a " + roundNumber(fileSize, 2) + " MB file to print your entered size. ";
				displayErrorMessage();
				document.getElementById("jobOrderAction").disabled = false;
			}
		}
	}
}

function roundHalf(decimal) {
	var result = 0;
	var bottom = Math.floor(decimal);
	if (decimal == bottom) {
		result = new Number(decimal);
	} else {
		var temp = decimal * 100;
		temp = Math.round(temp) * .01;
		var half = bottom + .50;
		var top = Math.ceil(decimal);
		var mid = temp - bottom;
		if (temp == half) {
			result = temp;
		} else if (temp > half) {
			if (mid > .75) {
				result = top;
			} else {
				result = half;
			}
		} else {
			if (mid > .25) {
				result = half;
			} else {
				result = bottom;
			}
		}
	}
	return result;
}

function widthFromHeight() {
	temp = 0;
	if (widthRatio != 0) {
		if (printHeight) {
			printWidth = new Number(printHeight * widthRatio);
		}
	}
}

function heightFromWidth() {
	temp = 0;
	if (heightRatio != 0) {
		if (printWidth) {
			printHeight = new Number(printWidth * heightRatio);
		}
	}
}

function checkFit() {
	if (!isPriceOnly && !isInitial) {
		if (document.getElementById("stretcherBar").selectedIndex != 0
				&& !barFit()
				&& (document.getElementById("imageAdjustment").selectedIndex == 0)) {
			imageFits = false;
			document.getElementById("jobOrderAction").disabled = true;
			document.getElementById("fitStmt").innerHTML = "Image aspect ratio does not fit selected stretcher bar width and height. <span fontcolor=\"aqua\">The 'Place Order' "
					+ "button is disabled.</span> To place the print job , make a 'Ratio Adjustment' selection. In the 'Special Instruction' box, tell  us as to how to make "
					+ "the image fit your desired stretching frame.";
			document.getElementById("placeOrderStmt").innerHTML = "To place the print job , make a 'Ratio Adjustment' selection and provide instructions in 'Special Instructions' text area.";
		} else {
			imageFits = true;
			document.getElementById("fitStmt").innerHTML = "";
			document.getElementById("jobOrderAction").disabled = false;
			document.getElementById("placeOrderStmt").innerHTML = "";
			if (document.getElementById("stretcherBar").selectedIndex != 0) {
				if (!isEven(printWidth)) {
					if (barWrap() == borderWidth) {
						document.getElementById("printWidth").value = document
								.getElementById("barWidth").value;
					} else if (borderWidth < barWrap()) {
						document.getElementById("printWidth").value = new Number(
								document.getElementById("barWidth").value)
								+ (barWrap() - borderWidth);

					} else if (borderWidth > barWrap()) {
						document.getElementById("printWidth").value = new Number(
								document.getElementById("barWidth").value)
								+ (barWrap() - borderWidth);
					}
				} else if (!isEven(printHeight)) {
					if (barWrap() == borderWidth) {
						document.getElementById("printHeight").value = document
								.getElementById("barHeight").value;
					} else if (borderWidth < barWrap()) {
						document.getElementById("printHeight").value = new Number(
								document.getElementById("barHeight").value)
								+ (barWrap() - borderWidth);
					} else if (borderWidth > barWrap()) {
						document.getElementById("printHeight").value = new Number(
								document.getElementById("barHeight").value)
								+ (barWrap() - borderWidth);
					}
				}
			}
		}
		document.getElementById("constraintStmt").innerHTML = constraintStmt;
		if (document.getElementById("imageAdjustment").selectedIndex == 0) {
			document.getElementById("onOffStmt").innerHTML = onStmt;
		} else {
			document.getElementById("onOffStmt").innerHTML = offStmt;
		}
	}
}

function barFit() {
	var result = true;
	if (borderWidth == barWrap()) {
		if (barWidth != printWidth && barHeight != printHeight) {
			result = false;
		}
	} else {
		if (!isEven(printWidth) || !isEven(printHeight)) {
			result = false;
		}
	}
	return result;
}

function constrainImage(id) {
	if ((document.getElementById("stretcherBar").selectedIndex == 0)
			|| barChange || barSizeChange || edgeTreatChange) {
		var tempPaperSize;
		var tempBorderWidth;
		var tempBarSize;
		var tempSize;
		barIndex = document.getElementById("stretcherBar").selectedIndex;
		if (barSizeChange) {
			imageChange = false;
			barChange = false;
			borderChange = false;
		} else if (barChange) {
			imageChange = false;
			borderChange = false;
		} else if (borderChange) {
			imageChange = false;
		} else if (edgeTreatChange) {
			imageChange = false;
		} else {
			imageChange = true;
		}
		if (id == "printHeight") {
			if (!barChange) {
				printHeight = new Number(
						document.getElementById("printHeight").value);
			}
			if ((barIndex != 0)
					&& (printHeight > (paperHeight - (2 * printBarWrapBorder())))) {
				message = "Sorry, since you want to mount the image on stretcher bars, the selected "
						+ printHeight
						+ "\" Printed Image Height would place printed image against the  wall where it would not be visible.";
				displayErrorMessage();
				printHeight = prevPrintHeight;
				document.getElementById("printHeight").value = roundNumber(
						printHeight, 2);
			} else { // printHeight < paperHeight
				if (!isPriceOnly || widthRatio != 0) {
					widthFromHeight();
				}
				if (document.getElementById("imageAdjustment").selectedIndex == 0) {
					document.getElementById("printWidth").value = roundNumber(
							printWidth, 2);
				} else { // image adjustment selected
					printWidth = new Number(document
							.getElementById("printWidth").value);
				} // now have printWidth value
				if (barIndex != 0) { // stretcher bar selected
					if (barSizeChange) {
						paperWidth = printWidth + (2 * borderWidth);
						tempBarSize = paperWidth - (2 * barWrap());
						tempSize = Math.floor(tempBarSize);
						document.getElementById("barWidth").value = barWidth = isEven(tempSize) ? tempSize
								: ((tempSize + 1 > tempBarSize) ? tempSize - 1
										: tempSize + 1);
						if (tempSize != barWidth
								|| tempSize != document
										.getElementById("barWidth").value) {
							document.getElementById("jobOrderAction").disabled = true;
							paperWidth = barWidth + (2 + barWrap());
							message = "Sorry, the supplied Image Width does not match the required Bar Width. Select a 'Ratio Adjustment' "
									+ "and provide additional instructions in 'Special Instruction' text area to place the print job . \nRead text "
									+ "below 'Stretcher Bar' fields for further explanation.";

							displayErrorMessage();
							document.getElementById("jobOrderAction").disabled = true;
						}
					} else if (imageChange) {
						borderWidth = ((paperHeight - printHeight) / 2);
					} else if (barChange) {
						paperWidth = new Number(document
								.getElementById("barWidth").value)
								+ (2 * barWrap());
					}
				} // end stretcher bar selected
				if (isPriceOnly && pixelHeight == 0) {
					ppi = 300;
					pixelHeight = ppi * printHeight;

				} else {
					ppi = (pixelHeight / printHeight);
				}
				document.getElementById("ppi").value = roundNumber(ppi, 2);
			} // end printHeight < paperHeight
		} else { // id == "printWidth"
			if (!barChange) {
				printWidth = new Number(
						document.getElementById("printWidth").value);
			}
			if (barIndex != 0
					&& (printWidth > (paperWidth - (2 * printBarWrapBorder())))) { // print
				// on
				// back
				message = "Sorry, since you want to mount the image on stretcher bars, the selected "
						+ printWidth
						+ "\" Printed Image Width would place printed image against the  wall where it would not be visible.";
				displayErrorMessage();
				printWidth = prevPrintWidth;
				document.getElementById("printWidth").value = roundNumber(
						printWidth, 2);
			} else { // print not on back
				if (!isPriceOnly || heightRatio != 0) {
					heightFromWidth();
				}
				if (document.getElementById("imageAdjustment").selectedIndex == 0) { // no
					document.getElementById("printHeight").value = roundNumber(
							printHeight, 2);
				} else { // adjustment
					printHeight = new Number(document
							.getElementById("printHeight").value);
				} // continue processing
				if (barIndex != 0) { // stretcher bar selected
					if (barSizeChange) {
						paperHeight = printHeight + (2 * borderWidth);
						tempBarSize = paperHeight - (2 * barWrap());
						tempSize = Math.floor(tempBarSize);
						document.getElementById("barHeight").value = barHeight = isEven(tempSize) ? tempSize
								: ((tempSize + 1 > tempBarSize) ? tempSize - 1
										: tempSize + 1);
						if (tempSize != barHeight
								|| tempSize != document
										.getElementById("barHeight").value) {
							document.getElementById("jobOrderAction").disabled = true;
							paperHeight = barHeight + (2 * barWrap());
							message = "Sorry, the supplied Image Height does not match the required Bar Height. Select a 'Ratio Adjustment' and provide additional instructions in 'Special Instruction' text area to place the print job .";
							displayErrorMessage();
							document.getElementById("jobOrderAction").disabled = true;
						}
					} else if (imageChange) {
						borderWidth = roundNumber(
								((paperWidth - printWidth) / 2), 2);
					} else if (barChange) {
						paperHeight = new Number(document
								.getElementById("barHeight").value)
								+ (2 * barWrap());
					}
				} // stretcher bar not selected
				if (isPriceOnly && pixelWidth == 0) {
					ppi = 300;
					pixelWidth = ppi * printWidth;
				} else {
					ppi = (pixelWidth / printWidth);
				}
				document.getElementById("ppi").value = roundNumber(ppi, 2);
			} // end print not on back
		} // end id == printWidth
		if (isPriceOnly && pixelWidth != 0 && pixelHeight != 0
				&& widthRatio == 0 && heightRatio == 0) {
			widthRatio = (pixelWidth / pixelHeight);
			heightRatio = (pixelHeight / pixelWidth);
		}
		resolutionCheck();
		if (isOrderPage) {
			checkFit();
		}
		if (mediaList[document.getElementById("media").selectedIndex][0] == "Enhanced matte poster board") {
			if (printHeight > printWidth) {
				if (printHeight > 30) {
					document.getElementById("printHeight").value = printHeight = prevPrintHeight;
					document.getElementById("printWidth").value = printWidth = prevPrintWidth;
				} else if (printWidth > 24) {
					document.getElementById("printHeight").value = printHeight = prevPrintHeight;
					document.getElementById("printWidth").value = printWidth = prevPrintWidth;
				}
			} else {
				if (printWidth > 30) {
					document.getElementById("printHeight").value = printHeight = prevPrintHeight;
					document.getElementById("printWidth").value = printWidth = prevPrintWidth;
				} else if (printHeight > 24) {
					document.getElementById("printHeight").value = printHeight = prevPrintHeight;
					document.getElementById("printWidth").value = printWidth = prevPrintWidth;
				}
			}
		}
		prevPrintHeight = printHeight;
		prevPrintWidth = printWidth;
		priceImage();
	} else {
		message = "Sorry, the Printed Image "
				+ (id == "printWidth" ? "Width" : "Height")
				+ " cannot change when you have selected 'Edge Treatment' and 'Stretcher Bars'. To change the 'Printed Image "
				+ (id == "printWidth" ? "Width" : "Height")
				+ ", change the 'Bar "
				+ (id == "printWidth" ? "Width" : "Height") + ".";
		displayErrorMessage();
		if (id == "printWidth") {
			document.getElementById("printWidth").value = roundNumber(
					prevPrintWidth, 2);
		} else {
			document.getElementById("printHeight").value = roundNumber(
					prevPrintHeight, 2);
		}
	}
}

var isCanvasSet = false;
function priceImage() { // v1.0
	
	numberPrints = new Number(document.getElementById("quantity").value);
	if (printWidth == 0) {
		printWidth = new Number(document.getElementById("printWidth").value);
	}
	if (printHeight == 0) {
		printHeight = new Number(document.getElementById("printHeight").value);
	}
	printArea = roundNumber(printWidth * printHeight / 144, 2);
	if (isOrderPage || isPriceOnly) {
		/*
		 * if ((mediaList[document.getElementById("media").selectedIndex][0] ==
		 * "Double sided banner") ||
		 * (mediaList[document.getElementById("media").selectedIndex][0] ==
		 * "Smooth vinyl banner")) {
		 * document.getElementById("banner").style.visibility = "visible";
		 * document.getElementById("mediaList").colspan = 4; } else {
		 * document.getElementById("banner").style.visibility = "hidden";
		 * document.getElementById("mediaList").colspan = 5; }
		 */
		document.getElementById("mediaText").innerHTML = mediaList[document
				.getElementById("media").selectedIndex][1];
		mediaCost = new Number(
				mediaList[document.getElementById("media").selectedIndex][2]);
		if (mediaList[document.getElementById("media").selectedIndex][0] == "Canvas") {
			document.getElementById("treat").style.display = '';
		} else if (isEdgeTreat) {
			document.getElementById("borderWidth").value = borderWidth = 0;
			document.getElementById("edgeWidth").value = edgeWidth = 0;
			isPriceImageCall = true;
			checkEdgeTreat("edgeWidth");
			isPriceImageCall = false;
			document.getElementById("treat").style.display = 'none';
			
		}
		if (document.getElementById("stretcherBar").selectedIndex != 0
				&& mediaList[document.getElementById("media").selectedIndex][0] != "Canvas") {
			document.getElementById("stretcherBar").selectedIndex = 0;
            priceBar();
		}
		if (mediaList[document.getElementById("media").selectedIndex][0] == "Enhanced matte poster board") {
			message = mediaList[document.getElementById("media").selectedIndex][0]
					+ " currently is only "
					+ "available in 24\" X 30\" sheets; therefore the $40.00 Image Cost will be for the full sheet.\n\n";
			if (!isPriceOnly) {
				message = message
						+ "For specific dimensions less then 24\" X 30\", select 'Trim Print' option "
						+ "and give size in 'Special Instructions' text area.";
			}
			displayErrorMessage();
			document.getElementById("laminateType").disabled = false; // lam
			// yes
			document.getElementById("mounting").disabled = true;
			document.getElementById("borderWidth").disabled = true;
			document.getElementById("borderWidth").value = 0;
			printCost = 40.00;
		} else {
			document.getElementById("borderWidth").disabled = false;
			if ((mediaList[document.getElementById("media").selectedIndex][0] == "Back light film")
					|| (mediaList[document.getElementById("media").selectedIndex][0] == "Wall mural paper w/o glue")
					|| (mediaList[document.getElementById("media").selectedIndex][0] == "Wall mural fabric w/glue")
					|| (mediaList[document.getElementById("media").selectedIndex][0] == "Satin cloth")) {
				document.getElementById("mounting").disabled = true; // lam
				// no
				document.getElementById("laminateType").disabled = true; // mount
				// no
				document.getElementById("mounting").selectedIndex = 0; // mount
				// no
			} else if ((mediaList[document.getElementById("media").selectedIndex][0] == "Canvas")
					|| (mediaList[document.getElementById("media").selectedIndex][0] == "Hahnemuhle WT 310 Fine art")
					|| (mediaList[document.getElementById("media").selectedIndex][0] == "Premium luster")
					|| (mediaList[document.getElementById("media").selectedIndex][0] == "Premium high gloss")
					|| (mediaList[document.getElementById("media").selectedIndex][0] == "High gloss poster paper")
					|| (mediaList[document.getElementById("media").selectedIndex][0] == "Exhibition fiber")) {
				document.getElementById("laminateType").disabled = true; // lam
				// no
				document.getElementById("mounting").disabled = false; // mount
				// yes
			} else if ((mediaList[document.getElementById("media").selectedIndex][0] == "Enhanced matte poster board")
					|| (mediaList[document.getElementById("media").selectedIndex][0] == "Smooth vinyl banner")
					|| (mediaList[document.getElementById("media").selectedIndex][0] == "Double sided banner")) {
				document.getElementById("laminateType").disabled = false; // lam
				// yes
				document.getElementById("mounting").disabled = true; // mount
				// no
				document.getElementById("mounting").selectedIndex = 0; // mount
				// no
			} else {
				document.getElementById("mounting").disabled = false;
				document.getElementById("laminateType").disabled = false;
			}
			// if ((mediaList[document.getElementById("media").selectedIndex][0]
			// == "Wall Mural Paper w/o glue") ||
			// (mediaList[document.getElementById("media").selectedIndex][0] ==
			// "Wall Mural Fabric w/glue")) {
			// document.getElementById("varnish").checked = true; // varnish
			// required
			// }
			printCost = (mediaCost * printArea * numberPrints);
		}
		document.getElementById("printCost").value = roundNumber(printCost, 2);
		document.getElementById("mediaName").value = mediaList[document
				.getElementById("media").selectedIndex][0];
	}
	document.getElementById("printedArea").value = roundNumber(
			(printArea * numberPrints), 2);
	priceBorder();
}

function printBarWrapBorder() {
	var result = barWrap();
	if ((document.getElementById("edgeTreat") 
			&& document.getElementById("edgeTreat").checked) 
		|| (document.getElementById("userEdgeTreat") 
				&& document.getElementById("userEdgeTreat").checked)) {
		result -= edgeValue();
	}
	return result;
}

var finalPrice = false;
function priceBorder() {
	if (document.getElementById("stretcherBar").selectedIndex == 0 || isInitial
			|| edgeTreatChange	|| barChange || barSizeChange || finalPrice) {
		borderCost = 0.00;
		var tempBorderWidth = new Number(
				document.getElementById("borderWidth").value);
		var treatWidth = new Number(document.getElementById("edgeWidth").value);
		barIndex = document.getElementById("stretcherBar").selectedIndex;
		if (barIndex != 0
				|| document.getElementById("barHeight").selectedIndex != 0
				|| document.getElementById("barWidth").selectedIndex != 0) { // bars
			// selected
			var wrap = barWrap();
			var tempBorder;
			if (!barChange && !barSizeChange && !edgeTreatChange && !isInitial) { // bar
				// width
				// and
				// height
				// are
				// set
				if (imageChange) { // image changed
					if (isEven(paperWidth)) {
						borderWidth = roundNumber(
								((paperWidth - printWidth) / 2), 2);
					} else {
						borderWidth = roundNumber(
								((paperHeight - printHeight) / 2), 2);
					}
					if (borderWidth != tempBorderWidth) {
						document.getElementById("borderWidth").value = roundNumber(
								borderWidth, 2);
					}
				} else { // user changed border
					borderChange = true;
					if (priceBorderCnt++ == 0) {
						if (tempBorderWidth < printBarWrapBorder()) { // image
							// on
							// back
							message = "Sorry, since you want to mount the image on stretcher bars, the selected "
									+ tempBorderWidth
									+ "\" Border Width would place printed image against the  wall where it would not be visible. "
									+ " Set the Border Width to "
									+ printBarWrapBorder()
									+ " to wrap image around edge of Stretcher Bar.";
							displayErrorMessage();
							tempBorderWidth = borderWidth;
							document.getElementById("borderWidth").value = roundNumber(
									borderWidth, 2);
						} else if ((tempBorderWidth > printBarWrapBorder())
								&& (tempBorderWidth < barWrap())) { // image on
							// back
							message = "Sorry, since you want to mount the image on stretcher bars, the selected "
									+ tempBorderWidth
									+ "\" Border Width would place printed image only part way on bar edge. "
									+ " Set the Border Width to "
									+ printBarWrapBorder()
									+ " to wrap image around edge of Stretcher Bar.";
							displayErrorMessage();
							tempBorderWidth = borderWidth;
							document.getElementById("borderWidth").value = roundNumber(
									borderWidth, 2);
						} else { // image not on back
							borderWidth = tempBorderWidth;
							printWidth = paperWidth - (2 * borderWidth);
							document.getElementById("printWidth").value = roundNumber(
									printWidth, 2);
							printHeight = paperHeight - (2 * borderWidth);
							document.getElementById("printHeight").value = roundNumber(
									printHeight, 2);
						} // end image not on back
					} // priceBorderCount
				}
			} else if (barChange || edgeTreatChange) { // barChange
				if (priceBorderCnt++ == 0) {
						printWidth = paperWidth - (2 * borderWidth);
						document.getElementById("printWidth").value = roundNumber(
								printWidth, 2);
						printHeight = paperHeight - (2 * borderWidth);
						document.getElementById("printHeight").value = roundNumber(
								printHeight, 2);
				}
// } else if (edgeTreatChange) { // barChange
// if (priceBorderCnt++ == 0) {
// if (isEven(printWidth)) {
// constrainImage("printWidth");
// } else {
// constrainImage("printHeight");
// }
// }
			} else if (isInitial) { // barChange
				borderWidth = tempBorderWidth;
				paperWidth = printWidth + (borderWidth * 2);
				paperHeight = printHeight + (borderWidth * 2);
			}
		} else { // bars not selected
			borderWidth = tempBorderWidth;
			paperWidth = printWidth + (borderWidth * 2);
			paperHeight = printHeight + (borderWidth * 2);
			if ((mediaList[document.getElementById("media").selectedIndex][0] == "Double sided banner")) {
				paperHeight = paperHeight + 10;
			}
		}
		if (mediaList[document.getElementById("media").selectedIndex][0] == "Enhanced matte poster board") {
			if (paperWidth < paperHeight) {
				paperWidth = 24;
				paperHeight = 30;
			} else {
				paperWidth = 30;
				paperHeight = 24;
			}
		}
		paperArea = roundNumber(((paperWidth * paperHeight) / 144), 2);
		borderCost = (paperArea - printArea)
				* (new Number(
						mediaList[document.getElementById("media").selectedIndex][3]))
				* numberPrints;
		if (document.getElementById("paperWidth")) {
			document.getElementById("paperWidth").value = roundNumber(paperWidth, 2);
		}
		if (document.getElementById("paperHeight")) {
			document.getElementById("paperHeight").value = roundNumber(paperHeight,
				2);
		}
		document.getElementById("borderArea").value = roundNumber(
				((paperArea - printArea) * numberPrints), 2);
		document.getElementById("borderCost").value = roundNumber(borderCost, 2);
		if (document.getElementById("paperArea")) {
			document.getElementById("paperArea").value = roundNumber(paperArea, 2);
		}
		priceExcessPaper();
		if ((paperWidth <= 44 || paperHeight <= 44)
				&& (ppi >= 100 && (imageFits || document
						.getElementById("imageAdjustment").selectedIndex != 0))) {
			if (document.getElementById("jobOrderAction")) {
				document.getElementById("jobOrderAction").disabled = false;
			}
		}
		if (!edgeTreatChange && !barSizeChange && !barChange) {
			isPriceServices = isInitial ? false : true;
			priceServices();
		}
	} else {
		message = "Sorry, the 'Border Width' cannot change when you have selected 'Edge Treatment' and 'Stretcher Bars'. "
				+ " To change the 'Border Width', deselect 'Stretcher Bars'.";
		displayErrorMessage();
		document.getElementById("borderWidth").value = roundNumber(borderWidth,
				2);
	}
}

var lastDigital = "";
function priceDigitalArtwork() {
	if (document.getElementById("digitalArtworkCost") != null) {
		digitalArtworkCost = 0.00;
		selPhotoArtwork();
		selArtworkScan();
		document.getElementById("digitalArtworkCost").value = roundNumber(
				digitalArtworkCost, 2);
		calcSubTotal();
	}
}

function selPhotoArtwork() {
	if (document.getElementById("photoArtwork") != null) {
		document.getElementById("photoArtRate").innerHTML = numberPrints > 4 ? "25.00"
				: "30.00";
		if (document.getElementById("photoArtwork").checked) {
			if (document.getElementById("artworkScan").selectedIndex > 0
					&& lastDigital == "scan") {
				document.getElementById("artworkScan").selectedIndex = 0;
			}
			lastDigital = "photo";
			digitalArtworkCost = (numberPrints > 4 ? 25 : 30) * numberPrints;
		}
	}
}

function selArtworkScan() {
	if (document.getElementById("artworkScan") != null) {
		if (document.getElementById("artworkScan").selectedIndex > 0) {
			if (document.getElementById("photoArtwork").checked
					&& lastDigital == "photo") {
				document.getElementById("photoArtwork").checked = false;
			}
			lastDigital = "scan";
			var dpi = document.getElementById("artworkScan").value;
			var mb = (printWidth * dpi) * (printHeight * dpi) * 3 * .000001;
			if (mb < 21) {
				digitalArtworkCost = mbPrice.mb20;
			} else if (mb > 20 && mb < 41) {
				digitalArtworkCost = mbPrice.mb40;
			} else if (mb > 40 && mb < 81) {
				digitalArtworkCost = mbPrice.mb80;
			} else if (mb > 80 && mb < 151) {
				digitalArtworkCost = mbPrice.mb150;
			} else if (mb > 150 && mb < 301) {
				digitalArtworkCost = mbPrice.mb300;
			} else if (mb > 300 && mb < 451) {
				digitalArtworkCost = mbPrice.mb450;
			}
		}
	}
}

function priceColorCorrection() {
	if (document.getElementById("colorCorrect") != null) {
		totalColorCorrectCost = 0.00;
		if (document.getElementById("colorCorrect").checked) {
			totalColorCorrectCost += 5;
		}
		if (document.getElementById("artEffect").checked) {
			totalColorCorrectCost += 25;
		}
		if (document.getElementById("proof").checked) {
			totalColorCorrectCost += 5;
		}
		if (!document.getElementById("proof").checked) {
			if (document.getElementById("shipCorrectProof").checked) {
				document.getElementById("shipCorrectProof").checked = false;
			}
		}
		if (document.getElementById("shipCorrectProof").checked) {
			if (!document.getElementById("proof").checked) {
				document.getElementById("proof").checked = true;
				totalColorCorrectCost += 5;
			}
			totalColorCorrectCost += 2;
		}
		document.getElementById("totalColorCorrectCost").value = roundNumber(
				totalColorCorrectCost, 2);
		if (!isPriceServices && !isInitial) {
			isPriceServices = true;
			priceServices();
		}
	}
}

function priceColorMatch() {
	if (document.getElementById("colorMatch") != null) {
		totalColorMatchCost = 0.00;
		if (document.getElementById("colorMatch").checked) {
			totalColorMatchCost += 25;
		}
		if (document.getElementById("proofOnly").checked) {
			totalColorMatchCost += 5;
		}
		if (document.getElementById("shipMatchProof").checked) {
			totalColorMatchCost += 2;
		}
		document.getElementById("totalColorMatchCost").value = roundNumber(
				totalColorMatchCost, 2);
		if (!isPriceServices && !isInitial) {
			isPriceServices = true;
			priceServices();
		}
	}
}

function priceTrim() {
	// if (document.getElementById("mounting".selectedIndex == 0) {
	trimCost = 0.00;
	if (document.getElementById("trim").checked) {
		trimCost = (trimPrice * 4 * numberPrints);
	}
	document.getElementById("trimCost").value = roundNumber(trimCost, 2);
	if (!isPriceServices && !isInitial) {
		isPriceServices = true;
		priceServices();
	}
	// }
}

function priceVarnish() {
	varnishCost = 0.00;
	if (document.getElementById("varnish").checked) {
		document.getElementById("laminateType").selectedIndex = 0;
		varnishCost = (1.50 * paperArea * numberPrints);
	}
	document.getElementById("varnishCost").value = roundNumber(varnishCost, 2);
	if (!isPriceServices && !isInitial) {
		isPriceServices = true;
		priceServices();
	}
}

function priceMount() {
	mountingCost = 0.00;
	var mountIdx = document.getElementById("mounting").selectedIndex;
	if (document.getElementById("laminateType").selectedIndex == 0) {
		document.getElementById("trim").disabled = false;
	}
	if (mountIdx > 0) {
		document.getElementById("trim").checked = true;
		document.getElementById("trim").disabled = true;
		document.getElementById("stretcherBar").selectedIndex = 0;
		mountingCost = (numberPrints * paperArea * (new Number(boardList[mountIdx][4])));
	}
	document.getElementById("mountName").value = boardList[mountIdx][0];
	document.getElementById("mountingCost").value = roundNumber(mountingCost, 2);
	if (!isPriceServices && !isInitial) {
		isPriceServices = true;
		priceServices();
	}
}

function priceLaminate() {
	laminateCost = 0.00;
	if (document.getElementById("mounting").selectedIndex == 0) {
		document.getElementById("trim").disabled = false;
	}
	if (document.getElementById("laminateType").selectedIndex > 0) {
		document.getElementById("trim").checked = true;
		document.getElementById("trim").disabled = true;
		document.getElementById("varnish").checked = false;
		document.getElementById("stretcherBar").selectedIndex = 0;
		laminateCost = (numberPrints * paperArea * (new Number(document
				.getElementById("laminateType").value)));
	}
	document.getElementById("laminateCost").value = roundNumber(laminateCost, 2);
	document.getElementById("laminateName").value = laminateName[document
			.getElementById("laminateType").selectedIndex];
	if (!isPriceServices && !isInitial) {
		isPriceServices = true;
		priceServices();
	}
}

function barWrap() {
	barIndex = new Number(
			document.getElementById("stretcherBar").selectedIndex);
	return new Number(barList[barIndex][6][0]);
}

function edgeValue() {
	barIndex = new Number(
			document.getElementById("stretcherBar").selectedIndex);
	return new Number(barList[barIndex][3][0]);
}

function changeBarSize(id) {
	barSizeChange = true;
	barChange = false;
	imageChange = false;
	if (document.getElementById("stretcherBar").selectedIndex == 0) {
		document.getElementById("stretcherBar").selectedIndex = 1;
		setCanvasMedia();
	}
	borderWidth = barWrap();
	document.getElementById("borderWidth").value = roundNumber(borderWidth, 2);
	if (id == "barWidth") {
		barWidth = new Number(document.getElementById("barWidth").value);
		paperWidth = barWidth + (2 * barWrap());
		printWidth = paperWidth - (2 * borderWidth);
		document.getElementById("printWidth").value = roundNumber(printWidth, 2);
		constrainImage("printWidth");
	} else { // id == "barHeight"
		barHeight = new Number(document.getElementById("barHeight").value);
		paperHeight = barHeight + (2 * barWrap());
		printHeight = paperHeight - (2 * borderWidth);
		document.getElementById("printHeight").value = roundNumber(printHeight,
				2);
		constrainImage("printHeight");
	}
	priceBar();
	barSizeChange = false;
}

function isEven(value) {
	if (value % 2 == 0)
		return true;
	else
		return false;
}

function setCanvasMedia() {
	for (i = 0; i < mediaList.length; i++) {
		if (mediaList[i][0] == "Canvas") {
			document.getElementById("media").selectedIndex = i;
			document.getElementById("treat").style.display = '';
			isCanvasSet = true;
			break;
		}
	}
}

function setBarLength() {
	var index = new Number(
			document.getElementById("stretcherBar").selectedIndex);
    var lengths = barList[index][8],
        barWidth = document.forms["order"].elements["barWidth"],
        barHeight = document.forms["order"].elements["barHeight"],
        barDesc = barList[index][1][0];
    barWidth.options.length = 0;
    barHeight.options.length = 0;
	for (var i = 0; i < lengths.length; i++) {
		barWidth.options[i] = new Option(lengths[i]+'"', lengths[i]);
		barHeight.options[i] = new Option(lengths[i]+'"', lengths[i]);
    }
	document.getElementById("barDesc").innerHTML = barDesc;
}

function priceBar() {
	var isEdgeTreat = (document.getElementById("edgeTreat") 
            && document.getElementById("edgeTreat").checked); 
    var isUserEdgeTreat = (document.getElementById("userEdgeTreat") 
            && document.getElementById("userEdgeTreat").checked);
	if (isUserEdgeTreat && prevBarIdx > 0) {
		message = "You checked 'User applied edge on this print' and the supplied " +
				"image size is for the current bar type and width and height. " +
				"If you want a different bar type and width and height, cancel " +
				"this print job and upload the correct image. \nIf this edge " +
				"selection was in error, then uncheck the treatment selection first " +
				"before changing the bar selection.";
		displayErrorMessage();
		if (document.getElementById("stretcherBar")) {
			document.getElementById("stretcherBar").selectedIndex = prevBarIdx;
		}
		setBarLength();
		document.getElementById("barWidth").value = barWidth;
		document.getElementById("barHeight").value = barHeight;
	} else {
		barIndex = new Number(
				document.getElementById("stretcherBar").selectedIndex);
		var stmt = "";
		var tempSize = 0;
        if (barIndex == 0) {
		barWidth = 0;
		barHeight = 0;
		stretcherBarCost = 0.00;
		document.getElementById("barDesc").innerHTML = barList[barIndex][1][0];
		document.getElementById("barStmt").innerHTML = "";
		document.getElementById("wrapStmt1").innerHTML = "";
		document.getElementById("wrapStmt2").innerHTML = "";
		if (document.getElementById("noStretch")) { 
			document.getElementById("noStretch").checked = false;
			document.getElementById("noStretch").disabled = true;
		}
		if (document.getElementById("barWidth").value > 0
				&& document.getElementById("barHeight").value > 0) {
			document.getElementById("printWidth").value = printWidth = new Number(document
					.getElementById("barWidth").value);
			document.getElementById("printHeight").value = printHeight = new Number(document
					.getElementById("barHeight").value);
			paperWidth = printWidth	+ 2 * borderWidth;
			if (document.getElementById("paperWidth")) {
				document.getElementById("paperWidth").value = paperWidth;
			}
			paperHeight = printHeight + 2 * borderWidth;
			if (document.getElementById("paperHeight")) {
				document.getElementById("paperHeight").value = paperHeight;
			}
		}
		setBarLength();
	} else { // barIndex != 0
		var barWidthIndex = document.getElementById("barWidth").selectedIndex;
		var barHeightIndex = document.getElementById("barHeight").selectedIndex;
		var barSelUserTreatError = false;
		if (!isPriceServices) {
			if (borderChange) {
				barChange = false;
				imageChange = false;
				barSizeChange = false;
			} else if (barSizeChange) {
				barChange = false;
				imageChange = false;
			} else if (imageChange) {
				barChange = false;
			} else {
				if (!edgeTreatChange) {
					barChange = true;
				}
				if (document.getElementById("noStretch")) {
					document.getElementById("noStretch").disabled = false;
				}
				setCanvasMedia();
				if (barWidthIndex == 0 && barHeightIndex == 0) { // not set
					if (isUserEdgeTreat) {
						if (barList[barIndex][3][0] != document.getElementById("edgeWidth").value) {
							message = "You checked 'User applied edge on this print' and the supplied " +
							"image size does not match your selected bar type. " +
							"Please select the bar type that matches the edge width of your treatment. \n" +
							"If your selected edge width is in error, then select the correct edge width;" +
							"otherwise,  cancel this print job and upload the correct image.";
							displayErrorMessage();
							barSelUserTreatError = true;
						} else {
							barWidth = printWidth - 2*edgeValue();
							document.getElementById("barWidth").value = barWidth;
							barHeight = printHeight - 2*edgeValue();
							document.getElementById("barHeight").value = barHeight;
						}
					} else if (isEdgeTreat) {
						barWidth = printWidth - (2 * document.getElementById("edgeWidth").value);
						barHeight = printHeight - (2 * document.getElementById("edgeWidth").value);
					} else {
    					tempSize = Math.floor(printWidth);
    					barWidth = isEven(tempSize) ? tempSize
							: ((tempSize + 1 > printWidth) ? tempSize - 1
									: tempSize + 1);
    					if ((!isEdgeTreat && !isUserEdgeTreat) && ((barWidth - .25) > printWidth || printWidth > (barWidth + .25))) {
	    					document.getElementById("jobOrderAction").disabled = true;
			    			message = "Sorry, the Image Width does not match the required Bar Width. Select a 'Ratio Adjustment' to place the print job .";
				    		document.getElementById("placeOrderStmt").innerHTML = "To place the print job , make a 'Ratio Adjustment' selection and provide instructions in 'Special Instructions' text area.";
					    	displayErrorMessage();
    					}
	    				tempSize = Math.floor(printHeight);
		    			barHeight = isEven(tempSize) ? tempSize
							: ((tempSize + 1 > printWidth) ? tempSize - 1
			
									: tempSize + 1);
				    	if ((!isEdgeTreat && !isUserEdgeTreat) && ((barHeight - .25) > printHeight || printHeight > (barHeight + .25))) {
					    	document.getElementById("jobOrderAction").disabled = true;
    						message = "Sorry, the Image Height does not match the required Bar Height. Select a 'Ratio Adjustment' to place the print job .";
	    					document.getElementById("placeOrderStmt").innerHTML = "To place the print job , make a 'Ratio Adjustment' selection and provide instructions in 'Special Instructions' text area.";
		    				displayErrorMessage();
			    		}
					}
// }
					if (barSelUserTreatError) {
						document.getElementById("stretcherBar").selectedIndex = prevBarIdx;
						setBarLength();
					} else {
						prevBarIdx = barIndex;
					}
				} else { // bar size set
					barWidth = new Number(
							document.getElementById("barWidth").value);
					barHeight = new Number(
							document.getElementById("barHeight").value);
				}
				paperWidth = barWidth + (2 * barWrap());
				paperHeight = barHeight + (2 * barWrap());
				borderWidth = printBarWrapBorder();
				printWidth = paperWidth - (2 * borderWidth);
				printHeight = paperHeight - (2 * borderWidth);
				document.getElementById("borderWidth").value = borderWidth;
				if (document.getElementById("paperWidth")) {
					document.getElementById("paperWidth").value = paperWidth;
				}
				if (document.getElementById("paperHeight")) {
					document.getElementById("paperHeight").value = paperHeight;
				}
				document.getElementById("printWidth").value = printWidth;
				document.getElementById("printHeight").value = printHeight;
				// if (barWidthIndex != 0 && barHeightIndex != 0) {
				// if (isEven(printWidth)) {
				// document.getElementById("printWidth").value = (barWidth -
				// printBarWrapBorder());
				// constrainImage("printWidth");
				// } else {
				// document.getElementById("printHeight").value = (barHeight -
				// printBarWrapBorder());
				// constrainImage("printHeight");
				// }
				// }
				if (barChange || document.getElementById("edgeTreat").checked
		    			|| document.getElementById("userEdgeTreat").checked) {
					priceImage();
				}
				// printWidth = paperWidth - (2 * borderWidth);
				// printHeight = paperHeight - (2 * borderWidth);
				if (document.getElementById("trim").checked) {
					document.getElementById("trim").checked = false;
					document.getElementById("trim").disabled = false;
				}
				if (document.getElementById("mounting").selectedIndex != 0) {
					document.getElementById("mounting").selectedIndex = 0;
				}
				if (document.getElementById("laminateType").selectedIndex != 0) {
					document.getElementById("laminateType").selectedIndex = 0;
				}
			} // barIndex != 0
			stretcherBarCost = ((barWidth + barHeight) * 2
					* barList[barIndex][5][0] * numberPrints);
			var stmt;
			if (document.getElementById("stretcherBar").selectedIndex > 0) {
				if (isEdgeTreat) {
					document.getElementById("edgeWidth").value = edgeValue();
			    	stmt = "Because we are applying a mirrored edge treatment, for this size stretcher bar "
	    				+ "the edge of the canvas is fixed at "
		    			+ barWrap() + "\" beyond the edge of the supplied image"
			    		+"<br />Only the " + edgeValue() + "\" next to the image "
							+ "receives the edge treatment.";
				} else if (isUserEdgeTreat) {
					var printWrap = document.getElementById("edgeWidth").value;
					stmt = "Because you applied the edge treatment to the image, for this size stretcher bar "
					+ "the edge of the canvas is fixed at "
					+ printWrap
					+ "\" beyond the edge of the supplied image.";				
			    } else if (document.getElementById("borderWidth").value < barWrap()) {
					stmt = "Because the printed image is to wrap around the bars, for this size stretcher bar "
						+ "the edge of the canvas is fixed at "
						+ printBarWrapBorder()
						+ "\" beyond the edge of the image.";				
				} else {
					stmt = "This size stretcher bar requires "
						+ barWrap()
						+ "\" of Canvas to wrap and fasten to the bar. Therefore, "
						+ barWrap()
						+ "\" of "
						+ "border is added in print job  to have the image size match the bar size found above.";
				// Make sure the stretcher bar width and height found above " +
				// "is the size you want, for this bar add at least " +
				// stretchBorder + " inches of border for wrapping the canvas.
				// <br/>For " +
				// "a white border on the front of the canvas add additional
				// border but watch your bar size and adjust the image size
				// accordingly.";
			    }
				document.getElementById("barStmt").innerHTML = stmt;
			}
		} // !isPriceServices
		var imgToFrameEdge = barWrap() - borderWidth;
		var stmt;
		if (imgToFrameEdge == 0) {
			stmt = "The image edge is at the frame edge";
		} else if (imgToFrameEdge > 0) {
			stmt = "Image ";
			if (document.getElementById("userEdgeTreat") 
					&& document.getElementById("userEdgeTreat").checked) {
				stmt = stmt + "wraps";
			} else if (document.getElementById("edgeTreat") 
					&& document.getElementById("edgeTreat").checked) {
				stmt = stmt + "mirrors";
			}
			stmt = stmt + " around stretching frame " + imgToFrameEdge + "\"";
		} else {
			stmt + "Image edge is " + Math.abs(imgToFrameEdge)
					+ "\" from frame edge providing a "
					+ Math.abs(imgToFrameEdge)
					+ "\" border around image when stretched";
		}
		document.getElementById("wrapStmt1").innerHTML = stmt;
		document.getElementById("wrapStmt2").innerHTML = stmt;
	} // barIndex != 0
	document.getElementById("barWidth").value = barWidth;
	document.getElementById("barHeight").value = barHeight;
	document.getElementById("barName").value = barName[document
			.getElementById("stretcherBar").selectedIndex];
	document.getElementById("barCost").value = stretcherBarCost.toFixed(2);
	if (!isPriceServices && !edgeTreatChange && !barChange && !barSizeChange
			&& !isInitial) {
		isPriceServices = true;
		priceServices();
	} else {
		calcSubTotal();
	}
	barSizeChange = false;
	barChange = false;
	imageChange = false;
	priceBorderCnt = 0;
	}
}

// function clearButtonGroup() {
// document.getElementById("edgeTreatWhite").checked = false;
// document.getElementById("edgeTreatWrap").checked = false;
// document.getElementById("edgeTreatUser").checked = false;
// document.getElementById("edgeTreatMirror").checked = false;
// }


// function priceEdge() {
// barIndex = new Number(
// document.getElementById("stretcherBar").selectedIndex);
// var stmt = "";
// var edgeWidth = 0;
// var edgeHeight = 0;
// var edgeArea = 0;
// edge = 0;
// edgeCost = 0.00;
// // document.getElementById("edgeTreatmentName").value =
// // edgeTreatmentName[edgeIndex];
//
// if ((document.getElementById("edgeTreat")
// && document.getElementById("edgeTreat").checked)) {
// if (!isPriceServices) {
// if (borderChange) {
// barChange = false;
// imageChange = false;
// barSizeChange = false;
// edgeTreatChange = false;
// } else if (barSizeChange) {
// barChange = false;
// imageChange = false;
// edgeTreatChange = false;
// } else if (imageChange) {
// barChange = false;
// edgeTreatChange = false;
// } else {
// if (!barChange) {
// edgeTreatChange = true;
// }
// // stmt = "Selecting an edge treatment makes the 'Border Width'
// // not adjustable. <br/> The "
// // + document.getElementById("edgeTreatmentName").value
// // + " setup fee is $"
// // + document.getElementById("edgeTreat").value;
// // document.getElementById("edgeStmt").innerHTML = stmt;
// var bar = 0;
// if (barIndex == 0) {
// setCanvasMedia();
// if (document.getElementById("userEdgeTreat")
// && document.getElementById("userEdgeTreat").checked) {
// var temp = printWidth - 3;
// if (isEven(temp)) {
// bar = 2;
// } else {
// bar = 1;
// }
// document.getElementById("stretcherBar").options[bar].selected = true;
// setBarLength();
// document.getElementById("borderWidth").value = borderWidth =
// printBarWrapBorder();
// } else {
// bar = 1;
// document.getElementById("stretcherBar").options[bar].selected = true;
// setBarLength();
// document.getElementById("borderWidth").value = borderWidth = barWrap();
// }
// paperWidth = printWidth - (2 * borderWidth);
// paperHeight = printHeight - (2 * borderWidth);
// if (document.getElementById("paperWidth")) {
// document.getElementById("paperWidth").value = paperWidth;
// }
// if (document.getElementById("paperHeight")) {
// document.getElementById("paperHeight").value = paperHeight;
// }
// priceBar();
// }
// // if ((document.getElementById("barHeight").options[0].selected
// // && document
// // .getElementById("barWidth").options[0].selected)
// // || document.getElementById("edgeTreatWhite").checked) {
// // } else {
// borderWidth = printBarWrapBorder();
// printWidth = paperWidth - (2 * borderWidth);
// printHeight = paperHeight - (2 * borderWidth);
// document.getElementById("borderWidth").value = borderWidth;
// document.getElementById("printWidth").value = printWidth;
// document.getElementById("printHeight").value = printHeight;
// // }
// if (edgeTreatChange && !isInitial) {
// priceBar();
// priceImage();
// }
// if (document.getElementById("noStretch")
// && document.getElementById("noStretch").checked) {
// stmt = "No Stretcher Bars and no stretching will be provided.";
// document.getElementById("edgeStmt").innerHTML = stmt;
// stretcherBarCost = 0.00;
// document.getElementById("barCost").value = stretcherBarCost
// .toFixed(2);
// }
// // edgeWidth = new Number(barWidth) + (edgeValue() * 2);
// // edgeHeight = new Number(barHeight) + (edgeValue() * 2);
// // edgeArea = (numberPrints * (((edgeWidth * edgeHeight) / 144)
// // - printArea));
// // edgeCost = ((edgeArea
// // * new Number(document.getElementById("media").value) / 2) +
// // new Number(
// // document.getElementById("edgeTreat").value));
// // edgeArea = roundNumber(edgeArea, 2);
// // edgeCost = roundNumber(edgeCost, 2);
// }
// }
// } else if (!barChange) {
// if (document.getElementById("noStretch")) {
// document.getElementById("noStretch").checked = false;
// }
// document.getElementById("edgeStmt").innerHTML = "";
// document.getElementById("stretcherBar").selectedIndex = 0;
// setBarLength();
// document.getElementById("barCost").value = 0.00;
// }
// // document.getElementById("edgeWidth").value = edgeValue();
// // document.getElementById("edgeArea").value = edgeArea.toFixed(2);
// // document.getElementById("edgeCost").value = edgeCost.toFixed(2);
// calcSubTotal();
// edgeTreatChange = false;
// // if (!isPriceServices) {
// // isPriceServices = true;
// // priceServices();
// // }
// }

function calcSubTotal() {
	var subtotal = printCost + borderCost + wastedPaperCost
			+ digitalArtworkCost + totalColorCorrectCost + totalColorMatchCost
			+ trimCost + varnishCost + mountingCost + laminateCost
			+ stretcherBarCost + edgeCost;
	document.getElementById("subtotal").value = subtotal.toFixed(2);
}

function priceServices() {
	priceDigitalArtwork();
	priceColorMatch();
	priceColorCorrection();
	priceTrim();
	priceVarnish();
	priceMount();
	priceLaminate();
	priceBar();
// priceEdge();
	calcSubTotal();
	isPriceServices = false;
}

function priceAll() {
	finalPrice = true;
	priceImage();
}

function displayErrorMessage() {
	alert(message);
	message = "";
}

function priceExcessPaper() { // v1.0
// find number of prints per printRoll width
	var printsOn44Width = parseInt(44 / paperWidth, 10);
	var printsOn44Height = parseInt(44 / paperHeight, 10);
	var printsOn36Width = parseInt(36 / paperWidth, 10);
	var printsOn36Height = parseInt(36 / paperHeight, 10);
	var printsOn24Width = parseInt(24 / paperWidth, 10);
	var printsOn24Height = parseInt(24 / paperHeight, 10);
	var printsOn17Width = parseInt(17 / paperWidth, 10);
	var printsOn17Height = parseInt(17 / paperHeight, 10);
	// document.getElementById("printsOn44Width").value = printsOn44Width;
	// document.getElementById("printsOn44Height").value = printsOn44Height;
	// document.getElementById("printsOn36Width").value = printsOn36Width;
	// document.getElementById("printsOn36Height").value = printsOn36Height;
	// document.getElementById("printsOn24Width").value = printsOn24Width;
	// document.getElementById("printsOn24Height").value = printsOn24Height;
	// <!-- find number of rows with max prints per printRoll width -->
	var numberCompleteRows44Width = printsOn44Width != 0 ? parseInt(
			numberPrints / printsOn44Width, 10) : 0;
	var numberCompleteRows44Height = printsOn44Height != 0 ? parseInt(
			numberPrints / printsOn44Height, 10) : 0;
	var numberCompleteRows36Width = printsOn36Width != 0 ? parseInt(
			numberPrints / printsOn36Width, 10) : 0;
	var numberCompleteRows36Height = printsOn36Height != 0 ? parseInt(
			numberPrints / printsOn36Height, 10) : 0;
	var numberCompleteRows24Width = printsOn24Width != 0 ? parseInt(
			numberPrints / printsOn24Width, 10) : 0;
	var numberCompleteRows24Height = printsOn24Height != 0 ? parseInt(
			numberPrints / printsOn24Height, 10) : 0;
	var numberCompleteRows17Width = printsOn17Width != 0 ? parseInt(
			numberPrints / printsOn17Width, 10) : 0;
	var numberCompleteRows17Height = printsOn17Height != 0 ? parseInt(
			numberPrints / printsOn17Height, 10) : 0;
	// document.getElementById("completeRows44Width").value =
	// numberCompleteRows44Width;
	// document.getElementById("completeRows44Height").value =
	// numberCompleteRows44Height;
	// document.getElementById("completeRows36Width").value =
	// numberCompleteRows36Width;
	// document.getElementById("completeRows36Height").value =
	// numberCompleteRows36Height;
	// document.getElementById("completeRows24Width").value =
	// numberCompleteRows24Width;
	// document.getElementById("completeRows24Height").value =
	// numberCompleteRows24Height;
	// <!-- find number of prints on row less than max prints per printRoll
	// width -->
	var printsOnPartialRow44Width = printsOn44Width != 0 ? parseInt(
			numberPrints % printsOn44Width, 10) : 0;
	var printsOnPartialRow44Height = printsOn44Height != 0 ? parseInt(
			numberPrints % printsOn44Height, 10) : 0;
	var printsOnPartialRow36Width = printsOn36Width != 0 ? parseInt(
			numberPrints % printsOn36Width, 10) : 0;
	var printsOnPartialRow36Height = printsOn36Height != 0 ? parseInt(
			numberPrints % printsOn36Height, 10) : 0;
	var printsOnPartialRow24Width = printsOn24Width != 0 ? parseInt(
			numberPrints % printsOn24Width, 10) : 0;
	var printsOnPartialRow24Height = printsOn24Height != 0 ? parseInt(
			numberPrints % printsOn24Height, 10) : 0;
	var printsOnPartialRow17Width = printsOn17Width != 0 ? parseInt(
			numberPrints % printsOn17Width, 10) : 0;
	var printsOnPartialRow17Height = printsOn17Height != 0 ? parseInt(
			numberPrints % printsOn17Height, 10) : 0;
	// document.getElementById("printsOnPartialRow44Width").value =
	// printsOnPartialRow44Width;
	// document.getElementById("printsOnPartialRow44Height").value =
	// printsOnPartialRow44Height;
	// document.getElementById("printsOnPartialRow36Width").value =
	// printsOnPartialRow36Width;
	// document.getElementById("printsOnPartialRow36Height").value =
	// printsOnPartialRow36Height;
	// document.getElementById("printsOnPartialRow24Width").value =
	// printsOnPartialRow24Width;
	// document.getElementById("printsOnPartialRow24Height").value =
	// printsOnPartialRow24Height;
	// <!-- calculate area of total wasted paper -->
	var waste44Width = calculatePaperWaste(printsOn44Width,
			numberCompleteRows44Width, printsOnPartialRow44Width, paperWidth,
			paperHeight, 44);
	var waste44Height = calculatePaperWaste(printsOn44Height,
			numberCompleteRows44Height, printsOnPartialRow44Height,
			paperHeight, paperWidth, 44);
	var waste36Width = calculatePaperWaste(printsOn36Width,
			numberCompleteRows36Width, printsOnPartialRow36Width, paperWidth,
			paperHeight, 36);
	var waste36Height = calculatePaperWaste(printsOn36Height,
			numberCompleteRows36Height, printsOnPartialRow36Height,
			paperHeight, paperWidth, 36);
	var waste24Width = calculatePaperWaste(printsOn24Width,
			numberCompleteRows24Width, printsOnPartialRow24Width, paperWidth,
			paperHeight, 24);
	var waste24Height = calculatePaperWaste(printsOn24Height,
			numberCompleteRows24Height, printsOnPartialRow24Height,
			paperHeight, paperWidth, 24);
	var waste17Width = calculatePaperWaste(printsOn17Width,
			numberCompleteRows17Width, printsOnPartialRow17Width, paperWidth,
			paperHeight, 17);
	var waste17Height = calculatePaperWaste(printsOn17Height,
			numberCompleteRows17Height, printsOnPartialRow17Height,
			paperHeight, paperWidth, 17);
	// document.getElementById("waste44Width").value = waste44Width;
	// document.getElementById("waste44Height").value = waste44Height;
	// document.getElementById("waste36Width").value = waste36Width;
	// document.getElementById("waste36Height").value = waste36Height;
	// document.getElementById("waste24Width").value = waste24Width;
	// document.getElementById("waste24Height").value = waste24Height;
	// <!-- calculate area of allowed wasted paper -->
	var freeWaste44Width = calculateFreeWaste(printsOn44Width,
			numberCompleteRows44Width, printsOnPartialRow44Width, paperWidth,
			paperHeight, 44);
	var freeWaste44Height = calculateFreeWaste(printsOn44Height,
			numberCompleteRows44Height, printsOnPartialRow44Height,
			paperHeight, paperWidth, 44);
	var freeWaste36Width = calculateFreeWaste(printsOn36Width,
			numberCompleteRows36Width, printsOnPartialRow36Width, paperWidth,
			paperHeight, 36);
	var freeWaste36Height = calculateFreeWaste(printsOn36Height,
			numberCompleteRows36Height, printsOnPartialRow36Height,
			paperHeight, paperWidth, 36);
	var freeWaste24Width = calculateFreeWaste(printsOn24Width,
			numberCompleteRows24Width, printsOnPartialRow24Width, paperWidth,
			paperHeight, 24);
	var freeWaste24Height = calculateFreeWaste(printsOn24Height,
			numberCompleteRows24Height, printsOnPartialRow24Height,
			paperHeight, paperWidth, 24);
	var freeWaste17Width = calculateFreeWaste(printsOn17Width,
			numberCompleteRows17Width, printsOnPartialRow17Width, paperWidth,
			paperHeight, 17);
	var freeWaste17Height = calculateFreeWaste(printsOn17Height,
			numberCompleteRows17Height, printsOnPartialRow17Height,
			paperHeight, paperWidth, 17);
	// document.getElementById("freeWaste44Width").value = freeWaste44Width;
	// document.getElementById("freeWaste44Height").value = freeWaste44Height;
	// document.getElementById("freeWaste36Width").value = freeWaste36Width;
	// document.getElementById("freeWaste36Height").value = freeWaste36Height;
	// document.getElementById("freeWaste24Width").value = freeWaste24Width;
	// document.getElementById("freeWaste24Height").value = freeWaste24Height;
	var freeWaste = 0;
	var waste = 0;
	var orientation17;
	var freeWaste17 = 0;
	var waste17 = 0;
	var completeRows17 = 0;
	var completeRowPrints17 = 0;
	var partialRowPrints17 = 0;
	var orientation24;
	var freeWaste24 = 0;
	var waste24 = 0;
	var completeRows24 = 0;
	var completeRowPrints24 = 0;
	var partialRowPrints24 = 0;
	var orientation36;
	var freeWaste36 = 0;
	var waste36 = 0;
	var completeRows36 = 0;
	var completeRowPrints36 = 0;
	var partialRowPrints36 = 0;
	var orientation44;
	var freeWaste44 = 0;
	var waste44 = 0;
	var completeRows44 = 0;
	var completeRowPrints44 = 0;
	var partialRowPrints44 = 0;
	if (waste17Width <= waste17Height && paperWidth <= 17) {
		orientation17 = "width";
		printRoll = 17;
		freeWaste17 = freeWaste17Width;
		waste17 = waste17Width;
		completeRows17 = numberCompleteRows17Width;
		completeRowPrints17 = printsOn17Width;
		partialRowPrints17 = printsOnPartialRow17Width;
	} else if (waste17Height <= waste17Width && paperHeight <= 17) {
		orientation17 = "height";
		printRoll = 17;
		freeWaste17 = freeWaste17Height;
		waste17 = waste17Height;
		completeRows17 = numberCompleteRows17Height;
		completeRowPrints17 = printsOn17Height;
		partialRowPrints17 = printsOnPartialRow17Height;
	} else {
		if (waste17Height != 0) {
			orientation17 = "height";
			printRoll = 17;
			freeWaste17 = freeWaste17Height;
			waste17 = waste17Height;
			completeRows17 = numberCompleteRows17Height;
			completeRowPrints17 = printsOn17Height;
			partialRowPrints17 = printsOnPartialRow17Height;
		}
		if (waste17Width != 0) {
			orientation17 = "width";
			printRoll = 17;
			freeWaste17 = freeWaste17Width;
			waste17 = waste17Width;
			completeRows17 = numberCompleteRows17Width;
			completeRowPrints17 = printsOn17Width;
			partialRowPrints17 = printsOnPartialRow17Width;
		}
	}
	if (waste24Width <= waste24Height && paperWidth <= 24) {
		orientation24 = "width";
		printRoll = 24;
		freeWaste24 = freeWaste24Width;
		waste24 = waste24Width;
		completeRows24 = numberCompleteRows24Width;
		completeRowPrints24 = printsOn24Width;
		partialRowPrints24 = printsOnPartialRow24Width;
	} else if (waste24Height <= waste24Width && paperHeight <= 24) {
		orientation24 = "height";
		printRoll = 24;
		freeWaste24 = freeWaste24Height;
		waste24 = waste24Height;
		completeRows24 = numberCompleteRows24Height;
		completeRowPrints24 = printsOn24Height;
		partialRowPrints24 = printsOnPartialRow24Height;
	} else {
		if (waste24Height != 0) {
			orientation24 = "height";
			printRoll = 24;
			freeWaste24 = freeWaste24Height;
			waste24 = waste24Height;
			completeRows24 = numberCompleteRows24Height;
			completeRowPrints24 = printsOn24Height;
			partialRowPrints24 = printsOnPartialRow24Height;
		}
		if (waste24Width != 0) {
			orientation24 = "width";
			printRoll = 24;
			freeWaste24 = freeWaste24Width;
			waste24 = waste24Width;
			completeRows24 = numberCompleteRows24Width;
			completeRowPrints24 = printsOn24Width;
			partialRowPrints24 = printsOnPartialRow24Width;
		}
	}
	if (waste36Width <= waste36Height && paperWidth <= 36) {
		orientation36 = "width";
		printRoll = 36;
		freeWaste36 = freeWaste36Width;
		waste36 = waste36Width;
		completeRows36 = numberCompleteRows36Width;
		completeRowPrints36 = printsOn36Width;
		partialRowPrints36 = printsOnPartialRow36Width;
	} else if (waste36Height <= waste36Width && paperHeight <= 36) {
		orientation36 = "height";
		printRoll = 36;
		freeWaste36 = freeWaste36Height;
		waste36 = waste36Height;
		completeRows36 = numberCompleteRows36Height;
		completeRowPrints36 = printsOn36Height;
		partialRowPrints36 = printsOnPartialRow36Height;
	} else {
		if (waste36Width != 0) {
			orientation36 = "width";
			printRoll = 36;
			freeWaste36 = freeWaste36Width;
			waste36 = waste36Width;
			completeRows36 = numberCompleteRows36Width;
			completeRowPrints36 = printsOn36Width;
			partialRowPrints36 = printsOnPartialRow36Width;
		}
		if (waste36Height != 0) {
			orientation36 = "height";
			printRoll = 36;
			freeWaste36 = freeWaste36Height;
			waste36 = waste36Height;
			completeRows36 = numberCompleteRows36Height;
			completeRowPrints36 = printsOn36Height;
			partialRowPrints36 = printsOnPartialRow36Height;
		}
	}
	if (waste44Width <= waste44Height && paperWidth <= 44 && paperWidth < 36) {
		orientation44 = "width";
		printRoll = 44;
		freeWaste44 = freeWaste44Width;
		waste44 = waste44Width;
		completeRows44 = numberCompleteRows44Width;
		completeRowPrints44 = printsOn44Width;
		partialRowPrints44 = printsOnPartialRow44Width;
	} else if (waste44Height <= waste44Width && paperHeight <= 44
			&& paperHeight < 36) {
		orientation44 = "height";
		printRoll = 44;
		freeWaste44 = freeWaste44Height;
		waste44 = waste44Height;
		completeRows44 = numberCompleteRows44Height;
		completeRowPrints44 = printsOn44Height;
		partialRowPrints44 = printsOnPartialRow44Height;
	} else {
		if (waste44Width != 0) {
			orientation44 = "width";
			printRoll = 44;
			freeWaste44 = freeWaste44Width;
			waste44 = waste44Width;
			completeRows44 = numberCompleteRows44Width;
			completeRowPrints44 = printsOn44Width;
			partialRowPrints44 = printsOnPartialRow44Width;
		}
		if (waste44Height != 0) {
			orientation44 = "height";
			printRoll = 44;
			freeWaste44 = freeWaste44Height;
			waste44 = waste44Height;
			completeRows44 = numberCompleteRows44Height;
			completeRowPrints44 = printsOn44Height;
			partialRowPrints44 = printsOnPartialRow44Height;
		}
	}
	if (paperWidth > 44 && paperHeight > 44) {
		message = "Invalid paper size for print plus border. Please reduce one paper side to 44 inches or less. ";
		document.getElementById("jobOrderAction").disabled = true;
		displayErrorMessage(message);
	}

	// document.getElementById("completeRows44").value = completeRows44;
	// document.getElementById("completeRows36").value = completeRows36;
	// document.getElementById("completeRows24").value = completeRows24;
	// document.getElementById("orientation44").value = orientation44;
	// document.getElementById("orientation36").value = orientation36;
	// document.getElementById("orientation24").value = orientation24;
	// document.getElementById("printsOn44").value = completeRowPrints44;
	// document.getElementById("printsOn36").value = completeRowPrints36;
	// document.getElementById("printsOn24").value = completeRowPrints24;
	// document.getElementById("printsOnPartialRow44").value =
	// partialRowPrints44;
	// document.getElementById("printsOnPartialRow36").value =
	// partialRowPrints36;
	// document.getElementById("printsOnPartialRow24").value =
	// partialRowPrints24;
	// document.getElementById("waste44").value = waste44;
	// document.getElementById("waste36").value = waste36;
	// document.getElementById("waste24").value = waste24;
	// document.getElementById("freeWaste44").value = freeWaste44;
	// document.getElementById("freeWaste36").value = freeWaste36;
	// document.getElementById("freeWaste24").value = freeWaste24;
	if ((waste44 - freeWaste44) < (completeRowPrints36 > 0 ? (waste36 - freeWaste36)
			: 99999999)
			&& (waste44 - freeWaste44) < (completeRowPrints24 > 0 ? (waste24 - freeWaste24)
					: 99999999)
			&& (waste44 - freeWaste44) < (completeRowPrints17 > 0 ? (waste17 - freeWaste17)
					: 99999999)) {
		printOrientation = orientation44;
		printRoll = 44;
		freeWaste = freeWaste44;
		waste = waste44;
		completeRows = completeRows44;
		completeRowPrints = completeRowPrints44;
		partialRowPrints = partialRowPrints44;
	} else if (((waste36 - freeWaste36) < (completeRowPrints24 > 0 ? (waste24 - freeWaste24)
			: 99999999))
			&& ((waste36 - freeWaste36) < (completeRowPrints17 > 0 ? (waste17 - freeWaste17)
					: 99999999))
			&& ((waste36 - freeWaste36) < (completeRowPrints44 > 0 ? (waste44 - freeWaste44)
					: 99999999)) && completeRowPrints36 > 0) {
		printOrientation = orientation36;
		printRoll = 36;
		freeWaste = freeWaste36;
		waste = waste36;
		completeRows = completeRows36;
		completeRowPrints = completeRowPrints36;
		partialRowPrints = partialRowPrints36;
	} else if (((waste24 - freeWaste24) < (completeRowPrints36 > 0 ? (waste36 - freeWaste36)
			: 9999999))
			&& ((waste24 - freeWaste24) < (completeRowPrints17 > 0 ? (waste17 - freeWaste17)
					: 9999999))
			&& ((waste24 - freeWaste24) < (completeRowPrints44 > 0 ? (waste44 - freeWaste44)
					: 9999999)) && completeRowPrints24 > 0) {
		printOrientation = orientation24;
		printRoll = 24;
		freeWaste = freeWaste24;
		waste = waste24;
		completeRows = completeRows24;
		completeRowPrints = completeRowPrints24;
		partialRowPrints = partialRowPrints24;
	} else if (((waste17 - freeWaste17) < (completeRowPrints36 > 0 ? (waste36 - freeWaste36)
			: 9999999))
			&& ((waste17 - freeWaste17) < (completeRowPrints24 > 0 ? (waste24 - freeWaste24)
					: 9999999))
			&& ((waste17 - freeWaste17) < (completeRowPrints44 > 0 ? (waste44 - freeWaste44)
					: 9999999)) && completeRowPrints17 > 0) {
		printOrientation = orientation17;
		printRoll = 17;
		freeWaste = freeWaste17;
		waste = waste17;
		completeRows = completeRows17;
		completeRowPrints = completeRowPrints17;
		partialRowPrints = partialRowPrints17;
	}
	if (mediaList[document.getElementById("media").selectedIndex][0] == "Enhanced matte poster board") {
		var zero = 0;
		if (document.getElementById("wastedPaperCost")) {
			document.getElementById("wastedPaperCost").value = zero.toFixed(2);
		}
	} else {
		wastedPaperCost = (((waste - freeWaste) < 0 ? 0 : (waste - freeWaste)) * new Number(
				mediaList[document.getElementById("media").selectedIndex][4]));
		if (document.getElementById("wastedPaperCost")) {
			document.getElementById("wastedPaperCost").value = wastedPaperCost
			.toFixed(2);
		}
	}
	if (document.getElementById("wastedPaper")) {
		document.getElementById("wastedPaper").value = waste;
	}
	if (document.getElementById("rollWidth")) {
		document.getElementById("rollWidth").value = printRoll;
	}
	if (document.getElementById("printOrientation")) {
		document.getElementById("printOrientation").value = printOrientation;
	}
	if (document.getElementById("completeRows")) {
		document.getElementById("completeRows").value = completeRows;
	}
	if (document.getElementById("completeRowPrints")) {
		document.getElementById("completeRowPrints").value = completeRowPrints;
	}
	document.getElementById("partialRowPrints").value = partialRowPrints;
	calcSubTotal();
}

function calculatePaperWaste(printsOnRow, completeRows, printsOnPartialRow,
		paperLength, paperRun, rollWidth) {
	var waste = (((rollWidth - (printsOnRow * paperLength)) * paperRun) / 144)
			* completeRows;
	waste += printsOnPartialRow == 0 ? 0
			: ((rollWidth - (printsOnPartialRow * paperLength)) * paperRun) / 144;
	return roundNumber(waste, 2);
}

function calculateFreeWaste(printsOnRow, completeRows, printsOnPartialRow,
		paperLength, paperRun, rollWidth) {
	var waste = (3 * paperRun / 144) * completeRows;
	waste += printsOnPartialRow == 0 ? 0 : 3 * paperRun / 144;
	return roundNumber(waste, 2);
}

function validateEmail() {
	var result = true;
	if (document.getElementById("emailAddress").value != document
			.getElementById('emailAddress2').value) {
		message = "The email address entries do not match";
		displayErrorMessage();
		document.getElementById("custInfo").focus();
		document.getElementById("custInfo").select();
		result = false;
	}
	return result;
}

function capStr(id) {
	var str = document.getElementById(id).value;
	document.getElementById(id).value = str.toUpperCase();
	
}

function capitalize(id) {
	var str = document.getElementById(id).value;
	var first;
	var cap;
	var capStr = "";
	var space = " ";
	var strArray = str.split(" ");
	var set = /(ne)|(nw)|(se)|(sw)/i;
	for (j = 0; j < strArray.length; j++) {
		if (strArray[j].length == 2 && set.test(strArray[j])) {
			strArray[j] = strArray[j].toUpperCase();
		} else {
    		first = strArray[j].substring(0,1);
    		cap = first.toUpperCase();
    		strArray[j] = strArray[j].replace(first, cap);
		}
		capStr += strArray[j];
		if (j < strArray.length-1) {
			capStr += space;
    	}
	}
	document.getElementById(id).value = capStr;
}

function isGACounty(county) {
	var result = false;
	var i = 0;
	while (!result && (++i < gaCounty.length)) {
		if (county == gaCounty[i]) {
			result = true;
		}
	}
	return result;
}

function validateCounty(id) {
	var result = true;
	if (document.getElementById(id) && !document.getElementById(id).value) {
		message = "The county entry cannot be empty.";
		displayErrorMessage();
		document.getElementById(id).select();
		document.getElementById(id).focus();
		result = false;
	} else if ((document.getElementById("shipAddressState").value == "GA")
			&& !isGACounty(document.getElementById("shipAddressCounty").value)) {
		message = "The county entry is not a Georgia county. Please check spelling and capitalization";
		displayErrorMessage();
		document.getElementById("shipAddressCounty").select();
		document.getElementById("shipAddressCounty").focus();
		result = false;
	}
	document.getElementById("manageProfileAction").disabled = !result;
	return result;
}

function validateLogin() {
	var result = true;
	if (document.getElementById("userId").value.length < 6) {
		message = "The userId entry must be at least 6 characters.";
		displayErrorMessage();
		document.getElementById("custInfo").focus();
		document.getElementById("custInfo").select();
		result = false;
	}
	document.getElementById("manageProfileAction").disabled = !result;
	return result;
}

function validatePassword() {
	var result = true;
	if (document.getElementById('password').value.length != 8) {
		message = "The password must be 8 characters";
		displayErrorMessage();
		document.getElementById("password").focus();
		document.getElementById("password").select();
		result = false;
	} else if (document.getElementById('password').value != document
			.getElementById('password2').value) {
		message = "The password entries do not match.";
		displayErrorMessage();
		document.getElementById("password2").focus();
		document.getElementById("password2").select();
		result = false;
	}
	document.getElementById("manageProfileAction").disabled = !result;
	return result;
}

function hasSelectedCustomer() {
	var result = true;
	if (document.getElementById("customerList").selectedIndex == 0) {
		message = "A Customer must be selected.";
		displayErrorMessage();
		document.getElementById("customerList").focus();
		result = false;
	}
	return result;
}

function validate(isAdmin) {
	var result = true;
	if (button != "Finished") {
		if (button != "Create Account" && isAdmin && !hasSelectedCustomer()) {
			result = false;
		} else {
			if (!isAdmin
					|| (isAdmin && ((document.getElementById("userId").value.length > 0) || (button == "CreateAccount")))) {
				if (!validateCounty()) {
					result = false;
				} else if (!validateEmail()) {
					result = false;
				} else if (!validatePassword()) {
					result = false;
				}
			}
		}
	}
	return result;
}

function buttonClicked(buttonValue) {
	button = buttonValue;
}

function listImages() {
	document.getElementById("image").options.length = 0;
	document.getElementById("image").options[0] = new Option(
			"Select an Image...", "None", true, false);
	for (i = 0; i < imgArray.length; i++) {
		document.getElementById("image").options[(i + 1)] = new Option(
				imgArray[i], imgArray[i], false, false);
	}
}

function listOrders() {
	if (isReorder) {
		document.getElementById("printJob").options.length = 0;
		document.getElementById("printJob").options[0] = new Option(
				"Select an Order...", "None", true, false);
		var imgIdx = (document.getElementById("image").selectedIndex - 1);
		var ordSel = document.getElementById("image").selectedIndex;
		if (imgIdx >= 0) {
			var ordArray = imgOrdArray[imgIdx];
			for (o = 0; o < ordArray.length; o++) {
				document.getElementById("printJob").options[(o + 1)] = new Option(
						ordArray[o][1], ordArray[o][0], false, false);
			}
		}
	}
}

function setEnctype(id) {
	if (id == "image") {
		document.forms[0].encoding = "application/x-www-form-urlencoded";
		document.getElementById("imageFile").value = "";
	} else if (id == "imageFile") {
		document.forms[0].encoding = "multipart/form-data";
		document.getElementById("image").selectedIndex = 0;
	}
}

function hasSelection() {
	var result = true;
	if (!isHandDelivery) {
		if (isReorder) {
			if ((document.getElementById("image").selectedIndex == 0)
					&& (document.getElementById("printJob ").selectedIndex == 0)) {
				result = false;
				message = "Please select an image and a print job , then click on the Reorder button to place an print job .";
				displayErrorMessage();
			} else if (document.getElementById("printJob").selectedIndex == 0) {
				result = false;
				message = "Please select a print job , then click on the Reorder button to place a print job .";
				displayErrorMessage();
			}
		} else if (document.getElementById("imageFile").value.length == 0
				&& document.getElementById("image").selectedIndex == 0) {
			result = false;
			message = "Please select an image, then click on the New Order button to place a print job .";
			displayErrorMessage();
		} else if (document.getElementById("imageFile").value.length > 0
				&& document.getElementById("image").selectedIndex > 0) {
			result = false;
			message = "Please select only one image, then click on the New Order button to place a print job .";
			displayErrorMessage();
		}
	}
	return result;
}

var estimateTotal = 0.00;
var photoArt = 0.00;
var scanArt = 0.00;
var colorMatch = 0.00;
var colorCorrect = 0.00;
var sendProof = 0.00;

function estimateArtwork() {
	selPhotoArt();
	selScanArt();
	selColorMatch();
	selColorCorrect();
	selSendProof();
	selPrintOnly();
	estimateTotal = photoArt + scanArt + colorMatch + colorCorrect + sendProof;
	document.getElementById("estimateTotal").value = roundNumber(estimateTotal,
			2);
}

function selPhotoArt() {
	if (document.getElementById("photoArt").checked) {
		document.getElementById("scanArt").checked = false;
		document.getElementById("colorMatch").checked = true;
		document.getElementById("printOnly").checked = false;
		photoArt = 30 * document.getElementById("numPieces").value;
	} else {
		photoArt = 0;
	}
	document.getElementById("photoCost").value = roundNumber(photoArt, 2);
}

function selScanArt() {
	if (document.getElementById("scanArt").checked) {
		document.getElementById("photoArt").checked = false;
		document.getElementById("colorMatch").checked = true;
		document.getElementById("printOnly").checked = false;
		document.getElementById("inchWidth").value = "8";
		document.getElementById("inchHeight").value = "10";
		document.getElementById("artworkScan").selectedIndex = "7";
		scanArt = 55 * document.getElementById("numPieces").value;
	} else {
		scanArt = 0.00;
	}
	document.getElementById("scanCost").value = roundNumber(scanArt, 2);
}

function selColorMatch() {
	if (document.getElementById("colorMatch").checked) {
		document.getElementById("sendProof").checked = true;
		document.getElementById("printOnly").checked = false;
		document.getElementById("colorCorrect").checked = false;
		colorMatch = 25 * document.getElementById("numPieces").value;
	} else {
		document.getElementById("scanArt").checked = false;
		document.getElementById("photoArt").checked = false;
		colorMatch = 0;
	}
	document.getElementById("matchCost").value = roundNumber(colorMatch, 2);
}

function selColorCorrect() {
	colorCorrect = 0;
	if (document.getElementById("colorCorrect").checked) {
		document.getElementById("scanArt").checked = false;
		document.getElementById("photoArt").checked = false;
		document.getElementById("colorMatch").checked = false;
		document.getElementById("printOnly").checked = false;
		document.getElementById("sendProof").checked = true;
		colorCorrect = 5 * document.getElementById("numPieces").value;
	}
	document.getElementById("correctCost").value = roundNumber(colorCorrect, 2);
}

function selSendProof() {
	if (!document.getElementById("sendProof").checked) {
		document.getElementById("scanArt").checked = false;
		document.getElementById("photoArt").checked = false;
		sendProof = 0;
	} else {
		sendProof = 7 * document.getElementById("numPieces").value;
	}
	document.getElementById("proofCost").value = roundNumber(sendProof, 2);
}

function selPrintOnly() {
	if (document.getElementById("printOnly").checked) {
		document.getElementById("scanArt").checked = false;
		document.getElementById("photoArt").checked = false;
		document.getElementById("colorMatch").checked = false;
		document.getElementById("colorCorrect").checked = false;
		document.getElementById("sendProof").checked = false;
		estimateTotal = 0.00;
		photoArt = 0.00;
		scanArt = 0.00;
		colorMatch = 0.00;
		colorCorrect = 0.00;
		sendProof = 0.00;
	}
}

function calcPhotoCost() {
}

function calcScanCost() {
	scanWidth = document.getElementById("inchWidth").value;
	scanHeight = document.getElementById("inchHeight").value;
	scanPpi = document.getElementById("artworkScan").value;
	pixels = (scanWidth * scanPpi) * (scanHeight * scanPpi) * 3;

}

function calcMatchCost() {
}

function calcCorrectCost() {
}

function calcProofCost() {
}

function addInsurance() {

}

// function initCosts(shippingCost, taxRate, handleCost, discountRate,
// deliveryMethod) {
// this.shipCost = shippingCost;
// this.taxRate = taxRate;
// this.handleCost = handleCost;
// this.discountRate = discountRate;
// this.deliveryMethod = deliveryMethod;
// if (document.getElementById("discount")) {
// document.getElementById("discount").Value = document
// .getElementById("subtotal").value
// * discountRate / 100;
// document.getElementById("tax").Value = (new Number(document
// .getElementById("subtotal").value) - new Number(document
// .getElementById("discount").Value))
// * taxRate / 100;
// document.getElementById("hdlgCost").Value = handleCost;
// document.getElementById("totalCost").value = (new Number(document
// .getElementById("subtotal").value)
// - new Number(document.getElementById("discount").Value)
// + new Number(document.getElementById("tax").Value) + new Number(
// document.getElementById("hdlgCost").value)).toFixed(2);
// } else {
// document.getElementById("tax").Value = new Number(document
// .getElementById("subtotal").value)
// * taxRate / 100;
// document.getElementById("hdlgCost").Value = handleCost;
// document.getElementById("totalCost").value = (new Number(document
// .getElementById("subtotal").value)
// + new Number(document.getElementById("tax").Value) + new Number(
// document.getElementById("hdlgCost").value)).toFixed(2);
// }
// }

function calcShipCost(deliveryMethod) {
	cartChanged();
	if (deliveryMethod == "Pick up") {
		document.getElementById("shipCost").value = 0.0;
		document.getElementById("hdlgCost").value = 0.0;
	} else if (deliveryMethod == "USPS First Class") {
		document.getElementById("shipCost").value = shipCost;
		document.getElementById("hdlgCost").value = handleCost;
	} else if (deliveryMethod == "None") {
		document.getElementById("shipCost").value = "----";
	}
	calculateTotal();
}

function calculateTotal() {
	var amt;
// document.getElementById("deliveryMethod").value = deliveryMethod;
	if (document.getElementById("discount")) {
		amt = (new Number(document.getElementById("subtotal").value) - new Number(
				document.getElementById("discount").value));
	} else {
		amt = new Number(document.getElementById("subtotal").value);
	}
	document.getElementById("tax").value = roundNumber((amt * taxRate / 100), 2);
// document.writeln("starlab.js; calculateTotal(); delivery selection = " +
// document.getElementById("deliveryMethod").value);
	
	total = (amt + new Number(document.getElementById("tax").value)
			+ new Number(document.getElementById("hdlgCost").value) + (document
			.getElementById("shipCost").value == "----" ? 0 : new Number(
			document.getElementById("shipCost").value)));
	document.getElementById("totalCost").value = roundNumber(total, 2);
}

function roundNumber(num, dec) {
	var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
	return result;
}
var dateList;
var dateJobList;
var idx;
var selectedButton;

function loadJobList(id) {
	if (document.getElementById("radioButton")) {
        if (id == "") {
    		id = selectedButton = document.getElementById("radioButton").value;
        } else {
    		document.getElementById("radioButton").value = selectedButton = id;
        }
    	document.getElementById("printJobList").options.length = 0;
    	var prevDate = null;
    	var currDate = null;
        if (id == "date") {
    		dateList = new Array();
    		idx = 0;
        } else {
    		document.getElementById("dateSpan").style.visibility = "hidden";
        }
    	var jobNumber = document.getElementById("printJobNumber") ? document
    			.getElementById("printJobNumber").value : "";
    	var jobName = document.getElementById("printJobName") ? document
    			.getElementById("printJobName").value : "";
    	var jobDate = document.getElementById("printJobDate") ? document
    			.getElementById("printJobDate").value : "";

		var select=document.getElementById("printJobList");
		var labels=document.getElementsByTagName("label"),i;
		for( i=0; i<labels.length;i++ ){
			if(labels[i].htmlFor==select.id){
				labels[i].innerHTML = "Select " + id + ": ";
			}
		}
    	for ( var i = 0; i < printJobList.length; i++) {
    		if (id == "name") {
    			select.options.add(new Option(
    					printJobList[i][2], printJobList[i][0], false,
    					printJobList[i][2] == jobName ? true : false));
    		} else if (id == "number") {
    			select.options.add(new Option(
    					printJobList[i][1], printJobList[i][0], false,
    					printJobList[i][1] == jobNumber ? true : false));
    		} else if (id == "date") {
    			currDate = printJobList[i][3];
    			if (currDate != prevDate) {
    				select.options.add(new Option(
    						currDate, currDate, false,
    						printJobList[i][3] == jobDate ? true : false));
    				if (prevDate != null) {
    					dateList.push(dateJobList);
    				}
    				dateJobList = new Array();
    				dateJobList.push(currDate);
    				prevDate = currDate;
    			}
			dateJobList.push(new job(printJobList[i][0], printJobList[i][2],
					printJobList[i][2] == jobName ? true : false));
    		}
    	}
    	if (id == "date") {
    		dateList.push(dateJobList);
    		loadDateJobs();
    	}
	}
}

function loadDateJobs() {
	if (selectedButton == "date") {
		var jobDate = document.getElementById("printJobDate") ? document
				.getElementById("printJobDate").value : "";
		document.getElementById("dateJobList").options.length = 0;
		document.getElementById("dateSpan").style.visibility = "visible";
		dateJobList = dateList[document.getElementById("printJobList").selectedIndex];
		for ( var i = 1; i <= dateJobList.length; i++) {
			document.getElementById("dateJobList").options.add(new Option(
					dateJobList[i].name, dateJobList[i].id, false,
					dateJobList[i].selected));
		}
	} else {
		document.getElementById("dateSpan").style.visibility = "hidden";
// loadJobList(selectedButton);
	}
}

function job(id, name, selected) {
	this.id = id;
	this.name = name;
	this.selected = selected;
}

function checkMediaDetails() {
	var selIdx = document.getElementById("mediaList").selectedIndex;
	var delBtn;
	var elColl = document.mediaInfo.elements["mediaProfile"];
	if (selIdx == 0) {
		document.getElementById("err").innerHTML = "";
		document.getElementById("message").innerHTML = "";
		document.getElementById("mnemonic").value = "";
		document.getElementById("name").value = "";
		document.getElementById("descript").value = "";
		document.getElementById("weight").value = "";
		document.getElementById("cost").value = "";
		document.getElementById("printCost").value = "";
		document.getElementById("borderCost").value = "";
		for (i = 0; i < elColl.length; i++) {
			if (elColl[i].value == "Modify") {
				elColl[i].value = "Add";
			} else if (elColl[i].value == "Delete") {
				elColl[i].style.visibility = 'hidden';
			}

		}
	} else {
		for (i = 0; i < elColl[i].length; i++) {
			if (elColl[i].value == "Delete") {
				elColl[i].style.visibility = 'visible';
			}
		}
	}
}

function checkBarDetails() {
	var selIdx = document.getElementById("barList").selectedIndex;
	var delBtn;
	var elColl = document.barInfo.elements["barProfile"];
	if (selIdx == 0) {
		document.getElementById("err").innerHTML = "";
		document.getElementById("message").innerHTML = "";
		document.getElementById("mnemonic").value = "";
		document.getElementById("barType").value = "";
		document.getElementById("descript").value = "";
		document.getElementById("barWidth").value = "";
		document.getElementById("barDepth").value = "";
		document.getElementById("weight").value = "";
		document.getElementById("cost").value = "";
		document.getElementById("wrap").value = "";
		document.getElementById("barLengths").length = 0;
		for (i = 0; i < elColl.length; i++) {
			if (elColl[i].value == "Modify") {
				elColl[i].value = "Add";
			} else if (elColl[i].value == "Delete") {
				elColl[i].style.visibility = 'hidden';
			}

		}
	} else {
		for (i = 0; i < elColl[i].length; i++) {
			if (elColl[i].value == "Delete") {
				elColl[i].style.visibility = 'visible';
			}
		}
	}
}

function checkBoardDetails() {
	var selIdx = document.getElementById("boardList").selectedIndex;
	var delBtn;
	var elColl = document.mountInfo.elements["mountProfile"];
	if (selIdx == 0) {
		document.getElementById("err").innerHTML = "";
		document.getElementById("message").innerHTML = "";
		document.getElementById("mnemonic").value = "";
		document.getElementById("name").value = "";
		document.getElementById("descript").value = "";
		document.getElementById("weight").value = "";
		document.getElementById("cost").value = "";
		document.getElementById("thickness").selectedIndex = 0;
		for (i = 0; i < elColl.length; i++) {
			if (elColl[i].value == "Modify") {
				elColl[i].value = "Add";
			} else if (elColl[i].value == "Delete") {
				elColl[i].style.visibility = 'hidden';
			}

		}
	} else {
		for (i = 0; i < elColl[i].length; i++) {
			if (elColl[i].value == "Delete") {
				elColl[i].style.visibility = 'visible';
			}
		}
	}
}

function setSelection(id) {
    document.getElementById(id).options[document.getElementById(id).selectedIndex].selected = true;
  }  

function showButtons(id) {
	var idx = document.getElementById(id).selectedIndex;
	document.getElementById(id).options[idx].selected = true;
	if (id == "customerList") {
		if (idx > 0) {
			document.getElementById("manageProfileDetails").disabled = false;
			document.getElementById("manageProfileJobs").disabled = false;
			document.getElementById("manageProfileImageUpload").disabled = false;
			document.getElementById("manageProfileImages").disabled = false;
			document.getElementById("deleteCart").disabled = false;
// document.getElementById().disabled = false;
		} else  {
			document.getElementById("manageProfileDetails").disabled = true;
			document.getElementById("manageProfileJobs").disabled = true;
			document.getElementById("manageProfileImageUpload").disabled = true;
			document.getElementById("manageProfileImages").disabled = true;
			document.getElementById("deleteCart").disabled = true;
// document.getElementById().disabled = true;
			clearDetails();
		}
	}
}

function clearDetails() {
	document.getElementById("firstName").value = "";
	document.getElementById("midName").value = "";
	document.getElementById("lastName").value = "";
	document.getElementById("billAddressLine1").value = "";
	document.getElementById("billAddressLine2").value = "";
	document.getElementById("billAddressCity").value = "";
	document.getElementById("billAddressCounty").value = "";
	document.getElementById("billAddressState").value = "";
	document.getElementById("billAddressZipCode").value = "";
	document.getElementById("taxExempt").selectedIndex = 0;
	document.getElementById("shipAddressLine1").value = "";
	document.getElementById("shipAddressLine2").value = "";
	document.getElementById("shipAddressCity").value = "";
	document.getElementById("shipAddressCounty").value = "";
	document.getElementById("shipAddressState").value = "";
	document.getElementById("shipAddressZipCode").value = "";
	document.getElementById("primaryPhoneNumber").value = "";
	document.getElementById("secondaryPhoneNumber").value = "";
	document.getElementById("emailAddress").value = "";
	document.getElementById("emailAddress2").value = "";
	document.getElementById("userId").value = "";
	document.getElementById("password").value = "";
	document.getElementById("password2").value = "";
	document.getElementById("manageProfileAction").value = "Create Account";
	if (document.getElementById("manageProfileFinished")) {
		document.getElementById("manageProfileFinished").style.display = "none";
	}
	if (document.getElementById("manageProfileCancel")) {
		document.getElementById("manageProfileCancel").style.display = "none";
	}
}

var isCartSaved = false;

function cartChanged() {
	isCartSaved = false;
}

function continueShopping(v, m, f) {
	$.prompt('Do you want to continue ordering? ', {
		buttons : {
			Continue : false,
			Quit : true
		},
		callback : setAction
	});
}
var btnWhichButton;
function confirmAction() {
	var action = btnWhichButton;
	result = true;
	if (action == "Save Cart") {
		isCartSaved = true;
	} else if (action == "Add Another Order") {
		isCartSaved = false;
	} else if (action == "Empty Cart") {
		result = $.prompt(
				'Are you sure you want to empty your shopping cart? ', {
					buttons : {
						Yes : true,
						No : false
					},
					focus : 1,
					callback : continueShopping
				});
	} else if (action == "Quit") {
		result = $.prompt(
				'You will be logged out. What about your shopping cart? ', {
					buttons : {
						'Save Cart' : 1,
						'Empty Cart' : 2,
						Cancel : 3
					},
					focus : 3,
					callback : setAction

				});
	} 
	return result;
}

function setAction(v, m, f) {
	if (v == 3 || v == false) {
		return false;
	} else {
		document.getElementById("cartAction").value = m;
		return true;
	}
	// document.forms["cartForm"].submit();
}

function f_optionMove(s_from, s_to) {
	var e_from = document.forms['barInfo'].elements[s_from],
		e_to   = document.forms['barInfo'].elements[s_to];

	if (!e_from)
		return alert ("Error: selectbox with name '" + s_from + "' can't be found.");
	if (!e_to)
		return alert ("Error: selectbox with name '" + s_to + "' can't be found.");

	var n_moved = 0;

	for (var i = 0; i < e_from.options.length; i++) {
		if (e_from.options[i].selected) {
			e_to.options[e_to.options.length] = new Option(e_from.options[i].text, e_from.options[i].value);
			n_moved++;
		} else if (n_moved) {
			e_from.options[i - n_moved] = new Option(e_from.options[i].text, e_from.options[i].value);
		}
	}

	if (n_moved) {
		e_from.options.length = e_from.options.length - n_moved;
	} else
		alert("You haven't selected any options");

}


function f_optionMoveAll(s_from, s_to) {
	var e_from = document.forms['barInfo'].elements[s_from],
		e_to   = document.forms['barInfo'].elements[s_to];

	if (!e_from)
		return alert ("Error: selectbox with name '" + s_from + "' can't be found.");
	if (!e_to)
		return alert ("Error: selectbox with name '" + s_from + "' can't be found.");

	if (e_to.options.length > 0) 
		e_to.options.length = 	e_from.options.length + e_to.options.length;
	else
	e_to.options.length = 0;

	for (var i = 0; i < e_from.options.length; i++)
			e_to.options = new Option(e_from.options[i].text, e_from.options[i].value);

	e_from.options.length = 0;
}

function fixLength() {
	f_selectAll("barLengths");
	var e_to   = document.forms['barInfo'].elements["barLengths"];
	if (e_to.options[0].value == "0") {
		e_select.options[0].selected = false;
	}
}

function f_selectAll (s_select) {

	var e_select = document.forms['barInfo'].elements[s_select];

	for (var i = 0; i < e_select.options.length; i++)
			e_select.options[i].selected = true;

}

var isEdgeWidthSet = false;
function checkEdgeTreat(id) {
	var isEdgeWidthChange = false;
	if (id == "edgeTreat") {
		edgeTreatChange = true;
		isEdgeTreat = document.getElementById("edgeTreat").checked;
		document.getElementById("userEdgeTreat").checked = false;
		if (document.getElementById("edgeWidth").selectedIndex == 0
				&& document.getElementById("stretcherBar").selectedIndex == 0) {
			message = "Please select the 'Edge Width'";
			document.getElementById("jobOrderAction").disabled = true;
			displayErrorMessage();
    	} else {
			document.getElementById("jobOrderAction").disabled = false;
	    	if (!document.getElementById("edgeTreat").checked
	    			&& !document.getElementById("userEdgeTreat").checked) {
	    		document.getElementById("edgeWidth").selectedIndex = 0;
	    		isEdgeWidthSet = false;
	    		isEdgeWidthChange = true;
	    	}
		}
    } else if (id == "userEdgeTreat") {
		edgeTreatChange = true;
		isEdgeTreat = document.getElementById("userEdgeTreat").checked;
		document.getElementById("edgeTreat").checked = false;
		if (document.getElementById("edgeWidth").selectedIndex == 0) {
			message = "Please select the 'Edge Width'";
			document.getElementById("jobOrderAction").disabled = true;
			displayErrorMessage();
    	} else {
			document.getElementById("jobOrderAction").disabled = false;
	    	if (!document.getElementById("edgeTreat").checked
	    			&& !document.getElementById("userEdgeTreat").checked) {
	    		document.getElementById("edgeWidth").selectedIndex = 0;
	    		isEdgeWidthSet = false;
	    		isEdgeWidthChange = true;
	    	}
		}
    } else if (id == "edgeWidth") {
    	isEdgeWidthChange = edgeTreatChange = true;
		if (document.getElementById("edgeWidth").selectedIndex > 0) {
			document.getElementById("jobOrderAction").disabled = false;
			isEdgeWidthSet = true;
	    	if (!document.getElementById("edgeTreat").checked
	    			&& !document.getElementById("userEdgeTreat").checked) {
				message = "Please check 'Apply mirrored edge to this print' or 'User Applied treatment on this print'";
				document.getElementById("jobOrderAction").disabled = true;
				displayErrorMessage();
	    	} else if (document.getElementById("stretcherBar").selectedIndex > 0) {
	    				document.getElementById("borderWidth").value = printBarWrapBorder();
	    		} 
		} else {
			document.getElementById("userEdgeTreat").checked = false;
			document.getElementById("edgeTreat").checked = false;
			edgeTreatChange = false;
			isEdgeWidthSet = false;
		}
    }
	var edgeWidth = new Number(document.getElementById("edgeWidth").value);
   	if (document.getElementById("edgeTreat").checked) {
// prevPrintWidth = printWidth;
   		printWidth = printWidth + 2*edgeWidth;
		document.getElementById("printWidth").value = printWidth;
// prevPrintHeight = printHeight;
		printHeight = printHeight + 2*edgeWidth;
		document.getElementById("printHeight").value = printHeight;
	}
	document.getElementById("borderWidth").value = borderWidth =
		(isEdgeWidthSet ? (edgeWidth == 0.75 ? (2 - edgeWidth) : 
			(edgeWidth == 1.5 ? (3 - edgeWidth) : 
				(document.getElementById("stretcherBar").selectedIndex > 0 ? 
						barWrap() : 0))) : 0);
	if (edgeWidth == 0 && !document.getElementById("edgeTreat").checked && 
			!document.getElementById("userEdgeTreat").checked &&
			document.getElementById("stretcherBar").selectedIndex == 0
			&& !imageChange) {
		document.getElementById("printWidth").value = printWidth = prevPrintWidth;
		document.getElementById("printHeight").value = printHeight = prevPrintHeight;
	}
	if (document.getElementById("stretcherBar").selectedIndex > 0) {
		if (edgeTreatChange || isEdgeWidthSet) {
			priceBar();
		}
	}
	if (!isPriceImageCall && isEdgeWidthChange) {
		priceImage();
	}
}

function toggleDisplay(table, id) {
    if (table) {
        var trs = table.getElementsByClassName('togglerow');
        var src;
// for(var i = 0; i < trs.length; i++) {
            if  (document.getElementById(id).innerHTML == "more...") {
// trs[i].style.setVisibility = 'visible';
            	document.getElementById("paperSizeRow").style.visibility = 'visible';
            	document.getElementById("paperAreaRow").style.visibility = 'visible';
                document.getElementById(id).innerHTML  = 'less...';
            } else if  (document.getElementById(id).innerHTML == "less...") {
// trs[i].style.setVisibility = 'collapse';
            	document.getElementById("paperSizeRow").style.visibility = 'collapse';
            	document.getElementById("paperAreaRow").style.visibility = 'collapse';
                document.getElementById(id).innerHTML = 'more...';
            } 
// }
    }
}


