﻿$(document).ready(function() {
    menuSlide();
    categorySlide();
    brandSlide();
    tabs("tabA");
    tabs("tabB");
    tabs("tabC");
    tabs("orderWrap");
    $("#introBanner").slideDown(600);
    //$("#sideNav").children('dl').children('dd').hide();
    //$("#sideNav dl dd").hide();
    //$("#sideNav").children('dl').children('dt').children('span').eq(0).click();
    //$("#sideNav dl dt a").eq(0).click();
    prepareImg();
});
function tabs(s) {
    var styleWrap = "." + s;
    var tabsClass = $(styleWrap);
    if (tabsClass.length) {
        styleWrap = "." + s;
        $(styleWrap + " .tabs").children('li').children('a').click(function() {
            var tabsIdName = $(this).parents(styleWrap).get(0).id;
            var tab = $(this).parents("ul").children("li");
            var tabNum = tab.length;
            tab.removeClass("over");
            $(this).parent().addClass("over");
            for (var i = 1; i <= tabNum; i++) {
                $("#" + tabsIdName + "_" + i).css("display", "none");
            }
            $("#" + tabsIdName + "_" + this.rel).css("display", "").show();
            return false;
        });
    }
}
function menuSlide() {

    //var clickObj = $("#sideNav dt a");
    var clickObj = $("#sideNav").children('dl').children('dt').children('span')
    if (clickObj.length) {
        $(clickObj).click(function() {
            if (this.className == "btnShow") {
                $(clickObj).addClass("btnShow").removeClass("btnHide");
                $("#sideNav dl dd").hide();
                this.className = "btnHide";
                $(this).parents("dl").children("dd").show();
            } else {
                this.className = "btnShow";
                $(this).parents("dl").children("dd").hide();
            }
        });
    }
}
function categorySlide() {
    var clickObj = $("#allCategory .boxATop span");
    if (clickObj.length) {
        $(clickObj).click(function() {
            if (this.className == "btnShow") {
                $(clickObj).addClass("btnShow").removeClass("btnHide");
                $("#allCategory .boxAMain").hide();
                this.className = "btnHide";
                $(this).parents("div").children(".boxAMain").show();
            } else {
                this.className = "btnShow";
                $(this).parents("div").children(".boxAMain").hide();
            }
        });
    }
}
function brandSlide() {
    var clickObj = $("#allBrand .boxATop span");
    if (clickObj.length) {
        $(clickObj).click(function() {
            if (this.className == "btnShow") {
                $(clickObj).addClass("btnShow").removeClass("btnHide");
                $("#allBrand .boxAMain").hide();
                this.className = "btnHide";
                $(this).parents("div").children(".boxAMain").show();
            } else {
                this.className = "btnShow";
                $(this).parents("div").children(".boxAMain").hide();
            }
        });
    }
} /*Add By Milo*/
function onoff(s) {
    var objStyle = "." + s;
    var obj = $(objStyle);
    if (obj.length) {
        if ($.browser.msie) {
            obj.parent().hover(function() {
                $(this).addClass("over");
            }, function() {
                obj.parent().removeClass("over");
            });
        } else {
            obj.parent().mouseover(function() {
                $(this).addClass("over");
            }).mouseout(function() {
                $(this).removeClass("over");
            });
        }
    }
}
function onoffDelay(s, obj) {
    var timer, timer2;
    var objStyle = "." + s;
    //var obj =  //$(objStyle)
    //var obj = $("#menuList").children('li').children('.subMenu')

    obj.parent().mouseover(function() {
        var current = $(this);
        if (current.find(objStyle).css("display") == "block") {
            current.addClass('over');
            clearTimeout(timer2);
        } else {
            timer = setTimeout(function() {
                current.addClass('over');
            }, 300);
        }
    }).mouseout(function() {
        var current = $(this);
        if (timer) {
            clearTimeout(timer);
            timer2 = setTimeout(function() {
                current.removeClass('over');
            }, 300);
        }
    });
    obj.mouseover(function() {
        $(this).parent().addClass('over');
    });
}
function hideAD() {
    $("#introBanner").slideUp(600);
}
function switchStyle(o, oldC, newC) {
    $("#products").removeClass("list" + oldC).addClass("list" + newC);
    $(o).parent().html('<span class="current"></span>');

    var aHtml = $('<a href="#link"></a>');
    $("#productList .display .show" + oldC).empty().append(aHtml);
    aHtml.click(function() { switchStyle(this, newC, oldC) });


    switchStyleInCookie(newC);
}

function switchStyleInCookie(style) {
    var v = '';
    if (style == 'Row') {
        v = '2';
    }
    if (style == 'Grid') {
        v = '1';
    }
    if (v != "") {
        $.get(Env.CommonAjaxUrl, { type: v, op: 'DisplayType' }, null);
    }
}

