﻿/*
*
*  用于生成像百度一样的搜索建议下拉框
*
*  ！！！ 注意 ！！！  如果使用此功能，请在模板页引用[prototype.js]之前添加如下语句：
*
*  <script type="text/javascript" src="{#EasyStoreRivetTag*网站虚拟路径#}scripts/jquery-1.3.2.min.js"></script>
*  <script type="text/javascript"> jQuery.noConflict(); var absoluteUrl = "{#EasyStoreRivetTag*网站虚拟路径#}"; </script>
*
*/

//缓存搜索关键字
var wd = '';
//匹配字符串中开头和结尾的空格的正则表达式
var reExtraSpace = /^\s*/;

//记录当前按下的键是否是“↑”“↓”,用于搜索提示项的键盘操作
var up_or_down = false;


var timer1000 = null;
var timer1500 = null;
var eventName = (jQuery.browser.opera ? "keypress" : "keyup") + ".autocomplete";
var searchText = "请输入您想找的产品名称";
var searchTextFormat = "请输入您想找的{0}名称";
var sharedTextFormat = "五金天下网上商城找商品非常快，快来看看吧。\n{0}";

//当前页面的URL
var winHref = window.location.href.toLowerCase();

//
var advVersion = true;

//与根目录的相对路径, 用于确定Ajax请求页的URL
var absoluteUrl = '/';

function initSearchSuggest() {
    //关键字
    jQuery('#q_prokey').blur().css({ color: '#8d8d8d' }).attr('maxLength', 20).val(searchText).focus(function () {
        jQuery(this).val('').css({ color: '#5e5e5e' });
    }).parent().css({ 'padding-top': '0px' });
    //分类搜索
    jQuery('#q_proclassid_clone').hover(function () {
        jQuery(this).addClass("q_proclassid_clone_hover");
    }).click(function () {
        jQuery('.sc_container', jQuery(this).parent()).show();
    }).blur(function () {
        jQuery(this).removeClass("q_proclassid_clone_hover");
        setTimeout(function () { jQuery('.sc_container').hide(); }, 200);
    });
    jQuery('.sc_container tr').hover(function () {
        jQuery('.sc_container tr').attr('class', 'ml')
        jQuery(this).attr('class', 'mo');
    }, function () {
        jQuery(this).attr('class', 'ml');
    }).click(function () {
        jQuery('#q_proclassid_clone').val(jQuery(this).children('td').children('span').html());
        jQuery('#q_proclassid').attr('selectedIndex', jQuery('.sc_container tr').index(this));
    });
    //频道分类
    jQuery('#q_tabid_clone').hover(function () {
        jQuery(this).addClass("q_tabid_clone_hover");
    }).click(function () {
        jQuery('.st_container', jQuery(this).parent()).show();
    }).blur(function () {
        jQuery(this).removeClass("q_tabid_clone_hover");
        setTimeout(function () { jQuery('.st_container').hide(); }, 200);
    });
    jQuery('.st_container tr').hover(function () {
        jQuery('.st_container tr').attr('class', 'ml')
        jQuery(this).attr('class', 'mo');
    }, function () {
        jQuery(this).attr('class', 'ml');
    }).click(function () {
        var val = jQuery(this).children('td').children('span').html();
        searchText = searchTextFormat.replace("{0}", val);
        jQuery('#q_tabid_clone').val(val);
        jQuery('#q_tabid').attr('selectedIndex', jQuery('.st_container tr').index(this));
        jQuery('#q_prokey').css({ color: '#8d8d8d' }).val(searchText).focus(function () {
            jQuery(this).val('').css({ color: '#5e5e5e' });
        });
    });
    //建议关键字
    jQuery('#q_prokey').attr('autocomplete', 'off').focus(function () {
        timer1000 = setInterval(runTimer, 1000);
    }).bind(eventName, function (event) {
        doSuggest(jQuery('.ss_container'), jQuery('#q_prokey'), event.keyCode);
    }).bind("afterpaste", function () {
        doSuggest(jQuery('.ss_container'), jQuery('#q_prokey'), 0);
    }).blur(function () {
        clearInterval(timer1000);
        setTimeout(function () { jQuery('.ss_container').hide(); }, 200);
    });
    jQuery('#q_prokey').before("<div class='ss_container'><table cellspacing='0' cellpadding='2'><tbody></tbody></table></div>");

    jQuery('.ss_container').css({ 'width': getProkeyWidth, 'margin-top': '27px', 'margin-left': '0px' });

    //提交处理
    jQuery('.search02 form').add("#in_menum form").add(".bg_search_right form").add(".bg_search_left form").submit(function () {
        if (jQuery('#q_prokey', this).val() == searchText) jQuery('#q_prokey', this).val(""); 
        return true;
    });

    //初始化搜索表单
    var tab = parseInt(getRequestParameter("tab"));
    if (!isNaN(tab) && tab <= 7) {
        jQuery('#q_tabid_clone').val(jQuery('#q_tabid').val(tab).children(':selected').html());
    }
    var wd = getRequestParameter("wd");
    if (wd.length > 0) {
        jQuery('#q_prokey').css({ color: '#5e5e5e' }).val(wd).unbind("focus").focus(function () {
            timer1000 = setInterval(runTimer, 1000);
        });
    }
    if (typeof (absoluteUrl) == "undefined") absoluteUrl = '/';
}

function getProkeyWidth(index, value) {
    return jQuery('#q_prokey').width() + (jQuery.browser.msie || jQuery.browser.opera ? 8 : 8);
}
function getProkeyHeight(index, value) {
    return jQuery('#q_prokey').height();
}

function runTimer() {
    if (up_or_down) return;
    var wd_copy = jQuery('#q_prokey').val().replace(reExtraSpace, '');
    if (wd_copy.length == 0) {
        jQuery('.ss_container').hide();
        return;
    }
    if (wd_copy.length > 0 && wd != wd_copy) ajaxGet(jQuery('.ss_container'), jQuery('#q_prokey'), wd = wd_copy);
}

function doSuggest($container, $srcEle, keycode) {
    if (keycode == 38 || keycode == 40) {
        up_or_down = true;

        if (wd.length == 0) return;

        var _length = jQuery('tr', $container).length;
        if (_length == 0) ajaxGet($container, $srcEle, wd);

        if ($container.css('display').toLowerCase() == 'none') {
            $container.show();
        }
        else {
            var _index = -1;
            jQuery('tr', $container).each(function (index, domEle) { if (jQuery(domEle).is('.mo')) return _index = index; });

            var _current = 0;
            if (_index == -1) {
                _current = (keycode == 38 ? _length : 1);
            }
            else {
                _current = keycode - 38 + _index;
            }

            jQuery('tr.mo', $container).removeClass('mo').addClass('ml');

            if (_current <= 0 || _current > _length) {
                $srcEle.val(wd);
            }
            else {
                $srcEle.val(jQuery('tr:nth-child(' + _current + ')', $container).removeClass('ml').addClass('mo').children('td').html());
            }
        }
    }
    else {
        up_or_down = false;
        wd = $srcEle.val().replace(reExtraSpace, '');
        if (wd.length > 0) ajaxGet($container, $srcEle, wd);
        else $container.hide();
    }
}
function ajaxGet($container, $srcEle, wd) {
    var param1 = 'op=sou&tab=' + jQuery('#q_tabid').val() + '&wd=' + escape(wd);
    //alert(absoluteUrl + 'filehandle/searchform.ashx');
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param1,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
            //alert(textStatus);
            $container.hide();
        },
        success: function (data) {
            if (data.length > 0) {
                jQuery('tr', $container).remove();
                jQuery('tbody', $container).html(data);
                jQuery('tr', $container).hover(function () {
                    jQuery('tr', $container).attr('class', 'ml')
                    jQuery(this).attr('class', 'mo');
                }, function () {
                    jQuery(this).attr('class', 'ml');
                }).click(function () {
                    $srcEle.val(jQuery(this).children('td').html());
                });
                $container.show();
            }
            else {
                $container.hide();
            }
        }
    });
}


/*
*
* 创建类似走马灯的效果
*
*/
jQuery.extend({
    marqueeUp: function (obj, delay) {
        if (obj.height() < 40) return;
        var index = 1 - parseInt(obj.css("margin-top").replace("px", ""), 10) / 23;
        function fn() {
            var _index = 23 * index;
            if (_index > obj.height()) {
                index = 1;
                obj.css({ marginTop: 0 });
                return;
            }
            obj.animate({ opacity: 0.7 }, { duration: 500 });
            obj.animate({ marginTop: -_index }, { duration: 500 }, index++);
            obj.animate({ opacity: 1 }, { duration: 500 });
        };
        return setInterval(fn, delay);
    }
});

function initMarqueeUp() {
    var timer = jQuery.marqueeUp(jQuery(".productclass_level_1_content ul").hover(function () { clearInterval(timer) }, function () { timer = jQuery.marqueeUp(jQuery(this), 4000); }), 4000);
    jQuery(".productclass_level_1_content a[cid]").click(function () {
        var cid = jQuery(this).attr("cid");
        jQuery(".productclass_level_2_table tr").unbind('mouseenter mouseleave');
        jQuery(".productclass_level_2_table tr.level1_hover").removeClass("level1_hover");
        jQuery(".productclass_level_2_table td[cid='" + cid + "']").parent().addClass("level1_hover").hover(function () {
        }, function () {
            trLevel1_hover();
        });
    });
}
function trLevel1_hover() {
    jQuery(".productclass_level_2_table tr.level1").hover(function () {
        jQuery(this).removeClass("level1").addClass("level1_hover");
    }, function () {
        jQuery(this).removeClass("level1_hover").addClass("level1");
    });
}
/*
*
* 判断并异步加裁二级、三级分类
*
*/
function ajaxGetClassLevel() {
    if (jQuery("td.productclass_level_2_col2[cid]").length == 0) return;
    jQuery("td.productclass_level_2_col2[cid]").each(function (index, domEle) {
        var param = 'op=classlevel2&cid=' + jQuery(domEle).attr("cid");
        jQuery.ajax({
            type: 'POST',
            url: absoluteUrl + 'filehandle/searchform.ashx',
            data: param,
            cache: false,
            error: function (XMLHttpRequest, textStatus) {
                //alert(textStatus);
            },
            success: function (data) {
                jQuery(domEle).empty().html(data + "<br/><div class=\"level3_width\"></div><div class='level3'><div class='level3_title'><span class=\"l3_left\"></span><span class=\"l3_right\"><a href=\"javascript:noop()\">关闭</a></span></div><div class='level3_content'></div></div>");

                trLevel1_hover();

                jQuery(".productclass_level_2_col2 a[cid]", jQuery(domEle).parent()).click(function () {
                    ajaxGetClassLevel3(jQuery(this), jQuery(this).attr("cid"));
                })
            }
        });
    });
}
function ajaxGetClassLevel3($obj, cid) {
    jQuery("div.level3", $obj.parent().parent()).slideUp("fast");

    if (isNaN(cid) || cid <= 0) return;
    var param = 'op=classlevel3&cid=' + cid;
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
            //alert(textStatus);
        },
        success: function (data) {
            jQuery("div.level3 div.level3_title span.l3_left", $obj.parent().parent()).html("“<a href='productlist.aspx?c1=" + cid + "'>" + jQuery.trim($obj.text().replace("|", "")) + "</a>”的下级分类：");
            jQuery("div.level3 div.level3_title span.l3_right a", $obj.parent().parent()).click(function () {
                jQuery(this).parent().parent().parent().slideUp("fast");
            });
            jQuery("div.level3 div.level3_content", $obj.parent().parent()).html(data);
            jQuery("div.level3", $obj.parent().parent()).slideDown("fast");
        }
    });
}

