﻿

var GUI = (function() {
    function initGUI() {
        $('form[id^=AddToCartForm]').each(function() {
            var form = this;
            var subButton = $('.AddToCartButton', form);
            var quantity = $('small, #Quantity', form).insertBefore(subButton);

            //            $('FullProduct', 'form[id^=AddToCartForm]').contents().each(function() {
            //                if (this.nodeType == 3 && $.trim(this.nodeValue) == '&nbsp;') $(this).remove();
            //            });

            var noI = $('small');
            noI.attr('style', 'font-size:12px;');

            var items = $('input[type=text],select', form);
            items.each(function() {
                var item = $(this);
                item.after('<br/>');
                if (item.is('select')) {

                    if (item.is('#Color')) {

                        item.attr('size', '1');
                    }
                    else {
                        item.attr('size', '1');
                    }
                }
                if (item.is('#Quantity')) {

                    var sel = $('<select>').attr('id', 'QuantityDummy').change(function() { item.val($(this).val()) });
                    //var sel = $('<select>').attr('id', 'QuantityDummy').change(item.attr('onchange'));

                    for (var i = 1; i <= 9; i++) {
                        sel.append($('<option>').val(i).text(i));
                    }
                    item.before(sel);
                    item.hide();

                }


            });


        });

    }

    return {
        init: initGUI
    }
})();
jQuery( function() {
    GUI.init();
});
