function confirmation(variable_value) {
	var answer = confirm('Are you sure that you want to delete this job (lcs#'+variable_value+')?  All data in the job will be deleted.')
	if (answer){
		alert('job number '+variable_value+' has been deleted!');
		window.location = 'delete_job.php?lcs='+variable_value;
	}
	else{
		alert('This job will not be deleted');
	}
}
function bidConfirmation(variable_value) {
	var answer = confirm('Are you sure that you want to order bid '+variable_value+'?');
	if (answer){
		alert('bid number '+variable_value+' has been ordered!');
		window.location = 'order_bid.php?lcs='+variable_value;
	}
	else {
		alert('This bid will not be changed and will not be ordered');
	}
}
function open_new_window(url) {
	new_window = window.open(url,'window_name','resizable=1,width=520,height=370,left=80,top=80')
}
function open_help_window(url) {
	new_window = window.open(url,'window_name','resizable=1,width=1024,height=600,left=80,top=80,scrollbars=1')
}
function copyAddress(box) {
	if (box.checked) {
		$('b_address').value = $('address').value;
		$('b_city').value = $('city').value;
		$('b_state').value = $('state').value;
		$('b_zip').value = $('zip').value;
	}
}

function confirmDel() {
	if (confirm('Do you really want to clear the whole job?')){
		document.form1.clear.value = 'ClearingEverything';
		return true;
	}
	return false;
}
function findSelected(select, value) {
	for (i=0; i < select.options.length; i++) {
		if (select.options[i].text == value) {
			select.selectedIndex = i;
			break;
		}
	}
}

function setInitial() {
	$('whatselector').value = initial_what;
	whatOnChange();
	findSelected($('woodselector'),initial_wood);
	findSelected($('styleselector'),initial_style);
	//styleOnChange();
	findSelected($('panelselector'),initial_panel);
	findSelected($('stileRailselector'),initial_stile);
	findSelected($('edgeselector'),initial_edge);
	$('TopRail').value = initial_top;
	$('BottomRail').value = initial_bottom;
	$('LeftStile').value = initial_left;
	$('RightStile').value = initial_right;
	$('SBS').value = initial_sbs;
	$('DBL').value = initial_dbl;
}

function swapImage(selObj) {
	var img = $(selObj.name);
	if (selObj.value != '')
		img.src = public_site + "images/previews/" + selObj.name + "/" + selObj.value + ".jpg";
	else
		img.src = public_site + "images/previews/" + selObj.name + "/default_image.jpg";

}
function whatOnChange() {

	if(document.getElementById("whatselector").options[0].text == "--select--") {
		document.getElementById("whatselector").remove(0)
	}
	getWoods();
	getStyles();
	getStileAndRail();

	$("LeftStileBox").style.display = 'inline';
	$("RightStileBox").style.display = 'inline';
	$("SBSBox").style.display = 'inline';
	$("DBLBox").style.display = 'inline';
	$('stilerailboxmessage').innerHTML="";
	//set each of the stiles and rails and the sbs and dbls to the default of 2 1/2
	$('TopRail').value="2 1/2";
	$('BottomRail').value="2 1/2";
	$('LeftStile').value="2 1/2";
	$('RightStile').value="2 1/2";
	$('SBS').value="2 1/2";
	$('DBL').value="2 1/2";
	if($("whatselector").options[$("whatselector").selectedIndex].text == "Breadboard") {
		//that means that we need to get rid of the stile options and show only top and bottom rail options
		$("LeftStileBox").style.display = 'none';
		$("RightStileBox").style.display = 'none';
		$("SBSBox").style.display = 'none';
		$("DBLBox").style.display = 'none';
		$('LeftStile').value=0;
		$('RightStile').value=0;
		$('SBS').value=0;
		$('DBL').value=0;
		$('stilerailboxmessage').innerHTML="<br /><div align=center>A Breadboard always has a Maple panel, but the top and bottom rails will be of whatever woodtype you select above</div>";
	}
	if (perp_grain[$('whatselector').value] == true) {
		if (typeof(valid) != 'undefined')
			valid.useJS('width_height_explain.html');
	}
	styleOnChange();
}
function styleOnChange() {
	if ($('whatselector').value == 8 || $('whatselector').value == 11 || $('whatselector').value == 12 || ($('whatselector').value >= 15 && $('whatselector').value <= 17 || $('whatselector').value == 22))
		$("stilerailbox").style.display = 'none';
	else {
		$("stilerailbox").style.display = 'inline';
	}

}
function srOnChange() {
	if ($('styleselector').value == 18) {
	initial_edge = $('edgeselector').value;
	getEdges();
	switch ($('stileRailselector').value) {
		case '8':
		case '9':
		case '15':
		case '17':
			$("stilerailbox").style.display = 'none';
			break;
		case '10':
		case '13':
			$('LeftStile').value= DEFAULT_WIDTH_STILES_AND_RAILS_202;
			$('RightStile').value= DEFAULT_WIDTH_STILES_AND_RAILS_202;
			$('TopRail').value= DEFAULT_WIDTH_STILES_AND_RAILS_202;
			$('BottomRail').value= DEFAULT_WIDTH_STILES_AND_RAILS_202;
			$('SBS').value="";
			$('DBL').value="";
			$("SBSBox").style.display = 'none';
			$("DBLBox").style.display = 'none';
			$("stilerailbox").style.display = 'inline';
			break;
		case '11':
			$("stilerailbox").style.display = 'none';
			$('LeftStile').value= DEFAULT_WIDTH_STILES_AND_RAILS_203;
			$('RightStile').value= DEFAULT_WIDTH_STILES_AND_RAILS_203;
			$('TopRail').value= DEFAULT_WIDTH_STILES_AND_RAILS_203;
			$('BottomRail').value= DEFAULT_WIDTH_STILES_AND_RAILS_203;
			$('SBS').value="";
			$('DBL').value="";
			break;
		case '12':
		case '16':
			$("stilerailbox").style.display = 'none';
			$('LeftStile').value= DEFAULT_WIDTH_STILES_AND_RAILS_204;
			$('RightStile').value= DEFAULT_WIDTH_STILES_AND_RAILS_204;
			$('TopRail').value= DEFAULT_WIDTH_STILES_AND_RAILS_204;
			$('BottomRail').value= DEFAULT_WIDTH_STILES_AND_RAILS_204;
			$('SBS').value="";
			$('DBL').value="";
			break;
		default:
			$('LeftStile').value="2 1/2";
			$('RightStile').value="2 1/2";
			$('TopRail').value="2 1/2";
			$('BottomRail').value="2 1/2";
			$('SBS').value="2 1/2";
			$('DBL').value="2 1/2";
			$("stilerailbox").style.display = 'inline';
			$("SBSBox").style.display = 'inline';
			$("DBLBox").style.display = 'inline';
			break;
	}
	}
}
function callInProgress (xmlhttp) {
	switch (xmlhttp.readyState) {
		case 1: case 2: case 3:
			return true;
			break;
		// Case 4 and 0
		default:
			return false;
			break;
	}
}

