﻿
if (window.jQuery) {
    jQuery(function() {


        fixSubmits();

        if (jQuery('#CheckoutPayment div.cartTotals tr.voucher').size() > 0) {
            jQuery('#CheckoutPayment #VoucherDetails *').not("#VoucherApplied, span.title").hide();

        } else {
            jQuery("#VoucherApplied").hide();
        }

        //fix sidecart display
        jQuery('#SlideCart div.totals > span').addClass("label").wrap('<div class="row"></div>')
        jQuery('#SlideCart div.totals span.value').each(function() {
            jQuery(this).clone().appendTo(jQuery(this).closest('div.row'))
            jQuery(this).remove();
        });

    });
}



function fixSubmits() {
    //login page
    jQuery('.tblLogin input.text').live('keypress', function(e) {
        if (jQuery('input.password').val().length > 0) {
            if (e.keyCode == 13) {
                jQuery('.tblLogin input.submit').click();
                e.preventDefault();
            }
        }
    });

    jQuery('div.CartTotalsVoucher input[type=text]').live('keypress', function(e) {
        if (e.keyCode == 13) {
            jQuery('div.CartTotalsVoucher input.UpdateButton').click();
            e.preventDefault();
        }
    });

    jQuery('div.existingCustomer td.field input').live('keypress', function(e) {
        if (e.keyCode == 13) {
            jQuery('div.existingCustomer td.login input').click();
            e.preventDefault();
        }
    });
    jQuery('div.CartTotalsVoucher input[type=text]').live('keypress', function(e) {
        if (e.keyCode == 13) {
            jQuery('div.CartTotalsVoucher input.UpdateButton').click();
            e.preventDefault();
        }
    });
    //my details
    jQuery('table.RegistrationTable input[type=text]').live('keypress', function(e) {
        if (e.keyCode == 13) {
            jQuery('span.RegistrationSubmit input[type=submit]').click();
            e.preventDefault();
        }
    });
    //my details address details
    jQuery('#secondTab div.userDetails input[type=text], #secondTab div.billing input[type=text]').live('keypress', function(e) {
        if (e.keyCode == 13) {
            jQuery('#CheckoutAddressDetails #tblActions input').click();
            e.preventDefault();
        }
    });

    //address details in checkout

    jQuery('div.CheckoutOuterWrapper div.userDetails input[type=text], div.CheckoutOuterWrapper div.billing input[type=text]').live('keypress', function(e) {
        if (e.keyCode == 13) {
            jQuery('#CheckoutAddressDetails #tblActions input').click();
            e.preventDefault();
        }
    });
}