function show(s, obj) {
    if ($(obj).css("display") == "none") {
        $(obj).show();
        $(s).removeClass("show");
        $(s).addClass("hide");
    } else {
        $(obj).hide();
        $(s).removeClass("hide");
        $(s).addClass("show");
    }
}
function iniUnit(wrapId, id, dftNum, intStep) {
    //参数：外容器ID，容器ID，默认显示个数，每次移动个数
    var obj = $("#" + id).find(".moveUnit");
    var objNum = obj.length;
    if (objNum > dftNum) {
        addEvent(wrapId, id, dftNum, "next", intStep)
    }
}
function addEvent(wrapId, id, dftNum, strPN, intStep) {
    var strTitle;
    var objClick = $("#" + wrapId + " ." + strPN + "View");
    var objNumHref = objClick.find("a").length;
    objClick.removeClass(strPN + "Stop");
    if (objNumHref != 0)
        objClick = objClick.find("a");
    strTitle = objClick.find("span").text();
    objClick.attr("title", strTitle);
    objClick.click(function() {
        moveUnit(wrapId, id, dftNum, strPN, intStep);
        return false;
    });
}
function moveUnit(wrapId, id, dftNum, strPN, intStep) {
    //参数：外容器ID，容器ID，默认显示个数，前后方向，每次移动个数
    if ($("#" + wrapId).data("currSubName") != null)
        id = $("#" + wrapId).data("currSubName");
    var n = $("#" + id).data("nowUnit");
    if (isNaN(n)) n = 0;
    var objClick = $("#" + wrapId + " ." + strPN + "View");
    var objNumHref = objClick.find("a").length;
    objClick.removeClass(strPN + "Stop");
    if (objNumHref != 0)
        objClick = objClick.find("a");
    var obj = $("#" + id).find(".moveUnit");
    var objNum = obj.length;
    if (strPN == "next") {
        for (var i = 0; i < intStep; i++) {
            if (wrapId === "scrollTable")
                $(obj[n]).hide();
            else
                $(obj[n]).hide("fast");
            if (n == 0) {
                $("#" + wrapId + " .prevView").removeClass("prevStop");
                addEvent(wrapId, id, dftNum, "prev", intStep);
            }
            n = n + 1;
            if (n > (objNum - dftNum - 1)) {
                n = objNum - dftNum;
                $("#" + wrapId + " .nextView").addClass("nextStop");
                objClick.unbind("click").attr("title", "");
            }
        }
    } else {
        for (var i = 0; i < intStep; i++) {
            n = n - 1;
            if (wrapId === "scrollTable")
                $(obj[n]).show();
            else
                $(obj[n]).show("fast");
            if (n + dftNum + intStep == objNum) {
                $("#" + wrapId + " .nextView").removeClass("nextStop");
                addEvent(wrapId, id, dftNum, "next", intStep);
            }
            if (n <= 0) {
                n = 0;
                $("#" + wrapId + " .prevView").addClass("prevStop");
                objClick.unbind("click").attr("title", "");
            }
        }
    }
    $("#" + id).data("nowUnit", n);
}
function prepareImg() {
    var gallery = document.getElementById("thumList");
    if (!gallery) return false;
    var links = gallery.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++) {
        links[i].onmouseover = function() {
            changeImg(this);
        }
    }
}
function changeImg(whichPic) {
    var show = document.getElementById("mainShow");
    if (!show) return false;
    var src = whichPic.getAttribute("href");
    show.setAttribute("src", src);
}
var MyImgPlayer = {
    imgPlayer: function(o, xmlPath) {
        $.ajax({
            url: xmlPath,
            dataType: (jQuery.support.style) ? "xml" : "text",
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                window.xxx = XMLHttpRequest;
                window.yyy = textStatus;
                window.zzz = errorThrown;
            },
            success: function(data) {
                var xml;
                if (typeof data == "string") {
                    xml = new ActiveXObject("Microsoft.XMLDOM");
                    xml.async = false;
                    xml.loadXML(data);
                } else {
                    xml = data;
                }

                var i = 0;
                $(o).attr('data-image-length', $(xml).find("bannerAD img").length);
                $(o).attr('data-image-already_play', '');
                $(xml).find("bannerAD img").each(function() {
                    var htmlImg,
						htmlNum,
						htmlTitle;
                    htmlImg = "<li><a href='" + $(this).find("url").text() + "' title='" + $(this).find("title").text() + "' target='_blank'><img src='" + $(this).find("view").text() + "' /></a></li>";
                    i++;
                    htmlNum = "<li><span class='numVal'>" + i + "</span></li>";
                    htmlTitle = "<a href='" + decodeURIComponent( $(this).find("url").text() ) + "' class='title' target='_blank'>" + $(this).find("title").text() + "</a>";
                    $(o + " .img").append(htmlImg);
                    $(o + " .num").append(htmlNum);
                    $(o).append(htmlTitle);
                });
                if ($(xml).find("bannerAD img").length == 1) {
                    $(o + " .panel").hide();
                    $(o + " .num").hide();
                    $(o + " .title").hide();
                }
                $(o + " .img li").hide();
                $(o + " .title").hide();
                $(o + " .num li .numVal").mouseover(function() {
                    $(o + " .title").stop(false, true);
                    $(o + " .img li").stop(true, true);
                    $(o + " .num li").removeClass("over");
                    $(this).parent().addClass("over");
                    $(o + " .img li").fadeOut(1000).eq($(this).text() - 1).fadeIn(1000);
                    $(o + " .title").hide().eq($(this).text() - 1).fadeIn("slow");
                });
                MyImgPlayer.showNumImg(o);
            }
        });
    },
    showNumImg: function(o) {
        if (o.substring(0, 1) != "#") {
            o = "#" + o;
        }
        var imgCount = parseInt($(o).attr('data-image-length'));
        var alreadyPlay = $(o).attr('data-image-already_play');
        if (imgCount == 1 && alreadyPlay.length > 0) {
            return;
        }
        var n = $(o).find(".num li.over .numVal").text();
        if (n < 1 || n > $(o + " .num li").length - 1) n = 0;
        $(o + " .num li").removeClass("over").eq(n).addClass("over");
        $(o + " .img li").fadeOut(1000).eq(n).fadeIn(1000);
        if (imgCount > 1) {
            $(o + " .title").hide().eq(n).fadeIn("slow");
        }
        $(o).attr('data-image-already_play', 'true');
    }
}


