///////////////////////////////////////////////////////////////////////////////////////   
//This code selects a screen that roughly matches the budget the user has input   
///////////////////////////////////////////////////////////////////////////////////////
function BudgetChange(result)
	{
	if(result == 3.14159)
		{
		result = Number(document.forms['EstimateInputs'].elements['TotalBill'].value)
		document.forms['EstimateInputs'].elements['QtyScreens'].value = 1
		document.forms['EstimateInputs'].elements['MountingMethod'].value = 'HooksHinges'
		document.forms['EstimateInputs'].elements['TrackLength'].value = '0'
		document.forms['EstimateInputs'].elements['TrackQty'].value = '0'
		document.forms['EstimateInputs'].elements['Delivery'].value = 'PickUp'
		document.forms['EstimateInputs'].elements['InstallationMethod'].value = 'SelfInstall'
		document.forms['EstimateInputs'].elements['AddrState'].value = "WA"
		document.forms['EstimateInputs'].elements['WoodType'].value = 'DouglassFir'
		document.forms['EstimateInputs'].elements['Finish'].value = 'Natural'
		document.forms['EstimateInputs'].elements['Facing'].value = 'SingleSided'
	
		if(result <= 250)
  			{
			document.forms['EstimateInputs'].elements['ScreenHeight'].value = '12'
			document.forms['EstimateInputs'].elements['ScreenWidth'].value = '12'
 			document.forms['EstimateInputs'].elements['NumVertKmko'].value = '0'
			document.forms['EstimateInputs'].elements['NumHrzKmko'].value = '0'
  			result = 235.76
  			}
 
   	if(result >250 && result <=350)
  			{
			document.forms['EstimateInputs'].elements['ScreenHeight'].value = '48'
			document.forms['EstimateInputs'].elements['ScreenWidth'].value = '24' 
 			document.forms['EstimateInputs'].elements['NumVertKmko'].value = '1'
			document.forms['EstimateInputs'].elements['NumHrzKmko'].value = '1'
  			result = 308.70
  			}
  
   	if(result >350 && result <=450)
  			{
			document.forms['EstimateInputs'].elements['ScreenHeight'].value = '72'
			document.forms['EstimateInputs'].elements['ScreenWidth'].value = '36' 
 			document.forms['EstimateInputs'].elements['NumVertKmko'].value = '2'
			document.forms['EstimateInputs'].elements['NumHrzKmko'].value = '5'
			document.forms['EstimateInputs'].elements['WoodType'].value = 'Cherry'		  	
  			result = 439.94
  			}

   	if(result >450 && result <=550)
  			{
  			document.forms['EstimateInputs'].elements['QtyScreens'].value = '2'
			document.forms['EstimateInputs'].elements['ScreenHeight'].value = '48'
			document.forms['EstimateInputs'].elements['ScreenWidth'].value = '24' 
 			document.forms['EstimateInputs'].elements['NumVertKmko'].value = '3'
			document.forms['EstimateInputs'].elements['NumHrzKmko'].value = '5'
  			result = 532.40
  			}
 
   	if(result >550 && result <=700)
  		{
    		document.forms['EstimateInputs'].elements['QtyScreens'].value = '3'
			document.forms['EstimateInputs'].elements['ScreenHeight'].value = '48'
			document.forms['EstimateInputs'].elements['ScreenWidth'].value = '24' 
 			document.forms['EstimateInputs'].elements['NumVertKmko'].value = '1'
			document.forms['EstimateInputs'].elements['NumHrzKmko'].value = '3'	
			result = 692.16
  		}

 		if(result > 700)
 			{
 			alert("You have many options at that budget level, adjust the parameters according to your project.")
 			document.forms['EstimateInputs'].elements['QtyScreens'].value = '4'
			document.forms['EstimateInputs'].elements['ScreenHeight'].value = '48'
			document.forms['EstimateInputs'].elements['ScreenWidth'].value = '24' 
 			document.forms['EstimateInputs'].elements['NumVertKmko'].value = '2'
			document.forms['EstimateInputs'].elements['NumHrzKmko'].value = '5'	
  			result = 921.79
			}

		result = String(result)
		document.forms['EstimateInputs'].elements['TotalBill'].value=result
		}
		ScreenCost()
	}

