
function GoHardware()
{
	UpdateForm();
	$("MivaMerchantForm")["Category_Code"].value = "_hardware_landing";
	$("MivaMerchantForm").submit();
}
function AddToCart()
{
	UpdateForm();
	$("MivaMerchantForm")["Category_Code"].value = "_Empty";
	show('DisabledWorkPage', 'Adding');
	AJAXSubmit();
}
function GoCheckout()
{
	UpdateForm();
	$("MivaMerchantForm")["Screen"].value = "BASK";
	$("MivaMerchantForm").submit();
}
function GetPairWidth()
{
	if (!isLeaf())
	{
		return parseInt($("PWI").value) + ($("PWE").selectedIndex / 8);
	}
	else
	{
		return (parseInt($("PWI").value) + ($("PWE").selectedIndex / 8))*2;
	}
}
function GetPairHeight()
{
		return parseInt($("PHI").value) + ($("PHE").selectedIndex / 8);
}
function Weight()
{
	var PW = GetPairWidth();
	var PH = parseInt($("PHI").value) + ($("PHE").selectedIndex / 8);
	Density = .016;
	if (isLeaf())
	{
		Density = .008;
	}
	return PW * PH * Density;
}
function AttValue(index)
{
	var S = "AttributeValue[" + index + "]";
	return $("MivaMerchantForm")[S];
}
function UpdateForm()
{
	var P = Price();
	$("MivaMerchantForm")["Action"].value = "ADPR";
	$("MivaMerchantForm")["OUIX_nextoffset"].value = "";
	$("MivaMerchantForm")["Offset"].value = "";
	$("MivaMerchantForm")["Product_Count"].value = "";
	$("MivaMerchantForm")["Screen"].value = "CTGY";
	$("MivaMerchantForm")["Product_Code"].value = "EXTERNAL";
	$("MivaMerchantForm")["Store_Code"].value = "VH";
	$("MivaMerchantForm")["Category_Code"].value = "_ShutterBuilder";
	for (t=1;t<=26;t++)
	{
		AttValue(t).value = "";
	}
	if (isLeaf())
	{
		P = P / 2;
		AttValue(2).value = AllStyles[CurrentStyle]["Name"] + " Shutter";
		AttValue(1).value = "Cedar Shutter, Leaf";
		AttValue(5).value = AllStyles[CurrentStyle]["Name"] + "(Leaves)";
	}
	else
	{
		AttValue(2).value = AllStyles[CurrentStyle]["Name"] + " Shutters";
		AttValue(1).value = "Cedar Shutters";
		AttValue(5).value = AllStyles[CurrentStyle]["Name"];
	}
	AttValue(3).value = P;
	AttValue(4).value = Weight();
	switch (CurrentPanel)
	{
		case 1:
		AttValue(6).value = "Traditional Raised Panel";
		break;
		case 2:
		AttValue(6).value = "Simple Raised Panel";
		break;
		case 3:
		AttValue(6).value = "Flat Panel";
		break;
		case 4:
		AttValue(6).value = "Shaker Panel";
		break;
	}
	switch (CurrentTrim)
	{
		case 1:
		AttValue(7).value = "Traditional Trim";
		break;
		case 2:
		AttValue(7).value = "Quarter Round Trim";
		break;
		case 3:
		AttValue(7).value = "No Trim";
		break;
	}
	if (CurrentCutout > 1)
	{
		AttValue(8).value = AllCutout[CurrentCutout]["Name"];
	}
	if (CurrentLouver != -1)
	{
		AttValue(9).value = AllLouvers[CurrentLouver]["Name"];
	}
	switch (CurrentDuty)
	{
		case 1:
		AttValue(11).value = "Standard Duty";
		break;
		case 2:
		AttValue(11).value = "Heavy Duty";
		break;
	}
	if (CurrentISB == 2)
	{
		AttValue(13).value = "Inner Stile Beading";
	}
	switch(CurrentOSD)
	{
		case 2:
		AttValue(14).value = "Outer Stile Beading";
		break;
		case 3:
		AttValue(14).value = "Simple Overlap Rabbeting";
		break;
		case 4:
		AttValue(14).value = "Beaded Overlap Rabbeting";
		break;
	}
	switch(CurrentCapping)
	{
		case 2:
		AttValue(15).value = "Copper Capping";
		break;
		case 3:
		AttValue(15).value = "Green Aluminum Capping";
		break;
		case 4:
		AttValue(15).value = "Red Aluminum Capping";
		break;
	}
	if (CurrentZ == 2)
	{
		AttValue(16).value = "Z Brace";
	}
	switch(CurrentArch)
	{
		case 2:
		if (AllStyles[CurrentStyle]["BnB"])
		{
			AttValue(17).value = "Archtop";
		}
		else
		{
			AttValue(17).value = "Solid Archtop";
		}
		AttValue(18).value = parseInt($("SSI").value) + ($("SSE").selectedIndex / 8);
		break;
		case 3:
		AttValue(17).value = "Full Archtop";
		AttValue(18).value = parseInt($("SSI").value) + ($("SSE").selectedIndex / 8);
		break;
	}
	if (CurrentFTR == 2)
	{
		AttValue(20).value = "False Tilt Rods";
	}
	AttValue(21).value = QS() + "&small=true";
	AttValue(22).value = AllPaint[CurrentPaint]["Name"];
	AttValue(23).value = GetPairWidth() + " (" + (GetPairWidth()/2) + " per Leaf)";
	AttValue(24).value = parseInt($("PHI").value) + ($("PHE").selectedIndex / 8);
	if (CurrentBahama == 2)
	{
		AttValue(25).value = "Bahama Style";
	}
	if (CurrentHorns == 2)
	{
		AttValue(26).value = "Horns";
	}
	$('FormQuantity').value = getQuantity();
}

