function SetupEmailRequest()
{
$('RequestHeader').value = QuoteNumber + " has be submitted for review";
var S = getPorchQS() + "\n";
S += "Saved as Quote " + QuoteNumber + "\n";
$('RequestBody').value = S;
$('RequestData').submit();
}




function getRestoringSteps()
{
var A=new Array();


if (getDDLvalue($('selectHeight')) == 85)
{
A.push("MudroomHeight(1);");
}
else
{
A.push("MudroomHeight(2);");
}

A.push("MudroomDoor(" + currentMudroomDoor + ");");
A.push("MudroomConfig();");
A.push("AcceptDesign()");




A.push(getInsertRestore());
A.push("setDB(" + CurrentDitmar + ");");
A.push("setPaint(" + (CurrentPaint + 1) + ");");

if (CurrentFrame)
{
A.push("setIF(1);");
}
else
{
A.push("setIF(2);");
}

if (CurrentGlass)
{
A.push("setSG(2);");
}
else
{
A.push("setSG(1);");
}


A.push("setRoofMaterial(" + CurrentRoofMaterial + ");");

A.push("setRoofStyle(" + CurrentRoofStyle + ");");
A.push("AcceptOptions();");




A.push(getTextboxRestore("BillName"));
A.push(getTextboxRestore("BillCompany"));
A.push(getTextboxRestore("BillStreet"));
A.push(getTextboxRestore("BillSuite"));
A.push(getTextboxRestore("BillCity"));
A.push(getTextboxRestore("BillZIP"));
A.push(getTextboxRestore("BillPhone"));
A.push(getTextboxRestore("BillFAX"));
A.push(getTextboxRestore("BillEmail"));
A.push(getDDLRestore('BillState'));
A.push(getCheckboxRestore("ShipToSame"));
A.push("SameAsChanged();");
A.push(getTextboxRestore("ShipName"));
A.push(getTextboxRestore("ShipCompany"));
A.push(getTextboxRestore("ShipStreet"));
A.push(getTextboxRestore("ShipSuite"));
A.push(getTextboxRestore("ShipCity"));
A.push(getTextboxRestore("ShipZIP"));
A.push(getTextboxRestore("ShipPhone"));
A.push(getTextboxRestore("ShipFAX"));
A.push(getTextboxRestore("ShipEmail"));
A.push(getDDLRestore('ShipState'));
A.push("QuoteInfoChanged();");
A.push(getTextboxRestore("customizeTagLine"));
A.push(getTextboxRestore("customizeURL"));
A.push(getTextboxRestore("customizeCompanyName"));
A.push(getTextboxRestore("OverrideShippingText"));
A.push(getTextboxRestore("customizeSalesRep"));
A.push(getTextboxRestore("OverrideTaxText"));
A.push(getTextboxRestore("OverrideInstallationText"));
A.push(getCheckboxRestore("OverrideShipping"));
A.push(getCheckboxRestore("OverrideTax"));
A.push(getCheckboxRestore("OverrideInstallation"));
A.push(getCheckboxRestore("OverridechkDiscount"));
A.push(getTextboxRestore("OverrideDiscount"));



A.push("overrides();");
A.push("updatedHeaderCN();");
A.push("updatedTagHeader();");
A.push("updatedHeader();");

A.push("while (NoteCount < " + NoteCount + ") {AddNote();}");

for (t=1;t<=NoteCount;t++)
{
A.push(getTextboxRestore("Note" + t));
}
return A.join("\n");
}

function getDDLRestore(name)
{
var S = "$('" + name + "').selectedIndex = " + $(name).selectedIndex + ";";
return S;
}

function getCheckboxRestore(name)
{
var S = "$('" + name + "').checked = " + $(name).checked + ";";
return S;
}

function getTextboxRestore(name)
{
var S = "$('" + name + "').value = '" + $(name).value + "';";
return S;
}


function getDoorRestore(Location)
{
var S;
S = getDDLRestore(Location + "DoorLocation");
S += getDDLRestore(Location + "DoorType");
S += getCheckboxRestore(Location + "OpenIn");
S += getCheckboxRestore(Location + "DoorRightHinged");
return S;
}



function getInsertRestore()
{
var S;
S = "CurrentUI = '" + CurrentUI + "';"
S += "CurrentLI = '" + CurrentLI + "';"

var X = 5;
switch (CurrentUI)
	{
	case "VICTORIANHALF":
	X = 1;
	break;
	case "QUEENANNEHALF":
	X = 2;
	break;
	case "DIVIDEDLIGHT":
	X = 3;
	break;
	case "PANEL":
	X = 4;
	break;
	}
S += "selectZone('UI', " + X + ");";
X = 5;
switch (CurrentUI)
	{
	case "VICTORIANBALLUSTER":
	X = 1;
	break;
	case "QUEENANNEBALLUSTER":
	X = 2;
	break;
	case "PANEL":
	X = 3;
	break;
	case "PANEL":
	X = 4;
	break;
	}
S += "selectZone('LI', " + X + ");";
return S;
}


