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 = 0.75;
var CP45 = 1.9618;
var POST = 3.625;
var IncludeRoof = false;
var FixingSteps = new Array();
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;
var NoteCount = 0;
var GlobalPrintDoc;

Array.prototype.contains = function(obj) {
  var i = this.length;
  while (i--) {
    if (this[i] === obj) {
      return true;
    }
  }
  return false;
}



function setupEPList()
{
	var DDL = $('numElectricalPosts');
	var lastValue = getDDLvalue(DDL);
	clearOptions(DDL);
	for (var t=0;t<=getCountOfPosts();t++)
		{
			addOption(DDL, t,t);
		}
	setDDLvalueBySoftTest(DDL, lastValue);
}

function numEPChanged()
{
ChangePriceLabel();
}

function electricalPostsCount()
{
	return selectedValue($('numElectricalPosts'));
}

function getCountOfPosts()
{
var count = 0;
for (var t=0;t<Manifest.length;t++)
	{
	var I = Manifest[t];
	if (I.item.name.indexOf("MJP")!=-1 || I.item.name.indexOf("JP1")!=-1 || I.item.name.indexOf("JP2")!=-1)
		{
			count += I.count;
		}
	}
return count;
}

function getAllOverridesQuery()
{

	var Output=new Array();
	var result;
	if (Design.RS)
	{
		result = getOverrideQuery(currentConfig(WallLocations.right).Parts);
		if (result.length > 0)
			{
				Output.push("ORIRS=" + result);
			}
			
		if (Design.C)
		{
			result = getOverrideQuery(currentConfig(WallLocations.rightcorner).Parts);
			if (result.length > 0)
				{
					Output.push("ORIRC=" + result);
				}
		}
	}
	
	if (Design.LS)
	{
		result = getOverrideQuery(currentConfig(WallLocations.left).Parts);
		if (result.length > 0)
			{
				Output.push("ORILS=" + result);
			}
			
		if (Design.C)
		{
			result = getOverrideQuery(currentConfig(WallLocations.leftcorner).Parts);
			if (result.length > 0)
				{
					Output.push("ORILC=" + result);
				}
		}
	}
	
	result = getOverrideQuery(currentConfig(WallLocations.front).Parts);
			if (result.length > 0)
				{
					Output.push("ORIFC=" + result);
				}
	
	if (Output.length > 0)
		{
			return "&" + Output.join("&");
		}
	else
		{return "";}
}


function getOverrideQuery(Parts)
{
var Item, CN, Ind;
var ORUN, ORLN;
ORUN = new Array();
ORLN = new Array();
	for(t=0;t<Parts.length;t++)
		{
			Item = Parts[t];
			if (Item.overrideUpperInsert)
				{
					if (ORUN.contains(Item.overrideUpperInsertCode))
						{
						}
					else
						{
						ORUN.push(Item.overrideUpperInsertCode);
						}
				}
			if (Item.overrideLowerInsert)
				{
					if (ORLN.contains(Item.overrideLowerInsertCode))
						{
						}
					else
						{
						ORLN.push(Item.overrideLowerInsertCode);
						}
				}
		}
	
	var returned = new Array();
	
	for (t=0;t<ORUN.length;t++)
		{
			CN = ORUN[t];
			Ind = new Array();
				for (x=0;x<Parts.length;x++)
					{
						Item = Parts[x];
						if (Item.overrideUpperInsert && (Item.overrideUpperInsertCode = CN))
							{
								Ind.push(x);
							}
					}
			var S="U-" + CN + "-" + Ind.join(",");
			returned.push(S);
		}
		
	for (t=0;t<ORLN.length;t++)
		{
			CN = ORLN[t];
			Ind = new Array();
				for (x=0;x<Parts.length;x++)
					{
						Item = Parts[x];
						if (Item.overrideLowerInsert && (Item.overrideLowerInsertCode = CN))
							{
								Ind.push(x);
							}
					}
			var S="L-" + CN + "-" + Ind.join(",");
			returned.push(S);
		}

	return returned.join("!");
}


function getPrice(partName, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame, partItem)
{
	var X = getPart(partName);
	var Nada;
	
	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-" + getUIwithOverride(partItem, UpperInsert) + "-" + X.upperInsertGroup).upperInsertGroup !="Z")
		{
			pN = "UGLASS-" + X.upperInsertGroup;
			returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame, Nada);
		}
		if (getPart("UI-" + getUIwithOverride(partItem, UpperInsert) + "-" + X.upperInsertGroup).upperInsertGroup !="Z")
		{
			pN = "USCREEN-" + X.upperInsertGroup;
			returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame, Nada);
		}
		
		if (reverseFrame)
		{
			pN = "URF-" + X.upperInsertGroup;
			returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame, Nada);
		}
		pN = "UI-" + getUIwithOverride(partItem, UpperInsert) + "-" + X.upperInsertGroup;
		returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame, Nada);
	}
	if (X.lowerInsertGroup != "X" && X.lowerInsertGroup != "Z")
	{
		if (hasGlass && getPart("LI-" + getLIwithOverride(partItem, lowerInsert) + "-" + X.lowerInsertGroup).lowerInsertGroup !="Z")
		{
			pN = "LGLASS-" + X.lowerInsertGroup;
			returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame, Nada);
		}
		if (getPart("LI-" + getLIwithOverride(partItem, lowerInsert) + "-" + X.lowerInsertGroup).lowerInsertGroup !="Z")
		{
			pN = "LSCREEN-" + X.lowerInsertGroup;
			returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame, Nada);
		}
		if (reverseFrame)
		{
			pN = "LRF-" + X.upperInsertGroup;
			returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame, Nada);
		}
		pN = "LI-" + getLIwithOverride(partItem, lowerInsert) + "-" + X.lowerInsertGroup;
		returned += getPrice(pN, paintColor, hasGlass, UpperInsert, lowerInsert, reverseFrame, Nada);
	}
	ManifestAdd(X, paintColor);
	return returned;
}


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, array[g]);
	}
	return total;
}


	
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, 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;
		if(Design.c)
		{
			if (Design.RS)
			{
				ATG += 10.0;
			}
			if (Design.LS)
			{
				ATG += 10.0;
			}
		}
		else
		{
			if (Design.RS)
			{
				ATG += 10.0;
			}
			if (Design.LS)
			{
				ATG += 10.0;
			}
			
		}
		
		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, new post());
		}
		if (ditmarBeam)
		{
			if (Design.C)
			{
				ATG = currentConfig(WallLocations.right).wall.runlength;
				ATG += 8.5;
				Total += DitmarPrice(ditmarBeam, ATG, paintColor);
			}
			else
			{
				ATG = currentConfig(WallLocations.right).wall.runlength;
				ATG += 8.5;
				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;
				ATG += 8.5;
				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, new post());
		}
		if (ditmarBeam)
		{
		
			if (Design.C)
			{
				ATG = currentConfig(WallLocations.left).wall.runlength;
				ATG += 8.5;
				Total += DitmarPrice(ditmarBeam, ATG, paintColor);
			}
			else
			{
				ATG = currentConfig(WallLocations.left).wall.runlength;
				ATG += 8.5;
				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;
				ATG += 8.5;
				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;
	}
	
	if (electricalPostsCount() > 0)
		{
		Total += ElectricalPostsPrice(paintColor);
		}
	
	Total += getLineItemsPrice();
	return Total * (1-Discount);
}



function GetCornerConfig(side, length)
{

	var Location;
	if (side=="LC")
	{
		Location = WallLocations.leftcorner;
	}
	else
	{
		Location = WallLocations.rightcorner;
	}
	var PanelLength = $('CornerLength').selectedIndex;
	var D;
	switch (PanelLength)
		{
		case 1:
		D = new Door(false, 49, 38, true, 4, "PD-49", false);
		break;
		case 2:
		D = new Door(false, 63, 52, true, 4, "PD-63", false);
		break;
		case 0:
		D = new Door(new endPost(4.125, false, true, "MEP-"), 36, 36, false, 0, "FD-36", false);
		break;
		}
	
	var CornerEndPosts = new Array();
	CornerEndPosts.push(new endPost(M45TP, true, true, "EP45-"));
	var JoiningPosts = new Array();
	var ModJP = new joiningPost(4.625, "MJP-");
	JoiningPosts.push(ModJP);
	if (CornerIsDoor(side))
	{
		return GetConfigurations(length, CornerEndPosts, CornerEndPosts, JoiningPosts, false, 0, 0, 2, D, Location);
	}
	else
	{
		return GetConfigurations(length, CornerEndPosts, CornerEndPosts, JoiningPosts, false, 0, 0, 0, Design.leftDoor, Location);
	}
	
}



function CornersHaveDoors()
{
	return $('CornerDoorSelect').selectedIndex != 0;
}

function CornerIsDoor(CornerName)
{
	var isDoor;
	var isDoorDDL = getDDLvalue($('CornerDoorSelect'));
	if (CornerName=="RC")
	{
		isDoor = (isDoorDDL == "Right Corner Door" || isDoorDDL == "Both Doors" || isDoorDDL == "Door");
	}
	else
	{
		isDoor = (isDoorDDL == "Left Corner Door" || isDoorDDL == "Both Doors" || isDoorDDL == "Door");
	}
	return isDoor;
}


var ConfigurationsBeforeBack = new Array();
ConfigurationsBeforeBack["configLeft"] = "";
ConfigurationsBeforeBack["configFront"] = "";
ConfigurationsBeforeBack["configRight"] = "";

HeaderLeft = 3.585;
HeaderCompanyName = ""
var CalledBack;


