function $(id) { return document.getElementById(id); }

function autoTab(field) {
	if (field == 'a') {
		var aValue = $('aField').value.replace(/([^0-9])/g, "");
		$('aField').value = aValue;
		if (aValue.length == 3) { $('bField').focus(); }
	}
	else if (field == 'b') {
		var bValue = $('bField').value.replace(/([^0-9])/g, "");
		$('bField').value = bValue;
		if (bValue.length == 3) { $('cField').focus(); }
	}	
	else if (field == 'c') { $('cField').value = $('cField').value.replace(/([^0-9])/g, ""); }
}

function validateJobQuoteLookup() {
	var errors = 0;
	if ($('quote_form').value.length != 2) { errors += 1; }
	if ($('aField').value.replace(/([^0-9])/g, "").length != 3) { $('aField').className = 'notice_o'; $('aField').focus(); errors += 1; } else { $('aField').className = 'mx'; }
	if ($('bField').value.replace(/([^0-9])/g, "").length != 3) { $('bField').className = 'notice_o'; $('bField').focus(); errors += 1; } else { $('bField').className = 'mx'; }
	if ($('cField').value.replace(/([^0-9])/g, "").length != 3) { $('cField').className = 'notice_o'; $('cField').focus(); errors += 1; } else { $('cField').className = 'mx'; }
	if (errors > 0) { return false; }
	else { return true; }
}


// This function provides the option to hide and show the product list
//	that is in the right side gray column
function displayProductList() {
	var nextYear = new Date();
	nextYear.setFullYear(nextYear.getFullYear() + 1);
	var tabColumnGroupStyle = $('tab_column_group').style;
	var tabColumnNameStyle = $('tab_column_name').style;
	var displayByButton = $('display_by_button');
	if (displayByButton.value == 'Show Me Products by Name') {
		displayByButton.value = "Show Me Products by Group";
		tabColumnGroupStyle.display = 'none';
		tabColumnNameStyle.display = 'block';
		document.cookie = "displayBy=byName; path=/; expires=" + nextYear.toGMTString();
	}
	else if (displayByButton.value == 'Show Me Products by Group') {
		displayByButton.value = "Show Me Products by Name";
		tabColumnGroupStyle.display = 'block';
		tabColumnNameStyle.display = 'none';
		document.cookie = "displayBy=byCategory; path=/; expires=" + nextYear.toGMTString();
	}
}

function displayGroupList(group_column) {
	var nextYear = new Date();
	nextYear.setFullYear(nextYear.getFullYear() + 1);
	var groupColumnStyle = $(group_column).style;
	var groupArrowClosed = $(group_column + '_closed').style;
	var groupArrowOpen = $(group_column + '_open').style;
	if (groupColumnStyle.display == "none") {
		groupColumnStyle.display = "block";
		groupArrowClosed.display = "none";
		groupArrowOpen.display = "inline";
		var cookieGroup = group_column.replace(/([^a-zA-Z])/g, "");
		document.cookie = cookieGroup + '=open; path=/; expires=' + nextYear.toGMTString();
	}	
	else {
		groupColumnStyle.display = "none";
		groupArrowClosed.display = "inline";
		groupArrowOpen.display = "none";
		var cookieGroup = group_column.replace(/([^a-zA-Z])/g, "");
		document.cookie = cookieGroup + '=closed; path=/; expires=' + nextYear.toGMTString();
	}
}