function AjaxSavePorch()
{
var URL = 'merchant.mvc';
var params = "";
params += "screen=CTGY&Category_Code=_PorchSystemSave&saveLetter=PS&savecode=_design_foyer";
if (QuoteNumber)
	{
	params += "&OQN=" + QuoteNumber.split("-")[1];
	}
params += "&savestring=" + escape(getRestoringSteps().replace(/#/g, "%23"));
makePOSTRequest(URL, params);
}

  function HandleResponse(value)
	{
	QuoteNumber = (value.split("|*^*|")[1]);
	$('OutputQuoteNumber').innerHTML = QuoteNumber;
	if (CalledBack)
		{CalledBack();}
	}



	




function getNotes()
{
var CN = 1;
var Node = document.getElementById("Note" + CN);
var N = new Array();

while (Node)
{
N.push(Node.value);
CN += 1;
Node = document.getElementById("Note" + CN);
}
return N;
}



function BackToMain()
{
hide('Lrg1');
BackToLayout();
ConfiguredBack();
GenerateBack();
$("Lrg1").src = MudRoomPreviews[currentMudroomDoor];
show('Lrg1');
}

function NoValidLayout(ErroredWalls)
{
	hide('ConfigDiv');
	show('ErrorDiv');
	var Zone = $('ErrorSuggestZone');
	var S = "<b>This porch could not be successfully fit!</b><br/><br/>";
	S += "Please contact Vixen Hill, and our design department will attempt to find a working solution!</br>";
	Zone.innerHTML = S;
}
function HaveWorkingLayout()
{
	hide('LSRETROCONTROL', 'FCRETROCONTROL', 'RSRETROCONTROL');
	show('BPAccept','BPLarge');
	hide('ErrorDiv');
	if (Design.WallConfigurations[WallLocations.left]!=nothing)
	{
		Design.WallConfigurations[WallLocations.left].sort(ConfigurationReorder);
		var select = $('configLeft');
		clearOptions(select);
		for (t=0;t<Design.WallConfigurations[WallLocations.left].length;t++)
		{
			addOption(select, Design.WallConfigurations[WallLocations.left][t].descriptor.Description, t);
		}
	}
	if (Design.WallConfigurations[WallLocations.right]!=nothing)
	{
		Design.WallConfigurations[WallLocations.right].sort(ConfigurationReorder);
		select = $('configRight');
		clearOptions(select);
		for (t=0;t<Design.WallConfigurations[WallLocations.right].length;t++)
		{
			addOption(select, Design.WallConfigurations[WallLocations.right][t].descriptor.Description, t);
		}
	}
	select = $('configFront');
	clearOptions(select);
	Design.WallConfigurations[WallLocations.front].sort(ConfigurationReorder);
	for (t=0;t<Design.WallConfigurations[WallLocations.front].length;t++)
	{
		addOption(select, Design.WallConfigurations[WallLocations.front][t].descriptor.Description, t);
	}
	SelectableConfigurations=new Array();
	ConfigNames = new Array();


	for (CWP=0;CWP<2;CWP++)
	{
		var X = new Array();
		var match = true;
		for (CWL=0;CWL<=2;CWL++)
		{
			if (Design.WallConfigurations[CWL] != nothing)
			{
				var group = getSolutionWithWallPanels(CWL, WallPanels[CWP], nothing);
				if (group.length > 0)
				{
					X[CWL] = group[0];
				}
				else
				{
					match = false;
				}
			}
		}
		if (match)
		{
			SelectableConfigurations.push(X);
			ConfigNames.push(WallPanels[CWP].runlength + " inch Panels");
		}
	}
	for (CWP=0;CWP<2;CWP++)
	{
		for (CWP2=CWP+1;CWP2<WallPanels.length;CWP2++)
		{
			var CWP1C = 0;
			var CWP2C = 0;

			var X = new Array();
			var match = true;
			for (CWL=0;CWL<=2;CWL++)
			{
				if (Design.WallConfigurations[CWL] != nothing)
				{
					var group = getSolutionWithWallPanels(CWL, WallPanels[CWP], WallPanels[CWP2]);
					if (group.length > 0)
					{
						X[CWL] = group[0];
						CWP1C += Design.WallConfigurations[CWL][group[0]].solution.wallPanel1Count;
						CWP2C += Design.WallConfigurations[CWL][group[0]].solution.wallPanel2Count;
					}
					else
					{
						match = false;
					}
				}
			}
			if (match && CWP1C > 0 && CWP2C > 0)
			{
				SelectableConfigurations.push(X);
				ConfigNames.push(WallPanels[CWP].runlength + " and " + WallPanels[CWP2].runlength + " inch Panels");
			}
		}
	}



	for (CWP=2;CWP<WallPanels.length;CWP++)
	{
		var X = new Array();
		var match = true;
		for (CWL=0;CWL<=2;CWL++)
		{
			if (Design.WallConfigurations[CWL] != nothing)
			{
				var group = getSolutionWithWallPanels(CWL, WallPanels[CWP], nothing);
				if (group.length > 0)
				{
					X[CWL] = group[0];
				}
				else
				{
					match = false;
				}
			}
		}
		if (match && CWP1 > 0 && CWP2 > 0)
		{
			SelectableConfigurations.push(X);
			ConfigNames.push(WallPanels[CWP].runlength + " inch Panels");
		}
	}
	for (CWP=2;CWP<WallPanels.length;CWP++)
	{
		for (CWP2=CWP+1;CWP2<WallPanels.length;CWP2++)
		{
			var CWP1C = 0;
			var CWP2C = 0;
			var X = new Array();
			var match = true;
			for (CWL=0;CWL<=2;CWL++)
			{
				if (Design.WallConfigurations[CWL] != nothing)
				{
					var group = getSolutionWithWallPanels(CWL, WallPanels[CWP], WallPanels[CWP2]);
					if (group.length > 0)
					{
						X[CWL] = group[0];
						CWP1C += Design.WallConfigurations[CWL][group[0]].solution.wallPanel1Count;
						CWP2C += Design.WallConfigurations[CWL][group[0]].solution.wallPanel2Count;
					}
					else
					{
						match = false;
					}
				}
			}
			if (match && CWP1C > 0 && CWP2C > 0)
			{
				SelectableConfigurations.push(X);
				ConfigNames.push(WallPanels[CWP].runlength + " and " + WallPanels[CWP2].runlength + " inch Panels");
			}
		}
	}




	{
		X = new Array();
		X[0] = 0;
		X[1] = 0;
		X[2] = 0;
		SelectableConfigurations.push(X);
		ConfigNames.push("Custom Configuration");
	}
	var box=$('Workbar');
	clearOptions(box);
	for (t=0;t<SelectableConfigurations.length;t++)
	{
		addOption(box, ConfigNames[t], t);
	}
	CurrentConfiguration=0;
	for (t=1;t<=7;t++)
	var C = "none";
	visControls(C, C, C, C, C, C);
	var Auto = $("LrgAuto");
	Auto.style.left = "0px";
	Auto.src = getPorchQS();
	Auto.style.display = "inline";
	ShowHideConfigBars();
}
function resetOptions()
{
	setIF(2);
	setDB(1);
	setPaint(1);
	setSG(1);
	popupLI(5, "NONE");
	popupUI(5, "NONE");
}

function RDimensionsChanged(target)
{

var DoorExists;

switch(target)
	{
	case "FC":
	DoorExists = !($('FrontDoorLocation').selectedIndex == 0);
	break;
	case "LS":
	DoorExists = !($('LeftDoorLocation').selectedIndex == 0);
	break;
	case "RS":
	DoorExists = !($('RightDoorLocation').selectedIndex == 0);
	break;
	}


var Sections = $(target + "SECTIONS").selectedIndex + 1;
for (var t=1;t<=5;t++)
	{
	if (t > Sections)
		{
		$(target + "SECDIV" + t).style.display = 'none';
		}
	else
		{
		$(target + "SECDIV" + t).style.display = 'block';
		}
	}

	if (Sections > 1)
		{
		if (DoorExists)
		{
		$(target + "RETROINNER").style.height = (23 * (Sections + 2)) + 'px';
		$(target + "RETROCONTROL").style.height = ((23 * (Sections + 2)) + 19) + 'px';
		$(target + "DOORDIV").style.top = ((Sections + 1) * 23) + 'px';
		$(target + "DOORDIV").style.display = 'block';
		}
		else
		{
		$(target + "RETROINNER").style.height = (23 * (Sections + 1)) + 'px';
		$(target + "RETROCONTROL").style.height = ((23 * (Sections + 1)) + 19) + 'px';
		$(target + "DOORDIV").style.top = ((Sections + 1) * 23) + 'px';
		$(target + "DOORDIV").style.display = 'none';
		}
		}
		else
		{
		$(target + "RETROINNER").style.height = '46px';
		$(target + "RETROCONTROL").style.height = '65px';
		$(target + "DOORDIV").style.display = 'none';
		}

	for (var t=1;t<=Sections;t++)
	{
	var Feet = $(target + "SEC" + t);
	var Inches = $(target + "SEC" + t + "I");

	var lngth = parseSectionValue (target, t)
	if (lngth > 0)
		{
		Feet.style.backgroundColor = "#FFFFFF";
		Inches.style.backgroundColor = "#FFFFFF";
		}
	else
		{
		Feet.style.backgroundColor = "#FFFFAA";
		Inches.style.backgroundColor = "#FFFFAA";
		}
	}
	var DoorSelect = $(target + "DOORSEC");
	var Current = DoorSelect.selectedIndex;
	clearOptions(DoorSelect);
	var Letters = ['A','B','C','D','E'];
	for (t=1;t<=Sections;t++)
		{	
		addOption(DoorSelect, Letters[t-1], t);
		}
	if (Current+1<=Sections)
		{
		DoorSelect.selectedIndex = Current;
		}
		
		

DimensionsChanged();
updateShapeImage();
}



var ManIndex = new Array();
var Manifest = new Array();
var Design;
var currentShape;
var currentWidth, currentDepth;
var timer;
var OLF, OLI, WW, WWI;
OLF = $('OLF');
OLI = $('outlineinner');
WW = $('workwindow');
WWI = $('workwindowinner');
var CurrentConfiguration=0;
var SelectableConfigurations;
var ConfigNames;
var MPW = 3.625;
var MECW = .5;
var SQTT = 1.41421 / 2.0;
var M45TP = 1.1568;
var CP45 = 2.6186;
var POST = 3.625;
var IncludeRoof = false;


var WallPanels = new Array(new WallPanel(63, 6, "WP-63"), new WallPanel(49, 6, "WP-49"), new WallPanel(36.5, 6, "WP-36"));
var StandardWallPanels = WallPanels;
var ExtendedWallPanels = new Array(new WallPanel(63, 6, "WP-63"), new WallPanel(49, 6, "WP-49"), new WallPanel(36.5, 6, "WP-36"), new WallPanel(24, 4, "WP-SHORT-"));

var nothing;

var WallLocations = {className:"Enumeration", front:0, left:1, right:2, leftcorner:3, rightcorner:4};
var DoorLocations = {className:"Enumeration", none:0, centered: 1, left: 2, right: 3};
var PaintColors = {className:"Enumeration",unpainted:0, white:1, nantucketWhite:2, cedartoneStain:3, twoToned:4};
var LastSelectedDoorLocation = 1;
var CurrentUI = "NONE";
var CurrentLI = "NONE";
var CurrentGlass = false;
var CurrentPaint = PaintColors.unpainted;
var CurrentDitmar=0;
var CurrentFrame=false;
var DoorBeingSwitched;
var PageBegin = "<table class='page'><tbody><tr><td><div style='position:relative;top:0in;left:0in;width:100%;height:100%'>";
var PageEnd = "</div></td></tr></tbody></table>";
var InfoError=false;




function QuoteInfoChangedDoit()
{

if (QICTO)
{
clearInterval(QICTO);
}
	var ShipToSame=$('ShipToSame').checked;
	if (ShipToSame)
	{
		$('ShipName').value = $('BillName').value;
		$('ShipCompany').value = $('BillCompany').value;
		$('ShipStreet').value = $('BillStreet').value;
		$('ShipSuite').value = $('BillSuite').value;
		$('ShipCity').value = $('BillCity').value;
		$('ShipZIP').value = $('BillZIP').value;
		$('ShipPhone').value = $('BillPhone').value;
		$('ShipFAX').value = $('BillFAX').value;
		$('ShipState').selectedIndex = $('BillState').selectedIndex;
	}
	var Price, Ship, Tax, Total, State;
	State = selectedValue($('ShipState'));
	Ship = getShipCost(State);
	Price = getPorchPrice(CurrentPaint, CurrentGlass, CurrentUI, CurrentLI, CurrentDitmar, CurrentFrame);
	Tax = 0;
	if (State == "PA")
	{
		Tax = (Math.floor((Price + Ship) * .06 * 100))/100;
	}
	Total = Ship + Price + Tax;
	var Error = false;
	Error = verify("Ship");
	Error = verify("Bill");
	InfoError=Error;
	if (Error)
	{
		$('PrintableFinalButton').style.backgroundColor='#777777';
	}
	else
	{
		$('PrintableFinalButton').style.backgroundColor='';
	}
	$('InfoPorch').innerHTML = Currency(Price);
	if (Ship == 0)
	{
		$('InfoShip').innerHTML = "CALL";
	}
	else
	{
		$('InfoShip').innerHTML = Currency(Ship);
	}
	$('InfoTax').innerHTML = Currency(Tax);
	$('InfoTotal').innerHTML = Currency(Total);
}
function getConfigDescription(C)
{
var Result = new Object();
var WPUsed = new Array();
var JPLUsed = new Array();
var JPUsed = new Array();
var EPUsed = new Array();
var UsesWingWall=false;

for (var x=0;x<C.Parts.length;x++)
	{
	var CP = C.Parts[x];
	var L = CP.className;
	switch (L)
		{
		case "WingWall":
			UsesWingWall=true;
		break;
		case "WallPanel":
			if (!(CFDC(WPUsed, CP.runlength)))
			{
			WPUsed.push(CP.runlength);
			}
		break;
		case "JoiningPost":
			if (!(CFDC(JPLUsed, CP.runlength)))
			{
			JPUsed.push(CP);
			JPLUsed.push(CP.runlength);
			}
		break;
		}
	}

var SV = 0;
var Desc;

if (WPUsed.length == 1)
	{
	if (CFDC(WPUsed, 63))
		{
		SV = 7000;
		Desc = "63 Inch Wall Panels";
		}
	if (CFDC(WPUsed, 49))
		{
		SV = 6000;
		Desc = "49 Inch Wall Panels";
		}
	if (CFDC(WPUsed, 36.5))
		{
		SV = 4000;
		Desc = "36 Inch Wall Panels";
		}
	}

if (WPUsed.length == 2)
	{
	if (!CFDC(WPUsed, 63))
		{
		SV = 2000;
		Desc = "49 & 36 Inch Wall Panels";
		}
	if (!CFDC(WPUsed, 49))
		{
		SV = 3000;
		Desc = "63 & 36 Inch Wall Panels";
		}
	if (!CFDC(WPUsed, 36.5))
		{
		SV = 5000;
		Desc = "63 & 49 Inch Wall Panels";
		}
	}
if (WPUsed.length == 3)
		{
		SV = 1000;
		Desc = "63,49 & 36 Inch Wall Panels";
		}

if (WPUsed.length == 0)
		{
		SV = 8000;
		Desc = "No Wall Panels";
		}

if (JPUsed.length == 1)
	{
	var P = JPUsed.pop();
	SV += 400 + (P.runlength * 10);
	Desc += "/" + P.partName.replace(/-/, "");
	}
else
	{
	if (JPUsed.length != 0)
		{
		Desc += "/Mixed Joining Posts";
		}
	}

if (UsesWingWall)
	{
	SV -= 1;
	Desc += "/Wing Wall";
	}

Result.value = SV;
Result.Description = Desc;
return Result;
}


var Discount = 0;
var ImageLogo = "<img style='position:absolute;top:0in;left:0in;width:3.585in; height:0.75in;' src='http://vixenhill.com/Merchant2/graphics/logo.gif'/>";



function DiscountChanged()
{
	Discount = selectedValue($('AppliedDiscount')) / 100;
	ElevationViewChanged();
	setGlassAvailable();

}


function CFDC(array, value)
{
for (var t=0;t<array.length;t++)
	{
	if (array[t]==value)
		{return true;}
	}
return false;
}



function ConfigurationReorder(A, B)
{
	if (A.descriptor.value<B.descriptor.value)
	{
	return 1;
	}
	return -1;

}




function setGlassAvailable()
{
var Glass = "DisabledGlass";
var UUG, LUG;
UUG = getPart("UI-" + CurrentUI + "-A").upperInsertGroup=="Z";
LUG = getPart("LI-" + CurrentLI + "-A").lowerInsertGroup=="Z";

if (UUG && LUG)
	{
	setSG(1)
	show(Glass);

	}
	else
	{
	hide(Glass);
	}

}



function DelayedupdateShapeImage()
{
	setTimeout("updateShapeImage()", 2);
}

function updateShapeImage()
{
	$('Lrg1').src = getConfigSrc();
}

function DoorButtonPress(target)
{
	var DT, DS;
	DoorBeingSwitched = target;
	var DL = $(DoorBeingSwitched + "DoorLocation").selectedIndex;
	DT = $(DoorBeingSwitched + "DoorType").selectedIndex;
	DS = $(DoorBeingSwitched + "OpenIn").checked;
	RH = $(DoorBeingSwitched + "DoorRightHinged").checked;
	if (DL != 0)
	{
		DoorLocationSelected(DL);
		if (DT==0)
		{
			if (DS)
			{
				if (RH)
				{
					DoorSelected(8);
				}
				else
				{
					DoorSelected(3);
				}
			}
			else
			{
				if (RH)
				{
					DoorSelected(7);
				}
				else
				{
					DoorSelected(2);
				}
			}
		}
		else
		{
			DoorSelected(DT + 3);
		}
	}
	else
	{
		DoorSelected(1);
	}
	$('DoorChangeControl').style.display = 'inline';
}

function DoorCloseButtonPressed(value)
{
	$('Lrg1').src = getConfigSrc();
	hide('DoorChangeControl');
}

function PrepQuoteHeader()
{
	var D = new Date();
	$('QuoteDate').innerHTML = "Date: <b>" + D.toDateString() + "</b>";
	SubPrepQuoteHeader("Name");
	SubPrepQuoteHeader("Company");
	SubPrepQuoteHeader("Street");
	SubPrepQuoteHeader("Suite");
	SubPrepQuoteHeader("City");
	SubPrepQuoteHeader("ZIP");
	SubPrepQuoteHeader("Phone");
	SubPrepQuoteHeader("FAX");
	SubPrepQuoteHeader("Email");
	$('PQShipState').innerHTML = selectedValue($('ShipState'));
	$('PQBillState').innerHTML = selectedValue($('BillState'));
	var Price, Ship, Tax, Total, State, Install;

	if ($('OverrideInstallation').checked)
	{
	$('QuoteInstallationRow').style.display = '';
	Install = Math.floor(100 * parseFloat($('OverrideInstallationText').value))/100;
	$('QuoteInstallation').innerHTML = Currency(Install);
	}
	else
	{
	$('QuoteInstallationRow').style.display = 'none';
	Install = 0;
	}
	
	

	State = selectedValue($('ShipState'));
	Ship = 0;
	Price = getPorchPrice(CurrentPaint, CurrentGlass, CurrentUI, CurrentLI, CurrentDitmar, CurrentFrame);
	if ($('OverrideShipping').checked)
	{
		Ship = Math.floor(100 * parseFloat($('OverrideShippingText').value))/100;
		$('QuoteShipping').innerHTML = Currency(Ship);
	}
	else
	{
	$('QuoteShipping').innerHTML = Currency(Ship);
	}

	if (State == "PA")
	{
		Tax = (Math.floor((Price + Ship + Install) * .06 * 100))/100;
	}
	else
	{
		Tax = 0;
	}

	if ($('OverrideTax').checked)
	{
		Tax = Math.floor((Price + Ship + Install) * parseFloat($('OverrideTaxText').value))/100;
	}


	Total = Ship + Price + Tax + Install;

	

	if (Discount > 0)
	{
	$('QuoteSub1').innerHTML = Currency(Price / (1-Discount));
	$('QuoteDiscountLine').style.display = '';
	$('QuoteSubDiscount').innerHTML = Currency((Price / (1-Discount)*Discount));
	}
	else
	{
	$('QuoteSub1').innerHTML = Currency(Price);
	$('QuoteDiscountLine').style.display = 'none';
	}


	$('QuoteTax').innerHTML = Currency(Tax);
	$('QuoteSub2').innerHTML = Currency(Total);
	$('QuoteDeposit').innerHTML = Currency(Total * .25);
	$('QuoteBalance').innerHTML = Currency(Total * .75);
}

function SubPrepQuoteHeader(field)
{
	if ($('PQShip' + field) == nothing || $('PQBill' + field)==nothing)
	{
		alert(field);
		return;
	}
	$('PQShip' + field).innerHTML = $('Ship' + field).value;
	$('PQBill' + field).innerHTML = $('Bill' + field).value;
}

function GoInfo()
{
	show('QuoteCustomerInformation');
	hide('ManifestStage');
	SameAsChangedTimeout();
}

function InfoBack()
{
	hide('QuoteCustomerInformation');
	show('ManifestStage');
}

function ZIPsubverify(target)
{
	if (target.disabled)
	{
		target.style.backgroundColor = "#CCCCCC";
	}
	else
	{
		if (target.value.length != 5)
		{
			target.style.backgroundColor = "#FFFF00";
		}
		else
		{
			target.style.backgroundColor = "#FFFFFF";
		}
	}
	return (target.value.length == 5);
}


function subverify(target)
{
	target = $(target);
	if (target.disabled)
	{
		target.style.backgroundColor = "#CCCCCC";
	}
	else
	{
		if (target.value.length < 1)
		{
			target.style.backgroundColor = "#FFFF00";
		}
		else
		{
			target.style.backgroundColor = "#FFFFFF";
		}
	}
	return (target.value.length > 0);
}


function partVerify(target, Error)
{
return 	Error = !(subverify(target)) || Error;
}



function verify(Side)
{
	var target;
	var Error = false;
	Error = partVerify(Side + "Name", Error);
	Error = partVerify(Side + "Street", Error);
	Error = partVerify(Side + "City", Error);
	Error = partVerify(Side + "State", Error);
	Error = partVerify(Side + "ZIP", Error);
	if (Error)
	{
		$('OutError').innerHTML = 'Fields in Yellow are Required.';
	}
	else
	{
		$('OutError').innerHTML = '';
	}
	return Error;
}

function SameAsChanged()
{
	setTimeout("SameAsChangedTimeout()", 10);
}

function SameAsChangedTimeout()
{
	var val=$('ShipToSame').checked;
	$('ShipName').disabled = val;
	$('ShipCompany').disabled = val;
	$('ShipStreet').disabled = val;
	$('ShipSuite').disabled = val;
	$('ShipCity').disabled = val;
	$('ShipState').disabled = val;
	$('ShipZIP').disabled = val;
	$('ShipPhone').disabled = val;
	$('ShipFAX').disabled = val;
	QuoteInfoChanged();
}

function getShipWeight()
{
	var Weight=0;
	for (var t=0;t<Manifest.length;t++)
	{
		var ITM = Manifest[t].item;
		var QTY = Manifest[t].count;
		Weight += ITM.weight * QTY;
	}
	return Weight;
}

function QuoteInfoChanged()
{
if (QICTO)
{
clearInterval(QICTO);
}
QICTO = setInterval("QuoteInfoChangedDoit()", 250);
}


var QICTO;



function Checkout()
{
	var Form, Input;
	Form = $('formTestX');
	Input = document.createElement('input');
	Input.name = "PaintColor";
	Input.value = CurrentPaint;
	Form.appendChild(Input);
	Input = document.createElement('input');
	Input.name = "Overhead";
	Input.value = getPorchQS();;
	Form.appendChild(Input);

	Input = document.createElement('input');
	Input.name = "PanelHeight";
	Input.value = getPanelHeight();
	Form.appendChild(Input);


	for (var t=0;t<Manifest.length;t++)
	{
		var ITM = Manifest[t].item;
		var QTY = Manifest[t].count;
		Input = document.createElement('input');
		Input.name = 'PartId';
		if (ITM.partClass == "Beam")
		{
			Input.value = "DITMAR_BEAM_2X" + ITM.name.substr(14, 1);
		}
		else
		{
			Input.value = ITM.name;
		}
		Form.appendChild(Input);
		Input = document.createElement('input');
		Input.name = 'QTY';
		Input.value = QTY;
		Form.appendChild(Input);
		Input = document.createElement('input');
		Input.name = 'ARGS';
		Input.value = ITM.runLength;
		Form.appendChild(Input);
	}
	Form.submit();
}

function ShowAllElevation()
{
	var E = window.open("");
	E.document.write("<head></head><body><div style='text-align:left;width:100%'>Front Center Wall</div>");
	var adiv;
	var target=WallLocations.front;
	adiv=getElevations(currentConfig(target).Parts, CurrentPaint, CurrentGlass, CurrentUI, CurrentLI);
	E.document.write("<div style='position:relative;width:100%;top:0px;left:0px;height:" + adiv.style.height +"'>");
	E.document.write(adiv.innerHTML);
	E.document.write("</div><hr/>");
	if (Design.RS)
	{
		target=WallLocations.right
		adiv=getElevations(currentConfig(target).Parts, CurrentPaint, CurrentGlass, CurrentUI, CurrentLI);
		E.document.write("<div style='text-align:left;width:100%'>Right Wall</div>");
		E.document.write("<div style='position:relative;width:100%;top:0px;left:0px;height:" + adiv.style.height +"'>");
		E.document.write(adiv.innerHTML);
		E.document.write("</div><hr/>");
	}
	if (Design.LS)
	{
		target=WallLocations.left
		adiv=getElevations(currentConfig(target).Parts, CurrentPaint, CurrentGlass, CurrentUI, CurrentLI);
		E.document.write("<div style='text-align:left;width:100%'>Left Wall</div>");
		E.document.write("<div style='position:relative;width:100%;top:0px;left:0px;height:" + adiv.style.height +"'>");
		E.document.write(adiv.innerHTML);
		E.document.write("</div><hr/>");
	}
	if ((Design.RS || Design.LS) && Design.C)
	{
		target=WallLocations.leftcorner
		adiv=getElevations(currentConfig(target).Parts, CurrentPaint, CurrentGlass, CurrentUI, CurrentLI);
		E.document.write("<div style='text-align:left;width:100%'>Corner Walls</div>");
		E.document.write("<div style='position:relative;width:100%;top:0px;left:0px;height:" + adiv.style.height +"'>");
		E.document.write(adiv.innerHTML);
		E.document.write("</div><hr/>");
	}
	E.document.close();
}

function createPrintDiv(X, Y, W, H, specialStyle)
{
	var S = "<div style='position:absolute;left:" + X + "in;"
	S += "top:" + Y + "in;Width:" + W + "in;Height:" + H + "in;";
	S += specialStyle + "'>";
	return S;
}

function getQuoteElevationsHTML()
{
	var ElevationHeader = "<div style='position:relative;top:0in;left:0in;width:100%;height:1in;font-size:.35in;text-align:center'>" + ImageLogo + "<div style='position:absolute;top:0in;left:3.6in;width:3.4in;height:.75in'>Porch System <br/> Elevation Views</div></div><hr />";


	ElevationHeader += "<img style='position;relative;left:3in;top:0in;width:2in;height:2in' src='";

	ElevationHeader += "http://secure.vixenhill.com/Gazebos/SideView.aspx?H=300&W=300" + "&P=" + getPanelHeight();
	if (CurrentDitmar != 0)
	{
	ElevationHeader += "&D=TRUE";
	}

	ElevationHeader += "' /><hr/>";






	var PPI = 150;
	var OldMan = Manifest;
	var S=PageBegin;
	S += ElevationHeader;
	var A = new Array();
	var O;
	if (Design.RS)
	{
		var O = new Object();
		O.span = currentConfig(WallLocations.right).Parts;
		O.desc = getWallName(WallLocations.right);
		A.push(O);
	}
	if (Design.LS)
	{
		var O = new Object();
		O.span = currentConfig(WallLocations.left).Parts;
		O.desc = getWallName(WallLocations.left);
		A.push(O);
	}
	O = new Object();
	O.span = currentConfig(WallLocations.front).Parts;
	O.desc = getWallName(WallLocations.front);
	A.push(O);
	if (Design.C && (Design.LS || Design.RS))
	{
		if (Design.LS)
		{
			var O = new Object();
			O.span = currentConfig(WallLocations.leftcorner).Parts;
			O.desc = "Corners";
			A.push(O);
		}
		else
		{
			var O = new Object();
			O.span = currentConfig(WallLocations.rightcorner).Parts;
			O.desc = "Corners";
			A.push(O);
		}
	}
	var CX, CY, scalefactor, DrawWidth, DrawHeight, Offset, rowHeight;

	rowHeight = RTT(getPart(A[0].span[0].partName).imageHeight / PPI);

	var newPageHTML = "</div></td></tr></tbody></table>";


	newPageHTML += "<table class='page'><tbody><tr><td><div style='position:relative;top:0in;left:0in;width:100%;height:100%'>"
	newPageHTML += ElevationHeader;
	CX = .2;
	CY = 3.4;
	for (t=0;t<A.length;t++)
	{
		S += createPrintDiv(CX, CY, 6.25, rowHeight, "");
		for (c=0;c<A[t].span.length;c++)
		{
			scalefactor = 1;
			var tempitm = A[t].span[c];
			var rl = tempitm.runlength;
			var item=getPart(tempitm.partName);
			if (tempitm.trim != nothing)
			{
				scalefactor = (rl - tempitm.trim) / (rl);
			}
			else
			{
				if (tempitm.className == "WingWall")
				{
					scalefactor = (24 - rl) / 24;
				}
				if (tempitm.className == "InlinePost")
				{
					scalefactor = (rl) / 1000;
				}
			}
			DrawWidth = RTT(item.imageWidth * scalefactor / PPI);
			DrawHeight = RTT(item.imageHeight / PPI);

			if (CX + DrawWidth > 6.25)
			{
				S += "</div>";
				CX = .2;
				CY += rowHeight;
				if (CY + rowHeight > 10)
				{
					CY = 1.2;
					S += newPageHTML;
				}
				S += createPrintDiv(CX, CY, 7.25, rowHeight, "");
			}
			S += printingImage(item, PPI, CX, CurrentPaint, CurrentGlass, CurrentUI, CurrentLI, DrawWidth, DrawHeight, tempitm.trim);
			CX += DrawWidth;
		}
		CX = .2;
		S += "</div>";
		CY += rowHeight;
		if (CY + .195 > 10)
		{
			S += newPageHTML;
			CY = 1.2;
		}
		S += createPrintDiv(CX, CY, 6.25, .175, "text-align:center;font-size:.15in;");
		S += A[t].desc + "</div>";
		CY += .175
		S += createPrintDiv(CX, CY, 6.25, .03, "");
		S += "</div>";
		CY += .03;
		S += createPrintDiv(CX, CY, 6.25, .04, "");
		S += "<hr style='margin:0;padding:0;' /></div>";
		CY += .04;
		S += createPrintDiv(CX, CY, 6.25, .03, "");
		S += "</div>";
		CY += .13;
		if (CY + rowHeight > 10 && (t+1<A.length) )
		{
			S += newPageHTML;
			CY = 1.2;
		}
	}
	S += PageEnd;
	return S;
}

function QuotePrintHTML()
{
	Manifest.sort(manifestorder);
	var OP = "";
	var PaintPrice = 0;


	var LineItems = new Array();
	for (var t=0;t<Manifest.length;t++)
	{
		var ITM = Manifest[t].item;
		var QTY = Manifest[t].count;
		var unitPrice = ITM.price;
		switch(CurrentPaint)
		{
			case 1:
			case 2:
			PaintPrice += ITM.paintPrice * QTY;
			break;
			case 3:
			PaintPrice += ITM.stainPrice * QTY;
			break;
			case 4:
			PaintPrice += ITM.twoTonePrice * QTY;
		}
		if (Discount <= 0)
		{
		unitPrice *= 1 - Discount;
		}
		if (!(ITM.dontManifest=='N'))
		{
			S = "";
			S += "<tr><td>" + QTY + "</td>";
			S += "<td style='text-align:left;'>" + QuotePrintHTMLAlignmentSplit(ITM.description) + "</td>";
			S += "<td style='text-align:right;'>" + Currency(unitPrice) + "</td>";
			S += "<td style='text-align:right;'>" + Currency(unitPrice * QTY) + "</td></tr>";
			if (Discount > 0)
			{
			unitPrice *= 1 - Discount;
			}
			totalPrice += unitPrice * QTY;
			LineItems.push(S);
		}
	}
	LineItems.push("<tr><td>1</td><td style='text-align:left;'>" + "Finish - " + getPaintName(CurrentPaint) + "</td><td style='text-align:right;'>" + Currency(PaintPrice) + "</td><td style='text-align:right;'>" + Currency(PaintPrice) + "</td></tr>");
	
	var NLI = getNotes();
	
	for (var t=0;t<NLI.length;t++)
	{
	S = "<tr><td><b>NOTE</B></td><td colspan='3'>";
	S += NLI[t] + "</td></tr>";
	LineItems.push(S);
	}






	OP += "<table class='PrintPartsList' style='width:100%;font-size:.15in' border=1><tbody><tr><td><b>QTY</b></td><td><b>Description</b></td><td><b>Unit Price</b></td><td style='text-align:right'><b>Total Price</b></td></tr>";
	var S;
	var totalPrice = 0;
	var count = 0;
	for (var t=0;t<LineItems.length;t++)
	{
	
			if (count > 22)
			{
				S = "</tbody></table>\n";
				S+=($('QuoteFooter').innerHTML);
				S+=("</div></td></tr></tbody></table><span style='height:0; line-height:0;page-break-after: always;' class='breakhere'>&nbsp;</span>");
				S+=("<table class='page'><tbody><tr><td><div style='position:relative;top:0in;left:0in;width:100%;height:100%'>");
				S+=($('QuoteHeader').innerHTML);
				S += "<table class='PrintPartsList' style='width:100%;font-size:.15in' border=1><tbody><tr><td><b>QTY</b></td><td><b>Description</b></td><td><b>Unit Price</b></td><td style='text-align:right'><b>Total Price</b></td></tr>";
				OP += S;
				count = 0;
			}
			S = LineItems[t];
			OP += S;
			count += 1;
	}

	return OP;
}



function QuotePrintHTMLAlignmentSplit(value)
{
if (value.indexOf("(") == -1)
{
return "<span style='float:left'>" + value + "</span>";
}
var returned = "<span style='float:left'>";
var before, after, A;
A = value.split("(");
before = A[0];
after = "(" + A[1];
returned += before + "</span><span style='float:right'>" + after;
returned += "</span>";
return returned;
}



function getPrintManifestDisplay(thing)
{
	var IPP = 1.5/200; 
	var xih = RTT(thing.item.manifestImageHeight * IPP);
	var DivH = xih + .5;

	var item=thing.item;
	var Q = thing.count;
	var div="<td style='width:1.5in;height:" + DivH + "in;text-align:center' valign='top'>";
	div += "<img style='width:1.5in;height:" + xih + "in' src='" + getManifestImageFilename(item, CurrentPaint) + "'><br/>";
	div += "<span style='width:1.4in;height:.2in;font-size:.15in;text-Align:center'>(" + Q + ") x " + item.description + "</span></td>";
	return div;
}

function PrintableVersion(doprint)
{

	var Stack = new Array();
	PrepQuoteHeader();
	Stack.push("<div id='PrintingItOutDiv' class='PrintCloseButton'><div style='position:absolute;top:1px; left: 25%; width:202px; height: 30px; background-Color: #000000;'><button type='submit' onClick='ClosePrintDiv()' class='bgreen twhite' style='position:absolute;font-size:13px;text-decoration:underline;width:198px;height:26px;top:2px;left:2px'>Return to Builder</button></div></div>");
	Stack.push("<div class='PrintSpacer'>&nbsp;</div>");
	Stack.push("<table class='page'><tbody><tr><td><div style='position:relative;top:0in;left:0in;width:100%;height:100%'>");
	Stack.push($('QuoteHeader').innerHTML);
	Stack.push(QuotePrintHTML());
	Stack.push($('QuoteFooter').innerHTML);
	Stack.push("</div></td></tr></tbody></table><span style='height:0; line-height:0;page-break-after: always;' class='breakhere'>&nbsp;</span>");
	Stack.push("<table class='page'><tbody><tr><td><div style='position:relative;top:0in;left:0in;width:100%;height:100%'>");
	Stack.push("<img style='width:6.5in;height:9in;' src='");
	Stack.push(getPorchPrintQS());
	Stack.push("'>");
	Stack.push("</div></td></tr></tbody></table><span style='height:0; line-height:0;page-break-after: always;' class='breakhere'>&nbsp;</span>");
	Stack.push(getQuoteElevationsHTML());
	Stack.push("<span style='height:0; line-height:0;page-break-after: always;' class='breakhere'>&nbsp;</span><table id='LastPage1' class='page'><tbody><tr><td><div style='position:relative;top:0in;left:0in;width:100%;height:100%'>");
	var ElevationHeader = "<div style='position:relative;top:0in;left:0in;width:100%;height:1in;font-size:.35in;text-align:center'>" + ImageLogo  + HeaderCompanyName + "<div class='URLabel' style='position:absolute;top:0in;left:3.6in;width:3.4in;height:.75in'>Porch System <br/>Parts List</div></div><hr />";
	var Page = 1;
	Stack.push(ElevationHeader);
	Stack.push("<table><tbody><tr>")
	var current = 1;

	var lastHeight = Manifest[0].item.manifestImageHeight;
	var curY = 1.25;
	var IPP = 1.5/200;
	curY += .75;
	curY += lastHeight * IPP;

	Manifest.sort(manifestDisplayOrder);



	for (var t=0;t<Manifest.length;t++)
	{
		if (!(Manifest[t].item.dontManifest=='N'))
		{
			if (current > 4  || Manifest[t].item.manifestImageHeight != lastHeight)
			{
				lastHeight = Manifest[t].item.manifestImageHeight;
				curY += .75 + (lastHeight * IPP);
				current = 1;
				Stack.push('</tr><tr>');
				if (curY > 10.00)
				{
					Page += 1;
					CloseAndReopenPrintManifest(Stack, Page, ElevationHeader);
					curY = 1.25 + .75 + (lastHeight * IPP);
				}
			}


			Stack.push(getPrintManifestDisplay(Manifest[t]));
			current += 1;

		}
	}



	Stack.push("</tr></tbody></table>")
	Stack.push("</div></td></tr></tbody></table><span style='height:0; line-height:0;page-break-after: always;' class='breakhere'>&nbsp;</span>");
	
	
	var Div = document.createElement('div');

	
	Div.style.position = "absolute";
	Div.style.top = "0in";
	Div.style.left = "0in";
	
	Div.innerHTML = Stack.join("");
	Div.id = "PrintingItOutDiv";


document.body.style.backgroundColor = "#FFFFFF";

hide('GlobalMainDisplay');
document.body.appendChild(Div);
	
	
	
	$('LastPage' + Page).style.pageBreakAfter = "auto";
	if  (doprint)
	{
		window.print();
	}
}





function ClosePrintDiv()
{
var Old = document.getElementById("PrintingItOutDiv");
document.body.removeChild(Old);
document.body.style.backgroundColor = "#C8B48A";
show('GlobalMainDisplay');
}



function CloseAndReopenPrintManifest(E, Page, ElevationHeader)
{
					E.push("</tr></tbody></table>")
					E.push("</div></td></tr></tbody></table><span style='height:0; line-height:0;page-break-after: always;' class='breakhere'>&nbsp;</span>");
					E.push("<table id='LastPage" + Page + "' class='page'><tbody><tr><td><div style='position:relative;top:0in;left:0in;width:100%;height:100%'>");
					E.push(ElevationHeader);
					E.push("<table><tbody><tr>");
}




function DoorLocationSelected(x)
{
	DorLoc = $(DoorBeingSwitched + "DoorLocation");
	var y=x;
	DorLoc.selectedIndex = y;
	LastSelectedDoorLocation = x;
	for (var t=1;t<=3;t++)
	{
		$('DoorLocationSelected' + t).style.backgroundColor = '#FFFFFF';
	}
	$('DoorLocationSelected' + x).style.backgroundColor = '#FF0000';
	updateShapeImage();
}


function getImageFilename(item, paint)
{
	var value = "/Merchant2/graphics/PorchBI/";
	switch (paint)
	{
		case PaintColors.unpainted:
		value += "N/";
		break;
		case PaintColors.cedartoneStain:
		value += "C/";
		break;
		case PaintColors.white:
		case PaintColors.nantucketWhite:
		value += "w/";
		break;
		case PaintColors.twoToned:
		if (item.partClass == "InsertUpper" || item.partClass == "InsertLower")
		{
			value += "C/";
		}
		else
		{
			value += "w/";
		}
		break;
	}
	value += item.imageFileName;
	return value;
}

function getManifestImageFilename(item, paint)
{
	return "/Merchant2/graphics/PSTemp/" + item.manifestImage;
}





function manifestorder(A, B)
{
	if (A.item.partClass==B.item.partClass)
	{
		if (A.item.description > B.item.description)
		{
			return 1;
		}
		return -1;
	}
	else
	{
		if (A.item.partClass > B.item.partClass)
		{
			return 1;
		}
		return -1;
	}
}

function BackToOptions()
{
	hide('ManifestStage');
	show('ConfigureOptions');
}

function AcceptOptions()
{
	show('ManifestStage');
	hide('ConfigureOptions');
	displayManifest();
}



function manifestDisplayOrder(A, B)
{
if (A.item.manifestImageHeight > B.item.manifestImageHeight)
	{
	return 1;
	}

if (A.item.manifestImageHeight < B.item.manifestImageHeight)
	{
	return -1;
	}

	if (A.item.partClass==B.item.partClass)
	{
		if (A.item.description > B.item.description)
		{
			return 1;
		}
		return -1;
	}
	else
	{
		if (A.item.partClass > B.item.partClass)
		{
			return 1;
		}
		return -1;
	}


}




function getManifestDisplay(thing)
{
	var item=thing.item;
	var Q = thing.count;
	var div=document.createElement('td');
	div.style.width = '200px';
	div.style.height = (item.manifestImageHeight + 22) + 'px';
	div.style.position = 'relative';
	div.style.top = '0px';
	div.style.left = '0px';
	div.style.textAlign='center';
	var i = document.createElement('img');
	i.src = getManifestImageFilename(item, CurrentPaint);
	i.style.width = '200px';
	i.style.height = item.manifestImageHeight + 'px';
	div.appendChild(i);
	div.appendChild(document.createElement('br'));
	var sp = document.createElement('span');
	sp.style.textAlign = 'center';
	var S = thing.count + " X " + item.description;
	sp.innerHTML = S;
	div.appendChild(sp);
	return div;
}

function displayManifest()
{
	Manifest.sort(manifestDisplayOrder);
	var MD = $('ManifestOutput');
	removeAllChildren(MD);
	var tbl, tbd, tbr;
	tbl=document.createElement('table');
	tbl.style.width = '100%';
	tbd = document.createElement('tbody');
	tbr = document.createElement('tr');
	var current = 1;
	var lastHeight = Manifest[0].item.manifestImageHeight;

	for (var t=0;t<Manifest.length;t++)
	{
		if (!(Manifest[t].item.dontManifest=='N'))
		{
			if (current > 4 || Manifest[t].item.manifestImageHeight != lastHeight )
			{
				lastHeight = Manifest[t].item.manifestImageHeight;
				current = 1;
				tbd.appendChild(tbr);
				tbr = document.createElement('tr');
			}
			tbr.appendChild(getManifestDisplay(Manifest[t]));
			current += 1;

		}
	}
	if (current != 1)
	{
		tbd.appendChild(tbr);
	}
	tbl.appendChild(tbd);
	MD.appendChild(tbl);
}

function displayManifestTable()
{
	var TD;
	Manifest.sort(manifestorder);
	var MD = $('ManifestOutput');
	removeAllChildren(MD);
	var tbl=document.createElement('table');
	var tbd=document.createElement('tbody');
	tbl.style.width = '100%';
	tbl.appendChild(tbd);
	var TR = document.createElement('tr');
	createChild(TR, 'td', "<b>QTY</b>");
	createChild(TR, 'td', "<b>Description</b>");
	createChild(TR, 'td', "<b>Image</b>");
	createChild(TR, 'td', "<b>Unit Price</b>");
	createChild(TR, 'td', "<b>Total Price</b>").style.textAlign='right';
	tbd.appendChild(TR);
	var totalPrice = 0;
	for (var t=0;t<Manifest.length;t++)
	{
		var ITM = Manifest[t].item;
		var QTY = Manifest[t].count;
		var unitPrice = ITM.price;
		switch(CurrentPaint)
		{
			case 1:
			case 2:
			unitPrice += ITM.paintPrice;
			break;
			case 3:
			unitPrice += ITM.stainPrice;
			break;
			case 4:
			unitPrice += ITM.twoTonePrice;
		}
		unitPrice *= (1-Discount);
		if (!(ITM.dontManifest=='N'))
		{
			var TR = document.createElement('tr');
			createChild(TR, 'td', QTY);
			createChild(TR, 'td', ITM.description);
			createChild(TR, 'td', "<img src='" + getManifestImageFilename(ITM, CurrentPaint) + "' />");
			createChild(TR, 'td', Currency(unitPrice));
			createChild(TR, 'td', Currency(unitPrice * QTY)).style.textAlign='right';
			totalPrice += unitPrice * QTY;
			tbd.appendChild(TR);
		}
	}
	var TR = document.createElement('tr');
	createChild(TR, 'td', "<b></b>");
	createChild(TR, 'td', "Finish - " + getPaintName(CurrentPaint) + "");
	createChild(TR, 'td', "");
	createChild(TR, 'td', "");
	createChild(TR, 'td', "");
	tbd.appendChild(TR);
	var TR = document.createElement('tr');
	TR.style.backgroundColor = "#DDDDDD";
	createChild(TR, 'td', "<b></b>");
	createChild(TR, 'td', "<b>Total</b>");
	createChild(TR, 'td', "");
	createChild(TR, 'td', "");
	createChild(TR, 'td', Currency(totalPrice)).style.textAlign='right';
	tbd.appendChild(TR);
	MD.appendChild(tbl);
}

function DitmarPrice(size, length, paintColor)
{
	length = (Math.ceil(length*8))/8;
	var ld, ones, et;
	ones = length * 8;
	et = ones % 8;
	ones = ones - et;
	ones /= 8;
	ld = ones;
	if (et != 0)
	{
		ld += " " + et + "/" + 8;
	}
	var X, N;
	if (size==2)
	{
		N = "DITMAR_BEAM_2X8";
	}
	else
	{
		N = "DITMAR_BEAM_2X6";
	}
	N = getPart(N);
	X = new PricedItem(N.name + "_" + ld , N.partClass, length, N.heightGroup, N.price * length / 12, N.Name, N.imageWidth, N.imageHeight, N.upperInsertGroup, N.lowerInsertGroup, N.paintPrice, N.stainPrice, N.twoTonePrice, N.insertsX, N.uiY, N.liY, ld + " inch " + N.description ,N.dontManifest, N.manifestImage, N.weight * length, N.manifestImageHeight);
	ManifestAdd(X, paintColor);
	return X.price;
}

function PopUI()
{
	show('Popup','PopupUI');
	hide('OptionsControl');
}

function PopLI()
{
	show('Popup','PopupLI');
	hide('OptionsControl');
}


function popupUI(value, in_name)
{
	CurrentUI = in_name;
	selectZone("UI", value);
	hide('PopupUI','Popup');
	show('OptionsControl');
	ElevationViewChanged();
	setGlassAvailable();
	UpdatePerspective();
	
}

function popupLI(value, in_name)
{
	CurrentLI = in_name;
	selectZone("LI", value);
	hide('PopupLI','Popup');
	show('OptionsControl');
	ElevationViewChanged();
	setGlassAvailable();
	UpdatePerspective();
}

function setUI(value)
{
	var UIS=new Array("VICTORIANHALF", "QUEENANNEHALF", "DIVIDEDLIGHT", "PANEL");
	CurrentUI = UIS[value-1];
	selectZone("UI", value);
	ElevationViewChanged();
	setGlassAvailable();
	UpdatePerspective();
}

function setLI(value)
{

	var LIS=new Array("VICTORIANBALLUSTER","QUEENANNEBALLUSTER","PANEL","CHIPPENDALEFULL");
	CurrentLI = LIS[value-1];
	selectZone("LI", value);
	ElevationViewChanged();
	setGlassAvailable();
	UpdatePerspective();
}

function setDB(value)
{
	CurrentDitmar = value;
	selectZone("DB", value+1);
	ElevationViewChanged();
}

function setIF(value)
{
	CurrentFrame = (value == 1);
	selectZone("IF", value);
	ElevationViewChanged();
}

function setPaint(value)
{
	CurrentPaint=value-1;
	selectZone("Paint", value);
	ElevationViewChanged();
}

function setSG(value)
{
	CurrentGlass = (value==2);
	selectZone("SG", value);
	ElevationViewChanged();
}

function selectZone(name, number)
{
	var e=1;
	while ($(name + e) != nothing)
	{
		$(name + e).style.backgroundColor = "#FFFFFF";
		e++;
	}
	$(name + number).style.backgroundColor = "#FF0000";
}

function setElevationsAvailable()
{
	var Sel = $('ElevationSelected');
	clearOptions(Sel);
	addOption(Sel, "Front Wall", WallLocations.front);
	if (Design.LS)
	{
		addOption(Sel, "Left Wall", WallLocations.left);
	}
	if (Design.RS)
	{
		addOption(Sel, "Right Wall", WallLocations.right);
	}
	if (Design.C)
	{
		addOption(Sel, "Corners", WallLocations.leftcorner);
	}
	ElevationViewChanged();
}

function ChangePriceLabel()
{
	var Price = getPorchPrice(CurrentPaint, CurrentGlass, CurrentUI, CurrentLI, CurrentDitmar, CurrentFrame);
	$('DisplayPrice').innerHTML = Currency(Price);
}

function ElevationViewChanged()
{
	if ($('ElevationSelected').options.length < 1)
	{
		return;
	}
	var target=selectedValue($('ElevationSelected'));
	var ED = $('Elevations');
	removeAllChildren(ED);
	var adiv;
	if (target == WallLocations.leftcorner || target == WallLocations.rightcorner)
	{
		if (Design.WallConfigurations[target] == nothing)
		{
			target = WallLocations.rightcorner;
		}
		adiv=getElevations(Design.WallConfigurations[target][0].Parts, CurrentPaint, CurrentGlass, CurrentUI, CurrentLI);
	}
	else
	{
		adiv=getElevations(currentConfig(target).Parts, CurrentPaint, CurrentGlass, CurrentUI, CurrentLI);
	}
	ED.appendChild(boxUp(adiv));
	ChangePriceLabel();
}

function boxUp(div, ilabel)
{
	var border, container, label;
	border = document.createElement('div');
	container = document.createElement('div');
	container.style.height = parseInt(div.style.height) + 4;
	container.style.width = 996;
	container.style.backgroundColor = '#FFFFFF';
	container.style.position = 'absolute';
	container.style.top = '2px';
	container.style.left = '2px';
	border.style.backgroundColor = '#000000';
	border.style.width = '1000px';
	border.style.position = 'relative';
	border.style.top = '0px';
	border.style.left = '0px';
	border.style.height = parseInt(div.style.height) + 8;
	container.appendChild(div);
	border.appendChild(container);
	return border;
}

function locatedImage(filename, width, height, position, left, top, Z, title)
{
	var Image = document.createElement('img');
	Image.src = filename;
	Image.style.width = width;
	Image.style.height = height;
	Image.style.position = position;
	Image.style.left = left;
	Image.style.top = top;
	Image.style.zIndex = Z;
	Image.title = title;
	return Image;
}

function getElevations(partsArray, paintColor, hasGlass, UI, LI)
{
	var HolderDiv = document.createElement('div');
	HolderDiv.style.position='relative';
	HolderDiv.style.left='0px';
	HolderDiv.style.top='0px';
	HolderDiv.style.width='992px';

	var MainDiv = document.createElement('div');
	MainDiv.style.position='absolute';
	MainDiv.style.left='200px';
	MainDiv.style.top='0px';
	MainDiv.style.overflow='auto';
	MainDiv.style.width='792px';
	var X=0;
	var Target;
	var img;
	var mainH = 0;
	for (var t=0;t<partsArray.length;t++)
	{
		{
			Target = getImage(partsArray[t], paintColor, hasGlass, UI, LI);
			Target.div.style.left = X;
			Target.div.style.position = 'absolute';
			X += parseInt(Target.div.style.width);
			mainH = Math.max(parseInt(Target.div.style.height), mainH);
			MainDiv.appendChild(Target.div);
		}
	}
	MainDiv.style.margin = "0 auto";
	if (X <= 792)
	{
		MainDiv.style.height = mainH;
		MainDiv.style.width = X+'px';
		MainDiv.style.left = (200 + ((792-X)/2)) + 'px';
		HolderDiv.style.height = mainH;
	}
	else
	{
		MainDiv.style.height = mainH + 20;
		HolderDiv.style.height = mainH + 20;
	}

	var Black = document.createElement('img');
	Black.style.position = 'absolute';
	Black.style.top = '0px';
	Black.style.left = '0px';
	Black.style.width = '180px';
	Black.style.height = mainH + 'px';
	
	
	Black.src = "http://secure.vixenhill.com/Gazebos/SideView.aspx?H=" + mainH + "&P=" + getPanelHeight();
	if (CurrentDitmar != 0)
	{
	Black.src += "&D=TRUE";
	}

	

	fixChildren(MainDiv);

	HolderDiv.appendChild(Black);
	HolderDiv.appendChild(MainDiv);

	return HolderDiv;
}

function DivItem(div, item)
{
	this.div = div;
	this.item = item;
}

function removeAllChildren(cell)
{
	if ( cell.hasChildNodes() )
	{
		while ( cell.childNodes.length >= 1 )
		{
			cell.removeChild( cell.firstChild );
		}
	}
}

function ManifestAdd(in_item, in_paint)
{
	if (ManIndex[in_item.name] == nothing)
	{
		ManIndex[in_item.name] = Manifest.length;
		Manifest.push(new Count(in_item, in_paint));
	}
	else
	{
		Manifest[ManIndex[in_item.name]].count += 1;
	}
}

function Count(in_item, in_paint)
{
	this.item = in_item;
	this.paint = in_paint;
	this.count = 1;
}

function getPaintName(value)
{
	switch (value)
	{
		case 0: return 'Unpainted';
		break;
		case 1: return 'White';
		break;
		case 2: return 'Nantucket White';
		break;
		case 3: return 'Cedartone Stain';
		break;
		case 4: return 'Two Toned';
		break;
	}
	return value;
}

function getPorchPrice(paintColor, hasGlass, UpperInsert, lowerInsert, ditmarBeam, reverseFrame)
{
	ManIndex = new Array();
	Manifest = new Array();
	var Total = 0;

	if (IncludeRoof)
		{
		Total = getPrice("MudRoomRoof" + CurrentRoofStyle + CurrentRoofMaterial, paintColor, false, false, false, false);
		}

	var ATG;
	var P = new post();
	P = P.partName;

	Total += getPartPrices(currentConfig(WallLocations.front).Parts, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
	if (ditmarBeam)
	{
		ATG = currentConfig(WallLocations.front).wall.runlength;
		Total += DitmarPrice(ditmarBeam, ATG, paintColor)
	}
	if (Design.RS)
	{
		Total += getPartPrices(currentConfig(WallLocations.right).Parts, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
		if (!Design.C)
		{
			Total += getPrice(P, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
		}
		if (ditmarBeam)
		{
			ATG = currentConfig(WallLocations.right).wall.runlength;
			Total += DitmarPrice(ditmarBeam, ATG, paintColor);
		}
		if (Design.C)
		{
			Total += getPartPrices(currentConfig(WallLocations.rightcorner).Parts, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
			if (ditmarBeam)
			{
				ATG = currentConfig(WallLocations.rightcorner).wall.runlength;
				Total += DitmarPrice(ditmarBeam, ATG, paintColor);
			}
		}
	}
	if (Design.LS)
	{
		Total += getPartPrices(currentConfig(WallLocations.left).Parts, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
		if (!Design.C)
		{
			Total += getPrice(P, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
		}
		if (ditmarBeam)
		{
			ATG = currentConfig(WallLocations.left).wall.runlength;
			Total += DitmarPrice(ditmarBeam, ATG, paintColor);
		}
		if (Design.C)
		{
			Total += getPartPrices(currentConfig(WallLocations.leftcorner).Parts, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
			if (ditmarBeam)
			{
				ATG = currentConfig(WallLocations.leftcorner).wall.runlength;
				Total += DitmarPrice(ditmarBeam, ATG, paintColor);
			}
		}
	}
	if (Design.C)
	{
		Manifest[ManIndex["EP45-" + getHeightGroup()]].count /= 2;
		Total -= getPrice("EP45-" + getHeightGroup(), ATG, paintColor) * Manifest[ManIndex["EP45-" + getHeightGroup()]].count;
		Manifest[ManIndex["EP45-" + getHeightGroup()]].count -= 1;
	}
	return Total * (1-Discount);
}

function getPartPrices(array, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame)
{
	var total = 0;
	for (var g=0;g<array.length;g++)
	{
		if (array[g].partName == nothing)
		{
		}
		total += getPrice(array[g].partName, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
	}
	return total;
}

function getPart(partName)
{
	if (Prices[partName + getHeightGroup()])
	{
		return Prices[partName + getHeightGroup()];
	}
	else
	{
		return Prices[partName];
	}
}

function getPrice(partName, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame)
{
	var X = getPart(partName);
	if (X==nothing)
	{
		return 0;
	}
	var returned = X.price;
	if (paintColor == 1 || paintColor == 2)
	{
		returned += X.paintPrice;
	}
	if (paintColor == 3)
	{
		returned += X.stainPrice;
	}
	if (paintColor == 4)
	{
		returned += X.twoTonePrice;
	}
	var pN;
	if (X.upperInsertGroup != "X" && X.upperInsertGroup != "Z")
	{
		if (hasGlass && getPart("UI-" + UpperInsert + "-" + X.upperInsertGroup).upperInsertGroup !="Z")
		{
			pN = "UGLASS-" + X.upperInsertGroup;
			returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
		}
		if (getPart("UI-" + UpperInsert + "-" + X.upperInsertGroup).upperInsertGroup !="Z")
		{
			pN = "USCREEN-" + X.upperInsertGroup;
			returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
		}
		if (reverseFrame)
		{
			pN = "URF-" + X.upperInsertGroup;
			returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
		}
		pN = "UI-" + UpperInsert + "-" + X.upperInsertGroup;
		returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
	}
	if (X.lowerInsertGroup != "X" && X.lowerInsertGroup != "Z")
	{
		if (hasGlass && getPart("LI-" + lowerInsert + "-" + X.lowerInsertGroup).lowerInsertGroup !="Z")
		{
			pN = "LGLASS-" + X.lowerInsertGroup;
			returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
		}
		if (getPart("LI-" + lowerInsert + "-" + X.lowerInsertGroup).lowerInsertGroup !="Z")
		{
			pN = "LSCREEN-" + X.lowerInsertGroup;
			returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
		}
		if (reverseFrame)
		{
			pN = "LRF-" + X.upperInsertGroup;
			returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
		}
		pN = "LI-" + lowerInsert + "-" + X.lowerInsertGroup;
		returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame);
	}
	ManifestAdd(X, paintColor);
	return returned;
}

function getPriceItem(object)
{
	var HG = getHeightGroup();
}


function getPanelHeight()
{

	
	var sel = $('selectHeight');
	var H = parseInt(sel.options[sel.selectedIndex].value);

	sel = $('selectHeightE');
	H += parseFloat(sel.options[sel.selectedIndex].value);


	if (CurrentDitmar == 0)
		{
		H -= .75;
		}

	return H;
}

function getHeightGroup()
{



	var H = getPanelHeight();
	if (H <= 85)
	{
		return "A";
	}
	if (H <= 81)
	{
		return "B";
	}
	if (H <= 96)
	{
		return "C";
	}
	if (H <= 100)
	{
		return "D";
	}
	if (H <= 106)
	{
		return "G";
	}
	if (H <= 111)
	{
		return "H";
	}
	return "I";
}

function getSolutions(Wall)
{
	if (Wall.doorLocation == DoorLocations.none)
	{
		return getSolutionsNoDoor(Wall);
	}
	if (Wall.doorLocation == DoorLocations.centered)
	{
		return getSolutionsMidDoor(Wall);
	}
	return getSolutionsEndDoor(Wall);
}

function getSolutionsNoDoor(Wall)
{
	var Solutions = new Array();
	var FunctionalLength;
	var S;
	for (FEP=0;FEP<Wall.usableParts.ForeEndPosts.length;FEP++)
	{
		for (REP=0;REP<Wall.usableParts.RearEndPosts.length;REP++)
		{
			for (JP=0;JP<Wall.usableParts.JoiningPosts.length;JP++)
			{
				for (WP=0;WP<WallPanels.length;WP++)
				{
					CFEP = Wall.usableParts.ForeEndPosts[FEP];
					CREP = Wall.usableParts.RearEndPosts[REP];
					CJP = Wall.usableParts.JoiningPosts[JP];
					CWP1 = WallPanels[WP];
					FunctionalLength = Wall.runlength;
					FunctionalLength -= CFEP.runlength;
					FunctionalLength -= CREP.runlength;
					S = CheckDistances(FunctionalLength, CWP1, CJP, Wall.wingWallMin, Wall.wingWallMax, 0);
					if (S)
					{
						Solutions.push(new solution(CWP1, S.cWP1, nothing, 0, CJP, CFEP, CREP, S.WingWall));
					}
					if (Wall.wingWallMin > 0)
					{
						S = CheckDistances(FunctionalLength, CWP1, CJP, 0, 0, 0);
						if (S)
						{
							Solutions.push(new solution(CWP1, S.cWP1, nothing, 0, CJP, CFEP, CREP, S.WingWall));
						}
					}
					for (WP2=WP+1;WP2<WallPanels.length;WP2++)
					{
						CWP2 = WallPanels[WP2];
						S = CheckDistancesTwoPanel(FunctionalLength, CWP1, CWP2, CJP, Wall.wingWallMin, Wall.wingWallMax, 0);
						if (S)
						{
							Solutions.push(new solution(CWP1, S.cWP1, CWP2, S.cWP2, CJP, CFEP, CREP, S.WingWall));
						}
						if (Wall.wingWallMin > 0)
						{
							S = CheckDistancesTwoPanel(FunctionalLength, CWP1, CWP2, CJP, 0, 0, 0);
							if (S)
							{
								Solutions.push(new solution(CWP1, S.cWP1, CWP2, S.cWP2, CJP, CFEP, CREP, S.WingWall));
							}
						}
					}
				}
			}
		}
	}
	return Solutions;
}

function CheckDistances(runlength, WP, JP, WWMin, WWMax, availableTrim)
{
	var Panels = 1;
	var e;
	e = PanelComboLength(Panels, WP, JP, WWMin, WWMax);
	while (e.min - availableTrim < runlength)
	{
		if (e.min - availableTrim <= runlength & e.max >= runlength)
		{
			var Z = WP.runlength * Panels;
			Z += (Panels - 1) * (JP.runlength);
			Z += WWMin;
			Z -= runlength;
			var result = new Object();
			result.cWP1 = Panels;
			if (Z < 0)
			{
				result.WingWall = WWMin - Z;
			}
			else
			{
				result.WingWall = WWMin;
			}
			return result;
		}
		Panels++;
		e = PanelComboLength(Panels, WP, JP, WWMin, WWMax);
	}
	return false;
}

function CheckDistancesTwoPanel(runlength, WP, WP2, JP, WWMin, WWMax, availableTrim)
{
	if (WP2.runlength > WP.runlength)
	{
		var Buffer = WP1;
		WP1 = WP2;
		WP2 = Buffer;
	}
	var P1, P2;
	P1 = 1;
	P2 = 1;
	var e = PanelComboLength2(P1, P2, WP, WP2, JP, WWMin, WWMax);
	while (e.min - availableTrim <= runlength)
	{
		var innerE;
		innerE = e;
		while (innerE.min - availableTrim <= runlength)
		{
			if (innerE.min - availableTrim <= runlength && innerE.max >= runlength)
			{
				var WW = WWMin;
				var UL = P1 * (WP.runlength);
				UL += P2 * (WP2.runlength);
				UL += JP.runlength * (P1 + P2 - 1);
				UL += WWMin;
				if (UL < runlength)
				{
					UL = runlength - UL;
					UL += WWMin;
				}
				else
				{
					UL = WWMin;
				}
				if (UL < WWMin || UL > WWMax)
				{
					var X;
					X = 7;
				}
				var result = new Object();
				result.cWP1 = P1;
				result.cWP2 = P2;
				result.WingWall = UL;
				return result;
			}
			P2 += 1;
			innerE = PanelComboLength2(P1, P2, WP, WP2, JP, WWMin, WWMax);
		}
		P1 += 1;
		P2 = 1;
		e = PanelComboLength2(P1, P2, WP, WP2, JP, WWMin, WWMax);
	}
	return false;
}

function getSolutionsEndDoor(Wall)
{
	var Solutions = new Array();
	var FunctionalLength;
	var S;
	for (FEP=0;FEP<Wall.usableParts.ForeEndPosts.length;FEP++)
	{
		for (REP=0;REP<Wall.usableParts.RearEndPosts.length;REP++)
		{
			for (JP=0;JP<Wall.usableParts.JoiningPosts.length;JP++)
			{
				for (WP=0;WP<WallPanels.length;WP++)
				{
					CFEP = Wall.usableParts.ForeEndPosts[FEP];
					CREP = Wall.usableParts.RearEndPosts[REP];
					CJP = Wall.usableParts.JoiningPosts[JP];
					CWP1 = WallPanels[WP];
					var DoorOnly;
					if (!Wall.usableParts.Door.needsSpecialEndPost)
					{
						DoorOnly = CFEP.runlength;
						DoorOnly += CREP.runlength;
					}
					DoorOnly += Wall.usableParts.Door.runlength;
					var DMax = DoorOnly;
					var DMin = DoorOnly - Wall.usableParts.Door.maxTrim;
					var ANoWW, AWW;
					ANoWW = false;
					AWW = false;
					if (DMax >= Wall.runlength && DMin <= Wall.runlength)
					{
						ANoWW = true;
					}
					var DWMax = DoorOnly + Wall.wingWallMax;
					var DWMin = DoorOnly + Wall.wingWallMin - Wall.usableParts.Door.maxTrim;
					if (DWMax >= Wall.runlength && DWMin <= Wall.runlength)
					{
						AWW = true;
					}
					if (ANoWW || AWW)
					{
						if (ANoWW)
						{
							Solutions.push(new solution(CWP1, 0, nothing, 0, CJP, CFEP, CREP, 0));
						}
						else
						{
							Solutions.push(new solution(CWP1, 0, nothing, 0, CJP, CFEP, CREP, Wall.runlength - DMax));
						}
					}
					else
					{
						DoorTrim = Wall.usableParts.Door.maxTrim;
						FunctionalLength = Wall.runlength;
						FunctionalLength -= Wall.usableParts.Door.runlength;
						FunctionalLength -= CREP.runlength;
						if (!Wall.usableParts.Door.needsSpecialEndPost)
						{
							FunctionalLength -= CFEP.runlength;
							FunctionalLength -= CJP.runlength;
						}
						else
						{
							FunctionalLength -= Wall.usableParts.Door.specialEndPost.runlength;
						}
						S = CheckDistances(FunctionalLength, CWP1, CJP, Wall.wingWallMin, Wall.wingWallMax, DoorTrim);
						if (S)
						{
							Solutions.push(new solution(CWP1, S.cWP1, nothing, 0, CJP, CFEP, CREP, S.WingWall));
						}
						if (Wall.wingWallMin > 0)
						{
							S = CheckDistances(FunctionalLength, CWP1, CJP, 0, 0, DoorTrim);
							if (S)
							{
								Solutions.push(new solution(CWP1, S.cWP1, nothing, 0, CJP, CFEP, CREP, S.WingWall));
							}
						}
						for (WP2=WP+1;WP2<WallPanels.length;WP2++)
						{
							CWP2 = WallPanels[WP2];
							S = CheckDistancesTwoPanel(FunctionalLength, CWP1, CWP2, CJP, Wall.wingWallMin, Wall.wingWallMax, DoorTrim);
							if (S)
							{
								Solutions.push(new solution(CWP1, S.cWP1, CWP2, S.cWP2, CJP, CFEP, CREP, S.WingWall));
							}
							if (Wall.wingWallMin > 0)
							{
								S = CheckDistancesTwoPanel(FunctionalLength, CWP1, CWP2, CJP, 0, 0, DoorTrim);
								if (S)
								{
									Solutions.push(new solution(CWP1, S.cWP1, CWP2, S.cWP2, CJP, CFEP, CREP, S.WingWall));
								}
							}
						}
					}
				}
			}
		}
	}
	return Solutions;
}

function getSolutionsMidDoor(Wall)
{
	var Solutions = new Array();
	var FunctionalLength;
	var S;
	for (FEP=0;FEP<Wall.usableParts.ForeEndPosts.length;FEP++)
	{
		for (REP=0;REP<Wall.usableParts.RearEndPosts.length;REP++)
		{
			for (JP=0;JP<Wall.usableParts.JoiningPosts.length;JP++)
			{
				for (WP=0;WP<WallPanels.length;WP++)
				{
					CFEP = Wall.usableParts.ForeEndPosts[FEP];
					CREP = Wall.usableParts.RearEndPosts[REP];
					CJP = Wall.usableParts.JoiningPosts[JP];
					CWP1 = WallPanels[WP];
					var DoorOnly;
					if (!Wall.usableParts.Door.needsSpecialEndPost)
					{
						DoorOnly = CFEP.runlength;
						DoorOnly += CREP.runlength;
					}
					DoorOnly += Wall.usableParts.Door.runlength;
					var DMax = DoorOnly;
					var DMin = DoorOnly - Wall.usableParts.Door.maxTrim;
					var ANoWW, AWW;
					ANoWW = false;
					AWW = false;
					if (DMax >= Wall.runlength && DMin <= Wall.runlength)
					{
						ANoWW = true;
					}
					var DWMax = DoorOnly + Wall.wingWallMax;
					var DWMin = DoorOnly + Wall.wingWallMin - Wall.usableParts.Door.maxTrim;
					if (DWMax >= Wall.runlength && DWMin <= Wall.runlength)
					{
						AWW = true;
					}
					if (ANoWW || AWW)
					{
						if (ANoWW)
						{
							Solutions.push(new solution(CWP1, 0, nothing, 0, CJP, CFEP, CREP, 0));
						}
						else
						{
							Solutions.push(new solution(CWP1, 0, nothing, 0, CJP, CFEP, CREP, Wall.runlength - DMax));
						}
					}
					else
					{
						DoorTrim = Wall.usableParts.Door.maxTrim;
						FunctionalLength = Wall.runlength;
						FunctionalLength -= Wall.usableParts.Door.runlength;
						FunctionalLength -= CREP.runlength;
						FunctionalLength -= CFEP.runlength;
						if (!Wall.usableParts.Door.needsSpecialEndPost)
						{
							FunctionalLength -= CJP.runlength * 2;
						}
						else
						{
							FunctionalLength -= Wall.usableParts.Door.specialEndPost.runlength * 2;
						}
						FunctionalLength /= 2;
						S = CheckDistances(FunctionalLength, CWP1, CJP, Wall.wingWallMin/2, Wall.wingWallMax/2, DoorTrim/2);
						if (S)
						{
							Solutions.push(new solution(CWP1, S.cWP1 * 2, nothing, 0, CJP, CFEP, CREP, S.WingWall * 2));
						}
						if (Wall.wingWallMin > 0)
						{
							S = CheckDistances(FunctionalLength, CWP1, CJP, 0, 0, DoorTrim/2);
							if (S)
							{
								Solutions.push(new solution(CWP1, S.cWP1 * 2, nothing, 0, CJP, CFEP, CREP, S.WingWall));
							}
						}
						for (WP2=WP+1;WP2<WallPanels.length;WP2++)
						{
							CWP2 = WallPanels[WP2];
							S = CheckDistancesTwoPanel(FunctionalLength, CWP1, CWP2, CJP, Wall.wingWallMin/2, Wall.wingWallMax/2, DoorTrim/2);
							if (S)
							{
								Solutions.push(new solution(CWP1, S.cWP1 * 2, CWP2, S.cWP2 * 2, CJP, CFEP, CREP, S.WingWall * 2));
							}
							if (Wall.wingWallMin > 0)
							{
								S = CheckDistancesTwoPanel(FunctionalLength, CWP1, CWP2, CJP, 0, 0, DoorTrim/2);
								if (S)
								{
									Solutions.push(new solution(CWP1, S.cWP1 * 2, CWP2, S.cWP2 * 2, CJP, CFEP, CREP, S.WingWall));
								}
							}
						}
					}
				}
			}
		}
	}
	return Solutions;
}

function PanelComboLength(Panels, WP, JP, WWMin, WWMax)
{
	var result = new Object();
	result.min = Panels * (WP.runlength - WP.maxTrim);
	result.min += (Panels - 1) * JP.runlength;
	result.min += WWMin;
	result.max = Panels * WP.runlength;
	result.max += (Panels - 1) * JP.runlength;
	result.max += WWMax;
	return result;
}

function PanelComboLength2(Panels1, Panels2, WP1, WP2, JP, WWMin, WWMax)
{
	var result = new Object();
	result.min = Panels1 * (WP1.runlength - WP1.maxTrim);
	result.min += Panels2 * (WP2.runlength - WP2.maxTrim);
	result.min += (Panels1 + Panels2 - 1) * JP.runlength;
	result.min += WWMin;
	result.max = Panels1 * WP1.runlength;
	result.max += Panels2 * WP2.runlength;
	result.max += (Panels1 + Panels2 - 1) * JP.runlength;
	result.max += WWMax;
	return result;
}

function span(inLength, inForeEndPosts, inRearEndPosts, inJoiningPosts, inAllowWingWall, inWWMin, inWWMax, inDoorLocation, inDoor)
{
	this.className = "Span";
	this.runlength = inLength;
	this.usableParts = new Object();
	this.usableParts.ForeEndPosts = inForeEndPosts;
	this.usableParts.RearEndPosts = inRearEndPosts;
	this.usableParts.JoiningPosts = inJoiningPosts;
	this.usableParts.Door = inDoor;
	this.allowWingWall = inAllowWingWall;
	this.wingWallMin = inWWMin;
	this.wingWallMax = inWWMax;
	this.doorLocation = inDoorLocation;
}

function post()
{
	this.className = "Post";
	this.partName = "POST-";
}

function solution(inWallPanel1, inWallPanel1Count, inWallPanel2, inWallPanel2Count, inJoiningPost, inForeEndPost, inRearEndPost, inWW)
{
	this.className = "Solution";
	this.wallPanel1 = inWallPanel1;
	this.wallPanel2 = inWallPanel2;
	this.wallPanel1Count = inWallPanel1Count;
	this.wallPanel2Count = inWallPanel2Count;
	if (inWallPanel2 != nothing)
	{
		this.panelTypeCount = 2;
	}
	else
	{
		this.panelTypeCount = 1;
	}
	this.joiningPost = inJoiningPost;
	this.foreEndPost = inForeEndPost;
	this.rearEndPost = inRearEndPost;
	if (inWW > 0)
	{
		this.usesWingWall = true;
		this.wingWallLength = inWW;
	}
	else
	{
		this.usesWingWall = false;
		this.wingWallLength = 0;
	}
this.description = function()
{
	var S = "";
	if (this.wallPanel2 != nothing)
	{
		S = this.wallPanel1.runlength + " and " + this.wallPanel2.runlength + " inch panels";
	}
	else
	{
		S = this.wallPanel1.runlength + " inch panels";
	}
	if (this.usesWingWall)
	{
		S += " w/ Wing Wall";
	}
	return S;
}
}

function endPost(inLength, inIsAngledCut, inIsModular, inPartName)
{
	this.className = "EndPost";
	this.runlength = inLength;
	this.isAngledCut = inIsAngledCut;
	this.isModular = inIsModular;
	this.partName = inPartName;
this.clone = function()
{
var Doppel = new endPost(this.runlength, this.isAngledCut, this.isModular, this.partName);
Doppel.facesForward = this.facesForward;
return Doppel;
}
this.queryString = function()
{
	var S;
	if (this.isAngledCut)
	{
		if (this.facesForward)
		{
			S = "MEP45-";
		}
		else
		{
			S = "RMEP45-";
		}
	}
	else
	{
		if (this.facesForward)
		{
			if (this.isModular)
			{
				S = "MEP-";
			}
			else
			{
				S = "EP-";
			}
		}
		else
		{
			if (this.isModular)
			{
				S = "RMEP-";
			}
			else
			{
				S = "REP-";
			}
		}
	}
	return S + this.runlength;
}
}

function Door(inSpecialEndPost, inLength, inDoorLength, inIsDouble, inMaxTrim, inPartName, inRightHinged)
{
this.clone = 
function ()
{
	var clone = new Door(this.specialEndPost, this.runlength, this.doorLength, this.isDouble, this.maxTrim, this.partName, this.rightHinged);
	clone.opensInward = this.opensInward;
	clone.trim = this.trim;
	return clone;
}
this.rightHinged = inRightHinged;
this.partName = inPartName;
this.opensInward = false;
this.className = "Door";
if (inSpecialEndPost != nothing && inSpecialEndPost.className == "EndPost")
{
	this.needsSpecialEndPost = true;
	this.specialEndPost = inSpecialEndPost;
}
else
{
	this.needsSpecialEndPost = false;
}
this.runlength = inLength;
this.doorLength = inDoorLength;
this.isDouble = inIsDouble;
this.maxTrim = inMaxTrim;
this.queryString = function()
{
	var S = "";
	if (this.opensInward)
	{
		S = "I";
	}
	S += "DP-" + (this.runlength - this.trim) + "-" + this.doorLength;
	if (this.isDouble)
	{
		S += "-D";
	}
	else
	{
		S += "-S";
	}
	if (this.rightHinged)
	{
		S += "-R";
	}
	return S;
}
this.description = function()
{
	var S = "A ";
	S += inDoorLength + " inch";
	if (this.needsSpecialEndPost)
	{
		S += " freehung";
	}
	if (this.isDouble)
	{
		S += " double";
	}
	S += " door";
	return S;
}
}

function WingWall(inLength)
{
	this.partName = "WingWall";
	this.className = "WingWall";
	this.runlength = inLength;
this.queryString = function()
{
	return "WW-" + this.runlength;
}
this.clone = function()
{
return new WingWall(this.runlength);
}
}


function PUSHONEPANEL(ST, WP, C, JP)
{
for (var t=1;t<=C;t++)
	{
	ST.push(WP.clone());
	ST.push(JP.clone());
	}
ST.pop();
return ST;
}




function EVENEVEN(ST, WP1, WP1C, WP2, WP2C, LEFT, JP)
{
if (WP1C > WP2C)
	{
	MWP = WP1;
	MWPC = WP1C;
	LWP = WP2;
	LWPC = WP2C;
	}
else
	{
	MWP = WP2;
	MWPC = WP2C;
	LWP = WP1;
	LWPC = WP1C;
	}

if (MWPC == LWPC)
	{
	if (LEFT)
		{
		ST.push(MWP.clone());
		ST.push(JP.clone());
		return ODDTOTALPUSHPANELS(ST, MWP, MWPC-1, LWP, LWPC, LEFT, JP);
		}
		else
		{
		ST = ODDTOTALPUSHPANELS(ST, MWP, MWPC-1, LWP, LWPC, LEFT, JP);
		ST.push(JP.clone());
		ST.push(MWP.clone());
		}
	}
else
	{
	}

var RemainingMWP = MWPC - (LWPC + 1);
var FC, RC;
RC = Math.floor(RemainingMWP / 2);
FC = RC;
if (FC + RC < RemainingMWP)
{
RC += 1;
}
if (LEFT)
	{var Buf = FC;
	FC = RC;
	RC = Buf;
	}

for (var t=1;t<=FC;t++)
	{
	ST.push(MWP.clone());
	ST.push(JP.clone());
	}
	
	ST = PUSHPANELS(ST, MWP, LWPC+1, LWP, LWPC, LEFT, JP);
	ST.push(JP.clone());

for (var t=1;t<=RC;t++)
	{
	ST.push(MWP.clone());
	ST.push(JP.clone());
	}

ST.pop();
return ST;


}


function ODDODD(ST, WP1, WP1C, WP2, WP2C, LEFT, JP)
{
if (WP1C > WP2C)
	{
	MWP = WP1;
	MWPC = WP1C;
	LWP = WP2;
	LWPC = WP2C;
	}
else
	{
	MWP = WP2;
	MWPC = WP2C;
	LWP = WP1;
	LWPC = WP1C;
	}

if (LEFT)
	{
	ST.push(MWP.clone());
	ST.push(JP.clone());
	}

	ST = PUSHPANELS(ST, MWP, MWPC-1, LWP, LWPC, LEFT, JP);

if (!LEFT)
	{
	ST.push(JP.clone());
	ST.push(MWP.clone());
	}




return ST;
}


function EVENTOTALPUSHPANELS(ST, WP1, WP1C, WP2, WP2C, LEFT, JP)
{

if (WP1C % 2 == 1)
	{return ODDODD(ST, WP1, WP1C, WP2, WP2C, LEFT, JP);}
else
	{return EVENEVEN(ST, WP1, WP1C, WP2, WP2C, LEFT, JP);}
}



function ODDTOTALPUSHPANELS(ST, WP1, WP1C, WP2, WP2C, LEFT, JP)
{

if (WP1C > WP2C)
	{
	MWP = WP1;
	MWPC = WP1C;
	LWP = WP2;
	LWPC = WP2C;
	}
else
	{
	MWP = WP2;
	MWPC = WP2C;
	LWP = WP1;
	LWPC = WP1C;
	}

var NOS = LWPC;
var STANDARDMWPSEC = Math.floor(MWPC / (NOS + 1));
var EXTRAS = MWPC - (STANDARDMWPSEC * (NOS+1));
var C = new Array();
for (var t=1;t<=NOS+1;t++)
	{
	C.push(STANDARDMWPSEC);
	}

var FE, RE;
FE = 0;
RE = C.length -1;

while (EXTRAS > 0)
	{
	C[FE] += 1;
	FE += 1;
	EXTRAS -= 1;
	if (EXTRAS > 0)
		{
		C[RE] -= 1;
		RE -= 1;
		EXTRAS -=1;
		}
	
	}

for (var t=0;t<C.length;t++)
	{
	for (var x=1;x <= C[t];x++)
		{
		ST.push(MWP.clone());
		ST.push(JP.clone());
		}
	ST.push(LWP.clone());
	ST.push(JP.clone());
	}

ST.pop();
ST.pop();
ST.pop();
return ST;
}



function PUSHPANELS(ST, WP1, WP1C, WP2, WP2C, LEFT, JP)
{
if (WP2C == 0)
	{return PUSHONEPANEL(ST, WP1, WP1C, JP);}
if (WP1C == 0)
	{return PUSHONEPANEL(ST, WP2, WP2C, JP);}


if ((WP1C + WP2C) % 2 == 1)
	{return ODDTOTALPUSHPANELS(ST, WP1, WP1C, WP2, WP2C, LEFT, JP);}
else
	{return EVENTOTALPUSHPANELS(ST, WP1, WP1C, WP2, WP2C, LEFT, JP);}


return ST;
}


function DoorOnly(STACK, DOOR, FEP, REP)
{
	var B;
	if (DOOR.needsSpecialEndPost)
	{
		STACK.push(DOOR.clone());
	}
	else
	{
		B = FEP.clone();
		B.facesForward = true;
		STACK.push(B);
		STACK.push(DOOR);
		B = REP.clone();
		B.facesForward = false;
		STACK.push(B);
	}
return STACK;
}


function NoDoor(ST, WP1, WP1C, WP2, WP2C, FEP, REP, JP, LEFT)
{
		var B;
		B = FEP.clone();
		B.facesForward = true;
		ST.push(B);
		ST = PUSHPANELS(ST, WP1, WP1C, WP2, WP2C, LEFT, JP);
		B = REP.clone();
		B.facesForward = false;
		ST.push(B);
		return ST;
}


function LeftDoor(ST, DOOR, WP1, WP1C, WP2, WP2C, FEP, REP, JP, LEFT)
{
var B;
	if (DOOR.needsSpecialEndPost)
	{
		ST.push(DOOR.clone());
		B = FEP.clone();
		B.facesForward = true;
		STACK.push(B);
	}
	else
	{
		B = FEP.clone();
		B.facesForward = true;
		ST.push(B);
		ST.push(DOOR.clone());
		ST.push(JP.clone());
	}
	ST = PUSHPANELS(ST, WP1, WP1C, WP2, WP2C, LEFT, JP);
	B = REP.clone();
	B.facesForward = false;
	ST.push(B);
	return ST;
}


function RightDoor(ST, DOOR, WP1, WP1C, WP2, WP2C, FEP, REP, JP, LEFT)
{
var B;
	B = FEP.clone();
	B.facesForward = true;
	ST.push(B);
	ST = PUSHPANELS(ST, WP1, WP1C, WP2, WP2C, LEFT, JP);


	if (DOOR.needsSpecialEndPost)
	{
		B = REP.clone();
		B.facesForward = false;
		ST.push(B);
		ST.push(DOOR.clone());

	}
	else
	{
		ST.push(JP.clone());
		ST.push(DOOR.clone());
		B = REP.clone();
		B.facesForward = false;
		ST.push(B);
	}
	return ST;
}


function CenteredDoor(ST, DOOR, WP1, WP1C, WP2, WP2C, FEP, REP, JP, LEFT)
{
var B;
	B = FEP.clone();
	B.facesForward = true;
	ST.push(B);
	ST = PUSHPANELS(ST, WP1, WP1C/2, WP2, WP2C/2, LEFT, JP);


	if (DOOR.needsSpecialEndPost)
	{
		B = REP.clone();
		B.facesForward = false;
		ST.push(B);
		ST.push(DOOR.clone());
		B = FEP.clone();
		B.facesForward = true;
		ST.push(B);

	}
	else
	{
		ST.push(JP.clone());
		ST.push(DOOR.clone());
		ST.push(JP.clone());
	}

	ST = PUSHPANELS(ST, WP1, WP1C/2, WP2, WP2C/2, !LEFT, JP);
	B = REP.clone();
	B.facesForward = false;
	ST.push(B);
	return ST;
}






function GetConfigurations(inLength, inForeEndPosts, inRearEndPosts, inJoiningPosts, inAllowWingWall, inWWMin, inWWMax, inDoorLocation, inDoor, inWallLocation)
{
	var SP = new span(inLength, inForeEndPosts, inRearEndPosts, inJoiningPosts, inAllowWingWall, inWWMin, inWWMax, inDoorLocation, inDoor);
	var SOL = getSolutions(SP);
	var WallName, WallCollectionName, LeftWW;
	switch(inWallLocation)
	{
		case WallLocations.front:
		WallName = "FC";
		WallCollectionName = "PFC";
		LeftWW = (!Design.LS);
		break;
		case WallLocations.left:
		WallName = "LS";
		WallCollectionName = "PLS";
		LeftWW = true;
		break;
		case WallLocations.right:
		WallName = "RS";
		WallCollectionName = "PRS";
		LeftWW = false;
		break;
		case WallLocations.leftcorner:
		WallName = "LC";
		WallCollectionName = "PLC";
		LeftWW = true;
		break;
		case WallLocations.rightcorner:
		WallName = "RC";
		WallCollectionName = "PRC";
		LeftWW = true;
		break;
	}
	var Returned = new Array();
	for (t=0;t<SOL.length;t++)
	{
		Returned.push(new solutionToConfiguration(SP, SOL[t], WallName, WallCollectionName, LeftWW));
	}
	if (Returned.length != SOL.length)
	{
		alert('Configurations does not equal solutions. Problem.');
	}
	if (Returned.length == 0)
	{
		Returned = new Object();
		Returned.isError = true;
		Returned.inLength=inLength;
		Returned.inForeEndPosts = inForeEndPosts;
		Returned.inRearEndPosts = inRearEndPosts;
		Returned.inJoiningPosts = inJoiningPosts;
		Returned.inAllowWingWall = inAllowWingWall;
		Returned.inWWMin = inWWMin;
		Returned.inWWMax = inWWMax;
		Returned.inDoorLocation = inDoorLocation;
		Returned.inDoor = inDoor;
		Returned.inWallLocation = inWallLocation;
	}
	return Returned;
}

function Select(group, Value)
{
	if (Value==-1)
	{
		return;
	}
	$(group + Value).style.backgroundColor = '#FF0000';
}

function Disable(value)
{
	$("Disabled" + value).style.display = 'block';
}

function Enable(value)
{
	$("Disabled" + value).style.display = 'none';
}

function Clear(value, MaxValue)
{
	for(var t=1;t<=MaxValue;t++)
	{
		$(value + t).style.backgroundColor = '#FFFFFF';
	}
}

function selectedValue(SB)
{
	return SB.options[SB.selectedIndex].value;
}

function addOption(selectbox, text, value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function HeightChanged()
{
	var Height = (selectedValue($('selectHeight')));
}

function BaseConfig()
{
	timer = 0;
	$('workwindow').style.overflow='hidden';
	$('workwindowinner').style.overflow='hidden';
	timer = 398;
	$('Lrg1').style.left = ((timer / 2) - 199) + "px";
	$('Lrg1').src = getConfigSrc();
	OLF.style.width = (600 + timer) + "px";
	OLI.style.width = (600 + timer - 10) + "px";
	WW.style.width = Math.max(396 - timer, 0) + "px";
	WW.style.left = (603 + timer) + "px";
	WWI.style.width = Math.max(386 - timer, 0) + "px";
	$('Controls').style.display = 'block';
	relocateControlsForShape();
	$('BPBut').style.display = 'block';
	$('BPBackBut').style.display = 'block';
}

function GenerateBack()
{
	$('Controls').style.display = 'none';
	$('Lrg1').style.left = "0px";
	$('Lrg1').src = getShapeSrc(currentShape);
	OLF.style.width = '600px';
	OLI.style.width = '590px';
	WW.style.width = '396px';
	WWI.style.width = '386px';
	WW.style.left = '603px';
	$('BPBut').style.display = 'none';
	$('BPBackBut').style.display = 'none';
	$('ButtonFrontDoor').style.display = 'none';
	$('ButtonRightDoor').style.display = 'none';
	$('ButtonLeftDoor').style.display = 'none';
	$('ControlRightWW').style.display = 'none';
	$('ControlLeftWW').style.display = 'none';
}

function changeOpacity(opacity, element)
{
}

function DoorChanged()
{
	DoorChangedLocation("Front");
	DoorChangedLocation("Left");
	DoorChangedLocation("Right");
	SetOpenIns();
}

function DoorChangedLocation(location)
{
	DL = $(location + "DoorLocation");
	DT = $(location + "DoorType");
	DI = $(location + "DoorOpenIn");
	if (DL.selectedIndex == 0)
	{
		DT.style.display = 'none';
		DI.style.display = 'none';
	}
	else
	{
		DT.style.display = 'block';
		DI.style.display = 'block';
	}
}

function locateControls(WX, WY, DX, DY, FX, FY, LX, LY, RX, RY, CX, CY)
{
	$('CornersControl').style.top = CY + 'px';
	$('WidthControl').style.top = WY + 'px';
	$('DepthControl').style.top = DY + 'px';
	$('FrontControl').style.top = FY + 'px';
	$('LeftControl').style.top = LY + 'px';
	$('RightControl').style.top = RY + 'px';
	$('CornersControl').style.left = CX + 'px';
	$('WidthControl').style.left = WX + 'px';
	$('DepthControl').style.left = DX + 'px';
	$('FrontControl').style.left = FX + 'px';
	$('LeftControl').style.left = LX + 'px';
	$('RightControl').style.left = RX + 'px';
}

function visControls(W, D, F, L, R, C)
{
	doubleDisplay($('CornersControl') , C);
	doubleDisplay($('WidthControl') , W);
	doubleDisplay($('DepthControl') , D);
	doubleDisplay($('FrontControl') , 'none');
	doubleDisplay($('LeftControl') , 'none');
	doubleDisplay($('RightControl') , 'none');
}

function doubleDisplay(target, value)
{
	target.style.display = value;
	if (value=='none')
	{
		target.style.visibility='hidden';
	}
	else
	{
		target.style.visibility='visible';
	}
}

function GoGenerate()
{
	if (HaveData())
	{
		InitializePorch();
	}
	else
	{
		alert('Please enter Dimensions.');
	}
}

function Porch(D, W)
{
	this.depth = D;
	this.width = W;
}

function SelectedDoor(Word)
{
	var RH=false;
	if ($(Word + "DoorRightHinged"))
	{
		RH = ($(Word + "DoorRightHinged")).checked;
	}
	var D;
	switch ($(Word + "DoorType").selectedIndex)
	{
		case 0:
		D = new Door(false, 51, 36, false, 2, "PD-51", RH);
		break;
		case 1:
		D = new Door(false, 49, 38, true, 4, "PD-49", RH);
		break;
		case 2:
		D = new Door(false, 63, 52, true, 4, "PD-63", RH);
		break;
		case 3:
		D = new Door(false, 87, 72, true, 4, "PD-87", RH);
		break;
	}
	D.opensInward = ($(Word + "OpenIn")).checked;
	return D;
}

function setDesignValues(Design, name, nameQS, LS, RS, C, DPTHChange, WDTHChange)
{
	Design.name = name;
	Design.nameQS = nameQS;
	Design.LS = LS;
	Design.RS = RS;
	Design.C = C;
	Design.deckWidth = Design.width;
	Design.width -= WDTHChange;
	Design.deckLength = Design.depth;
	Design.depth -= DPTHChange;
}

function CheckErrors()
{
	var ErroredWalls = new Array();
	for (t=0;t<=4;t++)
	{
		if (Design.WallConfigurations[t] != nothing)
		{
			if (Design.WallConfigurations[t].isError)
			{
				ErroredWalls.push(t);
			}
		}
	}
	if (ErroredWalls.length == 0)
	{
		HaveWorkingLayout();
	}
	else
	{
		NoValidLayout(ErroredWalls);
	}
}

function getWallName(int)
{
	switch (int)
	{
		case WallLocations.front:
		return "Front Wall";
		break;
		case WallLocations.left:
		return "Left Wall";
		break;
		case WallLocations.right:
		return "Right Wall";
		break;
	}
}

function ShowHideConfigBars()
{
	setVisible('customConfigs', ($('Workbar').selectedIndex == SelectableConfigurations.length - 1));
	setVisible('divCL', (Design.WallConfigurations[WallLocations.left] != nothing));
	setVisible('divCR', (Design.WallConfigurations[WallLocations.right] != nothing));
}

function WBlayoutChanged()
{
	CurrentConfiguration=$('Workbar').selectedIndex;
	$("LrgAuto").src = getPorchQS();
	ShowHideConfigBars();
}


function getSolutionWithWallPanels(location, WP1, WP2)
{
	
	var Wall = Design.WallConfigurations[location];
	var returned = new Array();
	var Thousands;

	if (WP2 == nothing)
	{
		Thousands = 4;
		switch(WP1.runlength)
			{
			case 63:
			Thousands = 7;
			break;
			case 49:
			Thousands = 6;
			break;
			}
	}
	else
	{
	if (WP2.runlength > WP1.runlength)
		{
		var Buffer = WP2;
		WP2 = WP1;
		WP1 = Buffer;
		}
	
	if (WP1.runlength == 63)
		{
		if (WP2.runlength == 49)
			{
			Thousands = 5;
			}
		else
			{
			Thousands = 3;
			}
		}
	else
		{
		Thousands = 2;
		}	


	}



	for (t=0;t<Wall.length;t++)
	{
		var Layout = Wall[t];
		var Sol = Layout.descriptor.value;
		Sol = Math.floor(((Sol + 1)/1000));
		if(Sol==Thousands || Sol == 8)
		{
				returned.push(t);
		}
	}
	return returned;
}

function ConfigChanged(it, loc)
{
	ShowHideConfigBars();
	SelectableConfigurations[SelectableConfigurations.length - 1][loc] = it.selectedIndex;
	$("LrgAuto").src = getPorchQS();
}


function getSuggestions(Location)
{
	var EW = Design.WallConfigurations[Location];
	var S = "";
	var X, t;
	if (EW.inWallLocation == WallLocations.right || EW.inWallLocation == WallLocations.left)
	{
		if (!EW.inAllowWingWall)
		{
			X = GetConfigurations(EW.inLength, EW.inForeEndPosts, EW.inRearEndPosts, EW.inJoiningPosts, true, 12, 36, EW.inDoorLocation, EW.inDoor, EW.inWallLocation);
			if (!X.isError)
			{
				S += "<a style='text-decoration: underline;' href='javascript:AllowWingWall(" + Location + "," + t + ")'>";
				S += getWallName(Location) + " can be fit if a wing wall is allowed.</a><br/>";
			}
		}
	}
	var AllDoors = new Array(new Door(false, 51, 36, false, 2, "PD-51", false), new Door(false, 49, 38, true, 4, "PD-49", false), new Door(false, 63, 52, true, 4, "PD-63", false), new Door(new endPost(1.5, false, false, "EP2-", false), 36, 36, false, 0, "FD-36", false));
	if (EW.inDoorLocation != DoorLocations.none)
	{
		for (t=1;t<=3;t++)
		{
			if (t != EW.inDoorLocation)
			{
				X = GetConfigurations(EW.inLength, EW.inForeEndPosts, EW.inRearEndPosts, EW.inJoiningPosts, EW.inAllowWingWall, EW.inWWMin, EW.inWWMax, t, EW.inDoor, EW.inWallLocation);
				if (!X.isError)
				{
					S += "<a style='text-decoration: underline;' href='javascript:MoveDoor(" + Location + "," + t + ")'>";
					S += getWallName(Location) + " can be fit if the door is moved to " + GetDoorLocation(t) + ".</a><br/>";
				}
			}
		}
		for (t=0;t<AllDoors.length;t++)
		{
			X = GetConfigurations(EW.inLength, EW.inForeEndPosts, EW.inRearEndPosts, EW.inJoiningPosts, EW.inAllowWingWall, EW.inWWMin, EW.inWWMax, EW.inDoorLocation, AllDoors[t], EW.inWallLocation);
			if (!X.isError)
			{
				S += "<a style='text-decoration: underline;' href='javascript:ChangeDoor(" + Location + "," + t + ")'>";
				S += getWallName(Location) + " can be fit if the door is changed to " + AllDoors[t].description() + ".</a><br/>";
			}
		}
	}
	WallPanels = ExtendedWallPanels;
	X = GetConfigurations(EW.inLength, EW.inForeEndPosts, EW.inRearEndPosts, EW.inJoiningPosts, EW.inAllowWingWall, EW.inWWMin, EW.inWWMax, EW.inDoorLocation, EW.inDoor, EW.inWallLocation);
	if (false)
	{
		S += "<a href='javascript:AllowNarrowPanels(" + Location + ")'>";
		S += getWallName(Location) + " can be fit if narrow Panels are allowed.</a><br/>";
	}
	WallPanels = StandardWallPanels;
	return S;
}

function GetDoorLocation(t)
{
	var L = new Array("none", "center", "left", "right");
	return L[t];
}

function AllowWingWall(Location)
{
	var EW = Design.WallConfigurations[Location];
	var X = GetConfigurations(EW.inLength, EW.inForeEndPosts, EW.inRearEndPosts, EW.inJoiningPosts, EW.inAllowWingWall, 12, 36, EW.inDoorLocation, EW.inDoor, EW.inWallLocation);
	Design.WallConfigurations[Location] = X;
	CheckErrors();
}

function ChangeDoor(Location, t)
{
	var AllDoors = new Array(new Door(false, 51, 36, false, 2, "PD-51", false), new Door(false, 49, 38, true, 4, "PD-49", false), new Door(false, 63, 52, true, 4, "PD-63", false), new Door(new endPost(1.5, false, false, "EP2-", false), 36, 36, false, 0, "FD-36", false));
	var EW = Design.WallConfigurations[Location];
	var X = GetConfigurations(EW.inLength, EW.inForeEndPosts, EW.inRearEndPosts, EW.inJoiningPosts, EW.inAllowWingWall, EW.inWWMin, EW.inWWMax, EW.inDoorLocation, AllDoors[t], EW.inWallLocation);
	Design.WallConfigurations[Location] = X;
	CheckErrors();
}

function MoveDoor(Location, t)
{
	var EW = Design.WallConfigurations[Location];
	var X = GetConfigurations(EW.inLength, EW.inForeEndPosts, EW.inRearEndPosts, EW.inJoiningPosts, EW.inAllowWingWall, EW.inWWMin, EW.inWWMax, t, EW.inDoor, EW.inWallLocation);
	Design.WallConfigurations[Location] = X;
	CheckErrors();
}

function AllowNarrowPanels(Location)
{
	var EW = Design.WallConfigurations[Location];
	WallPanels = ExtendedWallPanels;
	var X = GetConfigurations(EW.inLength, EW.inForeEndPosts, EW.inRearEndPosts, EW.inJoiningPosts, EW.inAllowWingWall, EW.inWWMin, EW.inWWMax, EW.inDoorLocation, EW.inDoor, EW.inWallLocation);
	WallPanels = StandardWallPanels;
	Design.WallConfigurations[Location] = X;
	CheckErrors();
}

function ConfiguredBack()
{
	$('Lrg1').style.left = "0px";
	$('Lrg1').style.display = "inline";
	relocateControlsForShape();
	hide('LrgAuto','ConfigDiv','ErrorDiv','BPAccept','BPLarge','BPChangeLengths');
	show('BPBackBut','BPBut');
}

function AcceptDesign()
{
	resetOptions();
	setElevationsAvailable();
	show('ConfigureOptions');
	hide('ConfigDiv','LayoutDiv');
}

function BackToLayout()
{
	resetOptions();
	hide('ConfigureOptions');
	show('ConfigDiv','LayoutDiv');
}

function SetOpenIns()
{
	SOI("Front");
	SOI("Left");
	SOI("Right");
}

function SOI(value)
{
	if ($(value + "DoorType").selectedIndex != 0)
	{
		hide(value + "DoorOpenIn");
		$(value + "OpenIn").checked = false;
	}
	else
	{
		show(value + "DoorOpenIn");
	}
}

function getShipCost(State)
{
	var at;
	var ShipCost=0;
	var Group=-1;
	var Weight = getShipWeight();
	for (at=1;at<=8;at++)
	{
		if (ShipRegions[at].indexOf(State) != -1)
		{
			Group = at;
		}
	}
	for (at=0;at<ShipZones.length;at++)
	{
		if (ShipZones[at].zone == Group)
		{
			if (ShipZones[at].min <= Weight && ShipZones[at].max > Weight)
			{
				ShipCost = ShipZones[at].price;
			}
		}
	}
	return ShipCost;
}

function printingImage(item, PPI, CX, CP, hasGlass, UI, LI, DW, DH, trim)
{
	var CY = 0;
	var scalefactor=1;
	var DrawWidth, DrawHeight, vOffset, hOffset;
	var S="";
	
	DrawWidth = DW;
	DrawHeight = DH;
	var IW=DW;
	var hOffset = 0;
	if (trim != nothing)
	{
	hOffset = (DrawWidth - RTT(item.imageWidth / PPI))/2;
	IW = RTT(item.imageWidth / PPI);
	}
	var args='Overflow:hidden;';
	S = createPrintDiv(CX, CY, DrawWidth, DrawHeight, args);
	S += "<img style='position:absolute;left:" + hOffset + "in;top:0px;width:" + IW + "in;Height:" + DrawHeight + "in;' src='";
	S += getImageFilename(item, CurrentPaint);
	S += "' />";
	var Ins, buffer, FileN, insY;
	var insX = item.insertsX / PPI;
	insX = (Math.ceil(insX * 1000) / 1000);
	insX += hOffset;
	if (item.upperInsertGroup != "X" && item.upperInsertGroup != "Z")
	{
		Ins = getPart("UI-" + UI + "-" + item.upperInsertGroup);
		FileN = getImageFilename(Ins, CurrentPaint);
		insY = RTT(item.uiY / PPI);
		DrawWidth = RTT(Ins.imageWidth / PPI);
		DrawHeight = RTT(Ins.imageHeight / PPI);
		S += "<img style='position:absolute;left:" + insX + "in;top:" + insY + "in;width:" + DrawWidth + "in;Height:" + DrawHeight + "in;' src='";
		S += FileN;
		S += "' />";
	}
	if (item.lowerInsertGroup != "X" && item.lowerInsertGroup != "Z")
	{
		Ins = getPart("LI-" + LI + "-" + item.lowerInsertGroup);
		FileN = getImageFilename(Ins, CurrentPaint);
		insY = RTT(item.liY / PPI);
		DrawWidth = RTT(Ins.imageWidth / PPI);
		DrawHeight = RTT(Ins.imageHeight / PPI);
		S += "<img style='position:absolute;left:" + insX + "in;top:" + insY + "in;width:" + DrawWidth + "in;Height:" + DrawHeight + "in;' src='";
		S += FileN;
		S += "' />";
	}
	S += "</div>";
	return S;
}

function currentConfig(value)
{
if (value == WallLocations.leftcorner || value == WallLocations.rightcorner)
	{return Design.WallConfigurations[value][0]}
else
	{return Design.WallConfigurations[value][SelectableConfigurations[CurrentConfiguration][value]];}
}

function joiningPost(inLength, inPartName)
{
	this.className = "JoiningPost";
	this.runlength = inLength;
	this.isModular = false;
this.queryString = function()
{
	if (!this.isModular)
	{
		return "JP-" + this.runlength;
	}
	else
	{
		return "MJP-" + this.runlength;
	}
}
this.clone = function()
{
	var Doppel = new joiningPost(this.runlength, this.partName);
	Doppel.isModular = this.isModular;
	return Doppel;
}
this.partName = inPartName;
}

function WallPanel(inLength, inMaxTrim, inPartName)
{
	this.className = "WallPanel";
	this.maxTrim = inMaxTrim;
	this.runlength = inLength;
	this.partName = inPartName;
this.queryString = function()
{
	if (this.trim != nothing)
	{
		return "WP-" + (this.runlength - this.trim);
	}
	else
	{
		return "WP-" + this.runlength;
	}
}
this.clone = function()
{
	var Doppel = new WallPanel(this.runlength, this.maxTrim, this.partName);
	Doppel.trim = 0;
	return Doppel;
}
}



IncludeRoof = true;



CurrentRoofStyle = 1;
CurrentRoofMaterial = 1;




function UpdatePerspective()
{
var Img=$('PerspectiveRoof');
var src = 'graphics/MudroomPerspective/';
if (CurrentRoofStyle == 1)
{
src += 'Hipped/';
}
else
{
src += 'Peaked/';
}


switch (CurrentRoofMaterial)
{
case 1:
src += "Shingles.png";
break;

case 2:
src += "TG.png";
break;


case 3:
src += "Copper.png";
break;

case 4:
src += "Green.png";
break;

case 5:
src += "Red.png";
break;
}
Img.src = src;

var DoorPath;

if (currentMudroomDoor == 5)
{
DoorPath = 'graphics/MudroomPerspective/Double/';
$('PerspectiveDoor').src = 'graphics/MudroomPerspective/DoubleDoor.png';
}
else
{
DoorPath = 'graphics/MudroomPerspective/Single/';
$('PerspectiveDoor').src = 'graphics/MudroomPerspective/SingleDoor.png';
}


if (CurrentGlass)
{
$('PerspectiveGlass').src = DoorPath + "Glass.png";
}
else
{
$('PerspectiveGlass').src = DoorPath + "Screens.png";
}



$('PerspectiveUI').src = DoorPath + "UI" + CurrentUI + ".png"; 
$('PerspectiveLI').src = DoorPath + "LI" + CurrentLI + ".png"; 


fixChildren($('PerspectiveView'));
}





function newSetSG(value)
{
setSG(value);
UpdatePerspective();

}




function setRoofStyle(value)
{
	CurrentRoofStyle = value;
	selectZone("RoofStyle", value);
	ElevationViewChanged();
	UpdatePerspective();
}


function setRoofMaterial(value)
{
	CurrentRoofMaterial = value;
	selectZone("RoofMat", value);
	ElevationViewChanged();
	UpdatePerspective();
}





var MudRoomPreviews = new Array();

MudRoomPreviews[1] = "http://secure.vixenhill.com/Gazebos/MudRoom.aspx?FC=87.75&PFC=EP-0.5!WP-20!JP-1.5!DP-48.375-36-S!JP-1.5!WP-20!REP-0.5&Shape=UShaped&DL=undefined&DW=undefined&RS=87.75&PRS=EP-0.5!WP-43.28125!JP-1.5!WP-43.28125!RMEP-4.125&LS=87.75&PLS=MEP-4.125!WP-43.28125!JP-1.5!WP-43.28125!REP-0.5&COLOR=238!238!255&shapemode=yes&W=590&H=500";
MudRoomPreviews[2] = "http://secure.vixenhill.com/Gazebos/MudRoom.aspx?FC=87.75&PFC=EP-0.5!WP-20!JP-1.5!IDP-48.375-36-S!JP-1.5!WP-20!REP-0.5&Shape=UShaped&DL=undefined&DW=undefined&RS=87.75&PRS=EP-0.5!WP-43.28125!JP-1.5!WP-43.28125!RMEP-4.125&LS=87.75&PLS=MEP-4.125!WP-43.28125!JP-1.5!WP-43.28125!REP-0.5&COLOR=238!238!255&shapemode=yes&W=590&H=500";
MudRoomPreviews[3] = "http://secure.vixenhill.com/Gazebos/MudRoom.aspx?FC=87.75&PFC=EP-0.5!WP-20!JP-1.5!DP-48.375-36-S-R!JP-1.5!WP-20!REP-0.5&Shape=UShaped&DL=undefined&DW=undefined&RS=87.75&PRS=EP-0.5!WP-43.28125!JP-1.5!WP-43.28125!RMEP-4.125&LS=87.75&PLS=MEP-4.125!WP-43.28125!JP-1.5!WP-43.28125!REP-0.5&COLOR=238!238!255&shapemode=yes&W=590&H=500";
MudRoomPreviews[4] = "http://secure.vixenhill.com/Gazebos/MudRoom.aspx?FC=87.75&PFC=EP-0.5!WP-20!JP-1.5!IDP-48.375-36-S-R!JP-1.5!WP-20!REP-0.5&Shape=UShaped&DL=undefined&DW=undefined&RS=87.75&PRS=EP-0.5!WP-43.28125!JP-1.5!WP-43.28125!RMEP-4.125&LS=87.75&PLS=MEP-4.125!WP-43.28125!JP-1.5!WP-43.28125!REP-0.5&COLOR=238!238!255&shapemode=yes&W=590&H=500";
MudRoomPreviews[5] = "http://secure.vixenhill.com/Gazebos/MudRoom.aspx?FC=87.75&PFC=EP-0.5!WP-20!JP-1.5!DP-48.375-38-D!JP-1.5!WP-20!REP-0.5&Shape=UShaped&DL=undefined&DW=undefined&RS=87.75&PRS=EP-0.5!WP-43.28125!JP-1.5!WP-43.28125!RMEP-4.125&LS=87.75&PLS=MEP-4.125!WP-43.28125!JP-1.5!WP-43.28125!REP-0.5&COLOR=238!238!255&shapemode=yes&W=590&H=500";





function getMudRoomDesign(FrontType)

{
var Design = {"C": false, "RS": true, "LS": true, "name": "Three Sided", "nameQS": "UShaped"};





Design.WallConfigurations = new Array();

var StandardEndPosts = new Array();
StandardEndPosts.push(new endPost(.5, false, true, "MCP-CAP-"));
var JoiningPosts = new Array();
JoiningPosts.push(new joiningPost(1.5, "JP1-"));

var FrontProto = GetConfigurations(87.75, StandardEndPosts, StandardEndPosts, JoiningPosts, false, 0, 0, DoorLocations.none, nothing, WallLocations.front);
var LeftProto = GetConfigurations(87.75, StandardEndPosts, StandardEndPosts, JoiningPosts, false, 0, 0, DoorLocations.none, nothing, WallLocations.left);
var RightProto = GetConfigurations(87.75, StandardEndPosts, StandardEndPosts, JoiningPosts, false, 0, 0, DoorLocations.none, nothing, WallLocations.right);


var MEP = new endPost(4.125, false, true, "MEP-");
var WP49 = new WallPanel(49, 6, "WP-49");
var JP1 = new joiningPost(1.5, "JP1-");
var CAP = new endPost(.5, false, false, "MCP-CAP-");


var LSP = new Array();
LSP.push(MEP.clone());
LSP[0].facesForward = true;
var T = WP49.clone();
T.trim = 4.0625;
LSP.push(T);
LSP.push(JP1.clone());
var T = WP49.clone();
T.trim = 4.0625;
LSP.push(T);
LSP.push(CAP.clone());

var RSP = new Array();

RSP.push(CAP.clone());
RSP[0].facesForward = true;
var T = WP49.clone();
T.trim = 4.0625;
RSP.push(T);
RSP.push(JP1.clone());
var T = WP49.clone();
T.trim = 4.0625;
RSP.push(T);
RSP.push(MEP.clone());


var FCP = new Array();
FCP.push(CAP.clone());
FCP[0].facesForward = true;

switch (FrontType)
{
case 1:
	{
	var W = new WallPanel(20, 6, "WP-20");
	W.trim = 0;
	FCP.push(W);
	FCP.push(JP1.clone());
	var D = new Door(false, 51, 36, false, 4, "PD-51", false);
	D.trim = 2.625;
	FCP.push(D);
	FCP.push(JP1.clone());
	var W = new WallPanel(20, 6, "WP-20");
	W.useRightInserts = true;
	W.trim = 0;
	FCP.push(W);
	}
break;

case 2:
	{
	var W = new WallPanel(20, 6, "WP-20");
	W.trim = 0;
	FCP.push(W);
	FCP.push(JP1.clone());
	var D = new Door(false, 51, 36, false, 4, "PD-51", false);
	D.trim = 2.625;
	D.opensInward = true;
	FCP.push(D);
	FCP.push(JP1.clone());
	var W = new WallPanel(20, 6, "WP-20");
	W.useRightInserts = true;
	W.trim = 0;
	FCP.push(W);
	}
break;

case 3:
	{
	var W = new WallPanel(20, 6, "WP-20");
	W.trim = 0;
	FCP.push(W);
	FCP.push(JP1.clone());
	var D = new Door(false, 51, 36, false, 4, "PD-51", true);
	D.trim = 2.625;
	FCP.push(D);
	FCP.push(JP1.clone());
	var W = new WallPanel(20, 6, "WP-20");
	W.useRightInserts = true;
	W.trim = 0;
	FCP.push(W);
	}
break;

case 4:
	{
	var W = new WallPanel(20, 6, "WP-20");
	W.trim = 0;
	FCP.push(W);
	FCP.push(JP1.clone());
	var D = new Door(false, 51, 36, false, 4, "PD-51", true);
	D.trim = 2.625;
	D.opensInward = true;
	FCP.push(D);
	FCP.push(JP1.clone());
	var W = new WallPanel(20, 6, "WP-20");
	W.useRightInserts = true;
	W.trim = 0;
	FCP.push(W);
	}
break;






case 5:
	{
	var W = new WallPanel(20, 6, "WP-20");
	W.trim = 0;
	FCP.push(W);
	FCP.push(JP1.clone());
	var D = new Door(false, 49, 38, true, 4, "PD-49", false);
	D.trim = .625;
	FCP.push(D);

	FCP.push(JP1.clone());
	var W = new WallPanel(20, 6, "WP-20");
	W.useRightInserts = true;
	W.trim = 0;
	FCP.push(W);
	}
break;



}
FCP.push(CAP.clone());






for (var t=0;t<=2;t++)
{
Design.WallConfigurations[t] = new Array()
}

LeftProto[0].Parts = LSP;
RightProto[0].Parts = RSP;
FrontProto[0].Parts = FCP;


Design.WallConfigurations[0][0] = FrontProto[0];
Design.WallConfigurations[1][0] = LeftProto[0];
Design.WallConfigurations[2][0] = RightProto[0];



return Design;
}






function getRetrofitEnteredValues(Target)
{
var value=new Object();
var L=new Array();
var PL=new Array();
var PW=new Array();
value.DL=$(Target + "DOORSEC").selectedIndex;

var MaxSections = $(Target + "SECTIONS").selectedIndex + 1;


var lngth = parseSectionValue (Target, 1)
L.push(lngth);

var at=2;
lngth = parseSectionValue(Target, at);

while (at <= MaxSections)
{
L.push(lngth);
PL.push(6);
PW.push(6);
at++;
lngth = parseSectionValue(Target, at);
}

value.L = L;
value.PL = PL;
value.PW = PW;
return value;
}


function Cull(S)
{
var Output = new Array();

for (var t=0;t<S.length;t++)
	{
	var Value = new Array();
	for (y=0;y<S[t].length;y++)
		{
		var Exists = false;
		for (q=0;q<Value.length;q++)
			{
			if (Value[q].queryString() == S[t][y].queryString())
				{
				Exists = true;
				}
			}
		if (!Exists)
			{
			Value.push(S[t][y]);
			}
		}
	Output.push(Value);
	}
return Output;
}





function RetrofitConfigurations(inLengths, inPostLengths, inPostWidths, inWallLocation, inDoorLocation, inDoor, inDoorSection, inEndPosts, inJoiningPosts)
{
var Secs = new Array();
for (var c=0;c<inLengths.length;c++)
	{
	if (inDoorSection == c)
		{
		Secs[c] = GetConfigurations(inLengths[c], inEndPosts, inEndPosts, inJoiningPosts, false, 0, 0, inDoorLocation, inDoor, inWallLocation);
		}
	else
		{
		Secs[c] = GetConfigurations(inLengths[c], inEndPosts, inEndPosts, inJoiningPosts, false, 0, 0, DoorLocations.none, inDoor, inWallLocation);
		}
	}

Secs = Cull(Secs);
var P = getPermutations(Secs);


var Solutions = new Array();

for (var t=0;t<P.length;t++)
	{
	var Sol = clone(P[t][0]);
		var newParts = new Array();
		for (var x=0;x<Sol.Parts.length;x++)
			{
			var Px = Sol.Parts[x].clone();
			Px.trim = Sol.Parts[x].trim;
			newParts.push(Px);
			}
		Sol.Parts = newParts;


		for (var x=1;x<P[t].length;x++)
			{
			Sol.Parts.push(new InlinePost(inPostLengths[x-1], inPostWidths[x-1]));
			for (var y=0;y<P[t][x].Parts.length;y++)
				{
				var Px = P[t][x].Parts[y].clone();
				Px.trim = P[t][x].Parts[y].trim;
				Sol.Parts.push(Px);
				}
			}
	Sol.descriptor = getConfigDescription(Sol);
	Solutions.push(Sol);
	}


for (var t=0;t<Secs.length;t++)
	{
	if (Secs[t].length < 1)
		{Solutions.isError=true;}
	}


return Solutions;

}


function getPermutations(S)
{
var List = Permutations([], S, []);

var ret = new Array();

for (var t=0;t<List.length;t++)
	{
	var add = new Array();
	for (var y=0;y<List[t].length;y++)
		{

		add.push(S[y][List[t][y]]);
		}
	ret.push(add);
	}
return ret;
}


function Permutations(InStack, ToPermute, Output)
{
var at=InStack.length;

if (at == ToPermute.length-1)
	{
	for (var x=0;x<ToPermute[at].length;x++)
		{
		var Addon = new Array();
		for (var y=0;y<InStack.length;y++)
			{
			Addon.push(InStack[y]);
			}
		Addon.push(x);
		Output.push(Addon);
		}
	return Output;
	}
else
	{
	for (var x=0;x<ToPermute[at].length;x++)
		{
		InStack.push(x);
		Output = Permutations(InStack, ToPermute, Output);
		InStack.pop(x);
		}
	return Output;
	}

}


function getConfigSrc()
{
	var target=currentShape;
	var value="http://secure.vixenhill.com/Gazebos/MudRoom.aspx?Shapemode=yes&W=988&H=500&Color=238!238!255&";
	switch (target)
	{
		case 1:
		value += "shape=LeftHandedL&LS=150&RS=150&";
		value += ShapeWallString("Left", "PLS");
		value += ShapeWallString("Front", "PFC");
		break;
		case 2:
		value += "shape=OneSided&FC=150&";
		value += ShapeWallString("Front", "PFC");
		break;
		case 3:
		value += "shape=RightHandedL&RS=150&FC=150&";
		value += ShapeWallString("Front", "PFC");
		value += ShapeWallString("Right", "PRS");
		break;
		case 4:
		value += "shape=UShaped&RS=150&FC=150&LS=150&";
		value += ShapeWallString("Front", "PFC");
		value += ShapeWallString("Right", "PRS");
		value += ShapeWallString("Left", "PLS");
		break;
	}
	value += "Zippo=EG";
	return value;
}


function ShapeWallString(wallName, Colstring)
{

	var DLoc, DT, DOI, DRH;
	DLoc = $(wallName + "DoorLocation").selectedIndex;
	DT = $(wallName + "DoorType").selectedIndex;
	DOI = $(wallName + "OpenIn").checked;
	DRH = $(wallName + "DoorRightHinged").checked;
	var value=Colstring + "=";
	var DoorString;
	var DL;
	


	switch (DT)
	{
		case 0:
		if (DOI)
		{
			DoorString = "IDP-48-36-S";
			DL = 48;
		}
		else
		{
			DoorString = "DP-48-36-S";
			DL = 48;
		}

		break;
		case 1:
		DoorString = "DP-48-38-D";
		DL = 48;
		break;
		case 2:
		DoorString = "DP-62-52-D";
		DL = 62;
		break;
		case 3:
		DoorString = "DP-82-72-D";
		DL = 82;
		break;
	}
		if (DRH)
		{
			DoorString += "-R";
		}
		else
		{
			DoorString += "-L";
		}
var RN = Colstring.substr(1, 2);
var DoorSec = $(RN + "DOORSEC").selectedIndex + 1;
var Sections = $(RN + "SECTIONS").selectedIndex + 1;


value += getStringForPreview(1, PreviewSectionLength(RN, 1), "A", DoorSec, DLoc, DL, DoorString)

Letters = ["A", "B", "C", "D", "E"];

for (var t=2;t<=Sections;t++)
{
value += "!ILP-3-3!" + getStringForPreview(t, PreviewSectionLength(RN, t), Letters[t-1], DoorSec, DLoc, DL, DoorString);

}

	value += "&";
	return value;

}

function getStringForPreview(Sec, SecL, SecSt, DSec, DLoc, DL, DS)
{
if (Sec==DSec && !(DLoc == 0))
	{
	if (DL + 3 > SecL)
		{
		return DS + "-" + SecSt;
		}
	else
		{
		switch(DLoc)
			{
			case 1:
				var WPL = (SecL - (DL + 3))/2;
				return "WP-" + WPL + "!JP-1.5!" + DS + "-" + SecSt + "!JP-1.5!WP-" + WPL;
			break;
			case 2:
				var WPL = SecL - (DL + 3);
				return DS + "-" + SecSt + "!JP-1.5!WP-" + WPL;
			break;
			case 3:
				var WPL = SecL - (DL + 3);
				return "WP-" + WPL + "!JP-1.5!" + DS + "-" + SecSt;
			break;
			}
		}


	}
else
{
return "WP-" + SecL + "-" + SecSt;
}

}



function PreviewSectionLength(Wall, Section)
{
var X = parseSectionValue(Wall , Section);

if (X>30)
	{return X;}
return 80; 
}




function printingImage(item, PPI, CX, CP, hasGlass, UI, LI, DW, DH, trim)
{
	var CY = 0;
	var scalefactor=1;
	var DrawWidth, DrawHeight, vOffset, hOffset;
	var S="";
	

	DrawWidth = DW;
	DrawHeight = DH;
	var IW=DW;
	var hOffset = 0;
	if (trim != nothing)
	{
	hOffset = (DrawWidth - RTT(item.imageWidth / PPI))/2;
	IW = RTT(item.imageWidth / PPI);
	}

	var args='Overflow:hidden;';
	S = createPrintDiv(CX, CY, DrawWidth, DrawHeight, args);
	S += "<img style='position:absolute;left:" + hOffset + "in;top:0px;width:" + IW + "in;Height:" + DrawHeight + "in;' src='";
	S += getImageFilename(item, CurrentPaint);
	S += "' />";
	var Ins, buffer, FileN, insY;
	var insX = item.insertsX / PPI;
	insX = (Math.ceil(insX * 1000) / 1000);
	insX += hOffset;
	if (item.upperInsertGroup != "X" && item.upperInsertGroup != "Z")
	{
		Ins = getPart("UI-" + UI + "-" + item.upperInsertGroup);
		FileN = getImageFilename(Ins, CurrentPaint);
		insY = RTT(item.uiY / PPI);
		DrawWidth = RTT(Ins.imageWidth / PPI);
		DrawHeight = RTT(Ins.imageHeight / PPI);
		S += "<img style='position:absolute;left:" + insX + "in;top:" + insY + "in;width:" + DrawWidth + "in;Height:" + DrawHeight + "in;' src='";
		S += FileN;
		S += "' />";
	}
	if (item.lowerInsertGroup != "X" && item.lowerInsertGroup != "Z")
	{
		Ins = getPart("LI-" + LI + "-" + item.lowerInsertGroup);
		FileN = getImageFilename(Ins, CurrentPaint);
		insY = RTT(item.liY / PPI);
		DrawWidth = RTT(Ins.imageWidth / PPI);
		DrawHeight = RTT(Ins.imageHeight / PPI);
		S += "<img style='position:absolute;left:" + insX + "in;top:" + insY + "in;width:" + DrawWidth + "in;Height:" + DrawHeight + "in;' src='";
		S += FileN;
		S += "' />";
	}
	S += "</div>";
	return S;
}




function getPorchPrintQS()
{
	S = "http://secure.vixenhill.com/Gazebos/QuickDisplay.aspx?";
	S += currentConfig(WallLocations.front).queryString();
	S += "&Shape=" + Design.nameQS;
	S += "&DL=" + Design.deckLength;
	S += "&DW=" + Design.deckWidth;
	if (Design.RS)
	{
		S += "&" + currentConfig(WallLocations.right).queryString();
		if (Design.C)
		{
			S += "&" + currentConfig(WallLocations.rightcorner).queryString();
		}
	}
	if (Design.LS)
	{
		S += "&" + currentConfig(WallLocations.left).queryString();
		if (Design.C)
		{
			S += "&" + currentConfig(WallLocations.leftcorner).queryString();
		}
	}
	S += "&LABEL=YES&PRINT=YES";
	return S;
}
function DoorSelected(x)
{
	var DorLoc, DorType, DorSwingIn, DorRH;
	DorLoc = $(DoorBeingSwitched + "DoorLocation");
	DorType = $(DoorBeingSwitched + "DoorType");
	DorSwingIn = $(DoorBeingSwitched + "OpenIn");
	DorRH = $(DoorBeingSwitched + "DoorRightHinged");
	DorRH.checked = (x==7||x==8);
	for (var t=1;t<=8;t++)
	{
		$('DoorSelected' + t).style.backgroundColor = '#FFFFFF';
	}
	$('DoorSelected' + x).style.backgroundColor = '#FF0000';
	if (x >= 7)
	{
		x-=5;
	}
	if (x==1)
	{
		$('DivDoorHasLocation').style.display = 'none';
		DorLoc.selectedIndex = 0;
	}
	else
	{
		$('DivDoorHasLocation').style.display = 'inline';
		DorLoc.selectedIndex = LastSelectedDoorLocation;
	}
	if (x==3)
	{
		DorSwingIn.checked = true;
	}
	else
	{
		DorSwingIn.checked = false;
	}
	if (x==2 || x==3)
	{
		DorType.selectedIndex = 0;
	}
	if (x > 3)
	{
		DorType.selectedIndex = x-3;
	}
	RDimensionsChanged("FC");
	RDimensionsChanged("RS");
	RDimensionsChanged("LS");
	updateShapeImage();
}


function Rightify(S, bool)
{
if (bool)
{
S = S.replace("/w/", "/w/r");
S = S.replace("/C/", "/C/r");
S = S.replace("/N/", "/N/r");
}
return S;
}



function getImage(item, paintColor, hasGlass, UI, LI)
{
	
	if (item.partName == nothing)
	{
		var i, d;
		i = document.createElement('img');
		i.src = '/Merchant2/graphics/mt.gif';
		i.style.height = '1px';
		d = document.createElement('div');
		d.style.height = '1px';
		d.appendChild(i);
		return new DivItem(d, nothing);
	}
	var rl=item.runlength;
	var scalefactor = 1;
	if (item.trim != nothing)
	{
		scalefactor = (rl - item.trim) / (rl);
	}
	else
	{
		if (item.className == "WingWall")
		{
			scalefactor = (24 - rl) / 24;
		}
		if (item.className == "InlinePost")
		{
			scalefactor = (rl) / 1000;
		}

	}
	var i = getPart(item.partName);
	var actualwidth = i.imageWidth * scalefactor;
	actualwidth = Math.floor(actualwidth);
	var shift = (i.imageWidth - actualwidth) / 2;
	shift = Math.floor(shift);
	var div = document.createElement('div');
	div.style.overflow = 'hidden';
	div.style.width = actualwidth;
	div.style.height = i.imageHeight;
	div.appendChild(new locatedImage(getImageFilename(i, paintColor), i.imageWidth, i.imageHeight, 'absolute', (- shift) + 'px', '0px', '200', item.partName));
	var buffer;
	if (i.upperInsertGroup != "X" && i.upperInsertGroup != "Z")
	{
		var UpI;
		UpI = getPart("UI-" + UI + "-" + i.upperInsertGroup);
		if (UpI.upperInsertGroup !="Z")
		{
			if (hasGlass)
			{
				buffer = getPart("UGLASS-" + i.upperInsertGroup);
			}
			else
			{
				buffer = getPart("USCREEN-" + i.upperInsertGroup);
			}
			div.appendChild(new locatedImage(getImageFilename(buffer, paintColor), buffer.imageWidth, buffer.imageHeight, 'absolute', (i.insertsX - shift) + 'px', i.uiY +'px', '201', buffer.partName));
		}
		buffer = "UI-" + UI + "-" + i.upperInsertGroup;
		buffer = getPart(buffer);
		div.appendChild(new locatedImage(Rightify(getImageFilename(buffer, paintColor), item.useRightInserts), buffer.imageWidth, buffer.imageHeight, 'absolute', (i.insertsX - shift) + 'px', i.uiY +'px', '202', buffer.partName));
	}
	if (i.lowerInsertGroup != "X" && i.lowerInsertGroup != "Z")
	{
		var UpI;
		UpI = getPart("LI-" + LI + "-" + i.lowerInsertGroup);
		if (UpI.lowerInsertGroup !="Z")
		{
			if (hasGlass)
			{
				buffer = getPart("LGLASS-" + i.upperInsertGroup);
			}
			else
			{
				buffer = getPart("LSCREEN-" + i.upperInsertGroup);
			}
			div.appendChild(new locatedImage(getImageFilename(buffer, paintColor), buffer.imageWidth, buffer.imageHeight, 'absolute', (i.insertsX - shift) + 'px', i.liY +'px', '201', buffer.partName));
		}
		buffer = getPart("LI-" + LI + "-" + i.upperInsertGroup);
		div.appendChild(new locatedImage(Rightify(getImageFilename(buffer, paintColor),item.useRightInserts), buffer.imageWidth, buffer.imageHeight, 'absolute', (i.insertsX - shift) + 'px', i.liY +'px', '202', buffer.partName));
	}
	return new DivItem(div, i);
}
function joiningPost(inLength, inPartName)
{
	this.className = "JoiningPost";
	this.runlength = inLength;
	this.isModular = false;

this.queryString = function()
{
	if (!this.isModular)
	{
		return "JP-" + this.runlength;
	}
	else
	{
		return "MJP-" + this.runlength;
	}
}

this.clone = function()
{
	var Doppel = new joiningPost(this.runlength, this.partName);
	Doppel.isModular = this.isModular;
	return Doppel;
}



this.partName = inPartName;
}

function InlinePost(inLength, inWidth)
{
	this.className = "InlinePost";
	this.maxTrim = 0;
	this.runlength = inLength;
	this.width = inWidth;
	this.partName = "ILP-";
this.queryString = function()
{
		return "ILP-" + this.runlength + "-" + this.width;
}

this.clone = function()
{
	var Doppel = new InlinePost(this.runlength,this.width);
	return Doppel;
}
}




function WallPanel(inLength, inMaxTrim, inPartName)
{
	this.className = "WallPanel";
	this.maxTrim = inMaxTrim;
	this.runlength = inLength;
	this.partName = inPartName;
this.queryString = function()
{
	if (this.trim != nothing)
	{
		return "WP-" + (this.runlength - this.trim);
	}
	else
	{
		return "WP-" + this.runlength;
	}
}

this.clone = function()
{
	var Doppel = new WallPanel(this.runlength, this.maxTrim, this.partName);
	Doppel.trim = 0;
	return Doppel;
}
}
function solutionToConfiguration(inWall, inSolution, inWallName, inWallCollectionName, inWingWallLeft)
{
	this.wall = inWall;
	this.solution = inSolution;
	this.wallName = inWallName;
	this.wallCollectionName = inWallCollectionName;
	this.wingWallLeft = inWingWallLeft;
	this.Parts = new Array();

	var WP1, WP2, WP1C, WP2C, FEP, REP, JP, DOOR, LEFT;
	WP1 = this.solution.wallPanel1;
	WP2 = this.solution.wallPanel2;
	if (WP2 == nothing)
		{
		WP2 = WP1.clone();
		}
	WP1C = this.solution.wallPanel1Count;
	WP2C = this.solution.wallPanel2Count;
	FEP = this.solution.foreEndPost;
	REP = this.solution.rearEndPost;
	JP = this.solution.joiningPost;
	DOOR = this.wall.usableParts.Door;
	LEFT = inWingWallLeft;
	
	if (this.wingWallLeft == true && this.solution.usesWingWall)
	{
		this.Parts.push(new WingWall(this.solution.wingWallLength))
	}


	if (WP1C + WP2C == 0)
		{
		this.Parts = DoorOnly(this.Parts, DOOR, FEP, REP);
		}
	else
		{
		switch (this.wall.doorLocation)
			{
			case DoorLocations.none:
				this.Parts = NoDoor(this.Parts, WP1, WP1C, WP2, WP2C, FEP, REP, JP, LEFT);
			break;

			case DoorLocations.centered:
				this.Parts = CenteredDoor(this.Parts, DOOR, WP1, WP1C, WP2, WP2C, FEP, REP, JP, LEFT, DOOR);
			break;

			case DoorLocations.left:
				this.Parts = LeftDoor(this.Parts, DOOR, WP1, WP1C, WP2, WP2C, FEP, REP, JP, LEFT, DOOR);
			break;

			case DoorLocations.right:
				this.Parts = RightDoor(this.Parts, DOOR, WP1, WP1C, WP2, WP2C, FEP, REP, JP, LEFT, DOOR);
			break;

			}
		}




	if (this.wingWallLeft == false && this.solution.usesWingWall)
	{
		this.Parts.push(new WingWall(this.solution.wingWallLength))
	}
	
		
	var doorNumber;

	this.actualLength = 0;
	this.trimableParts = 0;
	this.availableTrim = 0;
	for (var t=0;t<this.Parts.length;t++)
	{
		this.actualLength += this.Parts[t].runlength;
		if (this.Parts[t].maxTrim != nothing)
		{
			this.Parts[t].trim = 0;
			this.trimableParts++;
			this.availableTrim += this.Parts[t].maxTrim;
		}
		if (this.Parts[t].className == "Door")
		{
			doorNumber = t;
		}
	}
	var TrimToTake = this.actualLength - this.wall.runlength;
	if (this.availableTrim < TrimToTake)
	{
		this.isError=true;
	}
	else
	{
		if (this.wall.doorLocation==DoorLocations.centered)
		{
			var WallTrim = Math.ceil(TrimToTake / .125);
			var remTrimables = this.trimableParts;
			while (WallTrim >= remTrimables)
			{
				remTrimables = 0;
				for (var ctr=0;ctr<this.Parts.length;ctr++)
				{
					if (this.Parts[ctr].maxTrim != nothing)
					{
						if (this.Parts[ctr].trim + .125 <= this.Parts[ctr].maxTrim)
						{
							remTrimables += 1;
							this.Parts[ctr].trim += .125;
							WallTrim -= 1;
						}
					}
				}
			}
			if (WallTrim % 2 == 1)
			{
				var D = this.Parts[doorNumber];
				if (D.trim + .125 > D.maxTrim)
				{
					WallTrim += 1;
					D.trim -= .125;
				}
				else
				{
					WallTrim -= 1;
					D.trim += .125;
				}
			}
			var start = 0;
			var end = this.Parts.length - 1;
			while (WallTrim > 0)
			{
				while (this.Parts[start].maxTrim == nothing)
				{
					start += 1;
				}
				while (this.Parts[end].maxTrim == nothing)
				{
					end -= 1;
				}
				this.Parts[start].trim += .125;
				this.Parts[end].trim += .125;
				WallTrim -= 2;
			}
		}
		else
		{
			var polarity = 1;
			var startat = 0;
			var endat = this.Parts.length;
			if (!this.wingWallLeft)
			{
				polarity = -1;
				startat = this.Parts.length -1;
			}
			while (TrimToTake > 0)
			{
				var t=startat;
				while (t>=0 && t<this.Parts.length)
				{
					thing = this.Parts[t];
					if (thing.maxTrim != nothing)
					{
						if (thing.trim < thing.maxTrim && TrimToTake > 0)
						{
							thing.trim += .125;
							TrimToTake -= .125;
						}
					}
					t += polarity;
				}
			}
		}
	}
this.queryString = function()
{
	var S = this.wallName + "=" + this.wall.runlength + "&" + this.wallCollectionName + "=";
	for (var t=0;t<this.Parts.length;t++)
	{
		S += this.Parts[t].queryString();
		if ((t+1) < this.Parts.length)
		{
			S += "!";
		}
	}
	return S;
}

this.descriptor = getConfigDescription(this);
}

function setShape(value)
{
	currentShape = value;
	relocateControlsForShape();
	$('Controls').style.display = 'none';
	$('Lrg1').style.display = 'inline';
	DimensionsChanged();
}


var currentMudroomDoor = 1;



function MudroomConfig()
{
BaseConfig();
GoGenerate();
}


function MudroomDoor(value)
{
currentMudroomDoor = value;
Clear('DoorPicked', 5);
Select('DoorPicked', value);
MudDoorChanged();
$("Lrg1").src = MudRoomPreviews[value];
}

function MudDoorChanged()
{
}



function getShapeSrc(target)
{
	var value="http://secure.vixenhill.com/Gazebos/MudRoom.aspx?Shapemode=yes&SDL=yes&W=590&H=500&Color=238!238!255&";
	switch (target)
	{
		case 1:
		value += "shape=LeftHandedL&LS=100&PLS=WP-49!JP-2!WP-49&FC=100&PFC=WP-49!JP-2!WP-49";
		break;
		case 2:
		value += "shape=OneSided&FC=100&PFC=WP-49!JP-2!WP-49";
		break;
		case 3:
		value += "shape=RightHandedL&RS=100&PRS=WP-49!JP-2!WP-49&FC=100&PFC=WP-49!JP-2!WP-49";
		break;
		case 4:
		value += "shape=UShaped&RS=100&PRS=WP-49!JP-2!WP-49&FC=100&PFC=WP-49!JP-2!WP-49&LS=100&PLS=WP-49!JP-2!WP-49";
		break;
		case 5:
		value += "shape=DoubleCorner&RS=100&PRS=WP-49!JP-2!WP-49&FC=100&PFC=WP-49!JP-2!WP-49&LS=100&PLS=WP-49!JP-2!WP-49&RC=36&PRC=WP-36&LC=36&PLC=WP-36";
		break;
		case 6:
		value += "shape=LeftHandedCorner&FC=100&PFC=WP-49!JP-2!WP-49&LS=100&PLS=WP-49!JP-2!WP-49&LC=36&PLC=WP-36";
		break;
		case 7:
		value += "shape=RightHandedCorner&RS=100&PRS=WP-49!JP-2!WP-49&FC=100&PFC=WP-49!JP-2!WP-49&RC=36&PRC=WP-36";
		break;
	}
	return value;
}
function Initialize()
{
	var S = $('selectHeight');
	var e;
	for (t=83;t<=116;t++)
	{
		addOption(S, t, t);
	}
	S = $('selectHeightE');
	addOption(S, " inches", 0);

var num, denom;
	for (t=1;t<=7;t++)
	{
		denom = 8;
		num = t;
		while (num % 2 == 0)
			{
			num /= 2;
			denom /= 2;
			}
		addOption(S, num + "/" + denom + " inches", t/8);
	}
	MudroomDoor(1);
	HeightChanged();
	setShape(4);
	DoorChanged();
RDimensionsChanged("FC");
RDimensionsChanged("RS");
RDimensionsChanged("LS");

setRoofStyle(2);
setRoofMaterial(1);
setDB(1);
}
function DimensionsChanged()
{

	var ProceedButton = $('ButGenerate');
		if (HaveData())
		{
			ProceedButton.setAttribute('className', 'Button');
			ProceedButton.className = 'Button';
		}
		else
		{
			ProceedButton.className = 'Disabled';
			ProceedButton.setAttribute('className', 'Disabled');
		}
	
}
function HaveData()
{
return true;
}


function HaveDataS(side)
{
var Sections = $(side + "SECTIONS").selectedIndex + 1;
var ret = true;
	for (var t=1;t<=Sections;t++)
	{
	ret = ret && (parseSectionValue (side, t) > 0);
	}
return ret;
}

function parseSectionValue (side, t)
{
var Box = $(side + "SEC" + t);
var Inches = $(side + "SEC" + t + "I");

if (!Box || !Inches)
	{return 0;}

var L = 0;
if (!isNaN(parseFloat(Box.value)))
	{
	L += parseFloat(Box.value) * 12;
	}

if (!isNaN(parseFloat(Inches.value)))
	{
	L += parseFloat(Inches.value);
	}	

return L;
}

function relocateControlsForShape()
{
	switch (currentShape)
	{
		case 1:
		SetupControls(393, 455, 444, 340, true, 60, 145, false, 100, 200, true, 140, 200, 100, 240, false, 100, 500, 100, 600);
		SetupRetrofitControls(393, 150, true, 5, 5, false, 0, 0);
		break;
		case 2:
		SetupControls(393, 215, 444, 265, false, 60, 145, false, 100, 200, false, 140, 200, 100, 240, false, 100, 500, 100, 600);
		SetupRetrofitControls(393, 10, false, 0, 0, false, 0, 0);
		break;
		case 3:
		SetupControls(393, 455, 444, 340, true, 60, 145, false, 100, 200, false, 140, 200, 100, 240, true, 740, 200, 740, 240);
		SetupRetrofitControls(393, 150, false, 780, 5, true, 780, 5);
		break;
		case 4:
		SetupControls(393, 455, 444, 340, true, 60, 145, false, 100, 200, true, 140, 200, 100, 240, true, 740, 200, 740, 240);
		SetupRetrofitControls(393, 150, true, 5, 5, true, 780, 5);
		break;
	}
}

function SetupRetrofitControls(FX, FY, SL, LX, LY, SR, RX, RY)
{
	SetSingleControl('FCRETROCONTROL', true, FX, FY, false);
	SetSingleControl('LSRETROCONTROL', SL, LX, LY, false);
	SetSingleControl('RSRETROCONTROL', SR, RX, RY, false);

RDimensionsChanged("FC");
RDimensionsChanged("RS");
RDimensionsChanged("LS");

}


function SetupControls(WX, WY, FDX, FDY, HS, HX, HY, SC, CX, CY, SLS, LSDX, LSDY, LSWWX, LSWWY, SRS, RSDX, RSDY, RSWWX, RSWWY)
{
	SetSingleControl('WidthControl', false, WX, WY, false);
	SetSingleControl('DepthControl', false, 0, HY, false);
	SetSingleControl('ButtonFrontDoor', true, FDX, FDY, false);
	SetSingleControl('CornersControl', false, CX, CY, false);
	SetSingleControl('ButtonLeftDoor', SLS, 5, LSDY, false);
	SetSingleControl('ControlLeftWW', false, 5, 5, false);
	SetSingleControl('ButtonRightDoor', SRS, 5, RSDY, true);
	SetSingleControl('ControlRightWW', false, 5, 5, false);
}
function SetSingleControl(id, visible, X, Y, right)
{
	var E = $(id);
	if (visible)
	{
		E.style.display = 'inline';
		E.style.visibility = 'visible';
	}
	else
	{
		E.style.display = 'none';
		E.style.visibility = 'hidden';
	}
	E.style.right = "";
	E.style.bottom = "";
	if (right)
	{
		var Loc = parseInt(E.style.width);
		Loc = 988 - (Loc + X);
		E.style.left = Loc + "px";
	}
	else
	{
		try{
		var Arg = X + "px";
		E.style.left = Arg;
		}
		catch(err)
		{
		}
	}
	E.style.top = Y + "px";
}
function ShowLarger()
{
	S = "http://secure.vixenhill.com/Gazebos/QuickDisplay.aspx?";
	S += currentConfig(WallLocations.front).queryString();
	S += "&Shape=" + Design.nameQS;
	if (Design.RS)
	{
		S += "&" + currentConfig(WallLocations.right).queryString();
		if (Design.C)
		{
			S += "&" + currentConfig(WallLocations.rightcorner).queryString();
		}
	}
	if (Design.LS)
	{
		S += "&" + currentConfig(WallLocations.left).queryString();
		if (Design.C)
		{
			S += "&" + currentConfig(WallLocations.leftcorner).queryString();
		}
	}
	S += "&COLOR=238!238!255&label=yes&w=1500&h=1000";
	window.open(S);
}
function getPorchQS()
{
	S = "http://secure.vixenhill.com/Gazebos/QuickDisplay.aspx?";
	S += currentConfig(WallLocations.front).queryString();
	S += "&Shape=" + Design.nameQS;
	S += "&DL=" + Design.deckLength;
	S += "&DW=" + Design.deckWidth;
	if (Design.RS)
	{
		S += "&" + currentConfig(WallLocations.right).queryString();
		if (Design.C)
		{
			S += "&" + currentConfig(WallLocations.rightcorner).queryString();
		}
	}
	if (Design.LS)
	{
		S += "&" + currentConfig(WallLocations.left).queryString();
		if (Design.C)
		{
			S += "&" + currentConfig(WallLocations.leftcorner).queryString();
		}
	}
	S += "&COLOR=238!238!255&label=yes";
	return S;
}
function InitializePorch()
{
	show('BPChangeLengths');
	hide('BPBackBut','BPBut','ButtonFrontDoor','ButtonRightDoor','ButtonLeftDoor','ControlRightWW', 'ControlLeftWW');
	var C = "none";
	visControls(C, C, C, C, C, C);
	Design = new Porch(currentDepth, currentWidth);
	switch (currentShape)
	{
		case 1:
		setDesignValues(Design, "Left Handed L", "LeftHandedL", true, false, false, 4, 4);
		break;
		case 2:
		setDesignValues(Design, "Straight", "OneSided", false, false, false, 0, 0);
		break;
		case 3:
		setDesignValues(Design, "Right Handed L", "RightHandedL", false, true, false, 4, 4);
		break;
		case 4:
		setDesignValues(Design, "Three Sided", "UShaped", true, true, false, 4, 8);
		break;
	}


	Design.rightDoor = SelectedDoor("Right");
	Design.leftDoor = SelectedDoor("Left");
	Design.frontDoor = SelectedDoor("Front");
	Design.Center = new Object();
	Design.RightSide = new Object();
	Design.LeftSide = new Object();
	Design.Corner = new Object();
	var MPW = 3.625;
	var MECW = .5;
	var SQTT = 1.41421 / 2.0;
	var M45TP = 1.6242;
	var CP45 = 1.9618;
	var POST = 3.625;



	var FDL, LDL, RLD;
	FDL = $('FrontDoorLocation').selectedIndex;
	LDL = $('LeftDoorLocation').selectedIndex;
	RDL = $('RightDoorLocation').selectedIndex;
	var ModularEndPosts = new Array();
	ModularEndPosts.push(new endPost(4.125, false, true, "MEP-"));
	var StandardEndPosts = new Array();
	StandardEndPosts.push(new endPost(.5, false, true, "MCP-CAP-"));
	var CornerEndPosts = new Array();
	CornerEndPosts.push(new endPost(M45TP, true, true, "EP45-"));
	ModularEndPosts[0].isModular=true;
	var JoiningPosts = new Array();
	var ModJP = new joiningPost(4.625, "MJP-");
	ModJP.isModular = true;


	JoiningPosts.push(ModJP);
	if (!($('ChkUpperTier').checked))
	{
		JoiningPosts.push(new joiningPost(1.5, "JP1-"));
	}
	Design.WallConfigurations = new Array();
	Design.Walls = new Array();
	var CFEP, CREP;
	CFEP = StandardEndPosts;
	CREP = StandardEndPosts;
	if (!Design.LS)
	{
		CFEP = ModularEndPosts;
	}
	if (!Design.RS)
	{
		CREP = ModularEndPosts;
	}
	if (Design.C)
	{
		if (Design.LS)
		{
			CFEP = CornerEndPosts;
		}
		if (Design.RS)
		{
			CREP = CornerEndPosts;
		}
	}




var AR = getRetrofitEnteredValues("FC");
	
Design.WallConfigurations[WallLocations.front] = RetrofitConfigurations(AR.L, AR.PL, AR.PW, WallLocations.front, FDL, Design.frontDoor, AR.DL, CFEP, JoiningPosts);




	if (Design.RS)
	{
	AR = getRetrofitEnteredValues("RS");
	Design.WallConfigurations[WallLocations.right] = RetrofitConfigurations(AR.L, AR.PL, AR.PW, WallLocations.right, RDL, Design.rightDoor, AR.DL, CFEP, JoiningPosts);

	}
	if (Design.LS)
	{
	var AR = getRetrofitEnteredValues("LS");
	Design.WallConfigurations[WallLocations.left] = RetrofitConfigurations(AR.L, AR.PL, AR.PW, WallLocations.left, LDL, Design.leftDoor, AR.DL, CFEP, JoiningPosts);
	}

Design = getMudRoomDesign(currentMudroomDoor);
	CheckErrors();
}



HeaderLeft = 3.585;
HeaderCompanyName = ""

function REreplace(s, RE, replacement)
{
var Sentry=true;
var sub;
while (Sentry)
{
sub = s.replace(RE, replacement);
if (!(RE.test(sub)))
	{Sentry=false;}
s = sub;

}
return s;
}




function overrides()
{
if ($('OverridechkDiscount').checked)
	{
	Discount = parseFloat($('OverrideDiscount').value) / 100;
	}
	else
	{
	Discount = 0;
	}
QuoteInfoChanged();

}

var Ximage;
var ImageTimeout;
var regex = /[iI][dD]=['"]*.*?['"]* /;

function updatedHeaderCN()
{
$('QuoteCompanyName').innerHTML = $('customizeCompanyName').value;



HeaderCompanyName = "<span style='position:absolute;top:.23in;left:" + HeaderLeft + "in;font-size:.35in'>" + $('customizeCompanyName').value +"</span>"

var Preview = $('QuoteHeaderSub').innerHTML;
Preview = REreplace(Preview, regex, "");
$('HeaderPreview').innerHTML = Preview;
}




function updatedTagHeader()
{
$('QuoteTagline').innerHTML = $('customizeTagLine').value;
var Preview = $('QuoteHeaderSub').innerHTML;
Preview = REreplace(Preview, regex, "");
$('HeaderPreview').innerHTML = Preview;

if ($('customizeSalesRep').value.length > 0)
{
$('QuoteSalesRep').innerHTML = "Sales Rep: " + $('customizeSalesRep').value;
}
else
{
$('QuoteSalesRep').innerHTML = "";
}

}


function updatedHeader()
{
clearTimeout(ImageTimeout);
ImageTimeout = setTimeout('XILTO()', 500);

$('QuoteLogo').style.display = 'none';
$('QuoteTagline').innerHTML = $('customizeTagLine').value;
HeaderLeft = 0;


var Preview = $('QuoteHeaderSub').innerHTML;
Preview = REreplace(Preview, regex, "");
$('HeaderPreview').innerHTML = Preview;
updatedHeaderCN();

}

function XILTO()
{

$('QuoteLogo').style.display = 'none';
$('QuoteCompanyName').style.left = ".1in";
ImageLogo = "";

var Preview = $('QuoteHeaderSub').innerHTML;
Preview = REreplace(Preview, regex, "");
$('HeaderPreview').innerHTML = Preview;
$('QuoteLogo').src = $('customizeURL').value;
Ximage = new Image();
Ximage.onload = XIL;
Ximage.src = $('customizeURL').value;



$('customizeURL').style.backgroundColor = 'yellow';
}



function XIL()
{
var W, H;
W = Ximage.width;
H = Ximage.height;

if (H==1 && W==1)
{

}
else
{
if (W/H > 3.585 / .75)
{
var Scale = 3.585 / W;
H = H * Scale;
W = 3.585;
}
else
{
var Scale = .75 / H;
W = W * Scale;
H = .75;
}
$('customizeURL').style.backgroundColor = 'white';
$('QuoteLogo').style.display = '';
$('QuoteLogo').style.width = W + "in";
$('QuoteLogo').style.height = H + "in";

if (H < .75)
{
$('QuoteLogo').style.top = ((.75 - H)/2) + "in";
}
else
{
$('QuoteLogo').style.top = "0in";
}


$('QuoteCompanyName').style.left = (W + .1) + "in";
HeaderLeft = W + .1;
updatedHeaderCN();
var Preview = $('QuoteHeaderSub').innerHTML;
Preview = REreplace(Preview, regex, "");
$('HeaderPreview').innerHTML = Preview;

ImageLogo = "<img style='position:absolute;top:0in;left:0in;width:" + W + "in; height:" + H + "in;' src='" + $('customizeURL').value + "'/>";


}





}

function CloseCustomize()
{
$('QuoteCustomerInformation').style.display = '';
$('QuoteCustomization').style.display = 'none';
}

function OpenCustomize()
{
$('QuoteCustomerInformation').style.display = 'none';
$('QuoteCustomization').style.display = '';
updatedHeader();

}



var NoteCount = 0;
var GlobalPrintDoc;






var CalledBack;

function SeeQuoteX()
{
	if (InfoError)
	{
		return;
	}
PrintableVersion(false);
CalledBack = GPVCB;
AjaxSavePorch();	
}

function SQXCB()
{
}


function GoPrintableVersion()
{
	if (InfoError)
	{
		return;
	}
PrintableVersion(true);
CalledBack = GPVCB;
AjaxSavePorch();
}

function GPVCB()
{
}

function SubmitForReviewX()
{
	if (InfoError)
	{
		return;
	}
$('SavingDiv').style.display = '';
CalledBack = SFRCB;
AjaxSavePorch();
}

function SFRCB()
{
SetupEmailRequest();
}

function SaveThisQuote()
{
	if (InfoError)
	{
		return;
	}
$('SavingDiv').style.display = '';
CalledBack = STQCB;
AjaxSavePorch();
}

function STQCB()
{
$('SavingDiv').style.display = 'none';
alert("Your porch has been saved.  Your Quote Number is " + QuoteNumber);
}


function GoCheckoutX()
{
$('ManifestSaving').style.display = '';
CalledBack = CheckoutBack;
AjaxSavePorch();
}

function CheckoutBack()
{
Checkout();
}


function SanitizeJS(text)
{
text = escape(text);
return text;
}









function OpenNotes()
{
$('NotesDiv').style.display = '';
$('NotesFooter').style.display = '';
$('QuoteCustomerInformation').style.display = 'none';
if (NoteCount == 0)
{
AddNote();
}
}

function CloseNotes()
{
$('NotesDiv').style.display = 'none';
$('NotesFooter').style.display = 'none';
$('QuoteCustomerInformation').style.display = '';
}




function AddNote()
{
var vals = new Array();
for (t=1;t<=NoteCount;t++)
{
vals[t] = document.getElementById('Note' + t).value;
}


NoteCount += 1;
var S = "<span id='NoteSpan" + NoteCount + "'>Note:<input maxlength='110' id='Note" + NoteCount + "' type='text' style='width:600px'>";
S += "<button onClick='removeNote(" + NoteCount + ")' class='bgreen twhite'>Remove</button><br/></span>";
$('NotesDiv').innerHTML += S;

for (t=1;t<=NoteCount-1;t++)
{
document.getElementById('Note' + t).value = vals[t];
}

}


function removeNote(x)
{
for (var t=x;t<NoteCount;t++)
{
var up, down;
down = document.getElementById('Note' + t);
up = document.getElementById('Note' + (t+1));
down.value = up.value;
}
$('NotesDiv').removeChild(document.getElementById('NoteSpan' + NoteCount));
NoteCount -= 1;
}

function MudroomHeight(value)
{
Clear('MudroomHeight', 2);
Select('MudroomHeight', value);
setDDLvalue($('selectHeightE'), 0);
if (value == 1)
{
setDDLvalue($('selectHeight'), 85);
}
else
{
setDDLvalue($('selectHeight'), 97);
}
}