var LastHinged, LastSwing, LastDoorSelected;
LastHinged = 1;
LastSwing = 1;
LastDoorSelected = 0;


function CornerTypeChanged()
{
	var DDL = $('CornerDoorSelect');
	var lastValue = getDDLvalue(DDL);
	clearOptions(DDL);
	if	(currentShape == 5)
	{
	addOption(DDL, "No Door", "No Door");
	addOption(DDL, "Left Corner Door", "Left Corner Door");
	addOption(DDL, "Right Corner Door", "Right Corner Door");
	addOption(DDL, "Both Doors", "Both Doors");
		
	}
	else
	{
	addOption(DDL, "No Door", "No Door");
	addOption(DDL, "Door", "Door");
	}
}




var LineItemCount = 0;


function getLineItemsPrice()
{
	var total = 0;
	for (t=1;t<=LineItemCount;t++)
	{
		total += parseFloat($('LineItemCost' + t).value);
	}
	return total;
}

function OpenLineItems()
{
$('LineItemsDiv').style.display = '';
$('LineItemsFooter').style.display = '';
$('QuoteCustomerInformation').style.display = 'none';
if (LineItemCount == 0)
{
AddLineItem();
}
}

function CloseLineItem()
{
$('LineItemsDiv').style.display = 'none';
$('LineItemsFooter').style.display = 'none';
$('QuoteCustomerInformation').style.display = '';
QuoteInfoChanged();
}


function AddLineItem()
{
var vals = new Array();
var Costs = new Array();


for (t=1;t<=LineItemCount;t++)
{
vals[t] = document.getElementById('LineItem' + t).value;
}

for (t=1;t<=LineItemCount;t++)
{
Costs[t] = document.getElementById('LineItemCost' + t).value;
}

LineItemCount += 1;
var S = "<span id='LineItemSpan" + LineItemCount + "'>Line Item:<input maxlength='110' id='LineItem" + LineItemCount + "' type='text' style='width:350px'>";
S += "Cost: $<input id='LineItemCost" + LineItemCount + "' type='text' style='width:100px'><button onClick='removeLineItem(" + LineItemCount + ")' class='bgreen twhite'>Remove</button><br/></span>";
$('LineItemsDiv').innerHTML += S;

for (t=1;t<=LineItemCount-1;t++)
{
document.getElementById('LineItem' + t).value = vals[t];
document.getElementById('LineItemCost' + t).value = Costs[t];
}

}


function removeLineItem(x)
{
for (var t=x;t<LineItemCount;t++)
{
var up, down;
down = document.getElementById('LineItem' + t);
up = document.getElementById('LineItem' + (t+1));
down.value = up.value;

down = document.getElementById('LineItemCost' + t);
up = document.getElementById('LineItemCost' + (t+1));
down.value = up.value;


}
$('LineItemsDiv').removeChild(document.getElementById('LineItemSpan' + LineItemCount));
LineItemCount -= 1;
}







function getDDLtext(DDL)
{
	if (DDL.selectedIndex == -1)
	{
		return undefined;
	}
	return DDL.options[DDL.selectedIndex].text;
} 

function StoreCurrentConfigurationOnBack()
{
	ConfigurationsBeforeBack['configLeft'] = getDDLtext($('configLeft'));
	ConfigurationsBeforeBack['configFront'] = getDDLtext($('configFront'));
	ConfigurationsBeforeBack['configRight'] = getDDLtext($('configRight'));
}

function RestoreSelectedConfigurationAfterBack()
{
setDDLvalueBySoftTest($('configLeft'), ConfigurationsBeforeBack['configLeft']);
setDDLvalueBySoftTest($('configFront'), ConfigurationsBeforeBack['configFront']);
setDDLvalueBySoftTest($('configRight'), ConfigurationsBeforeBack['configRight']);
ConfigChanged($('configLeft'), WallLocations.left);
ConfigChanged($('configFront'), WallLocations.front);
ConfigChanged($('configRight'), WallLocations.right);
}

function NewDoorChanged()
{

switch (LastDoorSelected)
	{
	case 0:
		DoorSelected(1);
	break;
	
	case 1:
		if (LastSwing==1)
			{
			if (LastHinged==1)
				{
				DoorSelected(3);
				}
			else
				{
				DoorSelected(8);
				}
			}
		else
			{
			if (LastHinged==1)
				{
				DoorSelected(2);
				}
			else
				{
				DoorSelected(7);
				}
			}
	break;
	
	case 2:
		DoorSelected(4);
	break;
	
	case 3:
		DoorSelected(5);
	break;
	
	case 4:
		DoorSelected(6);
	break;
	
	case 5:
		if (LastSwing==1) //SwingIn
			{
			if (LastHinged==1) //Left
				{
				DoorSelected(10);
				}
			else //Right
				{
				DoorSelected(12);
				}
			}
		else //SwingOut
			{
			if (LastHinged==1) //Left
				{
				DoorSelected(9);
				}
			else				//Right
				{
				DoorSelected(11);
				}
			}
	break;
	
	}
}

function RevisionSetDoor(value)
{
	LastDoorSelected = value;
	if (value==0)
		{
		hide('DivDoorHasLocation');
		hide('DoorSwingSelector', 'DoorHingedSelector');
		}
	else
		{
		show('DivDoorHasLocation');
		if (value==1 || value==5)
			{
			show('DoorSwingSelector', 'DoorHingedSelector');
			RevisionHingedChanged(2);
			RevisionSwingChanged(2);
			}
		else
			{
			hide('DoorSwingSelector', 'DoorHingedSelector');
			}
		}
	NewDoorChanged();
}

function RevisionHingedChanged(value)
{
	Clear('RevisionHingedSelected', 2);
	Select('RevisionHingedSelected', value);
	LastHinged = value;
	NewDoorChanged();
}

function RevisionSwingChanged(value)
{
	Clear('RevisionSwingSelected', 2);
	Select('RevisionSwingSelected', value);
	LastSwing = value;
	NewDoorChanged();
}

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

}

function SilentSave()
{
if (!QuoteNumber)
{
CalledBack = SQXCB;
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.split("-")[1] + ".  Please write this number down, as you will need it to restore this quote.");
}


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

function CheckoutBack()
{
Checkout();
}


function SanitizeJS(text)
{
text = escape(text.replace(/'/g, ""));
return text;
}



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 = unescape('" + SanitizeJS($(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 = 2;
	break;
	case "QUEENANNEHALF":
	X = 3;
	break;
	case "DIVIDEDLIGHT":
	X = 4;
	break;
	case "OPENFRAME":
	X = 1;
	break;
	}
S += "selectZone('UI', " + X + ");";
X = 5;
switch (CurrentUI)
	{
	case "VICTORIANBALLUSTER":
	X = 2;
	break;
	case "QUEENANNEBALLUSTER":
	X = 3;
	break;
	case "PANEL":
	X = 4;
	break;
	case "OPENFRAME":
	X = 1;
	break;
	}
S += "selectZone('LI', " + X + ");";
return S;
}




function GoRequest()
{
	RQuoteInfoChanged();
	show('RequestInfo');
	hide('ManifestStage');
}

function RequestBack()
{
	hide('RequestInfo');
	show('ManifestStage');
}




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]=[\d\w]*/;
var regex2 = /[iI][dD]=[\d\w]*>/;

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


function UpdateHeaderPreview()
{
var Preview = $('QuoteHeaderSub').innerHTML;
Preview = REreplace(Preview, regex2, ">");
Preview = REreplace(Preview, regex, "");
$('HeaderPreview').innerHTML = Preview;
}



function updatedTagHeader()
{
$('QuoteTagline').innerHTML = $('customizeTagLine').value;

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


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

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

}

