if(window.document.forms[1] != null)
{
	mainForm = window.document.forms[1];
}
else
{
	mainForm = window.document.forms[0];
}
var indexOfFirstRow = 70;
var lastConstructionTypeID = 0;
var allBottomMaterials = null;
var allSideMaterials = null;
var invalid14BottomMaterials = null;
var invalid38BottomMaterials = null;
var invalid12BottomMaterials = null;
var invalid12SideMaterials = null;
var invalid58SideMaterials = null;
var invalidPre14BottomMaterials = null;
var invalidPre38BottomMaterials = null;
var invalidPre12BottomMaterials = null;
var invalidPre12SideMaterials = null;
var invalidPre58SideMaterials = null;
var underNotchNames = null;
var underNotchValidSizesIn = null;
var underNotchValidSizesMm = null;
var promptDefaultSave = false;
var progressMessage = "";
var startTime = new Date().getTime();
var lastTime = new Date().getTime();
var hasDefaults = false;
var promptDefaultChanged = false;
var defaultConstructionTypeID = 0;
var defaultAssemblyTypeID = 0;
var defaultFinishID = 0;
var defaultSideMaterialWidth = 0;
var defaultSideMaterialID = 0;
var defaultEdgeDetailID = 0;
var defaultEdgeBandID = 0;
var defaultBottomWidth = 0;
var defaultBottomMaterialID = 0;
var defaultMeasurementUnit = 0;
var defaultUnderNotchID = 0;
var defaultWantsSlides = 0;
var defaultInstallLockingDevices = 0;
var defaultSlideTypeID = 0;
var defaultRushOrder = 0;

