$(function() {
    if('#menu'){
        $('#menu').tabs();
    }
});

function showContainer(thisid){
    if($('#'+thisid)){
        $('#'+thisid).toggle();
    }
}


$(function(){

    if($('.add-button')){
        $('.add-button').bind('click',function(){
            var add_button_id 		= this.id;
            var where_is_offer=add_button_id.indexOf('-');
            
            if(where_is_offer==-1){
                var product_id 		= add_button_id;

                if($('#product-option-' + product_id).val()){
                    var option_id_price = $('#product-option-' + product_id).val();
                }else{
                    var option_id_price = 0 ;
                }

                var postdata = $('#form-' + product_id).serialize();
                $.ajax({
                    url: "menu/addItem",
                    type: "post",
                    data:{
                        postdata:postdata
                    },
                    beforeSend: function(){
                        $('*').removeClass('redflaged');
                        $('.choose-selection').remove();
                        
                        required = $('.sub_menu-' + product_id + '-required');
                        var error  = false;
                        required.each(function() {
                            var $thisInput = $(this);
                            $thisInput.removeClass('redflaged');
                            if($thisInput.val() == 0 ){
                                // $thisInput.parent().addClass('redflaged');
                                var parent_parent = $thisInput.parent().parent();
                                $("<tr class='choose-selection'><td colspan='4'>Please choose your selections below</td></tr>").insertBefore(parent_parent).slideDown('slow');
                                error = true;
                            }
                        })
                       
                        
                        var no_of_options = $('form :input').filter('.no_of_options-' + product_id);
                        no_of_options.each(function(){
                            var $thisInput = $(this);

                            /* no_of_options-1-4 */
                            var name = $thisInput.attr('name');
                            var no_of_options_required = $thisInput.val();
                            var product_menu_header = parseInt(name.replace('no_of_options-' + product_id + '-',''));

                            /* get the maximum number of options allowed */
                            var max_no_of_options_required = $('#max_num_of_options-' + product_id + '-' + product_menu_header).val();

                            /* get the number of checkd boxes */
                            var no_of_options = $('form :input:checked').filter('.options_' + product_id + '_'+ product_menu_header + '_conditional').size();
                            if((no_of_options_required !=0) && (no_of_options < no_of_options_required )){
                                var this_extra_toppings =  $('#extra-toppings-' + product_id + '-' + product_menu_header);
                                this_extra_toppings.show().find('div.topping-list-wrapper').addClass('redflaged');
                                $("<tr class='choose-selection'><td colspan='4'>Please choose "+ no_of_options_required +" option(s) from below</td></tr>").insertBefore(this_extra_toppings).slideDown('slow');

                                error = true;
                            }
                            if((max_no_of_options_required !=0) && (no_of_options > max_no_of_options_required) ){
                                var this_extra_toppings =  $('#extra-toppings-' + product_id + '-' + product_menu_header);
                                this_extra_toppings.show().find('div.topping-list-wrapper').addClass('redflaged');
                                $("<tr class='choose-selection'><td colspan='4'>Maximum of "+ max_no_of_options_required +" option(s) is allowed with this item</td></tr>").insertBefore(this_extra_toppings).slideDown('slow');

                                error = true;
                            }
                        });

                        if(error){
                            return false;
                        }
                        var scroll = $('#' + product_id).offset().top;
                        $("#loading").css('top',scroll - 185);
                        $("#loading").show("fast");
                    }, //show loading just when link is clicked
                    complete: function(data){
                        $("#loading").hide("fast");
                        
                    }, //stop showing loading when the process is complete
                    success: function(data){ //so, if data is retrieved, store it in html
                        //alert(('#basket-items').html(data.table));
                        $('*').removeClass('redflaged');
                        $('.extra-toppings').fadeOut('slow');
                        $("#menu form input:checked").each(function(){
                            var  $this = $(this);
                            $this.attr('checked',false);
                        });
                        
                        $('#basket-items').html(data.table);
                        $('#total-items').text(data.total_items);
                        $('#total_to_pay').text(data.total_to_pay);
                        $('#deliveryVal').text(data.delivery);
                        $('#discountVal').text(data.discount);
                    },
                    dataType:'json'
                }); //close $.ajax(

            } else {
                //alert(add_button_id);
                var split_add_button_id = add_button_id.split("-");
                var offer_id_jay  = split_add_button_id[1];

                if($('#buy-product-option-' + offer_id_jay).val()){
                    var buy_option_id_price = $('#buy-product-option-' + offer_id_jay).val();
                }else{
                    var buy_option_id_price = 0 ;
                }

                var is_dash_buy_option_id_price=buy_option_id_price.indexOf('-');

                if(is_dash_buy_option_id_price==-1){

                } else {
                    var split_buy_option_id_price = buy_option_id_price.split("-");
                    var product_id  = split_buy_option_id_price[2];
                    var option_id_price = split_buy_option_id_price[0]+'-'+split_buy_option_id_price[1] ;
                }

                var postdata = $('#form-offer-' + offer_id_jay).serialize();
				
                $.ajax({
                    url: "menu/addItem",
                    type: "post",
                    data:{
                        postdata:postdata
                    },
                    beforeSend: function(){
                        var scroll = $('#offer-' + offer_id_jay).offset().top;
                        $("#loading").css('top',scroll - 185);
                        $("#loading").show("fast");
               
                    }, //show loading just when link is clicked
                    complete: function(data){
                        $("#loading").hide("fast");
                    }, //stop showing loading when the process is complete
                    success: function(data){ //so, if data is retrieved, store it in html
                        $('#basket-items').html(data.table);
                        $('#total-items').text(data.total_items);
                        $('#total_to_pay').text(data.total_to_pay);
                        $('#deliveryVal').text(data.delivery);
                    },
                    dataType:'json'
                }); //close $.ajax(
            }
        });

    }
});


