﻿var cdnCss = "http://css1.cdn.tradejob.net";
/*  Public JavaScript
/*--------------------------------------------------------------------------*/
/*onkeyNextPage*/
window.document.onkeydown = function (event) {
    var keyCode = getkeycode(event);

    if (keyCode == "37" && document.getElementById("PreviousPage") != null) {
        window.location.href = document.getElementById("PreviousPage").href;
    } else if (keyCode == "39" && document.getElementById("NextPage") != null) {
        window.location.href = document.getElementById("NextPage").href;
    }
}
/*onkeyNextPage*/

/*分组下的产品列表的产品描述*/
var li, i, liid, __id, len, isAllShowLi = false;
function ShowHiddenLi() {
    if (isAllShowLi) { return; }
    isAllShowLi = true;
    var modelname = $("#morebtn").attr("modelname");
    i = parseInt(arguments[1]);
    __id = arguments[0];
    li = $("#" + __id).find("li");
    len = $("#" + __id).find("li").length;
    if (len <= i) { return; }
    var isShow = false; if (li.eq(i).css("display") == "none") { isShow = true; }
    if (isShow) {
        li.slice(i).show(len * 10, function () { $("#morebtn").attr("src", cdnCss + "/showroom/css/" + modelname + "/img/subtract.gif"); isAllShowLi = false; });
    } else {
        li.slice(i).hide(len * 10, function () { $("#morebtn").attr("src", cdnCss + "/showroom/css/" + modelname + "/img/plus.gif"); isAllShowLi = false; });
    }
}
/*分组下的产品列表的产品描述*/

/*语言选择*/
var showID, hiddenID;
function showlanguagelist() {
    try
    { window.clearTimeout(hiddenID); } catch (ex) { }
    showID = setTimeout(
        function block() {
            document.getElementById('sel_btn').className = 'selon'; document.getElementById('languageList').style.display = 'block';
        }
        , 100);
}
function hiddenlanguagelist() {
    try
    { window.clearTimeout(showID); } catch (ex) { }
    hiddenID = setTimeout(
        function none() {
            document.getElementById('sel_btn').className = 'sel'; document.getElementById('languageList').style.display = 'none';
        }
    , 300);
}
/*语言选择*/
/*导航 nav*/
var showNavID, hiddenNavID;
function showNextBar() {
    try { window.clearTimeout(hiddenNavID); } catch (ex) { }
    var navId = arguments[0];
    showNavID = setTimeout(
    function blockNav() {
        $("div[id^='zdybar_']").css("display", "none"); $("a[id^='firstbar_']").attr("class", "");
        $("#zdybar_" + navId).css("display", ""); $("#firstbar_" + navId).attr("class", "on");
    }, 50);
}
function hiddenNextBar() {
    try { window.clearTimeout(showNavID); } catch (ex) { }
    var navId = arguments[0];
    hiddenNavID = setTimeout(function noneNav() {
        $("div[id^='zdybar_']").css("display", "none");
        $("a[id^='firstbar_']").attr("class", "");
        if ($.trim($("#firstBarID").val()) != "") { $("#" + $("#firstBarID").val()).attr("class", "on"); }
    }, 60);
}
$(function () {
    $("div[id^='zdybar_']").css("display", "none");
    $("#firstBarID").val('');
    try {
        var host = "http://" + location.host;
        var url = location.href.replace(host, "");
        $("a[id^='firstbar_']").each(function () {
            if (url == $(this).attr("href").replace(host, "")) {
                $(this).attr("class", "on");
                $("#firstBarID").val($(this).attr("id"));
            }
            else {
                $(this).attr("class", "");
            }
        })
    } catch (ex) { }
})
/*导航 nav*/
function setStyleCSSCookies() {
    $.ajax({
        type: "get",
        url: "/js/ajax/setModelColor.aspx",
        data: "Config_ModelName=" + arguments[0] + "&Config_Color=" + arguments[1] + "&Math=" + Math.random(),
        success: function (html) {
            window.location.reload();
        }
    })
}