//$(document).ready(function() {
//    menuSlide();
//    menuonoff();
//    tabs("tabsWrap");
//    tabs("tabsHome");
//    tabs("orderWrap");
//    noFocus();
//});
function noFocus() {
    $(":button").focus(function() {
        $(this).blur();
    });
    $(":image").focus(function() {
        $(this).blur();
    });
    $(":reset").focus(function() {
        $(this).blur();
    });
}
//function tabs(s) {
//    var styleWrap = "." + s;
//    var tabsClass = $(styleWrap);
//    if (tabsClass.length) {
//        styleWrap = "." + s;
//        $(styleWrap + " .tabs li a").click(function() {
//            var tabsIdName = $(this).parents(styleWrap).get(0).id;
//            var tab = $(this).parents("ul").children("li");
//            var tabNum = tab.length;
//            tab.removeClass("over");
//            this.parentNode.className = "over";
//            for (var i = 1; i <= tabNum; i++) {
//                $("#" + tabsIdName + "_" + i).css("display", "none");
//            }
//            $("#" + tabsIdName + "_" + this.rel).css("display", "").hide().fadeIn("slow");
//        });
//    }
//}

//function menuSlide() {
//    var clickObj = $("#sideLeft dt em");
//    if (clickObj.length) {
//        $(clickObj).click(function() {
//            if (this.className == "close") {
//                this.className = "";
//                $(this).parents("dl").children("dd").slideDown("slow");
//            } else {
//                this.className = "close";
//                $(this).parents("dl").children("dd").slideUp("slow");
//            }
//        });
//    }
//}

//function menuonoff() {
//    var objStyle = ".subNav";
//    var obj = $(objStyle);
//    if (obj.length) {
//        if ($.browser.msie) {
//            obj.parent().hover(function() {
//                $(this).addClass("over");
//            }, function() {
//                obj.parent().removeClass("over");
//            });
//        } else {
//            obj.parent().mouseover(function() {
//                $(this).addClass("over");
//            }).mouseout(function() {
//                $(this).removeClass("over");
//            });
//        }
//    }
//}

function search(v) {
    if (validataSearchKeyword()) {
        if ($.trim(v) == $.trim($("#keyword").val())) {
            return;
        }
        $('#searchForm').submit();
    }
}
function validataSearchKeyword() {
    if ($.trim($('#keyword').val()) != '') {
        return true;
    }
    else {
        window.alert(infos.CE009);
        return false;
    }
    return true;
}
function addToCart(itemCode, qty, gifts, isGroupBuyItem) {
    var para;
    if (gifts && gifts.MainItemBuyCount > 1) {
        var textFormat = infos.CM0002;
        var text = textFormat.replace(/\$\$\$Count\$\$\$/g, gifts.MainItemBuyCount + '');
        showConfirm(text, "addToCartOk('" + itemCode + "'," + qty + ",'" + JSON.stringify(gifts) + "'," + isGroupBuyItem + ")", "addToCartCancel()");
    } else {
        addToCartOk(itemCode, qty, null, isGroupBuyItem);
    }
}