/* REMOVE ITM fROM BASKET */

function removeItem(id){
    var product_id_option_id_hash 		= id;
    var postcodeVal = $('#postcode').val();

    $.ajax({
        url :"menu/removeItem",
        type:"post",
        data:{
            product_id_option_id_hash:product_id_option_id_hash,
            postcode:postcodeVal
        },

        success:function(data){
            $('#basket-items').html(data.table);
            $('#total-items').text(data.total_items);
            $('#total_to_pay').text(data.total_to_pay);
            $('#deliveryVal').text(data.delivery);
            $('#discountVal').text(data.discount);
        },
        dataType:'json'

    });
};

/* UPDATE QUANTITY */

function updateItemsQty(){

    var input_qty = $('.input-qty').serialize();
    var postcodeVal = $('#postcode').val();
    var spend_over_offer_option = '0';

    if($('#spend_over_offer_option').val()){
        spend_over_offer_option = $('#spend_over_offer_option').val();
    }

    $.post(
        'menu/updateqty',
        {
            'input_qty':input_qty,
            postcode:postcodeVal,
            spend_over_offer_option:spend_over_offer_option
        },
        function(data){
            $('#basket-items').html(data.table);
            $('#total-items').text(data.total_items);
            $('#total_to_pay').text(data.total_to_pay);
            $('#deliveryVal').text(data.delivery);
            $('#discountVal').text(data.discount);
        },
        'json'
        );
};

/* DELIVERY TYPE - COLLECTION - DELIVERY */
$(function(){
    var deliveryType = $("input[name=delivery_type]:radio");
    setDeliveryBox();
    deliveryType.click(function(){
        updateDeliveryType();
    });
});

/* This when we click the delivery type radio buttons in -- checkout page -- I should have used one function */

function updateDeliveryType(){
    var postcodeVal = $('#postcode').text();
    $.ajax({
        url: "menu/updateDelivery",
        data:{
            deliveryType:$("input[@name='delivery_type']:checked").val(),
            postcode:postcodeVal
        },
        type: "post",
        beforeSend: function(){
            $("#loading").css('top',10);
            $("#loading").show("fast");
        }, //show loading just when link is clicked
        complete: function(data){
            $("#loading").hide("fast");
        }, //stop showing loading when the process is complete
        success: function(data){ //so, if data is retrieved, store it in html
            if(data.deliveryStatus == 'ok'){
                $('#deliveryVal').text(data.delivery);
                $('#totalVal').text(data.total_to_pay);/* I should have used class to update both ones - the top and the bottom total*/
                $('#total_to_pay').text(data.total_to_pay);
                $('#discountVal').text(data.discount);
            }
        },
        dataType:'json'
    });

    setDeliveryBox();
}

