var ProductDetailsForm = Class.create();	
ProductDetailsForm.prototype = {
	initialize: function() {
		var me = this;
		document.getElementsByClassName('attributeDropdown').each(function(box) {
			box.onchange = me.updatePriceDisplay.bindAsEventListener(me);	
		});
		
	},
	
	validate: function() {
		if(!$("quantity").value.match("^[1-9]\\d{0,3}$"))
		{
			this.showError("Please enter a valid quantity.");
			return false;
		}

		return true;
	},
	
	showError: function(message) {
		$("productDetailError").innerHTML = message;
		$("productDetailError").style.display = "inline";
	},
	
	submit: function(submitAction, url) {
		$("destURL").value = url;		
		$("productDisplayForm").action = submitAction;
		$("productDisplayForm").submit();
	},
	
	updatePriceDisplay: function() {
		var url = itemPriceUrl+'&productId='+$('productId').value;
				
		for (i=1;i<=2;i++)
		{
			var name = $('attrName_'+i);
			var value = $('attrValue_'+i);
			if (name == null || value == null)
			{
				break;
			}
			
			url = url + '&attributeName'+i+'='+encodeURIComponent(name.value)
				+'&attributeValue'+i+'='+encodeURIComponent(value.value)
				+'&attributeValueOperator'+i+'=EQUAL'
				+'&attributeValueType'+i+'=STRING';
		}

		new Ajax.Updater( 'itemPriceDiv', url, { method: 'post' } );		
	}
	
}