/*
*
* jQuery关于cookie的操作
*
*/
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
        }
        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 {
        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]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


/*
*
*  在线时长维护
*
*/
function checkOnline() {
    var userid = jQuery.cookie('CurrentUserID');
    if (userid == null || userid.length == 0 || isNaN(parseInt(userid, 10))) {
        return;
    }
    var lastest = jQuery.cookie('LastestCheckOnline');
    if (lastest == null || lastest.length == 0) {
        lastest = 0;
    }
    else {
        lastest = parseInt(lastest, 10);
        if (isNaN(lastest)) {
            lastest = 0;
        }
    }
    var dtime = new Date().getTime();
    //alert(dtime - lastest);
    if (dtime - lastest < 60 * 1000) return;

    var param = 'op=checkonline&uid=' + userid;
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
        },
        success: function (data) {
            jQuery.cookie('LastestCheckOnline', (new Date().getTime()), { path: "/" });
            jQuery.cookie('CurrentUserID', userid, { expires: (20.0 / (24 * 60)), path: "/" });
        }
    });
}
checkOnline();
setInterval(checkOnline, 60 * 1000);

/*
*
* 最近浏览产品相关
*
*/
function setViewed(pid) {
    if (pid == null || pid < 0) {
        jQuery.cookie('viewed', null);
        return;
    }
    var viewed = jQuery.cookie('viewed');
    if (viewed != null) {
        var s_viewed = viewed.split(',');
        viewed = "";
        for (var i = s_viewed.length - 1, j = 0; i >= 0 && j < 9; i--, j++) {
            if (s_viewed[i].length > 0 && parseInt(s_viewed[i], 10) != pid) viewed = s_viewed[i] + "," + viewed;
        }
    } else {
        viewed = '';
    }
    viewed += pid;
    jQuery.cookie('viewed', viewed.replace(/(\s)|(null)/ig, ',').replace(/[,]+/ig, ',').replace(/(^[,]*)|(^\s*)|([,]*$)|(\s*$)/ig, ''));
}
function getLatestViewed(count) {
    var viewed = jQuery.cookie('viewed');
    if (viewed == null || viewed.length == 0) {
        jQuery('.zjll_list').empty();
        return;
    }
    var param2 = 'op=viewed&num=' + (count == null ? 6 : count) + '&wd=' + escape(viewed);
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param2,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
            //alert(textStatus);
            jQuery('.zjll_list').empty();
        },
        success: function (data) {
            if (data.length > 0) {
                jQuery('.zjll_list').html(data);
            }
            else {
                jQuery('.zjll_list').empty();
            }
        }
    });
    jQuery(".bg_tab02 a.btn_clear").click(clearViewed);
}
function clearViewed() {
    jQuery.cookie('viewed', '');
    jQuery('.zjll_list').empty();
}


/*
*
* 商品比较相关
*
*/
function initCompareCHK() {
    jQuery(".divList input:checkbox[pid]").each(function (index, domEle) {
        jQuery(domEle).unbind('click').bind('click', function () {
            setCompare(jQuery(this).attr('pid'), jQuery(this).attr('checked'));
        });
    });
    jQuery('.spbj_ul01 li.btn_db>a').unbind('click').bind('click', function () {
        redirect2Compare();
    });
    refreshCompareArea(4);
}
function setCompare(pid) {
    if (pid == null || pid < 0) {
        jQuery.cookie('compare', null);
        return;
    }
    var compare = jQuery.cookie('compare');
    if (compare != null) {
        var s_compare = compare.split(',');
        var l_count = (arguments.length < 2 || arguments[1] ? 3 : 4);
        compare = "";
        for (var i = s_compare.length - 1, j = 0; i >= 0 && j < l_count; i--, j++) {
            if (s_compare[i].length > 0 && parseInt(s_compare[i], 10) != pid) {
                compare = s_compare[i] + "," + compare;
            }
        }
    } else {
        compare = '';
    }
    if (arguments.length < 2 || arguments[1]) {
        compare += pid;
    }
    var date = new Date();
    date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000));
    jQuery.cookie('compare', compare.replace(/(\s)|(null)/ig, ',').replace(/[,]+/ig, ',').replace(/(^[,]*)|(^\s*)|([,]*$)|(\s*$)/ig, ''), { expires: date });

    refreshCompareArea();
}
function removeCompare(pid) {
    setCompare(pid, false);
    jQuery(".divList input:checkbox[pid='" + pid + "']").attr("checked", false);
}
function refreshCompareArea(count) {
    var compare = jQuery.cookie('compare');
    if (compare == null || compare.length == 0) {
        jQuery('.spbj_ul01 li.dingwei').empty();
        jQuery(".divList input:checkbox").attr("checked", false);
        return;
    } else {
        var s_compare = compare.split(',');
        for (var i = s_compare.length - 1, j = 0; i >= 0 && j < count; i--, j++) {
            jQuery(".divList input:checkbox[pid='" + s_compare[i] + "']").attr("checked", true);
        }
    }
    var param3 = 'op=compare&num=' + (count == null ? 4 : count) + '&wd=' + escape(compare);
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param3,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
            //alert(textStatus);
            jQuery('.spbj_ul01 li.dingwei').empty();
        },
        success: function (data) {
            var images = data.split('*');
            var index = 0;
            if (images.length > 0) {
                jQuery('.spbj_ul01 li.dingwei').each(function (index, domEle) {
                    jQuery(domEle).html(index >= images.length ? "" : images[index]);
                });
                jQuery('.spbj_ul01 li.dingwei>div.b').each(function (index, domEle) {
                    jQuery(domEle).hover(function () {
                        jQuery(this).css({ opacity: 1 });
                    }, function () {
                        jQuery(this).css({ opacity: 0.7 });
                    }).click(function () {
                        removeCompare(jQuery(this).attr('pid'));
                    }).attr('title', '排除比较');
                });
            }
            else {
                jQuery('.spbj_ul01 li.dingwei').empty();
            }
        }
    });
}
function redirect2Compare() {
    if (jQuery('.spbj_ul01 li.dingwei>img').length <= 1) {
        alert("请您至少选择两种商品，谢谢！");
        return false;
    }
    window.open("product_contrast.aspx?s=" + escape(jQuery.cookie('compare')));
}


/*
*
* 继续搜索
*
*/
function getRequestParameter(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var url = window.location.href;
    try { url = decodeURI(url); } catch (e) { }
    var results = regex.exec(url);
    if (results == null) return "";
    else return unescape(results[1]);
}
function setRequestParameter(name, value) {
    ;
    var winhref = window.location.href;
    var qstring = name + "=" + value;
    if (winhref.indexOf('.aspx?' + name + '=') > 0) {
        var regexS = "[\\?]" + name + "=([^&#]*)";
        winhref = winhref.replace(new RegExp(regexS), '?' + qstring);
    }
    else if (winhref.indexOf('&' + name + '=') > 0) {
        var regexS = "[\\&]" + name + "=([^&#]*)";
        winhref = winhref.replace(new RegExp(regexS), '&' + qstring);
    }
    else if (winhref.indexOf('.aspx?') > 0) {
        winhref = winhref + "&" + qstring;
    }
    else {
        winhref = winhref + "?" + qstring;
    }
    return winhref;
}
function initGoonSearch() {
    jQuery(".search_jx input#textfield").val(getRequestParameter("wd2")).attr('autocomplete', 'off').focus(function () {
        timer1500 = setInterval(runTimer1500, 1500);
    }).bind(eventName, function (event) {
        doSuggest(jQuery('.ss2_container'), jQuery(this), event.keyCode);
    }).bind("afterpaste", function () {
        doSuggest(jQuery('.ss2_container'), jQuery(this), 0);
    }).blur(function () {
        clearInterval(timer1500);
        setTimeout(function () { jQuery('.ss2_container').hide(); }, 200);
    }).after("<br /><div class='ss2_container'><table cellspacing='0' cellpadding='2'><tbody></tbody></table></div>");

    jQuery(".search_jx img.goonsearch").css({ cursor: 'hand' }).unbind("click").bind("click", function () {
        window.location = setRequestParameter("wd2", jQuery(".search_jx input#textfield").val());
    });
    jQuery(".bg_search_right input#textfield2").val(searchText).css({ color: '#8d8d8d' }).focus(function () {
        jQuery(this).css({ color: '#000000' });
        if (jQuery(this).val() == searchText) jQuery(this).val("");
    }).blur(function () {
        jQuery(".bg_search_right a").attr("href", "?t=" + jQuery(".bg_search_right select").val() + "&wd=" + escape(jQuery(this).val()));
    });
}

function runTimer1500() {
    if (up_or_down) return;
    var wd_copy = jQuery('.search_jx input#textfield').val().replace(reExtraSpace, '');
    if (wd_copy.length > 0 && wd != wd_copy) ajaxGet(jQuery('.ss2_container'), jQuery('.search_jx input#textfield'), wd = wd_copy);
}