function setDeliveryBox(){
    var deliveryType = $("input[name=delivery_type]:radio");
    var paymentMethodValue = $('#payment-method').val();

    if($("input[@name='delivery_type']:checked").val() == 0){
        /* collection */
        $('#fieldset-deliveryaddress').hide();
        $('#fieldset-copydeliveryaddress').hide();
    }else{
        if(paymentMethodValue == 'online'){
            $('#fieldset-copydeliveryaddress').show();
        }
        $('#fieldset-deliveryaddress').show();
    }
}

$(function(){
    $('#checkout-form-cash').submit(function() {
        if($('#terms').is(':checked')){
            return true;
        }else{
            Boxy.alert('<p>You have to agree on our terms and condition to be able to proceed in your order!</p>',null,{
                modal:false,
                fixed:false,
                center:true
            });
            return false;
        }
    });

    $('#checkout-form-online').submit(function() {
        if($('#terms').is(':checked')){
            return true;
        }else{
            Boxy.alert('<p>You have to agree on our terms and condition to be able to proceed in your order!</p>',null,{
                modal:false,
                fixed:false,
                center:true
            });
            return false;
        }
    });
});

/* TRIGGER BY CHANGING RADIO BUTTON IN MENU PAGE */
$(function(){
    if($("input[@name='delivery']")){
        $("input[@name='delivery']").click(function(){
            updateDeliveryCharge();
        }
        );
    }
});
/* TRIGGER BY CLICKING GO BUTTON IN MENU PAGE */
function updateDeliveryCharge(){
    var postcodeVal = $('#postcode').val();
    $.ajax({
        url: "menu/updateDelivery",
        data:{
            deliveryType:$("input[@name='delivery']:checked").val(),
            postcode:postcodeVal
        },
        type: "post",
        beforeSend: function(){
            $('#postcodeLockup').hide().text('');
            var re = /[a-z]{1,2}\d{1,2}[a-z]{0,1}\s{0,1}\d{1}[a-z]{2}/i;
            if(postcodeVal == ''){
                Boxy.alert('<p>Please enter your postcode to be able to proceed in your order!</p>',null,{
                    modal:false
                });
                return false;
            }else if(!re.test(postcodeVal)){
                Boxy.alert('<p>Please enter a valid  postcode!</p>',null,{
                    modal:false
                });
                return false;
            }

            $("#loading").css('top',10);
            $("#loading").show("fast");

        }, //show loading just when link is clicked
        complete: function(data){
            $("#loading").hide("fast");
        }, //stop showing loading when the process is complete
        success: function(data){ //so, if data is retrieved, store it in html
            //alert(data.deliveryStatus);
            if(data.deliveryStatus == 'ok'){
                $('#deliveryVal').text(data.delivery);
                $('#totalVal').text(data.total_to_pay);/* I should have used class to update both ones - the top and the bottom total*/
                $('#total_to_pay').text(data.total_to_pay);
                $('#less-than-min-order').text(data.isLessThanMinOrder);
                $('#discountVal').text(data.discount);
            }else{
                /* opps the postcode is not in our database */
                $('#postcodeLockup').show().text('Sorry, but this restaurant does not deliver to your postcode');
            }
        },
        dataType:'json'
    });
}

function updateSurCharge(pm){
    var paymentMethod = pm; 
    $.ajax({
        url: "menu/updateSurcharge",
        data:{
            paymentMethod:paymentMethod
        },
        type: "post",
        beforeSend: function(){		
            if(paymentMethod == ''){
                Boxy.alert('<p>Please choose your payment method!</p>',null,{
                    modal:false
                });
                return false;
            }
            $("#loading").css('top',10);
            $("#loading").show("fast");
			
        }, //show loading just when link is clicked
        complete: function(data){
            $("#loading").hide("fast");
        }, //stop showing loading when the process is complete
        success: function(data){ //so, if data is retrieved, store it in html
            //alert("Hello 6 -- " +data);
            //alert(data.surchargeStatus);
            //alert(data.surcharge);
            //alert(data.total_to_pay);
            if(data.surchargeStatus == 'ok'){
                $('#surchargeVal').text(data.surcharge);
                $('#totalVal').text(data.total_to_pay);/* I should have used class to update both ones - the top and the bottom total*/
                $('#total_to_pay').text(data.total_to_pay);
            } else {
                $('#surchargeVal').text(data.surcharge);
                $('#totalVal').text(data.total_to_pay);/* I should have used class to update both ones - the top and the bottom total*/
                $('#total_to_pay').text(data.total_to_pay);
            }
        },
        dataType:'json'
    });
}