function addToCartOk(itemCode, qty, gifts, isGroupBuyItem) {
    if (gifts != null) {
        para = { op: "2", itemcode: itemCode, qty: qty, productGift: gifts, isGroupBuyItem: isGroupBuyItem };
    } else {
        para = { op: "2", itemcode: itemCode, qty: qty, productGift: "", isGroupBuyItem: isGroupBuyItem };
    }
    $.getJSON(Env.ProductAjaxUrl, para,
        function(result) {
            if (result.SuccessApply) {
                window.location = Env.ShoppingCartUrl;
            }
            else {
                switch (result.ApplyMessage) {
                    case "1":
                        window.alert(infos.CE010);
                        break;
                    case "2":
                        window.alert(infos.CE011);
                        break;
                    default:
                        window.alert(infos.CE006);
                        break;
                }
            }
        }
    );
}

function addToCartCancel() {
    return false;
}

function allCategory(style) {
    if (style == "over")
        document.getElementById('allCategory').style.display = '';
    else
        document.getElementById("allCategory").style.display = "none";
}

function popTips(obj) {
    $(obj).addClass("inputOver");
    $(obj).parent("li").children(".enterTips").css("display", "");
}
function hideTips(obj) {
    $(obj).removeClass("inputOver");
    $(obj).parent("li").children(".enterTips").css("display", "none");
}


//-------------------------------------------------------------------
//   11/6/2008 Add by Steven.G.Liu(Stevent.G.Liu@newegg.com0
//   Purpose: product picture show, product pricture pop show
//-------------------------------------------------------------------
function getSrc(big, small) {
    var imgscr = big.split('//');
    var imgscr = imgscr[1].split('/');
    var width = imgscr[imgscr.length - 2];
    var imgTmpScr = "http:/";
    imgscr = small.split('//');
    imgscr = imgscr[1].split('/');
    imgscr[imgscr.length - 2] = width;
    for (var i = 0; i < imgscr.length; i++) {
        imgTmpScr = imgTmpScr + "/" + imgscr[i];
    }
    return imgTmpScr;
}

function nextClick(rel, isLi) {
    var list = $("li[rel='" + rel + "']");
    var maxIdx = list.length - 1;
    //we will move when the lastest picture is hide.
    if ($(list[maxIdx]).css("display") == "none") {
        for (var i = 0; i <= maxIdx; i++) {
            if ($(list[i]).css("display") != "none") {
                $(list[i]).css("display", "none");
                $(list[i + 5]).css("display", "");
                break;
            }
        }
    }
    reSetPrveNext();
}
function prevClick(rel, isLi) {
    var list = $("li[rel='" + rel + "']");
    if (!isLi)
        list = $("a[rel='" + rel + "']");
    var maxIdx = list.length - 1;
    //we will move when the first picture is hide.
    if ($(list[0]).css("display") == "none") {
        try {
            for (var i = maxIdx; i >= 0; i--) {
                if ($(list[i]).css("display") != "none") {
                    $(list[i]).css("display", "none");
                    $(list[i - 5]).css("display", "");
                    break;
                }
            }
        }
        catch (e) {
            //alert(e);
        }
    }
    reSetPrveNext();
}

function reSetPrveNext() {
    var list = $("li[rel='imglist']");
    var maxIdx = list.length - 1;


    if (maxIdx <= 4) {
        $("#nextLink").get(0).className = "next1";
        $("#prevLink").get(0).className = "prev1";
        return;
    }

    if ($(list[maxIdx]).css("display") == "none") {
        $("#nextLink").get(0).className = "next";
    }
    else {
        $("#nextLink").get(0).className = "next1";
    }

    if ($(list[0]).css("display") == "none") {
        $("#prevLink").get(0).className = "prev";
    }
    else {
        $("#prevLink").get(0).className = "prev1";
    }

    if (maxIdx <= 0) {
        $("#nextLink").get(0).className = "next1";
        $("#prevLink").get(0).className = "prev1";
    }
}

function getZoomSrc(small) {
    var imgTmpScr = "http:/";
    imgscr = small.split('//');
    imgscr = imgscr[1].split('/');
    imgscr[imgscr.length - 2] = Env.ImageFolderConfig.ZoomImageFolder; //"W640H480";
    for (var i = 0; i < imgscr.length; i++) {
        imgTmpScr = imgTmpScr + "/" + imgscr[i];
    }
    return imgTmpScr;
}

