﻿var centerThreeBlindsWidth
var centerThreeBlindsWidthe
var RightTwoBlindWidth
var RightTwoBlindWidthe
var outSideThreeBlindsWidth
var outSideThreeBlindsWidthe
var twoLeftBlindWidth
var twoLeftBlindWidthe

$(document).ready(function () {
	var RMOffset = $('#RightMenu').offset();
	if (RMOffset != null) {
		var RightMenuMarginTop = RMOffset.top;
		var scrollingDiv = $("#RightMenu");
		$(window).scroll(function () {
			if ($(window).scrollTop() > RightMenuMarginTop) {
				$("#RightMenu")
				  .stop()
				  .animate({ "marginTop": ($(window).scrollTop() - RightMenuMarginTop) + "px" });
			}
		});
	}
	$("#accessoriesDiv").find("input").click(function () {
		if ($(this).attr("checked")) {
			$("#a" + $(this).val()).val("Yes")
		}
		else {
			$("#a" + $(this).val()).val("No")
		}
	});

	var baseWidth = $('#baseWidth').find("option:selected").text();
	var baseHeight = $('#baseHeight').find("option:selected").text();
	var baseWidthE = $('#baseWidthEight').find("option:selected").text();
	var baseHeigthE = $('#baseHeigthEight').find("option:selected").text();
	var twoleftw, twolefth, tworightw, tworighth, threeleftw, threelefth, threerightw, threerighth, threecenterw, threecenterh;
	var twoleftwe, twolefthe, threeleftwe, threelefthe;


	//load our headrail blinds
	var twoOnOneWindow = MultiheadRailSplitCalculator(baseWidth, baseWidthE, 2);
	twoLeftBlindWidth = twoOnOneWindow.leftrightBlindInches;
	twoLeftBlindWidthe = twoOnOneWindow.leftrightBlindEighths;
	RightTwoBlindWidth = twoOnOneWindow.remainingBlindInches;
	RightTwoBlindWidthe = twoOnOneWindow.remainingBlindEighths;

	var threeOnOneWindow = MultiheadRailSplitCalculator(baseWidth, baseWidthE, 3);
	outSideThreeBlindsWidth = threeOnOneWindow.leftrightBlindInches;
	outSideThreeBlindsWidthe = threeOnOneWindow.leftrightBlindEighths;
	centerThreeBlindsWidth = threeOnOneWindow.remainingBlindInches;
	centerThreeBlindsWidthe = threeOnOneWindow.remainingBlindEighths;



	$("#configUpdateButton").click(function () {
		var twoBlindWidthTotal = parseInt($("#tworaildiv").find("#LeftBlind").find("#leftWidth").find("option:selected").text()) + parseInt($("#tworaildiv").find("#RightBlind").find("#rightWidth").find("option:selected").text());
		var threeBlindWidthTotal = parseInt($("#threeraildiv").find("#LeftBlind").find("#leftWidth").find("option:selected").text()) + parseInt($("#threeraildiv").find("#CenterBlind").find("#centerWidth").find("option:selected").text()) + parseInt($("#threeraildiv").find("#RightBlind").find("#rightWidth").find("option:selected").text());

	});

	var cartDataCartRecID = "CartRecID=" + $("#CartRecIDHidden").val();
	var cartDataProdID = 0, cartDataVarID;

	$("#freesamplelink").click(function () {
		if (cartDataProdID != 0) {
			$.ajax({
				type: "POST",
				url: "addtocart.aspx",
				data: cartDataCartRecID + "&" + cartDataProdID + "&" + cartDataVarID + "&IsWishList=0&VariantStyle=0&IsGiftRegistry=0&Quantity_vldt=1",
				success: function (msg) {
					alert("Sample added to cart ");
				},
				error: function (xhr, ajaxOptions, thrownError) {
					alert("z added to cart ");
				}
			});
		}
	});

	var myPreviewValueBC = $(".myPreviewValueBC");
	$(".blindColorLink").click(function () {

		$("#BlindColorSelect option[selected]").removeAttr("selected");
		$("#BlindColorSelect").val($(this).val()).attr("selected", "selected");
		myPreviewValueBC.text($(this).text());

	});
	//$("#myPreviewValueTiltLocation").val("Left");

	//$("#myPreviewValueTiltType")
	//$("#myPreviewValueLiftLocation").val("Left");

	$("#Routelesstapes").click(function () {
		$("#clothTapeItems").hide();
	});

	$("#Standardtapes").click(function () {
		$("#clothTapeItems").hide();
	});

	$("#Clothtapes").click(function () {
		$("#clothTapeItems").show();
	});


	$(".colorSample").find("input:radio").click(function () {
		$("#colorSampleLarge").find("img").attr("src", $(this).attr("src"));
		$(".myPreviewValueBC").val($(this).attr("alt"));
		cartDataProdID = "ProductID=" + $(this).siblings("#cartProductID").val();
		cartDataVarID = "VariantID=" + $(this).siblings("#cartVariantID").val();
		/**/
		var inputBox = $("#ProductID_1_1");
		if (inputBox.length > 0) inputBox[0].value = $(this).siblings("#cartProductID").val();
		inputBox = $("#VariantID_1_1");
		if (inputBox.length > 0) inputBox[0].value = $(this).siblings("#cartVariantID").val();
		
		/**/
		//alert($(this).find("a").attr("href"));
		//$("#freesamplelink").attr("href",$(this).find("#freesamplelinkRadio").attr("href"));

	});


	$(".ClothTapeOptionPics").find("input:radio").click(function () {
		//alert($(this).attr("alt"));
		$("#ClothImage").attr("src", $(this).attr("src"));
		$(".myPreviewValueCT").val($(this).attr("alt"));
	});


	$(".KitItemsOptions").find(".KitTopBar").find(".Step").find("span").each(function (i) {
		$(this).append(i + 1);
	});

	var myPreviewValueBC = $(".myPreviewValueBC");
	$("#BlindColorSelect").change(function () {
		myPreviewValueBC.val($(this).find("option:selected").text());
	});


	var myPreviewValueNN = $("#myPreviewValueNN");
	$(".POTextBoxName").find("input:text").change(function () {
		myPreviewValueNN.val($(this).val());
	});

	var myPreviewValueMount = $("#myPreviewValueMount");
	$("#mountDiv").find("input:radio").click(function () {
		myPreviewValueMount.val($(this).attr("alt"));
	});
	$("#Standardtapes").click(function () {

		$(".myPreviewTapeOptionValueCT").val("Standard Ladders");
		$(".myPreviewValueCT").val($(this).attr("alt"));
	});
	$("#Clothtapes").click(function () {
		$(".myPreviewTapeOptionValueCT").val("Cloth Tapes");
	});
	$("#Routelesstapes").click(function () {
		$(".myPreviewTapeOptionValueCT").val("Routeless");
		$(".myPreviewValueCT").val($(this).attr("alt"));
	});
	var myPreviewValueCT = $(".myPreviewValueCT");
	var myPreviewSpanCT = $("#myPreviewSpanCT");
	$("#clothTape").find("#details").find("#radioDetails").find("input:radio").change(function () {

		if ($(this).val() == "routeless") {
			myPreviewSpanCT.text("No Colors");
		}
		if ($(this).val() == "no") {
			myPreviewSpanCT.text("No Color");
		}
		if ($(this).val() == "yes") {
			myPreviewSpanCT.text("Color");
			$("#tapeColors").change(function () {
				myPreviewValueCT.val($(this).find("option:selected").text());
			});
		}
		myPreviewValueCT.val($(this).val());
	});

	//valances
	$("#valanceopt").change(function () {
		$("#myPreviewValueValance").val($(this).find("option:selected").text());
	});

	// img rollover


	//
	var myPreviewValueRightBlind = $("#myPreviewValueRightBlind");
	var myPreviewValueCenterBlind = $("#myPreviewValueCenterBlind");
	//single and multiple head rails

	var oneheadrailclick = function () {
		$("#singleBlind").show();
		$("#LeftBlind").hide();
		$("#RightBlind").hide();
		$("#CenterBlind").hide();
		$("#oneraildiv").show();
		$("#soneraildiv").show();
		$("#tworaildiv").hide();
		$("#threeraildiv").hide();
		$(".myPreviewValueHeadrail").val($(this).attr("alt"));
		$(".oneHeadRailOption").find("select").removeAttr("disabled");
		$(".twoheadrail").find("select").attr("disabled", "disabled");
		$(".threeheadrail").find("select").attr("disabled", "disabled");
	}

	$(".oneHeadRailOption").find("input:radio").click(oneheadrailclick);

	var twoheadrailclick = function () {

		$("#singleBlind").hide();
		$("#LeftBlind").show();
		$("#RightBlind").show();
		$("#soneraildiv").hide();
		$("#oneraildiv").hide();
		$("#tworaildiv").show();
		$("#threeraildiv").hide();
		$(".myPreviewValueHeadrail").val($(this).attr("alt"));
		$(".twoheadrail").find("select").removeAttr("disabled");
		$(".oneHeadRailOption").find("select").attr("disabled", "disabled");
		$(".threeheadrail").find("select").attr("disabled", "disabled");

	}

	$(".twoheadrail").find("input:radio").click(twoheadrailclick);

	var threeheadrailclick = function () {
		$("#singleBlind").hide();
		$("#LeftBlind").show();
		$("#RightBlind").show();
		$("#CenterBlind").show();
		$("#oneraildiv").hide();
		$("#tworaildiv").hide();
		$("#threeraildiv").show();
		$(".myPreviewValueHeadrail").val($(this).attr("alt"));
		$(".threeheadrail").find("select").removeAttr("disabled");
		$("#threeraildiv").find("#LeftBlind").find("select").removeAttr("disabled");
		$("#threeraildiv").find("#RightBlind").find("select").removeAttr("disabled");
		$("#threeraildiv").find("#CenterBlind").find("select").removeAttr("disabled");
		$(".oneHeadRailOption").find("select").attr("disabled", "disabled");
		$(".twoheadrail").find("select").attr("disabled", "disabled");
	}
	$(".threeheadrail").find("input:radio").click(threeheadrailclick);

	$("#inputValance").find("input:radio").click(function () {
		$("#myPreviewValueValance").val($(this).attr("alt"));
	});

	//single blind
	$(".oneHeadRailOption").find("#TilterLocation").change(function () {

		$("myPreviewValueTiltLocation").val($(this).find("option:selected").text());
		//alert($(this).text() + $("#LiftLocation").find("option:selected").text());

		if ($(this).find("option:selected").text() == 'Right') {
			if ($("#LiftLocation").find("option:selected").text() == 'Right') {
				$("#singlerail").attr("src", "/images/RRcontrol.png");
			}
			if ($("#LiftLocation").find("option:selected").text() == 'Left') {
				$("#singlerail").attr("src", "/images/LRcontrol.png");
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($("#LiftLocation").find("option:selected").text() == 'Right') {
				$("#singlerail").attr("src", "/images/LRcontrol.png");
			}
			if ($("#LiftLocation").find("option:selected").text() == 'Left') {
				$("#singlerail").attr("src", "/images/LLcontrols.jpg");
			}
		}
		//$("#singlerail").attr("src","/images/RRcontrol.png");    
		$("#singleBlind").find("#myPreviewValueTiltLocation").val($(this).find("option:selected").text());
	});
	//shade single blind
	$("#soneraildiv").find("select").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			$("#singlerail").attr("src", "/images/shadeLRcontrol.png");
		}
		if ($(this).find("option:selected").text() == 'Left') {

			$("#singlerail").attr("src", "/images/shadeLLcontrols.jpg");

		}
	});

	$(".oneHeadRailOption").find("#TilterType").change(function () {
		$("#singleBlind").find("#myPreviewValueTiltType").val($(this).find("option:selected").text());
	});
	$(".oneHeadRailOption").find("#LiftLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			if ($("#TilterLocation").find("option:selected").text() == 'Right') {
				$("#singlerail").attr("src", "/images/RRcontrol.png");
			}
			if ($("#TilterLocation").find("option:selected").text() == 'Left') {
				$("#singlerail").attr("src", "/images/LRcontrol.png");
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($("#TilterLocation").find("option:selected").text() == 'Right') {
				$("#singlerail").attr("src", "/images/LRcontrol.png");
			}
			if ($("#TilterLocation").find("option:selected").text() == 'Left') {
				$("#singlerail").attr("src", "/images/LLcontrols.jpg");
			}
		}
		$("#singleBlind").find("#myPreviewValueLiftLocation").val($(this).find("option:selected").text());
	});
	//rightMenuTitle
	//    $("#blindColorRadio").click(function() {
	//        $(".rightMenuTitle").append($("#blindColorRadio").text());
	//    });

	//2 on one 
	//left
	$(".twoheadrail").find("#LeftTilterLocation").change(function () {

		$("myPreviewValueTiltLocation").val($(this).find("option:selected").text());
		if ($(this).find("option:selected").text() == 'Right') {
			if ($("#LeftLiftLocation").find("option:selected").text() == 'Right') {
				if ($("#RightLiftLocation").find("option:selected").text() == 'Right' && $("#RightTiltLocation").find("option:selected").text() == 'Right') {
					$("#singlerail").attr("src", "/images/RRRRcontrol.png");
				}
				if ($("#RightLiftLocation").find("option:selected").text() == 'Left' && $("#RightTiltLocation").find("option:selected").text() == 'Right') {
					$("#singlerail").attr("src", "/images/RRLRcontrol.png");
				}
				if ($("#RightLiftLocation").find("option:selected").text() == 'Right' && $("#RightTiltLocation").find("option:selected").text() == 'Left') {
					$("#singlerail").attr("src", "/images/RRRLcontrol.png");
				}
				if ($("#RightLiftLocation").find("option:selected").text() == 'Left' && $("#RightTiltLocation").find("option:selected").text() == 'Left') {
					$("#singlerail").attr("src", "/images/RRLLcontrol.png");
				}
				//$("#singlerail").attr("src","/images/RRRRcontrol.png");  
			}
			if ($("#LeftLiftLocation").find("option:selected").text() == 'Left') {
				if ($("#RightLiftLocation").find("option:selected").text() == 'Right' && $("#RightTiltLocation").find("option:selected").text() == 'Right') {
					$("#singlerail").attr("src", "/images/LRRRcontrol.png");
				}
				if ($("#RightLiftLocation").find("option:selected").text() == 'Left' && $("#RightTiltLocation").find("option:selected").text() == 'Right') {
					$("#singlerail").attr("src", "/images/LLLRcontrol.png");
				}
				if ($("#RightLiftLocation").find("option:selected").text() == 'Right' && $("#RightTiltLocation").find("option:selected").text() == 'Left') {
					$("#singlerail").attr("src", "/images/LRRLcontrol.png");
				}
				if ($("#RightLiftLocation").find("option:selected").text() == 'Left' && $("#RightTiltLocation").find("option:selected").text() == 'Left') {
					$("#singlerail").attr("src", "/images/LLLLcontrol.png");
				}
				//$("#singlerail").attr("src","/images/LRRRcontrol.png");  
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($("#LeftLiftLocation").find("option:selected").text() == 'Right') {
				$("#singlerail").attr("src", "/images/LRRRcontrol.png");
			}
			if ($("#LeftLiftLocation").find("option:selected").text() == 'Left') {
				$("#singlerail").attr("src", "/images/LLRRcontrols.jpg");
			}
		}
		$("#LeftBlind").find("#myPreviewValueTiltLocation").val($(this).find("option:selected").text());
	});
	$(".twoheadrail").find("#LeftTilterType").change(function () {
		$("#LeftBlind").find("#myPreviewValueTiltType").val($(this).find("option:selected").text());
	});
	$(".twoheadrail").find("#LeftLiftLocation").change(function () {
		$("#LeftBlind").find("#myPreviewValueLiftLocation").val($(this).find("option:selected").text());
	});
	$(".twoheadrail").find("#LeftBlind").find("#width").change(function () {
		$("#LeftBlind").find("#myPreviewValueWidght").val($(this).find("option:selected").text());
	});
	$(".twoheadrail").find("#LeftBlind").find("#widtheight").change(function () {
		if ($(this).find("option:selected").text() != "0/8") {
			$("#LeftBlind").find("#myPreviewValueWidght").append("&nbsp;" + $(this).find("option:selected").text());
		}
		else {
			$("#LeftBlind").find("#myPreviewValueWidght").val($(".twoheadrail").find("#width").find("option:selected").text() + '"');
		}
	});
	$(".twoheadrail").find("#LeftBlind").find("#height").change(function () {
		$("#LeftBlind").find("#myPreviewValueHeight").val($(this).find("option:selected").text());
	});
	$(".twoheadrail").find("#LeftBlind").find("#heighteight").change(function () {
		if ($(this).find("option:selected").text() != "0/8") {
			$("#LeftBlind").find("#myPreviewValueHeight").append("&nbsp;" + $(this).find("option:selected").text());
		}
		else {
			$("#LeftBlind").find("#myPreviewValueHeight").val($(".twoheadrail").find("#height").find("option:selected").text() + '"');
		}
	});
	//right
	$(".twoheadrail").find("#RightTilterLocation").change(function () {
		$("#RightBlind").find("#myPreviewValueTiltLocation").val($(this).find("option:selected").text());
	});
	$(".twoheadrail").find("#RightTilterType").change(function () {
		$("#RightBlind").find("#myPreviewValueTiltType").val($(this).find("option:selected").text());
	});
	$(".twoheadrail").find("#RightLiftLocation").change(function () {
		$("#RightBlind").find("#myPreviewValueLiftLocation").val($(this).find("option:selected").text());
	});
	$(".twoheadrail").find("#RightBlind").find("#width").change(function () {
		$("#RightBlind").find("#myPreviewValueWidght").val($(this).find("option:selected").text());
	});
	$(".twoheadrail").find("#RightBlind").find("#widtheight").change(function () {
		if ($(this).find("option:selected").text() != "0/8") {
			$("#RightBlind").find("#myPreviewValueWidght").append("&nbsp;" + $(this).find("option:selected").text());
		}
		else {
			$("#RightBlind").find("#myPreviewValueWidght").val($(".twoheadrail").find("#width").find("option:selected").text() + '"');
		}
	});
	$(".twoheadrail").find("#RightBlind").find("#height").change(function () {
		$("#RightBlind").find("#myPreviewValueHeight").val($(this).find("option:selected").text());
	});
	$(".twoheadrail").find("#RightBlind").find("#heighteight").change(function () {
		if ($(this).find("option:selected").text() != "0/8") {
			$("#RightBlind").find("#myPreviewValueHeight").append("&nbsp;" + $(this).find("option:selected").text());
		}
		else {
			$("#RightBlind").find("#myPreviewValueHeight").val($(".twoheadrail").find("#height").find("option:selected").text() + '"');
		}
	});
	//3 on one
	//left
	$(".threeheadrail").find("#TilterLocation").change(function () {
		$("#LeftBlind").find("#myPreviewValueTiltLocation").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#TilterType").change(function () {
		$("#LeftBlind").find("#myPreviewValueTiltType").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#LiftLocation").change(function () {
		$("#LeftBlind").find("#myPreviewValueLiftLocation").val($(this).find("option:selected").text());
	});
	//center
	$(".threeheadrail").find("#TilterLocation").change(function () {
		$("#CenterBlind").find("#myPreviewValueTiltLocation").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#TilterType").change(function () {
		$("#CenterBlind").find("#myPreviewValueTiltType").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#LiftLocation").change(function () {
		$("#CenterBlind").find("#myPreviewValueLiftLocation").val($(this).find("option:selected").text());
	});
	//right
	$(".threeheadrail").find("#TilterLocation").change(function () {
		$("#CenterBlind").find("#myPreviewValueTiltLocation").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#TilterType").change(function () {
		$("#CenterBlind").find("#myPreviewValueTiltType").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#LiftLocation").change(function () {
		$("#CenterBlind").find("#myPreviewValueLiftLocation").val($(this).find("option:selected").text());
	});
	//wid/heigh
	$(".threeheadrail").find("#RightBlind").find("#width").change(function () {
		$("#RightBlind").find("#myPreviewValueWidght").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#RightBlind").find("#widtheight").change(function () {
		if ($(this).find("option:selected").text() != "0/8") {
			$("#RightBlind").find("#myPreviewValueWidght").append("&nbsp;" + $(this).find("option:selected").text());
		}
		else {
			$("#RightBlind").find("#myPreviewValueWidght").val($(".threeheadrail").find("#width").find("option:selected").text() + '"');
		}
	});
	$(".threeheadrail").find("#RightBlind").find("#height").change(function () {
		$("#RightBlind").find("#myPreviewValueHeight").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#RightBlind").find("#heighteight").change(function () {
		if ($(this).find("option:selected").text() != "0/8") {
			$("#RightBlind").find("#myPreviewValueHeight").append("&nbsp;" + $(this).find("option:selected").text());
		}
		else {
			$("#RightBlind").find("#myPreviewValueHeight").val($(".threeheadrail").find("#height").find("option:selected").text() + '"');
		}
	});


	$(".threeheadrail").find("#CenterBlind").find("#width").change(function () {
		$("#CenterBlind").find("#myPreviewValueWidght").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#CenterBlind").find("#widtheight").change(function () {
		if ($(this).find("option:selected").text() != "0/8") {
			$("#CenterBlind").find("#myPreviewValueWidght").append("&nbsp;" + $(this).find("option:selected").text());
		}
		else {
			$("#CenterBlind").find("#myPreviewValueWidght").val($(".threeheadrail").find("#width").find("option:selected").text() + '"');
		}
	});
	$(".threeheadrail").find("#CenterBlind").find("#height").change(function () {
		$("#CenterBlind").find("#myPreviewValueHeight").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#CenterBlind").find("#heighteight").change(function () {
		if ($(this).find("option:selected").text() != "0/8") {
			$("#CenterBlind").find("#myPreviewValueHeight").append("&nbsp;" + $(this).find("option:selected").text());
		}
		else {
			$("#CenterBlind").find("#myPreviewValueHeight").val($(".threeheadrail").find("#height").find("option:selected").text() + '"');
		}
	});

	$(".threeheadrail").find("#CenterBlind").find("#width").change(function () {
		$("#CenterBlind").find("#myPreviewValueWidght").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#CenterBlind").find("#widtheight").change(function () {
		if ($(this).find("option:selected").text() != "0/8") {
			$("#CenterBlind").find("#myPreviewValueWidght").append("&nbsp;" + $(this).find("option:selected").text());
		}
		else {
			$("#CenterBlind").find("#myPreviewValueWidght").val($(".threeheadrail").find("#width").find("option:selected").text() + '"');
		}
	});
	$(".threeheadrail").find("#CenterBlind").find("#height").change(function () {
		$("#CenterBlind").find("#myPreviewValueHeight").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#CenterBlind").find("#heighteight").change(function () {
		if ($(this).find("option:selected").text() != "0/8") {
			$("#CenterBlind").find("#myPreviewValueHeight").append("&nbsp;" + $(this).find("option:selected").text());
		}
		else {
			$("#CenterBlind").find("#myPreviewValueHeight").val($(".threeheadrail").find("#height").find("option:selected").text() + '"');
		}
	});

	$(".threeheadrail").find("#LeftBlind").find("#width").change(function () {
		$("#LeftBlind").find("#myPreviewValueWidght").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#LeftBlind").find("#widtheight").change(function () {
		if ($(this).find("option:selected").text() != "0/8") {
			$("#LeftBlind").find("#myPreviewValueWidght").append("&nbsp;" + $(this).find("option:selected").text());
		}
		else {
			$("#LeftBlind").find("#myPreviewValueWidght").val($(".threeheadrail").find("#width").find("option:selected").text() + '"');
		}
	});
	$(".threeheadrail").find("#LeftBlind").find("#height").change(function () {
		$("#LeftBlind").find("#myPreviewValueHeight").val($(this).find("option:selected").text());
	});
	$(".threeheadrail").find("#LeftBlind").find("#heighteight").change(function () {
		if ($(this).find("option:selected").text() != "0/8") {
			$("#LeftBlind").find("#myPreviewValueHeight").append("&nbsp;" + $(this).find("option:selected").text());
		}
		else {
			$("#LeftBlind").find("#myPreviewValueHeight").val($(".threeheadrail").find("#height").find("option:selected").text() + '"');
		}
	});
	$(".AddToCartButton").click(function () {
		if ($("#windowName").val() == "Give your window a nickname: ie Kitchen Middle Top") {
			$("#windowName").val("");
		}

	});

	$("#update").click(function () {

		if ($("#windowSizeDim").find("#width").find("option:selected").text() == "--" || $("#windowSizeDim").find("#height").find("option:selected").text() == "--") {
			alert("Please select a valid size");
		}
		else {
			processFacetSubmit()
		}

	});

	$("DIV.CatLanding input").click(function () {
		processFacetSubmit();
	});

	function processFacetSubmit() {

		var queryString = new Array();
		if (parseInt($('select[name="width"]').val(), 10) > 0) {
			queryString.push('facetquery=width:' + $('select[name="width"]').val());
			queryString.push('width=' + $('select[name="width"]').val());
		}
		if (parseInt($('select[name="height"]').val(), 10) > 0) {
			queryString.push('facetquery=height:' + $('select[name="height"]').val());
			queryString.push('height=' + $('select[name="height"]').val());
		}
		if (parseInt($('select[name="widtheighth"]').val(), 10) > 0) {
			queryString.push('widtheighth=' + $('select[name="widtheighth"]').val());
		}
		if (parseInt($('select[name="heighteighth"]').val(), 10) > 0) {
			queryString.push('heighteighth=' + $('select[name="heighteighth"]').val());
		}

		$("input[name=FacetQuery]:checked").each(function (index) {
			queryString.push('facetquery=' + $(this).val());
		});

		$("input[name=FacetQuery][type != checkbox]").each(function (index) {
			queryString.push('&facetquery=' + $(this).val());
		});
		if (queryString.length > 0) {
			window.location = location.pathname + "?" + queryString.join('&');
		} else {
			window.location = location.pathname;
		}

	}

	$("#windowName").click(function () {
		if ($("#windowName").val() == "Give your window a nickname: ie Kitchen Middle Top") {
			$("#windowName").val("");
		}

	});

	$("#windowName").change(function () {
		$("#myPreviewValueNN").val($("#windowName").val());
	});

	$("#baseWidth").change(function() {
	    RedirectToProductValidate();
	});

	$("#baseHeight").change(function() {
	    RedirectToProductValidate();
	});

	$("#updateDim").click(function () {
		RedirectToProductValidate();
	});
	function RedirectToProductValidate() {
		var url = String('/productvalidate.aspx/ProductValidateReturnUrl');
		$.ajax({
			url: url,
			dataType: 'json',
			data: { sProductId: $('#baseProductId').attr('value'),
				sWidth: "\"" + $('#baseWidth').find("option:selected").text() + "\"",
				sHeight: "\"" + $('#baseHeight').find("option:selected").text() + "\"",
				sWidthEight: "\"" + $('#baseWidthEight').find("option:selected").text() + "\"",
				sHeightEight: "\"" + $('#baseHeigthEight').find("option:selected").text() + "\""
			},
			contentType: 'application/json',
			success: ProcessRedirectToProductValidate,
			error: ProcessRedirectToProductValidateError
		});
	}
	function ProcessRedirectToProductValidate(data) {
		if (data.d) window.location = data.d;
		else alert(data);
	}

	function ProcessRedirectToProductValidateError(XMLHttpRequest, textStatus, errorThrown) {
		var response = XMLHttpRequest.responseText;

		//HACK - Workaround for unlicensed ASPDNSF
		if (textStatus == "parsererror") {
			var i = response.indexOf("}");
			var cleanResponse = response.substring(0, i + 1);
			var data = $.parseJSON(cleanResponse);
			if (data.d) {
				window.location = data.d;
				return 0;
			}
		} else if (textStatus == "error") {
			var i = response.indexOf("}");
			var cleanResponse = response.substring(0, i + 1);
			var data = $.parseJSON(cleanResponse);
			if (data.Message) {
				alert(data.Message + "\n Please select another size.");
				return 0;
			}
		}
		//END HACK

		try {
			var error = jQuery.parseJSON(response);
			if (error.Message) alert(error.Message + "\n Please select another size.");
			else alert("Error:" + response);
		} catch (ex) {
			alert(ex);
		}

	}

	var showTapes = $("#Clothtapes").is(':checked');
	var showRouteless = $("#Routelesstapes").is(':checked');
	var showStandard = $("#Standardtapes").is(':checked');

	switch (true) {
		case showRouteless:
			$("#clothTapeItems").hide();
			break;
		case showStandard:
			$("#clothTapeItems").hide();
			break;
		case showTapes:
			$("#clothTapeItems").show();
			break;
		default:
			$("#clothTapeItems").hide();
	}


	if ($(".oneHeadRailOption :radio:first").is(':checked')) {
		oneheadrailclick();
	}

	if ($(".twoheadrail :radio:first").is(':checked')) {
		twoheadrailclick();
	}

	if ($(".threeheadrail :radio:first").is(':checked')) {
		threeheadrailclick();
	}

	//LeftBlindmyPreviewValueWidght
	//ntwoleftw, ntwolefth, ntworightw, ntworighth, nthreeleftw, nthreelefth, nthreerightw, nthreerighth, nthreecenterw, nthreecenterh;

	//for automating the blinds widths on multiple rails
	//    $("#tworaildiv").find("#LeftBlind").find("#leftwidth").click(
	//    $("#tworaildiv").find("#RightBlind").find("#rightHeight").val(tworighth).attr("selected", "selected");
	//    $("#threeraildiv").find("#LeftBlind").find("#leftWidth").val(threeleftw).attr("selected", "selected");

	//for displaying wid/heigh on each blind
	var temp;

	$("#leftWidth").change(function () {
		//        if (ntwoleftw == 0) {
		//            ntwoleftw = $(this).find("option:selected").text();
		//        }
		//        else {
		//            otwoleftw = ntwoleftw;
		//            ntwoleftw = $(this).find("option:selected").text();
		//        }
		//        temp = parseFloat($("#tworaildiv").find("#RightBlind").find("#rightWidth").find("option:selected").text());
		//        temp += otwoleftw - ntwoleftw;
		//        alert(temp);
		//        if (temp > 0 && temp < (baseWidth - 6)) {
		//            $("#tworaildiv").find("#RightBlind").find("#rightWidth").val(temp).attr("selected", "selected");
		//        }
		//        else {
		//            alert("Please try a different combo");
		//        }
		$("#LeftBlind").find("#myPreviewValueWidght").val($(this).find("option:selected").text());
	});
	$("#leftWidthe").change(function () {
		$("#LeftBlind").find("#myPreviewValueWidght").val($("#LeftBlind").find("#myPreviewValueWidght").val() + " " + $(this).find("option:selected").text());
	});
	$("#leftHeight").change(function () {
		$("#LeftBlind").find("#myPreviewValueHeight").val($(this).find("option:selected").text());
	});
	$("#leftHeighte").change(function () {
		$("#LeftBlind").find("#myPreviewValueHeight").val($("#LeftBlind").find("#myPreviewValueHeight").val() + " " + $(this).find("option:selected").text());
	});

	$("#rightWidth").change(function () {
		$("#RightBlind").find("#myPreviewValueWidght").val($(this).find("option:selected").text());
	});
	$("#rightWidthe").change(function () {
		$("#RightBlind").find("#myPreviewValueWidght").val($("#RightBlind").find("#myPreviewValueWidght").val() + " " + $(this).find("option:selected").text());
	});
	$("#rightHeight").change(function () {
		$("#RightBlind").find("#myPreviewValueHeight").val($(this).find("option:selected").text());
	});
	$("#rightHeighte").change(function () {
		$("#RightBlind").find("#myPreviewValueHeight").val($("#RightBlind").find("#myPreviewValueHeight").val() + " " + $(this).find("option:selected").text());
	});

	$("#centerWidth").change(function () {
		$("#CenterBlind").find("#myPreviewValueWidght").val($(this).find("option:selected").text());
	});
	$("#centerWidthe").change(function () {
		$("#CenterBlind").find("#myPreviewValueWidght").val($("#CenterBlind").find("#myPreviewValueWidght").val() + " " + $(this).find("option:selected").text());
	});
	$("#centerHeight").change(function () {
		$("#CenterBlind").find("#myPreviewValueHeight").val($(this).find("option:selected").text());
	});
	$("#centerHeighte").change(function () {
		$("#CenterBlind").find("#myPreviewValueHeight").val($("#CenterBlind").find("#myPreviewValueHeight").val() + " " + $(this).find("option:selected").text());
	});

	$("#threeraildiv").find("#leftWidth").change(function () {
		$("#LeftBlind").find("#myPreviewValueWidght").val($(this).find("option:selected").text());
	});
	$("#threeraildiv").find("#leftWidthe").change(function () {
		$("#LeftBlind").find("#myPreviewValueWidght").val($("#LeftBlind").find("#myPreviewValueWidght").val() + " " + $(this).find("option:selected").text());
	});
	$("#threeraildiv").find("#leftHeight").change(function () {
		$("#LeftBlind").find("#myPreviewValueHeight").val($(this).find("option:selected").text());
	});
	$("#threeraildiv").find("#leftHeighte").change(function () {
		$("#LeftBlind").find("#myPreviewValueHeight").val($("#LeftBlind").find("#myPreviewValueHeight").val() + " " + $(this).find("option:selected").text());
	});

	$("#threeraildiv").find("#rightWidth").change(function () {
		$("#RightBlind").find("#myPreviewValueWidght").val($(this).find("option:selected").text());
	});
	$("#threeraildiv").find("#rightWidthe").change(function () {
		$("#RightBlind").find("#myPreviewValueWidght").val($("#RightBlind").find("#myPreviewValueWidght").val() + " " + $(this).find("option:selected").text());
	});
	$("#threeraildiv").find("#rightHeight").change(function () {
		$("#RightBlind").find("#myPreviewValueHeight").val($(this).find("option:selected").text());
	});
	$("#threeraildiv").find("#rightHeighte").change(function () {
		$("#RightBlind").find("#myPreviewValueHeight").val($("#RightBlind").find("#myPreviewValueHeight").val() + " " + $(this).find("option:selected").text());
	});

	$("#tworaildiv").find("#LeftBlind").find("#LeftLiftLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			if ($("#tworaildiv").find("#LeftBlind").find("#LeftTilterLocation").find("option:selected").text() == 'Right') {
				$("#2left1").attr("src", "/images/RRcontrol.png");
			}
			if ($("#tworaildiv").find("#LeftBlind").find("#LeftTilterLocation").find("option:selected").text() == 'Left') {
				$("#2left1").attr("src", "/images/LRcontrol.png");
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($("#tworaildiv").find("#LeftBlind").find("#LeftTilterLocation").find("option:selected").text() == 'Right') {
				$("#2left1").attr("src", "/images/LRcontrol.png");
			}
			if ($("#tworaildiv").find("#LeftBlind").find("#LeftTilterLocation").find("option:selected").text() == 'Left') {
				$("#2left1").attr("src", "/images/LLcontrol.png");
			}
		}
	});
	$("#tworaildiv").find("#LeftBlind").find("#LeftTilterLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			if ($("#tworaildiv").find("#LeftBlind").find("#LeftLiftLocation").find("option:selected").text() == 'Right') {
				$("#2left1").attr("src", "/images/RRcontrol.png");
			}
			if ($("#tworaildiv").find("#LeftBlind").find("#LeftLiftLocation").find("option:selected").text() == 'Left') {
				$("#2left1").attr("src", "/images/LRcontrol.png");
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($("#tworaildiv").find("#LeftBlind").find("#LeftLiftLocation").find("option:selected").text() == 'Right') {
				$("#2left1").attr("src", "/images/LRcontrol.png");
			}
			if ($("#tworaildiv").find("#LeftBlind").find("#LeftLiftLocation").find("option:selected").text() == 'Left') {
				$("#2left1").attr("src", "/images/LLcontrol.png");
			}
		}
	});
	$("#tworaildiv").find("#RightBlind").find("#RightLiftLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			if ($("#tworaildiv").find("#RightBlind").find("#RightTilterLocation").find("option:selected").text() == 'Right') {
				$("#2right1").attr("src", "/images/RightRRcontrol.png");
			}
			if ($("#tworaildiv").find("#RightBlind").find("#RightTilterLocation").find("option:selected").text() == 'Left') {
				$("#2right1").attr("src", "/images/RightLRcontrol.png");
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($("#tworaildiv").find("#RightBlind").find("#RightTilterLocation").find("option:selected").text() == 'Right') {
				$("#2right1").attr("src", "/images/RightLRcontrol.png");
			}
			if ($("#tworaildiv").find("#RightBlind").find("#RightTilterLocation").find("option:selected").text() == 'Left') {
				$("#2right1").attr("src", "/images/RightLLcontrol.png");
			}
		}
	});
	$("#tworaildiv").find("#RightBlind").find("#RightTilterLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			if ($("#tworaildiv").find("#RightBlind").find("#RightLiftLocation").find("option:selected").text() == 'Right') {
				$("#2right1").attr("src", "/images/RightRRcontrol.png");
			}
			if ($("#tworaildiv").find("#RightBlind").find("#RightLiftLocation").find("option:selected").text() == 'Left') {
				$("#2right1").attr("src", "/images/RightLRcontrol.png");
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($("#tworaildiv").find("#RightBlind").find("#RightLiftLocation").find("option:selected").text() == 'Right') {
				$("#2right1").attr("src", "/images/RightLRcontrol.png");
			}
			if ($("#tworaildiv").find("#RightBlind").find("#RightLiftLocation").find("option:selected").text() == 'Left') {
				$("#2right1").attr("src", "/images/RightLLcontrol.png");
			}
		}
	});
	$(".threeheadrail").find("#LeftBlind").find("#LiftLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			if ($(".threeheadrail").find("#LeftBlind").find("#TilterLocation").find("option:selected").text() == 'Right') {
				$("#left1").attr("src", "/images/RRcontrol.png");
			}
			if ($(".threeheadrail").find("#LeftBlind").find("#TilterLocation").find("option:selected").text() == 'Left') {
				$("#left1").attr("src", "/images/LRcontrol.png");
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($(".threeheadrail").find("#LeftBlind").find("#TilterLocation").find("option:selected").text() == 'Right') {
				$("#left1").attr("src", "/images/LRcontrol.png");
			}
			if ($(".threeheadrail").find("#LeftBlind").find("#TilterLocation").find("option:selected").text() == 'Left') {
				$("#left1").attr("src", "/images/LLcontrol.png");
			}
		}
	});
	$(".threeheadrail").find("#LeftBlind").find("#TilterLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			if ($(".threeheadrail").find("#LeftBlind").find("#LiftLocation").find("option:selected").text() == 'Right') {
				$("#left1").attr("src", "/images/RRcontrol.png");
			}
			if ($(".threeheadrail").find("#LeftBlind").find("#LiftLocation").find("option:selected").text() == 'Left') {
				$("#left1").attr("src", "/images/LRcontrol.png");
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($(".threeheadrail").find("#LeftBlind").find("#LiftLocation").find("option:selected").text() == 'Right') {
				$("#left1").attr("src", "/images/LRcontrol.png");
			}
			if ($(".threeheadrail").find("#LeftBlind").find("#LiftLocation").find("option:selected").text() == 'Left') {
				$("#left1").attr("src", "/images/LLcontrol.png");
			}
		}
	});
	$(".threeheadrail").find("#RightBlind").find("#LiftLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			if ($(".threeheadrail").find("#RightBlind").find("#TilterLocation").find("option:selected").text() == 'Right') {
				$("#right1").attr("src", "/images/RightRRcontrol.png");
			}
			if ($(".threeheadrail").find("#RightBlind").find("#TilterLocation").find("option:selected").text() == 'Left') {
				$("#right1").attr("src", "/images/RightLRcontrol.png");
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($(".threeheadrail").find("#RightBlind").find("#TilterLocation").find("option:selected").text() == 'Right') {
				$("#right1").attr("src", "/images/RightLRcontrol.png");
			}
			if ($(".threeheadrail").find("#RightBlind").find("#TilterLocation").find("option:selected").text() == 'Left') {
				$("#right1").attr("src", "/images/RightLLcontrol.png");
			}
		}
	});
	$(".threeheadrail").find("#RightBlind").find("#TilterLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			if ($(".threeheadrail").find("#RightBlind").find("#LiftLocation").find("option:selected").text() == 'Right') {
				$("#right1").attr("src", "/images/RightRRcontrol.png");
			}
			if ($(".threeheadrail").find("#RightBlind").find("#LiftLocation").find("option:selected").text() == 'Left') {
				$("#right1").attr("src", "/images/RightLRcontrol.png");
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($(".threeheadrail").find("#RightBlind").find("#LiftLocation").find("option:selected").text() == 'Right') {
				$("#right1").attr("src", "/images/RightLRcontrol.png");
			}
			if ($(".threeheadrail").find("#RightBlind").find("#LiftLocation").find("option:selected").text() == 'Left') {
				$("#right1").attr("src", "/images/RightLLcontrol.png");
			}
		}
	});
	$(".threeheadrail").find("#CenterBlind").find("#LiftLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			if ($(".threeheadrail").find("#CenterBlind").find("#TilterLocation").find("option:selected").text() == 'Right') {
				$("#center1").attr("src", "/images/RightRRcontrol.png");
			}
			if ($(".threeheadrail").find("#CenterBlind").find("#TilterLocation").find("option:selected").text() == 'Left') {
				$("#center1").attr("src", "/images/RightLRcontrol.png");
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($(".threeheadrail").find("#CenterBlind").find("#TilterLocation").find("option:selected").text() == 'Right') {
				$("#center1").attr("src", "/images/RightLRcontrol.png");
			}
			if ($(".threeheadrail").find("#CenterBlind").find("#TilterLocation").find("option:selected").text() == 'Left') {
				$("#center1").attr("src", "/images/RightLLcontrol.png");
			}
		}
	});
	$(".threeheadrail").find("#CenterBlind").find("#TilterLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			if ($(".threeheadrail").find("#CenterBlind").find("#LiftLocation").find("option:selected").text() == 'Right') {
				$("#center1").attr("src", "/images/RightRRcontrol.png");
			}
			if ($(".threeheadrail").find("#CenterBlind").find("#LiftLocation").find("option:selected").text() == 'Left') {
				$("#center1").attr("src", "/images/RightLRcontrol.png");
			}
		}
		if ($(this).find("option:selected").text() == 'Left') {
			if ($(".threeheadrail").find("#CenterBlind").find("#LiftLocation").find("option:selected").text() == 'Right') {
				$("#center1").attr("src", "/images/RightLRcontrol.png");
			}
			if ($(".threeheadrail").find("#CenterBlind").find("#LiftLocation").find("option:selected").text() == 'Left') {
				$("#center1").attr("src", "/images/RightLLcontrol.png");
			}
		}
	});

	$("#shadeLeftBlind").find("#LeftLiftLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {
			$("#2left1").attr("src", "/images/shadeLRcontrol.png");
		}
		if ($(this).find("option:selected").text() == 'Left') {
			$("#2left1").attr("src", "/images/shadeLLcontrols.jpg");
		}
	});
	$("#shadeRightBlind").find("#RightLiftLocation").change(function () {
		if ($(this).find("option:selected").text() == 'Right') {

			$("#2right1").attr("src", "/images/shadeRightLRcontrol.png");

		}
		if ($(this).find("option:selected").text() == 'Left') {

			$("#2right1").attr("src", "/images/shadeRightLLcontrol.png");

		}
	});
});

