$(function () {    // 登出    $('a.logout').click(function () {        var messageStyle = { padding: '10px', fontSize: '9pt', width: '500px' };        var link = this;        var ajaxUrl = link.href;        var redirectionUrl = $.trim($frontendVars.baseUrl) == '' ? link.href : $frontendVars.baseUrl;        $.blockUI({            css: messageStyle,            message: '登出中...'        });        //因於https下ajax呼叫登出會使ajax錯誤,所以加入此判斷        if (location.href.search(/^https:/)!==-1) {            ajaxUrl = link.href.replace(/^http:/,'https:');            redirectionUrl = link.href;        }        $.post(            ajaxUrl,            {},            function (json) {                $.floatMessanger({                    title: '已成功登出！',                    closeButton: false,                    buttons: {                        '回首頁': function () { location.href = redirectionUrl; }                    },                    message: '親愛的 (' + json.message + ')，您已成功登出了！'                });            },            'json'        );        return false;    });    $('a.cart').click(function () {        // BlockUI 訊息樣式        var messageStyle = { padding: '10px', fontSize: '9pt', width: '500px' };        var link = this;        $.blockUI({            css: messageStyle,            message: '加入中...'        });        $.post(            //link.href,            $('form#cartForm').attr('action'),            $('form#cartForm').serializeArray(),            function (json) {                var redirectUrl = $frontendVars.baseUrl + '/cart';                if (json.isLogin) {                    if (json.error) {                        $.floatMessanger({                            title: 'Oops！',                            message: json.message,                            buttons: {                                '確認': function () { $.unblockUI(); }                            }                        });                    } else {                        if (json.redirectUrl) {                            redirectUrl = json.redirectUrl;                        }                        location.href = redirectUrl;                    }                } else {                    $.floatMessanger({                        title: 'Oops！',                        message: '您尚未登入！',                        buttons: {                            '確認': function () {                                if ($('form#cartForm input[name=sku[]][checked]').length > 0) {                                    location.replace($frontendVars.baseUrl + '/my/redirect/url/productdetail/id/' + link.rel);                                } else {                                    location.replace(link.href);                                }                            }                        }                    });                }            },            'json'        );        return false;    });    var sslControllers = ['cart', 'campaign', 'event2009ac', 'installment', 'productset'];    var sslActions = ['step2', 'step3'];    // 避免購物車相關步驟的所有對外連結變成 https    if (0 <= $.inArray($frontendVars.controllerName, sslControllers)            && 0 <= $.inArray($frontendVars.actionName, sslActions)) {        $('a').each(function () {            if (-1 === this.href.search(/\/step2/)) {                this.href = this.href.replace(/^https:/, 'http:');            }        });    }    // 點選我的購物車，即出現更新購物車    $('#showUpdateCart').click(function () {        var messageStyle = { padding: '10px', fontSize: '9pt', width: '500px' };        $.blockUI({            css: messageStyle,            message: '加入中...'        });    });    // 計算點閱數的連結    $('a.clickCountLink').click(function () {        try {            var link = String(this.href);            var queryString = link.substr(link.search(/\?/) + 1);            var realLink = link.replace('?' + queryString, '');            var qs = new QueryString(queryString);            var clickType = qs.get('clickType', null);            if (null !== clickType) {                $.post(                    $frontendVars.baseUrl + '/index/addClickCountLink',                    { 'clickType': clickType, 'clickItemId': qs.get('clickItemId') }                );            }        } catch (e) {}        // 導向未加參數之連結        if ('_blank' == $(this).attr('target')) {            window.open(realLink);        } else {            location.href = realLink;        }        return false;    });    // 不可連結的超連結    $('a.canNotBeLinked').click(function () {        return false;    });   $('#searchfield').focus(function(){        if ('請輸入商品名稱、編號或關鍵字' == $(this).val()) {            $(this).val('');        }   });   $('#searchfield').blur(function(){        if ('' == $(this).val()) {            $(this).val('請輸入商品名稱、編號或關鍵字');        }   });});