function showImage(ctrl, imgid, flag) {
    var src = $(ctrl).children().attr('src');
    var prodImg = $("#" + imgid);
    if (prodImg != null) {
        prodImg.attr("src", getSrc(prodImg.attr("src"), src));
        $("#aProdPic").attr("href", getZoomSrc(prodImg.attr("src")));
        if (!flag) {
            $("#popPicList .on").removeClass("on");
        }
        else {
            $(".on").removeClass("on");
        }
        $(ctrl).addClass("on");
    }
}

function getImgName(src) {
    return src;
}

function prodPicOnloand(img) {
    var list = $("#imgList > li > a"); //imgList
    img = $("#" + img).attr("src");
    $("#aProdPic").attr("href", getZoomSrc(img));
    img = getImgName(img);
    for (var i = 0; i < list.length; i++) {
        var temsrc = $(list[i]).children("img").attr("src");
        temsrc = getImgName(temsrc);
        if (temsrc == img) {
            $(list[i]).addClass("on");
            break;
        }
    }

    list = $("li[rel='imgList']"); //imgList
    if (list) {
        for (var i = 0; i < 5; i++) {
            //alert(list[i]);
            $(list[i]).css("display", "");
        }
    }

    reSetPrveNext();
}


function prodPicOnloandNew(img) {
    var list = $("#thumList > li > a"); //imgList
    img = $("#" + img).attr("src");
    $("#aProdPic").attr("href", getZoomSrc(img));
    img = getImgName(img);
    for (var i = 0; i < list.length; i++) {
        var temsrc = $(list[i]).children("img").attr("src");
        temsrc = getImgName(temsrc);
        if (temsrc == img) {
            $(list[i]).addClass("on");
            break;
        }
    }

    list = $("li[rel='thumList']"); //imgList
    if (list) {
        for (var i = 0; i < 5; i++) {
            //alert(list[i]);
            $(list[i]).css("display", "");
        }
    }

    reSetPrveNext();
}


function popLoad(imgIndex) {
    var list = $("#thumList > li");
    if (list.length == 0) {
        list = $("#imgList > li");
    }
    var popList = $("#popPicList");
    //get
    for (var i = 0; i < list.length; i++) {
        var ctrl = $(list[i]).children();
        try {
            var newOne = ctrl.clone();
            newOne.id = newOne.id + i;
            popList.append(newOne);
        }
        catch (e) {
            alert(e);
        }
    }
    //set
    try {
        popList = $("#popPicList > a");
        for (var i = 0; i < popList.length; i++) {
            $(popList[i]).attr("href", "javascript:void(0);");
            $(popList[i]).removeAttr("onclick");
            $(popList[i]).removeAttr("onmousemove");
            $(popList[i]).attr("rel", "popImgList");
            $(popList[i]).bind("click", function() { showImage(this, "popImgProd", false); reSetPopupPrveNext(); });
        }
    }
    catch (e) {
        alert(e);
    }
    //alert($("#popPicList").html());
    //set main pricture
    if (popList.length > 0) {
        var imgscr = $(popList[imgIndex]).children().attr('src');
        var width = Env.ImageFolderConfig.PopupImageFolder; //"W640H480";
        var imgTmpScr = "http:/";
        imgscr = imgscr.split('//');
        imgscr = imgscr[1].split('/');
        imgscr[imgscr.length - 2] = width;
        for (var i = 0; i < imgscr.length; i++) {
            imgTmpScr = imgTmpScr + "/" + imgscr[i];
        }
        $("#popImgProd").attr("src", imgTmpScr);
    }

    reSetPopupPrveNext();
    if (popList == 1) {
        $("a[rel='prevPopLink']").css("color", "gray");
        $("a[rel='nextPopLink']").css("color", "gray");
    }
    if (imgIndex <= 0) {
        $("a[rel='prevPopLink']").css("color", "gray");
        if (popList.length > 1) {
            $("a[rel='nextPopLink']").css("color", "");
        } else {
            $("a[rel='nextPopLink']").css("color", "gray");
        }
    }
}

function ShowPresentImage() {
    var popList = $("#popPicList > a");
    if (popList.length > 0) {
        var imgscr = $(popList[0]).children().attr('src');
        var width = Env.ImageFolderConfig.PopupImageFolder; //"W640H480";
        var imgTmpScr = "http:/";
        imgscr = imgscr.split('//');
        imgscr = imgscr[1].split('/');
        imgscr[imgscr.length - 2] = width;
        for (var i = 0; i < imgscr.length; i++) {
            imgTmpScr = imgTmpScr + "/" + imgscr[i];
        }
        $("#popImgProd").attr("src", imgTmpScr);
    }
}

