/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


;(function($){
    $.fn.ajaxCart = function(options){

        this.options = options;
         
        this.products = new Array();
        this.shippingMethod = false;
        this.cartLoader = false;
        this.rangeSteps = false;
        that = this; 
        
		 
    
        
        this.loadCart = function() {
			
            var ajaxUrl = that.options.loadCardBaseUrl;

            if ($.cookie(that.options.cookieName4Shipping)) {
                //$('#shippingSelector').val($.cookie(that.options.cookieName4Shipping));
                that.shippingMethod = $.cookie(that.options.cookieName4Shipping);
            }
            
            //edit sh
            //if($('#checkoutTabs').length>0 && that.getTotalAmountPonchos()<5) {
			//	redirect = true;
			//}
			//if (redirect) {
            //    location.href='/online-shop-bestellen.html';
            //}

            if (that.getTotalAmount()) {

                $('#cartHasContent').removeClass('hidden');
                $('#buttonCheckout').show();
                if ($('#lowAmountMessage').length>0) {
                    $('#lowAmountMessage').detach();
                }
                for (c=0; c<that.products.length; c++) {
                    ajaxUrl += '&' + that.options.prefix + '[products][' + that.products[c].id + ']=' + that.products[c].amount;
                }

                $.ajax({url: ajaxUrl, dataType: 'html', cache:false, context:that,
                    beforeSend: function(jqXHR, settings) {
                        /*
                        now = new Date();
                        alert(Date.parse(now));
                        */
                        if (that.cartLoader) {
                            that.cartLoader.abort();
                        }
                        that.cartLoader = jqXHR;
                    },
                    success: function(data, textStatus, XMLHttpRequest) {
                        that.cartLoader = false;
                        /*
                         alert(data);
                        alert($(data).children().length);
                        
                        $(data).find('div').each(function(index,item) {
                            if ($(item).attr('id')) {
                                alert($(item).attr('id'));
                            }
                        });
                        */

                        $('#'+that.options.cartId).html($(data).find('#'+that.options.cartResponseId).html());
                        //alert($('#'+that.options.cartId).html());
                        if ($(data).find('.tooMuch').length>0) {
                            $('#buttonCheckout').hide();
                        }

                        $(data).find('#'+that.options.cartResponseId +' .product').each(function(index,item) {
                            var idParts = $(item).attr('id').split('-');
                            var title = $(item).find('.title').html();
                            var price = $(item).find('.price').html();
                            var categoryId = $(item).find('.category').html();
                            that.updateProduct(idParts[1], {title:title, price:price, categoryId:categoryId});
                           

                        });
                        $('#'+that.options.cartId +' .product').each(function(index,item) {
                            var idParts = $(item).attr('id').split('-');
                            $(item).find('.deleteProduct').bind('click', {productId: idParts[1]}, function(event) {
                                $('#product-'+idParts[1]).val('');
                                that.deleteProduct(event.data.productId);
                                that.saveCookie();
                                that.loadCart();
                                
                                if ($('#tabLinkConfirm').length>0 && $('#checkoutTabs').tabs('option', 'selected')==3) {
                                    $('#tabLinkBilling').click();
                                    $('#tabLinkConfirm').click();
                                }

                            });
                        });


                        $(data).find('#priceResult .price4Product').each(function(index,item) {
                            var priceId = $(item).attr('id');
                            $('#'+priceId).html($(item).html());
                        });

                        $(data).find('#priceGroups .priceGroup').each(function(index,item) {
                            if ($(item).attr('id')=='priceGroup-1') {
                                that.groupAmount = $(item).find('.amount').html();
                                var rangeIndex = 0;
                                if (that.rangeSteps) {
                                    for (c=0; c < that.rangeSteps.length; c++) {

                                        if (parseInt(that.groupAmount) >= parseInt(that.rangeSteps[c])) {
                                            rangeIndex = c;
                                        }
                                    }
                                    if (that.rangeSlider) {
                                        that.rangeSlider.slider('value', rangeIndex);
                                    }

                                    if (that.options.nextPriceGroupId) {
                                        if (rangeIndex+1 < that.rangeSteps.length) {
                                            that.nextPriceGroupValue = parseInt(that.rangeSteps[rangeIndex+1]) - parseInt(that.groupAmount);
                                            $('#'+that.options.nextPriceGroupId).html('Noch '+that.nextPriceGroupValue+' zur n&auml;chsten Preisstaffel.');
                                        }
                                    }
                                }

                            }
                        });

                        that.subtotal = parseFloat($('#floatvalSubtotal').html());

                        // shipping

                        $('#shippingSelector').val(that.shippingMethod);

                        selectedShippingValue = $('#shippingSelector').val();
                        selectedShipping = false;
                        $('#shippingSelector option').each(function (index,item) {
                            if ($(item).attr('value')==selectedShippingValue) {
                                selectedShipping = $(item).attr('class');
                            }
                        });
                        if (!selectedShipping) {
                            selectedShipping = $(data).find('#shippingSelector option').first().attr('class');
                            $('#shippingSelector option').first().attr('selected','selected');
                        }

                        var shippingPriceElements = selectedShipping.split('-');
                        that.setShippingPrice(shippingPriceElements[1]);
                        that.loadTotals(that.subtotal, shippingPriceElements[1]);

                        $('#shippingSelector').bind('change', function(event) {
                            that.shippingMethod = $('#shippingSelector option:selected').attr('value');
                            var shippingPriceElements = $('#shippingSelector option:selected').attr('class').split('-');
                            that.setShippingPrice(shippingPriceElements[1]);
                            that.loadTotals(that.subtotal, shippingPriceElements[1]);
                            that.saveCookie();

                            if ($('#shippingSelectorInCheckout-'+that.shippingMethod).length>0) {
                                $('#shippingSelectorInCheckout-'+that.shippingMethod).attr('checked','checked');
                            }

                            if ($('#tabLinkConfirm').length>0 && $('#checkoutTabs').tabs('option', 'selected')==3) {
                                $('#tabLinkBilling').click();
                                $('#tabLinkConfirm').click();
                            }
                        });
                        
                        //edit sh    
			//alert(that.getTotalAmountPonchos());   
                        if (that.getTotalAmountPonchos()>=1 && that.getTotalAmountPonchos()<5) {
                            that.showLowAmountMesage();
                        }
                }});
                //that.showCart();   
            }
            else {
                that.showCart();
                that.showEmptyCartMesage();
                
                $('#category-1 .price').html('ab &euro; 0,25');
                $('#category-2 .price').html('ab &euro; 0,36');
                $('#category-3 .price').html('ab &euro; 0,70');
                
                //that.hideCart();
            } 
            
			
            that.saveCookie();
            
        };

        this.showCart = function() {
            $('#cart').show();
            $('#cart').prev().show();
            //$('#nextPriceGroup').show();
            $('#nextPriceGroup').hide();
        };



        this.hideCart = function() {
            $('#cart').hide();
            $('#cart').prev().hide();
            $('#nextPriceGroup').hide();
        };

        this.showEmptyCartMesage = function() {
            var emptyCartMessage = '<h5>Ihr Warenkorb ist leer.</h5>';
            if ($('.'+that.options.amountInputClass).length>0) {
                emptyCartMessage += '<div class="info">Sie k&ouml;nnen Produkte in den Warenkorb legen durch Eingabe der Menge in den St&uuml;ckzahlfelder links.</div>'
            }

            $('#'+that.options.cartId).html(emptyCartMessage);
        };

        this.showLowAmountMesage = function() {
            $('#buttonCheckout').hide();
            var lowAmountMessage = '<h5 id="lowAmountMessage">Die Mindestbestellmenge betr&auml;gt 5 St&uuml;ck. (Regenponchos)</h5>';


            $('#'+that.options.cartId).append(lowAmountMessage);
        };

        this.setShippingPrice = function(price) {
            $('.shipping .shippingtotal .value').html('&euro; '+this.number_format(parseFloat(price), 2, ',', '.'));
        };

        this.loadTotals = function(subtotal, shipping) {
            var subtotalInclShipping = parseFloat(subtotal) + parseFloat(shipping);
            var taxValue  = subtotalInclShipping * 0.19;
            $('.tax .value').html('&euro; '+this.number_format(taxValue, 2, ',', '.'));
            var grandtotal = subtotalInclShipping + taxValue;
            $('.grandtotal .value').html('&euro; '+this.number_format(grandtotal, 2, ',', '.'));

        };


        this.number_format = function(number, decimals, dec_point, thousands_sep) {

            number = (number+'').replace(',', '').replace(' ', '');
            var n = !isFinite(+number) ? 0 : +number,
                prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
                sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
                s = '',
                toFixedFix = function (n, prec) {
                    var k = Math.pow(10, prec);
                    return '' + Math.round(n * k) / k;};
            // Fix for IE parseFloat(0.55).toFixed(0) = 0;
            s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
            if (s[0].length > 3) {
                s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);}
            if ((s[1] || '').length < prec) {
                s[1] = s[1] || '';
                s[1] += new Array(prec - s[1].length + 1).join('0');
            }return s.join(dec);
        };

        this.getTotalAmount = function() {
            amount = 0;
            for (c=0; c<that.products.length; c++) {

                amount += parseInt(that.products[c].amount);
                
                
            }
            return amount;
        }
        this.getTotalAmountPonchos = function() {
            amount = 0;
            for (c=0; c<that.products.length; c++) {
                if (that.products[c].categoryId<=3) {
                    amount += parseInt(that.products[c].amount);
                }
            }
            return amount;
        }
        this.isInCart = function(productId) {
            for (c=0; c<that.products.length; c++) {
                if (that.products[c].id==productId) {
                    return true;
                }
            }
            return false;
        };

        this.addProduct = function(data) {
            
            if (that.isInCart(data.id)) {
                that.updateProduct(data.id, data);
            }
            else {
                that.products.push(data);
            }
        };

        this.updateProduct = function(productId, data) {
            for (c=0; c<that.products.length; c++) {
                if (that.products[c].id==productId) {
                    if (data.amount) {
                        that.products[c].amount = data.amount;
                    }
                    if (data.title) {
                        that.products[c].title = data.title;
                    }
                    if (data.price) {
                        that.products[c].price = data.price;
                    }
                    if (data.categoryId) {
                        that.products[c].categoryId = data.categoryId;
                    }                    
                }
            }
        };

        this.deleteProduct = function(productId) {
            redirect = false;
            
            if (that.products.length==1 && $('#checkoutTabs').length>0) {
                if (confirm('Wenn Sie den Warenkorb w'+String.fromCharCode(228)+'hrend des Bestellprozesses leeren, wird der aktuell Bestellprozess abgebrochen. M'+String.fromCharCode(246)+'chten Sie fortfahren?')) {
                    redirect = true;
                }
                else {
                    return false;
                }
            }
            var copyArray = new Array();
            for (c=0; c<that.products.length; c++) {
                if (that.products[c].id!=productId) {
                    copyArray.push(that.products[c]);
                }
            }
            that.products = copyArray;
            
            if ($('#cartProduct-'+productId).length > 0) {
                $('#cartProduct-'+productId).detach();
                $('#product-'+productId+'-1').removeAttr('value');
                //alert('test');
            }
                     
          	if ($('#checkoutTabs').length>0) {     
				//alert('test');  
			}

            if (redirect) {
                location.href='/online-shop-bestellen.html';
            }
						
        }

        this.emptyCart = function() {
            that.products = new Array();
            that.loadCart();
        }

        this.saveCookie = function() {
            var cookieValue = '';
            for (c=0; c<that.products.length; c++) {
                cookieValue += (cookieValue?';':'') + that.products[c].id + '=' + that.products[c].amount + '=' + that.products[c].categoryId;
            }
            $.cookie(that.options.cookieName, cookieValue);

            cookieValue = that.shippingMethod;
            if (cookieValue) {
                $.cookie(that.options.cookieName4Shipping, cookieValue);
            }
            
        }

        this.bindAmountInputs = function() {
            $('.'+that.options.amountInputClass).each(function (index,item) {
                /*
                $(item).bind('keydown', {item:item}, function(event) {
                    $(event.data.item).val(parseInt($(event.data.item).val()));
                    if (isNaN($(event.data.item).val())) {
                        $(event.data.item).val(0);
                        return false;
                    }
                });
                */
                $(item).bind('keyup', {item:item}, function(event) {

                    $(event.data.item).val(parseInt($(event.data.item).val()));
                    if (isNaN($(event.data.item).val())) {
                        $(event.data.item).val(0);
                    }

                    var amountValue = $(event.data.item).val();
                    var idParts = $(event.data.item).attr('id').split('-');
                    var productId = idParts[1];
                    var categoryId = idParts[2];


                    if (amountValue>0) {
                        that.addProduct({
                            id: productId,
                            categoryId: categoryId,
                            amount: amountValue
                        })
                    }
                    else {
                        that.deleteProduct(productId);
                        $(event.data.item).val('');
                    }



                    that.loadCart();

                    if ($('#confirmCart').length>0) {
                        $('#tabLinkBilling').click();
                        $('#tabLinkConfirm').click();
                        
                    }

                });

                $(item).tooltip({
                        tipClass: "tooltip_holder",
                        tip: "#tooltip_holder_warenkorb",
                        effect: 'autoHide',
                        //layout: '<div><div class="tooltip_arrow"><div class="tooltip_arrow_inner"></div></div></div>',
                        //position: "top center",
                        offset: [ 0, 0],
                        delay: '0',
                        predelay: '100'
                        ,onHide: function() {
                      //  $(".tooltip_holder").remove();
                        //this.getTip().remove();
                        //toolTipper();
                       // this.fadeOut("slow");

                        },
                        events: {
                       // def: "mouseenter,mouseleave click"
                            input:   "keyup,blur"
                        }
                 });

                 
            });
        }

        this.bindAmountInputs();
        //$('.'+that.options.amountInputClass).keyup();
        $('.'+that.options.amountInputClass).blur();

        that.rangeSlider = new Array();
        $('.configurator').each(function(cIndex,configurator) {
            ajaxUrl = that.options.loadPriceGroupsBaseUrl;
            if ($(configurator).hasClass('special')) {
                ajaxUrl += '&tx_ddcontactform_pi1[type]=special';
            }
            $.ajax({url: ajaxUrl, async: false, success: function(data, textStatus, XMLHttpRequest){
                $(configurator).find('#'+that.options.rangeSliderBoardId).empty();
                that.rangeSteps = new Array();
                $(data).find('#priceGroupResult .priceGroup').each(function(index,item) {
                    that.rangeSteps.push($(item).find('.amount').html());
                    $(item).appendTo($(configurator).find('#'+that.options.rangeSliderBoardId));
                });

                if ($('#'+that.options.rangeSliderId).length>0) {
                    that.rangeSlider[cIndex] = $(configurator).find('#'+that.options.rangeSliderId).slider({
                        min: 0,
                        max: that.rangeSteps.length-1,
                        range: "min",
                        value: 0,
                        change: function( event, ui ) {
                            $(configurator).find('#'+that.options.rangeSliderBoardId+' .active').removeClass('active');
                            $(configurator).find('#'+that.options.rangeSliderBoardId+' .highlight').removeClass('highlight');
                            $(configurator).find('#'+that.options.rangeSliderBoardId+' .priceGroup').slice(ui.value,ui.value+1).addClass('active');
                            if (ui.value>0) {
                                $(configurator).find('#'+that.options.rangeSliderBoardId+' .priceGroup').slice(ui.value-1,ui.value).addClass('highlight');
                            }
                            $(configurator).find('#'+that.options.rangeSliderBoardId+' .priceGroup').slice(ui.value+1,ui.value+2).addClass('highlight');
                         }
                    });

                    $(configurator).find('#'+that.options.rangeSliderBoardId+' .priceGroup .amountSelector').each(function(index,item) {
                        $(item).bind('click', {index:index, cIndex:cIndex}, function(event) {
                            that.rangeSlider[event.data.cIndex].slider('value', event.data.index);
                        });
                    });

                    that.rangeSlider[cIndex].slider('value', 0);
                }




            }});
        });


        if ($.cookie(that.options.cookieName) && $('#'+that.options.cartId).length>0) {
            var regexpResult = $.cookie(that.options.cookieName).match(/[0-9]+=[0-9]+/g);
            if (regexpResult) {
                that.emptyCart();
                for (var i = 0; i < regexpResult.length; ++i) {
                    var values = regexpResult[i].split('=');
                    that.addProduct({
                        id: values[0],
                        amount: values[1],
                        categoryId: values[2]
                    });
                    $('#product-'+values[0]).val(values[1]);
                }
            }
            that.loadCart();
            that.showCart();
        }
        else {
            that.showEmptyCartMesage();
            //that.hideCart();
        }

        return this;

    };
})(jQuery);