function XILTO()
{

$('QuoteLogo').style.display = 'none';
$('QuoteCompanyName').style.left = ".1in";
ImageLogo = "";
UpdateHeaderPreview();
$('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();
UpdateHeaderPreview();
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();

}



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 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;
		$('ShipEmail').value = $('BillEmail').value;
	}
	
	var CName = $('BillCompany').value;
	CName = CName.replace(" ", "");
	if (CName.length > 0)
	{
		var YAL = "";
		YAL += $('BillStreet').value;
		
		if ($('BillSuite').value.replace(" ", "").length > 0)
		{
			YAL += ", " + $('BillSuite').value;
		}
		
		YAL += ", " + $('BillCity').value + ", " + getDDLvalue($('BillState')) + " " + $('BillZIP').value;
		if ($('BillPhone').value.replace(" ", "").length > 0)
		{
			YAL += " Ph: " + $('BillPhone').value;
		}
		
		if ($('BillFAX').value.replace(" ", "").length > 0)
		{
			YAL += " FAX: " + $('BillFAX').value;
		}
		
		if ($('BillEmail').value.replace(" ", "").length > 0)
		{
			YAL += " Email: " + $('BillEmail').value;
		}
		
		
		$('customizeTagLine').value = YAL;
		$('customizeCompanyName').value = $('BillCompany').value;
		updatedHeaderCN();
		updatedTagHeader();
	}
	
	var Price, Ship, Tax, Total, State, Install;
	State = selectedValue($('ShipState'));
	Ship = getShipCost(State);
	Price = getPorchPrice(CurrentPaint, CurrentGlass, CurrentUI, CurrentLI, CurrentDitmar, CurrentFrame);
	
	
	Tax = 0;

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

	if ($('OverrideShipping').checked)
	{
		Ship = Math.floor(100 * parseFloat($('OverrideShippingText').value))/100;
		$('InfoShip').innerHTML = Currency(Ship);
	}
	else
	{
	if (Ship == 0)
	{
		$('InfoShip').innerHTML = "CALL";
	}
	else
	{
		$('InfoShip').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;
	var Error = false;
	Error = verify("Ship");
	Error = verify("Bill");
	InfoError=Error;
	if (Error)
	{
		$('PrintableFinalButton').style.backgroundColor='#777777';
		$('PrintableSaveButton').style.backgroundColor='#777777';
		$('PrintableReviewButton').style.backgroundColor='#777777';
		$('PrintableSeeQuoteButton').style.backgroundColor='#777777';
		
		
	}
	else
	{
		$('PrintableFinalButton').style.backgroundColor='';
		$('PrintableSaveButton').style.backgroundColor='';
		$('PrintableReviewButton').style.backgroundColor='';
		$('PrintableSeeQuoteButton').style.backgroundColor='';
	}
	$('InfoPorch').innerHTML = Currency(Price);

	$('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 FrameColor = "DisabledFrame";
var UUG, LUG;
UUG = getPart("UI-" + CurrentUI + "-A").upperInsertGroup=="Z";
LUG = getPart("LI-" + CurrentLI + "-A").lowerInsertGroup=="Z";

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

	}
	else
	{
	hide(Glass);
	hide(FrameColor);
	}

}



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

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

function DoorButtonPress(target)
{

	Clear('RevisionHingedSelected', 2);
	Clear('RevisionSwingSelected', 2);

	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)
	{
		show('DivDoorHasLocation');
		hide('DoorSwingSelector', 'DoorHingedSelector');
		DoorLocationSelected(DL);
		if (DT==0)
		{
		setRevisionSelectedValue(1);
		show('DoorSwingSelector', 'DoorHingedSelector');
	
			if (DS)
			{
				if (RH)
				{
					DoorSelected(8);
					Select('RevisionHingedSelected', 2);
					LastHinged = 2;
					Select('RevisionSwingSelected', 1);
					LastSwing = 1;
	
				}
				else
				{
					DoorSelected(3);
					Select('RevisionHingedSelected', 1);
					LastHinged = 1;
					Select('RevisionSwingSelected', 1);
					LastSwing = 1;
				}
			}
			else
			{
				if (RH)
				{
					DoorSelected(7);
					Select('RevisionHingedSelected', 2);
					LastHinged = 2;
					Select('RevisionSwingSelected', 2);
					LastSwing = 2;
				}
				else
				{
					DoorSelected(2);
					Select('RevisionHingedSelected', 1);
					LastHinged = 1;
					Select('RevisionSwingSelected', 2);
					LastSwing = 2;
				}
			}
		}
		
		if (DT==4)
		{
		setRevisionSelectedValue(5);
		show('DoorSwingSelector', 'DoorHingedSelector');
	
			if (DS)
			{
				if (RH)
				{
					DoorSelected(12);
					Select('RevisionHingedSelected', 2);
					LastHinged = 2;
					Select('RevisionSwingSelected', 1);
					LastSwing = 1;
	
				}
				else
				{
					DoorSelected(10);
					Select('RevisionHingedSelected', 1);
					LastHinged = 1;
					Select('RevisionSwingSelected', 1);
					LastSwing = 1;
				}
			}
			else
			{
				if (RH)
				{
					DoorSelected(11);
					Select('RevisionHingedSelected', 2);
					LastHinged = 2;
					Select('RevisionSwingSelected', 2);
					LastSwing = 2;
				}
				else
				{
					DoorSelected(9);
					Select('RevisionHingedSelected', 1);
					LastHinged = 1;
					Select('RevisionSwingSelected', 2);
					LastSwing = 2;
				}
			}
		}
		
		
		if (!(DT==4 || DT == 0))
		{
			DoorSelected(DT + 3);
			setRevisionSelectedValue(DT+1);
		}
	}
	else
	{
		DoorSelected(1);
		hide('DivDoorHasLocation');
		hide('DoorSwingSelector', 'DoorHingedSelector');
		setRevisionSelectedValue(0);
	}
	$('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
	{
	if (Ship==0)
	{
		$('QuoteShipping').innerHTML = "CALL FOR PRICE";
	}
	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');
	BackToOptions();
}

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;
	$('ShipEmail').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);


	Input = document.createElement('input');
	Input.name = "QuoteNumber";
	Input.value = QuoteNumber;
	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.C)
			{
				target=WallLocations.rightcorner;
				adiv=getElevations(currentConfig(target).Parts, CurrentPaint, CurrentGlass, CurrentUI, CurrentLI);
				E.document.write("<div style='text-align:left;width:100%'>Right Corner</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.C)
		{
			target=WallLocations.leftcorner;
			adiv=getElevations(currentConfig(target).Parts, CurrentPaint, CurrentGlass, CurrentUI, CurrentLI);
			E.document.write("<div style='text-align:left;width:100%'>Left Corner</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 + HeaderCompanyName + "<div class='URLabel' 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 getNotes()
{
var CN = 1;
var Node = document.getElementById("Note" + CN);
var N = new Array();

if (CurrentFrameColor == 1)
{
N.push("Winchester Brown Screen/Storm Glass Frames");
}
else
{
N.push("White Screen/Storm Glass Frames");
}


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

}

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:relative;top:1px; left: 25%; width:402px; 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><button type='submit' onClick='window.print()' class='bgreen twhite' style='position:absolute;font-size:13px;text-decoration:underline;width:198px;height:26px;top:2px;right:2px'>Print</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>");
	
	
	var Div = document.createElement('div');

	

	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 getPartClassValue(S)
{
switch (S.item.partClass)
{
case "EndPost":
return 3;
break;
case "GlassUpper":
if (S.item.description.indexOf("Glass")==-1)
{
return 6;
}
else
{
return 7;
}
break;
case "GlassLower":
if (S.item.description.indexOf("Glass")==-1)
{
return 6;
}
else
{
return 7;
}
break;
break;
case "ReverseFrame":
return 5;
break;
case "InsertUpper":
return 4;
break;
case "InsertLower":
return 4;
break;
case "WallPanel":
return 1;
case "JoiningPost":
return 3;
break;
case "Door":
return 2;
case "Beam":
return 0;
case "Post":
return 3;
break;
}
return 8;
}



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

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

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



function manifestDisplayOrder(A, B)
{
	if (getPartClassValue(A) == getPartClassValue(B))
	{
		if (A.item.description > B.item.description)
		{
			return 1;
		}
		return -1;
	}
	else
	{
		if (getPartClassValue(A) > getPartClassValue(B))
		{
			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 ElectricalPostsPrice(paintColor)
{
	var Count=electricalPostsCount();
	var X;
	var N=getPart("DITMAR_BEAM_2X6");
	X = new PricedItem("ElectricalPostUpgrade", N.partClass, length, N.heightGroup, 85, N.Name, N.imageWidth, N.imageHeight, N.upperInsertGroup, N.lowerInsertGroup, N.paintPrice, N.stainPrice, N.twoTonePrice, N.insertsX, N.uiY, N.liY, "Electical Post Upgrade" , 'NI', "", N.weight * length, N.manifestImageHeight);
	for (var Q=1;Q<=Count;Q++)
		{
		ManifestAdd(X, paintColor);
		}
	return X.price * Count;
}

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)
{
	if (inUIOverRide)
	{
		OverridePanel.overrideUpperInsert = true;
		OverridePanel.overrideUpperInsertCode = in_name;
		if (in_name == CurrentUI)
			{
			OverridePanel.overrideUpperInsert = false;
			}
		inUIOverRide = false;
	}
	else
	{
		CurrentUI = in_name;
		selectZone("UI", value);
	}
	hide('PopupUI','Popup');
	show('OptionsControl');
	ElevationViewChanged();
	setGlassAvailable();
}

function popupLI(value, in_name)
{
	if (inLIOverRide)
	{
		OverridePanel.overrideLowerInsert = true;
		OverridePanel.overrideLowerInsertCode = in_name;
		if (in_name == CurrentLI)
			{
			OverridePanel.overrideLowerInsert = false;
			}
		inLIOverRide = false;
	}
	else
	{
		CurrentLI = in_name;
		selectZone("LI", value);
	}
	hide('PopupLI','Popup');
	show('OptionsControl');
	ElevationViewChanged();
	setGlassAvailable();
}

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

function setLI(value)
{

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

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

function setFrameColor(value)
{
	CurrentFrameColor = value;
	selectZone("FrameColor", value);
}

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

function setPaint(value)
{
	CurrentPaint=value-1;
	
	if (value == 3|| value == 2)
	{
	setFrameColor(2);
	}
else
	{
	setFrameColor(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.C)
		{
			addOption(Sel, "Left Corner", WallLocations.leftcorner);
		}
	}
	if (Design.RS)
	{
		addOption(Sel, "Right Wall", WallLocations.right);
		if (Design.C)
		{
			addOption(Sel, "Right Corner", WallLocations.rightcorner);
		}
	}
	
	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 = filename;
	return Image;
}

function locatedImageInsert(filename, width, height, position, left, top, Z, title, part, isUI)
{
	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 = 255;
	Image.title = filename;
	//Image.title = title;
	var AIndex = ElevationPanelArray.length;
	
	ElevationPanelArray.push(part);
	if (isUI)
		{
			bindEvent(Image,'click', function(){clickedOverRideUpperInsert(AIndex);});
		}
	else
		{
			bindEvent(Image, 'click', function(){clickedOverRideLowerInsert(AIndex);});
		}
	return Image;
}

function bindEvent(el, eventName, eventHandler) 
	{
	  if (el.addEventListener){
		el.addEventListener(eventName, eventHandler, false); 
	  } else if (el.attachEvent){
		el.attachEvent('on'+eventName, eventHandler);
	  }
	}


var inUIOverRide = false;
var inLIOverRide = false;
var OverridePanel;

function clickedOverRideUpperInsert(num)
{
	var part = ElevationPanelArray[num];
	inUIOverRide = true;
	
	OverridePanel = part;
	PopUI();
}

function clickedOverRideLowerInsert(num)
{
	var part = ElevationPanelArray[num];
	inLIOverRide = true;
	OverridePanel = part;
	PopLI();
}



var ElevationPanelArray; 

function getElevations(partsArray, paintColor, hasGlass, UI, LI)
{

	ElevationPanelArray = new Array();
	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';
	MainDiv.style.zIndex = '2509';
	
	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 getPart(partName)
{
	if (Prices[partName + getHeightGroup()])
	{
		return Prices[partName + getHeightGroup()];
	}
	else
	{
		return Prices[partName];
	}
}


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);
	H -= .75;
	return H;
}

function getHeightGroup()
{



	var H = getPanelHeight();
	if (H <= 85.75)
	{
		return "A";
	}
	if (H <= 91)
	{
		return "B";
	}
	if (H <= 96)
	{
		return "C";
	}
	if (H <= 100.75)
	{
		return "D";
	}
	if (H <= 106.5)
	{
		return "G";
	}
	if (H <= 111.75)
	{
		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=0;
					
					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;
						
						if (!Wall.usableParts.Door.needsSpecialEndPost)
						{
							FunctionalLength -= CFEP.runlength;
							FunctionalLength -= CREP.runlength;
							FunctionalLength -= CJP.runlength;
						}
						else
						{
							if (Wall.doorLocation == 3) //Door on Right Side
							{
								FunctionalLength -= CFEP.runlength;
							}
						else
							{
								FunctionalLength -= CREP.runlength;
							}
							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.overrideLowerInsert = false;
	this.overrideUpperInsert = false;
	this.overrideLowerInsertCode = -1;
	this.overrideUpperInsertCode = -1;
	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
		{
		var Buffer = MWP.clone();
		ST = ODDTOTALPUSHPANELS(ST, MWP, MWPC-1, LWP, LWPC, LEFT, JP);
		ST.push(JP.clone());
		ST.push(Buffer);
		return ST;
		}
	}
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 = DOOR.specialEndPost.clone();
		B.facesForward = true;
		ST.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 = DOOR.specialEndPost.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 = DOOR.specialEndPost.clone();
		B.facesForward = false;
		ST.push(B);
		ST.push(DOOR.clone());
		B = DOOR.specialEndPost.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";
	relocateControlsForShape();
	show('BPBut', 'BPBackBut', 'Controls')
	try
	{
	HeightConfig();
	}
	catch(err)
	{
	}
	
}

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';
	hide('BPBut', 'BPBackBut',  'ButtonFrontDoor', 'ButtonRightDoor', 'ButtonLeftDoor', 'ControlRightWW', 'ControlLeftWW');
}

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();
		MatchCustomToDefault();
		$('Workbar').selectedIndex = SelectableConfigurations.length - 1;
		WBlayoutChanged();
		RestoreSelectedConfigurationAfterBack();
		$("LrgAuto").src = getPorchQS();
	}
	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;
		case 4:
		D = new Door(new endPost(4.125, false, true, "MEP-"), 36, 36, false, 0, "FD-36", 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', true);
	setVisible('divCL', (Design.WallConfigurations[WallLocations.left] != nothing));
	setVisible('divCR', (Design.WallConfigurations[WallLocations.right] != nothing));
}

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

function setDDLvalueBySoftTest(ddl, ivalue)
{
 var target = -1;
 var mylength = ddl.options.length;
 for (qt = 0; qt < mylength; qt ++ )
	{
	if (ddl.options[qt].text == ivalue)
		{
		target = qt;
		}
	}
if (!(target==-1))
{
	ddl.selectedIndex = target;
}
} 


function setDDLvalueByTest(ddl, ivalue)
{
 var target = 0;
 var mylength = ddl.options.length;
 for (qt = 0; qt < mylength; qt ++ )
	{
	if (ddl.options[qt].text == ivalue)
		{
		target = qt;
		}
	}
ddl.selectedIndex = target;
} 


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(4.125, false, true, "MEP-"), 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)
{
	FixingSteps.push("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)
{
	FixingSteps.push("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)
{
	FixingSteps.push("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)
{
	FixingSteps.push("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()
{
	StoreCurrentConfigurationOnBack();
	FixingSteps = new Array();
	$('Lrg1').style.left = "0px";
	$('Lrg1').style.display = "inline";
	relocateControlsForShape();
	hide('LrgAuto','ConfigDiv','ErrorDiv','BPAccept','BPLarge','BPChangeLengths');
	show('BPBackBut','BPBut');
	
}

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

function BackToLayout()
{
	resetOptions();
	MatchCustomToDefault();
	$('Workbar').selectedIndex = SelectableConfigurations.length - 1;
	WBlayoutChanged();
	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 (!Design)
	{
		return nothing;
	}
if (value == WallLocations.leftcorner || value == WallLocations.rightcorner)
	{return Design.WallConfigurations[value][0];}
else
	{return Design.WallConfigurations[value][SelectableConfigurations[CurrentConfiguration][value]];}
}


function MatchCustomToDefault()
{
	if (Design)
	{
		if (Design.LS)
			{
			setDDLvalueByTest($('configLeft'), currentConfig(WallLocations.left).descriptor.Description);
			}
		if (Design.RS)
			{
			setDDLvalueByTest($('configRight'), currentConfig(WallLocations.right).descriptor.Description);
			}
		setDDLvalueByTest($('configFront'), currentConfig(0).descriptor.Description);
	}
}



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.overrideLowerInsert = false;
		this.overrideUpperInsert = false;
		this.overrideLowerInsertCode = -1;
		this.overrideUpperInsertCode = -1;
		
		
	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 removeAllChildrenX(element)
{
while (element.hasChildNodes)
	{element.removeChild(element.firstChild);}
}


function pdfAddresses(inputname, outputname)
{
createTextElement(outputname + "Name", $(inputname + "Name").value);
createTextElement(outputname + "Firm", $(inputname + "Company").value);
createTextElement(outputname + "Street", $(inputname + "Street").value);
createTextElement(outputname + "Suite", $(inputname + "Suite").value);
createTextElement(outputname + "City", $(inputname + "City").value);
createTextElement(outputname + "ZIP", $(inputname + "ZIP").value);
createTextElement(outputname + "Phone", $(inputname + "Phone").value);
createTextElement(outputname + "FAX", $(inputname + "FAX").value);
createTextElement(outputname + "Email", $(inputname + "Email").value);
createTextElement(outputname + "State", getDDLvalue($(inputname + 'State')));
	
}

function pdfHeaderSetup()
{
pdfAddresses('Bill', 'Sold');
pdfAddresses('Ship', 'Ship');

createTextElement("CompanyNameForHead", $('QuoteCompanyName').innerHTML);

if ($('QuoteLogo').style.display == 'none')
	{}
else
	{createTextElement("LogoURL", $('QuoteLogo').src);}
	createTextElement('Tagline', $('QuoteTagline').innerHTML);
	createTextElement('SalesRep', $('customizeSalesRep').value);

		var NLI = getNotes();
	for (var t=0;t<NLI.length;t++)
	{
	createTextElement("Note" + (t+1), NLI[t]);
	}
	
	if (!(Discount == 0))
	{
	createTextElement("Discount", Discount * 100);
	}
	
	if ($('OverrideInstallation').checked)
	{
	var Install = Math.floor(100 * parseFloat($('OverrideInstallationText').value))/100;
	createTextElement("Installation", Install);
	}
	


	if ($('OverrideTax').checked)
	{
		createTextElement("TaxRate", parseFloat($('OverrideTaxText').value)); 
	}	
	
	else
	{
		if (selectedValue($('ShipState')) == "PA")
		{
			createTextElement("TaxRate", 6); 
		}
		else
		{
			createTextElement("TaxRate", 0); 
		}
	}
	if ($('OverrideShipping').checked)
	{
		createTextElement("ShippingCost", Math.floor(100 * parseFloat($('OverrideShippingText').value))/100);
	}
	
	
}



function pdfImage(item, PPI, CX, CY, CP, hasGlass, UI, LI, DW, DH, trim, Elevation, Unit, FullItem)
{
	var scalefactor=1;
	var DrawWidth, DrawHeight, vOffset, hOffset;
	var DrawWidth = DW;
	var DrawHeight = DH;
	var IW=DW;
	var hOffset = 0;
	var CSU = 2;
	if (trim != nothing)
	{
	hOffset = (DrawWidth - RTT(item.imageWidth / PPI))/2;
	IW = RTT(item.imageWidth / PPI);
	}
	CreateElevationUnit(Elevation, Unit, CX, CY, DW, DH);
	CreateElevationSubUnit(Elevation, Unit, 1, hOffset, 0, IW, DH, "http://vixenhill.com" + getImageFilename(item, CurrentPaint));
	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-" + getUIwithOverride(FullItem, UI) + "-" + item.upperInsertGroup);
		FileN = getImageFilename(Ins, CurrentPaint);
		insY = RTT(item.uiY / PPI);
		DrawWidth = RTT(Ins.imageWidth / PPI);
		DrawHeight = RTT(Ins.imageHeight / PPI);
		CreateElevationSubUnit(Elevation, Unit, CSU, insX, insY, DrawWidth, DrawHeight, "http://vixenhill.com" + FileN);
		CSU += 1;
	}
	if (item.lowerInsertGroup != "X" && item.lowerInsertGroup != "Z")
	{
		Ins = getPart("LI-" + getLIwithOverride(FullItem, LI) + "-" + item.lowerInsertGroup);
		FileN = getImageFilename(Ins, CurrentPaint);
		insY = RTT(item.liY / PPI);
		DrawWidth = RTT(Ins.imageWidth / PPI);
		DrawHeight = RTT(Ins.imageHeight / PPI);
		CreateElevationSubUnit(Elevation, Unit, CSU, insX, insY, DrawWidth, DrawHeight, "http://vixenhill.com" + FileN);
	}

}

function getPDFElevations()
{
	var PPI = 150;
	var OldMan = Manifest;
	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;
	
	var currentWorkingElevation = 1;
	rowHeight = RTT(getPart(A[0].span[0].partName).imageHeight / PPI);
	var CurrentRow;
	
	for (t=0;t<A.length;t++)
	{
		CurrentRow = A[t];
		currentWorkingElevation += 1;
		createTextElement("ElevationName" + currentWorkingElevation, A[t].desc);
		CY = 0.0;
		CX = 0.0;
		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)
			{
				CX = 0;
				CY += rowHeight + .125;
			}
			pdfImage(item, PPI, CX, CY, CurrentPaint, CurrentGlass, CurrentUI, CurrentLI, DrawWidth, DrawHeight, tempitm.trim, currentWorkingElevation, c+1, tempitm);
			CX += DrawWidth;
		}
	}
	S += PageEnd;
	return S;
}

function PDFElevations()
{
	var PanelElevationURL = "http://secure.vixenhill.com/Gazebos/SideView.aspx?H=300&W=300" + "&P=" + getPanelHeight();
	if (CurrentDitmar != 0)
	{
	PanelElevationURL += "&D=TRUE";
	}
	createTextElement("ElevationName1", "");
	CreateElevationUnit(1, 1, 0, 0, 2, 2);
	CreateElevationSubUnit(1, 1, 1,  0, 0, 2, 2, PanelElevationURL);
	getPDFElevations();
}

function CreateElevationUnit(Elevation, Unit, Left, Top, Width, Height)
{

	createTextElement("Elevation" + Elevation + "Unit" + Unit + "Left", Left);
	createTextElement("Elevation" + Elevation + "Unit" + Unit + "Top", Top);
	createTextElement("Elevation" + Elevation + "Unit" + Unit + "Width", Width);
	createTextElement("Elevation" + Elevation + "Unit" + Unit + "Height", Height);
}

function CreateElevationSubUnit(Elevation, Unit, SubUnit, Left, Top, Width, Height, imageURL)
{

	createTextElement("E" + Elevation + "U" + Unit + "SU" + SubUnit +  "URL", imageURL);
	createTextElement("E" + Elevation + "U" + Unit + "SU" + SubUnit +  "L",  Left);
	createTextElement("E" + Elevation + "U" + Unit + "SU" + SubUnit +  "T", Top);
	createTextElement("E" + Elevation + "U" + Unit + "SU" + SubUnit +  "W", Width);
	createTextElement("E" + Elevation + "U" + Unit + "SU" + SubUnit +  "H", Height);
}

function PDFgetManifestQuoteImages()
{
Manifest.sort(manifestDisplayOrder);
var Current = 1;
	for (var t=0;t<Manifest.length;t++)
	{
		if  ((!(Manifest[t].item.dontManifest=='N')) && (!(Manifest[t].item.dontManifest=='NI')))
		{
			makePDFManifestDisplay(Manifest[t], Current);
			Current += 1;
		}
	}
	
}

function makePDFManifestDisplay(thing, item)
{	
createTextElement("ShowItemLabel" + item, "(" + thing.count + ") " + thing.item.description)
createTextElement("ShowItemURL" + item, getManifestPDFImageFilename(thing.item))
}



function getManifestPDFImageFilename(item)
{
	return "http://vixenhill.com/Merchant2/graphics/PSTemp/" + item.manifestImage;
}

function GetPDFQuote()
{
removeAllChildren($('PDFForm'));
pdfHeaderSetup();
createTextElement("OverheadURL", getPorchPrintQS())
addQuoteItemsPDF();
PDFgetManifestQuoteImages();
PDFElevations();
if (QuoteNumber)
{
createTextElement("QuoteNumber", QuoteNumber);
}
else
{
createTextElement("QuoteNumber", "Unsaved");
}
$('PDFForm').submit();
}

function addQuoteItemsPDF()
{
Manifest.sort(manifestorder);
var CurrentItem = 1;
var PaintPrice = 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:
			PaintPrice += ITM.paintPrice * QTY;
			break;
			case 3:
			PaintPrice += ITM.stainPrice * QTY;
			break;
			case 4:
			PaintPrice += ITM.twoTonePrice * QTY;
		}
		if (!(ITM.dontManifest=='N'))
		{
		createQuoteItemPDF(QTY, descriptionSplitPDF(ITM.description, true) , descriptionSplitPDF(ITM.description, false), unitPrice, CurrentItem);
		CurrentItem += 1;
		}
	}
if (PaintPrice > 0)
	{
	createQuoteItemPDF(1, "Finish - " + getPaintName(CurrentPaint), "", PaintPrice, CurrentItem);
	CurrentItem += 1;
	}
	
for (var t=1;t<=LineItemCount;t++)
	{
	createQuoteItemPDF(1, $('LineItem' + t).value, "", $('LineItemCost' + t).value, CurrentItem);
	}
}



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





function createQuoteItemPDF(qty, LeftText, RightText, price, item)
{
createTextElement("ItemQuantity" + item, qty)
createTextElement("ItemName" + item, LeftText)
createTextElement("ItemRightDescriptor" + item, RightText)
createTextElement("ItemPrice" + item, price)
createCheckboxElement("ItemDiscountable" + item, true)
}

function createTextElement(name, value)
{
var Element = document.createElement('input');
Element.type = "text";
Element.name = name;
Element.value = value;
$('PDFForm').appendChild(Element);
}


function createCheckboxElement(name, checked)
{
var Element;
	try 
		{  
		Element = document.createElement("<input type='checkbox' name='" + name + "' checked>");  
		}  
	catch (e) 
		{  
		Element = document.createElement("input");  
		Element.type = "checkbox";  
		Element.checked = true;
		Element.name = name;
		}  
$('PDFForm').appendChild(Element);
}




function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function getRevisionSelectedValue()
{
return getCheckedValue(document.forms['DoorRadioButtons'].elements['DoorStyle']);
}

function setRevisionSelectedValue(value)
{
setCheckedValue(document.forms['DoorRadioButtons'].elements['DoorStyle'], value);
}

function SecondaryDatabaseParameters()
{
	var S=[];
	S.push("SecureByEmail=" + SecureByEmail());
	S.push("SName=" + $('BillName').value);
	S.push("SMail=" + $('BillEmail').value);
	S.push("SFirm=" + $('BillCompany').value);
	
	S.push("LTagline=" + $('customizeTagLine').value);
	S.push("LLogoURL=" + $('customizeURL').value);
	S.push("LCompanyName=" + $('customizeCompanyName').value);
	S.push("LSalesRep=" + $('customizeSalesRep').value);
	
	
	
	
	var returned = S.join("&");
	return returned;
}

function SecureByEmail()
{
	if ($('SecureByEmail').checked)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

function HeightConfig() {
	$('HeightImage').style.display = 'none';
	$('Heightworkwindowinner').style.display = 'none';
	$('workwindowinner').style.display = 'inline';
	$('Lrg1').style.display = "inline";
}


function HeightConfigBack() {
	$('HeightImage').style.display = 'inline';
	$('Heightworkwindowinner').style.display = '';
	$('workwindowinner').style.display = 'none';
	$('Lrg1').style.display = "none";
}



    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 GoRequest() {
        RQuoteInfoChanged();
        show('RequestInfo');
        hide('ManifestStage');
    }

    function RequestBack() {
        hide('RequestInfo');
        show('ManifestStage');
    }

    function Xverify(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);
        Error = partVerify(Side + "Email", Error);
        if (Error) {
            $('OutError').innerHTML = 'Fields in Yellow are Required.';
        }
        else {
            $('OutError').innerHTML = '';
        }
        return Error;
    }


    function getRestoringSteps() {
        var A = new Array();
        A.push(getDDLRestore('selectHeight'));
        A.push(getDDLRestore('selectHeightE'));
        A.push("setShape(" + currentShape + ");");
        A.push(getCheckboxRestore('ChkUpperTier'));
        A.push("BaseConfig();");
        A.push(getCheckboxRestore('LeftWingWall'));
        A.push(getCheckboxRestore('RightWingWall'));
        A.push(getCheckboxRestore('CheckRightIsLeft'));
        A.push(getDDLRestore('CornerLength'));
		A.push(getDDLRestore('CornerDoorSelect'));
		
        A.push(getTextboxRestore('LeftFeet'));
        A.push(getTextboxRestore('LeftInches'));
        A.push(getTextboxRestore('RightFeet'));
        A.push(getTextboxRestore('RightInches'));
        A.push(getTextboxRestore('WidthFeet'));
        A.push(getTextboxRestore('WidthInches'));
        A.push(getDoorRestore('Left'));
        A.push(getDoorRestore('Right'));
        A.push(getDoorRestore('Front'));
        A.push("DimensionsChanged();");
        A.push("GoGenerate();");
        A.push(FixingSteps.join());
        A.push(getDDLRestore('Workbar'));
        A.push("WBlayoutChanged();");
        A.push(getDDLRestore('configFront'));
        A.push("ConfigChanged($('configFront'), WallLocations.front);");
        A.push(getDDLRestore('configLeft'));
        A.push("ConfigChanged($('configLeft'), WallLocations.left);");
        A.push(getDDLRestore('configRight'));
        A.push("ConfigChanged($('configRight'), WallLocations.right);");
        A.push("AcceptDesign();");
        A.push(getInsertRestore());
        A.push("setDB(" + CurrentDitmar + ");");
        A.push("setPaint(" + (CurrentPaint + 1) + ");");
		A.push("setFrameColor(" + CurrentFrameColor + ");");
        if (CurrentFrame) {
            A.push("setIF(1);");
        }
        else {
            A.push("setIF(2);");
        }

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

		A.push(getDDLRestore('numElectricalPosts'));
        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("SecureByEmail"));
        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));
        }
		
		  A.push("while (LineItemCount < " + LineItemCount + ") {AddLineItem();}");

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


    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 + ");";
		S += getOverrideRestores();
        return S;
    }
	
function getOverrideRestores()
{
	var S="";
	var target=WallLocations.front;
	S += getOverrideRestoresFor(currentConfig(target).Parts, target);
	if (Design.RS)
	{
		target=WallLocations.right;
		S += getOverrideRestoresFor(currentConfig(target).Parts, target);
		
			if (Design.C)
			{
				target=WallLocations.rightcorner;
				S += getOverrideRestoresFor(currentConfig(target).Parts, target);
			}
	}
	if (Design.LS)
	{
		target=WallLocations.left;
		S += getOverrideRestoresFor(currentConfig(target).Parts, target);
		
		if (Design.C)
		{
			target=WallLocations.leftcorner;
			S += getOverrideRestoresFor(currentConfig(target).Parts, target);
		}
	}
	return S;
}

function getOverrideRestoresFor(array, index)
{
	var S="";
	for(var current=0;current<array.length;current++)
	{
		var Part=array[current];
		if (Part.overrideLowerInsert)
			{
			S += "RestoreLIOverride('" + Part.overrideLowerInsertCode + "', ";
			S += index + ", " + current + ");";
			}
		if	(Part.overrideUpperInsert)
			{
			S += "RestoreUIOverride('" + Part.overrideUpperInsertCode + "', ";
			S += index + ", " + current + ");";
			}
	}
	return S;
}

function RestoreUIOverride(code, wall, part)
{
	currentConfig(wall).Parts[part].overrideUpperInsert = true;
	currentConfig(wall).Parts[part].overrideUpperInsertCode = code;
	
}

function RestoreLIOverride(code, wall, part)
{
	currentConfig(wall).Parts[part].overrideLowerInsert = true;
	currentConfig(wall).Parts[part].overrideLowerInsertCode = code;
}


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

    function HandleResponse(value) {
        QuoteNumber = (value.split("|*^*|")[1]);
        $('OutputQuoteNumber').innerHTML = QuoteNumber;
        if (CalledBack)
        { CalledBack();
			ShowQuoteNumber();}
    }
	
	function CADURL()
	{
	S = "http://secure.vixenhill.com/Gazebos/newporchdxf.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();
		}
	}
	return S;
	}
	
    function ThreeDURL() {
        var S = "http://vixenhill.com/Merchant2/PorchSystem3DView.xbap?";
        var sel = $('selectHeight');
        var H = parseInt(sel.options[sel.selectedIndex].value);
        sel = $('selectHeightE');
        H += parseFloat(sel.options[sel.selectedIndex].value);
        S += currentConfig(WallLocations.front).queryString();
        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 += "&H=" + H;
        S += "&UI=" + CurrentUI;
        S += "&LI=" + CurrentLI;
		S += "&SG=" + CurrentGlass; //Storm Glass (truefalse)
		S += "&IF=" + CurrentFrame; //InnerFrame (truefalse)
        S += "&DB=" + CurrentDitmar;
        S += "&PAINT=" + CurrentPaint;
		S += getAllOverridesQuery();
        return S;
    }

function OpenThreeD() 
{
	window.open(ThreeDURL());
}

function GetCad() 
{
	window.open(CADURL());
}

function RightDepth()
{
	if (HasLeftSide() && $('CheckRightIsLeft').checked)
	{
		return LeftDepth();
	}
	return sizeInputValue('Right') - 4;
}
function LeftDepth()
{
	return sizeInputValue('Left') - 4;
}
function HasRightSide()
{
	return (currentShape == 3||currentShape == 4||currentShape==5||currentShape==7);
}
function HasLeftSide()
{
	return (currentShape == 1||currentShape == 4||currentShape==5||currentShape==6);
}
function textBoxValue(boxname)
{
	var X = $(boxname).value;
	X = parseFloat(X);
	if (!isNaN(X))
	{
		return X;
	}
	else
	{
		return 0;
	}
}
function sizeInputValue(name)
{
	var value = textBoxValue(name + 'Feet') * 12;
	value += textBoxValue(name + 'Inches');
	return value;
}
function DimensionsChanged()
{
	if (HasLeftSide() && $('CheckRightIsLeft').checked)
	{
		hide('DepthRightInput');
	}
	if (HasRightSide() && (!HasLeftSide() || !$('CheckRightIsLeft').checked))
	{
		show('DepthRightInput');
	}
	currentWidth = sizeInputValue('Width');
	var ProceedButton = $('ButGenerate');
	if (HaveData())
	{
		ProceedButton.setAttribute('className', 'Button');
		ProceedButton.className = 'Button';
	}
	else
	{
		ProceedButton.setAttribute('className', 'Disabled');
		ProceedButton.className = 'Disabled';
	}
}
function HaveData()
{
return (currentWidth > 0 && (!HasRightSide() || RightDepth() > 0) && (!HasLeftSide() || LeftDepth() > 0));
}
function getConfigSrc()
{
	var target=currentShape;
	var value="http://secure.vixenhill.com/Gazebos/QuickDisplay.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;
		case 5:
		value += "shape=DoubleCorner&RS=150&LS=150&FC=150&";
		value += ShapeWallString("Front", "PFC");
		value += ShapeWallString("Right", "PRS");
		value += ShapeWallString("Left", "PLS");
		value += ShapeCorner("RC");
		value += ShapeCorner("LC");
		break;
		case 6:
		value += "shape=LeftHandedCorner&FC=150&LS=150&";
		value += ShapeWallString("Left", "PLS");
		value += ShapeWallString("Front", "PFC");
		value += ShapeCorner("LC");
		break;
		case 7:
		value += "shape=RightHandedCorner&RS=150&FC=150&" + ShapeWallString("Front", "PFC") + ShapeWallString("Right", "PRS")+ShapeCorner("RC");
		break;
	}
	value += "Zippo=EG";
	return value;
}
function ShapeCorner(wallName)
{
	var length = $('CornerLength');
	if (length.selectedIndex == nothing)
	{
		length = 3;
	}
	else
	{
		length = length.selectedIndex + 3;
	}
	length *= 12;
	
	var isDD = (length==60);
	var isDoor = false;
	var isDoorDDL = getDDLvalue($('CornerDoorSelect'));
	
	if (wallName=="RC")
	{
		isDoor = (isDoorDDL == "Right Corner Door" || isDoorDDL == "Both Doors" || isDoorDDL == "Door");
	}
	else
	{
		isDoor = (isDoorDDL == "Left Corner Door" || isDoorDDL == "Both Doors" || isDoorDDL == "Door");
	}
	
	if (isDoor)
	{
		var value=wallName + "=" + length + "&P" + wallName + "=";
		switch(length)
		{
			case 36:
				value += "DP-36-36-S";
			break;
			case 48:
				value += "DP-48-36-D";
			break;
			case 60:
				value += "DP-60-52-D";
			break;
		}
		return value + "&";
	}
	else
	{
		return wallName + "=" + length + "&P" + wallName + "=WP-" + length + "&";
	}
}
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;
	var WallLength = 150;
	switch (DT)
	{
		case 0:
		if (DOI)
		{
			DoorString = "IDP-48-36-S";
			DL = 48;
		}
		else
		{
			DoorString = "DP-48-36-S";
			DL = 48;
		}
		if (DRH)
		{
			DoorString += "-R";
		}
		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;
		case 4:
		if (DOI)
		{
			DoorString = "IDP-36-36-S";
			DL = 36;
		}
		else
		{
			DoorString = "DP-36-36-S";
			DL = 36;
		}
		if (DRH)
		{
			DoorString += "-R";
		}
	}
	if (wallName=="Left")
	{
		if ($('LeftWingWall').checked)
		{
			value += "WW-24!";
			WallLength -= 24;
		}
	}
	if (wallName=="Right")
	{
		if ($('RightWingWall').checked)
		{
			WallLength -= 24;
		}
	}
	value += "EP-.75!";
	switch(DLoc)
	{
		case 0:
		value += "WP-" + WallLength;
		break;
		case 1:
		var WPL = WallLength - DL;
		WPL /= 2;
		WPL -= 1.5;
		value += "WP-" + WPL + "!JP-1.5!" + DoorString + "!JP-1.5!WP-" + WPL + "";
		break;
		case 3:
		var WPL = WallLength - DL;
		WPL -= 1.5;
		value += "WP-" + WPL + "!JP-1.5!" + DoorString + "";
		break;
		case 2:
		var WPL = WallLength - DL;
		WPL -= 1.5;
		value += DoorString + "!JP-1.5!WP-" + WPL + "";
		break;
	}
	value += "!REP-.75";
	if (wallName=="Right")
	{
		if ($('RightWingWall').checked)
		{
			value += "!WW-24";
		}
	}
	value += "&";
	return value;
}
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");
	

	
	DorLoc.selectedIndex = LastSelectedDoorLocation;
	DorRH.checked = false;
	DorSwingIn.checked = false;
	
	switch(x)
		{
			case 1:
				//No Door
				DorLoc.selectedIndex = 0;
			break;
			
			case 2:
				//36-WP, Hinged Left, Swing Out
				DorType.selectedIndex = 0;
				DorRH.checked = false;
				DorSwingIn.checked = false;
			break;
			
			case 3:
				//36-WP, Hinged Left, Swing In
				DorType.selectedIndex = 0;
				DorRH.checked = false;
				DorSwingIn.checked = true;
			break;
			
			case 4:
				//38" French Doors
				DorType.selectedIndex = 1;
			break;
			
			case 5:
				//52" French Doors
				DorType.selectedIndex = 2;
			break;
			
			case 6:
				//72" French Doors
				DorType.selectedIndex = 3;
			break;
			
			case 7:
				//36-WP, Hinged Right, Swing Out
				DorType.selectedIndex = 0;
				DorRH.checked = true;
				DorSwingIn.checked = false;
			break;
			
			case 8:
				//36-WP, Hinged Right, Swing In
				DorType.selectedIndex = 0;
				DorRH.checked = true;
				DorSwingIn.checked = true;
			break;
			
			case 9:
				//36FH, Hinged Left, Swings Out
				DorType.selectedIndex = 4;
				DorRH.checked = false;
				DorSwingIn.checked = false;
			break;
			
			case 10:
				//36FH, Hinged Left, Swings In
				DorType.selectedIndex = 4;
				DorRH.checked = false;
				DorSwingIn.checked = true;
			break;
			
			case 11:
				//36FH, Hinged Right, Swings Out
				DorType.selectedIndex = 4;
				DorRH.checked = true;
				DorSwingIn.checked = false;

			break;
			
			case 12:
				//36FH, Hinged Right, Swings In
				DorType.selectedIndex = 4;
				DorRH.checked = true;
				DorSwingIn.checked = true;

			break;
		}
	updateShapeImage();
}


	this.overrideLowerInsert = false;
	this.overrideUpperInsert = false;
	this.overrideLowerInsertCode = -1;
	this.overrideUpperInsertCode = -1;