/*
*
* 初始化列表头部[显示方式+显示数量+排序方式]
*
*/
function initListHead() {
    //显示方式
    var s = getRequestParameter("s");
    var ints = -1;
    try { ints = parseInt(s, 10); } catch (e) { }
    if (isNaN(ints)) ints = -1;
    jQuery(".xsfs_list01 a.lds").each(function (index, domEle) {
        jQuery(domEle).attr("href", setRequestParameter("s", index - 1)).addClass("lds_" + (index + 1) + (index == ints + 1 ? 1 : 0));
    });
    if (ints == 1) jQuery(".kuang_cplist_top").add(".kuang_cpwz_top").hide();
    else if (ints == 0) {
        jQuery(".kuang_cplist_top").hide();
        jQuery(".kuang_cpwz_top").show();
    }
    //显示数量
    var n = getRequestParameter("n");
    var intn = -1;
    try { intn = parseInt(n, 10); } catch (e) { }
    if (isNaN(intn)) intn = -1;
    jQuery(".xsfs_list02 a.lps").each(function (index, domEle) {
        jQuery(domEle).attr("href", setRequestParameter("n", index - 1)).addClass("lps_" + (index + 1) + (index == intn + 1 ? 1 : 0));
    });
    //排序方式
    var o = getRequestParameter("o");
    var into = 100;
    try { into = parseInt(o, 10); } catch (e) { }
    if (isNaN(into) || into <= 0) into = 100;
    o = "000" + into;

    var asc_desc = ['点击启用默认排序方法', '点击启用默认排序方法', '点击按照店铺等级从高到低排序', '点击按照店铺等级从低到高排序', '点击按照更新时间从新到旧排序', '点击按照更新时间从旧到新排序', '点击按照价格从高到低排序', '点击按照价格从低到高排序'];


    var bit_1 = o.charAt(o.length - 3); bit_1 = (bit_1 == '0' ? '0' : '1');

    var bit_2 = o.charAt(o.length - 2); bit_2 = (bit_1 == '1' ? '0' : (bit_2 == '1' ? '1' : (bit_2 == '2' ? '2' : '0')));
    var bit$2 = (bit_2 == '0' ? '1' : (bit_2 == '1' ? '2' : '1'));
    var bit_3 = o.charAt(o.length - 1); bit_3 = (bit_1 == '1' ? '0' : (bit_2 == '1' ? '0' : (bit_3 == '1' ? '1' : (bit_3 == '2' ? '2' : '0'))));
    var bit$3 = (bit_3 == '0' ? '1' : (bit_3 == '1' ? '2' : '1'));

    if (bit_2 == '0' && bit_3 == '0') bit_1 = '1';

    var $ldos = jQuery(".xsfs_list03 a.ldo");

    $ldos.eq(0).attr("href", setRequestParameter("o", "100")).addClass("ldo_1" + bit_1).attr("title", asc_desc[0]);

    $ldos.eq(1).hide();

    $ldos.eq(2).attr("href", setRequestParameter("o", ("0" + bit$2 + "0"))).addClass("ldo_3" + bit_2).attr("title", asc_desc[4 + (bit_2 == '1' ? 1 : 0)]);

    $ldos.eq(3).attr("href", setRequestParameter("o", ("0" + "0" + bit$3))).addClass("ldo_4" + bit_3).attr("title", asc_desc[6 + (bit_3 == '1' ? 1 : 0)]);

}


/*
*
* “五金百科/五金资讯”选项卡切换
*
*/
function tabBKZX() {
    jQuery("li.ggtab01").hover(function () {
        jQuery(this).attr('class', 'ggtab01');
        jQuery(this).siblings(".ggtab01").attr('class', 'ggtab02');
        jQuery(".list02pad:last", jQuery(this).parent().parent().parent()).hide();
        jQuery(".list02pad:first", jQuery(this).parent().parent().parent()).show();
    });
    jQuery("li.ggtab02").hover(function () {
        jQuery(this).attr('class', 'ggtab01');
        jQuery(this).siblings(".ggtab01").attr('class', 'ggtab02');
        jQuery(".list02pad:first", jQuery(this).parent().parent().parent()).hide();
        jQuery(".list02pad:last", jQuery(this).parent().parent().parent()).show();
    });
}


/*
*
* “商品细览”页选项卡切换
*
*/
function tabPOverview() {
    jQuery(".cpxx_cp_r_4top li[th]").hover(function () {
        jQuery("li[th]", jQuery(this).parent()).removeClass("cpxx_cp_r_jrgw");
        jQuery(this).attr("class", "cpxx_cp_r_jrgw");
        jQuery(".cpxx_cp_r_4bottom[tb!=" + jQuery(this).attr("th") + "]", jQuery(this).parent().parent().parent().parent()).hide();
        jQuery(".cpxx_cp_r_4bottom[tb=" + jQuery(this).attr("th") + "]", jQuery(this).parent().parent().parent().parent()).show();
    });
}
function tabPDetails() {
    jQuery(".tabhead").hover(function () {
        jQuery(".tabhead[th]", jQuery(this).parent()).attr("class", "cpxx_cp_tit2 tabhead");
        jQuery(this).attr("class", "cpxx_cp_tit1 tabhead");
        var th = jQuery(this).attr("th");
        jQuery(".tabbody[tb!=" + th + "]", jQuery(this).parent().parent().parent()).hide();
        jQuery(".tabbody[tb=" + th + "]", jQuery(this).parent().parent().parent()).show();
    });
}

/*
*
* 搜索条件中的“更多>>”
*
*/
function initMoreCondition() {
    jQuery(".tiaocon li.more>a").click(function () {
        var $more = jQuery("div.more", jQuery(this).parent());
        jQuery("div.more").each(function (index, domEle) {
            if (jQuery(domEle) != $more) jQuery(domEle).hide();
        });
        $more.css('z-index', 9999).show();
        jQuery("li.classli_close", $more).unbind('click').bind('click', function () { $more.hide(); });
    });
}


/*
*
* 初始化超链接
*
*/
function initClassHref() {
    jQuery("a[key]").each(function (index, domEle) {
        jQuery(domEle).attr("href", "product/productsearchlist.aspx?q_proclassid_clone=" + escape(jQuery(domEle).attr("key")));
    });
}

function initPagerHref() {
    jQuery("a[pageindex]").each(function (index, domEle) {
        jQuery(domEle).attr("href", setRequestParameter("pageindex", jQuery(domEle).attr("pageindex")));
    });
    jQuery(".fenye span.disabled").css("color", "#999999");
    jQuery(".page_left span.disabled").css("color", "#999999");
    jQuery("input.goto").css({ "border": "solid 1px #D9D7CF", "width": "24px", "height": "16px", "background-color": "#FCFCFC", "padding": "2px", "margin": "auto 4px", "font-size": "12px" }).val("GO").focus(function () {
        jQuery(this).val("");
    }).bind(eventName, function (event) {
        if (event.keyCode == 13) {
            var maxpage = parseInt(jQuery(this).attr("max"));
            var gopage = parseInt(jQuery(this).val());
            if (isNaN(gopage) || gopage > maxpage) {
                jQuery(this).val("");
            }
            else {
                window.location = setRequestParameter("pageindex", jQuery(this).val());
            }
        }
    });
}


/*
*
* 异步加载品牌分类组
*
*/
function initBrandClass() {
    jQuery(".pplist_top a[val]").each(function (index, domEle) {
        jQuery(domEle).unbind("click").bind("click", function () {
            var val = jQuery(this).attr("val");
            getBrandGroup(val);
            /*
            var $group = jQuery(".classlist3 div[val=" + val + "]");
            getBrandGroup(val);
            if ($group.length == 0) {
            jQuery(this).addClass("toggle");
            getBrandGroup(val);
            }
            else {
            jQuery(this).removeClass("toggle");
            $group.remove();
            }*/
        });
    });
    jQuery(".tg_box3 .pplist_boxtoggle>a").unbind("click").bind("click", function () {
        jQuery(this).toggleClass("toggle");
        jQuery(this).parent().parent().parent().find(".tg_boxbod").slideToggle("fast");
    });
}
function getBrandGroup(c1) {
    var param5 = 'op=brandgroup&c1=' + c1;
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param5,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
            //alert(textStatus);
        },
        success: function (data) {
            if (data.length > 20) {
                var arr = data.split('##########');
                if (arr.length >= 1 && arr[0].length > 10) jQuery(".pplist_navpath").html(arr[0]);
                if (arr.length >= 2 && arr[1].length > 10) {
                    jQuery(".pplist_top>ul").html(arr[1]);
                    initBrandClass();
                }
                if (arr.length >= 3 && arr[2].length > 10) {
                    jQuery(".pplist_top").after(arr[2]);
                    jQuery(".tg_box3 .pplist_boxtoggle>a").unbind("click").bind("click", function () {
                        jQuery(this).toggleClass("toggle");
                        jQuery(this).parent().parent().parent().find(".tg_boxbod").slideToggle("fast");
                    });
                }
            }
        }
    });
}



/*
*
* 初始化店铺列表
*
*/
function initShopList() {
    jQuery(".tg_box3 .pplist_boxtoggle>a").unbind("click").bind("click", function () {
        jQuery(this).toggleClass("toggle");
        jQuery(this).parent().parent().parent().find(".tg_boxbod").slideToggle("fast");
    });
    jQuery("a[pageindex]").each(function (index, domEle) {
        jQuery(domEle).attr("href", setRequestParameter("pageindex", jQuery(domEle).attr("pageindex")));
    });
    jQuery(".pplist_boxdetail span.disabled").css("color", "#999999");
    jQuery("input.goto").css({ "border": "solid 1px #D9D7CF", "width": "24px", "height": "16px", "background-color": "#FCFCFC", "padding": "2px", "margin": "auto 4px", "font-size": "12px" }).val("GO").focus(function () {
        jQuery(this).val("");
    }).bind(eventName, function (event) {
        if (event.keyCode == 13) {
            var maxpage = parseInt(jQuery(this).attr("max"));
            var gopage = parseInt(jQuery(this).val());
            if (isNaN(gopage) || gopage > maxpage) {
                jQuery(this).val("");
            }
            else {
                window.location = setRequestParameter("pageindex", jQuery(this).val());
            }
        }
    });
}