/* CHECKOUT */

function showCheckoutBox(){
    /* some settings to new customer section */
    $('#new-customer-div').show();
    $('#new-customer-details').hide();
    var postcodVal = $('#postcode').val();


    if($('#spend_over_offer_option').val()){
        spend_over_offer_option = $('#spend_over_offer_option').val();
        $.ajax({
            url: "menu/update_spend_over_offer",
            data: {
                spend_over_offer_option:spend_over_offer_option
            }
        });
    }

    $.ajax({
        url:"menu/hasidentity",
        type:"post",
        success:function(data){
            if(data.hasidentity == 'yes'){
                postcodVal = postcodVal.replace(' ','');
                location.href = location.href + 'checkout/pc/' + postcodVal;
            }else{
                var re = /[a-z]{1,2}\d{1,2}[a-z]{0,1}\s{0,1}\d{1}[a-z]{2}/i;
                var total_to_pay = parseInt($('#total_to_pay').text());
                if(total_to_pay != 0 ){
                    var postcode = $('#postcode').val();
                    $('#customer-postcode').val(postcode);
                    var delivery = $("input[@name='delivery']:checked").val();

                    if(postcode == ''){
                        Boxy.alert('<p>Please enter your postcode!</p>',null,{
                            modal:false
                        });
                        return false;
                    }else if(!re.test(postcode)){
                        Boxy.alert('<p>Please enter a valid  postcode!</p>',null,{
                            modal:false
                        });
                        return false;
                    }

                    dial = $('#dialog').css('display');
                    if(!(dialogbox = 	Boxy.get('#dialog'))){
                        var dialogbox = new Boxy('#dialog',{
                            title:'Continue to Checkout',
                            show:false,
                            modal:true,
                            fixed:false,
                            center:true
                        });

                        /* dialogbox.moveTo(450,90); */
                        dialogbox.center(0);
                    }
                    dialogbox.toggle();
                }else{
                    Boxy.alert('<p>Your basket is still empty, please add some items before continue to checkout!</p>',null,{
                        modal:false
                    });
                    return false;
                }
            }
        },
        beforeSend:function(){
            var minOrde = $('#min-prder').text();
            var isLessThanMinOrder = $("#less-than-min-order").text();
            var deliveryVal = parseInt($("#deliveryVal").text());
            var total_items = parseInt($('#total-items').text()) ;
            var orderType = $("input[@name='delivery']:checked").val();
            var re = /[a-z]{1,2}\d{1,2}[a-z]{0,1}\s{0,1}\d{1}[a-z]{2}/i;

            /*  console.log(minOrder); */
            if(total_items > 0 ){
                var postcode = $('#postcode').val();
                $('#customer-postcode').val(postcode);

                if(postcode == ''){
                    Boxy.alert('<p>Please enter your postcode to be able to proceed in your order</p>',null,{
                        modal:false
                    });
                    return false;
                }else if(!re.test(postcode)){
                    Boxy.alert('<p>Please enter a valid  postcode!</p>',null,{
                        modal:false
                    });
                    return false;
                }else{
                    var postcodeFound = $.ajax({
                        url: "menu/checkpostcode",
                        data: {
                            postcode:postcode
                        },
                        async: false
                    }).responseText;

                    if(postcodeFound == 'no'){
                        Boxy.alert('<p>Sorry, but this restaurant does not deliver to your postcode</p>',null,{
                            modal:false
                        });
                        return false;
                    }
                    updateDeliveryCharge();
                    /* check if total is less than min order if delivery was chosen */
                    if(isLessThanMinOrder == 1){
                        Boxy.alert('<p>The minimum order required is <strong>&pound;' + minOrde + '</strong>. Please add more items to your basket to be able to proceed in your order.</p>',null,{
                            modal:false
                        });
                        return false;
                    }

                }

            }else{
                Boxy.alert('<p>Your basket is still empty, please add some items before continue to checkout!</p>',null,{
                    modal:false
                });
                return false;
            }
        },
        dataType:'json'
    });
}

