/*

	@Class: ProductDetailInterface 
	
	@Brief: The Product Detail Interface is used to change out any type of 
	        dynamic material in the Detail section. This includes images 
		   and any select bars. 
			
	@Notes: This class requires MooTools!
	
*/

var ProductDetailInterface = new Class({
	options: {
		AddCartButton:    Class.empty,  // Add To Cart Button
		AddCartForm:      Class.empty  // Cart Form
	}, 
	
	initialize: function(options) {
		// Start-Up Code	
		this.setOptions(options);
				
		// Find Instances
		this.AddCart   = $( this.options.AddCartButton );
		this.CartForm  = $( this.options.AddCartForm );
		
		if( this.AddCart )
			this.AddCart.addEvent( 'click', this.AddCartItem.bindWithEvent(this) );	
	},
	
	AddCartItem: function( event ) {
		if( !(/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/.test( this.CartForm.Quantity.value )) )
			alert( 'Quantity\'s must be numeric values.' );
		else if( this.CartForm.Quantity.value == 0 )
			alert( 'You must enter a quantity greater than 0 to add this item to your bag.' );
		else
			this.CartForm.submit();
		
		event.stop();
	},
		
	StripSlash: function( sMessage ) {
		return sMessage.replace( /\//g, "slash_" );	
	},
	
	Echo: function( sMessage ) {
		alert( sMessage ); 
	}

});

ProductDetailInterface.implement(new Options);

window.addEvent('load', function() {
	var DetailInterface = new ProductDetailInterface({
		AddCartButton: 'AddToCart',
          AddCartForm:   'CartForm'
	}); 							 
 });