/*
*
* 遮罩效果
*
*/
var winMask = {
    $: function (obj) {
        if (typeof obj == 'string') { var obj = document.getElementById(obj); return obj; }
        return null;
    },
    show: function () {
        this.oc(1); //显示遮罩

    },
    hide: function () {
        this.oc(0); //关闭遮罩
    },
    oc: function (o) {
        if (!o) { var o = 0; }
        this.bodyBg(o);
    },
    bodyBg: function (o) {//创建|显示隐藏透明遮罩
        var obj = this.$("body_pr");
        if (o == 0) {
            if (obj != null) {
                document.getElementsByTagName("body")[0].removeChild(this.$("body_pr"));
            }
        }
        else {
            if (obj == null) {
                document.getElementsByTagName("body")[0].style.height = "100%";
                var style = { position: "absolute", left: "0", top: "0", zIndex: "9999", width: "100%", height: jQuery(document).height() + "px", backgroundColor: "#000", filter: "alpha(opacity=30)", opacity: "0.3" }
                this.cDiv("body_pr", "div", style, document.getElementsByTagName("body")[0]);
            }
        }
    },
    cDiv: function (id, tag, style, fid) {//创建HTML标签方法
        var div = document.createElement(tag);
        div.id = id;
        for (var i in style) { div.style[i] = style[i]; }
        fid.appendChild(div);
    }
}
function hideMask() {
    jQuery("div:visible").each(function (index, domEle) {
        if (jQuery(domEle).css('z-index') >= 10000) jQuery(domEle).hide();
    });
    winMask.hide();
    jQuery(window).unbind("scroll").bind("scroll", gotoTop2);
}
jQuery(window).bind("resize", gotoTop);

function gotoTop2() {
    if (jQuery(window).scrollTop() < 100) {
        jQuery(".backtop").fadeOut();
    }
    else {
        jQuery(".backtop").fadeIn();
    }
    //针对IE6、IE7，需要重新计算
    if (advVersion) return;
    jQuery(".backtop").css("top", jQuery(window).scrollTop() + (jQuery(window).height() - 60) / 2);
}
function gotoTop() {
    var loactionX = (jQuery(window).width() - 1032) / 2;
    var locationY = (jQuery(window).height() - 60) / 2;
    jQuery(".backtop").each(function (index, domEle) {
        if (jQuery(domEle).is("._left")) jQuery(domEle).css("left", ((jQuery(window).width() < 1036) ? -50 : loactionX)).css("top", locationY);
        else jQuery(domEle).css("right", ((jQuery(window).width() < 1036) ? 5 : loactionX)).css("top", locationY);
    });
}


/*
*
* 询盘与留言对话框
*
*/
function initDialogLY() {
    jQuery(".idply").add(".iwyly").unbind("click").bind("click", function () {
        winMask.show();
        jQuery(".dply_box").css({ top: function () { return (jQuery(window).scrollTop() + jQuery(window).height() / 2 - 150); }, left: function () { return (jQuery(document).width() / 2 - 230); } }).show();
    });
    jQuery(".dply_buttoninput:button").bind("click", function () {
        jQuery(".dply_box").hide();
        winMask.hide();
    });
    jQuery("#dply_nr").bind(eventName, function (event) {
        var leaveword = 100 - jQuery(this).val().length;
        if (leaveword >= 100) jQuery(".dply_info").html("请输入留言主题和内容[10-100字]").css("color", "#ff4321");
        else if (leaveword >= 0) jQuery(".dply_info").html("[" + leaveword + "]").css("color", "#20a0e0");
        else jQuery(".dply_info").html("[" + leaveword + "]").css("color", "#ff4321");
    });
    jQuery(".dply_box2 form").bind("submit", function () {
        var leaveword = jQuery("#dply_zt", jQuery(this)).val().length;
        if (leaveword < 10) {
            jQuery(".dply_info", jQuery(this)).html("<img src='../admin/images/validate_error.gif' width='22' height='22' align='absmiddle'>留言主题长度不符合要求[10-100字]！");
            return false;
        }
        leaveword = jQuery("#dply_nr", jQuery(this)).val().length;
        if (leaveword > 100 || leaveword < 10) {
            jQuery(".dply_info", jQuery(this)).html("<img src='../admin/images/validate_error.gif' width='22' height='22' align='absmiddle'>留言内容长度不符合要求[10-100字]！");
            return false;
        }
        jQuery("#dply_zt", jQuery(this)).val(jQuery("#dply_zt", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        jQuery("#dply_nr", jQuery(this)).val(jQuery("#dply_nr", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        return true;
    });
}
function initDialogXP() {
    jQuery(".iwyxp").unbind("click").bind("click", function () {
        var pid = getRequestParameter("q_productid");
        if (pid == "") pid = jQuery(this).attr("pid");
        getXPInfo(pid);
        winMask.show();
        jQuery("input#thePid").val(pid);
        jQuery(".xp_box").css({ top: function () { return (jQuery(window).scrollTop() + jQuery(window).height() / 2 - 280); }, left: function () { return (jQuery(document).width() / 2 - 230); } }).show();
    });
    jQuery(".xp_buttoninput:button").bind("click", function () {
        jQuery(".xp_box").hide();
        winMask.hide();
    });
    jQuery("#xp_nr").bind(eventName, function (event) {
        var leaveword = 100 - jQuery(this).val().length;
        if (leaveword >= 100) jQuery(".xp_info").html("请输入询盘信息[10-100字]").css("color", "#ff4321");
        else if (leaveword >= 0) jQuery(".xp_info").html("[" + leaveword + "]").css("color", "#20a0e0");
        else jQuery(".xp_info").html("[" + leaveword + "]").css("color", "#ff4321");
    });
    jQuery(".xp_box2 form").bind("submit", function () {
        var leaveword = jQuery("#xp_nr", jQuery(this)).val().length;
        if (leaveword > 100 || leaveword < 10) {
            jQuery(".xp_info", jQuery(this)).html("<img src='../admin/images/validate_error.gif' width='22' height='22' align='absmiddle'>询盘信息长度不符合要求[10-100字]！");
            return false;
        }
        jQuery("#xp_nr", jQuery(this)).val(jQuery("#xp_nr", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        return true;
    });
}
function getXPInfo(pid) {
    var param6 = 'op=qanda&pid=' + pid;
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param6,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
            //alert(textStatus);
        },
        success: function (data) {
            jQuery("ul.xp_qanda").html(data).scrollTop(10000);
        }
    });
}


/*
*
* 收藏商品与店铺
*
*/
function initCollection() {
    //
    // 收藏商品
    //
    jQuery(".cpxx_bt_r a").attr("href", "javascript:noop();").click(function () {
        var pname = jQuery(".cpxx_bt_l").text();
        jQuery("#scsp_name").val(pname.length > 25 ? (pname.substring(0, 24) + "..") : pname);
        if (jQuery(".sc_ss_container", jQuery("#scsp_group").parent()).length == 0) getCollectionGroup(3); //获取关注分组
        winMask.show();
        jQuery(".scsp_box").css({ top: function () { return (jQuery(window).scrollTop() + jQuery(window).height() / 2 - 150); }, left: function () { return (jQuery(document).width() / 2 - 230); } }).show();
    });
    jQuery(".scsp_buttoninput:button").bind("click", function () {
        jQuery(".scsp_box").hide();
        winMask.hide();
    });
    jQuery("#scsp_name").bind(eventName, function (event) {
        jQuery("#button.scsp_buttoninput").attr("disabled", (jQuery(this).val().length == 0));
    });
    jQuery("#scsp_group").hover(function () {
        jQuery(this).addClass("scsp_fzinput_hover");
    }).dblclick(function () {
        jQuery('.sc_ss_container', jQuery(this).parent()).show();
    }).blur(function () {
        jQuery(this).removeClass("scsp_fzinput_hover");
        setTimeout(function () { jQuery('.sc_ss_container').hide(); }, 200);
    });

    jQuery(".scsp_box2 form").bind("submit", function () {
        if (jQuery("#scsp_name", this).val().length == 0) {
            jQuery("#button.scsp_buttoninput", this).attr("disabled", true);
            return false;
        }
        jQuery("#scsp_name", jQuery(this)).val(jQuery("#scsp_name", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        jQuery("#scsp_group", jQuery(this)).val(jQuery("#scsp_group", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        return true;
    });
    //
    // 收藏店铺
    //
    jQuery(".cp_r_topbod_l3 .idpsc:enabled").click(function () {
        var sname = jQuery(".cp_r_topbod_li[title]").attr("title");
        jQuery("#scdp_name").val(sname.length > 25 ? (sname.substring(0, 24) + "..") : sname);
        if (jQuery(".sc_ss_container", jQuery("#scdp_group").parent()).length == 0) getCollectionGroup(2); //获取关注分组
        winMask.show();
        jQuery(".scdp_box").css({ top: function () { return (jQuery(window).scrollTop() + jQuery(window).height() / 2 - 150); }, left: function () { return (jQuery(document).width() / 2 - 230); } }).show();
    });
    jQuery(".scdp_buttoninput:button").bind("click", function () {
        jQuery(".scdp_box").hide();
        winMask.hide();
    });
    jQuery("#scdp_name").bind(eventName, function (event) {
        jQuery("#button.scdp_buttoninput").attr("disabled", (jQuery(this).val().length == 0));
    });
    jQuery("#scdp_group").hover(function () {
        jQuery(this).addClass("scdp_fzinput_hover");
    }).dblclick(function () {
        jQuery('.sc_ss_container', jQuery(this).parent()).show();
    }).blur(function () {
        jQuery(this).removeClass("scdp_fzinput_hover");
        setTimeout(function () { jQuery('.sc_ss_container').hide(); }, 200);
    });

    jQuery(".scdp_box2 form").bind("submit", function () {
        if (jQuery("#scdp_name", this).val().length == 0) {
            jQuery("#button.scdp_buttoninput", this).attr("disabled", true);
            return false;
        }
        jQuery("#scdp_name", jQuery(this)).val(jQuery("#scdp_name", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        jQuery("#scdp_group", jQuery(this)).val(jQuery("#scdp_group", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        return true;
    });
    jQuery("#scsp_group").add("#scdp_group").attr("title", "双击选择已有分组");

    //
    checkCollections(2, function () {
        jQuery(".cp_r_topbod_l3 .idpsc:enabled").unbind("click").click(function () {
            alert("您已经收藏了该店铺！");
        });
    });
    checkCollections(3, function () {
        jQuery(".cpxx_bt_r a").unbind("click").click(function () {
            alert("您已经收藏了该商品！");
        });
    });
}
function getCollectionGroup(type) {
    var param8 = 'op=collectiongroup&type=' + type;
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param8,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
            //alert(textStatus);
        },
        success: function (data) {
            if (type == 2) jQuery("#scdp_group").after("<br /><div class='sc_ss_container'><table cellspacing='0' cellpadding='2'><tbody>" + data + "</tbody></table></div>");
            else if (type == 3) jQuery("#scsp_group").after("<br /><div class='sc_ss_container'><table cellspacing='0' cellpadding='2'><tbody>" + data + "</tbody></table></div>");

            jQuery('.sc_ss_container tr').hover(function () {
                jQuery('.sc_ss_container tr').attr('class', 'ml')
                jQuery(this).attr('class', 'mo');
            }, function () {
                jQuery(this).attr('class', 'ml');
            }).click(function () {
                jQuery("input:text", jQuery(this).parent().parent().parent().parent()).val(jQuery.trim(jQuery(this).children('td').html()));
            });
        }
    });
}
function checkCollections(type, callback) {
    var param = 'op=checkcollections&type=' + type + '&pid=' + getRequestParameter("q_productid");
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
            callback();
        },
        success: function (data) {
            if (data != "true") callback();
        }
    });
}
function checkCollections2(callback) {
    var param = 'op=checkcollections2&sid=' + getRequestParameter("StoreId");
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
            callback();
        },
        success: function (data) {
            if (data != "true") callback();
        }
    });
}


function showMSG() {
    if (hasInit) return;
    if (jQuery.cookie("ShowMSGBOX") == null) return;

    var msg = getRequestParameter("msg");
    if (msg == "ok") {
        winMask.show();
        msgShow(1);
    }
    else if (msg == "error") {
        winMask.show();
        msgShow(0);
    }
    jQuery.cookie("ShowMSGBOX", null);
    setShowMSGBOXCookie();
}

function setShowMSGBOXCookie() {
    var param = 'op=cookie&name=ShowMSGBOX&value=false';
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
        },
        success: function (data) {
        }
    });
}

