锘縱ar inquiryurl = "/inquiry.aspx";
var cbsid = [];
var page = 1;
var isLoad = false;
var pageCount = 0;
$(function () {
delCookie("merge");
$(window).scroll(function () {
var scrollTop = $(this).scrollTop();
if (scrollTop > 150) {
$("#dv_head_float").show();
}
else {
$("#dv_head_float").hide();
}
});
$("#float_search_btn_hide").click(function () {
var kwd = $("#float_search_text").val();
window.location = "/ProductList_EN.aspx?kwd=" + encodeURIComponent(kwd);
})
$("#float_search_btn").click(function () {
$("#float_search_btn_hide").trigger("click");
});
$("#float_search_text").keyup(function (event) {
var which = event.which;
if (which == 13) {
$("#float_search_btn_hide").trigger("click");
}
});
//Set default value
//Japan
$("#float_search_btn_hide_JP").click(function () {
var kwd = $("#float_search_text_JP").val();
window.location = "/ProductList_JP.aspx?kwd=" + encodeURIComponent(kwd);
})
$("#float_search_btn_JP").click(function () {
$("#float_search_btn_hide_JP").trigger("click");
});
$("#float_search_text_JP").keyup(function (event) {
var which = event.which;
if (which == 13) {
$("#float_search_btn_hide_JP").trigger("click");
}
});
//Set default value $("#float_search_text").val(getSearchKeyWord());
$(".search_str").click(function () {
location.href = "/StructuredSearch_EN.htm";
});
//Increase paging url
$("a[data-page-number]").each(function () {
var nm = $(this).attr("data-page-number");
var url = getUrl("page", nm);
$(this).attr("href", url);
});
$(".Fil_l").on("click", "li", function () {
var data = $(this).data();
if ($(this).hasClass("Sel_h")) {
$(this).removeClass("Sel_h");
window.location.href = removeUrlSearch("page", removeUrl(data.key));
}
else {
$(this).addClass("Sel_h");
window.location.href = removeUrlSearch("page", getUrl(data.key, data.name));
}
});
$("#bt_delegate_list").click(function () {
var cas = $("#bt_delegate_list").attr("data-cas");
var productname = $("#bt_delegate_list").attr("data-productname");
cbnumber = $("#bt_delegate_list").attr("data-cbnumber");
source = $("#bt_delegate_list").attr("data-source") == "" ? "pageleft" : $("#bt_delegate_list").attr("data-source");
location.href = "/InquiryToSupplier.aspx?cas=" + cas + "&n=" + productname + "&cbnumber=" + cbnumber + "&source=" + source;
});
$(".Sel_O").click(function (event) {
var $target = $(event.target);
if ($target.hasClass("Fmore")) {
var data = $target.data();
if (data.expend) {
var $conditionElement = $(this).parent();
var condition = new Conditions($conditionElement, $target);
if (data.expend == "multiple") {
condition.multiple();
}
else {
condition.more();
}
}
}
else if ($target.hasClass("Sel_dx")) {
var data = $target.parent().data();
if (data.expend) {
var $conditionElement = $(this).parent();
var condition = new Conditions($conditionElement, $target.parent());
if (data.expend == "multiple") {
condition.multiple();
}
}
}
else if ($target.get(0).tagName == "INPUT") {
var data = $target.data();
if (data.operator) {
var $conditionElement = $target.parent();
var condition = new Conditions($conditionElement, $target);
if (data.operator == "save") {
condition.multipleSearch();
}
else {
condition.expend();
}
}
}
else if ($target.get(0).tagName == "LI" || $target.get(0).tagName == "A") {
var $conditionElement = $(this).parent();
var condition = new Conditions($conditionElement, $target);
condition.singSearch($conditionElement, $target);
}
});
displaySearchConditions();
$(".Sel_Y").on("click", "b[data-key]", function () {
var $target = $(this);
$target.parent().remove();
window.location.href = removeUrl($target.attr("data-key"));
});
var userName = $("#cookie_userName").val();
if (userName != null) {
getMyAccount();
}
var $Sel = $(".Sel_O");
var cwidth = 0;
for (var i = 0; i < $Sel.length; i++) {
cwidth = 0;
var $curSel = $("#Sel" + i);
$curSel.find("li").each(function () {
cwidth += $(this).width() + 20;
if (cwidth > 730) {
$curSel.find("span[data-expend='more']").show();
}
else {
$curSel.find("span[data-expend='more']").hide();
}
});
}
$("a[data-source='ch']").attr("href", "/ProductIndex.aspx");
$("a[data-source='en']").attr("href", "/ProductIndex_EN.aspx");
$("a[data-source='jp']").attr("href", "/ProductIndex_JP.aspx");
$("a[data-source='de']").attr("href", "/ProductIndex_DE.aspx");
$("a[data-source='kr']").attr("href", "/ProductIndex_KR.aspx");
bindEvent();
var showPage = $("#showPage").val();
var path = location.href;
if (showPage == "False" && path.indexOf("/Manufacturers/") > -1) {
loadPage();
}
})
//Multi-selection vendor displays selected quantity labels
function mergeShow(m) {
var $merge = $(".Merge").clone();
$merge.attr("style", "").attr("data-merge", true);
$merge.attr("style", "");
$merge.find(".arrow_cho").after("Contact " + cbsid.length + "/5 Suppliers");
$merge.find(".mergebox2").click(function () {
setCookie("merge", cbsid.join(","), "d1");
var delegate = $("#bt_delegate_list");
var cas = delegate.attr("data-cas");
var cbnumber = delegate.attr("data-cbnumber");
var productname = delegate.attr("data-productname");
var source = "ProductList_Supplier_Multi";
location.href = "/InquiryToSupplier.aspx?cas=" + cas + "&n=" + encodeURIComponent(productname) + "&cbnumber=" + cbnumber + "&source=" + source;
});
m.after($merge);
}
//Function: Get url address
function getUrl(name, value) {
var search = window.location.search;
value = escape(value);
if (search) {
var searchs = search.replace(/\?/g, "").split("&");
var repeater = false;
for (var i = 0; i < searchs.length; i++) {
if (searchs[i].indexOf(name + "=") == 0) {
searchs[i] = name + "=" + value;
repeater = true;
break;
}
}
if (!repeater) {
searchs.push(name + "=" + value);
}
return window.location.href.replace(search, "?" + searchs.join("&"));
}
else {
//http://book.hg.y866.cn/chemistry/Manufacturers/2-3-Bromophenyl-1-3-dioxolane.htm
//http://localhost:2755/Manufacturers/2-3-Bromophenyl-1-3-dioxolane-97/2.htm
if (window.location.href.split('/').length == 5) {
var url = "";
if (value == 1) {
url = "/" + window.location.href.split('/')[3] + "/" + window.location.href.split('/')[4].replace('.htm', '') + ".htm";
} else {
url = "/" + window.location.href.split('/')[3] + "/" + window.location.href.split('/')[4].replace('.htm', '') + "/" + value + ".htm";
}
return url;
}
else {
var url = "";
if (value == 1) {
url = "/" + window.location.href.split('/')[3] + "/" + window.location.href.split('/')[4].replace('.htm', '') + ".htm";
} else {
url = "/" + window.location.href.split('/')[3] + "/" + window.location.href.split('/')[4].replace('.htm', '') + "/" + value + ".htm";
}
return url;
}
}
};
//Function: delete url address
function removeUrlSearch(name, url) {
var patter = "&" + name + "=[^]+";
return url.replace(new RegExp(patter), "");
};
function removeUrl(name, url) {
var search = window.location.search;
if (search) {
var searchs = search.replace(/\?/g, "").split("&");
var index = -1;
for (var i = 0; i < searchs.length; i++) {
if (searchs[i].indexOf(name + "=") == 0) {
index = i;
break;
}
}
if (index > -1) {
searchs.splice(index, 1);
}
if (searchs.length > 0) {
return window.location.href.replace(search, "?" + searchs.join("&"));
}
else {
return window.location.href.replace(search, "");
}
}
}
//Display query conditions
function displaySearchConditions() {
var parameters = getSearchParameters();
if (parameters.length == 0) {
$(".Sel_Y").hide();
}
else {
var simepleQuery = "";
for (var i = 0; i < parameters.length; i++) {
var parameter = parameters[i];
if (parameter.key != 'left') {
$(".Sel_Y ul").append("
" + parameter.name + "
");
}
//Comprehensive search
$("li[data-key='" + parameter.key + "']").each(function () {
var text = $(this).text();
var name = $(this).attr("data-name").toLocaleLowerCase();
if (name == parameter.value.toLocaleLowerCase()) {
$(this).toggleClass("Sel_h");
return false;
}
})
}
}
}
//Function: Get the query parameter value
function getSearchParameters() {
var search = window.location.search;
var parameters = [];
if (search) {
var searchs = search.replace(/\?/g, "").split("&");
//Letters or letters + numbers are dynamic query conditions, two letters are fixed queries
for (var i = 0; i < searchs.length; i++) {
var parameter = searchs[i].split("=");
var key = parameter[0];
var name = unescape(parameter[1]).replace("<", "").replace(">", "").replace("script", "").replace(/\|/g, "銆?);
var value = name;
switch (key) {
case "ec":
switch (name) {
case "1":
name = "Bulk";
break;
}
break;
case "st":
name = "In Stock";
break;
case "hp":
name = "Price";
break;
case "pt":
name = "Bulk";
break;
default:
name = name.replace("<", "").replace(">", "").replace("script", "").replace(/\|/g, "銆?);
break;
}
var patter = /^(?:cbn|kwd|page)$/i;
if (!patter.test(key)) {
parameters.push({ key: key, name: name, value: value });
}
}
}
return parameters;
}
function Conditions(containerElement, targetElement) {
var _containerElement = containerElement;
var _targetElement = targetElement;
this.more = function () {
var moreClass = "Sel_more";
_containerElement.toggleClass(moreClass);
if (_containerElement.hasClass(moreClass)) {
targetElement.parent().html('Lessmultiselect');
}
else {
targetElement.parent().html('Moremultiselect');
}
},
this.multiple = function () {
targetElement.parent().hide();
var moreClass = "Sel_more";
if (_containerElement.hasClass(moreClass)) {
_containerElement.removeClass(moreClass);
targetElement.parent().html('Lessmultiselect');
}
_containerElement.toggleClass("Sel_multiple");
},
this.expend = function () {
_containerElement.parent().parent().removeClass("Sel_multiple");
_containerElement.prev().show()
},
this.multipleSearch = function () {
var key, name;
var $selected = _containerElement.parent().find(".Sel_h [data-key]");
if ($selected.length == 0) {
$selected = _containerElement.parent().find(".Sel_h[data-key]");
}
$selected.each(function () {
var data = $(this).data();
key = data.key;
if (name) {
name += "|" + data.name;
}
else {
name = data.name;
}
});
if (key && name) {
window.location.href = removeUrlSearch("page", getUrl(key, name));
}
},
this.singSearch = function () {
if (_containerElement.hasClass("Sel_multiple")) {
targetElement.toggleClass("Sel_h");
//Activate OK button
var selectedLength = _containerElement.find(".Sel_h").length;
var $save = _containerElement.find(":button[data-operator='save']");
if (selectedLength > 0) {
$save.prop("disabled", false);
}
else {
$save.prop("disabled", true);
}
}
else {
var data = targetElement.data();
var redirectUrl = getUrl(data.key, data.name);
if (redirectUrl.lastIndexOf("#J_Condition") == -1) {
var urlStr = redirectUrl.split('?')[0];
var tag = urlStr.lastIndexOf("/") + 1;
var mm = urlStr.length - 5;
var urlName = urlStr.substring(tag, mm);
if (urlName.toUpperCase() == 'PRODUCTLIST_SUPPLIER') {
redirectUrl += "&left=" + $("#isShowLeft").val();
}
redirectUrl = redirectUrl + "#J_Condition";
}
window.location.href = removeUrlSearch("page", redirectUrl);
}
};
}
function getMyAccount() {
$.ajax({
url: "/UserProfile/GetMyAccount.ashx",
dataType: "json",
cache: false,
success: function (json) {
if (json != 0) {
var count = json.InquiryCoutn + json.Quotation;
if (count > 0) {
$(".UserNo").text(count);
$(".UserNo").show();
}
else {
$(".UserNo").hide();
}
}
else {
$(".UserNo").hide();
}
}
});
}
function getSearchKeyWord() {
var search = window.location.search;
if (search) {
var reg = new RegExp(/kwd=([^&]+)/);
var matchs = reg.exec(search);
if (matchs != null && matchs.length >= 2) {
return decodeURIComponent(matchs[1]).replace("<", "").replace(">", "").replace("script", "").replace("'", "").replace("\"", "");
}
}
return "";
};
function bindEvent() {
$(".pageGo").click(function () {
var no = $(".pageNo").val();
if (parseInt(no) > 0) {
location.href = getUrl("page", no);
}
});
$("a[data-field='enterprise']").mouseover(function () {
var enterprise = $(this);
var number = $(enterprise).attr("data-number");
var security = $(enterprise).find(".Securityopen");
if (security.length > 0) {
$(security).css("visibility", "visible");
}
else {
var shtml = "";
$.post("/Handler/GetEnterpriseImg.ashx", { number: number }, function (result) {
if (result.length > 0) {
shtml += '
';
shtml += '
Enterprise Certification
';
shtml += '
';
shtml += '
';
shtml += '
';
shtml += '
verified
From:' + result[0].InputTime + '
';
shtml += '
';
shtml += '
';
shtml += '
';
shtml += '
';
shtml += '
';
for (var i = 0; i < result.length; i++) {
shtml += '
';
}
shtml += '
';
shtml += '
';
shtml += '
';
shtml += ' ';
shtml += '
';
shtml += '
';
}
$(enterprise).append(shtml);
$(enterprise).find("input[data-field='enterprise']").unbind("click");
$(enterprise).find("input[data-field='enterprise']").click(function () {
location.href = "/EnterpriseCertification_EN_" + number + ".htm";
});
var security = $(enterprise).find(".Securityopen");
(security).css("visibility", "visible");
}, "json");
}
})
$("a[data-field='enterprise']").mouseout(function () {
var security = $(this).find(".Securityopen");
if (security != null) {
$(security).css("visibility", "hidden");
}
})
$(":input[data-field='cbsid']").click(function () {
if ($(this)[0].checked) {
if (cbsid.length >= 5) {
alert("Select 5 suppliers at most!")
return false;
}
cbsid.push($(this).attr("data-cbsid"));
if (cbsid.length >= 1) {
$("div[data-merge='true']").remove();
mergeShow($(this));
}
}
else {
cbsid.removeByValue($(this).attr("data-cbsid"));
$("div[data-merge='true']").remove();
if (cbsid.length >= 1) {
var lastid = cbsid[cbsid.length - 1];
var lastCheckBox = $(":input:checkbox[data-cbsid='" + lastid + "']");
mergeShow(lastCheckBox);
}
}
});
$(":input[data-field='inquiry']").click(function () {
var cas = $("#bt_delegate_list").attr("data-cas");
var cbnumber = $(this).attr("data-cbnumber");
var productname = $(this).attr("data-product-name");
var cbsid = $(this).attr("data-cbsid");
var source = "ProductList_Supplier";
setCookie("merge", cbsid, "d1");
location.href = "/InquiryToSupplier.aspx?cas=" + cas + "&n=" + encodeURIComponent(productname) + "&cbnumber=" + cbnumber + "&source=" + source;
});
$("a[data-field='prev']").click(function () {
var imgs = $(this).parent().parent().find("img[data-field='img']");
var curr_i = 0;
for (var i = 0; i < imgs.length; i++) {
if ($(imgs[i]).hasClass("current_i")) {
$(imgs[i]).hide();
$(imgs[i]).removeClass("current_i");
curr_i = i;
}
}
if (curr_i == 0) {
$(imgs[imgs.length - 1]).show();
$(imgs[imgs.length - 1]).addClass("current_i");
}
else {
$(imgs[curr_i - 1]).show();
$(imgs[curr_i - 1]).addClass("current_i");
}
})
$("a[data-field='next']").click(function () {
var imgs = $(this).parent().parent().find("img[data-field='img']");
var curr_i = 0;
for (var i = 0; i < imgs.length; i++) {
if ($(imgs[i]).hasClass("current_i")) {
$(imgs[i]).hide();
$(imgs[i]).removeClass("current_i");
curr_i = i;
}
}
if (curr_i == imgs.length - 1) {
$(imgs[0]).show();
$(imgs[0]).addClass("current_i");
}
else {
$(imgs[curr_i + 1]).show();
$(imgs[curr_i + 1]).addClass("current_i");
}
})
}
function ChemBookImgPath(path) {
path = path.replace("\\", "/");
var array = path.split('/');
var tempi = 0;
if (array[0].indexOf("http") > -1) {
tempi = 3;
}
else if (array[0].indexOf(":") > -1) {
tempi = 2;
}
var listPath = [];
for (var i = tempi; i < array.length; i++) {
var value = array[i];
if (value != "") {
listPath.push(value);
}
}
return "http://hg.y866.cn/chemistry/lib/img/" + listPath.join("/");
}
function loadPage() {
var html = "";
var pages = $("#pages").val();
if (pages > 1) {
var prev = parseInt(page) - 1;
var next = parseInt(page) + 1;
if (prev < 1) {
prev = 1;
}
if (next > pages) {
next = pages;
}
html += `
`;
html += `
`;
html += `
`;
var start = parseInt(page) - 6;
if (start < 1) {
start = 1;
}
var end = parseInt(page) + 1;
if (end < 6) {
end = 7;
}
if (end > pages) {
end = pages;
}
var isHavePrev = true;
for (var i = start; i <= end; i++) {
if (parseInt(page) > 1 && parseInt(page) <= pages) {
if (isHavePrev) {
isHavePrev = false;
html += `