function QuantityChanged()
{
	var QTY = getQuantity();
	if (isLeaf())
	{
		SetArch(1);
		SetOSD(1);
		SetISB(1);
		show('LeafArch', 'LeafArchSS', 'LeafOSD', 'LeafISB');
	}
	else
	{
		hide('LeafArch', 'LeafArchSS', 'LeafOSD', 'LeafISB');
	}
	SetDimensionAvailable();
	Update();
}
function InitializeQuantity()
{
	var QtyBox = $('InputQuantity');
	ClearOptions(QtyBox);
	for (t=1;t<=30;t++)
	{
		addOption(QtyBox, t, t);
	}
	setDDLvalue(QtyBox, 1);
}
function Update()
{
	if (!SuppressUpdates)
	{
		UpdateImage();
		var P = Price();
		var TP = P * getQuantity();
		if (isLeaf())
		{
			TP /= 2;
		}
		$('ImagePriceOverlay').innerHTML = Currency(TP);
	}
}
function UpdateImage()
{
	$("OTFIMG").src = QS();
}
function QS()
{
	var QS='http://secure.vixenhill.com/Shutters/Shutter.aspx?';
	var PW = GetPairWidth();
	var PH = parseInt($("PHI").value) + ($("PHE").selectedIndex / 8);
	var SS = parseInt($("SSI").value) + ($("SSE").selectedIndex / 8);
	QS += "Style=" + AllStyles[CurrentStyle]["Name"] + "&";
	QS += "PW=" + PW + "&";
	QS += "PH=" + PH + "&";
	QS += "Paint=" + AllPaint[CurrentPaint]["Name"] +"&";
	if (AllStyles[CurrentStyle]["BnB"])
	{
		QS += "Batten=True&";
		if (CurrentZ == 2)
		{
			QS += "Z=TRUE&";
		}
		if (CurrentDuty == 2)
		{
			QS += "DUTY=HEAVY&";
		}
	}
	if (CurrentArch == 2)
	{
		QS += "ShortSide=" + SS + "&";
		if (!AllStyles[CurrentStyle]["BnB"])
		{
			QS += "Solid=True&";
		}
	}
	if (CurrentArch == 3)
	{
		QS += "Full=True&ShortSide=" + SS + "&";
	}
	if (CurrentLouver != -1)
	{
		QS += "Louver=" + AllLouvers[CurrentLouver]['Name'] + "&";
	}
	if (CurrentCutout != -1)
	{
		QS += "Cutout=" + AllCutout[CurrentCutout]['Name'] + "&";
	}
	if (CurrentHorns == 2)
	{
		QS += "Horns=true&"
	}
	if (CurrentBahama == 2)
	{
		QS += "Bahama=true&";
	}
	if (isLeaf())
	{
		QS += "Leaf=true&";
	}
	switch (CurrentPanel)
	{
		case 2:
		QS += "PANEL=SIMPLE RAISED PANEL&";
		break;
		case 3:
		QS += "PANEL=FLAT PANEL&";
		break;
		case 4:
		QS += "PANEL=SHAKER PANEL&";
		break;
	}
	switch (CurrentTrim)
	{
		case 2:
		QS += "TRIM=QUARTER ROUND TRIM&";
		break;
		case 3:
		QS += "TRIM=NO TRIM&";
		break;
	}
	switch (CurrentCapping)
	{
		case 2:
		QS += "CC=COPPER&";
		break;
		case 3:
		QS += "CC=ALUMINUMDARKGREEN&";
		break;
		case 4:
		QS += "CC=ALUMINUMRED&";
		break;
	}
	switch (CurrentOSD)
	{
		case 2:
		QS += "OSB=BEADED EDGE&";
		break;
		case 4:
		QS += "OSB=OVERLAP RABBETING&";
		break;
		case 3:
		QS += "OSB=SIMPLE RABBETING&";
		break;
	}
	if (CurrentISB == 2)
	{
		QS += "ISB=Inner Stile Beading&";
	}
	if (CurrentFTR == 2)
	{
		QS += "FTR=true&"
	}
	QS += "Tech=true";
	return QS;
}
function Price()
{
	var PW = GetPairWidth();
	var PH = parseInt($("PHI").value) + ($("PHE").selectedIndex / 8);
	var SS = parseInt($("SSI").value) + ($("SSE").selectedIndex / 8);
	var P = Prices['Base'];
	P += Math.floor(PW) * Math.floor(PH) * Prices['CentsPerSqIn'] / 100;
	if (PW > 40 || PH > 95)
	{
		P += 50;
	}
	P *= (1-ContractorDiscount);
	P += 15;
	if (AllStyles[CurrentStyle]['Sections'] > 2)
	{
		P += (AllStyles[CurrentStyle]['Sections'] - 2) * Prices['ExtraMidrail'];
	}
	if (AllStyles[CurrentStyle]['BnB'])
	{
		P += 1 * Prices['BoardAndBatten'];
	}
	if (PH > Prices['FinishHeightCutoff'])
	{
		P += AllPaint[CurrentPaint]["LargePrice"] * 1;
	}
	else
	{
		P += AllPaint[CurrentPaint]["SmallPrice"] * 1;
	}
	if (CurrentLouver != -1)
	{
		P += AllLouvers[CurrentLouver]["Price"] * 1;
	}
	if (CurrentPanel == 4)
	{
		P += Prices['ShakerPanel'] * 1;
	}
	if (CurrentCutout > 1)
	{
		P += Prices['Cutout'] * 1;
	}
	if (CurrentFTR == 2)
	{
		P += Prices['FalseTiltRods'] * 1;
	}
	if (CurrentCapping > 1)
	{
		P += Prices['Capping'] * 1;
	}
	if (CurrentHorns == 2)
	{
		P += Prices['Horns'] * 1;
	}
	if (CurrentBahama == 2)
	{
		P += Prices['BahamaStyle'] * 1;
	}
	if (CurrentISB == 2)
	{
		P += Prices['InnerStileBeading'] * 1;
	}
	if (CurrentArch == 2)
	{
		P += Prices['SolidArch'] * 1;
	}
	if (CurrentOSD == 2)
	{
		P += Prices['OuterStileBeading'] * 1;
	}
	if (CurrentOSD == 3)
	{
		P += Prices['SimpleRabbet'] * 1;
	}
	if (CurrentOSD == 4)
	{
		P += Prices['BeadedRabbet'] * 1;
	}
	if (CurrentDuty == 2)
	{
		P += Prices['HeavyBoardAndBatten'] * 1;
	}
	if (CurrentArch == 3)
	{
		P += Prices['FullArch'] * 1;
	}
	return P;
}
function PopUp()
{
	$('DisabledWorkPage').style.display = '';
	$('PopUpOuter').style.display = '';
	$('PopUpInner').style.display = '';
}
function PopDown()
{
	$('DisabledWorkPage').style.display = 'none';
	$('PopUpOuter').style.display = 'none';
	$('PopUpInner').style.display = 'none';
}
function SetStyle(value)
{
	var BNB, PAN, LVR;
	switch(value)
	{
		case 1:
		BNB=false;
		PAN=true;
		LVR=false;
		break;
		case 2:
		BNB=false;
		PAN=false;
		LVR=true;
		break;
		case 3:
		BNB=true;
		PAN=false;
		LVR=false;
		break;
		case 4:
		BNB=false;
		PAN=true;
		LVR=true;
		break;
	}
	var Count = 0;
	var LastShutter = 0;
	var PopWindow = $('PopUpInner');
	PopWindow.innerHTML = '';
	var Col = 0;
	var Y = 1;
	var X = -68;
	var IH = "";
	for(t=0;t<AllStyles.length;t++)
	{
		if ( true )
		{
			Count += 1;
			LastShutter = t;
			X += 78;
			Col += 1;
			if (Col > 6)
			{
				Col = 1;
				Y += 134;
				X = 10;
			}
			var NewBlock="<div class='PopStyleOuter' onmouseover='style.backgroundColor=\"#FFFFFF\"' onmouseout='style.backgroundColor=\"#000000\"' style='left:";
			NewBlock += X;
			NewBlock += ";top:" + Y + "'><div class='PopStyleInner'><img class='Pop' onclick='PopDownSetStyle(" + t + ");' src='" + AllStyles[t]['LargeImageURL'] + "' />";
			NewBlock += "<div class='PopLabel'>" + AllStyles[t]['Name'] + "</div></div></div>";
			IH += NewBlock;
		}
	}
	PopWindow.innerHTML = IH;
	PopUp();
	if (Count == 1)
	{
		PopDownSetStyle(LastShutter);
	}
}
function ShortSideChanged()
{
	SetDimensionAvailable();
	Update();
}
function ChangedDimensions()
{
	SetSSAvailable();
	var PH = GetPairHeight();
	PW = GetPairWidth();
	var WantedSS = PH - (PW / 2.0);
	var inches = Math.floor(WantedSS);
	var Eights = Math.floor((WantedSS - inches) * 8);
	setDDLvalue($("SSI"), inches);
	setDDLvalue($("SSE"), Eights);
	
	if (GetPairWidth() < 24)
	{
		SetCutout(-1);
	}
	if (AllStyles[CurrentStyle]["Paneled"] && GetPairWidth() >= 24)
	{
		SetCutout(0);
	}
	if (GetPairWidth() < 40)
	{
		SetBahama(-1);
	}
	else
	{
		if (CurrentArch <= 1 && !AllStyles[CurrentStyle]["BnB"])
		{
			SetBahama(0);
		}
	}
	Update();
}
function ClearOptions(selectbox)
{
	for (x = selectbox.length; x >= 0; x = x - 1)
	{
		selectbox[x] = null;
	}
}
function SetSSAvailable()
{
	if (CurrentStyle == 0)
	{
	}
	var Max = parseInt($("PHI").value);
	if (CurrentArch == 2 && (!AllStyles[CurrentStyle]["BnB"]))
	{
		Max -= 2;
	}
	var Min = Math.ceil(ArchMin());
	if (Min >= Max)
	{
		Min = Max - 1;
	}
	var Current = parseInt($("SSI").value);
	ClearOptions($("SSI"));
	for (t=Min;t<Max;t++)
	{
		addOption($("SSI"), t, t);
	}
	setDDLvalue($("SSI"), Current);
}
function SetDimensionAvailable()
{
	var PWMin, PWMax, PHMin, PHMax, SSMin, SSMax;
	PWMin = 22;
	PWMax = 72;
	if (CurrentBahama == 2)
	{
		PWMin = 40;
	}
	if (AllStyles[CurrentStyle]["BnB"])
	{
		PHMin = 24;
		PHMax = 132;
	}
	else
	{
		if (AllStyles[CurrentStyle]['Sections'] == 1)
		{
			PHMax = 80;
		}
		else
		{
			PHMax = 132;
		}
		if (AllStyles[CurrentStyle]['Paneled'])
		{
			PHMin = 8.5;
			PHMin += 3.5 * (AllStyles[CurrentStyle]['Sections'] - 1);
			PHMin += 500.0 / AllStyles[CurrentStyle]['SmallPanel'];
			PHMin = Math.ceil(PHMin);
		}
		else
		{
			PHMin = 8.5;
			PHMin += 2.625 * (AllStyles[CurrentStyle]['Sections'] - 1);
			PHMin += 300.0 / AllStyles[CurrentStyle]['SmallLouver'];
			PHMin = Math.ceil(PHMin);
		}
	}
	if(CurrentHorns == 2)
	{
		PHMin += 3;
	}
	if(CurrentArch > 1)
	{
		PHMin = Math.max(PHMin, parseInt($("SSI").value));
	}
	PW = parseInt($("PWI").value);
	PH = parseInt($("PHI").value);
	if (isLeaf())
	{
		PWMin /= 2;
		PWMax /= 2;
	}
	ClearOptions($("PWI"));
	ClearOptions($("PHI"));
	for (t=PWMin;t<=PWMax;t++)
	{
		addOption($("PWI"), t, t);
	}
	for (t=PHMin;t<=PHMax;t++)
	{
		addOption($("PHI"), t, t);
	}
	setDDLvalue($("PWI"), PW);
	setDDLvalue($("PHI"), PH);
	Update();
}
function setDDLvalue(ddl, ivalue)
{
	var target = 0;
	var mylength = ddl.options.length;
	for (qt = 0; qt < mylength; qt ++ )
	{
		if (ddl.options[qt].value == ivalue)
		{
			target = qt;
		}
	}
	ddl.selectedIndex = target;
}
function addOption(selectbox, text, value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}
function SolidArchTopLowSideMinimum()
{
	if (AllStyles[CurrentStyle]["BnB"])
	{
		return 20;
	}
	if (AllStyles[CurrentStyle]["Sections"] > 2)
	{
		return 47;
	}
	return 31;
}
function ArchMin()
{
	if (CurrentArch == 2)
	{
		return Math.min(SolidArchTopLowSideMinimum(), parseInt($("PHI").value)-2);
	}
	else
	{
		return FullArchTopLowSideMinimum();
	}
}
function FullArchTopLowSideMinimum()
{
	var isLouvered = AllStyles[CurrentStyle]['Louvered'];
	var isPaneled = AllStyles[CurrentStyle]['Paneled'];
	var TopAreaPercent = AllStyles[CurrentStyle]['TopAreaPercent']
	var Sections = AllStyles[CurrentStyle]['Sections'];
	if (AllStyles[CurrentStyle]["BnB"])
	{
		return 20;
	}
	else
	{
		var totalsectionarea;
		totalsectionarea = parseInt($("PHI").value) + ($("PHE").selectedIndex / 8);
		var PairHeight = totalsectionarea;
		var HBuf = 0;
		if (CurrentHorns == 2)
		{
			totalsectionarea -= 6;
			PairHeight -= 6;
			HBuf = 6;
		}
		if (isLouvered && isPaneled)
		{
			totalsectionarea = totalsectionarea - (3 + 5.125);
			totalsectionarea = totalsectionarea - ((Sections - 1) * 3.5);
			return PairHeight - (3 + (totalsectionarea / 100 * TopAreaPercent)) + HBuf;
		}
		else
		{
			if (isLouvered)
			{
				totalsectionarea = totalsectionarea - (3 + 5.125);
				totalsectionarea = totalsectionarea - ((Sections - 1) * 3.5);
				return PairHeight - (2.375 + (totalsectionarea / 100 * TopAreaPercent)) + HBuf;
			}
			else
			{
				totalsectionarea = totalsectionarea - (4.25 + 3);
				totalsectionarea = totalsectionarea - ((Sections - 1) * 3.5);
				return PairHeight - (2 + (totalsectionarea / 100 * TopAreaPercent)) + HBuf;
			}
		}
	}
}
function PopDownSetStyle(value)
{
	SuppressUpdates = true;
	PopDown();
	CurrentStyle = value;
	SetDimensionAvailable();
	var LVR, PNL, BNB;
	LVR = AllStyles[CurrentStyle]["Louvered"];
	PNL = AllStyles[CurrentStyle]["Paneled"];
	BNB = AllStyles[CurrentStyle]["BnB"];
	if (PNL && !BNB && !LVR)
	{
		SetISB(0);
	}
	else
	{
		SetISB(-1);
	}
	if (PNL)
	{
		SetPanel(0);
		SetTrim(0);
		if (GetPairWidth() >= 24)
		{
			SetCutout(0);
		}
		else
		{
			SetCutout(-1);
		}
	}
	else
	{
		SetPanel(-1);
		SetTrim(-1);
		SetCutout(-1);
	}
	if (LVR)
	{
		SetLouver(0);
		SetFTR(0);
	}
	else
	{
		SetLouver(-1);
		SetFTR(-1);
	}
	if (BNB)
	{
		SetBahama(-1);
		DisableSection("FullArch");
		if (CurrentArch == 3)
		{
			SetArch(2);
		}
		SetHorns(-1);
		SetCapping(-1);
		SetDuty(0);
		SetZ(0);
		SetOSD(-1);
	}
	else
	{
		EnableSection("FullArch");
		SetHorns(0);
		SetCapping(0);
		SetDuty(-1);
		SetZ(-1);
		if (CurrentArch == 1 || CurrentArch == -1)
		{
			SetOSD(0);
		}
		else
		{
			SetOSD(-1);
		}
		if ( !!(GetPairWidth() >= 40) && !!(CurrentArch == 1 || CurrentArch == -1))
		{
			SetBahama(1);
		}
		else
		{
			SetBahama(-1);
		}
		if (CurrentBahama != 2 && !TrimmedLouver() && (CurrentOSD == 1 || CurrentOSD == -1))
		{
			SetArch(0);
		}
	}
	SuppressUpdates = false;
	Update();
}
function SetPaint(value)
{
	Clear("Paint", 2);
	if (value==-1)
	{
		DisableSection("Paint");
		CurrentPaint = -1;
	}
	else
	{
		EnableSection("Paint");
		if (value == 0)
		{
			if (CurrentPaint != -1)
			{
				value = CurrentPaint;
			}
			else
			{
				value = 1;
			}
		}
		if (value == 4)
		{
			PopDownPaint();
		}
		else
		{
			CurrentPaint = value;
			Select("Paint", value);
			Update();
		}
	}
}
function PopDownPaint()
{
	var PopWindow = $('PopUpInner');
	var X, Y;
	X = 1;
	Y = 2;
	var PD = "";
	for (t=2;t<AllPaint.length;t++)
	{
		var NewBlock="<div class='SimpleButtonOuterPopup' onmouseover='style.backgroundColor=\"#FFFFFF\"' onmouseout='style.backgroundColor=\"#000000\"' style='left:";
		NewBlock += X;
		NewBlock += ";top:" + Y + ";width:96px;height:159px;'><div class='SimpleButtonInnerPopup' style='width:94px;height:157px;top:1px;left:1px;'><img class='SimpleImage' style='width:92px;height:155px;top:1px;left:1px;' onclick='PopDownSetPaint(" + t + ");' src='" + AllPaint[t]["LargeImageURL"] + "' alt='" + AllPaint[t]["Name"] +"' title='" + AllPaint[t]["Name"] + "' />";
		NewBlock += "</div></div>";
		PD += NewBlock;
		X += 96;
		if (X > 450)
		{
			X = 1;
			Y += 159;
		}
	}
	PD += "<div style='text-decoration: underline; font-size: 16px; position: absolute; bottom: 5px; right: 5px;'><a href='javascript:PopDown()'>Back</a></div>";
	PopWindow.innerHTML = PD;
	PopUp();
}
function PopDownSetPaint(value)
{
	CurrentPaint = value;
	if (value == 6)
	{
		value = 2;
	}
	else
	{
		if (value >= 2)
		{
			value = 3;
		}
	}
	ClearSelect("Paint", value, 3);
	Update();
	PopDown();
}
function SetPanel(value)
{
	Clear("Panel", 4);
	if (value==-1)
	{
		DisableSection("Panel");
		CurrentPanel = -1;
	}
	else
	{
		EnableSection("Panel");
		if (value == 0)
		{
			if (CurrentPanel != -1)
			{
				value = CurrentPanel;
			}
			else
			{
				value = 1;
			}
		}
		CurrentPanel = value;
		Select("Panel", value);
		Update();
	}
}
function SetTrim(value)
{
	Clear("Trim", 3);
	if (value==-1)
	{
		DisableSection("Trim");
		CurrentTrim = -1;
	}
	else
	{
		EnableSection("Trim");
		if (value == 0)
		{
			if (CurrentTrim != -1)
			{
				value = CurrentTrim;
			}
			else
			{
				value = 1;
			}
		}
		CurrentTrim = value;
		Select("Trim", value);
		Update();
	}
}
function SetLouver(value)
{
	Clear("Louver", 4);
	if (value==-1)
	{
		DisableSection("Louver");
		CurrentLouver = -1;
	}
	else
	{
		EnableSection("Louver");
		if (value == 0)
		{
			if (CurrentLouver != -1)
			{
				value = CurrentLouver;
			}
			else
			{
				value = 1;
			}
		}
		if (value == 4)
		{
			PopDownLouver();
		}
		else
		{
			CurrentLouver = value;
			Select("Louver", value);
			Update();
			if (AllLouvers[value]["Trim"])
			{
				SetArch(-1);
			}
			else
			{
				if (CurrentBahama != 2 && (CurrentOSD == 1 || CurrentOSD == -1))
				{
					SetArch(0);
				}
			}
		}
	}
}
function PopDownLouver()
{
	var PopWindow = $('PopUpInner');
	var X, Y;
	X = 6;
	Y = 10;
	var PD = "";
	for (t=1;t<AllLouvers.length;t++)
	{
		if (! (AllLouvers[t]["Trim"] && !(CurrentArch == 1 || CurrentArch == -1)) )
		{
			var NewBlock="<div class='SimpleButtonOuterPopup' onmouseover='style.backgroundColor=\"#FFFFFF\"' onmouseout='style.backgroundColor=\"#000000\"' style='left:";
			NewBlock += X;
			NewBlock += ";top:" + Y + "'><div class='SimpleButtonInnerPopup'><img class='SimpleImage' onclick='PopDownSetLouver(" + t + ");' src='" + AllLouvers[t]["ImageURL"] + "' alt='" + AllLouvers[t]["Name"] +"' title='" + AllLouvers[t]["Name"] + "' />";
			NewBlock += "</div></div>";
			PD += NewBlock;
			X += 53;
			if (X > 482)
			{
				X = 6;
				Y += 60;
			}
		}
	}
	PopWindow.innerHTML = PD;
	PopUp();
}
function PopDownSetLouver(value)
{
	CurrentLouver = value;
	ClearSelect("Louver", value, 4);
	Update();
	if (AllLouvers[value]["Trim"])
	{
		SetArch(-1);
	}
	else
	{
		if (CurrentBahama != 2 && (CurrentOSD == 1 || CurrentOSD == -1))
		{
			SetArch(0);
		}
	}
	PopDown();
}
function isLeaf()
{
	return ($('InputPairs').selectedIndex == 0);
}
function SetFTR(value)
{
	if (value==-1)
	{
		DisableSection("FTR");
		CurrentFTR = -1;
	}
	else
	{
		EnableSection("FTR");
		if (value == 0)
		{
			if (CurrentFTR != -1)
			{
				value = CurrentFTR;
			}
			else
			{
				value = 1;
			}
		}
		CurrentFTR = value;
		ClearSelect("FTR", value, 2);
		Update();
	}
}
function SetCutout(value)
{
	if (value==-1)
	{
		DisableSection("Cutout");
		CurrentCutout = -1;
	}
	else
	{
		EnableSection("Cutout");
		if (value == 4)
		{
			PopDownCutout();
			return;
		}
		if (value == 0)
		{
			if (CurrentCutout != -1)
			{
				value = CurrentCutout;
			}
			else
			{
				value = 1;
			}
		}
		CurrentCutout = value;
		ClearSelect("Cutout", value, 4);
		Update();
	}
}
function PopDownCutout()
{
	var PopWindow = $('PopUpInner');
	var X, Y;
	X = 6;
	Y = 10;
	var PD = "";
	for (t=1;t<AllCutout.length;t++)
	{
		var NewBlock="<div class='SimpleButtonOuterPopup' onmouseover='style.backgroundColor=\"#FFFFFF\"' onmouseout='style.backgroundColor=\"#000000\"' style='left:";
		NewBlock += X;
		NewBlock += ";top:" + Y + "'><div class='SimpleButtonInnerPopup'><img class='SimpleImage' onclick='PopDownSetCutout(" + t + ");' src='" + AllCutout[t]["ImageURL"] + "' alt='" + AllCutout[t]["Name"] +"' title='" + AllCutout[t]["Name"] + "' />";
		NewBlock += "</div></div>";
		PD += NewBlock;
		X += 53;
		if (X > 482)
		{
			X = 6;
			Y += 60;
		}
	}
	PopWindow.innerHTML = PD;
	PopUp();
}
function InitializePaint()
{
	for (t=1;t<=3;t++)
	{
		var AN = "PaintImg" + t;
		$(AN).src = AllPaint[t]["ImageURL"];
		$(AN).alt = AllPaint[t]["Name"];
		$(AN).title = AllPaint[t]["Name"];
	}
}
function InitializeLouvers()
{
	for (t=1;t<=3;t++)
	{
		var AN = "LVRImg" + t;
		$(AN).src = AllLouvers[t]["ImageURL"];
		$(AN).alt = AllLouvers[t]["Name"];
		$(AN).title = AllLouvers[t]["Name"];
	}
}
function InitializeCutouts()
{
	for (t=1;t<=3;t++)
	{
		var AN = "COImg" + t;
		$(AN).src = AllCutout[t]["ImageURL"];
		$(AN).alt = AllCutout[t]["Name"];
		$(AN).title = AllCutout[t]["Name"];
	}
}
function PopDownSetCutout(value)
{
	CurrentCutout = value;
	ClearSelect("Cutout", value, 4);
	Update();
	PopDown();
}
function SetHorns(value)
{
	if (value==-1)
	{
		DisableSection("Horns");
		CurrentHorns = -1;
	}
	else
	{
		EnableSection("Horns");
		if (value == 0)
		{
			if (CurrentHorns != -1)
			{
				value = CurrentHorns;
			}
			else
			{
				value = 1;
			}
		}
		CurrentHorns = value;
		ClearSelect("Horns", value, 2);
		Update();
	}
	ChangedDimensions();
}
function SetArch(value)
{
	var OldArch = CurrentArch;
	if (value == 3 && AllStyles[CurrentStyle]["BnB"])
	{
		return;
	}
	if (value==-1)
	{
		DisableSection("Arch");
		CurrentArch = -1;
	}
	else
	{
		EnableSection("Arch");
		if (value == 0)
		{
			if (CurrentArch != -1)
			{
				value = CurrentArch;
			}
			else
			{
				value = 1;
			}
		}
		CurrentArch = value;
		if (value != 1)
		{
			SetOSD(-1);
			SetBahama(-1);
			EnableSection('ShortSide');
			SetCapping(-1);
		}
		else
		{
			DisableSection('ShortSide');
			if (!AllStyles[CurrentStyle]["BnB"] && CurrentCapping == -1)
			{
				SetCapping(0);
			}
			if (!AllStyles[CurrentStyle]["BnB"] && CurrentOSD == -1)
			{
				SetOSD(0);
				if (GetPairWidth() >= 40)
				{
					SetBahama(0);
				}
			}
		}
		ClearSelect("Arch", value, 3);
		SetSSAvailable();
		if (OldArch == 1 && CurrentArch != 1)
		{
			StartPulse("SSPulse");
		}
		Update();
	}
}
function SetOSD(value)
{
	if (value==-1)
	{
		DisableSection("OSD");
		CurrentOSD = -1;
	}
	else
	{
		EnableSection("OSD");
		if (value == 0)
		{
			if (CurrentOSD != -1)
			{
				value = CurrentOSD;
			}
			else
			{
				value = 1;
			}
		}
		CurrentOSD = value;
		if (value != 1)
		{
			SetArch(-1);
		}
		if (value == 1 && !TrimmedLouver() && CurrentBahama != 2)
		{
			SetArch(0);
		}
		ClearSelect("OSD", value, 4);
		Update();
	}
}
function SetISB(value)
{
	if (value==-1)
	{
		DisableSection("ISB");
		CurrentISB = -1;
	}
	else
	{
		EnableSection("ISB");
		if (value == 0)
		{
			if (CurrentISB != -1)
			{
				value = CurrentISB;
			}
			else
			{
				value = 1;
			}
		}
		CurrentISB = value;
		ClearSelect("ISB", value, 2);
		Update();
	}
}
function SetBahama(value)
{
	if (value==-1)
	{
		DisableSection("Bahama");
		CurrentBahama = -1;
	}
	else
	{
		EnableSection("Bahama");
		if (value == 0)
		{
			if (CurrentBahama != -1)
			{
				value = CurrentBahama;
			}
			else
			{
				value = 1;
			}
		}
		if (value == 2)
		{
			SetArch(-1);
		}
		if (value == 1)
		{
			if (!TrimmedLouver() && (CurrentOSD == 1 || CurrentOSD == -1))
			{
				SetArch(0);
			}
		}
		CurrentBahama = value;
		ClearSelect("Bahama", value, 2);
		SetDimensionAvailable();
		Update();
	}
}
function SetCapping(value)
{
	if (value==-1)
	{
		DisableSection("Capping");
		CurrentCapping = -1;
	}
	else
	{
		EnableSection("Capping");
		if (value == 0)
		{
			if (CurrentCapping != -1)
			{
				value = CurrentCapping;
			}
			else
			{
				value = 1;
			}
		}
		CurrentCapping = value;
		ClearSelect("Capping", value, 4);
		Update();
	}
}
function SetDuty(value)
{
	if (value==-1)
	{
		DisableSection("Duty");
		CurrentDuty = -1;
	}
	else
	{
		EnableSection("Duty");
		if (value == 0)
		{
			if (CurrentDuty != -1)
			{
				value = CurrentDuty;
			}
			else
			{
				value = 1;
			}
		}
		CurrentDuty = value;
		ClearSelect("Duty", value, 2);
		Select("Duty", value);
		Update();
	}
}
function SetZ(value)
{
	if (value==-1)
	{
		DisableSection("Z");
		CurrentZ = -1;
	}
	else
	{
		EnableSection("Z");
		if (value == 0)
		{
			if (CurrentZ != -1)
			{
				value = CurrentZ;
			}
			else
			{
				value = 1;
			}
		}
		CurrentZ = value;
		ClearSelect("Z", value, 2);
		Update();
	}
}
function TrimmedLouver()
{
	if (CurrentLouver == -1)
	{
		return false;
	}
	return AllLouvers[CurrentLouver]["Trim"];
}