function msgShow(i) {
    if (jQuery(".msg_box").length == 0) {
        jQuery("body").append("<div class=\"msg_box\"><div class=\"msg_box2\"><div class=\"msg_icon\"></div><div class=\"msg_text\"></div><div class=\"msg_buttons\"><input type=\"button\" name=\"button2\" class=\"msg_buttonclose\" value=\"关闭\" /></div></div></div>")
        jQuery(".msg_buttonclose", jQuery(".msg_box")).bind("click", function () {
            jQuery(".msg_box").hide();
            winMask.hide();
        });
    }

    var $msgbox = jQuery(".msg_box");
    $msgbox.css({ top: function () { return (jQuery(window).scrollTop() + jQuery(window).height() / 2 - 150); }, left: function () { return (jQuery(document).width() / 2 - 230); } });

    if (i == 0) {
        jQuery(".msg_icon", $msgbox).addClass("msg_icon_error");
        jQuery(".msg_text", $msgbox).html("对不起，保存失败！");
    } else {
        jQuery(".msg_icon", $msgbox).addClass("msg_icon_ok");
        jQuery(".msg_text", $msgbox).html("保存成功，谢谢您的参与！");
    }
    $msgbox.show();
}


function showBKMSG() {
    if (jQuery.cookie("ShowMSGBOX") == null) return;

    var msg = getRequestParameter("msg");
    if (msg == "ok") {
        winMask.show();
        msgShowBK(1);
    }
    else if (msg == "yes") {
        winMask.show();
        msgShowBK(1, "设置成功！");
    }
    else if (msg == "error") {
        winMask.show();
        msgShowBK(0);
    }
    jQuery.cookie("ShowMSGBOX", null);
    setShowMSGBOXCookie();
}

function msgShowBK(i, msg) {
    if (jQuery(".msg_box").length == 0) {
        jQuery("body").append("<div class=\"msg_box\"><div class=\"msg_box2\"><div class=\"msg_icon\"></div><div class=\"msg_text\"></div><div class=\"msg_buttons\"><input type=\"button\" name=\"button2\" class=\"msg_buttonclose\" value=\"关闭\" /></div></div></div>")
        jQuery(".msg_buttonclose", jQuery(".msg_box")).bind("click", function () {
            jQuery(".msg_box").hide();
            winMask.hide();
        });
    }

    var $msgbox = jQuery(".msg_box");
    $msgbox.css({ top: function () { return (jQuery(window).scrollTop() + jQuery(window).height() / 2 - 150); }, left: function () { return (jQuery(document).width() / 2 - 230); } });

    if (i == 0) {
        jQuery(".msg_icon", $msgbox).addClass("msg_icon_error");
        jQuery(".msg_text", $msgbox).html("对不起，保存失败，请稍候重试！");
    } else {
        jQuery(".msg_icon", $msgbox).addClass("msg_icon_ok");
        if (msg == null) {
            jQuery(".msg_text", $msgbox).html("保存成功，谢谢您的参与！<br>如果审核通过，您的问题将在24小时内得到发布！");
        }
        else {
            jQuery(".msg_text", $msgbox).html(msg);
        }
    }
    $msgbox.show();
}

/*
*
* 商品评价表单
*
*/
function initFormComment() {
    jQuery("input:radio").attr("checked", false);
    jQuery(".cpxx_textarea").bind(eventName, function (event) {
        var leaveword = 100 - jQuery(this).val().length;
        if (leaveword >= 100) jQuery(".cpxx_info").html("请输入留言内容[10-100字]").css("color", "#ff4321");
        else if (leaveword >= 0) jQuery(".cpxx_info").html("[" + leaveword + "]").css("color", "#20a0e0");
        else jQuery(".cpxx_info").html("[" + leaveword + "]").css("color", "#ff4321");
    });
    jQuery(".cpxx_cp_xx form").bind("submit", function () {
        if (jQuery("input:radio:checked", jQuery(this)).length <= 0) {
            jQuery(".cpxx_info", jQuery(this)).html("<img src='../admin/images/validate_error.gif' width='22' height='22' align='absmiddle'>请选择一个评价等级！");
            return false;
        }
        var leaveword = jQuery(".cpxx_textarea", jQuery(this)).val().length;
        if (leaveword > 100 || leaveword < 10) {
            jQuery(".cpxx_info", jQuery(this)).html("<img src='../admin/images/validate_error.gif' width='22' height='22' align='absmiddle'>留言内容长度不符合要求[10-100字]！");
            return false;
        }
        jQuery(".cpxx_info", jQuery(this)).val(jQuery(".cpxx_info", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        return true;
    });
    jQuery(".cpxx_zcpl input[cid]").add(".cpxx_fdpl input[cid]").each(function (index, domEle) {
        jQuery(domEle).click(function () {
            jQuery("input[cid]", jQuery(this).parent().parent()).attr("disabled", true);
            var param7 = 'op=ccomment&cid=' + jQuery(this).attr("cid") + "&type=" + escape(jQuery(this).attr("title"));
            jQuery.ajax({
                type: 'POST',
                url: absoluteUrl + 'filehandle/searchform.ashx',
                data: param7,
                cache: false,
                error: function (XMLHttpRequest, textStatus) {
                    //alert(textStatus);
                    jQuery(domEle).attr("disabled", false);
                },
                success: function (data) {
                    if (data.length > 2) jQuery(domEle).val(data);
                }
            });
        });
    });
}


/*
*
* 初始化商品对比页布局
*
*/
function initContrastLayout() {
    var iCount = jQuery(".db_box1:visible").length + 1;
    if (iCount < 2) return;

    var iWidth = 858 / iCount;
    jQuery(".db_box1:visible").css("width", iWidth - 1);
    jQuery(".db_box2").css("width", iWidth);

    var rBoxUL = jQuery(".db_box2>ul")
    jQuery(".db_box_mc>ul>li").each(function (index, domEle) {
        var iHeight = Math.max(jQuery(domEle).height(), jQuery("li:eq(" + index + ")", rBoxUL).height());
        jQuery(".db_box1:visible").each(function (index2, domEle2) {
            iHeight = Math.max(iHeight, jQuery("ul li:eq(" + index + ")", jQuery(domEle2)).height());
        });
        jQuery(domEle).height(iHeight);
        jQuery("li:eq(" + index + ")", rBoxUL).height(iHeight);
        jQuery(".db_box1:visible").each(function (index2, domEle2) {
            jQuery("ul li:eq(" + index + ")", jQuery(domEle2)).height(iHeight);
        });
    });
    if (iCount > 2) {
        jQuery(".db_title:visible:gt(0)").append("<div class='db_delete' title='排除比较'></div>");
        jQuery(".db_delete").click(function () {
            if (jQuery(this).parent().parent().is(".db_box2")) {
                jQuery(".db_box1:visible:last").removeClass("db_box1").addClass("db_box2");
            }
            jQuery(this).parent().parent().hide();
            jQuery(".db_delete").remove();
            initContrastLayout();
        });
    }
    jQuery(".db_delete").hover(function () {
        jQuery(this).css({ filter: "alpha(opacity=100)", opacity: "1.0" });
    }, function () {
        jQuery(this).css({ filter: "alpha(opacity=50)", opacity: "0.5" });
    });
}


/*
*
* 购物车页所使用的方法
*
*/
function AbuthDle(ipt) {
    if (confirm("删除后将不可再恢复，您确认要删除所选择吗？")) {
        var $eachCar = jQuery(ipt).parent().parent().parent().parent().parent().parent().parent().parent();
        jQuery("#cbTm:checked", $eachCar).each(function (index, domEle) {
            var param = "Option=del&id=" + jQuery(domEle).val();
            jQuery.ajax({
                type: 'POST',
                url: absoluteUrl + 'product/shoppingcart.aspx',
                data: param,
                cache: false
            });
        });
        setTimeout(function () {
            window.location.reload();
        }, 1000);
    }
}

function UpdataShoppCart(obj, Count, ID, ProductId) {
    var reg = /[\D]/g;
    if (reg.exec(Count)) {
        alert("修改数量必须是数字！");
        jQuery(obj).val(jQuery(obj).attr("original"));
        return false;
    }
    if (Count <= 0) {
        alert("修改数量必须大于零！");
        jQuery(obj).val(jQuery(obj).attr("original"));
        return false;
    }
    if (Count == jQuery(obj).attr("original")) {
        return true;
    }
    var param = "Option=MofiyInfo&productcount=" + Count + "&id=" + ID + "&productId=" + ProductId;
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'product/shoppingcart.aspx',
        data: param,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
            //alert(textStatus);
        },
        success: function (data) {
            if (data != "ok") {
                var originalnum = jQuery(obj).attr("original");
                jQuery(obj).val(originalnum);
                originalnum = parseInt(data);
                alert("购买商品数量有误，您最多可以购买的数量是 " + (isNaN(originalnum) ? data : originalnum) + " ！");
                return false;
            }
            else {
                window.location.reload();
            }
        }
    });
}