function moveClick(isback) {
    var list = $("a[rel='popImgList']");
    var prodImg = $("#popImgProd");
    var maxIndex = list.length - 1;
    try {
        for (var i = 0; i <= maxIndex; i++) {
            if ($(list[i]).attr("class") == "on") {

                var ssrc;
                if (isback && i < maxIndex) {
                    $(list[i]).removeClass("on");
                    $(list[i + 1]).addClass("on");
                    ssrc = $(list[i + 1]).children().attr("src");
                }
                else if (!isback && i > 0) {
                    $(list[i]).removeClass("on");
                    $(list[i - 1]).addClass("on");
                    ssrc = $(list[i - 1]).children().attr("src");
                }
                //alert($(list[i - 1]).children().attr("src"));
                prodImg.attr("src", getSrc(prodImg.attr("src"), ssrc));
                break;
            }
        }
    }
    catch (e) {
        //            alert(e);
    }
    reSetPopupPrveNext();
}


function reSetPopupPrveNext() {
    var list = $("a[rel='popImgList']");
    var maxIdx = list.length - 1;

    if ($(list[maxIdx]).attr("class") == "on") {
        $("a[rel='nextPopLink']").css("color", "gray");
    }
    else {
        $("a[rel='nextPopLink']").css("color", "");
    }

    if ($(list[0]).attr("class") == "on") {
        $("a[rel='prevPopLink']").css("color", "gray");
    }
    else {
        $("a[rel='prevPopLink']").css("color", "");
    }

    if (maxIdx <= 0) {
        $("a[rel='nextPopLink']").css("color", "gray");
        $("a[rel='prevPopLink']").css("color", "gray");
    }

}
//--------------------------------------------------------------------------

Object.fromJSON = function(text) {
    try {
        return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\tnew Date\([0-9]\)]/.test(text.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + text + ')');
    } catch (e) {
        return false;
    };
}

//-------------------------------------------------------------------
//   Add by Henson
//-------------------------------------------------------------------
function changeURLPar(destiny, par, par_value) {
    var pattern = par + '=([^&]*)';
    var replaceText = par + '=' + par_value;
    if (destiny.match('[\?]')) {
        var h = destiny.substring(0, destiny.indexOf("?"));
        var l = destiny.substring(destiny.indexOf("?")).toLowerCase();
        destiny = h + l;
    }
    if (destiny.match(pattern)) {
        var tmp = '/\\' + par + '=[^&]*/';
        tmp = destiny.replace(eval(tmp), replaceText);
        return (tmp);
    }
    else {
        if (destiny.match('[\?]')) {
            return destiny + '&' + replaceText;
        }
        else {
            return destiny + '?' + replaceText;
        }
    }
    return destiny + '\n' + par + '\n' + par_value;
}

function jump(event, o, q, c) {
    if (event == null || (event != null && event.keyCode == 13)) {
        var v = $.trim(o.val());
        if (v == "") {
            return false;
        } else if (parseInt(v) != v || parseInt(v) <= 0) {
            window.alert(infos.CE002);
            o.val("");
            return false;
        } else if (parseInt(v) > c) {
            window.alert(infos.CE001);
            o.val("");
            return false;
        }
        window.location.href = changeURLPar(window.location.href, q.toLowerCase(), v);
        return false;
    }
}



function openWindow(u, w, h, t, l) {
    if (!(typeof (u) === "string" && u.length != 0)) {
        return;
    }
    if (((w - 0).toString() === "NaN") || w == 0) {
        w = 640;
    }
    if (((h - 0).toString() === "NaN") || h == 0) {
        h = 480;
    }
    if (((t - 0).toString() === "NaN") || t == 0) {
        t = 300;
    }
    if (((l - 0).toString() === "NaN") || l == 0) {
        l = 300;
    }
    var op = window.open(u, "_blank", "height=" + h + ",width=" + w + ",left=" + l + ",top=" + t + ",resizable=1,scrollbars=1,status=no,toolbar=no,location=0,menu=no,titlebar=0");
    if (op == null) {
        window.alert(infos.CE004);
    }
}


Date.CreateDateTime = function(t) {
    var tm = new Date();
    var split = "-";
    var splitTwo = ":";
    var year = tm.getFullYear();
    var month = tm.getMonth() + 1;
    var day = tm.getDay();
    var hh = tm.getHours();
    var mm = tm.getMinutes();
    var ss = tm.getSeconds();
    var date = year + split + month + split + day;
    var time = hh + splitTwo + mm + splitTwo + ss;
    switch (t) {
        case "1":
            return date;
        case "2":
            return date + " " + time;
        case "3":
            return time;
        default:
            return date;
    }
}


