/**
 * Products JS
 * Dependencies: Mootools v1.1+
 * @author Kevin Dew <kev@dewsolutions.co.uk>
 * @copyright Copyright Kevin Dew, 2007
 */

window.addEvent('domready', function()
{
        var validator = new Validation(validationRules, validationTop, 'error', 'val_form');
        var scroll = new Fx.Scroll(window, {wait: false, duration: 250, transition: Fx.Transitions.Quad.easeInOut});
        
        
        $('val_form').addEvent('submit', function(e)
        {
                validator.clearErrors();
                validator.test();
                
                var anyZero = false;
                        
                $each($ES('select[id^=product_options]'), function(select)
                {
                        if(select.getValue() == 0)
                        {
                                anyZero = true;
                                select.addClass('error');
                        }
                });
                
                if(anyZero)
                        validator.addError('', 'Please select all options');
                                
                if(validator.hasErrors())
                {
                        validator.makeErrorList();
                        scroll.toElement('val_form_errors');
                        new Event(e).stop();
                }
        });
        
        if($('email_address'))
        {
                $('email_address').addEvent('focus', function()
                {
                        if($(this).getValue() == 'email address')
                                $(this).setProperty('value', '');
                });
                
        }
        
});