function getWoods() {
	wreturnto = 'woodselector';
	$(wreturnto).disabled = true;
	if ($('whatselector').value != '') {
		$(wreturnto).style.background = 'url(images/loading.gif) no-repeat center';
		var url = 'dynamic_list.php';
		var WoodAjax = new Ajax.Request( url, {
			method: 'post',
			parameters: {action: 'getWoods', what: $('whatselector').value, initial: initial_wood, field: wreturnto},
			onSuccess: function(Response) {
				$(wreturnto).style.background = '';
				$(wreturnto).disabled = false;
				$(wreturnto).replace(Response.responseText);
				if (initial_wood) {
					$(wreturnto).value = initial_wood;
					$(wreturnto).onchange();
				}
				swapImage($(wreturnto));
				getPanels();
				getPricingData();

			}
		});
	}
}
function getStyles() {
	sreturnto = 'styleselector';
	$(sreturnto).disabled = true;
	if ($('whatselector').value != '') {
		$(sreturnto).style.background = 'url(images/loading.gif) no-repeat center';
		var url = 'dynamic_list.php';
		var StyleAjax = new Ajax.Request( url, {
			method: 'post',
			parameters: {action: 'getStyles', what: $('whatselector').value, field: sreturnto},
			onSuccess: function(Response) {
				$(sreturnto).style.background = '';
				$(sreturnto).disabled = false;
				$(sreturnto).replace(Response.responseText);
				if (initial_style) {
					$(sreturnto).value = initial_style;
					$(sreturnto).onchange();
				}
				swapImage($(sreturnto));
				getEdges();
				getPricingData();
			}
		});
	}
}
function getStileAndRail() {
	srreturnto = 'stileRailselector';
	$(srreturnto).disabled = true;
	if ($('whatselector').value != '') {
		$(srreturnto).style.background = 'url(images/loading.gif) no-repeat center';
		var url = 'dynamic_list.php';
		var StileAjax = new Ajax.Request( url, {
			method: 'post',
			parameters: {action: 'getStile', what: $('whatselector').value, panel: $('panelselector').value, field: srreturnto},
			onSuccess: function(Response) {
				$(srreturnto).style.background = '';
				$(srreturnto).disabled = false;
				$(srreturnto).replace(Response.responseText);
				if (initial_stile) {
					$(srreturnto).value = initial_stile;
					$(srreturnto).onchange();
				}
				swapImage($(srreturnto));
				getPricingData();
			}
		});
	}
}
function getPanels() {
	returnto = 'panelselector';
	$(returnto).disabled = true;
	if ($('woodselector').value != '') {
		$(returnto).style.background = 'url(images/loading.gif) no-repeat center';
		var url = 'dynamic_list.php';
		var myAjax = new Ajax.Request( url, {
			method: 'post',
			parameters: {action: 'getPanels', what: $('whatselector').value, wood: $('woodselector').value, field: returnto},
			onSuccess: function(Response) {
				$(returnto).style.background = '';
				$(returnto).disabled = false;
				$(returnto).replace(Response.responseText);
				if (initial_panel) {
					$(returnto).value = initial_panel;
					$(returnto).onchange();
				}
				swapImage($(returnto));
				getPricingData();
			}
		});
	}
}
function getEdges() {
	ereturnto = 'edgeselector';
	$(ereturnto).disabled = true;
	if ($('styleselector').value != '') {
		$(ereturnto).style.background = 'url(images/loading.gif) no-repeat center';
		var url = 'dynamic_list.php';
		var EdgeAjax = new Ajax.Request( url, {
			method: 'post',
			parameters: {action: 'getEdges', what: $('whatselector').value, style: $('styleselector').value, sr: $('stileRailselector').value, field: ereturnto},
			onSuccess: function(Response) {
				$(ereturnto).style.background = '';
				$(ereturnto).disabled = false;
				$(ereturnto).replace(Response.responseText);
				if (initial_edge) {
					$(ereturnto).value = initial_edge;
				}
				swapImage($(ereturnto));
				getPricingData();
			}
		});
	}
}
var oldParams = new Hash();
var PriceAjax;
function getPricingData() {
	var groupDoesHaveAnItem = false;
	if($('whatselector').value != '' &&
	$('woodselector').value != '' &&
	$('styleselector').value != '' &&
	$('panelselector').value != '' &&
	$('stileRailselector').value != '' &&
	$('edgeselector').value != '') {
		var params = new Hash({
			what: $('whatselector').value,
			wood: $('woodselector').value,
			style: $('styleselector').value,
			panel: $('panelselector').value,
			stileandrail: $('stileRailselector').value,
			edge: $('edgeselector').value,
			toprail: $('TopRail').value,
			bottomrail: $('BottomRail').value,
			leftstile: $('LeftStile').value,
			rightstile: $('RightStile').value,
			sbs: $('SBS').value,
			dbl: $('DBL').value
		});
		var i=0;
		for (i=0;i<30;i++)
		{
			if($('qty'+i).value > 0 &&
			$('width'+i).value.length > 0 &&
			$('length'+i).value.length > 0 ) {
				params['qty'+i] = $('qty'+i).value;
				params['width'+i] = $('width'+i).value;
				params['length'+i] = $('length'+i).value;
				params['wide'+i] = $('wide'+i).value;
				params['long'+i] = $('long'+i).value;
				$('priceEach'+i).style.background = "#F0E8D7 url(images/loading.gif) no-repeat center";
				groupDoesHaveAnItem = true;
			}
		}
		if(params != oldParams && groupDoesHaveAnItem) {
			getRidOfOldPrices();
			var url = 'cuts_ajax_populate.php';
			if (PriceAjax)
				if (callInProgress(PriceAjax.transport))
					PriceAjax.transport.abort();
			PriceAjax = new Ajax.Request( url, {
				method: 'post',
				parameters: params,
				onSuccess: showPricingData
			});
			$('groupPrice').style.background = "#F0E8D7 url(images/loading.gif) no-repeat center";
			oldParams = params;
/*			params.each(function(pair) {
			alert(pair.key + ' = "' + pair.value + '"');
			});
*/
		}
	}
	else
		getRidOfOldPrices();
}
function getRidOfOldPrices()
{
	//get rid of the old prices
	$('groupPrice').value = "";
	for (i=0;i<30;i++)
	{
		$('priceEach'+i).value = "";
	}
}
function showPricingData(response)
{
	var formObj = document.forms['form1'];
	eval(response.responseText);
	//get rid of the loading arrows for everything
	$('groupPrice').style.backgroundImage = "";
	for (i=0;i<30;i++)
	{
		$('priceEach'+i).style.backgroundImage = "";
	}
}
function validateAll() {
	for (i=0;i<30;i++) {
		if($('qty'+i).value > 0)
			if (validateQty($('qty'+i).value,'qty'+i) == false)
				return false;
		if ($('width'+i).value.length > 0)
			if (validatePanelWidth($('width'+i).value,'width'+i) == false)
				return false;
		if($('length'+i).value.length > 0)
			if (validatePanelLength($('length'+i).value,'length'+i) == false)
				return false;
	}
	return true;
}
function validateNumber(fieldvalue, elID) {
	var filter = new RegExp('^([0-9]{0,3}(\\s?[0-9]{1,2}\\/[0-9]{1,2})?|[0-9]{0,3}\\.[0-9]{1,5})?$');
	if (filter.test(fieldvalue)  || (!fieldvalue)) {
		if (Number(fracToDec(fieldvalue)) > MAX_WIDTH_LENGTH) {
			alert(MAX_WIDTH_LENGTH+'" is the maximum length for our products in order to guarantee a structurally sound product.  Please break up this door into sections '+ MAX_WIDTH_LENGTH +'" or smaller or call 1-435-363-4511 for assistance.');
			$(elID).focus()
			$(elID).select()
			return false
		}
		return true//alert('This is a number greater than 0: ' + fracToDec(fieldvalue));
	}
	else {
		alert(fieldvalue + ' is not a valid measurement for ' + elID +': \ncorrect examples: 9, 15 2/3, 1/2, .5');
		$(elID).value = '';
		$(elID).focus();
		$(elID).select();
		return false;
	}
}