function logout() {
    $("#hidlogout").attr("value", "logout");
    $("#Logform").submit();
}
function SearchProduct(event, SearchUrl, homeUrl) {
    if (event == null || (event != null && event.keyCode == 13)) {
        var v = $.trim($("#Search").val());
        if (v == "") {
            window.location = homeUrl;
        }
        else {
            window.location = SearchUrl + "?keyword=" + v;
        }
    }
}
//-------------------------------------------------------------------
//  12/04/2008 Add by Marble.M.Wu(Marble.M.Wu@newegg.com)
//
//  Purpose: StringBuilder for javascript
//
//-------------------------------------------------------------------
var StringBuilder = function() {
    this.textArray = new Array();
};
StringBuilder.prototype.add = function(text) {
    this.textArray.push(text);
};
StringBuilder.prototype.clear = function() {
    this.textArray.length = 0;
};
StringBuilder.prototype.toString = function() {
    return this.textArray.join("");
};

//-------------------------------------------------------------------
//  12/11/2008 Add by Marble.M.Wu(Marble.M.Wu@newegg.com)
//
//  Purpose: Length for GBK/GB2312 characters
//
//-------------------------------------------------------------------
function getBytesLength(input) {
    return input.replace(/[^\x00-\xff]/g, 'sb').length;
}

function subStringByBytes(val, maxBytesLen) {
    var len = maxBytesLen;
    var result = val.slice(0, len);
    while (getBytesLength(result) > maxBytesLen) {
        result = result.slice(0, --len);
    }
    return result;
}

//-------------------------------------------------------------------
//  12/04/2008 Add by henson.j.li
//  Purpose: input just only write number
//
//----- Usage: -------------------------------------------------------
//
// onkeydown="onlyNum(event)"
//-------------------------------------------------------------------
function onlyMoney(event) {
    var e = window.event || event;
    if (!((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105) || e.keyCode == 8 || e.keyCode == 9 || e.keyCode == 190)) {
        if (document.all) {
            e.returnValue = false;
        } else {
            e.preventDefault();
        }
    }
}

function getSubCate(o, number) {
    var n, index = cur = number;
    while ((n = document.getElementById("sltCate" + (++index))) != null) {
        $(n).remove();
    }
    if ($(o).val() == "0") {
        return;
    }
    jQuery.getJSON
    (Env.CommonAjaxUrl,
    { id: $(o).val(), op: "Category" },
    function(data) {
        if (data != null) {
            var slt = $("<select class='selectForSearch' name='sltCate" + (cur + 1) + "' id='sltCate" + (cur + 1) + "' onchange='getSubCate(this," + (cur + 1) + ")'></select>");
            for (var i = 0; i < data.length; i++) {
                $("<option value='" + data[i].Id + "'>" + data[i].Name + "</option>").appendTo(slt);
            }
            $(o).after(slt);
        }
    })
}

function focusSearchText(v) {
    var sv = $.trim($('#keyword').val());
    if (sv == v) {
        $('#keyword').val('')
    }
}

function blurSearchText(v) {
    var sv = $.trim($('#keyword').val());
    if (sv == "") {
        $('#keyword').val(v);
    }
}

function createFlash(u, id, w, h, flv) {
    var params = new Object();
    params.menu = "false";
    params.wmode = "opaque";
    params.allowscriptaccess = "sameDomain";
    params.quality = "High";
    params.bgcolor = "#DFEFF9";
    var attributes = new Object();
    attributes.id = id;
    attributes.name = id;
    swfobject.embedSWF(u, id, w, h, "9.0.0", "", flv, params, attributes);
}

(function($) {
    $.fn.decorateIframe = function(options) {
        if ($.browser.msie && $.browser.version < 7) {
            var opts = $.extend({}, $.fn.decorateIframe.defaults, options);
            $(this).each(function() {
                var $myThis = $(this);
                //´´½¨Ò»¸öIFRAME
                var divIframe = $("<iframe />");
                divIframe.attr("id", opts.iframeId);
                divIframe.css("position", "absolute");
                divIframe.css("display", "none");
                divIframe.css("display", "block");
                divIframe.css("z-index", opts.iframeZIndex);
                divIframe.css("border");
                divIframe.css("top", "0");
                divIframe.css("left", "0");
                if (opts.width == 0) {
                    divIframe.css("width", $myThis.width() + parseInt($myThis.css("padding")) * 2 + "px");
                }
                if (opts.height == 0) {
                    divIframe.css("height", $myThis.height() + parseInt($myThis.css("padding")) * 2 + "px");
                }
                divIframe.css("filter", "mask(color=#fff)");
                $myThis.append(divIframe);
            });
        }
    }
    $.fn.decorateIframe.defaults = {
        iframeId: "decorateIframe1",
        iframeZIndex: -1,
        width: 0,
        height: 0
    }
})(jQuery);


