function ProductForm()

{
	var me = this;
	// Variables to control the number of eyeglasses
	// we allow a user to try
	me.length = 2;
	me.selectedLength = 0;
	me.last = new Array();
	me.last[0] = null;
	me.last[1] = null;

	// Initialize all the event handlers.
	this.initialize = function() 
	{
		$(".prodSquare").each(function()
		{
//			$(this).removeClass('prodSquare');
			$(this).addClass('prodInactive');
		});

		$(".prodInactive").click(this.setActiveProduct);

		// Check all previously checked boxes.
		$(":checked").removeAttr("checked");
		$("#TrialSelectProductForm").submit(this.onFormSubmit);
		$("select", ".prodOptions").click(function(e)
		{
			e.stopPropagation();
		});
	}

	this.toInput = function(node)
	{
		var id = "#" + node.attr("title") + "Select";
		var elem = $(id);

		return elem;
	}

	// Select a product.  Check the matching input.
	this.setActiveProduct = function()
	{
		var curNode = $(this);
		if (curNode.hasClass('prodActive'))
		{
			curNode.removeClass('prodActive');
			curNode.addClass('prodInactive');
			me.selectedLength--;
		}
		else 
		{
			if (me.selectedLength >= 3)
			{
				alert("You may select only 2 items.  Please unselect an item (by clicking on it again) before adding a new item.");
			}
			else {
				curNode.addClass('prodActive');
				curNode.removeClass('prodInactive');
				me.selectedLength++;
			}
		}
/*
		if (me.last[0] != null)
		{
			me.last[0].removeClass('prodActive');
			me.last[0].addClass('productSquare');
		}

		curNode.removeClass('productSquare');
		curNode.addClass('prodActive');

		// Set up the stack of products.
		var i = 0;
		for (i; i < me.last.length - 1; i++)
		{
			me.last[i] = me.last[i+1];
		}
		me.last[i] = curNode;
*/
	}

	// map input to form
	this.onFormSubmit = function()
	{
		// Check off Products
		$(".prodActive").each(function()
		{
			var formID = "#" + this.title + "Select";
			$(formID).attr("checked", "checked");
		});

		// Select Options
		$(".colorBlockActive").each(function()
		{
			var selectID = "#" + $(this).closest('.prodSquare').attr('title') + "OptionsColor";
			$(selectID).val(this.title);
		});

		// Select all Other options
		$("select", $(".prodOptions")).each(function()
		{
			var selectID = "#" + $(this).closest('.prodSquare').attr('title') + "Options" + this.id;
			$(selectID).val($(this).val());
		});
	}
}