function MultiheadRailSplitCalculator(inches, eighthsAsFraction, numberOfBlinds) {
    //convert eighths to an integer of the number of eithts . 2 = 2 eighths
    var eighthsAsDecimal = eighthsAsFraction.substring(0, 1) / eighthsAsFraction.substring(2);

    //set to 0 if no fraction was passed
    eighthsAsDecimal = eighthsAsDecimal > 0 ? eighthsAsDecimal : 0;

    var eighthsAsInt = eighthsAsDecimal * 8;
    // convert our inches to a number of eights
    var inchesAsIntOfEighths = inches * 8;
    var totalEighths = inchesAsIntOfEighths + eighthsAsInt;

    //get calc for both window variations
    var calculatedSplit = totalEighths / numberOfBlinds;
    //if there is no remainder we could return here!!!!

    //round down
    calculatedSplit = Math.floor(calculatedSplit);

    //convert back to inches and eights
    //convert to eights as decimal
    var calculatedBlindSize = calculatedSplit / 8;
    var totalCalculatedBlindSizeEighths = calculatedSplit * (numberOfBlinds - 1);

    var remainingBlindSizeEighths = totalEighths - totalCalculatedBlindSizeEighths;

    var remainingBlindSize = remainingBlindSizeEighths / 8;

    var calculatedBlindInches = Math.floor(calculatedBlindSize);
    var calculatedBlindEighths = (calculatedBlindSize - calculatedBlindInches) * 8;
    var remainingBlindInches = Math.floor(remainingBlindSize);
    var remainingBlindEighths = (remainingBlindSize - remainingBlindInches) * 8;

    return {
        leftrightBlindInches: calculatedBlindInches,
        leftrightBlindEighths: calculatedBlindEighths,
        remainingBlindInches: remainingBlindInches,
        remainingBlindEighths: remainingBlindEighths
    };
}
