function initializeCustomSizes() {
	var selOptions = document.getElementById('selOptions');
	if (selOptions != null)
		toggleCustomSizes(selOptions.value);
}

function toggleCustomSizes(value) {
	var CustomOptionSelect = document.getElementById('CustomOptionSelect');
	if (CustomOptionSelect)
		CustomOptionSelect.style.display = ((value == 'CUSTOM')?'':'none');
}

function populateCustomOptionId(optionId, width) {
	document.getElementById('CustomOption').value = optionId;
	document.getElementById('txtCustomWidth').value = width;
}

function populateCustomLength(attributeIndex, widthIndex, curLenFt, curLenIn) {
	var objSel = document.getElementById('descLength'),
		objLenFt = document.getElementById('txtCustomLengthFt'),
		objLenIn = document.getElementById('txtCustomLengthIn'),
		objDispLenIn = document.getElementById('dispCustomLengthIn');
	var optionId = optionIds[attributeIndex][widthIndex],
		optionWidth = optionWidths[attributeIndex][widthIndex];
	var arrOption = eval('arrOption' + optionId);
	var minLen = arrOption[0],
		maxLen = arrOption[1],
		lenInc = arrOption[2];
	var minFt = parseInt(minLen / 12),
		minIn = minLen % 12,
		maxFt = parseInt(maxLen / 12),
		maxIn = maxLen % 12,
		incFt = parseInt(lenInc / 12),
		incIn = lenInc % 12;
	var text = '(' + minFt + ' ft.';
	if (minIn != 0)
		text += ' ' + minIn + ' in.';
	text += ' - ' + maxFt + ' ft.';
	if (maxIn != 0)
		text += ' ' + maxIn + ' in.';
	text += ',';
	if (incFt != 0)
		text += ' ' + incFt + ' ft.';
	if (incIn != 0)
		text += ' ' + incIn + ' in.';
	text += ' increments)';
	objSel.innerHTML = text;
	objLenFt.maxLen = maxFt.toString().length;
	objLenFt.size = maxFt.toString().length;
	objLenFt.value = ((curLenFt == 0)?minFt:curLenFt);
	if (incIn != 0)	{
		objLenIn.value = ((curLenIn == 0)?minIn:curLenIn);
		objDispLenIn.style.display = '';
	} else {
		objLenIn.value = 0;
		objDispLenIn.style.display = 'none';
	}
	document.getElementById('txtCustLenMin').value = minLen;
	document.getElementById('txtCustLenMax').value = maxLen;
	document.getElementById('txtCustLenInc').value = lenInc;
		
	populateCustomOptionId(optionId, optionWidth);
}

function populateOptionAttributes(currentAttribute, curWidth, curLenFt, curLenIn) {
	var objSel = document.getElementById('selCustomOptions');
	if (objSel) {
		objSel.options.length = 0;
		var length = optionAttribute.length;
		for (var x=0; x<length; x++) {
			objSel.options[objSel.options.length] = new Option(optionAttribute[x], x, false, (currentAttribute == x));
		}
		document.getElementById('trCustomOptions').style.display = ((length > 1)?'':'none');
		populateOptionWidths(objSel.value, curWidth, curLenFt, curLenIn);
	}
}

function populateOptionWidths(attributeIndex, curWidth, curLenFt, curLenIn) {
	var objSel = document.getElementById('selCustomWidth');
	if (objSel) {
		objSel.options.length = 0;
		var length = optionWidths[attributeIndex].length;
		for (var x=0; x<length; x++) {
			var width = optionWidths[attributeIndex][x];
			var widthFt = parseInt(width / 12),
				widthIn = width % 12;
			var text = widthFt + ' ft.';
			if (widthIn != 0)
				text += ' ' + widthIn + ' in.';
			objSel.options[objSel.options.length] = new Option(text, x, false, (curWidth == x));
		}
		populateCustomLength(attributeIndex, objSel.value, curLenFt, curLenIn);
	}
}

function checkNumeric(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
 return true;
}

function swapImage(itemid, basepath, medimage, largeimage, caption) {
	document.getElementById('medImage').src = basepath + medimage;
	document.getElementById('imgCaption').innerHTML = caption;
	document.getElementById('aEnlarge').href = 'Enlarge.cfm?ItemID=' + itemid + '&imgLarge=' + largeimage + '&caption=' + caption;
}