///////////////////////////////////////////////////////////////////////////////////////   
//This code adjusts the budget total based on a change of any of the parameters   
///////////////////////////////////////////////////////////////////////////////////////
function ScreenCost() 
{
BeenSaved('NeedsSaving') //go switch the status of the save buttons

//MATERIAL COST CONSTANTS (represent non-taxed)
var cnsFirWoodCost = 0.495/12
var cnsPineWoodCost = 0.495/12
var cnsPopWoodCost = 0.865/12
var cnsOakWoodCost = .992/12
var cnsMapleWoodCost = 1.81/12
var cnsCherryWoodCost = 2.16/12
var cnsFoamBrush = 0.67 
var cnsCanStain = 4.00 
var cnsCanPreCond = 4.00
var cnsCanPoly = 5.36
var cnsTackCloth = .98 
var cnsSandPaper220 = .4
var cnsSawBlade = 13.00
cnsSawBlade = cnsSawBlade * .01
var cnsWoodGlue = 3.98
cnsWoodGlue = cnsWoodGlue * .1
var cnsAcrylicMatt = 12.84 
cnsAcrylicMatt = cnsAcrylicMatt * .1
var cnsDropCloth = 16.00
cnsDropCloth = cnsDropCloth*.0625
var cnsRollersDN50CF = 30.59 
var cnsU45AL6pt5ft = 45.00//Price reflects the aluminum Facia. This should be replaced by the actuall AL Facia cost
var cnsU45AL9pt85ft = 72.77//This becomes inaccurate for more than (2) tracks
var cnsHingesHooks = 5.00
var cnsWarlonPaper = 72.10

//MULTIPLIERS
var cnsWaTax = .08808933
var cnsWoodFaciaMltplr = 7.0//Each facia is twice a 1x2 and there are 2 facia's and a header that is 3 times a 1x2
var cnsKickBoardMltplr = 3.0//A 5.5inch kickboard is an additional 4" of width of raw material (4" ~ 3 times a 1x2)
var cnsPaperBulk = 0.9//ten percent off a bulk order of paper
var cnsKmkoPer1by2 = 3.0

//DESIGN CONSTANTS
var cnsKickBoardTrip = 71.0
var cnsPaperHeight = 72.5
var cnsPaperWidth = 36.5
var cnsKickBoardWd = 5.5
var cnsFrameStockWd = 1.5
var cnsPackingFactor = 0.5

//LABOR COST CONSTANTS
var cnsLaborRate = 12//Dollars an hour
var cnsBilling = 50-cnsLaborRate//Dollars an hour
cnsLaborRate = cnsLaborRate/60//Dollars per minute
cnsBilling = cnsBilling/60//Dollars per minute

//LABOR STANDARDS IN MINUTES
var cnsDesignSetUp = 61.0
var cnsFrameCut = 10.0
var cnsFrameSand = 7.0
var cnsFrameMaskStain = 7.0
var cnsFramePrecondition = 9.0
var cnsFrameStain = 10.0
var cnsFramePoly1 = 7.0
var cnsFramePoly2 = 13.0
var cnsFrameGlueAssemble = 12.0
var cnsSquareFabSU = 5.0
var cnsSquareFab = 1//Kumiko
var cnsKmkoFab = 1//Kumiko
var cnsKmkoDbr = 0.16//per intersection
var cnsKmkoStain = 0.02//per inch of kumiko
var cnsAssFrntBrd = 15.0
var cnsCutPaper = 5.0
var cnsAssembleKmko = 0.08//intersection
var cnsLayPaper = 0.08//intersection
var cnsInstallHardware = 15.0
var cnsAssembleTrack = 90.0//Consists of cutting&staining wood facia and header, assembling with 3/8" plugs
var cnsLowerTrack = 60.0//You'll have to route the bottom of each screen or install 1/4" plugs
var cnsStdDelivery = 75.0
var cnsInstallFee = 400.0

//VARIABLE INITIALIZATION
var vTotalMatCost = 0.0
var vTotalLbrCost = 0.0
var vTotalBudget = 0.0
var vWaTax = 0.0
var vSubTotal = 0.0
var vInstallCharge = 0.0
var vInputLength = 0.0
var vRawMatl = 0.0
var vTotalProfit = 0.0
var vScreenInteriorHt = 0.0
var vScreenInteriorWd =0.0

//Get the estimation form data

var  vQtyScreens =  Number(document.forms['EstimateInputs'].elements['QtyScreens'].value);
var  vMountingMethod =  document.forms['EstimateInputs'].elements['MountingMethod'].value;
var  vTrackLength =  Number(document.forms['EstimateInputs'].elements['TrackLength'].value);
var  vTrackQty =  Number(document.forms['EstimateInputs'].elements['TrackQty'].value);
var  vScreenHeight =  Number(document.forms['EstimateInputs'].elements['ScreenHeight'].value);
var  vScreenWidth =  Number(document.forms['EstimateInputs'].elements['ScreenWidth'].value);
var  vWoodType =  document.forms['EstimateInputs'].elements['WoodType'].value;
var  vFinish =  document.forms['EstimateInputs'].elements['Finish'].value;
var  vColorChoice =  document.forms['EstimateInputs'].elements['ColorChoice'].value;
var  vNumVertKmko =  Number(document.forms['EstimateInputs'].elements['NumVertKmko'].value);
var  vNumHrzKmko =  Number(document.forms['EstimateInputs'].elements['NumHrzKmko'].value);
var  vFacing =  document.forms['EstimateInputs'].elements['Facing'].value;
var  vDelivery =  document.forms['EstimateInputs'].elements['Delivery'].value;
var  vInstallationMethod =  document.forms['EstimateInputs'].elements['InstallationMethod'].value;
var  vAddrState =  document.forms['EstimateInputs'].elements['AddrState'].value;

// ADJUST THE REPRESENTATIVE SCREEN GRAPHIC
for (var vScreenNum = 1; vScreenNum <= 4; vScreenNum++)
	{
	if(vScreenNum > vQtyScreens){vPaintPallet = "Clear"}
	else {vPaintPallet = vWoodType}
	ReDrawGraphic(vNumHrzKmko,vNumVertKmko,vScreenHeight,vScreenWidth,vPaintPallet,vFinish,cnsKickBoardTrip,vScreenNum)
	}

vPaintPallet= vWoodType	
DrawTrack(vPaintPallet,vFinish,vMountingMethod)

if(vScreenHeight > cnsKickBoardTrip){vScreenInteriorHt = vScreenHeight - (cnsKickBoardWd + cnsFrameStockWd)}
else{vScreenInteriorHt = vScreenHeight - 2*cnsFrameStockWd}
vScreenInteriorWd = vScreenWidth - 2*cnsFrameStockWd

//PER SCREEN COSTS
	// Frame, Material Costs
		if(vWoodType == "DouglassFir"){vWoodCost = cnsFirWoodCost}
		if(vWoodType == "Pine"){vWoodCost = cnsPineWoodCost}
		if(vWoodType == "Poplar"){vWoodCost = cnsPopWoodCost}
		if(vWoodType == "Oak"){vWoodCost = cnsOakWoodCost}
		if(vWoodType == "Maple"){vWoodCost = cnsMapleWoodCost}
		if(vWoodType == "Cherry"){vWoodCost = cnsCherryWoodCost}
		if(vWoodType == "Other")
			{
			vWoodType =  document.getElementById("Comments").value
			if(vWoodType.indexOf("CUSTOM WOOD @") == -1)
				{
				vWoodCost = prompt('Enter price per foot . . .')
				vWoodType = vWoodType + " CUSTOM WOOD @ $" + vWoodCost + " per foot. (" + prompt("Enter Wood Type . . .") + ")";
				document.getElementById("Comments").value = vWoodType;
				}
			else
				{
				vWoodCost = Number(vWoodType.slice(vWoodType.indexOf("@ $")+3,vWoodType.indexOf(" per foot")))
				}
			vWoodCost = vWoodCost/12
			}

		vInputLength = vScreenHeight
		vRawMatl = RawMatl(vInputLength)
		vTotalMatCost = vTotalMatCost + 2*(vRawMatl*vWoodCost)
		vInputLength = vScreenWidth
		vRawMatl = RawMatl(vInputLength)
		vTotalMatCost = vTotalMatCost + 2*(vRawMatl*vWoodCost)
		
		//Kick Board?
		if(vScreenHeight > cnsKickBoardTrip)
			{
			vInputLength = vScreenWidth
			vRawMatl = RawMatl(vInputLength)
			vTotalMatCost = vTotalMatCost + cnsKickBoardMltplr*(vRawMatl*vWoodCost)
			}

	//Frame Fabrication and Assembly, Labor Costs
		vTotalLbrCost = vTotalLbrCost + (cnsFrameCut+cnsFrameSand)*cnsLaborRate
		vTotalProfit = vTotalProfit + (cnsFrameCut+cnsFrameSand)*cnsBilling
	
	// Kumiko, Material Costs
		// Add single/Double Sided
		if(vFacing == "DoubleSided")
			{
			vNumVertKmko = vNumVertKmko*2
			vNumHrzKmko = vNumHrzKmko*2	
			}
		//Add borders
			vNumVertKmko = vNumVertKmko + 4
			vNumHrzKmko = vNumHrzKmko + 4
		
		//Convert to inches of wood and add to Material Costs
		vInputLength = vScreenInteriorHt
		vRawMatl = RawMatl(vInputLength)
		vTotalMatCost = vTotalMatCost + vWoodCost*((vRawMatl*vNumVertKmko)/cnsKmkoPer1by2)
		vInputLength = vScreenInteriorWd
		vRawMatl = RawMatl(vInputLength)
		vTotalMatCost = vTotalMatCost + vWoodCost*((vRawMatl*vNumHrzKmko)/cnsKmkoPer1by2)		

	//Kumiko, Labor Costs
		vTotalLbrCost = vTotalLbrCost + cnsSquareFabSU*cnsLaborRate
		vTotalLbrCost = vTotalLbrCost + cnsSquareFab*(vNumVertKmko + vNumHrzKmko)*cnsLaborRate
		vTotalLbrCost = vTotalLbrCost + cnsKmkoFab*(vNumVertKmko + vNumHrzKmko)*cnsLaborRate		
		vTotalLbrCost = vTotalLbrCost + cnsKmkoDbr*(vNumVertKmko*vNumHrzKmko)*cnsLaborRate

		vTotalProfit = vTotalProfit + cnsSquareFabSU*cnsBilling
		vTotalProfit = vTotalProfit + cnsSquareFab*(vNumVertKmko + vNumHrzKmko)*cnsBilling
		vTotalProfit = vTotalProfit + cnsKmkoFab*(vNumVertKmko + vNumHrzKmko)*cnsBilling		
		vTotalProfit = vTotalProfit + cnsKmkoDbr*(vNumVertKmko*vNumHrzKmko)*cnsBilling

	//Finishes 
		if(vFinish == "Natural")
			{
			document.forms['EstimateInputs'].elements['ColorChoice'].value='Not Applicable'	
			document.getElementById('ColorChoice').disabled=true;
			}
		else
			{
			document.getElementById('ColorChoice').disabled=false;
			}

		if(vFinish == "Stain")
			{
			vTotalMatCost = vTotalMatCost + cnsFoamBrush + cnsCanPreCond + cnsCanStain
			vTotalLbrCost = vTotalLbrCost + (cnsFrameMaskStain+cnsFramePrecondition+cnsFrameStain)*cnsLaborRate
			vTotalProfit = vTotalProfit + (cnsFrameMaskStain+cnsFramePrecondition+cnsFrameStain)*cnsBilling	
			vTotalLbrCost = vTotalLbrCost + (cnsKmkoStain*(vScreenHeight*vNumVertKmko+vScreenWidth*vNumHrzKmko))		
			vTotalProfit = vTotalProfit + (cnsKmkoStain*(vScreenHeight*vNumVertKmko+vScreenWidth*vNumHrzKmko))
			if(document.forms['EstimateInputs'].elements['ColorChoice'].value== 'Not Applicable'	)
				{
				document.forms['EstimateInputs'].elements['ColorChoice'].value= 'Not needed for estimate'
				}					
			}
		if(vFinish == "StainCoat" || vFinish =="Paint")//Assumes painting is about equivalent in labr/cost to stain and Poly.
			{
			vTotalMatCost = vTotalMatCost + cnsFoamBrush + cnsCanPreCond + cnsCanStain
			vTotalLbrCost = vTotalLbrCost + (cnsFrameMaskStain+cnsFramePrecondition+cnsFrameStain)*cnsLaborRate
			vTotalProfit = vTotalProfit + (cnsFrameMaskStain+cnsFramePrecondition+cnsFrameStain)*cnsBilling
			vTotalLbrCost = vTotalLbrCost + (cnsKmkoStain*(vScreenHeight*vNumVertKmko+vScreenWidth*vNumHrzKmko))		
			vTotalProfit = vTotalProfit + (cnsKmkoStain*(vScreenHeight*vNumVertKmko+vScreenWidth*vNumHrzKmko))	
			vTotalMatCost = vTotalMatCost + cnsFoamBrush + cnsCanPoly + cnsTackCloth + cnsFoamBrush
			vTotalLbrCost = vTotalLbrCost + (cnsFramePoly1+cnsFramePoly2)*cnsLaborRate
			vTotalProfit = vTotalProfit + (cnsFramePoly1+cnsFramePoly2)*cnsBilling
			if(document.forms['EstimateInputs'].elements['ColorChoice'].value== 'Not Applicable'	)
				{
				document.forms['EstimateInputs'].elements['ColorChoice'].value= 'Not needed for estimate'
				}	
			}
	
	//Mounting
	if(vMountingMethod == "HooksHinges")
		{
		vTotalMatCost = vTotalMatCost + cnsHingesHooks
		document.forms['EstimateInputs'].elements['TrackLength'].value=' '	;
		document.getElementById('TrackLength').disabled=true;	
		document.forms['EstimateInputs'].elements['TrackQty'].value='0';
		document.getElementById('TrackQty').disabled=true;					
		}
	else
		{
		vTotalMatCost = vTotalMatCost + cnsRollersDN50CF
		document.getElementById('TrackLength').disabled=false;	
		document.getElementById('TrackQty').disabled=false;	
		}
	vTotalLbrCost = vTotalLbrCost + cnsInstallHardware*cnsLaborRate
	vTotalProfit = vTotalProfit + cnsInstallHardware*cnsBilling
	
	//Assembly
		//Paper
		if(vScreenInteriorHt > (cnsPaperHeight/2) && vScreenInteriorWd > (cnsPaperWidth/2)){vTotalMatCost = vTotalMatCost + cnsWarlonPaper}
		if(vScreenInteriorHt > (cnsPaperHeight/2) && vScreenInteriorWd < (cnsPaperWidth/2)){vTotalMatCost = vTotalMatCost + cnsWarlonPaper/2}
		if(vScreenInteriorHt < (cnsPaperHeight/2) && vScreenInteriorWd > (cnsPaperWidth/2)){vTotalMatCost = vTotalMatCost + cnsWarlonPaper/2}	
		if(vScreenInteriorHt < (cnsPaperHeight/2) && vScreenInteriorWd < (cnsPaperWidth/2)){vTotalMatCost = vTotalMatCost + cnsWarlonPaper/4}

		//Labor
		vTotalLbrCost = vTotalLbrCost + (cnsFrameGlueAssemble + cnsAssFrntBrd + cnsCutPaper + cnsInstallHardware)*cnsLaborRate
		vTotalProfit = vTotalProfit + (cnsFrameGlueAssemble + cnsAssFrntBrd + cnsCutPaper + cnsInstallHardware)*cnsBilling		
		vTotalLbrCost = vTotalLbrCost + (vNumVertKmko*vNumHrzKmko)*(cnsAssembleKmko + cnsLayPaper)*cnsLaborRate	
		vTotalProfit = vTotalProfit + (vNumVertKmko*vNumHrzKmko)*(cnsAssembleKmko + cnsLayPaper)*cnsBilling

	//Consumeables
	vTotalMatCost = vTotalMatCost + (cnsTackCloth + 2*cnsSandPaper220 + cnsSawBlade + cnsWoodGlue + cnsAcrylicMatt + cnsDropCloth)

//PER-ORDER COSTS
	//Per Unit Costs accumulated times qty of screens
	vTotalMatCost = vTotalMatCost*vQtyScreens
	vTotalLbrCost = vTotalLbrCost*vQtyScreens
	vTotalProfit = vTotalProfit*vQtyScreens

	//Additional Costs
	vTotalLbrCost = vTotalLbrCost + (cnsDesignSetUp)*cnsLaborRate
	vTotalProfit = vTotalProfit + (cnsDesignSetUp)*cnsBilling

	if(vMountingMethod != "HooksHinges" && vTrackLength < "1")
		{
		document.forms['EstimateInputs'].elements['TrackLength'].value = "78"
		document.forms['EstimateInputs'].elements['TrackQty'].value='1';
		vTrackLength = 78
		vTrackQty = 1
		}

	if(vMountingMethod == "AlumTrackNo")
		{
		if(vTrackLength <= "78"){vTotalMatCost = vTotalMatCost + cnsU45AL6pt5ft*vTrackQty;}//Track can be made with just one 6.5 U45AL
		if(vTrackLength <= "118.2" && vTrackLength > "78"){vTotalMatCost = vTotalMatCost + cnsU45AL9pt85ft*vTrackQty;}//Track can be made with just one 9.85 U45AL
		if(vTrackLength > "118.2" && vTrackLength <= "156"){vTotalMatCost = vTotalMatCost + (cnsU45AL6pt5ft+cnsU45AL6pt5ft)*vTrackQty}//Add two 6.5's
		if(vTrackLength > "156" && vTrackLength <= "196.2") {vTotalMatCost = vTotalMatCost + (cnsU45AL9pt85ft+cnsU45AL6pt5ft)*vTrackQty}//one 9.85 & one 6.5
		if(vTrackLength > "196.2") {vTotalMatCost = vTotalMatCost + (cnsU45AL9pt85ft+cnsU45AL9pt85ft)*vTrackQty}//two 9.85's

		vInputLength = vTrackLength
		RawMatl(vInputLength,vRawMatl)		
		vTotalMatCost = vTotalMatCost + vWoodCost*vRawMatl*cnsWoodFaciaMltplr
		vTotalLbrCost = vTotalLbrCost + cnsAssembleTrack*cnsLaborRate
		vTotalProfit = vTotalProfit + cnsAssembleTrack*cnsBilling
		}

	if(vMountingMethod == "AlumTrackYes")
		{
		if(vTrackLength <= "78"){vTotalMatCost = vTotalMatCost + cnsU45AL6pt5ft*vTrackQty;}//Track can be made with just one 6.5 U45AL
		if(vTrackLength <= "118.2" && vTrackLength > "78"){vTotalMatCost = vTotalMatCost + cnsU45AL9pt85ft*vTrackQty;}//Track can be made with just one 9.85 U45AL
		if(vTrackLength > "118.2" && vTrackLength <= "156"){vTotalMatCost = vTotalMatCost + (cnsU45AL6pt5ft+cnsU45AL6pt5ft)*vTrackQty}//Add two 6.5's
		if(vTrackLength > "156" && vTrackLength <= "196.2") {vTotalMatCost = vTotalMatCost + (cnsU45AL9pt85ft+cnsU45AL6pt5ft)*vTrackQty}//one 9.85 & one 6.5
		if(vTrackLength > "196.2") {vTotalMatCost = vTotalMatCost + (cnsU45AL9pt85ft+cnsU45AL9pt85ft)*vTrackQty}//two 9.85's
		vInputLength = vTrackLength//Add in the wood facia
		RawMatl(vInputLength,vRawMatl)		
		vTotalMatCost = vTotalMatCost + vWoodCost*vRawMatl*cnsWoodFaciaMltplr
		vTotalMatCost = vTotalMatCost + vTotalMatCost*0.15
		vTotalLbrCost = vTotalLbrCost + (cnsAssembleTrack + cnsLowerTrack)*cnsLaborRate
		vTotalProfit = vTotalProfit + (cnsAssembleTrack + cnsLowerTrack)*cnsBilling
		}

//TOTALS
vSubTotal = vTotalMatCost + vTotalLbrCost + vTotalProfit

//Tax if applicable
var WarningText = "<h2>Cautions:</h2>"
var warning = document.getElementById('Warnings')

if(vAddrState == "WA" || vAddrState == "Washington")
	{
	vWaTax = cnsWaTax*vSubTotal
	WarningText = WarningText + "<li>This is an estimate only</li>"
	}
else
	{
	vWaTax = 0
	document.forms['EstimateInputs'].elements['InstallationMethod'].value = "SelfInstall"
	if(vDelivery == "ShpDeliver")
		{
		var vGirth = (2*(vScreenWidth) + 2*(vQtyScreens*(.75+cnsPackingFactor)+2*cnsPackingFactor)) + vScreenHeight
		if(vGirth > 164.99 || vScreenHeight > 80)
			{
			WarningText = WarningText + "<li>Exceeds standard shipping dimensions.  Shipping Cost TBD</li>"			
			}
		else
			{
			WarningText = WarningText + "<li>A nominal shipping charge has been added to your bill, actual charge will be location dependent</li>"
			}
		WarningText = WarningText + "<li>Out-of-State installation by Seattle Custom Shoji is not available</li>"
		}
	if(vDelivery != "ShpDeliver")
		{
		WarningText = WarningText + "<li>Out-of-State installation by Seattle Custom Shoji is not available</li>"
		}
	}
warning.innerHTML = WarningText;

if(vInstallationMethod == "PaidInstall")
	{
	vSubTotal = vSubTotal +cnsInstallFee
	vDelivery = "Accountedforwithinstallation"
	}
	
if(vDelivery == "ShpDeliver"){vSubTotal = vSubTotal + cnsStdDelivery}

vTotalBudget = vSubTotal+vWaTax

	var vEstFormString = ReadEstimationData()
	var vCode = "profit"
	var vStart = vEstFormString.indexOf('Comments=');
	vStart = vStart + 9
	var vEnd = vStart + vCode.length
	var vTest = vEstFormString.slice(vStart,vEnd);
	if (vTest == vCode) //If the private code has been entered, show statistics
		{
		alert("COGS = "  +  vTotalMatCost + ", Total Labor Cost = " + vTotalLbrCost + " Profit =  " +  vTotalProfit)
		}

//OUTPUT TO TABLE

document.forms['EstimateInputs'].elements['TotalBill'].value = vTotalBudget.toFixed(2)

//See if the projects need to be summed
SumProjects()

}