function checkOrder(tname) {
    var retv = true;
    jQuery("#" + tname + " input.the_count").each(function (index, domEle) {
        var thevalue = parseInt(jQuery(domEle).val());
        var maxvalue = parseInt(jQuery(domEle).attr("max"));
        if (isNaN(thevalue) || isNaN(maxvalue) || thevalue > maxvalue) {
            retv = false;
            jQuery(domEle).css("background", "#ffc5d4");
        }
    });
    return retv;
}

/*
function SubmitOrders(id, Tyid) {
SendAjax("SubmitOrders", id, Tyid);
}
function SendAjax(op, id, Tyid) {
var param = "Option=" + op;
var options = {
method: 'post',
parameters: param,
onComplete:
function(transport) {
var retv = transport.responseText;
window.location.href = retv + "?MeId=" + id + "&MeTyId=" + Tyid + ""
}

}
new Ajax.Request('ShoppingCart.aspx', options);
}
*/

function selectAllShoppingCar(theBox) {
    xState = theBox.checked;
    jQuery("#cbTm", jQuery(theBox).parent().parent().parent()).attr("checked", jQuery(theBox).attr("checked"));
}

function initShoppingCart() {
    jQuery(":checkbox").attr("checked", false).click(function () {
        var $eachCar = jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent();
        if (0 == jQuery("input:checked", $eachCar).size()) jQuery("a.abuthdledisabled", $eachCar).removeClass("enabled").unbind("click");
        else jQuery("a.abuthdledisabled", $eachCar).addClass("enabled").unbind("click").bind("click", function () { AbuthDle(this); });
    });
    jQuery("a.abuthdledisabled").css("cursor", "pointer");
}


//-----------------------------------------------------------------------------
/*
*
* 店铺首页的相关方法
*
*/
var hasInit = false;

function initStoreHref() {
    //    jQuery("a[href^='/']").each(function() { jQuery(this).attr("href", " http://test7.weka.cn" + jQuery(this).attr("href")); });
    //    jQuery("a[href^='../']").each(function() { jQuery(this).attr("href", " http://test7.weka.cn" + jQuery(this).attr("href").substring(2)); });
}