/*function validateQty(fieldvalue, elID) {
	if (!isNaN(fieldvalue) && (fieldvalue>0) && (fracToDec(fieldvalue)<99) || (!fieldvalue)) {
	//alert('This is a number greater than 0: ' + fracToDec(fieldvalue));
	}
	else {
		alert(fieldvalue + ' is not a valid quantity for ' + elID )
		$(elID).value = '';
		$(elID).focus()
		$(elID).select()
	}
}*/
function validatePanelWidth(fieldvalue, elID, wideLong, PanelsWide, panelWidth, orientation) {
	orientation = (typeof orientation == 'undefined') ? 'portrait' : orientation;
	if($('whatselector').value == 2 || $('whatselector').value == 16 || $('whatselector').value == 17) {
		panelWidth = Number(fracToDec(fieldvalue)) + BREADBOARD_SLAB_DRAWERFRONT_AND_DOOR_OVERAGE_WIDTH;
		if(panelWidth > MAX_PANEL_WIDTH_SLABS_BREADBOARD_SLABROUTED_TOP) {
			alert('this '+$('whatselector').options[$('whatselector').selectedIndex].text+' is too wide, the maximum panel width for this type of item is ' + MAX_PANEL_WIDTH_SLABS_BREADBOARD_SLABROUTED_TOP+'", this item\'s panel width would be ' + panelWidth+'"')
			$(elID).value = "";
			$(elID).focus();
			return false;
		}
	}
	var WidthMinimum = Math.round((PanelsWide * (MINIMUM_PANEL_WIDTH + PANEL_UNDERAGE_FOR_ALLOWANCE_FOR_SPACEBALLS) + fracToDec($("LeftStile").value) - STILE_AND_RAIL_CUT_DEPTH + fracToDec($("RightStile").value) - STILE_AND_RAIL_CUT_DEPTH + (fracToDec($("SBS").value) - STILE_AND_RAIL_CUT_DEPTH * 2) * (PanelsWide-1))*1000)/1000;
	//end Panel width
	if(panelWidth < MINIMUM_PANEL_WIDTH) {
		var varand = "";
		if(orientation == 'landscape') {
			if(PanelsWide > 1)
				varand = "and doubles ";
			alert("This door is impossible to build.  You have several options: \n1. Order the door at a longer size. \n(With the currently selected rails " + varand + "you would need at height of at least " + WidthMinimum + ")  \n2.  Order the door in a different group with narrower rails.  \n3. Order this door as a slab \nOr for further assistance call 1-435-363-4511.\n(The panel width for this door would be : " + panelWidth + " it needs to be at least "+MINIMUM_PANEL_WIDTH+")");
		}
		else {
			if(PanelsWide > 1)
				varand = "and side by sides ";
			alert("This door is impossible to build.  You have several options: \n1. Order the door at a wider size. \n(With the currently selected stiles " + varand + "you would need at width of at least " + WidthMinimum + ")  \n2.  Order the door in a different group with narrower stiles.  \n3. Order this door as a slab \nOr for further assistance call 1-435-363-4511.\n(The panel width for this door would be : " + panelWidth + " it needs to be at least "+MINIMUM_PANEL_WIDTH+")");
		}
		$(elID).focus();
		$(elID).value = "";
		return false;
	}
	else if(panelWidth < MINIMUM_PANEL_WIDTH_BEFORE_FLAT_PANEL) {
		alert("The current panel width for this door would be : " + panelWidth + "\nBecause it has a panel width of under 4 inches, this door will be built with a flat panel in order to be correct. \nplease call us at 1-435-363-4511 if you have any questions");
	}
	else if(($("stileRailselector").value >= 8 && $("stileRailselector").value <= 13) || ($("stileRailselector").value >=15 && $("stileRailselector").value <= 17)) {
		//things to do if its a 200 series stile and rail
		if(panelWidth > MAX_PANEL_WIDTH_200_SERIES) {
			alert('This door is IMPOSSIBLE TO BUILD.  The maximum panel width of a door with a 200 series stile and rail is '+ MAX_PANEL_WIDTH_200_SERIES +'".  This door\'s panel width would be ' + panelWidth)
			$(elID).focus();
			$(elID).value = "";
			return false;

		}
		else if(panelWidth > MAX_PANEL_WIDTH_BEFORE_SBS) {
			alert('This door WILL NOT BE UNDER WARRANTY.  The maximum panel width of a door with a 200 series stile and rail that we can warranty is '+ MAX_PANEL_WIDTH_BEFORE_SBS +'".  This door\'s panel width would be ' + panelWidth)
		}
	}
	else if(panelWidth > MAX_PANEL_WIDTH_BEFORE_SBS && !($('whatselector').value == 2 || $('whatselector').value == 16 || $('whatselector').value == 17) && !wideLong)
		alert('Notice: This door will be split by side by sides. Panel Width = '+panelWidth);
	return true;
}
function validateWidth(fieldvalue, elID, wideLong) {
	if (typeof wideLong == 'undefined') wideLong = false;
	var panelWidth = 0;
	if(validateNumber(fieldvalue, elID) && fieldvalue != "") {
		if ($('whatselector').value == 16 || $('whatselector').value == 17) {
			return true;
		}
		if($("panelselector").value == 1 && $('whatselector').value != 9 && $('whatselector').value != 10) // that means that there is no panel
				return true;
		var PanelsWide = 1;//start by assuming that there is just 1 panel wide
		//if they typed something in whe wide field
		if($("wide" + elID.replace(/width/,"")).value != "") {
			if((($("stileRailselector").value >= 8 && $("stileRailselector").value <= 13) || ($("stileRailselector").value >=15 && $("stileRailselector").value <= 17)) && $("wide" + elID.replace(/width/,"")).value != '1') {
				alert("200 series stile and rail doors can not have more than 1 panel");
				$("wide" + elID.replace(/width/,"")).value = "";
				return false;
			}
			//then make panels wide equal to what they typed in
			PanelsWide = $("wide" + elID.replace(/width/,"")).value;
		}
		panelWidth = (((Number(fracToDec(fieldvalue)) - fracToDec($("LeftStile").value) + STILE_AND_RAIL_CUT_DEPTH - fracToDec($("RightStile").value) + STILE_AND_RAIL_CUT_DEPTH - ((fracToDec($("SBS").value) - STILE_AND_RAIL_CUT_DEPTH * 2) * (PanelsWide-1)))  / PanelsWide)  - PANEL_UNDERAGE_FOR_ALLOWANCE_FOR_SPACEBALLS);
		if ($('whatselector').value == 6 || $('whatselector').value == 7) //perpendicular products are flipped
			return validatePanelLength(fieldvalue, elID, wideLong, PanelsWide, panelWidth, 'landscape');
		else
			return validatePanelWidth(fieldvalue, elID, wideLong, PanelsWide, panelWidth);
	}
}
function validateHeight(fieldvalue, elID, wideLong) {
	if (typeof wideLong == 'undefined') wideLong = false;
	var panelLength = 0;
	if(validateNumber(fieldvalue, elID) && fieldvalue != "") {
		// Panel Length
		if($("panelselector").value == 1 && $('whatselector').value != 9 && $('whatselector').value != 10) // that means that there is no panel
			return true;
		var PanelsLong = 1;//start by assuming that there is just 1 panel long
		//if they typed something in whe long field
		if($("long" + elID.replace(/length/,"")).value != "") {
			if((($("stileRailselector").value >= 8 && $("stileRailselector").value <= 13) || ($("stileRailselector").value >=15 && $("stileRailselector").value <= 17)) && $("long" + elID.replace(/length/,"")).value != '1') {
				alert("200 series stile and rail doors can not have more than 1 panel");
				$("long" + elID.replace(/length/,"")).value = "";
				return false;
			}

			//then make panels long equal to what they typed in
			PanelsLong = $("long" + elID.replace(/length/,"")).value;
		}
		if($('whatselector').value == 2 || $('whatselector').value == 16 || $('whatselector').value == 17) {
			panelLength = Number(fracToDec(fieldvalue)) + BREADBOARD_SLAB_DRAWERFRONT_AND_DOOR_OVERAGE_LENGTH;
		}
		else {
			panelLength = (((Number(fracToDec(fieldvalue)) - fracToDec($("TopRail").value) + STILE_AND_RAIL_CUT_DEPTH - fracToDec($("BottomRail").value) + STILE_AND_RAIL_CUT_DEPTH - ((fracToDec($("DBL").value) - STILE_AND_RAIL_CUT_DEPTH * 2) * (PanelsLong-1)))  / PanelsLong)  - PANEL_UNDERAGE_FOR_ALLOWANCE_FOR_SPACEBALLS);
		}
		if ($('whatselector').value == 6 || $('whatselector').value == 7) //perpendicular products are flipped
			return validatePanelWidth(fieldvalue, elID, wideLong, PanelsLong, panelLength,'landscape');
		else
			return validatePanelLength(fieldvalue, elID, wideLong, PanelsLong, panelLength);
	}

}
function validatePanelLength(fieldvalue, elID, wideLong, PanelsLong, panelLength, orientation) {
	orientation = (typeof orientation == 'undefined') ? 'portrait' : orientation;
	if($('whatselector').value == 16 || $('whatselector').value == 17) {
		panelWidth = Number(fracToDec(fieldvalue)) + BREADBOARD_SLAB_DRAWERFRONT_AND_DOOR_OVERAGE_WIDTH;
		if(panelWidth > MAX_PANEL_WIDTH_SLABS_BREADBOARD_SLABROUTED_TOP) {
			alert('this '+$('whatselector').options[$('whatselector').selectedIndex].text+' is too tall, the maximum panel height for this type of item is ' + MAX_PANEL_WIDTH_SLABS_BREADBOARD_SLABROUTED_TOP+'", this item\'s panel height would be ' + panelWidth+'"')
			$(elID).value = "";
			$(elID).focus();
			return false;
		}
	}

	var LengthMinimum = Math.round((PanelsLong * (MINIMUM_PANEL_LENGTH + PANEL_UNDERAGE_FOR_ALLOWANCE_FOR_SPACEBALLS) + fracToDec($("TopRail").value) - STILE_AND_RAIL_CUT_DEPTH + fracToDec($("BottomRail").value) - STILE_AND_RAIL_CUT_DEPTH + (fracToDec($("DBL").value) - STILE_AND_RAIL_CUT_DEPTH * 2) * (PanelsLong-1))*1000)/1000;
	//end Panel LENGTH
	if(panelLength < MINIMUM_PANEL_LENGTH) {
		var varand = "";
		if(orientation == 'landscape') {
			if(PanelsLong > 1)
				varand = "and side by sides ";
			alert("This door is impossible to build.  You have several options: \n1. Order the door at a longer size. \n(With the currently selected stiles " + varand + "you would need at length of at least " + LengthMinimum + ")  \n2.  Order the door in a different group with narrower stiles.  \n3. Order this door as a slab \nOr for further assistance call 1-435-363-4511.\n(The panel length for this door would be : " + panelLength + " it needs to be at least "+MINIMUM_PANEL_LENGTH+")");
		}
		else {
			if(PanelsLong > 1)
				varand = "and doubles ";
			alert("This door is impossible to build.  You have several options: \n1. Order the door at a longer size. \n(With the currently selected rails " + varand + "you would need at height of at least " + LengthMinimum + ")  \n2.  Order the door in a different group with narrower rails.  \n3. Order this door as a slab \nOr for further assistance call 1-435-363-4511.\n(The panel length for this door would be : " + panelLength + " it needs to be at least "+MINIMUM_PANEL_LENGTH+")");
		}
		$(elID).focus();
		$(elID).value = "";
		return false;
	}
	else if(panelLength < MINIMUM_PANEL_LENGTH_BEFORE_FLAT_PANEL) {
		alert("The current panel length for this door would be : " + panelLength + "\nBecause it has a panel length of under 4 inches, this door will be built with a flat panel in order to be correct.\nplease call us at 1-435-363-4511 if you have any questions");
	}
	else if(($("stileRailselector").value >= 8 && $("stileRailselector").value <= 13) || ($("stileRailselector").value >=15 && $("stileRailselector").value <= 17)) {
		//things to do if its a 200 series stile and rail
		if(panelLength > MAX_PANEL_LENGTH_BEFORE_DBL) {
			alert('This door WILL NOT BE UNDER WARRANTY.  The maximum panel length of a door with a 200 series stile and rail that we can warranty is '+ MAX_PANEL_LENGTH_BEFORE_DBL +'".  This door\'s panel length would be ' + panelLength);
		}
	}
	else if(panelLength > MAX_PANEL_LENGTH_BEFORE_DBL && !($('whatselector').value == 2 || $('whatselector').value == 16 || $('whatselector').value == 17) && !wideLong)
		alert('Notice: This door will be split by doubles. Panel length= ' + panelLength);
	return true;
}

