锘縱ar attachmentpath = ""; var inquirysource = ""; var cbnumber = ""; $(function () { var remark = "Specification:\r\nPacking:\r\nPayment term:\r\nPurity:\r\nOther:"; $("#remark").val(remark); $("#remarkvalidate").val(remark); //Submit an inquiry $("input[data-submit='true']").click(function () { var isSigIn = $("#islogin").val(); //Product name verification var productname = $("#productname").val(); if ($.trim(productname) == "") { var prompt = $("#productname").parent().next(); if (!prompt.hasClass("prompt")) { var error = '
'; $("#productname").parent().after(error); return; } else { return; } } //Cas number verification var cas = $("#cas").val(); if ($.trim(cas)!="") { if (!$.isCas(cas)) { var prompt = $("#cas").parent().next(); if (!prompt.hasClass("prompt")) { var error = ''; $("#cas").parent().after(error); return; } else { return; } } } //Quantity verification var amount = $("#amount").val(); if ($.trim(amount) == "") { var prompt = $("#amount").parent().next(); if (!prompt.hasClass("prompt")) { var error = ''; $("#amount").parent().after(error); return; } else { return; } } //Remarks information verification var describtion = $("#remark").val(); if ($.trim(describtion) == $.trim($("#remarkvalidate").val())) { var prompt = $("#remark").parent().next(); if (!prompt.hasClass("prompt")) { var error = ''; $("#remark").parent().after(error); return; } else { return; } } var unit = $("#unit").val(); var unitname = $("#unit option:selected").text(); var port = $("#port").val(); var portdescribe = $("#portdescribe").val(); var country = $("#country").val(); var countrytext = $("#country option:selected").text(); var argument = { productname: productname, cas: cas, cbnumber: cbnumber, number: amount+unitname, unit: unit, port: port, portdescribe: portdescribe, country: country, describtion: describtion, attachmentpath: attachmentpath, inquirysource: inquirysource, countrytext: countrytext }; if (isSigIn == "True") { inquirySave(argument); } else { var $elementLogin = $("#dv_login"); var setSigIn = function (argument) { if (argument.isSigIn) { $("#islogin").val("True"); inquirySave(argument); } } var loginView = buildLoginView($elementLogin, setSigIn, argument); loginView.init(); } }); //Remove verification box $("input[data-validate='true']").blur(function () { if ($(this)[0].id=="cas") { if ($.trim($(this).val()) == "" || $.isCas(cas)) { var prompt = $(this).parent().next(); if (prompt.hasClass("prompt")) { prompt.remove(); } } } else { if ($.trim($(this).val()) != "") { var prompt = $(this).parent().next(); if (prompt.hasClass("prompt")) { prompt.remove(); } } } }); $("textarea[data-validate='true']").blur(function () { if ($.trim($(this).val()) != $.trim($("#remarkvalidate").val())) { var prompt = $(this).parent().next(); if (prompt.hasClass("prompt")) { prompt.remove(); } } }); //Upload Attachment $("#btnUpload").click(function () { $("#filepath").click(); }); $("b[data-field='close']").click(function () { $("#div_inquiry").dialog("close"); }); GetPackAgeUnitOfInquiry(); GetPortOfInquiry(); GetCountry(); }) /*****Save inquiry*****/ function inquirySave(argument) { $.ajax({ url: "/UserProfile/PurchaseHelper/Purchases/GlobalDelegateInquiry.ashx", cache: false, type: "Post", data: { str: JSON.stringify(argument) }, dataType: "text", success: function (data) { if (data == "success") { alert("Your query has been sent successfully."); $("#div_inquiry").dialog("close"); } else { alert(data); } } }) } /**Get the packaging unit**/ function GetPackAgeUnitOfInquiry() { $.ajax({ url: "/UserProfile/GlobalTrade/GetPackAgeUnitOfInquiry.ashx", dataType: "json", success: function (data) { $("#unit").find("option").remove(); var len = data.length; for (var i = 0; i < len; i++) { var unit = data[i]; $("#unit").append($("").val(unit.id).text(unit.name)); } } }); } /**Get port**/ function GetPortOfInquiry() { $.ajax({ url: "/UserProfile/GlobalTrade/GetPortOfInquiry.ashx", dataType: "json", success: function (data) { $("#port").find("option").remove(); var len = data.length; for (var i = 0; i < len; i++) { var port = data[i]; $("#port").append($("").val(port.id).text(port.name)); } } }); } /**Getting the country**/ function GetCountry() { $.ajax({ url: "/UserProfile/GlobalTrade/GetCountry.ashx", dataType: "json", success: function (data) { $("#country").find("option").remove(); var len = data.length; var shtml = ""; for (var i = 0; i < len; i++) { var country = data[i]; if (country.name=="China") { shtml += ""; } else { shtml += ""; } } $("#country").html(shtml); } }); } /***Upload Attachment****/ function fileupload() { $.ajaxFileUpload ( { url: '/UploadProductResource.up?max=2M', //Server-side request address for file upload secureuri: false, //Whether you need a security protocol, generally set to false fileElementId: 'filepath', //File upload domain ID dataType: 'json', //Return value type is generally set to json success: function (data, status) //Server successful response handler { if (typeof (data.error) != 'undefined') { if (data.error != '') { } else { $("#btnUpload").val("Upload Success"); attachmentpath = data.fileurl; alert("Upload success!"); $("span[data-field='filename']").text(data.filename); $("a[data-field='remove'").unbind(); $("a[data-field='remove'").click(function () { attachmentpath = ""; $("span[data-field='filename']").text(""); $(".finish").hide(); }); $(".finish").show(); } } }, error: function (data, status, e)//Server response failure handler { } } ); }