/* SIGNIN */

$(function(){
    $('#signin').click(function(){
        $('.error').remove();
        var postdata = $('#checkout-login-form').serialize();

        $.ajax({
            url:"menu/login",
            data:{
                postdata:postdata
            },
            type: "post",
            cache:false,
            complete: function(data){
            },
            beforeSend:function(XMLHttpRequest){

                /* clear all error messages */
                /* var paymentMethod = $('#payment'); */
                var email    = $('#login_email');
                var loginPassword = $('#login_password');

                var flag = true;
                
                /* validate email */
                if(!email.val()){
                    var errorMessage = 'Please fill your in e-mail address';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(email.parents(':first'));
                    flag = false;
                }else if( !/.+@.+\.[a-zA-Z]{2,4}$/.test(email.val())){
                    var errorMessage = 'Valid e-mail address required';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(email.parents(':first'));
                    flag = false;
                }
                /* validate password */
                if(!loginPassword.val()){
                    var errorMessage = 'Please fill in your password';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(loginPassword.parents(':first'));
                    flag = false;
                }
                if(flag){
                    $("#loading-icon").show("fast");
                }
                return flag;
            },
            complete:function(){
                $("#loading-icon").hide("fast");
            },

            success: function(data){
                $("#loading-icon").hide("fast");
                /*	$('#checkout-login-form').submit(); */
                if( data.status == 'ok' ){
                    $('#checkout-login-form').submit();
                }else{
                    var errorMessage = 'The e-mail address or password is incorrect. Please try again.';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo('#fieldset-existing-customer');
                }
            },
            dataType:'json'
        });
    });
});

$(function(){
    $('#forgot-password').click(function(e){
        $('#password-recovery-form').toggle();
    });
	
    $('#pw-recovery-submit').click(function(e){
        $('.error').remove();
        var serializedpostdata = $('#password-recovery-form').serialize();
        $.ajax({
            url:"user/passwordrecovery",
            data:{
                postdata:serializedpostdata
            },
            type:'post',
            cashe:false,
            beforeSend:function(XMLHttpRequest){
                $("#loading-icon").show("fast");
                var email = $('#pw-recovery-email');
                var flag = true;
                /* validate email */
                if(!email.val()){
                    var errorMessage = 'Please enter your e-mail address';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(email.parents(':first'));
                    flag = false;
                }else if( !/.+@.+\.[a-zA-Z]{2,4}$/.test(email.val())){
                    var errorMessage = 'Valid e-mail address required';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(email.parents(':first'));
                    flag = false;
                }
                return flag;
            },
            complete: function(data){
                $("#loading-icon").hide("fast");
            },
            success: function(data){     
                $("#loading-icon").hide("fast");
                if( data.status == 'ok' ){
                    var errorMessage = '<p><strong>We have sent you an email with instructions on how to access you account. If you still have problems accessing your account, please contact us.</strong></p>';
                    $('<div></div>').html(errorMessage).appendTo('#fieldset-pw-recovery');
                }else{
                    var errorMessage = '<p>This email address isn\'t recognised on our system, please try again.</p>';
                    $('<div></div>').addClass('error').html(errorMessage).appendTo('#fieldset-pw-recovery');
                }	
            },
            dataType:'json'	 
        });
    });
});