;(function($){
    $.fn.ajaxCheckout = function(options){


        this.options = options;
        this.shippingAddress = false;
        this.billingAddress = false;
        this.addressId = false;
        this.shippingMethod = false;
        this.paymentMethod = false;
        this.forgottenPasswordFormContent = false;
        thatCheckout = this;
        this.products = new Array();

        $('#'+this.options.tabsId).tabs();
        
        this.emptyCart = function() {
            thatCheckout.products = new Array();
        };

        this.isInCart = function(productId) {
            for (c=0; c<thatCheckout.products.length; c++) {
                if (thatCheckout.products[c].id==productId) {
                    return true;
                }
            }
            return false;
        };

        this.addProduct = function(data) {
            if (thatCheckout.isInCart(data.id)) {
                thatCheckout.updateProduct(data.id, data);
            }
            else {
                thatCheckout.products.push(data);
            }
        };

        this.updateProduct = function(productId, data) {
            for (c=0; c<thatCheckout.products.length; c++) {
                if (thatCheckout.products[c].id==productId) {
                    if (data.amount) {
                        thatCheckout.products[c].amount = data.amount;
                    }
                    if (data.title) {
                        thatCheckout.products[c].title = data.title;
                    }
                    if (data.price) {
                        thatCheckout.products[c].price = data.price;
                    }
                }
            }
        };

        this.loadProducts = function() {
            if ($.cookie(thatCheckout.options.cookieName)) {
                var regexpResult = $.cookie(thatCheckout.options.cookieName).match(/[0-9]+=[0-9]+/g);
                if (regexpResult) {
                    thatCheckout.emptyCart();
                    for (var i = 0; i < regexpResult.length; ++i) {
                        var values = regexpResult[i].split('=');
                        thatCheckout.addProduct({
                            id: values[0],
                            amount: values[1],
                            categoryId: values[2]
                        });
                    }
                }
            }
        };

        this.loadProducts();

        $('#'+this.options.tabsId).tabs( "option", "disabled", [1, 2, 3] );

        $('#buttonNextData').click(function () {
            $('#'+thatCheckout.options.tabsId).tabs( "option", "disabled", [2, 3] );
            $('#tabLinkShipping').click();
        });

        this.loadPageShipping = function() {
            var ajaxUrl = '/index.php?id=84&no_cache=1';
            for (c=0; c<thatCheckout.products.length; c++) {
                ajaxUrl += '&' + thatCheckout.options.prefix + '[products][' + thatCheckout.products[c].id + ']=' + thatCheckout.products[c].amount;
            }
            $.ajax({url: ajaxUrl, cache:false, success: function(data, textStatus, XMLHttpRequest){
                $('#checkoutTab-shipping').empty();    
                $('#checkoutTab-shipping').html(data);
                $('#buttonNextShipping').click(function() {
                    thatCheckout.shippingAddress = $("input[name='shippingAddress']:checked").val();
                    $('#'+thatCheckout.options.tabsId).tabs( "option", "disabled", [3] );
                    $('#tabLinkBilling').click();
                });
                if (!thatCheckout.shippingAddress) {
                    thatCheckout.shippingAddress = $("input[name='shippingAddress']:checked").val();
                }
                else {
                    $("input[name='shippingAddress']").each(function (index,item) {
                        if ($(item).val()==thatCheckout.shippingAddress) {
                            $(item).attr('checked','checked');
                        }
                    });
                }
                


                $('input[name="shippingMethod"]').each(function (index,item) {
                    if ($('#shippingSelector').val()==$(item).val()) {
                        $(item).attr('checked','checked');
                        thatCheckout.shippingMethod = $(item).val();
                    }
                    $(item).bind('click', {item:item}, function(event) {
                        thatCheckout.shippingMethod = $(event.data.item).val();
                        $('#shippingSelector').val($(event.data.item).val());
                        $('#shippingSelector').change();
                    });
                });                
                
                $("input[name='shippingAddress']").each(function (index,item) {
                    $(item).bind('click', {item:item}, function(event) {
                        idElements = $(event.data.item).attr('id').split('_');
                        addressCountryCode = idElements[2];
                        firstFound = false;
                        $("#shippingMethodSelection input[name='shippingMethod']").each(function (mIndex, method) {
                            idElements = $(method).attr('id').split('-');
                            methodCountryCode = idElements[2];
                            if (addressCountryCode == methodCountryCode) {
                                $(method).parent().show();
                                if (!firstFound) {
                                    firstFound = true;
                                    $(method).click();
                                }
                            }
                            else {
                                $(method).parent().hide();                                
                            }
                        });
                        
                        $('#shippingSelector option').each(function(oIndex, option) {
                            idElements = $(option).attr('value').split('-');
                            optionCountryCode = idElements[1];
                            if (addressCountryCode == optionCountryCode) {
                                $(option).show();
                                if (!firstFound) {
                                    firstFound = true;
                                }
                            }
                            else {
                                $(option).hide();                                
                            }                            
                        });
                        
                    });
                });
                $("input[name='shippingAddress']:checked").click();


                $('#dialogNewAddressShipping').dialog({
                    drag: function(event, ui) {
                        $(this).parent().css('opacity', .9)
                    },
                    dragStop: function(event, ui) {
                        $(this).parent().css('opacity', 1)
                    },
                    title: 'Neue Addresse...',
                    autoOpen: false,
                    width: 800,
                    open: function() {

                        $.ajax({url: '/index.php?id=88&no_cache=1', success: function(formData){
                            $('#dialogNewAddressShipping').html(formData);
                            $('#addressesForm-country').change(function() {
                                if ($('#addressesForm-country').val()=='AT') {
                                    $('#addressVatId').show();
                                }
                                else {
                                    $('#addressVatId').hide();
                                }
                            });
                            $('#addressesForm-country').change();
                        }});
     
                    },
                    close: function(event) {
                        event.preventDefault();
                        
                        //$('#dialogNewAddressShipping').dialog('close');
                    },
                    buttons: {

                        "Addresse speichern": function() {
                            $('#addressesForm').validator({
                                lang: 'de',
                                position: 'bottom center'
                            });

                            if ($("#addressesForm").data("validator").checkValidity()) {
                                ajaxUrl = '/index.php?id=89&no_cache=1&'+decodeURIComponent($('#addressesForm').serialize());
                                $.ajax({url: ajaxUrl, dataType: 'html', success: function(data, textStatus, XMLHttpRequest){
                                    $("#addressesForm").data("validator").destroy();
                                    $('#dialogNewAddressShipping').dialog("close");
                                    thatCheckout.loadPageShipping();
                                }, error: function(jqXHR, textStatus, errorThrown) {
                                    alert(errorThrown);
                                }});
                            }
                            else {
                                $("#addressesForm").data("validator").invalidate({
                                        '[required]' 	: 'Bitte f&uuml;llen Sie dieses Feld aus'
                                });
                            }
                            
                        }
                    }
                });

                $('#buttonNewAddressShipping').click(function() {
                    $('#dialogNewAddressShipping').dialog("open");
                });


                $('#dialogEditAddressShipping').dialog({
                    drag: function(event, ui) {
                        $(this).parent().css('opacity', .9)
                    },
                    dragStop: function(event, ui) {
                        $(this).parent().css('opacity', 1)
                    },
                    title: 'Addresse bearbeiten...',
                    autoOpen: false,
                    width: 800,
                    open: function() {
                        ajaxUrl = '/index.php?id=93&no_cache=1';
                        ajaxUrl += '&' + thatCheckout.options.prefix + '[uid]='+thatCheckout.addressId;

                        $.ajax({url: ajaxUrl, cache: false, success: function(formData){
                            $('#dialogEditAddressShipping').html(formData);
                            $('#addressesForm-country').change(function() {
                                if ($('#addressesForm-country').val()=='AT') {
                                    $('#addressVatId').show();
                                }
                                else {
                                    $('#addressVatId').hide();
                                }
                            });
                            $('#addressesForm-country').change();
                        }});
                    },
                    close: function(event) {
                        event.preventDefault();
                        
                        //$('#dialogEditAddressShipping').dialog('close');
                    },
                    buttons: {

                        "Addresse speichern": function() {
                            $('#addressesForm').validator({
                                lang: 'de',
                                position: 'bottom center'
                            });
                            if ($("#addressesForm").data("validator").checkValidity()) {
                                ajaxUrl = '/index.php?id=94&no_cache=1&'+decodeURIComponent($('#addressesForm').serialize());
                                $.ajax({url: ajaxUrl, dataType: 'html', success: function(data, textStatus, XMLHttpRequest){
                                    $('#dialogEditAddressShipping').dialog("close");
                                    $("#addressesForm").data("validator").destroy();
                                    thatCheckout.loadPageShipping();
                                }});
                            }
                            else {
                                $("#addressesForm").data("validator").invalidate({
                                        '[required]' 	: 'Bitte f&uuml;llen Sie dieses Feld aus'
                                });
                            }
                            
                        }
                    }
                });

                $('.editShippingAddressButton').each(function (index,item) {
                    $(item).click(function() {
                        var idParts = $(item).attr('id').split('-');
                        thatCheckout.addressId = idParts[1];
                        $('#dialogEditAddressShipping').dialog("open");
                    })
                });


                $('#dialogDeleteAddressShipping').dialog({
                    drag: function(event, ui) {
                        $(this).parent().css('opacity', .9)
                    },
                    dragStop: function(event, ui) {
                        $(this).parent().css('opacity', 1)
                    },
                    title: 'Addresse l&ouml;schen...',
                    autoOpen: false,
                    width: 400,
                    open: function() {
                        ajaxUrl = '/index.php?id=95&no_cache=1';
                        ajaxUrl += '&' + thatCheckout.options.prefix + '[uid]='+thatCheckout.addressId;
                        $('#dialogDeleteAddressShipping').load(ajaxUrl);
                    },
                    buttons: {
                        "Nein, Abbrechen": function() {
                            $('#dialogDeleteAddressShipping').dialog("close");
                        },
                        "Ja, Adresse entfernen": function() {
                            ajaxUrl = '/index.php?id=96&no_cache=1&'+$('#addressesDeleteForm').serialize();
                            $.ajax({url: ajaxUrl, dataType: 'html', success: function(data, textStatus, XMLHttpRequest){
                                $('#dialogDeleteAddressShipping').dialog("close");
                                thatCheckout.loadPageShipping();
                            }});
                        }
                    }
                });
                $('.deleteShippingAddressButton').each(function (index,item) {
                    $(item).click(function() {
                        var idParts = $(item).attr('id').split('-');
                        thatCheckout.addressId = idParts[1];
                        $('#dialogDeleteAddressShipping').dialog("open");
                    })
                });


            }});
        };

        this.loadPageBilling = function() {
            var ajaxUrl = '/index.php?id=85&no_cache=1';
            $.ajax({url: ajaxUrl, cache:false, success: function(data, textStatus, XMLHttpRequest){

                $('#checkoutTab-billing').html(data);
                $('#buttonPrevBilling').click(function() {
                    $('#tabLinkShipping').click();
                });
                $('#buttonNextBilling').click(function() {
                    thatCheckout.billingAddress = $("input[name='billingAddress']:checked").val();
                    $('#'+thatCheckout.options.tabsId).tabs( "option", "disabled", [] );
                    $('#tabLinkConfirm').click();
                });

                if (!thatCheckout.billingAddress) {
                    thatCheckout.billingAddress = $("input[name='billingAddress']:checked").val();
                }
                else {
                    $("input[name='billingAddress']").each(function (index,item) {
                        if ($(item).val()==thatCheckout.billingAddress) {
                            $(item).attr('checked','checked');
                        }
                    });
                }

                $('#dialogNewAddressBilling').dialog({
                    drag: function(event, ui) {
                        $(this).parent().css('opacity', .9)
                    },
                    dragStop: function(event, ui) {
                        $(this).parent().css('opacity', 1)
                    },
                    title: 'Neue Addresse...',
                    autoOpen: false,
                    width: 800,
                    open: function() {
                        $.ajax({url: '/index.php?id=88&no_cache=1', success: function(formData){
                            $('#dialogNewAddressBilling').html(formData);
                            $('#addressesForm-country').change(function() {
                                if ($('#addressesForm-country').val()=='AT') {
                                    $('#addressVatId').show();
                                }
                                else {
                                    $('#addressVatId').hide();
                                }
                            });
                            $('#addressesForm-country').change();
                        }});
                    },
                    close: function(event) {
                        event.preventDefault();
                        
                        //$('#dialogNewAddressBilling').dialog('close');
                    },
                    buttons: {

                        "Addresse speichern": function() {
                            $('#addressesForm').validator({
                                lang: 'de',
                                position: 'bottom center'
                            });

                            if ($("#addressesForm").data("validator").checkValidity()) {
                                ajaxUrl = '/index.php?id=89&no_cache=1&'+decodeURIComponent($('#addressesForm').serialize());
                                $.ajax({url: ajaxUrl, dataType: 'html', success: function(data, textStatus, XMLHttpRequest){
                                    $("#addressesForm").data("validator").destroy();
                                    $('#dialogNewAddressBilling').dialog("close");
                                    thatCheckout.loadPageBilling();
                                }});
                            }
                            else {
                                $("#addressesForm").data("validator").invalidate({
                                        '[required]' 	: 'Bitte f&uuml;llen Sie dieses Feld aus'
                                });
                            }

                        }
                    }
                });

                $('#buttonNewAddressBilling').click(function() {
                    $('#dialogNewAddressBilling').dialog("open");
                });


                $('#dialogEditAddressBilling').dialog({
                    drag: function(event, ui) {
                        $(this).parent().css('opacity', .9)
                    },
                    dragStop: function(event, ui) {
                        $(this).parent().css('opacity', 1)
                    },
                    title: 'Addresse bearbeiten...',
                    autoOpen: false,
                    width: 800,
                    open: function() {

                        ajaxUrl = '/index.php?id=93&no_cache=1';
                        ajaxUrl += '&' + thatCheckout.options.prefix + '[uid]='+thatCheckout.addressId;

                        $.ajax({url: ajaxUrl, cache:false, success: function(formData){
                            $('#dialogEditAddressBilling').html(formData);
                            $('#addressesForm-country').change(function() {
                                if ($('#addressesForm-country').val()=='AT') {
                                    $('#addressVatId').show();
                                }
                                else {
                                    $('#addressVatId').hide();
                                }
                            });
                            $('#addressesForm-country').change();
                        }});
                    },
                    close: function(event) {
                        event.preventDefault();
                        
                        //$('#dialogEditAddressBilling').dialog('close');
                    },
                    buttons: {

                        "Addresse speichern": function() {
                            $('#addressesForm').validator({
                                lang: 'de',
                                position: 'bottom center'
                            });
                            if ($("#addressesForm").data("validator").checkValidity()) {
                                ajaxUrl = '/index.php?id=94&no_cache=1&'+decodeURIComponent($('#addressesForm').serialize());
                                $.ajax({url: ajaxUrl, dataType: 'html', success: function(data, textStatus, XMLHttpRequest){
                                    $("#addressesForm").data("validator").destroy();
                                    $('#dialogEditAddressBilling').dialog("close");
                                    thatCheckout.loadPageBilling();
                                }});
                            }
                            else {
                                $("#addressesForm").data("validator").invalidate({
                                        '[required]' 	: 'Bitte f&uuml;llen Sie dieses Feld aus'
                                });
                            }

                        }
                    }
                });

                $('.editBillingAddressButton').each(function (index,item) {
                    $(item).click(function() {
                        var idParts = $(item).attr('id').split('-');
                        thatCheckout.addressId = idParts[1];
                        $('#dialogEditAddressBilling').dialog("open");
                    })
                });


                $('#dialogDeleteAddressBilling').dialog({
                    drag: function(event, ui) {
                        $(this).parent().css('opacity', .9)
                    },
                    dragStop: function(event, ui) {
                        $(this).parent().css('opacity', 1)
                    },
                    title: 'Addresse l&ouml;schen...',
                    autoOpen: false,
                    width: 400,
                    open: function() {
                        ajaxUrl = '/index.php?id=95&no_cache=1';
                        ajaxUrl += '&' + thatCheckout.options.prefix + '[uid]='+thatCheckout.addressId;
                        $('#dialogDeleteAddressBilling').load(ajaxUrl);
                    },
                    buttons: {
                        "Nein, Abbrechen": function() {
                            $('#dialogDeleteAddressBilling').dialog("close");
                        },
                        "Ja, Addresse entfernen": function() {
                            ajaxUrl = '/index.php?id=96&no_cache=1&'+$('#addressesDeleteForm').serialize();
                            $.ajax({url: ajaxUrl, dataType: 'html', success: function(data, textStatus, XMLHttpRequest){
                                $('#dialogDeleteAddressBilling').dialog("close");
                                thatCheckout.loadPageBilling();
                            }});
                        }
                    }
                });
                $('.deleteBillingAddressButton').each(function (index,item) {
                    $(item).click(function() {
                        var idParts = $(item).attr('id').split('-');
                        thatCheckout.addressId = idParts[1];
                        $('#dialogDeleteAddressBilling').dialog("open");
                    })
                });

                $('input[name="paymentMethod"]').each(function (index,item) {
                    if (!thatCheckout.paymentMethod && !index) {
                        $(item).attr('checked','checked');
                        thatCheckout.paymentMethod = $(item).val();
                    }
                    if (thatCheckout.paymentMethod && $(item).val()==thatCheckout.paymentMethod) {
                        $(item).attr('checked','checked');
                        thatCheckout.paymentMethod = $(item).val();
                    }
                    $(item).click(function() {
                        thatCheckout.paymentMethod = $(item).val();
                    });
                });

            }});
        };


        this.loadPageConfirm = function() {
            thatCheckout.loadProducts();
            var ajaxUrl = '/index.php?id=86&no_cache=1';
            ajaxUrl += '&' + thatCheckout.options.prefix + '[shippingAddress]='+thatCheckout.shippingAddress;
            ajaxUrl += '&' + thatCheckout.options.prefix + '[billingAddress]='+thatCheckout.billingAddress;

            ajaxUrl += '&' + thatCheckout.options.prefix + '[paymentMethod]='+thatCheckout.paymentMethod;

            for (c=0; c<thatCheckout.products.length; c++) {
                ajaxUrl += '&' + thatCheckout.options.prefix + '[products][' + thatCheckout.products[c].id + ']=' + thatCheckout.products[c].amount;
            }

            if ($.cookie(thatCheckout.options.cookieName4Shipping)) {
                ajaxUrl += '&' + thatCheckout.options.prefix + '[shippingMethod]='+$.cookie(thatCheckout.options.cookieName4Shipping);
            }
            else {
                ajaxUrl += '&' + thatCheckout.options.prefix + '[shippingMethod]='+thatCheckout.shippingMethod;
            }

            $.ajax({url: ajaxUrl, cache:false, success: function(data, textStatus, XMLHttpRequest){

                


                $('#checkoutTab-confirm').html(data);
                $.ajax({url: '/index.php?id=145', success: function(htmlData){
                        $('#conditionsContent').html($(htmlData).find('#main .page').html());
                }});
                
                that.bindAmountInputs();
                $('#buttonPrevConfirm').click(function() {
                    $('#tabLinkBilling').click();
                });
                $('#buttonOrder').click(function() {
                    if ($('#conditionsConfirm').attr('checked')) {
                        ajaxUrl = '/index.php?id=87&no_cache=1';
                        ajaxUrl += '&' + thatCheckout.options.prefix + '[shippingAddress]='+thatCheckout.shippingAddress;
                        ajaxUrl += '&' + thatCheckout.options.prefix + '[billingAddress]='+thatCheckout.billingAddress;
                        ajaxUrl += '&' + thatCheckout.options.prefix + '[paymentMethod]='+thatCheckout.paymentMethod;

                        for (c=0; c<thatCheckout.products.length; c++) {
                            ajaxUrl += '&' + thatCheckout.options.prefix + '[products][' + thatCheckout.products[c].id + ']=' + thatCheckout.products[c].amount;
                        }

                        if ($.cookie(thatCheckout.options.cookieName4Shipping)) {
                            ajaxUrl += '&' + thatCheckout.options.prefix + '[shippingMethod]='+$.cookie(thatCheckout.options.cookieName4Shipping);
                        }
                        else {
                            ajaxUrl += '&' + thatCheckout.options.prefix + '[shippingMethod]='+thatCheckout.shippingMethod;
                        }
                        $.ajax({url: ajaxUrl, success: function(data, textStatus, XMLHttpRequest){
                            $('#checkoutTabs').html(data);
                            that.emptyCart();
                        }});
                    }
                    else {
                        alert('Um die Bestellung absenden zu k'+String.fromCharCode(246)+'nnen, m'+String.fromCharCode(252)+'ssen Sie unsere Allgemeine Gesch'+String.fromCharCode(228)+'ftsbedingungen akzeptieren.');
                    }
                    
                });

                $('.switchToShipping').click(function () {
                    $('#tabLinkShipping').click();
                });
                $('.switchToPayment').click(function () {
                    $('#tabLinkBilling').click();
                });
            }});
        };

        $('#'+this.options.tabsId).bind( "tabsshow", function(event, ui) {

            switch($('#checkoutTabs').tabs('option', 'selected')) {
                case 1:
                    thatCheckout.loadPageShipping();
                    break;

                case 2:
                    thatCheckout.loadPageBilling();
                    break;
                case 3:
                    thatCheckout.loadPageConfirm();
                    break;
            }

        });

        performLogin = function() {
            var ajaxUrl = '/index.php?id=83&no_cache=1&'+$('#loginForm').serialize();
            //alert(ajaxUrl);
            $.ajax({url: ajaxUrl, success: function(data, textStatus, XMLHttpRequest){

                //alert(data);
                /*
                alert($(data).first().html());
                var message = $(data).find('message').text();
                alert($(data).find('message').length);
                alert(message);
                    */
                if (data.search('success')>0) {
                    $('#dialogLogin').dialog("close");
                    $('#'+thatCheckout.options.tabsId).tabs( "option", "disabled", [2, 3] );
                    //$('#tabLinkShipping').click();
                    $('#loginSuccessUser').val($('#loginBoxUser').val());
                    $('#loginSuccessPass').val($('#loginBoxPass').val());
                    $('#loginSuccessForm').submit();
                    //location.href='/index.php?id=80&no_cache=1';
                }
                else {
                    if (!$('#dialogLoginMessage').length>0) {
                        $('#dialogLogin').prepend('<div id="dialogLoginMessage" class="warning">Email-Adresse oder Passwort sind nicht korrekt. Bitte &uuml;berpr&uuml;fen Sie die Eingaben.</div>');
                    }
                }
            }});
        };

        $('#dialogLogin').dialog({
            drag: function(event, ui) {
                $(this).parent().css('opacity', .9)
            },
            dragStop: function(event, ui) {
                $(this).parent().css('opacity', 1)
            },
            title: 'Login',
            autoOpen: false,
            width: 400,
            open: function() {
                $('#loginForm input').keyup(function (event) {
                    if (event.keyCode == '13') {
                        performLogin();
                    }
                });
            },
            buttons: {

                "Login": function() {

                    performLogin();

                }
            }
        });

        $('#buttonDataLogin').click(function() {
            $('#dialogLogin').dialog("open");
        });


        $('#dialogForgottenPassword').dialog({
            drag: function(event, ui) {
                $(this).parent().css('opacity', .9)
            },
            dragStop: function(event, ui) {
                $(this).parent().css('opacity', 1)
            },
            title: 'Passwort vergessen',
            autoOpen: false,
            width: 400,
            open: function() {
                if (thatCheckout.forgottenPasswordFormContent) {
                    $('#dialogForgottenPassword').html(thatCheckout.forgottenPasswordFormContent);
                    $('#dialogForgottenPassword').dialog( "option" , 'buttons' , {

                        "Passwort zusenden": function() {
                            var ajaxUrl = '/index.php?'+$('#forgottenPasswordForm').serialize();

                            //alert(ajaxUrl);
                            $.ajax({url: ajaxUrl, success: function(data, textStatus, XMLHttpRequest){
                                $('#dialogForgottenPassword').html(data);
                                $('#dialogForgottenPassword').dialog( "option" , 'buttons' ,
                                    {
                                        "OK": function() {
                                            $('#dialogForgottenPassword').dialog('close');
                                        }
                                    }
                                );
                            }});
                        }
                    });
                }
                else {
                    thatCheckout.forgottenPasswordFormContent = $('#dialogForgottenPassword').html();
                }
            },
            buttons: {

                "Passwort zusenden": function() {
                    var ajaxUrl = '/index.php?'+$('#forgottenPasswordForm').serialize();

                    //alert(ajaxUrl);
                    $.ajax({url: ajaxUrl, success: function(data, textStatus, XMLHttpRequest){
                        $('#dialogForgottenPassword').html(data);
                        $('#dialogForgottenPassword').dialog( "option" , 'buttons' ,
                            {
                                "OK": function() {
                                    $('#dialogForgottenPassword').dialog('close');
                                }
                            }
                        );
                    }});
                }
            }
        });

        $('#forgotPasswortLink').click(function(event) {
            event.preventDefault();
            $('#dialogLogin').dialog("close");
            $('#dialogForgottenPassword').dialog("open");
        });

        
        $('#dialogRegister').dialog({
            drag: function(event, ui) {
                $(this).parent().css('opacity', .9)
            },
            dragStop: function(event, ui) {
                $(this).parent().css('opacity', 1)
            },
            title: 'Registrieren',
            autoOpen: false,
            width: 800,
            open: function() {
                ajaxUrl = '/index.php?id=134&no_cache=1';

                $.ajax({url: ajaxUrl, success: function(data, textStatus, XMLHttpRequest){
                    $('#dialogRegister').html(data);
                    $('#registerCountry').change(function() {
                        if ($('#registerCountry').val()=='AT') {
                            $('#addressVatId').show();
                        }
                        else {
                            $('#addressVatId').hide();
                        }
                    });
                    $('#registerCountry').change();
                }});

            },
            buttons: {

                "Registrieren": function() {

                    var ajaxUrl = '/index.php?id=136&no_cache=1&'+decodeURIComponent($('#registerForm').serialize());
                    $.ajax({url: ajaxUrl, type: 'POST', success: function(data, textStatus, XMLHttpRequest){
                        $('#registerFormMessage').removeClass('warning');
                        responseCode = parseInt($(data).find('code').html());
                        if (responseCode) {
                            $('#registerFormMessage').addClass('warning');
                            $('#registerFormMessage').html($(data).find('message').html());
                        }
                        else {

                            var loginUrl = '/index.php?id=83&no_cache=1';
                            loginUrl += '&user='+$('#registerEmail').val();
                            loginUrl += '&pass='+$('#registerPassword').val();
                            loginUrl += '&logintype=login&pid=71&redirect_url=&tx_felogin_pi1[noredirect]=1';
                            $.ajax({url: loginUrl, type: 'POST', success: function(loginData, loginTextStatus, loginXMLHttpRequest){

                                $('#dialogRegister').dialog("close");
                                $('#'+thatCheckout.options.tabsId).tabs( "option", "disabled", [2, 3] );
                                $('#tabLinkShipping').click();

                            }});

                        }
                        
                        
                    }});

                }
            }
        });

        $('#buttonDataRegister').click(function() {
            $('#dialogRegister').dialog("open");
        });

        $('#dialogGuest').dialog({
            drag: function(event, ui) {
                $(this).parent().css('opacity', .9)
            },
            dragStop: function(event, ui) {
                $(this).parent().css('opacity', 1)
            },
            title: 'Als Einmalkunde bestellen...',
            autoOpen: false,
            width: 800,
            open: function() {

                ajaxUrl = '/index.php?id=135&no_cache=1';

                $.ajax({url: ajaxUrl, success: function(data, textStatus, XMLHttpRequest){
                    $('#dialogGuest').html(data);
                    $('#guestCountry').change(function() {
                        if ($('#guestCountry').val()=='AT') {
                            $('#addressVatId').show();
                        }
                        else {
                            $('#addressVatId').hide();
                        }
                    });
                    $('#guestCountry').change();
                }});
            },
            buttons: {

                "Weiter": function() {

                    var ajaxUrl = '/index.php?id=137&no_cache=1&'+decodeURIComponent($('#guestForm').serialize());
                    $.ajax({url: ajaxUrl, type: 'POST', success: function(data, textStatus, XMLHttpRequest){
                        $('#guestFormMessage').removeClass('warning');
                        responseCode = parseInt($(data).find('code').html());
                        if (responseCode) {
                            $('#guestFormMessage').addClass('warning');
                            $('#guestFormMessage').html($(data).find('message').html());
                        }
                        else {

                            var loginUrl = '/index.php?id=146&no_cache=1';
                            loginUrl += '&user='+$('#guestEmail').val();
                            loginUrl += '&pass=guest';
                            loginUrl += '&logintype=login&pid=147&redirect_url=&tx_felogin_pi1[noredirect]=1';
                            $.ajax({url: loginUrl, type: 'POST', success: function(loginData, loginTextStatus, loginXMLHttpRequest){

                                $('#dialogGuest').dialog("close");
                                $('#'+thatCheckout.options.tabsId).tabs( "option", "disabled", [0, 2, 3] );
                                $('#tabLinkShipping').click();
                                
                                

                            }});

                        }


                    }});

                }
            }
        });

        $('#buttonDataGuest').click(function() {
            $('#dialogGuest').dialog("open");
        });


        return this;
    };
})(jQuery);