/*切换左侧的联系方式*/
function contact() {
    $.ajax({
        type: "get",
        url: "/js/ajax/contact.aspx",
        data: "Num=" + arguments[0] + "&ishome=" + arguments[1] + "&Math=" + Math.random(),
        success: function (html) {
            if (html.indexOf("页面出错呐") == -1)
                $("#technical").html(html);
            else
                $("#technical").html("请完善联系信息");
        }
    })
}
/*切换左侧的联系方式*/

/*产品分组*/
var catefilterLi;
var catefilterState = true;
function openNextGroup() {
    var obj = arguments[0];
    var categoriesShowtype = $("#categoriesShowtype").val();
    if (categoriesShowtype == "1") {
        // if(catefilterState){catefilterState=false;
        catefilterLi = $(obj).parent().attr("id");
        $("li[id^='Cli_']").find("ul").hide();
        $(obj).parent().find("ul").slideDown(100, function () {
            $(obj).parent().attr("class", "jian"); catefilterState = true;
            $("#" + catefilterLi).find("ul").mouseoutHide(catefilterLi);
        });
        // }
    }
    else {
        if (catefilterLi != $(obj).parent().attr("id") && catefilterState) {
            catefilterLi = $(obj).parent().attr("id");
            //  setTimeout(function(){
            //   catefilterState = false;
            $("#catefilter li").find("ul").stop(true, true);
            //   $("#catefilter li").find("ul").slideUp(500,function(){
            $(obj).parent().find("ul").slideDown(300, function () { $(obj).parent().attr("class", "jian"); catefilterState = true; });
            //    });
            //  },800)
        }
    }
}
/*产品分组*/

/*search*/
function gosearch() {
    var searchterm = arguments[0].replace(/[\,]+/g, " ").replace(/(^\s*)|(\s*$)/g, "");
    if (searchterm.length < 2 || searchterm == arguments[1]) {
        alert(arguments[1]);
    } else {
        window.location.href = arguments[2].replace("$searchterm$", encodeURIComponent(searchterm));
    }
}
/*search*/

/*addCard*/
function addCard() {
    document.getElementById("cartlabel_" + arguments[0]).innerHTML = "<img src=\"" + cdnCss + "/showroom/css/comm/loading.gif\" width=\"15\" align=\"absmiddle\" />Adding...";
    $.ajax({
        type: "get",
        url: "/js/ajax/cardOperate.aspx",
        data: "Rnd=" + Math.random() + "&addlist=" + arguments[0] + "&operate=add",
        success: function (html) {
            setTimeout(
            function () {
                document.getElementById("cartlabel_" + html).innerHTML = "<a href=\"/cart.do\" class=\"mycard\"><img src=\"" + cdnCss + "/showroom/css/comm/ok.gif\" width=\"15\" style=\"border:0px;\" align=\"absmiddle\" />My Cart</a>";
                /*set Card Number*/
                try { document.getElementById("cardnumber").innerHTML = parseInt(document.getElementById("cardnumber").innerHTML) + 1; } catch (ex) { };
                /*set Card Number*/
            },
            1000);
        }
    })
}
/*addCard*/

/*viewcard*/
$(function () {
    $.ajax({
        type: "get",
        url: "/js/ajax/cardOperate.aspx",
        data: "Rnd=" + Math.random() + "&operate=view",
        success: function (html) {
            try { document.getElementById("cardnumber").innerHTML = "0"; } catch (ex) { }
            var arr = new Array();
            arr = html.split(",");
            var thislable = document.getElementsByTagName("div");
            for (var p = 0; p < thislable.length; p++) {
                for (var i = 0; i < arr.length; i++) {
                    if (thislable[p].id == "cartlabel_" + arr[i])
                        document.getElementById("cartlabel_" + arr[i]).innerHTML = "<a href=\"/cart.do\" class=\"mycard\"><img src=\"" + cdnCss + "/showroom/css/comm/ok.gif\" width=\"15\" style=\"border:0px;\"  align=\"absmiddle\" />My Cart</a>";
                }
            }
            /*set Card Number*/
            try { if (html != "") { document.getElementById("cardnumber").innerHTML = arr.length; } } catch (ex) { }
            /*set Card Number*/
        }
    })
});
/*viewcard*/