$(function(){
    $('#new-customer').click(function(){
        $('#new-customer-details').toggle();
        $('#new-customer-div').hide();
    });
    
    $('#new-customer-submit').click(function(){
        $('.error').remove();
        var postdata = $('#checkout-new-customer-form').serialize();

        $.ajax({
            url:"menu/newcustomer",
            data:{
                postdata:postdata
            },
            type: "post",
            cache:false,
            beforeSend:function(XMLHttpRequest){
                $("#loading-icon").show("fast");
                var first_name		=$('#first_name');
                var last_name		=$('#last_name');
                var email   		 = $('#email');
                var emailConfirm    = $('#email_confirm');
                var password 		 = $('#password');
                var passwordConfirm = $('#password_confirm');
                var flag = true;
                /* Validate first name and last name */

                if(!first_name.val()){
                    var errorMessage = 'Please enter your first name';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(first_name.parents(':first'));
                    flag = false;
                }

                if(!last_name.val()){
                    var errorMessage = 'Please enter your first name';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(last_name.parents(':first'));
                    flag = false;
                }

                /* validate email */
                if(!email.val()){
                    var errorMessage = 'Please enter your e-mail address';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(email.parents(':first'));
                    flag = false;
                }else if( !/.+@.+\.[a-zA-Z]{2,4}$/.test(email.val())){
                    var errorMessage = 'Valid e-mail address required';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(email.parents(':first'));
                    flag = false;
                }

                if(!emailConfirm.val()){
                    var errorMessage = 'Please re-enter your e-mail address';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(emailConfirm.parents(':first'));
                    flag = false;
                }else if( !/.+@.+\.[a-zA-Z]{2,4}$/.test(emailConfirm.val())){
                    var errorMessage = 'Valid e-mail address required';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(emailConfirm.parents(':first'));
                    flag = false;
                }
	
                if(email.val() && emailConfirm.val() && email.val()!=emailConfirm.val()){
                    var errorMessage = 'The email addresses you entered do not match';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(emailConfirm.parents(':first'));
                    flag = false;
                }
                /* validate password */
                if(!password.val()){
                    var errorMessage = 'Please enter your password';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(password.parents(':first'));
                    flag = false;
                }
		
                if(!passwordConfirm.val()){
                    var errorMessage = 'Please re-enter your password';
                    $('<div></div>').addClass('error').text(errorMessage).appendTo(passwordConfirm.parents(':first'));
                    flag = false;
                }
		
                if(flag){
                    $("#loading-icon").show("fast");
                }
		
                return flag;
            },
            complete: function(data){
                $("#loading-icon").hide("fast");
            },
            success: function(data){
                $("#loading-icon").hide("fast");
		
		
                /*	$('#checkout-login-form').submit(); */
                if( data.status == 'ok' ){
                    $('#checkout-new-customer-form').submit();
                }else{
                    var errorMessage = '<p>Your e-mail address is already in our database.<br/> Please try a different e-mail address or click <bold>Forgotten your password</bold> link to retrieve your password.</p>';
                    $('<div></div>').addClass('error').html(errorMessage).appendTo('#fieldset-new-customer');
                }
            },
            dataType:'json'
        });
    });
});

/* PAYMENT METHOD */

$(function(){
    var paymentMethodValue = $('#payment-method').val();
    if( paymentMethodValue == 'online'){
        $('#fieldset-billingaddress').show();
        $('#fieldset-copydeliveryaddress').show();
    }else{
        $('#fieldset-billingaddress').hide();
        $('#fieldset-copydeliveryaddress').hide();
    }

    $('#payment-method').change(function(){
        var paymentValue = $(this).val();

        if(paymentValue == 'online'){
            $('#fieldset-billingaddress').show();
            $('#fieldset-copydeliveryaddress').show();
            updateDeliveryType();
        }else{
            $('#fieldset-billingaddress').hide();
            $('#fieldset-copydeliveryaddress').hide();
            updateDeliveryType();
        }
    });
});

$(function(){
    if($('#fieldset-copydeliveryaddress')){
        $('#fieldset-copydeliveryaddress').click(function(){
            $('#billing_address_line1').val($('#delivery_address_line1').val());
            $('#billing_address_line2').val($('#delivery_address_line2').val());
            $('#billing_postcode').val($('#delivery_postcode').val());
            $('#billing_city').val($('#delivery_city').val());
        });
    }
});


/* CORRECT BASKET PLACE */
$(function(){
    if ($("#basket-wrapper")) {

        var basketWrapperOff = $("#basket-wrapper").offset();

        if(basketWrapperOff){
            $(window).scroll(function(){
                var scroll = $(this).scrollTop();
                if (scroll > basketWrapperOff.top ){

                    /* $("#basket-wrapper").css("padding-top", (scroll - basketWrapperOff.top));*/
                    $("#basket-wrapper").css("top", (scroll - basketWrapperOff.top));
                    $("#basket").hide();
                    $("#basket-delivery").hide();
                    $("#my-order-title").hide();
                    $("#my-cart-total").hide();
                } else {
                    var currenttop = $("#basket-wrapper").css("top");
                    $("#basket-wrapper").css("top", 10);
                    $("#basket").show();
                    $("#basket-delivery").show();
                    $("#my-order-title").show();
                    $("#my-cart-total").show();
                }

            });
        }

    }

});