;(function($){
    $.fn.ajaxSampleOrder = function(options){


        this.options = options;
        this.selected = new Array();
        this.maxProducts = 3;

        var thatSampleOrder = this;

        $('#'+this.options.productsId).find('.'+this.options.productsClass).bind('click', function() {
            var idElements = $(this).attr('id').split('-');
            var productId = idElements[1];
            var productTitle = $(this).parents('.product').find('h4').text();
            var productImage = $(this).parents('.product').find('img').clone();

            if (thatSampleOrder.selected.length >= thatSampleOrder.maxProducts || $(this).find('.soldOut').length>0) {
                
            }
            else {
                
                var cIndex = thatSampleOrder.selected.length;
                var selectedContainer = $('#'+thatSampleOrder.options.selectedId).find('.'+thatSampleOrder.options.selectedClass).slice(cIndex,cIndex+1);
                $(selectedContainer).empty();
                $(selectedContainer).append(productImage);
                $(selectedContainer).append('<h4>'+productTitle+'</h4>');
                $(selectedContainer).append('<input type="hidden" name="tx_ddcontactform_pi1[products][]" value="'+productId+'" />');
                $(selectedContainer).parent().find('a.deleteProduct').show();

                $('#'+thatSampleOrder.options.selectedId).find('a.deleteProduct').each(function(index, item) {
                    $(item).click(function(event) {
                        var selectedContainer = $('#'+thatSampleOrder.options.selectedId).find('.'+thatSampleOrder.options.selectedClass).slice(index,index+1);
                        $(selectedContainer).empty();
                        $(selectedContainer).append('noch kein Muster ausgew&auml;hlt');
                        $(item).hide();
                        var copyArray = new Array();
                        for (c=0; c<thatSampleOrder.selected.length; c++) {
                            if (c!=index) {
                                copyArray.push(thatSampleOrder.selected[c]);
                            }
                        }
                        thatSampleOrder.selected = copyArray;
                    });
                });

                thatSampleOrder.selected.push(productId);
            }
        });

        $('#shipping_adress input').add('#shipping_adress select').each(function (index,item) {
            $(item).bind('keyup change', function(event) {
                if ($('#billing_is_shipping').attr('checked')) {
                    $('#billing_adress input').add('#billing_adress select').slice(index,index+1).val($(item).val());
                    $('#billing_adress input').add('#billing_adress select').change();
                }
            });
        });
        $('#billing_is_shipping').click(function(event) {
            if ($('#billing_is_shipping').attr('checked')) {
                $('#billing_adress').addClass('disabled');
                $('#billing_adress input').add('#billing_adress select').each(function(index,item) {
                    $(item).val($('#shipping_adress input').add('#shipping_adress select').slice(index,index+1).val());
                });
            }
            else {
                $('#billing_adress').removeClass('disabled');
            }
        });

        $('#shipping_country').change(function() {
            if ($(this).val()=='2') {
                $('#shipping_adress .atu-number').show();
            }
            else {
                $('#shipping_adress .atu-number').hide();
            }
        })
        $('#shipping_country').change();

        $('#billing_country').change(function() {
            if ($(this).val()=='2') {
                $('#billing_adress .atu-number').show();
            }
            else {
                $('#billing_adress .atu-number').hide();
            }
        })
        $('#billing_country').change();

        return this;
    };
})(jQuery);