///////////////////////////////////////////////////////////////////////////////////////   
//This function selects the appropriate sized raw material based on input length  
///////////////////////////////////////////////////////////////////////////////////////
function RawMatl(vInputLength)
{
vRawMatl = vInputLength*1.2
return vRawMatl;
}

///////////////////////////////////////////////////////////////////////////////////////   
//This function redraws the screen graphic according to the data entered. 
///////////////////////////////////////////////////////////////////////////////////////
function ReDrawGraphic(vNumHrzKmko,vNumVertKmko,vScreenHeight,vScreenWidth,vPaintPallet,vFinish,cnsKickBoardTrip,vScreenNum)
	{

	//Initialize variables
	var vGraphicHt = vScreenHeight
	var vGraphicWd = vScreenWidth
	if(vScreenHeight > 86){vGraphicHt = 86}
	if(vScreenWidth > 36){vGraphicWd = 36}
   var vCurrentCellColor = 0;
   var vCurrentCellHeight = 0;
   var vCurrentCellWidth = 0;
   var vScreenHtRatio = (330/86)*vGraphicHt; //330pixels is the height of the table, 86" is the tallest screen
   var vScreenWdRatio = (vGraphicWd/vGraphicHt)*vScreenHtRatio; 
   var vHrzWoodAmount = 12 + vNumHrzKmko*4; // 12 pixels is the width of a 1.5" frame piece, 4 pixels is the width of kumiko
   if(vGraphicHt>cnsKickBoardTrip){vHrzWoodAmount =vHrzWoodAmount + 40} // 40 pixels is the width of a kick board
   else {vHrzWoodAmount = vHrzWoodAmount + 12};
   var vVertWoodAmount = 8 + 8 +vNumVertKmko*4;
   var vVertWhtSpace = (vScreenHtRatio-vHrzWoodAmount)/(vNumHrzKmko+1);
   var vHorzWhtSpace = (vScreenWdRatio-vVertWoodAmount)/(vNumVertKmko+1);
   var vRepGraphic = "RepGraphic" + vScreenNum;
  	var vSubTable = document.getElementById(vRepGraphic);
   var vNumRows = vSubTable.rows.length;
	var vNumCols = vSubTable.rows;
	var vNumCells = vNumCols[0].cells.length;
	var vPaperColor = "#FFFFFF";

	var vWoodColor = PickWoodColor(vPaintPallet)
	if(vFinish == "Paint"){vWoodColor = "#222222"}
	if(vPaintPallet == "Clear")
		{
		vWoodColor = "#39391E";
		vPaperColor = "#39391E";
		}

// Clear the previous graphic
	while(vNumRows > 1)
		{
   	vSubTable.deleteRow(vSubTable.rows.length-1);
  		vNumRows = vSubTable.rows.length;
		}

	while(vNumCells > 0)
		{
		vNumCols[0].deleteCell(0);
		vNumCells = vNumCols[0].cells.length;
		}

   //Size the Screen
	vSubTable.style.height = vScreenHtRatio;
	vSubTable.style.width = vScreenWdRatio;

	vNumRows = vNumHrzKmko*2+3;//Each Kumiko has the kumiko and the white space +1, + the two frames
   vNumCols = vNumVertKmko*2+3;//Each Kumiko has the kumiko and the white space +1, + the two frames

	//Paint the screen row 1, column by column then row 2, etc.  seperate code will build the kickboard or lower frame
	for (var vCurrentRow = 0; vCurrentRow < (vNumRows-1); vCurrentRow++)
		{
   	if(vCurrentRow > 0){var row = vSubTable.insertRow(vCurrentRow)}
		if(vCurrentRow == 0){vCurrentCellHeight = "12"}
		else
			{
			if(vCurrentRow/2 == Math.round(vCurrentRow/2)){vCurrentCellHeight = 4}//Even Rows>0 are Kumiko Rows
			else{vCurrentCellHeight = vVertWhtSpace}
			}
		for (var vCurrentCol = 0; vCurrentCol < vNumCols ; vCurrentCol++)
			{
			if(vCurrentCol == 0 || vCurrentCol == (vNumCols - 1)){vCurrentCellWidth = 8}
			else
				{
				if(vCurrentCol/2 == Math.round(vCurrentCol/2)){vCurrentCellWidth = 4}
				else {vCurrentCellWidth = vHorzWhtSpace}
				}
			
			vCurrentCellColor = "#255255"
			if(vCurrentRow == 0){vCurrentCellColor = vWoodColor}
			if(vCurrentCol == 0 || vCurrentCol == (vNumCols-1)){vCurrentCellColor = vWoodColor}
			if(vCurrentCellColor == "#255255")
				{
				if(vCurrentCellHeight > 4 && vCurrentCellWidth > 4){vCurrentCellColor = vPaperColor}
				else {vCurrentCellColor = vWoodColor}
				}
			
   		vSubTable = document.getElementById(vRepGraphic);
   		vNewCell = vSubTable.rows[vCurrentRow].insertCell(vCurrentCol);
  			vNewCell.style.background = vCurrentCellColor;
  			vNewCell.style.width = vCurrentCellWidth;
  			vNewCell.style.height = vCurrentCellHeight;
			}
		}
	//Add in the lower Frame or Kick Board
	var row = vSubTable.insertRow(vNumRows-1)
	for (var vCurrentCol = 0; vCurrentCol < vNumCols ; vCurrentCol++)
		{
   	vSubTable = document.getElementById(vRepGraphic);
   	vNewCell = vSubTable.rows[vCurrentRow].insertCell(vCurrentCol);
  		vNewCell.style.background = vWoodColor;
		if(vGraphicHt > cnsKickBoardTrip){vNewCell.style.height = "25"}
		else {vNewCell.style.height = "12"}
		}
		
	}