function getUIwithOverride(item, UI)
{
	if (item.overrideUpperInsert)
		{
		return item.overrideUpperInsertCode;
		}
	else
		{return UI;}
}

function getLIwithOverride(item, UI)
{
	if (item.overrideLowerInsert)
		{
		return item.overrideLowerInsertCode;
		}
	else
		{return UI;}
}


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;
		}
	}
	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.style.zIndex = 99999;
	div.appendChild(new locatedImage(getImageFilename(i, paintColor), i.imageWidth, i.imageHeight, 'absolute', (- shift) + 'px', '0px', 0, item.partName));
	var buffer;
	if (i.upperInsertGroup != "X" && i.upperInsertGroup != "Z")
	{
		var UpI;
		UpI = getPart("UI-" + getUIwithOverride(item, 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-" + getUIwithOverride(item, UI) + "-" + i.upperInsertGroup;
		buffer = getPart(buffer);
		
		div.insertBefore(locatedImageInsert(getImageFilename(buffer, paintColor), buffer.imageWidth, buffer.imageHeight, 'absolute', (i.insertsX - shift) + 'px', i.uiY +'px', 202, buffer.partName, item, true), div.firstChild);
	}
	if (i.lowerInsertGroup != "X" && i.lowerInsertGroup != "Z")
	{
		var UpI;
		UpI = getPart("LI-" + getLIwithOverride(item, 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-" + getLIwithOverride(item, LI) + "-" + i.upperInsertGroup);
		div.insertBefore(locatedImageInsert(getImageFilename(buffer, paintColor), buffer.imageWidth, buffer.imageHeight, 'absolute', (i.insertsX - shift) + 'px', i.liY +'px', 202, buffer.partName, item, false), div.firstChild);
	}
	return new DivItem(div, i);
}
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.descriptor = getConfigDescription(this);
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;
}
}
function setShape(value)
{
	currentShape = value;
	Clear('Shape', 7);
	Select('Shape', value);
	relocateControlsForShape();
	$('Controls').style.display = 'none';
	$('Lrg1').style.display = 'inline';
	$('Lrg1').src = getShapeSrc(value);
	DimensionsChanged();
	CornerTypeChanged();
}
function getShapeSrc(target)
{
	var value="http://secure.vixenhill.com/Gazebos/QuickDisplay.aspx?Shapemode=yes&SDL=yes&W=590&H=500&Color=238!238!255&";
	switch (target)
	{
		case 1:
		value += "shape=LeftHandedL&LS=100&PLS=EP-0.75!WP-49!JP-2!WP-49!REP-0.75&FC=100&PFC=EP-0.75!WP-49!JP-2!WP-49!REP-0.75";
		break;
		case 2:
		value += "shape=OneSided&FC=100&PFC=EP-0.75!WP-49!JP-2!WP-49!REP-0.75";
		break;
		case 3:
		value += "shape=RightHandedL&RS=100&PRS=EP-0.75!WP-49!JP-2!WP-49!REP-0.75&FC=100&PFC=EP-0.75!WP-49!JP-2!WP-49!REP-0.75";
		break;
		case 4:
		value += "shape=UShaped&RS=100&PRS=EP-0.75!WP-49!JP-2!WP-49!REP-0.75&FC=100&PFC=EP-0.75!WP-49!JP-2!WP-49!REP-0.75&LS=100&PLS=EP-0.75!WP-49!JP-2!WP-49!REP-0.75";
		break;
		case 5:
		value += "shape=DoubleCorner&RS=100&PRS=MEP45-1.6!WP-49!JP-2!WP-49!REP-0.75RC=36&PRC=MEP45-1.6!WP-36!RMEP45-1.6&LC=36&PLC=MEP45-1.6!WP-36!RMEP45-1.6&FC=100&FC=100&PFC=MEP45-1.6!WP-49!JP-2!WP-49!RMEP45-1.6&LS=100&PLS=EP-0.75!WP-49!JP-2!WP-49!RMEP45-1.6&LC=36";
		break;
		case 6:
		value += "shape=LeftHandedCorner&LS=100&PLS=EP-0.75!WP-49!JP-2!WP-49!RMEP45-1.6&LC=36&PLC=MEP45-1.6!WP-36!RMEP45-1.6&FC=100&PFC=MEP45-1.6!WP-49!JP-2!WP-49!REP-0.75";
		break;
		case 7:
		value += "shape=RightHandedCorner&RS=100&PRS=MEP45-1.6!WP-49!JP-2!WP-49!REP-0.75&RC=36&PRC=MEP45-1.6!WP-36!RMEP45-1.6&FC=100&PFC=EP-0.75!WP-49!JP-2!WP-49!RMEP45-1.6";
		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);
	}
	HeightChanged();
	setShape(4);
	DoorChanged();
	setFrameColor(1);
}
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);
		break;
		case 2:
		SetupControls(393, 215, 444, 265, false, 60, 145, false, 100, 200, false, 140, 200, 100, 240, false, 100, 500, 100, 600);
		break;
		case 3:
		SetupControls(393, 455, 444, 340, true, 60, 145, false, 100, 200, false, 140, 200, 100, 240, true, 740, 200, 740, 240);
		break;
		case 4:
		SetupControls(393, 455, 444, 340, true, 60, 145, false, 100, 200, true, 140, 200, 100, 240, true, 740, 200, 740, 240);
		break;
		case 5:
		SetupControls(393, 455, 444, 340, true, 60, 145, true, 10, 400, true, 100, 200, 60, 240, true, 780, 200, 780, 240);
		break;
		case 6:
		SetupControls(393, 455, 444, 340, true, 60, 145, true, 10, 400, true, 140, 200, 100, 240, false, 740, 200, 740, 240);
		break;
		case 7:
		SetupControls(393, 455, 444, 340, true, 60, 145, true, 10, 400, false, 140, 200, 100, 240, true, 740, 200, 740, 240);
		break;
	}
}
function SetupControls(WX, WY, FDX, FDY, HS, HX, HY, SC, CX, CY, SLS, LSDX, LSDY, LSWWX, LSWWY, SRS, RSDX, RSDY, RSWWX, RSWWY)
{
	SetSingleControl('WidthControl', true, WX, WY, false);


	SetSingleControl('DepthLeftControl', HS && HasLeftSide(), 5, HY, false);
	SetSingleControl('DepthRightControl', HS && HasRightSide(), 5, HY-22, true);

	if (!HasRightSide())
	{
	$('LabelLeftDeck').innerHTML = '<b>Deck Depth</b>';
	}
	else
	{
	$('LabelLeftDeck').innerHTML = '<b>Left Deck Depth</b>';
	}

	if (!HasLeftSide())
	{
	$('LabelRightDeck').innerHTML = '<b>Deck Depth</b>';
	}
	else
	{
	$('LabelRightDeck').innerHTML = '<b>Right Deck Depth</b>';
	}

	if (HasRightSide() && HasLeftSide())
	{
	show('ShowRisL');
	}
	else
	{
	$('CheckRightIsLeft').checked = false;
	hide('ShowRisL');
	}

	SetSingleControl('ButtonFrontDoor', true, FDX, FDY, false);
	SetSingleControl('CornersControl', SC, CX, CY-30, false);
	SetSingleControl('ButtonLeftDoor', SLS, 5, LSDY, false);
	SetSingleControl('ControlLeftWW', SLS, 5, 5, false);
	SetSingleControl('ButtonRightDoor', SRS, 5, RSDY, true);
	SetSingleControl('ControlRightWW', SRS, 5, 5, true);
}
function SetSingleControl(id, visible, X, Y, right)
{
	var E = $(id);
	if (!E)
	{
		alert(id);
		return;
	}
	if (visible)
	{
		if (E.tagName.toUpperCase() == "TABLE")
			{
				E.style.display = '';
			}
		else
			{
			E.style.display = 'block';
			}
		E.style.visibility = 'visible';
	}
	else
	{
		E.style.display = 'none';
		E.style.visibility = 'hidden';
	}
	E.style.right = "";
	E.style.bottom = "";
	
	
	if (right)
	{
		var Loc = parseInt(getStyle(E,'width'));
		Loc = 988 - (Loc + X);
		X = Loc;
		
	}

	
		
	E.style.left = X + "px";
	E.style.top = Y + "px";
		
}