function buildLoginBox()
{
	var loginBoxUser = $("#boxLogin input#user");
	var loginBoxUserDefault = "Benutzername";

	loginBoxUser.attr("value", "Benutzername");

	loginBoxUser.focus(function(){
		if($(this).attr("value") == loginBoxUserDefault)
                $(this).attr("value", "");
	});
	loginBoxUser.blur(function(){
		if($(this).attr("value") == "")
                $(this).attr("value", loginBoxUserDefault);
	});



      

        var loginBoxPass = $("#boxLogin input#pass");
        var loginBoxPassDefault = "Passwort";

        loginBoxPass.attr("value", "Passwort");
        loginBoxPass.focus(function(){

		if($(this).attr("value") == loginBoxPassDefault);
                $(this).attr("value", "");
	});


        loginBoxPass.blur(function(){
		if($(this).attr("value") == "")
                $(this).attr("value", loginBoxPassDefault);

	});

/*
        loginBoxPass.focus(function(){
            
		if($(this).attr("value") == loginBoxPassDefault) 
                $(this)[0]. setAttribute('type','password');
                $(this).attr("value", "");
	});


        loginBoxPass.blur(function(){
		if($(this).attr("value") == ""){
                $(this).attr("value", loginBoxPassDefault);
                $(this)[0]. setAttribute('type','text');
                }else{
                    $(this)[0]. setAttribute('type','password');
                }
	});
*/

}

function buildAmountBox()
{
	var amountBox = $(".amountInput");
	var amountBoxDefault = "hier Stk.";

	amountBox.attr("value", "hier Stk.");

	amountBox.focus(function(){
		if($(this).attr("value") == amountBoxDefault)
                $(this).attr("value", "");
            $(this).css({
                color: '#4D9FBF'
            });
	});
	amountBox.blur(function(){
		if($(this).attr("value") == ""){
                $(this).attr("value", amountBoxDefault);
                $(this).css({
                color: '#cccccc'
                });
        }
	});





}
