
function reCalcQuote()
{
	displayArea();
	var totalDiv = this.document.getElementById("totalDiv");
	var cost = byoTable.getCost();
	if (byoTable.wireGuides)
		totalDiv.innerHTML = 'CALL 888-900-5235 FOR QUOTE.  (Sorry, we are not able to estimate wire guides online.)<br>Or you may send us an email <a href="http://www.erikorganic.com/Contact_Us_s/56.htm">here</a>';
	else if (cost > 0)
		totalDiv.innerHTML = byoTable.getCostDescription();
	else if (cost.length > 0)
		return cost;
	else
		totalDiv.innerHTML = "";
		
	if (byoTable.getSkirt() == 2 ) // && byoTable.length > 41 && byoTable.width > 41)
	{
		var leafInputDiv = this.document.getElementById("leafInputDiv");
		leafInputDiv.style.visibility = 'visible'; 
		var noLeafDiv = this.document.getElementById("noLeafDiv");
		noLeafDiv.style.visibility = 'hidden';
	}
	else
	{
		var leafInputDiv = this.document.getElementById("leafInputDiv");
		leafInputDiv.style.visibility = 'hidden';
		var noLeafDiv = this.document.getElementById("noLeafDiv");
		noLeafDiv.style.visibility = 'visible';
	}
	
	var leafWarning  = this.document.getElementById("leafWarning");
	if (byoTable.length > 0)
	{
		var leafLength = (byoTable.leaves[12] * 12 ) +  (18 * byoTable.leaves[18]);
		var lenLim = .8 * byoTable.length;
		if (leafLength > lenLim)
		{
			leafWarning.innerHTML = '<b>NOTE: You may not be able to use all of these leaves at the same time. Please see the section on table leaves in the <a href="http://www.erikorganic.com/Guide_to_Office_Furniture_s/250.htm#linktoleaves">Guide to Office Furniture</a> for more details.</b>';
			
			//The total length of leaves in use may not exceed' + lenLim.toFixed(2) + ' inches for this table.';
		}
		else
		{
			leafWarning.innerHTML = '';
		}
	}
	else
	{
		leafWarning.innerHTML = '';
	}
		
	var descripElement = this.document.getElementById("eoProductDescription");
	descripElement.innerHTML = byoTable.getDescription();
	
	this.document.eoProductForm.weight.value = byoTable.getWeight();
	this.document.eoProductForm.price.value = byoTable.getCost();
	
	this.document.eoProductForm.shippingCost.value = byoTable.getShippingCost();
	var shipElement = this.document.getElementById("shippingDiv");
	shipElement.innerHTML = byoTable.getShippingDescription();
	
	

	/*
	var addButton = this.document.getElementById("googleAddButton");
	if (byoTable.isComplete())
	{
		addButton.style.visibility = 'hidden';
	}
	else
	{
		addButton.style.visibility = 'visible';
	}
	*/
}

function displayArea()
{
	var areaDiv = this.document.getElementById("areaDiv");
	var tableArea = byoTable.getArea();
	if (tableArea > 0)
		areaDiv.innerHTML = tableArea + " sq in.";
	else
		areaDiv.innerHTML = "";
}

function getTableOpts()
{
	var customF = this.document.eoProductForm;
	var skirtSelector = customF.eoOptionSkirt;
	var topSelect = customF.eoOptionTableTop;
	var woodSelect = customF.eoOptionWood;
	var edgeSelect = customF.eoOptionTableEdge;
	var thicknessSelect = customF.eoOptionThickness;
	var finishSelect = customF.eoOptionFinish;
	var shippingTypeSelect = customF.eoOptionShippingType;
	
	var skirts = byoTable.getSkirts();
	var skirtDesc = byoTable.getSkirtDescriptions();
	var skirt = byoTable.getSkirt();
	fillTheSelect(skirtSelector,skirts,skirtDesc, skirt)

	var tops = byoTable.getTableTops();
	var top = byoTable.getTableTop();
	fillTheSelect(topSelect,tops, tops, top);
	
	var woods = byoTable.getWoodTypeOptions();
	var wood = byoTable.getWoodType();
	fillTheSelect(woodSelect, woods, woods, wood);
	
	var finishes = byoTable.getFinishOptions();
	var finish = byoTable.getFinish();
	if (finishSelect != null)
	{
		fillTheSelect(finishSelect, finishes, finishes, finish);
	}
	
	var edges = byoTable.getEdgeOptions();
	var edge = byoTable.getEdge();
	fillTheSelect(edgeSelect, edges, edges, edge);
	
	var thicknesses = byoTable.getThicknesses();
	var thickness = byoTable.getThickness();
	fillTheSelect(thicknessSelect, thicknesses, thicknesses, thickness);
	
	var shippingTypes = byoTable.getShippingTypeOptions();
	var shippingType = byoTable.getShippingType();
	fillTheSelect(shippingTypeSelect, shippingTypes, shippingTypes, shippingType);
}

function initTableOpts(tableWrapper)
{
	getTableDesignMenu(tableWrapper);
	var customF = this.document.eoProductForm;

	customF.eoOptionLength.value = tableWrapper.table.length;	
	customF.eoOptionWidth.value = tableWrapper.table.width;	
	customF.eoOptionHeight.value = tableWrapper.table.height;
	refresh();
}


function getTableDesignMenu(table)
{
	var customF = this.document.eoProductForm;
	var designSelect = customF.designMenu;
	var designs = table.getDesigns();
	var style = table.getStyle();
	fillTheSelect(designSelect, designs, designs, style);
}

function fillTheSelect(theSelect,values, desc, defaultVal) {
	if (values == null || values.length == null || theSelect.options == null) return;
	
	theSelect.options.length = 0;
	var select =  0;
	for(var i=0; i < values.length; i++) {
		theSelect.options[theSelect.options.length] = new Option(desc[i], values[i]);
		theSelect.options[theSelect.options.length - 1].innerHTML = desc[i];
		if (values[i] == defaultVal)
		{
			select = i;
		}
	}
	if (theSelect.options.length < 1) return;
	theSelect.options[select].selected = true;

}

function set(prod, attr, element)
{
		this.document.getElementById("bodyveil").style.zIndex = 5;
		eval('prod.set' + attr + '(element)');
		refresh();
		this.document.getElementById("bodyveil").style.zIndex = -5;
}

function refresh()
{
	changePic("Table", byoTable.getStyle());
	changePic("Edge", byoTable.getEdge());
	changePic("Top", byoTable.getTableTop());
	//changePic("Stain", byoTable.getStain());
	//var zipCode = this.document.eoProductForm.eoOptionZipCode.value;
	//getMiles(zipCode, byoTable);
	//var distance = this.document.eoProductForm.eoOptionDistance.value;
	//byoTable.setDistance(distance);
	getTableOpts();
	var customF = this.document.eoProductForm;
	customF.eoOptionLength.value = byoTable.table.length;	
	customF.eoOptionWidth.value = byoTable.table.width;	
	customF.eoOptionHeight.value = byoTable.table.height;

	reCalcQuote();
	
	
}

function changePic(type, design)
{
	//alert(design);
	var compressed = design.replace(/ /g,"").replace(/\//g,"")
						   .replace(/&deg;/g,"").replace(/&quot;/g,"");
	//alert(compressed);
	var style_photo = document.getElementById(type.toLowerCase() + "_photo");
	style_photo.src = "/dining-room/img/" + type + compressed + ".jpg"
}