///////////////////////////////////////////////////////////////////////////////////////   
//This function draws in the tracking as appropriate 
///////////////////////////////////////////////////////////////////////////////////////
function DrawTrack(vPaintPallet,vFinish,vMountingMethod)
	{
	var vParentTable = document.getElementById('ParentTable');
	var vWoodColor = PickWoodColor(vPaintPallet)
	if(vFinish == "Paint"){vWoodColor = "#222222"}
	if(vMountingMethod == "HooksHinges")
		{
		vParentTable.rows[0].cells[0].style.background = "#39391E";
		vParentTable.rows[2].cells[0].style.background = "#39391E";	
		}
	if(vMountingMethod == "AlumTrackNo")
		{
		vParentTable.rows[0].cells[0].style.background = vWoodColor;
		vParentTable.rows[2].cells[0].style.background = "#39391E";
		}
	if(vMountingMethod == "AlumTrackYes")
		{
		vParentTable.rows[0].cells[0].style.background = vWoodColor;
		vParentTable.rows[2].cells[0].style.background = vWoodColor;
		}
	}
///////////////////////////////////////////////////////////////////////////////////////   
//This function picks the correct "wood color" 
///////////////////////////////////////////////////////////////////////////////////////
function PickWoodColor(vPaintPallet)
	{
	var vWoodColor = "#000000"
	if(vPaintPallet == "DouglassFir"){vWoodColor = "#CC9966"}
	if(vPaintPallet == "Pine"){vWoodColor = "#FFCC66"}
	if(vPaintPallet == "Poplar"){vWoodColor = "#FFBD82"}
	if(vPaintPallet == "Oak"){vWoodColor = "#C27E3A"}
	if(vPaintPallet == "Maple"){vWoodColor = "#FFE699"}
	if(vPaintPallet == "Cherry"){vWoodColor = "#C47557"}
	if(vPaintPallet == "Other"){vWoodColor = "#C0C0C0"}
	return vWoodColor
	}

///////////////////////////////////////////////////////////////////////////////////////   
//This function sums all the projecst as required
///////////////////////////////////////////////////////////////////////////////////////	
function SumProjects()
	{
	if(document.getElementById("OtherScreens").checked == true)
		{
		$('#ProjTotal').show();
		var vProject = ProjectArray()//Pull a list of former projects (if any exist)
		var vProjectTotal = 0
		if (vProject[0] != '')
			{
			for (w=vProject.length-1;w>=0;w--)
				{
				vProjectTotal = vProjectTotal + Number(PullParameter(vProject[w],"TotalBill"));
				}
			}
		else
			{
			vProjectTotal = document.forms['EstimateInputs'].elements['TotalBill'].value;
			}
		document.getElementById('ProjTotal').innerHTML = "TOTAL: $" + vProjectTotal
		}
	else
		{
		$('#ProjTotal').hide();
		}		
		BeenSaved('not')
	}