//-------------------------------------------------------------------
//  3/10/2010 Add by steven.q.xu

function CustomerVote(question) {

    $("#vote").children('li').each(function(i) {
        if ($(this).find("input")[0].checked == true) {
            jQuery.getJSON
            (Env.CommonAjaxUrl,
            { aId: $(this).find("input").val(), qId: question, op: "Vote" },

            function(result) {
                if (result.Success) {
                    window.alert("投票成功");
                }
                else {
                    switch (result.Message) {
                        case "1":
                            window.alert(infos.M0001);
                            break;
                        case "2":
                            window.alert(infos.E0001);
                            break;
                        default:
                            window.alert(infos.E0001);
                            break;
                    }
                }
            }

            )
        }

    })
}

function ShowVoteResult(question) {
    var voteResult = "";
    jQuery.getJSON
    (Env.CommonAjaxUrl,
    { qId: question, op: "VoteResult" },
    function(result) {
        if (result != null) {
            for (i = 0; i < result.length; i++) {
                voteResult += "<li>" + result[i].AnswerName + "&nbsp;" + result[i].AnswerCount + "票&nbsp;" + result[i].AnswerRate + "</li>";
            }
            if (voteResult != "") {
                $("#showVoteResult").html(voteResult);
            }
            $("#vote").attr("style", "display:none");
            $("#showVoteResult").attr("style", "display:block");
            $("#btnVote").attr("style", "display:none");
            $("#btnViewResult").attr("style", "display:none");
            $("#btnCancelView").attr("style", "display:block");
        }
    })
}

function ReturnVote() {
    $("#vote").attr("style", "display:block");
    $("#showVoteResult").attr("style", "display:none");
    $("#btnVote").attr("style", "display:block");
    $("#btnViewResult").attr("style", "display:block");
    $("#btnCancelView").attr("style", "display:none");
}


function qqChat(qq) {
    var str = "tencent://message/?uin=" + qq + "&Site=www.jnzlcs.com;Menu=no\"";
    window.open(str);

}

//-------------------------------------------------------------------
//  10/22/2008 Add by Marble.M.Wu(Marble.M.Wu@newegg.com)
//  Purpose check all checkbox or uncheck all checkbox
//
//----- Usage: -------------------------------------------------------
//
//  check all checkbox : rel="checkAll"
//  single checkbox : rel="singleCheckBox"
//-------------------------------------------------------------------
$(document).ready(function() {
    $("input[rel='checkAll']").click(
    function() {
        if ($(this).attr("checked") == true) {
            $("input[rel='singleCheckBox']").each(function() {
                $(this).attr("checked", true);
                $("input[rel='checkAll']").attr("checked", true);
            });
        } else {
            $("input[rel='singleCheckBox']").each(function() {
                $(this).attr("checked", false);
                $("input[rel='checkAll']").attr("checked", false);
            });
        }
    });
    $("input[rel='singleCheckBox']").click(
    function() {
        var isCheckAll = true;
        $("input[rel='singleCheckBox']").each(function() {
            if ($(this).attr("checked") != true) {
                isCheckAll = false;
            }
            $("input[rel='checkAll']").attr("checked", isCheckAll);
        });
    });
});

function checkSelectItems() {
    var hasSelected = false;
    $("input[rel='singleCheckBox']").each(function() {
        if ($(this).attr("checked") == true) {
            hasSelected = true;
        }
    });
    return hasSelected;
}




function checkQty(originalQty, minQty, minAdd) {

    var M0001 = "<span>购买量必须是{0}的倍数！</span>";
    var M0002 = "<span>购买量必须大于{0}！</span>";
    var M0008 = "<span>请输入购买数量！</span>";
    var M0009 = "<span>数量只允许输入数字,并且最多只能有一位小数！</span>";

    if (originalQty <= 0) {
        alert(M0008);
        return false;
    }

    if (/^[0-9]+(.[0-9]{1})?$/i.test(originalQty+'') == false) {
        alert(M0009);
        return false;
    }

    if (minAdd > 0) {
        if ((originalQty * 10) % (minAdd * 10) != 0) {
            alert(M0001.replace('{0}', Math.round(minAdd * 10) / 10));
            return false;
        }
    }
    else if (minQty > 0) {
        if (originalQty < minQty) {
            alert(M0002.replace('{0}', Math.round(minQty * 10) / 10));
            return false;
        }
    }
    else if (minQty == 0) {
        if (originalQty < 1) {
            alert(M0002.replace('{0}', 1));
            return false;
        }
    }

    return true;
}