function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}


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";
	hide('CornersControl', 'WidthControl', 'DepthRightControl', 'DepthLeftControl', 'FrontControl', 'LeftControl', 'RightControl');
	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;
		case 5:
		setDesignValues(Design, "Three Sided with Clipped Corners", "DoubleCorner", true, true, true, 4, 8);
		break;
		case 6:
		setDesignValues(Design, "Left Handed L with Clipped Corners", "LeftHandedCorner", true, false, true, 4, 4);
		break;
		case 7:
		setDesignValues(Design, "Right Handed L with Clipped Corners", "RightHandedCorner", false, true, true, 4, 4);
		break;
	}
	if (Design.LS && $('LeftWingWall').checked)
	{
		Design.LWW = true;
		Design.LWWMin = 8;
		Design.LWWMax = 24;
	}
	else
	{
		Design.LWW = false;
		Design.LWWMin = 0;
		Design.LWWMax = 0;
	}
	switch ($('CornerLength').selectedIndex)
	{
		case 0:
		if (CornersHaveDoors())
			{	
			Design.CornerPanel = 34.5;
			}
		else
			{
			Design.CornerPanel = 36.5;
			}
		
		break;
		case 1:
		Design.CornerPanel = 49;
		break;
		case 2:
		Design.CornerPanel = 63;
		break;		
	}
	if (Design.RS && $('RightWingWall').checked)
	{
		Design.RWW = true;
		Design.RWWMin = 8;
		Design.RWWMax = 24;
	}
	else
	{
		Design.RWW = false;
		Design.RWWMin = 0;
		Design.RWWMax = 0;
	}
	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();

	if (!Design.C)
	{
		Design["Center"].runlength = Design.width;
		if (Design.RS)
		{
			Design["Center"].runlength -= (MPW / 2);
			Design["RightSide"].runlength = RightDepth() - ((MPW / 2));
		}
		if (Design.LS)
		{
			Design["Center"].runlength -= (MPW / 2);
			Design["LeftSide"].runlength = LeftDepth() - ((MPW / 2));
		}
	}
	else
	{
		CTU = Design.CornerPanel;
		CTU += M45TP * 2.0;
		CTU += CP45 * 2;
		CTU *= SQTT;
		Design["Center"] = new Object();
		Design["Center"].runlength = Design.width;
		if (Design.RS)
		{
			Design["Center"].runlength -= CP45;
			Design["RightSide"].runlength = RightDepth() - CP45;
			Design["Corner"].runlength = Design.CornerPanel + M45TP + M45TP;
			Design["Center"].runlength -= CTU;
			Design["RightSide"].runlength -= CTU;
		}
		if (Design.LS)
		{
			Design["Center"].runlength -= CP45;
			Design["LeftSide"].runlength = LeftDepth() - CP45;
			Design["Corner"].runlength = Design.CornerPanel + M45TP + M45TP;
			Design["Center"].runlength -= CTU;
			Design["LeftSide"].runlength -= CTU;
		}
	}
	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;
		}
	}
	Design.WallConfigurations[WallLocations.front] = GetConfigurations(Design["Center"].runlength, CFEP, CREP, JoiningPosts, false, 0, 0, FDL, Design.frontDoor, WallLocations.front);
	if (Design.RS)
	{
		CFEP = StandardEndPosts;
		CREP = ModularEndPosts;
		if (Design.C)
		{
			CFEP = CornerEndPosts;
		}
		Design.WallConfigurations[WallLocations.right] = GetConfigurations(Design["RightSide"].runlength, CFEP, CREP, JoiningPosts, Design.RWW, Design.RWWMin, Design.RWWMax, RDL, Design.rightDoor, WallLocations.right);
		if (Design.C)
		{
			Design.WallConfigurations[WallLocations.rightcorner] = Design.WallConfigurations[WallLocations.leftcorner] = GetCornerConfig("RC", Design["Corner"].runlength); 
		}
	}
	if (Design.LS)
	{
		CFEP = ModularEndPosts;
		CREP = StandardEndPosts;
		if (Design.C)
		{
			CREP = CornerEndPosts;
		}
		Design.WallConfigurations[WallLocations.left] = GetConfigurations(Design["LeftSide"].runlength, CFEP, CREP, JoiningPosts, Design.RWW, Design.LWWMin, Design.LWWMax, LDL, Design.leftDoor, WallLocations.left);
		if (Design.C)
		{
			Design.WallConfigurations[WallLocations.leftcorner] = GetCornerConfig("LC", Design["Corner"].runlength); 
		}
	}
	CheckErrors();
}
function NoValidLayout(ErroredWalls)
{
	hide('ConfigDiv');
	show('ErrorDiv');
	var Zone = $('ErrorSuggestZone');
	var haveSuggestions = true;
	for (var t=0;t<ErroredWalls.length;t++)
	{
		if (getSuggestions(ErroredWalls[t])=="")
		{
			haveSuggestions = false;
		}
	}
	var S;
	if (haveSuggestions)
	{
	
		S = "<b>Design Changes are needed to fit this porch.</b><br/><br/>";
		for (var t=0;t<ErroredWalls.length;t++)
		{
			S += "<b>" + getWallName(ErroredWalls[t]) + " needs alterations.</b><br/>";
			S += getSuggestions(ErroredWalls[t]) + "(Click to Change)<br/>";
		}
		if (Design.C)
		{
			S += "Your porch has clipped corners. Changing the wall panels used on the corner or switching to a non-clipped design may allow this porch to be fit.</br>";
		}
		S += "If these suggestions are insufficient, please contact Vixen Hill, and our design department will attempt to find a working solution!</br>";
	}
	else
	{
	
		S = "<b>This porch could not be successfully fit!</b><br/><br/>";
		for (var t=0;t<ErroredWalls.length;t++)
		{
			S += "<b>" + getWallName(ErroredWalls[t]) + " could not be fit!</b><br/>";
			S += getSuggestions(ErroredWalls[t]) + "<br/>";
		}
		if (Design.C)
		{
			S += "Your porch has clipped corners. Changing the wall panels used on the corner or switching to a non-clipped design may allow this porch to be fit.</br>";
		}
		S += "Please contact Vixen Hill, and our design department will attempt to find a working solution!</br>";
	}
	Zone.innerHTML = S;
}
function HaveWorkingLayout()
{
	show('BPAccept','BPLarge','ConfigDiv');
	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";
	hide('CornersControl', 'WidthControl', 'DepthRightControl', 'DepthLeftControl', 'FrontControl', 'LeftControl', 'RightControl');
	var Auto = $("LrgAuto");
	Auto.style.left = "0px";
	Auto.src = getPorchQS();
	Auto.style.display = "inline";
	ShowHideConfigBars();
}
var BeenToOptionspage = false;
function resetOptions()
{
	if (!BeenToOptionspage)
	{
	setIF(2);
	setDB(0);
	setPaint(1);
	setSG(1);
	popupLI(1, "NONE");
	popupUI(1, "NONE");
	BeenToOptionspage = true;
	}
}