function translateGOOGLE() { window.open(arguments[0].replace("$url$", this.location)); }


/*浮动工具条*/
$(function () {
    if ($("#tools")[0] != undefined) {
        $("#tools").load("/js/ajax/rightTools.aspx?Math=" + Math.random(), function () { $('#tools').pngFix(); });
    }
});
var rightTools = false;
function toBig() {
    if (rightTools == false) {
        rightTools = true;
        $("#toolsDIV").animate({ marginLeft: "0px" }, 300, function () { $("#toolsDIV").mouseoutTool(-152, 300); rightTools = false; });
    }
}
/*浮动工具条*/

/*详细页面产品图片切换*/
function ProductsDescSeePic() {
    var numId = arguments[1];
    var thispic = $(arguments[0]);
    var objPic = $("#viewPic");
    if (numId != objPic.attr("num")) {
        objPic.animate({ opacity: "0.8" }, 100, function () {
            var objImage = new Image();
            objImage.onload = function () {
                objPic.attr("src", objImage.src);
                $("#viewLagerPic").attr("href", objPic.attr("hrefSrc").replace(/[\'|\"]+/g, "").replace("$num$", numId));
                objPic.attr("num", numId)
                thispic.parent().children().removeClass("on");
                thispic.addClass("on");
                if (objPic.attr("Magnifier") != "0")
                    $("#viewLagerPic").CloudZoom();
                objPic.animate({ opacity: "1.0" }, 100);
            }
            objImage.src = objPic.attr("srcFmt").replace(/[\'|\"]+/g, "").replace("$num$", numId);
        });
    }
}
/*详细页面产品图片切换*/

/*标签系统JS 首页厂房图切换*/
var plantMove;
var plantMaxLength = $("#plantPageNum").find("a").length;
var thisPlantPicNum = 0;
function seePlantPic() {
    var numId = arguments[1];
    var thispic = arguments[0];
    var objPlantPic = $("#PlantImageShow");
    objPlantPic.animate({ opacity: "0.2" }, 500, function () {
        var plantImage = new Image();
        plantImage.onload = function () {
            $("#PlantImageShow").attr("src", plantImage.src);
            $("#plantPageNum").find("a").removeClass("on");
            $(thispic).addClass("on");
            thisPlantPicNum = parseInt($(thispic).text()) - 1;
            objPlantPic.animate({ opacity: "1.0" }, 500);
        }
        plantImage.src = objPlantPic.attr("srcFmt").replace(/[\'|\"]+/g, "").replace("$num$", numId);
    });
}

function relPlantPlay() {
    plantMaxLength = $("#plantPageNum").find("a").length;
    if (plantMaxLength <= 1) { return false; }
    plantMove = setInterval(function () {
        var charNum = 'a';
        if (++thisPlantPicNum == plantMaxLength) { thisPlantPicNum = 0; }
        switch (thisPlantPicNum) {
            case 0: charNum = "a"; break;
            case 1: charNum = "b"; break;
            case 2: charNum = "c"; break;
            case 3: charNum = "d"; break;
        }
        seePlantPic($("#plantImage_" + charNum)[0], charNum);
    }, 5000)
}
function stopRelPlantPlay() { try { window.clearInterval(plantMove); } catch (ex) { } }
/*标签系统JS 首页厂房图切换*/
/*产品列表*/
/*列表显示形式 大图显示*/
var isFristLoad = true;
var operateID
function prouduclistLoad() {
    if (isFristLoad) {
        var loadHrml = "<div class=\"bigProImg\" id=\"maxPic\"><a href=\"#\" id=\"biglink\" target=\"_blank\">";
        loadHrml += "<img id=\"maxPicImg\" width=\"229\" heigth=\"229\" src=\"/user/showroom/comm/img/noll.jpg\" /></a></div>";
        $("body").append(loadHrml);
        $("#maxPic").bind("mousemove", function () { maxpicOperate("show"); });
        $("#maxPic").bind("mouseout", function () { maxpicOperate("hidden"); });
        isFristLoad = false;
    }
    $("#maxPic").hide();
}
var maxPic__;
var operateState;
function maxpicOperate() {
    if (arguments.length == 2) { maxPic__ = arguments[0]; operateState = arguments[1]; }
    else { operateState = arguments[0]; }
    try { window.clearTimeout(operateID); } catch (ex) { }
    operateID = setTimeout(
        function operateMath() {
            if (operateState == "show") {
                $("#biglink").attr("href", $("#img_" + $(maxPic__).attr("id")).attr("maxlink"));
                $("#maxPicImg").attr("src", $("#img_" + $(maxPic__).attr("id")).attr("maxSrc"));
                $("#maxPic").css("top", $(maxPic__).offset().top + "px");// alert(($(maxPic__).offset().left - 5));
                $("#maxPic").css("left", ($(maxPic__).offset().left - 5) + "px");
                $("#maxPic").show();
                maxPicImg.src = $("#img_" + $(maxPic__).attr("id")).attr("maxSrc");
            } else
                $("#maxPic").hide();
        }
        , 200);

}
/*列表显示形式 大图显示*/

function viewShow() {
    var this_Gallery = arguments[0];
    $.ajax({
        type: "get",
        url: "/js/ajax/setautoShowType.aspx",
        data: "this_Gallery=" + this_Gallery + "&Math=" + Math.random(),
        success: function (html) {
            if (html == "true")
                window.location.reload();
        }
    })

}
/*产品列表*/
/*VipLogin登录*/
function checkVipLogin() {
    var cerCode = $("#CerCode").val()
    var userNo = $("#VipUserNo").val()
    var pwd = $("#VipPwd").val()
    if (userNo == "") { return alert('用户名不可以为空') }
    if (pwd == "") { return alert('密码不可以为空') }
    if (cerCode == "") { return alert('请填写验证码'); }
    $.ajax({
        type: 'get',
        url: "/js/ajax/vipLogin.aspx?cerCode=" + cerCode + "&pwd=" + pwd + "&userNo=" + userNo + "&math=" + Math.random(),
        success: function (_result) {
            if (_result == "errorCerCode") { return alert('验证码填写错误'); }
            else if (_result == "errorUserNo") { return alert('用户名错误'); }
            else if (_result == "errorPwd") { return alert('密码填写错误'); }
            else if (_result == "offVipUser") { return alert('该用户被屏蔽'); }
            else if (_result == "vipLinks") {
                var urlLinks = $("#VipProductsListLinkUrl").val()
                window.open(urlLinks);
            }
        }
    });
}
/*VipLogin登录*/
/*购物车删除*/
function deleteBasketPro() {
    var operateValue = $("#operateValue").val()
    var operate = $("#operate").val()
    $.ajax({
        type: 'get',
        url: "/js/ajax/DeleteBasketProduct.aspx?operate=" + operate + "&operateValue=" + operateValue + "&math=" + Math.random(),
        success: function (_result) {
            if (_result != "false")
            { return window.location.reload(); }
            else { return alert('删除失败！'); }
        }
    });
}
/*购物车删除*/
/*delCard*/
function deleteSelectCard() {
    var idlist = getCheckedIdlist(0, 8, "inquiry_");
    if (idlist != "") {
        if (confirm(document.getElementById("confirmTips").value)) {
            document.getElementById("operate").value = "delete";
            document.getElementById("operateValue").value = idlist;
            deleteBasketPro();
        }
    } else
        alert(document.getElementById("worryTips").value);
}
/*delCard*/

/*发送询盘*/
function sendinquiry() {
    var contactinfo = trim(document.getElementById("SendMessage1_senddesc").value);
    if (contactinfo.length < 20 || contactinfo.length > 3000 || contactinfo == "Enter your message here") {
        alert("Enter between 20 to 3,000 characters, English only.");
    } else {
        document.getElementById("sendform").submit();
    }
}
sendinquiry_dialogFirst = true;
function sendinquiry_ajax() {
    var operate = "";
    if (arguments.length > 0) { operate = arguments[0]; }
    var Email = $.trim($("#txtSendEmail").val());
    var ContactName = $.trim($("#txtContactName").val());
    var Mobile = $.trim($("#txtMobile").val());
    var Phone = $.trim($("#txtPhone").val());
    var Title = $.trim($("#txtSendTitle").val());
    var SendDesc = $.trim($("#txtSendDesc").val());
    var ProductsGuid = $("#txtProductsGuid")[0] != undefined ? ($("#txtProductsGuid").val()) : "";
    var ProductsGuidList = $("#txtProductsGuidList")[0] != undefined ? ($("#txtProductsGuidList").val()) : "";
    var Fax = $("#txtFax")[0] != undefined ? ($("#txtFax").val()) : "";
    var WebSite = $("#txtWebSite")[0] != undefined ? ($("#txtWebSite").val()) : "";
    var Address = $("#txtAddress")[0] != undefined ? ($("#txtAddress").val()) : "";
    var CerCode = $("#txtCerCode")[0] != undefined ? ($("#txtCerCode").val()) : "";

    var state = true;
    if (!v_emailtest(Email)) { alert($("#txtSendEmail").attr("WorryText")); state = false; return; }
    if ($.trim($("#txtContactName").attr("defValue")) == ContactName) { ContactName = ""; }
    if ($.trim($("#txtMobile").attr("defValue")) == Mobile) { Mobile = ""; }
    if ($.trim($("#txtPhone").attr("defValue")) == Phone) { Phone = ""; }
    if ($("#TelIsMust").val() == "0") {
        if (ContactName.length < 2) { alert($("#txtContactName").attr("WorryText")); state = false; return; }
        if (Mobile.length < 6 && Phone.length < 6) {
            alert($("#txtPhone").attr("WorryText"));
            state = false;
            return;
        }
    }
    if (Title.length < 2 || $("#txtSendTitle").attr("defValue") == Title) { alert($("#txtSendTitle").attr("WorryText")); state = false; return; }
    if (SendDesc.length < 20 || SendDesc.length > 3000 || SendDesc == $("#txtSendDesc").attr("defValue")) {
        alert($("#txtSendDesc").attr("WorryText")); state = false; return;
    }
    if (operate != "sendpage") {
        if (!$("#chkSendMail").attr("checked")) {
            alert($("#noCheck").val());
            state = false;
            return;
        }
    }
    if (state) {
        if (sendinquiry_dialogFirst == true) {
            var temp_float;
            temp_float = "<div id=\"floatBoxBg\" style=\"height:" + ($(document).height() - 4) + "px;filter:alpha(opacity=0);opacity:0;width:100%;background:#000;position:absolute; z-index:99998; top:0;left:0;\"></div>";
            temp_float += "<div id=\"floatBox\" style=\"position:absolute;top:" + ($(document).scrollTop() + 200) + "px; left:50%; z-index:99999;display:none;\"><img src=\"" + cdnCss + "/showroom/css/comm/sendloading.gif\"/></div>";
            $("body").append(temp_float);
            sendinquiry_dialogFirst = false;
        }
        $("#floatBoxBg").show();
        $("#floatBoxBg").animate({ opacity: "0.5" }, 300, function () {
            $("#floatBox").show();
            $.ajax({
                type: "post",
                url: "/js/ajax/sendInquiry.aspx",
                data: "Rnd=" + Math.random() + "&operate=" + encodeURIComponent(operate) + "&Email=" + encodeURIComponent(Email) + "&ContactName=" + encodeURIComponent(ContactName)
                 + "&Mobile=" + encodeURIComponent(Mobile) + "&Phone=" + encodeURIComponent(Phone) + "&Title=" + encodeURIComponent(Title) + "&DescInfo=" + encodeURIComponent(SendDesc)
                 + "&Fax=" + encodeURIComponent(Fax) + "&WebSite=" + encodeURIComponent(WebSite) + "&Address=" + encodeURIComponent(Address) + "&CerCode=" + encodeURIComponent(CerCode) + "&ProductsGuid=" + encodeURIComponent(ProductsGuid) + "&ProductsGuidList=" + encodeURIComponent(ProductsGuidList),
                success: function (html) {
                    if (html.split('|').length == 2 && html.split('|')[0] == "true") {
                        $("#floatBox").hide(200, function () {
                            $("#floatBoxBg").animate({ opacity: "0" }, 200, function () {
                                if (operate == "sendpage") { window.location.href = html.split('|')[1]; return; }
                                else { alert(html.split('|')[1]); }
                                $("#floatBoxBg").hide();
                            });
                            $("#txtSendTitle").val($("#txtSendTitle").attr("defValue"));
                            $("#txtSendDesc").val($("#txtSendDesc").attr("defValue"));
                        });
                    }
                    else if (html.split('|').length == 2 && html.split('|')[0] != "true") {
                        $("#floatBox").hide(200, function () { $("#floatBoxBg").animate({ opacity: "0" }, 200, function () { alert(html.split('|')[1]); $("#floatBoxBg").hide(); }); });
                    } else {
                        $("#floatBox").hide(200, function () { $("#floatBoxBg").animate({ opacity: "0" }, 200, function () { $("#floatBoxBg").hide(); }); });
                    }
                },
                error: function () { $("#floatBox").hide(200, function () { $("#floatBoxBg").animate({ opacity: "0" }, 200, function () { $("#floatBoxBg").hide(); }); }) }
            })
        });
    }
}
function trim() { return arguments[0].replace(/(^\s*)|(\s*$)/g, ""); }

//contactNow
function contactNow() {
    var idlist = getCheckedIdlist(0, 8, "inquiry_");
    if (idlist != "") {
        $("#txtSendProductsGuidList").val(idlist);
        $("#allcontacus").submit();
    }
    else
        alert(document.getElementById("contactUsWorryTips").value);
}
/*发送询盘*/
/*统计流量*/
$(document).ready(function () {
    if ($("#thisSeoMemberGuid")[0] != undefined && $("#thisSeoUseLanguage")[0] != undefined) {
        var ImportUrl = window.encodeURIComponent(document.referrer);
        var ThisPageUrl = window.encodeURIComponent(location.href);
        var MemberGuid = $("#thisSeoMemberGuid").val();
        var UseLanguage = $("#thisSeoUseLanguage").val();
        if (ImportUrl != ThisPageUrl) {
            var html = "<iframe width=\"0\"\
              height=\"0\" frameborder=\"0\" scrolling=\"no\"\
              src=\"http://service.admin.tradejob.net/CountSystem/WriteAccess.aspx?ImportUrl=" + ImportUrl + "&ThisPageUrl=" + ThisPageUrl + "&MemberGuid=" + MemberGuid + "&UseLanguage=" + UseLanguage + "&math=" + Math.random() + "\"\
              vspace=\"0\" hspace=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>";
            $("body").append(html);
        }
    }
});
/*统计流量*/