function ClearSelect(group, value, maxvalue)
{
Clear(group, maxvalue);
Select(group, value);
}

function Select(group, Value)
{
	if (Value==-1)
	{
		return;
	}
	if (Value > 4)
	{
		Value = 4;
	}
	$(group + Value).style.backgroundColor = '#FF0000';
}
function Clear(value, MaxValue)
{
	for(t=1;t<=MaxValue;t++)
	{
		$(value + t).style.backgroundColor = '#FFFFFF';
	}
}
function EnableSection(Id)
{
	hide(Id + "Disabled");
}
function DisableSection(Id)
{
	show(Id + "Disabled");
}
function getFormValues(fobj,valFunc)
{
	var str = "";
	var valueArr = null;
	var val = "";
	var cmd = "";
	for(var i = 0;i < fobj.elements.length;i++)
	{
		switch(fobj.elements[i].type)
		{
			case "text":
			case "hidden":
			str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
			break;
			case "select-one":
			str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
			break;
		}
	}
	str = str.substr(0,(str.length - 1));
	return str;
}
function valid(value)
{
	return (value != '');
}
function AJAXSubmit()
{
	var file = 'http://vixenhill.com/Merchant2/merchant.mvc?';
	var str = getFormValues(document.getElementById("MivaMerchantForm"), 'valid');
	makePOSTRequest(file, str)
}
function HandleResponse(value)
{
	value = value.split("<!--$$-->")[1];
	value = value.split("<!--@@-->")[0];
	$("CartStatus").innerHTML = (value);
	hide('Adding', 'DisabledWorkPage');
	setDDLvalue($("InputQuantity"), 1);
	Update();
}
function Pulse(id, value, polarity)
{
	InPulse = true;
	var element = $(id);
	element.style.backgroundColor = "RGB(255, 255, " + value + ")";
	var functioncall = "Pulse('" + id + "', ";
	if (polarity == -15)
	{
		value -= 15;
		if (value > 0)
		{
			functioncall += value + ", -15);";
		}
		else
		{
			functioncall += "0, 15);";
		}
		setTimeout(functioncall, 1);
	}
	if (polarity == 15)
	{
		value += 15;
		if (value > 255)
		{
			InPulse = false;
		}
		else
		{
			functioncall += value + ", 15);";
			setTimeout(functioncall, 1);
		}
	}
}
function StartPulse(Id)
{
	if (!InPulse)
	{
		Pulse(Id, 255, -15);
	}
}

if (ContractorDiscount != 0)
{
	var targetDiv = $("CDiscount");
	targetDiv.innerHTML = "(" + (ContractorDiscount * 100) + "% Discount)";
}
function getQuantity()
{
	return $("InputQuantity").selectedIndex + 1;
}
function ViewLarger()
{
	var S = QS();
	S = S.replace("/Shutter.aspx", "/LargeShutter.aspx");
	window.open(S);
}