function ShowQuoteNumber()
{
if (QuoteNumber)
	{
		FlashRedQuoteIfNeeded();
		$('DisplaySavedQuoteNumber').innerHTML = "Quote Number " + QuoteNumber.split("-")[1];
	}
}

function FlashRedQuoteIfNeeded()
{
var DSQN = $('DisplaySavedQuoteNumber');
var ShouldBe = "Quote Number " + QuoteNumber.split("-")[1];
if (!(DSQN.innerHTML == ShouldBe))
	{
		DSQN.style.color = "#FFFFFF";
		DSQN.style.backgroundColor = "#770000";
		setTimeout("ReturnfromRed();", 3000);
		Interval = setInterval("StarFlash()", 300);
	}
}

function StarFlash()
{
lastStarred = !lastStarred;
var text = "Quote Number " + QuoteNumber.split("-")[1];
if (!lastStarred)
	{text += "     ***";}
$('DisplaySavedQuoteNumber').innerHTML = text;
}


var Interval;
var lastStarred = true;

function ReturnfromRed()
{
	clearInterval(Interval);
	var DSQN = $('DisplaySavedQuoteNumber');
	DSQN.style.color = "#000000";
	DSQN.style.backgroundColor = "#FFFFFF";
	DSQN.innerHTML = "Quote Number " + QuoteNumber.split("-")[1];
}

Initialize();

 