function validateStileOrRail(fieldvalue, elID)
{
	var returnval = true;
	if (!isNaN(fracToDec(fieldvalue)) && (fracToDec(fieldvalue)>0) || (!fieldvalue)) {
		if($("stileRailselector").value == 10) {
			if (Number(fracToDec(fieldvalue)) > Number(MAX_STILE_RAIL_WIDTH_202)) {
				alert(MAX_STILE_RAIL_WIDTH_202 +'" is the maximum width for a stile, rail, side-by-side or double for style 202.');
				$(elID).focus();
				$(elID).select();
				fieldvalue = MAX_STILE_RAIL_WIDTH_202;
				returnval=false;
			}
			else if (Number(fracToDec(fieldvalue)) < Number(MIN_STILE_RAIL_WIDTH_202)) {
				alert(MIN_STILE_RAIL_WIDTH_202 +'" is the minimum width for a stile, rail, side-by-side or double for style 202.');
				fieldvalue = MIN_STILE_RAIL_WIDTH_202;
				returnval= false;
			}
			if (Number(fracToDec(fieldvalue)) < Number(MIN_STILE_RAIL_WIDTH_202_BEFORE_FORCED_E4) && $('edgeselector').value != 12) {
				alert('With a 202 style, if you have any stile, rail, side by side, or double under '+MIN_STILE_RAIL_WIDTH_202_BEFORE_FORCED_E4 +'", it MUST have an E4 Edge');
				//deleteAllInSelect($("edgeselector"))
				$('edgeselector').value = 12;
				//appendOptionLast('E4' , 'edgeselector')
				returnval= false;
			}
		}
		else if($("stileRailselector").value == 13) {
			if (Number(fracToDec(fieldvalue)) > Number(MAX_STILE_RAIL_WIDTH_202)) {
				alert(MAX_STILE_RAIL_WIDTH_202 +'" is the maximum width for a stile, rail, side-by-side or double for style 205.');
				$(elID).focus();
				$(elID).select();
				fieldvalue = MAX_STILE_RAIL_WIDTH_202;
				returnval=false;
			}
			else if (Number(fracToDec(fieldvalue)) < Number(MIN_STILE_RAIL_WIDTH_202)) {
				alert(MIN_STILE_RAIL_WIDTH_202 +'" is the minimum width for a stile, rail, side-by-side or double for style 205.');
				fieldvalue = MIN_STILE_RAIL_WIDTH_202;
				returnval= false;
			}
			if (Number(fracToDec(fieldvalue)) < Number(MIN_STILE_RAIL_WIDTH_202_BEFORE_FORCED_E4) && $('edgeselector').value != 12) {
				alert('With a 205 style, if you have any stile, rail, side by side, or double under '+MIN_STILE_RAIL_WIDTH_202_BEFORE_FORCED_E4 +'", it MUST have an E4 Edge');
				//deleteAllInSelect($("edgeselector"))
				$('edgeselector').value = 12;
				//appendOptionLast('E4' , 'edgeselector')
				returnval= false;
			}
		}

		else {
			if (Number(fracToDec(fieldvalue)) > MAX_STILE_RAIL_WIDTH_NORMAL) {
				alert(MAX_STILE_RAIL_WIDTH_NORMAL +'" is the maximum width for a stile, rail, side-by-side or double.');
				$(elID).focus();
				$(elID).select();
				fieldvalue = MAX_STILE_RAIL_WIDTH_NORMAL;
				returnval= false;
			}
			else if (Number(fracToDec(fieldvalue)) < MIN_STILE_RAIL_WIDTH_NORMAL) {
				alert(MIN_STILE_RAIL_WIDTH_NORMAL +'" is the minimum width for a stile, rail, side-by-side or double.');
				$(elID).focus();
				$(elID).select();
				fieldvalue = MIN_STILE_RAIL_WIDTH_NORMAL;
				returnval= false;
			}
		}
		//now check if its a miter and if it is make all of these the same
		if($('whatselector').value == 7 || $('whatselector').value == 5) {
			$('TopRail').value=
			$('BottomRail').value=
			$('LeftStile').value=
			$('RightStile').value=
			$('SBS').value=
			$('DBL').value=fieldvalue;
		}//end if
		return returnval//alert('This is a number greater than 0: ' + fracToDec(fieldvalue));
	}
	else {
		alert(fieldvalue + ' is not a valid measurment for ' + elID +': \ncorrect examples: 9, 15 2/3, 0 1/2, .5');
		$(elID).value = '';
		setTimeout("$('"+elID+"').focus();",1);
		setTimeout("$('"+elID+"').select();",1);
		return false;
	}
}