function initStoreIndex() {

    initStoreHref();

    var winhref = window.location.href;
    if (winhref.toLowerCase().indexOf('?storeid=') > 0) {

        jQuery("a[nhref]").each(function (index, domEle) {
            jQuery(domEle).attr("href", winhref.replace(/&type=([^&#]*)/ig, "").replace(/&src=([^&#]*)/ig, "") + "&" + jQuery(domEle).attr("nhref"))
        });
        var psrc = getRequestParameter("src").toLowerCase();
        if (psrc == "authentication") {
            jQuery(".dp_right_qrbod iframe").attr("src", window.location.href + "&n=2");
        }
        else if (psrc == "list") {
            jQuery(".dp_right_qrbod iframe").attr("src", window.location.href + "&n=1");
        }
        else if (psrc == "leaveword") {
            jQuery(".dp_right_qrbod iframe").attr("src", window.location.href + "&n=4");
        }
        else if (psrc == "information") {
            jQuery(".dp_right_qrbod iframe").attr("src", window.location.href + "&n=5");
        }
        else {
            jQuery(".dp_right_qrbod iframe").attr("src", window.location.href + "&n=0");
        }
        jQuery(".search_img").parent().attr("href", window.location.href + "&n=1");
        jQuery(".dp_search00").blur(function () {
            jQuery(".search_img").parent().attr("href", window.location.href + "&n=1&wd=" + escape(jQuery(this).val()));
        });
    }
    else {
        jQuery("a[nhref]").each(function (index, domEle) {
            jQuery(domEle).attr("href", winhref.replace(/&type=([^&#]*)/ig, "").replace(/&src=([^&#]*)/ig, "") + "?" + jQuery(domEle).attr("nhref"))
        });
        jQuery(".dp_right_qrbod iframe").attr("src", window.location.href + "?n=0");
        jQuery(".search_img").parent().attr("href", window.location.href + "?n=1");
        jQuery(".dp_search00").blur(function () {
            jQuery(".search_img").parent().attr("href", window.location.href + "?n=1&wd=" + escape(jQuery(this).val()));
        });
    }

    jQuery(".dp_leftzx_wuyl").unbind("click").bind("click", function () {
        winMask.show();
        jQuery(".dply_box").css({ top: function () { return (jQuery(window).scrollTop() + jQuery(window).height() / 2 - 150); }, left: function () { return (jQuery(document).width() / 2 - 230); } }).show();
    });
    jQuery("#button2.dply_buttoninput").bind("click", function () {
        jQuery(".dply_box").hide();
        winMask.hide();
    });
    jQuery("#dply_nr").bind(eventName, function (event) {
        var leaveword = 100 - jQuery(this).val().length;
        if (leaveword >= 100) jQuery(".dply_info").html("请输入留言主题和内容[10-100字]").css("color", "#ff4321");
        else if (leaveword >= 0) jQuery(".dply_info").html("[" + leaveword + "]").css("color", "#20a0e0");
        else jQuery(".dply_info").html("[" + leaveword + "]").css("color", "#ff4321");
    });
    jQuery(".dply_box2 form").bind("submit", function () {
        var leaveword = jQuery("#dply_zt", jQuery(this)).val().length;
        if (leaveword < 10) {
            jQuery(".dply_info", jQuery(this)).html("<img src='../admin/images/validate_error.gif' width='22' height='22' align='absmiddle'>留言主题长度不符合要求[10-100字]！");
            return false;
        }
        leaveword = jQuery("#dply_nr", jQuery(this)).val().length;
        if (leaveword > 100 || leaveword < 10) {
            jQuery(".dply_info", jQuery(this)).html("<img src='../admin/images/validate_error.gif' width='22' height='22' align='absmiddle'>留言内容长度不符合要求[10-100字]！");
            return false;
        }
        jQuery("#dply_zt", jQuery(this)).val(jQuery("#dply_zt", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        jQuery("#dply_nr", jQuery(this)).val(jQuery("#dply_nr", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        return true;
    });

    //初始化“店铺收藏”按钮
    initShopCollection();
    //初始化“站内短信”按钮
    initSiteMessage();
    //初始化“分享本店”按钮
    initShopShared();

    //显示“提交成功/失败”信息
    showMSG();

    hasInit = true;
}

//初始化店铺首页中iframe的高度和店铺链接
function initStoreIframe() {

    initStoreHref();

    jQuery(".dp_right_qrbod iframe", jQuery(window.parent.document)).height(10).height(jQuery(document).height() + 10);
    jQuery(".page_left span.disabled").css("color", "#999999");
    jQuery(".page_left a[pageindex]").css("cursor", "pointer").each(function (index, domEle) {
        jQuery(domEle).attr("href", setRequestParameter("pageindex", jQuery(domEle).attr("pageindex")));
    });
}

//初始化“店铺收藏”按钮
function initShopCollection() {
    if (hasInit) return;
    if (jQuery("img:eq(0)", jQuery(".dp_leftfont_bot")).attr("disabled") == "disabled") return;

    jQuery("img:eq(0)", jQuery(".dp_leftfont_bot")).click(function () {
        var sname = jQuery(".dp_leftfont>strong").text();
        jQuery("#scdp_name").val(sname.length > 25 ? (sname.substring(0, 24) + "..") : sname);
        if (jQuery(".sc_ss_container", jQuery("#scdp_group").parent()).length == 0) getCollectionGroup(2); //获取关注分组
        winMask.show();
        jQuery(".scdp_box").css({ top: function () { return (jQuery(window).scrollTop() + jQuery(window).height() / 2 - 150); }, left: function () { return (jQuery(document).width() / 2 - 230); } }).show();
    });
    jQuery(".scdp_buttoninput:button").bind("click", function () {
        jQuery(".scdp_box").hide();
        winMask.hide();
    });
    jQuery("#scdp_name").bind(eventName, function (event) {
        jQuery("#button.scdp_buttoninput").attr("disabled", (jQuery(this).val().length == 0));
    });
    jQuery("#scdp_group").hover(function () {
        jQuery(this).addClass("scdp_fzinput_hover");
    }).dblclick(function () {
        jQuery('.sc_ss_container', jQuery(this).parent()).show();
    }).blur(function () {
        jQuery(this).removeClass("scdp_fzinput_hover");
        setTimeout(function () { jQuery('.sc_ss_container').hide(); }, 200);
    });

    jQuery(".scdp_box2 form").bind("submit", function () {
        if (jQuery("#scdp_name", this).val().length == 0) {
            jQuery("#button.scdp_buttoninput", this).attr("disabled", true);
            return false;
        }
        jQuery("#scdp_name", jQuery(this)).val(jQuery("#scdp_name", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        jQuery("#scdp_group", jQuery(this)).val(jQuery("#scdp_group", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        return true;
    });
    jQuery("#scsp_group").add("#scdp_group").attr("title", "双击选择已有分组");

    checkCollections2(function () {
        jQuery("img:eq(0)", jQuery(".dp_leftfont_bot")).unbind("click").click(function () {
            alert("您已经收藏了该店铺！");
        });
    });
}

//初始化“店铺留言”对话框
function initSiteMessage() {
    if (hasInit) return;
    if (jQuery("img:eq(1)", jQuery(".dp_leftfont_bot")).attr("disabled") == "disabled") return;

    jQuery("img:eq(1)", jQuery(".dp_leftfont_bot")).click(function () {
        winMask.show();
        jQuery(".zndx_box").css({ top: function () { return (jQuery(window).scrollTop() + jQuery(window).height() / 2 - 150); }, left: function () { return (jQuery(document).width() / 2 - 230); } }).show();
    });
    jQuery(".zndx_buttoninput:button").bind("click", function () {
        jQuery(".zndx_box").hide();
        winMask.hide();
    });
    jQuery("#zndx_nr").bind(eventName, function (event) {
        var leaveword = 100 - jQuery(this).val().length;
        if (leaveword >= 100) jQuery(".zndx_info").html("请输入留言主题和内容[10-100字]").css("color", "#ff4321");
        else if (leaveword >= 0) jQuery(".zndx_info").html("[" + leaveword + "]").css("color", "#20a0e0");
        else jQuery(".zndx_info").html("[" + leaveword + "]").css("color", "#ff4321");
    });
    jQuery(".zndx_box2 form").bind("submit", function () {
        var leaveword = jQuery("#zndx_zt", jQuery(this)).val().length;
        if (leaveword < 10) {
            jQuery(".zndx_info", jQuery(this)).html("<img src='../admin/images/validate_error.gif' width='22' height='22' align='absmiddle'>留言主题长度不符合要求[10-100字]！");
            return false;
        }
        leaveword = jQuery("#zndx_nr", jQuery(this)).val().length;
        if (leaveword > 100 || leaveword < 10) {
            jQuery(".zndx_info", jQuery(this)).html("<img src='../admin/images/validate_error.gif' width='22' height='22' align='absmiddle'>留言内容长度不符合要求[10-100字]！");
            return false;
        }
        jQuery("#zndx_zt", jQuery(this)).val(jQuery("#zndx_zt", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        jQuery("#zndx_nr", jQuery(this)).val(jQuery("#zndx_nr", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        return true;
    });
}

//初始化“分享店铺”对话框
function initShopShared() {
    if (hasInit) return;
    if (jQuery("img:eq(2)", jQuery(".dp_leftfont_bot")).attr("disabled") == "disabled") return;

    jQuery("img:eq(2)", jQuery(".dp_leftfont_bot")).click(function () {
        jQuery("#fxdp_nr").text(sharedTextFormat.replace("{0}", jQuery("#theDomain").val()));
        winMask.show();
        jQuery(".fxdp_box").css({ top: function () { return (jQuery(window).scrollTop() + jQuery(window).height() / 2 - 240); }, left: function () { return (jQuery(document).width() / 2 - 200); } }).show();
    });
    jQuery(".fxdp_buttoninput:button").bind("click", function () {
        jQuery(".fxdp_box").hide();
        winMask.hide();
    });
    jQuery("#fxdp_emails").blur(function () {
        jQuery(this).val(jQuery(this).val().replace(/\r/ig, "").replace(/\n{2,}/ig, "\n").replace(/^\n*/ig, "").replace(/\n*$/ig, ""));
        validateEmail10(jQuery(this), jQuery(".fxdp_info"), jQuery(".fxdp_email_error"));
    });
    jQuery("#fxdp_nr").bind(eventName, function (event) {
        var leaveword = 200 - jQuery(this).val().length;
        if (leaveword >= 200) jQuery(".fxdp_info").html("请输入发送内容[200]").css("color", "#ff4321");
        else if (leaveword >= 0) jQuery(".fxdp_info").html("[" + leaveword + "]").css("color", "#20a0e0");
        else jQuery(".fxdp_info").html("[" + leaveword + "]").css("color", "#ff4321");
    });
    jQuery(".fxdp_box2 form").bind("submit", function () {
        if (!validateEmail10(jQuery("#fxdp_emails", jQuery(this)), jQuery(".fxdp_info", jQuery(this)), jQuery(".fxdp_email_error", jQuery(this)))) {
            return false;
        }
        var leaveword = jQuery("#fxdp_nr", jQuery(this)).val().length;
        if (leaveword > 200 || leaveword < 10) {
            jQuery(".fxdp_info", jQuery(this)).html("<img src='../admin/images/validate_error.gif' width='22' height='22' align='absmiddle'>内容长度不符合要求[10-200字] ！");
            return false;
        }
        jQuery("#fxdp_nr", jQuery(this)).val(jQuery("#fxdp_nr", jQuery(this)).val().replace("<", "&lt;").replace(">", "&gt;"));
        return true;
    });
}

//验证“分享店铺”时输入Email的控件，允许输入1~10个Email，每行一个
function validateEmail10($obj, $error, $errorpoint) {
    var arr = $obj.val().split('\n');
    if (arr.length > 10 || arr.length < 1 || arr[0].length == 0) {
        $error.html("<img src='../admin/images/validate_error.gif' width='22' height='22' align='absmiddle'>Email数量不符合要求[1-10个] ！");
        return false;
    }
    var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
    for (var i = 0; i < arr.length; i++) {
        if (!pattern.test(arr[i])) {
            $error.html("<img src='../admin/images/validate_error.gif' width='22' height='22' align='absmiddle'>Email格式错误！");
            $errorpoint.css("margin-top", 18 * i + 4).show();
            return false;
        }
    }
    $error.html("");
    $errorpoint.hide();
    return true;
}


//-----------------------------------------------------------------------------
/*
*
* 最近关注的新闻
*
*/

//浏览某新闻时，将新闻的ID记入Cookie
function setFocusNews(id) {
    if (id == null || id < 0) {
        jQuery.cookie('focusNews', null);
        return;
    }
    var focusNews = jQuery.cookie('focusNews');
    if (focusNews != null) {
        var s_focusNews = focusNews.split(',');
        focusNews = "";
        for (var i = s_focusNews.length - 1, j = 0; i >= 0 && j < 9; i--, j++) {
            if (s_focusNews[i].length > 0 && parseInt(s_focusNews[i], 10) != id) focusNews = s_focusNews[i] + "," + focusNews;
        }
    } else {
        focusNews = '';
    }
    focusNews += id;
    jQuery.cookie('focusNews', focusNews.replace(/(\s)|(null)/ig, ',').replace(/[,]+/ig, ',').replace(/(^[,]*)|(^\s*)|([,]*$)|(\s*$)/ig, ''));
}
//读取Cookie, Ajax获取最近浏览的新闻列表
function getFocusNews(count) {
    var focusNews = jQuery.cookie('focusNews');
    if (focusNews == null || focusNews.length == 0) {
        jQuery('.zjll_list').empty();
        return;
    }
    var param2 = 'op=focusnews&num=' + (count == null ? 6 : count) + '&wd=' + escape(focusNews);
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param2,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
            //alert(textStatus);
            jQuery('.list02pad').empty();
        },
        success: function (data) {
            if (data.length > 0) {
                jQuery('.list02pad').html(data);
            }
            else {
                jQuery('.list02pad').empty();
            }
        }
    });
    jQuery(".bg_tab02 a.btn_clear").click(clearFocusNews);
}
//清除“最近关注的新闻”
function clearFocusNews() {
    jQuery.cookie('focusNews', '');
    jQuery('.list02pad').empty();
}


//-----------------------------------------------------------------------------
/*
*
* 最近浏览的百科
*
*/

//浏览某百科时，将百科的ID记入Cookie
function setFocusBaike(id) {
    if (id == null || id < 0) {
        jQuery.cookie('focusBaike', null);
        return;
    }
    var focusBaike = jQuery.cookie('focusBaike');
    if (focusBaike != null) {
        var s_focusBaike = focusBaike.split(',');
        focusBaike = "";
        for (var i = s_focusBaike.length - 1, j = 0; i >= 0 && j < 10; i--, j++) {
            if (s_focusBaike[i].length > 0 && parseInt(s_focusBaike[i], 10) != id) focusBaike = s_focusBaike[i] + "," + focusBaike;
        }
    } else {
        focusBaike = '';
    }
    focusBaike += id;
    jQuery.cookie('focusBaike', focusBaike.replace(/(\s)|(null)/ig, ',').replace(/[,]+/ig, ',').replace(/(^[,]*)|(^\s*)|([,]*$)|(\s*$)/ig, ''));
}
//读取Cookie, Ajax获取最近浏览的百科列表
function getFocusBaike(count) {
    var focusBaike = jQuery.cookie('focusBaike');
    if (focusBaike == null || focusBaike.length == 0) {
        jQuery('.focused').empty();
        return;
    }
    var param2 = 'op=focusbaike&num=' + (count == null ? 10 : count) + '&wd=' + escape(focusBaike);
    jQuery.ajax({
        type: 'POST',
        url: absoluteUrl + 'filehandle/searchform.ashx',
        data: param2,
        cache: false,
        error: function (XMLHttpRequest, textStatus) {
            //alert(textStatus);
            jQuery('.focused').empty();
        },
        success: function (data) {
            if (data.length > 0) {
                jQuery('.focused').html("<ul>" + data + "</ul>");
            }
            else {
                jQuery('.focused').empty();
            }
        }
    });
    jQuery(".bk_focused a.btn_clear").click(clearFocusBaike);
}
//清除“最近浏览的百科”
function clearFocusBaike() {
    jQuery.cookie('focusBaike', '');
    jQuery('.focused').empty();
}


//-----------------------------------------------------------------------------
//主导航菜单应根据当前页面，高亮相应按钮
jQuery(document).ready(function () {

    if (winHref.indexOf('product/productclass.') > 0) {
        jQuery("#nav_2.wjnavtab02 a.nav_off").addClass("_hover");
    }
    else if (winHref.indexOf('product/productlist.') > 0) {
        jQuery("#nav_2.wjnavtab02 a.nav_off").addClass("_hover");
    }
    else if (winHref.indexOf('product/productcontent.') > 0) {
        jQuery("#nav_2.wjnavtab02 a.nav_off").addClass("_hover");
    }
    else if (winHref.indexOf('comment/default.') > 0) {
        jQuery("#nav_3.wjnavtab02 a.nav_off").addClass("_hover");
    }
    else if (winHref.indexOf('product/special.') > 0) {
        jQuery("#nav_4.wjnavtab02 a.nav_off").addClass("_hover");
    }
    else if (winHref.indexOf('product/productbrandlist.') > 0) {
        jQuery("#nav_5.wjnavtab02 a.nav_off").addClass("_hover");
    }
    else if (winHref.indexOf('article/index.') > 0) {
        jQuery("#nav_6.wjnavtab02 a.nav_off").addClass("_hover");
    }
    else if (winHref.indexOf('/baike/') > 0) {
        jQuery("#nav_7.wjnavtab02 a.nav_off").addClass("_hover");
    }
});

//-----------------------------------------------------------------------------
//根据URL确定当前页面，以执行相应页面的初始化操作
jQuery(document).ready(function () {

    if (jQuery(".backtop").length > 0) {
        advVersion = (jQuery(".backtop").css("position").toLowerCase() == "fixed");
    }
    //初始化搜索区域
    initSearchSuggest();
    //回到顶部
    gotoTop();

    if (winHref.indexOf('/default.') > 0) {
        //初始化首页的超链接
        initClassHref();
    }
    else if (winHref.indexOf('/productlist.') > 0) {
        //搜索条件中的“更多>>”
        initMoreCondition();
        //初始化“商品比较”选择框
        initCompareCHK();
        //初始化列表头部[显示方式+显示数量+排序方式]
        initListHead();
        //继续搜索
        initGoonSearch();
        //加载“最近浏览产品”视图
        getLatestViewed(6);
        //“五金百科/五金资讯”选项卡切换
        tabBKZX();

        //初始化分页超链接
        initPagerHref();
    }
    else if (winHref.indexOf('/productclass.') > 0) {
        //初始化走马灯效果
        initMarqueeUp();
        //判断并异步加裁二级、三级分类
        ajaxGetClassLevel();
    }
    else if (winHref.indexOf('/productlist2.') > 0) {
        //初始化走马灯效果
        initMarqueeUp();
        //判断并异步加裁二级、三级分类
        ajaxGetClassLevel();
    }
    else if (winHref.indexOf('/productbrandlist.') > 0) {
        //初始化品牌分类
        initBrandClass();
    }
    else if (winHref.indexOf('/shoplist.') > 0) {
        initShopList();
    }
    else if (winHref.indexOf('/productcontent.') > 0) {
        var qid = -1;
        try { qid = parseInt(getRequestParameter("q_productid"), 10); } catch (e) { }
        if (qid > 0) setViewed(qid);

        //选项卡切换
        tabPOverview();
        tabPDetails();
        //初始化对话框
        initDialogLY();
        initDialogXP();
        //初始化评论表单
        initFormComment();
        //初始化收藏按钮
        initCollection();

        jQuery(".cpxx_db_a1688").attr('href', 'javascript:gotoA1688();');
        jQuery(".cpxx_db_hc360").attr('href', 'javascript:gotoHC360();');

        //显示“提交成功/失败”信息
        showMSG();
    }
    else if (winHref.indexOf('/articlecontent.') > 0) {
        var aid = -1;
        try { aid = parseInt(getRequestParameter("Id"), 10); } catch (e) { }
        if (aid > 0) setFocusNews(aid);
    }
    else if (winHref.indexOf('/articlelist.') > 0) {
        //加载最近关注的新闻
        getFocusNews(6);
    }
    else if (winHref.indexOf('/bcinfolist.') > 0) {
        //加载最近关注的新闻
        getFocusNews(6);
    }
    else if (winHref.indexOf('/product_contrast.') > 0) {
        //初始化页面布局
        initContrastLayout();
        //初始化询盘对话框
        initDialogXP();

        //显示“提交成功/失败”信息
        showMSG();
    }
    else if (winHref.indexOf('/shoppingcart.') > 0) {
        //初始化购物车页
        initShoppingCart();
    }
    //else if (winHref.indexOf('/store_index.') > 0) {
    //    //初始化店铺首页
    //    initStoreIndex();
    //}
    else if (winHref.indexOf('/baike/list.') > 0) {
        //加载最近浏览的百科
        getFocusBaike(10);
    }
    else if (winHref.indexOf('/baike/add.') > 0) {
        //加载最近浏览的百科
        getFocusBaike(10);

        //显示“提交成功/失败”信息
        showBKMSG();
    }
    else if (winHref.indexOf('/baike/details.') > 0) {
        //显示“提交成功/失败”信息
        showMSG();

        var bkid = -1;
        try { bkid = parseInt(getRequestParameter("id"), 10); } catch (e) { }
        if (bkid > 0) setFocusBaike(bkid);
    }
    else if (winHref.indexOf('/baike/view.') > 0) {
        //显示“提交成功/失败”信息
        showBKMSG();

        var bkid = -1;
        try { bkid = parseInt(getRequestParameter("id"), 10); } catch (e) { }
        if (bkid > 0) setFocusBaike(bkid);
    }
});


//-----------------------------------------------------------------------------
//
//显示对话框+遮罩层
//width: 对话框宽度
//height: 对话框高度
//content: 对话框中显示的内容HTML
//bMask: 是否显示遮罩层
//callbackFun: 关闭对话框后执行的事件
function showDialog2(width, height, content, bMask, callbackFun) {
    if (jQuery(".msg_box").length == 0) {

        jQuery("body").append("<div class=\"msg_box\"><div class=\"msg_box2\"><div class=\"msg_content\"></div><div class=\"msg_buttons\"><input type=\"button\" name=\"button2\" class=\"msg_buttonclose\" value=\"关闭\" /></div></div></div>")

        jQuery(".msg_buttonclose", jQuery(".msg_box")).bind("click", function () {
            jQuery(".msg_box").hide();
            if (bMask == null) { winMask.hide(); }
            if (callbackFun != null) {
                callbackFun();
            }
        });
    }

    var $msgbox = jQuery(".msg_box");

    $msgbox.css({ width: function () { return width; }, height: function () { return height; }, top: function () { return (jQuery(window).scrollTop() + (jQuery(window).height() - height) / 2 - 10); }, left: function () { return (jQuery(document).width() - width) / 2; } });

    jQuery(".msg_box2", $msgbox).css({ width: function () { return width - 3 }, height: function () { return height - 3 } });

    jQuery(".msg_content", $msgbox).css({ width: function () { return width - 3 }, height: function () { return height - 40 } }).html(content);

    if (bMask == null) {
        winMask.show();
    }
    $msgbox.show();
}

//在父页面中显示对话框+遮罩层
function showDialog3(width, height, content, bMask, callbackFun) {
    if (jQuery(".msg_box").length == 0) {

        window.parent.jQuery("body").append("<div class=\"msg_box\"><div class=\"msg_box2\"><div class=\"msg_content\"></div><div class=\"msg_buttons\"><input type=\"button\" name=\"button2\" class=\"msg_buttonclose\" value=\"关闭\" /></div></div></div>");

        var $msgbox = window.parent.jQuery(".msg_box");

        window.parent.jQuery(".msg_buttonclose", ".msg_box").bind("click", function () {
            window.parent.jQuery(".msg_box").hide();
            if (bMask == null) { window.parent.winMask.hide(); }
            if (callbackFun != null) {
                callbackFun();
            }
            else {
                $msgbox.hide();
                $msgbox.width("0px");
                $msgbox.height("0px");

                $msgbox.remove();

            }
        });
    }

    $msgbox.css({ width: function () { return width; }, height: function () { return height; }, top: function () { return (jQuery(window).scrollTop() + height) }, left: function () { return (jQuery(document).width() - width) / 2 + 280 } });

    window.parent.jQuery(".msg_box2", $msgbox).css({ width: function () { return width - 3 }, height: function () { return height - 3 } });

    window.parent.jQuery(".msg_content", $msgbox).css({ width: function () { return width - 3 }, height: function () { return height - 40 } }).html(content);

    if (bMask == null) {
        window.parent.winMask.show();
    }
    window.top.showFrameBox(".msg_box");
}

//显示对话框+遮罩层
//width: 对话框宽度
//height: 对话框高度
//dom: 对话框中显示的已知控件对象
//bMask: 是否显示遮罩层
//callbackFun: 关闭对话框后执行的事件
function showDialog(width, height, dom, bMask, callbackFun) {
    showDialog2(width, height, jQuery(dom).html(), bMask, callbackFun);
}

//在父页面中显示对话框+遮罩层
function showDialog1(width, height, dom, bMask, callbackFun) {
    showDialog3(width, height, jQuery(dom).html(), bMask, callbackFun);
}


//-----------------------------------------------------------------------------
//商品对比页使用
//商品对比：表单目标“阿里巴巴”，Form提交，去阿里巴巴搜索同名商品
function GotoA1688(obj) {
    var pname = jQuery(".cpxx_bt_l", jQuery(obj).parent().parent().parent().parent()).text();
    if (window.frames["db"]) {
        window.frames["db"].souA1688(pname);
    }
}
//商品对比：表单目标“慧聪网”，Form提交，去慧聪网搜索同名商品
function GotoHC360(obj) {
    var pname = jQuery(".cpxx_bt_l", jQuery(obj).parent().parent().parent().parent()).text();
    if (window.frames["db"]) {
        window.frames["db"].souHC360(pname);
    }
}

//-----------------------------------------------------------------------------
//商品详细页使用
//商品对比：表单目标“阿里巴巴”，Form提交，去阿里巴巴搜索同名商品
function gotoA1688() {
    var pname = jQuery(".cpxx_bt_l").text();
    if (window.frames["db"]) {
        window.frames["db"].souA1688(pname);
    }
}
//商品对比：表单目标“慧聪网”，Form提交，去慧聪网搜索同名商品
function gotoHC360() {
    var pname = jQuery(".cpxx_bt_l").text();
    if (window.frames["db"]) {
        window.frames["db"].souHC360(pname);
    }
}

//-----------------------------------------------------------------------------
//分页控件使用
//初始分页控件中页码跳转事件
function GetGoPage(obj) {
    if (event.keyCode == 13) {
        var maxpage = parseInt(obj.max);
        var gopage = parseInt(obj.value);
        if (isNaN(gopage) || gopage > maxpage) {
            obj.value = "";
        }
        else {
            window.location = setRequestParameter("pageindex", obj.value);
        }
        event.returnValue = false;
    }
}

//-----------------------------------------------------------------------------
//空操作
function noop() { }