var hide  = true;
var lastID = 0;
function showHelp(parent, id)
{
	showLayer(parent, id);
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function showLayer(obj, id)
{
	var content = document.getElementById('contentLayer' + id);
	if(id != lastID)
	{
		var lastContent = document.getElementById('contentLayer' + lastID);
		if(lastContent != null)
		{
			lastContent.style.visibility = 'hidden';
		}
	} 
	lastID = id;
	if(content != null)
	{
		content.style.visibility = 'visible';
		setLyr(obj, content);
	}
}


function hideLayer(id)
{
	var content = document.getElementById('contentLayer' + id);
	if(content != null)
	{
		content.style.visibility = 'hidden';
	}
	else
	{
		alert("Content == " + 'contentLayer' + id);
	}
}

function setLyr(obj, content)
{
	var coors = findPos(obj);
	content.style.top = coors[1] + 'px';
	content.style.left = (parseInt(coors[0]) + 90) + 'px';
}



function isFieldDefault(field, value)
{
	for(var i = 0; i < field.length; i++)
	{
		if(field[i].checked)
		{
			return(field[i].value == value);
		}
	}
}

function defaultsChanged(theForm)
{
	if(hasDefaults)
	{
		if(!isFieldDefault(theForm.construction_type_id, defaultConstructionTypeID))
		{
			return(true);
		}
		if(!isFieldDefault(theForm.assembly_type_id, defaultAssemblyTypeID))
		{
			return(true);
		}
		if(!isFieldDefault(theForm.finish_id, defaultFinishID))
		{
			return(true);
		}
		if(!isFieldDefault(theForm.side_width, defaultSideWidth))
		{
			return(true);
		}
		if(!isFieldDefault(theForm.side_material_id, defaultSideMaterialID))
		{
			return(true);
		}
		if(!isFieldDefault(theForm.edgedetail_id, defaultEdgeDetailID))
		{
			return(true);
		}
		if(!isFieldDefault(theForm.edgeband_id, defaultEdgeBandID))
		{
			return(true);
		}
		if(!isFieldDefault(theForm.bottom_width, defaultBottomWidth))
		{
			return(true);
		}
		if(!isFieldDefault(theForm.bottom_material_id, defaultBottomMaterialID))
		{
			return(true);
		}
		if(!isFieldDefault(theForm.measurement_unit_id, defaultMeasurementUnit))
		{
			return(true);
		}
		if(!isFieldDefault(theForm.under_notch_id, defaultUnderNotchID))
		{
			return(true);
		}
		if(!isFieldDefault(theForm.install_locking_devices, defaultInstallLockingDevices))
		{
			return(true);
		}
		if(!isFieldDefault(theForm.rush_order, defaultRushOrder))
		{
			return(true);
		}
	}
	else
	{
		return(false);
	}
}

function updateProgressMessage(newMessage)
{
	var now = new Date().getTime();
	progressMessage += (now - lastTime) + ' ' + newMessage + '\r\n';
	lastTime = now;
}

function showProgressMessage()
{
	if(theForm)
	{
		if(theForm.view_alerts)
		{
			if(theForm.view_alerts.checked)
			{
				alert(progressMessage);
			}
		}
	}
	progressMessage = "";
}

function confirmNoLockingDeviceInstalled(field)
{
	if(field.form.install_locking_devices[1].checked && !field.checked)
	{
		return(confirm("Although you have selected to have Locking Devices to be installed on all line items, this line item will NOT have locking devices installed!"));
	}
	return(true);
}

function defaultPromptChanged(theForm, message)
{
	var setPromptDefaultChanged = true;
	if(promptDefaultChanged)
	{
		if(defaultsChanged(theForm))
		{
			if(confirm(message))
			{
				theForm.save_defaults.value = true;
				promptDefaultChanged = false;
			}
			setPromptDefaultChanged = false;
		}
		else
		{
			//alert('No defaults changed.');
		}
	}
	else
	{
		setPromptDefaultChanged = false;
	}
	theForm.prompt_default_changed.value = setPromptDefaultChanged;
}

function defaultPromptSave(theForm, message)
{
	if(promptDefaultSave)
	{
		if(confirm(message))
		{
			theForm.prompt_default_save.value = 'true';
			theForm.save_defaults.value = true;
		}
		else
		{
			theForm.prompt_default_save.value = 'false';
		}
		promptDefaultSave = false;
	}
}

function confirmNoUndermountNotch(field)
{
	for(var i = 0; i < field.form.length; i++)
	{
		if(field.form[i] == field)
		{
			i += 4;
			break;
		}
	}
	var lockingDeviceField = field.form[i];
	if(!field.form.under_notch_id[0].checked && !field.checked)
	{
		if(confirm("Although you have selected to have Undermount Notches to be cut on all line items, this line item will NOT have undermount notches cut!"))
		{
			lockingDeviceField.checked = false;
			lockingDeviceField.disabled = true;
			return(true);
		}
		else
		{
			return(false);
		}
	}
	else
	{
		lockingDeviceField.disabled = false;
		if(field.form.install_locking_devices[1].checked)
		{
			lockingDeviceField.checked = true;
		}
	}
	return(true);
}


function getFirstItemIndex(theForm)
{
	for(var i = 0; i < theForm.length; i++)
	{
		if(theForm[i].name.substring(0, 8) == "changed_")
		{
			return(i)
		}
	}
}

function enforceDimensions(theForm, offSet, j)
{
	if(theForm[offSet + 2].value.length == 0)
	{
		alert('Please enter the height for item ' + (parseInt(j) + parseInt(1)));
		theForm[offSet + 2].focus();
		return(false);
	}
	if(theForm[offSet + 3].value.length == 0)
	{
		alert('Please enter width the item ' + (parseInt(j) + parseInt(1)));
		theForm[offSet + 3].focus();
		return(false);
	}
	if(theForm[offSet + 4].value.length == 0)
	{
		alert('Please enter the depth for item ' + (parseInt(j) + parseInt(1)));
		theForm[offSet + 4].focus();
		return(false);
	}
	return(true);
}

function validateForm(theForm, supressDefaultSave)
{
	//alert("promptDefaultSave: " + promptDefaultSave);
	//alert("promptDefaultChanged: " + promptDefaultChanged);
	startTime = new Date().getTime();
	//updateProgressMessage("validateForm: Start" + ((new Date()).getTime() - startTime));
	if(!theForm.construction_type_id[0].checked && !theForm.construction_type_id[1].checked)
	{
		alert('Please specify a joint type in the Construction Section.');
		theForm.construction_type_id[0].focus();
		theForm.ACTION.value = "";
		return(false);
	}
	if(!theForm.assembly_type_id[0].checked && !theForm.assembly_type_id[1].checked)
	{
		alert('Please specify a assembly type in the Construction Section.');
		theForm.assembly_type_id[0].focus();
		theForm.ACTION.value = "";
		return(false);
	}
	if(!theForm.side_width[0].checked && !theForm.side_width[1].checked)
	{
		alert('Please specify a Side Material Thickness.');
		theForm.side_width[0].focus();
		theForm.ACTION.value = "";
		return(false);
	}
	if(!(theForm.finish_id[0].checked || theForm.finish_id[1].checked || theForm.finish_id[2].checked))
	{
		alert('Please specify a finish.');
		theForm.finish_id[0].focus();
		theForm.ACTION.value = "";
		return(false);
	}
	var materialSelected = false;
	for(var i = 0; i < theForm.side_material_id.length; i++)
	{
		if(theForm.side_material_id[i].checked)
		{
			materialSelected = true;
			break;
		}
	}
	if(!materialSelected)
	{
		alert('Please specify Side Material');
		if(theForm.side_material_id[0].disabled)
		{
			theForm.side_material_id[0].disabled = false;
			theForm.side_material_id[0].focus();
			theForm.side_material_id[0].disabled = true;
		}
		else
		{
			theForm.side_material_id[0].focus();
		}
		theForm.ACTION.value = "";
		return(false);
	}
	if(!theForm.edgedetail_id[0].checked && !theForm.edgedetail_id[1].checked)
	{
		alert('Please specify and Edge Detail.');
		theForm.edgedetail_id[1].focus();
		theForm.ACTION.value = "";
		return(false);
	}
	if(!(theForm.edgeband_id[0].checked ||theForm.edgeband_id[1].checked || theForm.edgeband_id[2].checked))
	{
		alert('Please specify an Edge Band.');
		theForm.edgeband_id.focus();
		theForm.ACTION.value = "";
		return(false);
	}
	if(!theForm.bottom_width[0].checked && !theForm.bottom_width[1].checked && !theForm.bottom_width[2].checked)
	{
		alert('Please specify a Bottom Material Thickness.');
		theForm.side_width[0].focus();
		theForm.ACTION.value = "";
		return(false);
	}
	materialSelected = false;
	for(var i = 0; i < theForm.bottom_material_id.length; i++)
	{
		if(theForm.bottom_material_id[i].checked)
		{
			materialSelected = true;
			break;
		}
	}
	if(!materialSelected)
	{
		alert('Please specify Bottom Material');
		for(var i = 0; i < theForm.bottom_material_id.length; i++)
		{
			if(!theForm.bottom_material_id[i].disabled)
			{
				theForm.bottom_material_id[i].focus();
				theForm.ACTION.value = "";
				return(false);
			}
		}
	}
	if(!(theForm.measurement_unit_id[0].checked || theForm.measurement_unit_id[1].checked))
	{
		alert('Please specify a Measurement Unit.');
		theForm.measurement_unit_id.focus();
		theForm.ACTION.value = "";
		return(false);
	}
	var underNotchSelected = isUnderNotchSelected(theForm);
	if(!underNotchSelected)
	{
		alert('Please specify an Undermount Notch Type.');
		theForm.under_notch_id[0].focus();
		theForm.ACTION.value = "";
		return(false);
	}
	if(!(theForm.install_locking_devices[0].checked || theForm.install_locking_devices[1].checked))
	{
		alert('Please specify a Locking Device Installation option.');
		theForm.install_locking_devices[0].focus();
		theForm.ACTION.value = "";
		return(false);
	}
	if(!supressDefaultSave)
	{
		defaultPromptSave(theForm, "Would you like to save this form's options as default?");
		//alert("saveDefaults: Before " + theForm.save_defaults.value);
		defaultPromptChanged(theForm, "You have changed the options from your default.\r\nWould you like to save this form's options as default?");
		//alert("saveDefaults: After " + theForm.save_defaults.value);
	}
	var j = 0;
	var offSet = indexOfFirstRow;
	while((offSet = getNextRowIndex(theForm, ++offSet)) > 0)
	{
		if(theForm[offSet].value == 'yes')
		{
			if(theForm[offSet + 1].value.length != 0)
			{
				if(!enforceDimensions(theForm, offSet, j))
				{
					theForm.ACTION.value = "";
					return(false);
				}
			}
			else
			{
				if(theForm[offSet].value == 'yes')
				{
					if(theForm[offSet + 2].value.length != 0 || theForm[offSet + 3].value.length != 0 || theForm[offSet + 4].value.length != 0)
					{
						alert("Please enter a quantity for item " + (j + 1));
						theForm.ACTION.value = "";
						return(false);
					}
					else
					{
						theForm[offSet].value = 'no';
						return(true);
					}
				}
			}
		}
		j++;
	}
	//updateProgressMessage("validateForm: Finsh" + ((new Date()).getTime() - startTime));
	//showProgressMessage();
	return(true);
}

var currentDividerIndex = -1;
var currentFileIndex = -1;
function dividerWidthChanged(theForm, index, row, selectedIndex)
{
	var widthValues ="0";
	var i = 0;
	var maxRows = parseInt(getElement(theForm, "length_divider_" + index).value) + parseInt(1);
	//alert(maxRows);
	if(selectedIndex || selectedIndex == 0)
	{
		widthValueArray = getElement(theForm, "divider_width_" + index).value.split(",");
		var newValue;
		//alert("Row: " + row);
		//alert("Index: " + index);
		for(i = 0; i < maxRows; i++)
		{
			if(i < widthValueArray.length)
			{
				if(i == row)
				{
					//alert("selectedIndex = " + widthValueArray[i]);
					newValue = selectedIndex;
				}
				else
				{
					//alert("widthValueArray[i] = " + widthValueArray[i]);
					if(widthValueArray[i])
					{
						newValue = widthValueArray[i];
					}
					else
					{
						newValue = 0;
					}	
				}
			}
			else
			{
				newValue = 0;
			}
			//alert("newValue = " + newValue);
			if(i == 0)
			{
				widthValues = Math.max(0, newValue);
			}
			else
			{
				widthValues += "," + Math.max(0, newValue);
			}
		}
	}
	else
	{
		var element;
		while((element = getElement(theForm, "divider_width_" + index + "_" + i)) != null && i < maxRows)
		{
			var val = "";
			if(element.selectedIndex || element.selectedIndex == 0)
			{
				val = element.selectedIndex;
			}
			else
			{
				if(isNaN(parseInt(element.innerHTML)))
				{
					val = 0;
				}
				else
				{
					val = element.innerHTML;
				}
			}
			//alert("val = " + val);
			if(i == 1)
			{
				widthValues = Math.max(0, val);
			}
			else
			{
				widthValues += "," + Math.max(0, val);
			}
			i++;
		}
		//alert(widthValues);
		for(; i < maxRows; i++)
		{
			widthValues += ",0";
		}
		
	}
	//alert(widthValues);
	getElement(theForm, "divider_width_" + index).value = widthValues;
}

function covertFloatToFraction(number)
{
	var retVal = "";
	var wholeNumber = parseInt(number);
	var fraction = number - wholeNumber;
	var numerator = Math.round(fraction * 16);
	var denominator = 16;
	if(wholeNumber > 0)
	{
		retVal = wholeNumber;
	}
	if(numerator != 0)
	{
		if(numerator == denominator)
		{
			if(retVal == "")
			{
				retVal = 1;
			}
			else
			{
				retVal++;
			}
		}
		else
		{
			if(numerator % 8 == 0)
			{
				numerator = numerator / 8;
				denominator = 2;
			}
			else
			{
				if(numerator % 4 == 0)
				{
					numerator = numerator / 4;
					denominator = 4;
				}
				else
				{
					if(numerator % 2 == 0)
					{
						numerator = numerator / 2;
						denominator = 8;
					}
				}
			}
			retVal = retVal + " " + numerator + "/" + denominator;
		}
	}
	return(retVal);
}

function fillDividerWidthArray(theForm, numCells, dimension)
{
	var cells = new Array(numCells);
	var cellActualWidth = dimension/numCells;
	var wholeNumber = parseInt(cellActualWidth);
	var minUnit = 1/16;
	if(1 != convertUnit(theForm, 1))
	{
		minUnit = 1;
	}
	var fraction = parseInt((cellActualWidth - wholeNumber) * 1 / minUnit) * minUnit;
	//alert(dimension);
	//alert(fraction);
	var cellWidth = wholeNumber + fraction;
	var totalWidth = 0;
	for(var i = 0; i < numCells; i++)
	{
		cells[i] = cellWidth;
		totalWidth += cellWidth;
	}
	var middleCell = parseInt(numCells / 2);
	var add = true;
	var i = 0;
	var k = 0;
	while(dimension - totalWidth >= minUnit || k > 10)
	{
		if(add)
		{
			cells[middleCell + i] += minUnit;
			i++;
		}
		else
		{
			cells[middleCell - i] += minUnit;
		}
		add = !add;
		totalWidth += minUnit;
	}
	if(minUnit == 1/16)
	{
		for(var i = 0; i < cells.length; i++)
		{
			cells[i] = covertFloatToFraction(cells[i]);
		}
	}
	return(cells);
}

function dividerChanged(theForm, index, show, useHiddenFields, useDropDowns)
{
	var element;
	var selectedIndex = selectedIndex = getElement(theForm, "length_divider_" + index).selectedIndex;
	if((element = getElement(theForm, "divider_" + index)))
	{
		if((selectedIndex != 0) && (show || index != currentDividerIndex))
		{
			var html = "";
			widthArr = getElement(theForm, "divider_width_" + index).value.split(",");
			var maxDividers = 0;
			for(var i = 0; i < widthArr.length; i++)
			{
				if(parseInt(widthArr[i]) > parseInt(maxDividers))
				{
					maxDividers = parseInt(widthArr[i]);
				}
			}
			var drawerDepth = getElement(theForm, "depth_" + index).value;
			var drawerWidth = getElement(theForm, "width_" + index).value;
			var width = Math.max(15 * convertToInches(theForm, Math.max(drawerDepth, 1)), 40 * maxDividers);
			var height = parseInt(width * 15/16 * Math.max(drawerWidth, 1) / Math.max(drawerDepth, 1));
			if(height < 160)
			{
				height = 160;
				width = parseInt(height * 16/15 * Math.max(drawerDepth, 1) / Math.max(drawerWidth, 1));
			}
			var lengthDividerElement = getElement(theForm, "length_divider_" + index);
			var numLength = 1;
			if(useHiddenFields)
			{
				numLength = Math.max(lengthDividerElement.value, 0) + parseInt(1);
			}
			else
			{
				numLength = Math.max(lengthDividerElement.selectedIndex , 1);
			}
			html += "<br><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"" + width + "\"><tr><td colspan=\"2\" class=\"dividerOutterTable\">Numbers in the cell are the depth inside the cell.<br><br></td><td class=\"dividerOutterTable\">Numbers in ( ) are actual widths inside of the cell.<br><br></td></tr><tr><td class=\"dividerOutterTable\" align=\"right\">|</td><td class=\"dividerOutterTable\" align=\"center\">DEPTH - ";
			html += drawerDepth;
			if(1 == convertUnit(theForm, 1))
			{
				html += " in";
			}
			else
			{
				html += " mm";
			}
			html += "</td><td class=\"dividerOutterTable\" align=\"left\" nowrap>|&nbsp;&nbsp;&nbsp;Number of Subdividers</td></tr>";
			var rowStartIndex = 0;
			for(var j = 0; j <= index; j++)
			{
				rowStartIndex = getNextRowIndex(theForm, rowStartIndex + 1);
			}
			var dividerMaterialWidth = 0;
			if(useHiddenFields)
			{
				//alert("userHiddenFields");
				dividerMaterialWidth = parseFloat(theForm.side_width.value);
			}
			else
			{
				//alert("!userHiddenFields");
				if(theForm.side_width[1].checked)
				{
					if(1 == convertUnit(theForm, 1))
					{
						dividerMaterialWidth = .625;
					}
					else
					{
						dividerMaterialWidth = 15.875;
					}
				
				}
				else
				{
					if(1 == convertUnit(theForm, 1))
					{
						dividerMaterialWidth = .5;
					}
					else
					{
						dividerMaterialWidth = 12.7;
					}
				}
			}
			var ftbDividerTotalWidth = dividerMaterialWidth * (1 + numLength);
			var ftbUnitLengths = (drawerWidth - ftbDividerTotalWidth);
			var dividerWidthArray = fillDividerWidthArray(theForm, numLength, ftbUnitLengths);
			for(var i = 0; i < numLength; i++)
			{
				var numWidth = 0;
				html += "<tr>";
				if(i < widthArr.length)
				{
					numWidth = widthArr[i];
				}
				if(i == 0)
				{
					html += "<td width=\"1%\" class=\"dividerOutterTable\" rowspan=\"" + numLength + "\">F<br>R<br>O<br>N<br>T<br><br>";
					for(var k = 0; k < drawerWidth.length; k++)
					{
						html += drawerWidth.charAt(k) + "<br>";
					}
					if(1 == convertUnit(theForm, 1))
					{
						html += "<br>i<br>n<br>";
					}
					else
					{
						html += "<br>m<br>m";
					}
					html += "</td>";
				}
				html += "<td width=\"*\">";
				html += "<table border=\"0\" cellpadding=\"0\" class=\"dividerTable\" cellspacing=\"1\" width=\"100%\" >";
				html += "<tr class=\"dividerTable\">";
				var stsDividerTotalLength = dividerMaterialWidth * (2 + parseInt(numWidth));
				var stsUnitLengths = (parseInt(drawerDepth) - stsDividerTotalLength);
				var dividerLengthArray = fillDividerWidthArray(theForm, parseInt(numWidth) + 1, stsUnitLengths);
				for(var j = 0; j <= numWidth; j++)
				{
					html += "<td class=\"dividerTable\">";
					var cellWidth = parseInt((width)/Math.max(parseInt(numWidth) + 1, 1)) - 5;
					html += "<table border=\"0\" cellpadding=\"0\" class=\"noBorder\" cellspacing=\"0\" width=\"100%\"><tr><td class=\"noBorder\"><img src=\"/images/spacer.gif\" border=\"0\" width=\"1\" height=\"" + (height/Math.max(numLength, 1) - 5) + "\"></td><td class=\"noBorder\"><span class=\"dividerOutterTable\">";
					html += dividerLengthArray[j];
					html += "</span></td></tr><tr><td colspan=\"2\" class=\"noBorder\"><img src=\"/images/spacer.gif\" border=\"0\" height=\"1\" width=\"" + (cellWidth) + "\"></td></tr></table></td>";
				}
				html += "</tr>";
				html += "</table>";
				html += "</td>";
				html += "<td width=\"1%\" class=\"dividerOutterTable\">";
				html += "&nbsp;&nbsp;&nbsp;&nbsp;(";
				html += dividerWidthArray[i];
				html += ")&nbsp;&nbsp;&nbsp;&nbsp;";
				if(!useDropDowns)
				{
					html += "<span id=\"divider_width_" + index + "_" + i + "\" class=\"dividerTableLg\">" + numWidth + "</span>";
				}
				else
				{
					html += "<select name=\"divider_width_" + index + "_" + i + "\" class=\"dividerTableLg\" onChange=\"dividerWidthChanged(this.form, " + index + ", " + i + ", this.selectedIndex); dividerChanged(this.form, " + index + ", true, " + useHiddenFields + ", " + useDropDowns + ");rowChanged(this.form, " + index + "); return(true);\">";
					html += "<option value=\"0\""
					if(numWidth == 0)
						html += " selected";
					html += ">None";
					html += "<option value=\"1\""
					if(numWidth == 1)
						html += " selected";
					html += ">1";
					html += "<option value=\"2\""
					if(numWidth == 2)
						html += " selected";
					html += ">2";
					html += "<option value=\"3\""
					if(numWidth == 3)
						html += " selected";
					html += ">3";
					html += "<option value=\"4\""
					if(numWidth == 4)
						html += " selected";
					html += ">4";
					html += "<option value=\"5\""
					if(numWidth == 5)
						html += " selected";
					html += ">5";
					html += "<option value=\"6\""
					if(numWidth == 6)
						html += " selected";
					html += ">6";
					html += "<option value=\"7\""
					if(numWidth == 7)
						html += " selected";
					html += ">7";
					html += "<option value=\"8\""
					if(numWidth == 8)
						html += " selected";
					html += ">8";
					html += "<option value=\"9\""
					if(numWidth == 9)
						html += " selected";
					html += ">9";
					html += "<option value=\"10\""
					if(numWidth == 10)
						html += " selected";
					html += ">10";
					html += "</select>";
				}
				html += "</td>";
				html += "</tr>";
			}
			html += "</table><br>";
			i = 0;
			/*var otherElement
			while((otherElement = getElement("divider_" + i++)) != null)
			{
				if(i != index);
					otherElement.innerHTML = "";
			}*/
			element.innerHTML = html;
			fileNotchChanged(index, true);
			currentDividerIndex = index;
			//alert(html);
		}
		else
		{
			if(selectedIndex == 0)
			{
				element.innerHTML = "";
			}
		}
	}
}

function fileNotchChanged(theForm, index, show)
{
	var element;
	if((element = getElement(theForm, "file_notch_" + index)))
	{
		var fileNotchValue = getElement(theForm, "file_notch_id_" + index).selectedIndex;
		if(fileNotchValue != 0 && (show || currentFileIndex != index))
		{
			var width = 200;
			var height = 200 * Math.max(getElement(theForm, "width_" + index).value, 1) / Math.max(getElement(theForm, "depth_" + index).value, 15) ;
			var html = "<br><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"" + height + "\" width=\"" + width + "\"><tr><td class=\"dividerOutterTable\" align=\"right\">|</td><td class=\"dividerOutterTable\" align=\"center\">DEPTH</td><td class=\"dividerOutterTable\">|</td></tr>";
			html += "<tr>";
			html += "<td width=\"1%\" class=\"dividerOutterTable\">F<br>R<br>O<br>N<br>T</td>";
			html += "<td width=\"*\" class=\"dividerOutterTable\">";
			html += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"dividerTable\" cellspacing=\"1\" width=\"100%\" height=\"" + height + "\">";
			switch(parseInt(fileNotchValue))
			{
				case(0):
					html += "<tr class=\"dividerTable\" height=\"*\">";
					html += "<td class=\"dividerTable\">File Notches";
					html += "</td>";
					html += "</tr>";
					html += "</tr>";
				break;
				case(1):
					html += "<tr class=\"dividerTable\" height=\"10%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"10%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"*\">";
					html += "<td class=\"dividerTableLg\">File Notches";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"10%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"10%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
				break;
				case(2):
					html += "<tr class=\"dividerTable\" height=\"10%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"*\">";
					html += "<td class=\"dividerTableLg\">File Notches";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"10%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
				break;
				case(3):
					html += "<tr class=\"dividerTable\" height=\"20%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "<tr class=\"dividerTable\" height=\"*\">";
					html += "<td class=\"dividerTableLg\">File Notches";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"20%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
				break;
				case(4):
					html += "<tr class=\"dividerTable\">";
					html += "<td class=\"dividerTable\" width=\"10%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"10%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTableLg\" width=\"*\" >File Notches";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"10%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"10%\" >&nbsp;";
					html += "</td>";
					html += "</tr>";
				break;
				case(5):
					html += "<tr class=\"dividerTable\">";
					html += "<td class=\"dividerTable\" width=\"10%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTableLg\" width=\"*\" >File Notches";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"10%\" >&nbsp;";
					html += "</td>";
					html += "</tr>";
				break;
				case(6):
					html += "<tr class=\"dividerTable\">";
					html += "<td class=\"dividerTable\" width=\"20%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTableLg\" width=\"*\" >File Notches";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"20%\" >&nbsp;";
					html += "</td>";
					html += "</tr>";
				break;
				case(7):
					html += "<tr class=\"dividerTable\" height=\"5%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"5%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"30\">";
					html += "<td class=\"dividerTableLg\">File Notches";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"5%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"10%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"5%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"30\">";
					html += "<td class=\"dividerTableLg\">File Notches";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"5%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"5%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
				break;
				case(8):
					html += "<tr class=\"dividerTable\" height=\"5%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"40\">";
					html += "<td class=\"dividerTableLg\">File Notches";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"10%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"40\">";
					html += "<td class=\"dividerTableLg\">File Notches";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"5%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
				break;
				case(9):
					html += "<tr class=\"dividerTable\" height=\"7%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"36\">";
					html += "<td class=\"dividerTableLg\">File Notches";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"14%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"36\">";
					html += "<td class=\"dividerTableLg\">File Notches";
					html += "</td>";
					html += "</tr>";
					html += "<tr class=\"dividerTable\" height=\"7%\">";
					html += "<td class=\"dividerTable\">&nbsp;";
					html += "</td>";
					html += "</tr>";
				break;
				case(10):
					html += "<tr class=\"dividerTable\">";
					html += "<td class=\"dividerTable\" width=\"5%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"5%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTableLg\" width=\"30\" >File Notches";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"5%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"10%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"5%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTableLg\" width=\"30\" >File Notches";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"5%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"5%\" >&nbsp;";
					html += "</td>";
					html += "</tr>";
				break;
				case(11):
					html += "<tr class=\"dividerTable\">";
					html += "<td class=\"dividerTable\" width=\"5%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTableLg\" width=\"40\" >File Notches";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"10%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTableLg\" width=\"40\" >File Notches";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"5%\" >&nbsp;";
					html += "</td>";
					html += "</tr>";
				break;
				case(12):
					html += "<tr class=\"dividerTable\">";
					html += "<td class=\"dividerTable\" width=\"7%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTableLg\" width=\"36\" >File Notches";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"14%\" >&nbsp;";
					html += "</td>";
					html += "<td class=\"dividerTableLg\" width=\"36\" >File Notches";
					html += "</td>";
					html += "<td class=\"dividerTable\" width=\"7%\" >&nbsp;";
					html += "</td>";
					html += "</tr>";
				break;			}
			html += "</table>";
			html += "</td>";
			html += "<td>&nbsp;";
			html += "</td>";
			html += "</tr>";
			html += "</table><br>";
			var i = 0;
			var otherElement
			while((otherElement = getElement(theForm, "file_notch_" + i++)) != null)
			{
				if(i != index);
					otherElement.innerHTML = "";
			}
			element.innerHTML = html;
			currentFileIndex = index;
		}
		else
		{
			if(fileNotchValue == 0)
			{
				element.innerHTML = "";
			}
		}
	}
}



function disableSides(theForm, type)
{
	disableMaterial(theForm, type, '_side');
}

function disableBottoms(theForm, type)
{
	disableMaterial(theForm, type, '_bottom');
}

function disableMaterial(theForm, type, edge)
{
	//updateProgressMessage("disable: " + type);
	var span;
	var i = 1;
	var element;
	while((element = getElement(theForm, "radio_" + type + "_" + (i) + edge)) != null)
	{
		/*if(element.id.indexOf(type) >= 0 && element.id.indexOf("_side") >= 0)
		{*/
			if(element.className != 'disabledMaterialRadioTable')
			{
				element.className = 'disabledMaterialRadioTable';
				element.disabled =  true;
				element.checked = false;
			}
		//}
		i++;
	}
}

function enableSides(theForm, type)
{
	enableMaterial(theForm, type, "_side");
}

function enableBottoms(theForm, type)
{
	enableMaterial(theForm, type, "_bottom");
}

function enableMaterial(theForm, type, edge)
{
	//updateProgressMessage("enable: " + type + "::" + edge);
	var span;
	var i = 1;
	var element;
	while((element = getElement(theForm, "radio_" + type + "_" + (i) + edge)) != null)
	{
		if(!(theForm.construction_type_id[0].checked && element.value == 14))
		{
			if(element.className != "disabledSizeRadioTable" && element.className != 'radioTable')
			{
				element.className = 'radioTable';
				element.disabled = false;
			}
		}
		i++;
	}
}

function updateMaterialBySizes(theForm, turnOn, turnOff)
{
	//updateProgressMessage("updateMaterialBySizes: ");
	var isDovetail = theForm.construction_type_id[0].checked;
	for(var i = 0; i < turnOn.length; i++)
	{
		var element = getElement(theForm, "radio_" + turnOn[i]);
		if(element != null)
		{
			//updateProgressMessage('element.value = ' + element.value);
			if(isDovetail && element.value == 14)
			{
				element.className =  "disabledSizeRadioTable";
				element.disabled =  true;
				element.checked = false;
			}
			else
			{
				element.className = 'radioTable';
				element.disabled =  false;
			}

		}
	}
	//alert('After turnOn');
	for(var i = 0; i < turnOff.length; i++)
	{
		var element = getElement(theForm, "radio_" + turnOff[i]);
		if(element != null)
		{
			element.className =  "disabledSizeRadioTable";
			element.disabled =  true;
			element.checked = false;
		}
	}
	//alert('After turnOff');
}

function getNextRowIndex(theForm, i, j)
{
	var iStart = i;
	while(i < theForm.length)
	{
		if(theForm[i].name == "changed_" + j)
		{	
			if(i == 0)
			{
				indexOfFirstRow = i;
			}
			return(i);
		}
		i++;
	}
	return(-1);
}

function submitForm()
{
	setTimeout("mainForm.submit();", 200);
}


function formUpdated(obj, validateOrder, validateRows, surpressNotchWarning, firstRun)
{
	startTime = new Date().getTime();
	//updateProgressMessage("formUpdated Start: " + ((new Date()).getTime() - startTime));
	theForm = obj.form;
	mainForm = obj.form;
	var constructionTypeChanged = obj == theForm.construction_type_id[0] || obj == theForm.construction_type_id[1];
	if(validateOrder)
	{
		var melamineSelected = false;
		var solidwoodSelected = false;
		var plywoodSelected = false;
		var allowMelamine = true;
		var allowSolidwood = true;
		var allowPlywood = true;
		var finishChanged = obj == theForm.finish_id[0] || obj == theForm.finish_id[1] || obj == theForm.finish_id[2];
		var sideWidthChanged = obj == theForm.side_width[0] || obj == theForm.side_width[1];
		var bottomWidthChanged = obj == theForm.bottom_width[0] || obj == theForm.bottom_width[1] || obj == theForm.bottom_width[2];
		//updateProgressMessage("constructionTypeChanged: " + constructionTypeChanged);
		//updateProgressMessage("finishChanged: " + finishChanged);
		//updateProgressMessage("sideWidthChanged: " + sideWidthChanged);
		//updateProgressMessage("bottomWidthChanged: " + bottomWidthChanged);
		
		//updateProgressMessage("formUpdated Before Construction: " + ((new Date()).getTime() - startTime));
		if(theForm.construction_type_id[0].checked)
		{
			allowMelamine = false;
			theForm.bottom_width[2].disabled = true;
			theForm.bottom_width[2].checked = false;
			theForm.bottom_width[1].disabled = false;
			var element;
			var i = 0;
			while((element = getElement(theForm, "bottom_size_" + (i++))) != null)
			{
				element.innerHTML = "3/8&quot;&nbsp;Bottom";
			}
		}
		else
		{
			theForm.bottom_width[1].disabled = true;
			theForm.bottom_width[1].checked = false;
			theForm.bottom_width[2].disabled = false;
			var i = 0;
			while((element = getElement(theForm, "bottom_size_" + (i++))) != null)
			{
				element.innerHTML = "1/2&quot;&nbsp;Bottom";
			}
		}
		//updateProgressMessage("formUpdated After Construction: " + ((new Date()).getTime() - startTime));
		if(theForm.assembly_type_id[0].checked)
		{
			theForm.finish_id[2].disabled = true;
			theForm.finish_id[2].checked = false;
			theForm.under_notch_id[0].checked = true;
			for(var i = 1; i < theForm.under_notch_id.length; i++)
			{
				theForm.under_notch_id[i].disabled = true;
			}
		}
		else
		{
			theForm.finish_id[2].disabled = false;
			for(var i = 1; i < theForm.under_notch_id.length; i++)
			{
				theForm.under_notch_id[i].disabled = false;
				theForm.under_notch_id[i].disabled = false;
			}
		}
		//updateProgressMessage("formUpdated After Assembly: " + ((new Date()).getTime() - startTime));
		if(constructionTypeChanged || finishChanged || sideWidthChanged || bottomWidthChanged || firstRun)
		{
			if(!theForm.finish_id[1].checked)
			{
				//updateProgressMessage("Finish After or Unfinished");
				if(sideWidthChanged || constructionTypeChanged || firstRun)
				{
					if(theForm.side_width[0].checked)
					{
						updateMaterialBySizes(theForm, allSideMaterials, invalid12SideMaterials);
					}
					else
					{
						updateMaterialBySizes(theForm, allSideMaterials, invalid58SideMaterials);
					}
				}
				if(bottomWidthChanged || finishChanged || firstRun)
				{
					if(theForm.bottom_width[1].checked)
					{
						//updateProgressMessage("Finish After or Unfinished - 3/8");
						updateMaterialBySizes(theForm, allBottomMaterials, invalid38BottomMaterials);
					}
					else
					{
						if(theForm.bottom_width[2].checked)
						{
							//updateProgressMessage("Finish After or Unfinished - 1/2");
							updateMaterialBySizes(theForm, allBottomMaterials, invalid12BottomMaterials);
						}
						else
						{
							//updateProgressMessage("Finish After or Unfinished - 1/4");
							updateMaterialBySizes(theForm, allBottomMaterials, invalid14BottomMaterials);
						}
					}
				}
			}
			else
			{
				//updateProgressMessage("Prefinish");
				if(sideWidthChanged || constructionTypeChanged || firstRun)
				{
					if(theForm.side_width[0].checked)
					{
						updateMaterialBySizes(theForm, allSideMaterials, invalidPre12SideMaterials);
					}
					else
					{
						updateMaterialBySizes(theForm, allSideMaterials, invalidPre58SideMaterials);
					}
				}
				if(bottomWidthChanged || finishChanged || firstRun)
				{
					if(theForm.bottom_width[1].checked)
					{
						//updateProgressMessage("Prefinish - 3/8");
						updateMaterialBySizes(theForm, allBottomMaterials, invalidPre38BottomMaterials);
					}
					else
					{
						if(theForm.bottom_width[2].checked)
						{
							//updateProgressMessage("Prefinish - 1/2");
							updateMaterialBySizes(theForm, allBottomMaterials, invalidPre12BottomMaterials);
						}
						else
						{
							//updateProgressMessage("Prefinish - 1/4");
							updateMaterialBySizes(theForm, allBottomMaterials, invalidPre14BottomMaterials);
						}
					}
				}
			}
		}
		if(theForm.finish_id[2].checked)
		{
			allowMelamine = false;
		}
		if(theForm.finish_id[1].checked)
		{
			allowSolidwood = false;
		}
		//updateProgressMessage("formUpdated Finish before loop: " + ((new Date()).getTime() - startTime));
		for(var i = 0; i < theForm.length; i++)
		{
			var element = theForm[i];
			if(element.id)
			{
				if(theForm[i].checked)
				{
					if(element.id.indexOf("melamine") >= 0)
					{
						melamineSelected = true && allowMelamine;
						solidwoodSelected = false;
						plywoodSelected = false;
						break;
					}
					if(element.id.indexOf("plywood") >= 0)
					{
						plywoodSelected = true;
						melamineSelected = false;
						solidwoodSelected = false;
						break;
					}
					if(element.id.indexOf("solidwood") >= 0)
					{
						solidwoodSelected = true;
						melamineSelected = false;
						plywoodSelected = false;
						break;
					}
				}
			}
		}
		//updateProgressMessage("formUpdated After Finish: " + ((new Date()).getTime() - startTime));
		if(melamineSelected)
		{
			if(obj != theForm.finish_id[0])
			{
				theForm.finish_id[1].checked = true;
				theForm.edgedetail_id[0].checked = false;
				theForm.edgedetail_id[0].disabled = true;
				theForm.edgedetail_id[1].checked = true;
			}
			for(var k = 0; k < theForm.length; k++)
			{
				if(theForm[k].name =="bottom_material_id")
				{
					if(theForm[k].id.indexOf("melamine") < 0)
					{
						theForm[k].disabled = true;
						theForm[k].checked = false;
					}
				}
			}
		}
		else
		{ 
			theForm.edgedetail_id[0].disabled = false;
		}
		if(theForm.edgedetail_id[1].checked && theForm.finish_id[1].checked )
		{
			theForm.edgeband_id[1].disabled = false;
			theForm.edgeband_id[2].disabled = false;
			if(melamineSelected)
			{
				var selectedSideMaterialID = 0;
				for(var i = 0; i < theForm.side_material_id.length; i++)
				{
					if(theForm.side_material_id[i].checked)
					{
						selectedSideMaterialID = theForm.side_material_id[i].value;
					}
				}
				if(selectedSideMaterialID == 57)
				{
					theForm.edgeband_id[0].disabled = false;
					if(!(theForm.edgeband_id[1].checked || theForm.edgeband_id[2].checked))
					{
						theForm.edgeband_id[0].checked = true;
					}
				}
				else
				{
					theForm.edgeband_id[0].disabled = true;
					if(!(theForm.edgeband_id[1].checked || theForm.edgeband_id[2].checked))
					{
						theForm.edgeband_id[1].checked = true;
					}
				}
			}
		}
		else
		{
			theForm.edgeband_id[0].checked = true;
			theForm.edgeband_id[1].checked = false;
			theForm.edgeband_id[1].disabled = true;
			theForm.edgeband_id[2].checked = false;
			theForm.edgeband_id[2].disabled = true;
		}
		//updateProgressMessage("formUpdated After Edgeband & Detail: " + ((new Date()).getTime() - startTime));
		//updateProgressMessage("allowMelamine: " + allowMelamine);
		//updateProgressMessage("allowSolidwood: " + allowSolidwood);
		//updateProgressMessage("allowPlywood: " + allowPlywood);
		
		//alert("Sides: Start");
		if(constructionTypeChanged || finishChanged || firstRun || sideWidthChanged)
		{
			if(allowMelamine)
			{
				enableSides(theForm, "melamine");
				//enableBottoms(theForm, "melamine");
			}
			else
			{
				disableSides(theForm, "melamine");
				//disableBottoms(theForm, "melamine");
			}
			if(allowSolidwood)
				enableSides(theForm, "solidwood");
			else
				disableSides(theForm, "solidwood");
			if(allowPlywood)
				enableSides(theForm, "plywood");
			else
				disableSides(theForm, "plywood");
		}
		//alert("Sides: End");
		//updateProgressMessage("formUpdated After Sides: " + ((new Date()).getTime() - startTime));
		if(!theForm.under_notch_id[0].checked)
		{
			var underNotchID = 0;
			for(var i = 0; i < theForm.under_notch_id.length; i++)
			{
				if(theForm.under_notch_id[i].checked)
				{
					underNotchID = i;
					break;
				}
			}
			if(theForm.assembly_type_id[1].checked)
			{
				theForm.install_locking_devices[1].disabled = false;
				var underMountName = underNotchNames[underNotchID] + " Notch";
				var i = 0;
				if(getElement(theForm, "undermount_name_0").innerHTML != underMountName)
				{
					while((element = getElement(theForm, "undermount_name_" + (i++))) != null)
					{
						element.innerHTML = underMountName;
					}
				}
				var lockingDeviceName = underNotchLockingDeviceNames[underNotchID];
				i = 0;
				if((element = getElement(theForm, "locking_device_name")).innerHTML != lockingDeviceName)
				{
					element.innerHTML = lockingDeviceName; 
					while((element = getElement(theForm, "locking_device_name_" + (i++))) != null)
					{
						element.innerHTML = lockingDeviceName;
					}
				}
			}
			else
			{
				theForm.install_locking_devices[1].checked = false;
				theForm.install_locking_devices[1].disabled = true;
				var i = 0;
				while((element = getElement(theForm, "undermount_name_" + (i++))) != null)
				{
					element.innerHTML = "Undermount Notch";
				}
				i = 0;
				getElement(theForm, "locking_device_name").innerHTML = "Closing Device";
				while((element = getElement(theForm, "locking_device_name_" + (i++))) != null)
				{
					element.innerHTML = "Closing Device";
				}
			}				
		}
		else
		{
			theForm.install_locking_devices[0].checked = true;
			theForm.install_locking_devices[1].checked = false;
			theForm.install_locking_devices[1].disabled = true;
			var i = 0;
			while((element = getElement(theForm, "undermount_name_" + (i++))) != null)
			{
				element.innerHTML = "Undermount Notch";
			}
			i = 0;
			getElement(theForm, "locking_device_name").innerHTML = "Closing Device";
			while((element = getElement(theForm, "locking_device_name_" + (i++))) != null)
			{
				element.innerHTML = "Closing Device";
			}
		}
		//updateProgressMessage("formUpdated After Notch: " + ((new Date()).getTime() - startTime));
	}
	//updateProgressMessage("formUpdated Starting Loop: " + ((new Date()).getTime() - startTime));
	var j = 0;
	var offSet = indexOfFirstRow;
	var hasShownNotchableWarning = false;
	var lastTime = null;
	while((offSet = getNextRowIndex(theForm, ++offSet, j)) > 0)
	{
		//updateProgressMessage("formUpdated Starting Row: " + ((new Date()).getTime() - startTime));
		lastTime = new Date().getTime();
		if(theForm[offSet].value == "yes" || validateRows || constructionTypeChanged)
		{
			//updateProgressMessage("Changed: " + j + ", value:" + theForm[offSet].value + '::validateRows: ' + validateRows);
			var assemblyTypeID = 0;
			var bottomWidth = 0;
			var constructionTypeID = 0;
			if(theForm.assembly_type_id.length)
			{
				if(theForm.assembly_type_id[0].checked)
				{
					assemblyTypeID = 1;
				}
				if(theForm.assembly_type_id[1].checked)
				{
					assemblyTypeID = 2;
				}
				if(theForm.bottom_width[0].checked)
				{
					bottomWidth = parseFloat(.25);
				}
				if(theForm.bottom_width[1].checked)
				{
					bottomWidth = parseFloat(.375);
				}
				if(theForm.bottom_width[2].checked)
				{
					bottomWidth = parseFloat(.5);
				}
				if(theForm.construction_type_id[0].checked)
				{
					constructionTypeID = 1;
				}
				if(theForm.construction_type_id[1].checked)
				{
					constructionTypeID = 2;
				}
			}
			else
			{
				assemblyTypeID = theForm.assembly_type_id.value;
				bottomWidth = parseFloat(theForm.bottom_width.value);
				constructionTypeID = theForm.construction_type_id.value;
			}
			if(melamineSelected || constructionTypeID == 2)
			{
				theForm[offSet + 6].checked = false;
				theForm[offSet + 6].disabled = true;
			}
			else
			{
				theForm[offSet + 6].disabled = false;
			}
			if(theForm[offSet + 1].value.length > 0)
			{
				if(!validateDimensions(theForm, offSet, j, constructionTypeID, 1, 2, 3, 4))
				{
					return(false);
				}
			}
			else
			{
				theForm[offSet].value = 'no';
				theForm[offSet + 2].value = '';
				theForm[offSet + 3].value = '';
				theForm[offSet + 4].value = '';
				continue;
			}
			if(theForm[offSet + 8].selectedIndex == 0)
			{
				theForm[offSet + 9].value = "";
			}
			if(assemblyTypeID == 1)
			{
				theForm[offSet + 8].disabled = true;
				theForm[offSet + 8].selectedIndex = 0;			
				theForm[offSet + 9].value = "";
				if(assemblyTypeID == 2)
				{
					dividerChanged(theForm, j, false);
				}
			}
			else
			{
				theForm[offSet + 8].disabled = false;
			}
			if(bottomWidth > .25)
			{
				theForm[offSet + 14].disabled = true;
				theForm[offSet + 14].checked = true;
			}
			else
			{
				theForm[offSet + 14].disabled = false;
				if(theForm.bottom_width.length)
				{
					if(obj == theForm.bottom_width[0])
					{
						theForm[offSet + 14].checked = false;
					}
				}
			}
			if(theForm[offSet + 10].checked)
			{
				theForm[offSet + 2].value = convertUnit(theForm, 6);
			}
			if((theForm[offSet + 2].value < convertUnit(theForm, 10)) || (theForm[offSet + 3].value < convertUnit(theForm, 13.5) && theForm[offSet + 4].value < convertUnit(theForm, 13.5))  || theForm[offSet + 8].selectedIndex != 0)
			{
				theForm[offSet + 12].selectedIndex = 0;
				theForm[offSet + 12].disabled = true;
			}
			else
			{
				theForm[offSet + 12].disabled = false;
				switch(theForm[offSet + 12].selectedIndex)
				{
					case(1):
					case(2):	fileNotchVerify(theForm, j, offSet, convertUnit(theForm, 17), convertUnit(theForm, 0)); break;
					case(3):	fileNotchVerify(theForm, j, offSet, convertUnit(theForm, 13.5), convertUnit(theForm, 0)); break;
					case(4):
					case(5):	fileNotchVerify(theForm, j, offSet, convertUnit(theForm, 0), convertUnit(theForm, 17)); break;
					case(6):	fileNotchVerify(theForm, j, offSet, convertUnit(theForm, 0), convertUnit(theForm, 13.5)); break;
					case(7):
					case(8):	fileNotchVerify(theForm, j, offSet, convertUnit(theForm, 35), convertUnit(theForm, 0)); break;
					case(9):	fileNotchVerify(theForm, j, offSet, convertUnit(theForm, 27), convertUnit(theForm, 0)); break;
					case(10):
					case(11):	fileNotchVerify(theForm, j, offSet, convertUnit(theForm, 0), convertUnit(theForm, 35)); break;
					case(12):	fileNotchVerify(theForm, j, offSet, convertUnit(theForm, 0), convertUnit(theForm, 27)); break;
				}
			}
			if(theForm[offSet + 12].selectedIndex == 0)
			{
				theForm[offSet + 13].checked = false;
				theForm[offSet + 13].disabled = true;
			}
			else
			{
				theForm[offSet + 13].disabled = false;
			}
			var underNotchSelected = isUnderNotchSelected(theForm);
			var isUnderNotchObject = false;
			for(var i = 0; i < theForm.under_notch_id.length; i++)
			{
				if(obj == theForm.under_notch_id[i])
				{
					isUnderNotchObject = true;
				}
			}
			if(assemblyTypeID == 2 && !theForm.under_notch_id[0].checked) // 7 is undermount notch, 11 is install locking device
			{
				var rowIsNotchable = isNotchable(theForm, parseFloat(theForm[offSet + 4].value));
				var underChecked = theForm[offSet + 7].checked;
				var underDisabled = theForm[offSet + 7].disabled;
				var installChecked = theForm[offSet + 11].checked;
				var installDisabled = theForm[offSet + 11].disabled;
				if(isUnderNotchObject ||  obj == theForm.install_locking_devices[1] || validateRows)
				{
					var underNotchValue = theForm[offSet + 7].checked;
					var installLockingDevicesValue = theForm[offSet + 11].checked;
					if(underNotchSelected && rowIsNotchable)
					{
						theForm[offSet + 7].disabled = false;
						theForm[offSet + 11].disabled = false;
						if(!(validateOrder && validateRows && surpressNotchWarning))
						{
							theForm[offSet + 7].checked = true;
							if(theForm.install_locking_devices[1].checked)
							{
								theForm[offSet + 11].checked = true;
							}
							else
							{
								if(obj == theForm.install_locking_devices[0])
								{
									theForm[offSet + 11].checked = false;
								}
							}
						}
					}
					else
					{
						theForm[offSet + 7].checked = false;
						theForm[offSet + 7].disabled = true;
						theForm[offSet + 11].checked = false;
						theForm[offSet + 11].disabled = true;
						if(!hasShownNotchableWarning && !isNaN(parseInt(theForm[offSet + 1].value)) && !surpressNotchWarning)
						{
							hasShownNotchableWarning = true;
							showNotchableWarning(theForm);
						}
					}
					if(underNotchValue != theForm[offSet + 7].checked)
					{
						theForm[offSet].value = "yes";
					}
					else
					{
						if(installLockingDevicesValue != theForm[offSet + 11].checked)
						{
							theForm[offSet].value = "yes";
						}
					}
				}
				else
				{
					if(obj == theForm[offSet + 4])
					{
						if(rowIsNotchable)
						{
							if(!theForm.under_notch_id[0].checked)
							{
								theForm[offSet + 7].checked = true;
								theForm[offSet + 7].disabled = false;
							}
							if(theForm.install_locking_devices[1].checked)
							{
								theForm[offSet + 11].checked = true;
								theForm[offSet + 11].disabled = false;
							}
						}
						else
						{
							theForm[offSet + 7].checked = false;
							theForm[offSet + 7].disabled = true;
							theForm[offSet + 11].checked = false;
							theForm[offSet + 11].disabled = true;
							if(!hasShownNotchableWarning && !isNaN(parseInt(theForm[offSet + 1].value)) && !surpressNotchWarning)
							{
								hasShownNotchableWarning = true;
								showNotchableWarning(theForm);
							}
						}
					}
				}
				//if(underChecked != theForm[offSet + 7].checked || installChecked != theForm[offSet + 11].checked)
				//{
					theForm[offSet].value = "yes";
				//}

			}
			else
			{
				theForm[offSet + 7].checked = false;
				theForm[offSet + 7].disabled = true;
				theForm[offSet + 11].checked = false;
				theForm[offSet + 11].disabled = true;
			}
			if(theForm[offSet + 14].checked && theForm[offSet + 18].value != 'yes') // 14 is thick_bottom
			{
				theForm[offSet + 18].value = 'yes';
				theForm[offSet].value = 'yes';
			}
			else
			{
				if(!theForm[offSet + 14].checked && theForm[offSet + 18].value != '')
				{
					theForm[offSet + 18].value = '';
					theForm[offSet].value = 'yes';
				}
			}
		}
		offSet += 20;
		j++;
		//updateProgressMessage('Item ' + j + ' took ' + (new Date().getTime() - lastTime)); 
	}
	//updateProgressMessage("formUpdated End: " + ((new Date()).getTime() - startTime));
	//showProgressMessage();
	return(true);
}

function isUnderNotchSelected(theForm)
{
	var underNotchSelected = false;
	for(var i = 0; i < theForm.under_notch_id.length; i++)
	{
		if(theForm.under_notch_id[i].checked)
		{
			underNotchSelected = true;
			break;
		}
	}
	return(underNotchSelected);
}

function showNotchableWarning(theForm)
{
	var underNotchID;
	for(var i = 1; i < theForm.under_notch_id.length; i++)
	{
		if(theForm.under_notch_id[i].checked)
		{
			underNotchID = i;
		}
	}
	var validSizes;
	if(theForm.measurement_unit_id[0].checked)
	{
		validSizes = underNotchValidSizesIn[underNotchID].split(',');
	}
	else
	{
		validSizes = underNotchValidSizesMm[underNotchID].split(',');
	}
	var units = "inches";
	if(theForm.measurement_unit_id[1].checked)
	{
		units = "mm";
	}
	alert('Warning:  ' + underNotchNames[underNotchID] + " Notches are only available on drawers of the following lengths:\n" + validSizes + ' ' + units + '.');
}

function fileNotchVerify(theForm, index, offSet, minWidth, minDepth)
{
	var width = convertUnit(theForm, theForm[offSet + 3].value);
	var depth = convertUnit(theForm, theForm[offSet + 4].value);
	if(width < minWidth)
	{
		alert("The drawer must be at least " + minWidth + " wide for your choice of File Notches");
		theForm[offSet + 12].selectedIndex = 0;
		theForm[offSet + 12].focus();
		fileNotchChanged(theForm, index, false);
	}
	if(depth < minDepth)
	{
		alert("The drawer must be at least " + minDepth + " deep for your choice of File Notches");
		theForm[offSet + 12].selectedIndex = 0;
		theForm[offSet + 12].focus();
		fileNotchChanged(theForm, index, false);
	}
	return(true);
}

function rowChanged(theForm, index)
{
	var element = getElement(theForm, 'changed_' + index);
	if(element != null)
	{
		element.value = 'yes';
	}
	else
	{
		alert('Unsupported Browser');
	}
}

function setCounties(theForm, selectedIndex, stateID, countyID)
{
	var titleElement = getElement(theForm, "county_lable");
	var dropDownElement = getElement(theForm, "county_dropdown");
	if(theForm.shipping_state_id[selectedIndex].value == 5 || stateID == 5)
	{
		if(titleElement.innerHTML.length == 0)
		{
			titleElement.innerHTML = "County:";
			var html = "<select name=\"shipping_county_id\">";
			for(var i = 0; i < countyIds.length; i++)
			{
				html += "<option value=\"" + countyIds[i] + "\"";
				if(countyID == countyIds[i])
				{
					html += " selected";
				}
				html += ">" + countyNames[i];	
			}
			html += "</select>";
			dropDownElement.innerHTML = html;
		}
	}
	else
	{
		titleElement.innerHTML = "";
		dropDownElement.innerHTML = "";
	}
}

function isNotchable(theForm, depth)
{
	var underNotchID = 0;
	for(var i = 1; i < theForm.under_notch_id.length; i++)
	{
		if(theForm.under_notch_id[i].checked)
		{
			underNotchID = i;
		}
	}
	if(underNotchID == 0)
	{
		return(true);
	}
	else
	{
		var validSizes;
		if(theForm.measurement_unit_id[0].checked)
		{
			validSizes = underNotchValidSizesIn[underNotchID].split(',');
		}
		else
		{
			validSizes = underNotchValidSizesMm[underNotchID].split(',');
		}
		for(var i = 0; i < validSizes.length; i++)
		{
			if(parseFloat(depth) == parseFloat(validSizes[i]))
			{
				return(true);
			} 
		}
	}
	return(false);
}