function validateQty(fieldvalue, elID) {
	if (fieldvalue && (isNaN(fieldvalue) || fieldvalue <=0 || fracToDec(fieldvalue) > 99)) {
		alert(fieldvalue + ' is not a valid quantity for ' + elID );
		$(elID).value = '';
		setTimeout("$('"+elID+"').focus();",1);
		setTimeout("$('"+elID+"').select();",1);
	}
	return true;
}
function fracToDec(fieldvalue) {
	if (!isNaN(fieldvalue))
		return fieldvalue;
	var dec = 0;
	var temp = fieldvalue.split("/");
	if (temp.length == 1)
		return fieldvalue;
	var den = temp[1];
	var temp2 = temp[0].split(" ");
	if (temp2.length > 1) {
		var whole = temp2[0];
		var num = temp2[1];
	}
	else {
		var whole = 0;
		var num = temp2[0];
	}
	if (den > 0)
		dec = (num / den);
	return Number(whole) + Number(dec);
}
function validateForm(form) {
	if (form.clear.value == 'ClearingEverything')
			return true;
	var returnfalse = false;
	var isQty = false;
	for (var i = 0; i<30; i++){
		if($('qty'+i).value){
			if(!$('width'+i).value || !$('length'+i).value){
				alert('error on item '+i+': \nMake sure that there is Width and Length everywhere you put a quantity')
				if(!$('width'+i).value){
					$('width'+i).focus()
					$('width'+i).select()
				}
				else if(!$('length'+i).value){
					$('length'+i).focus()
					$('length'+i).select()
				}
				return false
			}
			isQty = true;

		}
	}
	var alertmsg = ''
	if(isQty) {
		if($("whatselector").value == '') {
			alertmsg += '\nPlease select a What';
			form.What.focus()
			returnfalse = true
		}
		if($("woodselector").value == '') {
			alertmsg += '\nPlease select a Wood type';
			returnfalse = true
		}
		if($("styleselector").value == '') {
			alertmsg += '\nPlease select a door style (or \'none\')';
			returnfalse = true
		}
		if($("panelselector").value == '') {
			alertmsg += '\nPlease select a Panel type (or \'none\')';
			returnfalse = true
		}
		if($("stileRailselector").value == '') {
			alertmsg += '\nPlease select a StileAndRail type, (or \'none\')';
			returnfalse = true
		}
		if($("edgeselector").value == '') {
			alertmsg += '\nPlease select an Edge type (or \'none\')';
			returnfalse = true
		}
	}//end if there's something in qty1
	if($('DeliveryArea').value == "To Another Location") {
		if (!$('ship_zip').value) {
			alertmsg += '\nPlease enter a zip in the delivery address';
			$('ship_zip').focus()
			returnfalse = true
		}
		else if(isNaN($('ship_zip').value)) {
			alertmsg += '\nThe Zip code can only contain numbers';
			$('ship_zip').focus()
			$('ship_zip').select()
			returnfalse = true
		}
		if (!$('city').value) {
			alertmsg += '\nPlease enter a City in the delivery address';
			$('city').focus()
			returnfalse = true
		}
		if (!$('street').value) {
			alertmsg += '\nPlease enter a street address to be delivered to';
			$('street').focus()
			returnfalse = true
		}
	}
	if(!$('JobName').value) {
		alertmsg += '\nPlease give this job a name';
		$('JobName').focus()
		$('JobName').select()
		returnfalse = true
	}
	if (returnfalse) {
		alert('The following things are missing or incorrect: \n' + alertmsg)
		return false
	}
	else {
		$("whatselector").disabled=false
		$("woodselector").disabled=false
		$("styleselector").disabled=false
		$("panelselector").disabled=false
		$("stileRailselector").disabled=false
		$("edgeselector").disabled=false
		return true
	}
}
var MAX_DUMP_DEPTH = 10;
function dumpObj(obj, name, indent, depth) {
if (depth > MAX_DUMP_DEPTH) {
	return indent + name + ": <Maximum Depth Reached>\n";
}
if (typeof obj == "object") {
	var child = null;
	var output = indent + name + "\n";
	indent += "\t";
	for (var item in obj) {
		try {
			child = obj[item];
		} catch (e) {
			child = "<Unable to Evaluate>";
		}
		if (typeof child == "object")
			output += dumpObj(child, item, indent, depth + 1);
		else
			output += indent + item + ": " + child + "\n";
	}
	return output;
} else {
	return obj;
}
}
function show_all_job_progress(lcs) {
	var IDtoUpdate = 'jobProgress'+lcs;
	var url = 'ajax_calls.php';
	var myAjax = new Ajax.Request( url, {
		method: 'post',
		parameters: {q: 'show_all_job_progress', lcs: lcs},
		onSuccess: function(Response) {
			$(IDtoUpdate).innerHTML = Response.responseText;
		}
	});
}
function show_latest_job_progress(lcs) {
	var IDtoUpdate = 'jobProgress'+lcs;
	var url = 'ajax_calls.php';
	var myAjax = new Ajax.Request( url, {
		method: 'post',
		parameters: {q:'show_latest_job_progress', lcs: lcs},
		onSuccess: function(Response) {
			$(IDtoUpdate).innerHTML = Response.responseText;
		}
	});
}
function disp_alert() {
	alert("WARNING: \nWhen you manually change the number of panels wide or long, \nYou void the warranty from Lewis Cabinet Specialties. \nAll existing guarantees for our products may be compromised upon a manual change.\n This change may be built unless notified from our offices.")
}
function showAddress(objSel)
{

	var trStreet = $("trStreet");
	var trCity = $("trCity");

	var inpStreet = $("street");
	var inpCity = $("city");
	var inpState = $("state");
	var inpZip = $("ship_zip");

	if(objSel.options[objSel.selectedIndex].text == "To My Shop")
	{
		trStreet.style.display = "";
		trCity.style.display = "";
		inpStreet.value = address;
		inpCity.value = city;
		inpState.value = state;
		inpZip.value = ship_zip;

		inpStreet.disabled = true;
		inpCity.disabled = true;
		inpState.disabled = true;
		inpZip.disabled = true;
	}
	else if(objSel.options[objSel.selectedIndex].text == "Will Call")
	{
		trStreet.style.display = "none";
		trCity.style.display = "none";
		inpStreet.value = "Will Call";
		inpCity.value = "";
		inpState.value = "";
		inpZip.value = "";

		inpStreet.disabled = false;
		inpCity.disabled = false;
		inpState.disabled = false;
		inpZip.disabled = false;
	}
	else
	{
		trStreet.style.display = "none";
		trCity.style.display = "none";
	}
}
var checkAjax;
function checkLCS(lcs) {
	var url = 'ajax_calls.php';
	if (checkAjax)
		if (callInProgress(checkAjax.transport))
			checkAjax.transport.abort();
	if (lcs.value > 9000) {
		checkAjax = new Ajax.Request( url, {
			method: 'post',
			parameters: {q:'checkLCS', lcs: lcs.value},
			onSuccess: function(Response) {
				lcs.style.backgroundImage = "";
				if (Response.responseText == 'true')
					$('sidebar').submit();
				else
					$('isValidLCSErrorMessage').innerHTML = "invalid LCS#";
			}
		});
		lcs.style.background = "#F0E8D7 url(images/loading.gif) no-repeat center";
	}
}
function showPayBox(box) {
	$$('.paybox').each(function(s) {
		s.style.display = 'none';
	});
	if (box)
		$(box).style.display = 'block';
}
