var dCarryId="530";var dAddressId="1";var dPayId="258";var selectCarryId="530";var selectAddressId="1";var selectPayId="258";function setConfirmIdFromCookie(){dCarryId=myCookie.getCookie("defaultcarryid");if(dCarryId==""){myCookie.setCookie("defaultcarryid","530",{expireDays:30,path:"/"});dCarryId="530"}dAddressId=myCookie.getCookie("defaultaddressid");dPayId=myCookie.getCookie("defaultpayid");if(dPayId==""){myCookie.setCookie("defaultpayid","258",{expireDays:30,path:"/"});dPayId="258"}}function setSelectIdFromCookie(){selectCarryId=myCookie.getCookie("defaultcarryid");selectAddressId=myCookie.getCookie("defaultaddressid");selectPayId=myCookie.getCookie("defaultpayid")}function setCookieIdFromSelectId(){myCookie.setCookie("defaultcarryid",selectCarryId,{expireDays:30,path:"/"});myCookie.setCookie("defaultpayid",selectPayId,{expireDays:30,path:"/"});myCookie.setCookie("defaultaddressid",selectAddressId,{expireDays:30,path:"/"})}function openProductDetail(A){window.open("/market/productdetail.php?productid="+A)}function setProductInBodega(A){var B="productid="+A;jQuery.ajax({type:"POST",url:"/ajax/market/setproductinbodega.php",data:B,success:function(D){var C=createJson(D);if(C.success){alert(C.errmsg)}else{alert(C.errmsg);if(C.retcode==2){window.location.replace("/login.php?prepage="+window.location.href)}}},error:function(C){alert(json.errmsg)}})}function addProductFromPage(C,D,G){var B=myCookie.getCookie("mycart");var A=false;var I;var E;I=splitStr(B,"!@!");for(var F=I.length-1;F>=0;F--){E=splitStr(I[F],",");if(E[0]==C&&E[1]==D){I[F]=C+","+D+","+(parseInt(E[2])+parseInt(G));A=true;break}}if(A){B=I.join("!@!")}if(!A){if(B==""){B=C+","+D+","+G}else{B+="!@!"+C+","+D+","+G}}myCookie.setCookie("mycart",B,{expireDays:30,path:"/"});isrefresh=1;if(isrefresh==1){var H=window.open("/market/mycart.php","_self");H.focus()}}function set_Order_Type(A){var B=myCookie.getCookie("ordertype");if(A!=B){emptyCart()}myCookie.setCookie("ordertype",A,{expireDays:30,path:"/"})}function show_all_packages(A){if(A==1){jQuery("#all_packages").slideDown(600)}if(A==0){jQuery("#all_packages").slideUp(600)}}function chose_package(A,B){jQuery("#all_packages").slideUp(600);document.getElementById("current_package_name").innerHTML="<B>"+A+"</B>";document.getElementById("current_package_name").setAttribute("current_package_id",B)}function buy_now(A,C){var B="no";if(document.getElementById("current_package_name")){B=document.getElementById("current_package_name").getAttribute("current_package_id")}addProductFromPage(A,B,C);return true}function addProductFromCart(A,E){document.getElementById("i_ensure").disabled=true;if(isInt(E.value)&&parseInt(E.value)!="0"){if(E.value.trim2()==E.getAttribute("orgval")){document.getElementById("i_ensure").disabled=false;return true}var C=myCookie.getCookie("mycart");var D=splitStr(C,"!@!");var B=splitStr(D[A],",");D[A]=B[0]+","+B[1]+","+E.value.trim2();C=D.join("!@!");myCookie.setCookie("mycart",C,{expireDays:30,path:"/"});E.setAttribute("orgval",E.value.trim2());callselfFromCartOrCheckout()}else{document.getElementById("i_ensure").disabled=false;E.value=E.getAttribute("orgval")}return true}function delProductFromCart(B){document.getElementById("i_ensure").disabled=true;var C=myCookie.getCookie("mycart");if(C==""){return }var A=splitStr(C,"!@!");A.splice(B,1);if(A.length!=0){C=A.join("!@!");myCookie.setCookie("mycart",C,{expireDays:30,path:"/"})}else{emptyCart()}callselfFromCartOrCheckout()}function emptyCart(){myCookie.setCookie("mycart","",{expireDays:-1,path:"/"})}function nextMycartPage(E){var D=document.getElementsByTagName("TD");for(var C=0;C<D.length;C++){if(D[C].getAttribute("overstorage")){alert("对不起"+D[C].getAttribute("overstorage")+"超过最大可购买数量，请重新修改数量");return }}if(!E.getAttribute("isexecute")){E.setAttribute("isexecute","no")}if(E.getAttribute("isexecute")=="yes"){return }E.setAttribute("isexecute","yes");if(myCookie.getCookie("defaultcarryid")==""||myCookie.getCookie("defaultaddressid")==""||myCookie.getCookie("defaultpayid")==""){window.location.href="/market/shopingstep_1.php"}var A=myCookie.getCookie("defaultaddressid");var B="addressid="+A;jQuery.ajax({type:"POST",url:"/ajax/market/isexistaddress.php",data:B,success:function(G){var F=createJson(G);if(F.success){if(F.exist=="yes"||myCookie.getCookie("defaultcarryid")=="535"){window.location.href="/market/checkout.php"}else{window.location.href="/market/shopingstep_1.php"}}else{window.location.href="/market/shopingstep_1.php"}},error:function(F){window.location.href="/market/shopingstep_1.php"}})}function closeWindow(){window.opener=null;window.close()}function initShoping1(A){window.addressLen=A;setConfirmIdFromCookie();window.newAddressId="";window.selectAddressId="";if(addressLen<4){global3SetSelect(sj_area,["new_1","new_2","new_3"],["国家","省份、州","地级市、县"],[0,0,0])}selectCarryId=dCarryId;if(dCarryId=="535"){viewAddress(0);document.getElementById("r1_2").checked=true}else{viewAddress(1);if(document.getElementById("table_"+dAddressId)){document.getElementById("table_"+dAddressId).parentNode.className="selectedAddress";selectAddressId=dAddressId}else{selectAddressId=""}}if(document.getElementById("step1button")){document.getElementById("step1button").style.display="block"}}function changeCarryModel(A){if(A==1){selectCarryId="530"}if(A==0){selectCarryId="535"}viewAddress(A)}function viewAddress(A){if(A==0){document.getElementById("tbody_address").style.display="none";document.getElementById("tbody_consignee").style.display=""}if(A==1){document.getElementById("tbody_consignee").style.display="none";document.getElementById("tbody_address").style.display=""}}function setRWText(E,B){if(B=="new"){document.getElementById("table_command_new").style.display="none"}var D="";var C="";if(E==1){D="";C="none"}if(E==2){if(document.getElementById(B+"_1").length<1){var A=document.getElementById(B+"_1").getAttribute("val");var G=document.getElementById(B+"_2").getAttribute("val");var F=document.getElementById(B+"_3").getAttribute("val");global3SetSelect(sj_area,[B+"_1",B+"_2",B+"_3"],["国家","省份、州","地级市、县"],[0,0,0]);globalSetOrgValue([B+"_1",A],[B+"_2",G],[B+"_3",F])}D="none";C="";document.getElementById("table_"+B).parentNode.className="noselectedAddress";if(selectAddressId==B){selectAddressId=""}if((B=="new")&&selectAddressId==newAddressId){selectAddressId=""}}document.getElementById("table_read_"+B).style.display=D;document.getElementById("table_write_"+B).style.display=C}function reSetReadAddress(B){var A=document.getElementById(B+"_1").options[document.getElementById(B+"_1").selectedIndex].text;A+="&nbsp;"+document.getElementById(B+"_2").options[document.getElementById(B+"_2").selectedIndex].text;A+="&nbsp;"+document.getElementById(B+"_3").options[document.getElementById(B+"_3").selectedIndex].text;var E=document.getElementById("table_read_"+B);var D=document.getElementById("table_write_"+B);E.rows[2].cells[1].innerHTML=A;for(var C=1;C<D.rows.length-1;C++){if(C!=2){var F=D.rows[C].cells[1].getElementsByTagName("INPUT");E.rows[C].cells[1].innerHTML=F[0].value.trim2()}}}function addOrUpdateAddress(D,B,C){if(!checkNewAddress(D)){return }C.style.display="none";if(B==1){B="添加"}if(B==2||newAddressId!=""){B="修改"}document.getElementById(D+"_A_ADDRESS").value=document.getElementById(D+"_A_ADDRESS").value.replace(/\\/g,"");document.getElementById(D+"_A_ADDRESS").value=document.getElementById(D+"_A_ADDRESS").value.replace(/<+/g,"〈").replace(/>+/g,"〉");document.getElementById(D+"_A_USERNAME").value=document.getElementById(D+"_A_USERNAME").value.replace(/\\/g,"");document.getElementById(D+"_A_USERNAME").value=document.getElementById(D+"_A_USERNAME").value.replace(/<+/g,"〈").replace(/>+/g,"〉");var A="USERNAME="+escape(document.getElementById(D+"_A_USERNAME").value.trim2())+"&COUNTRY="+document.getElementById(D+"_1").value+"&PROVENCE="+document.getElementById(D+"_2").value;A+="&CITY="+document.getElementById(D+"_3").value+"&ADDRESS="+escape(document.getElementById(D+"_A_ADDRESS").value.trim2())+"&POSTCODE="+escape(document.getElementById(D+"_A_POSTCODE").value.trim2());A+="&MOBILE="+escape(document.getElementById(D+"_A_MOBILE").value.trim2())+"&PHONE="+escape(document.getElementById(D+"_A_PHONE").value.trim2());if(D=="new"&&newAddressId!=""){A+="&orgaddressid="+newAddressId}else{A+="&orgaddressid="+D}jQuery.ajax({type:"POST",url:"/ajax/market/addorupdateaddress.php",data:A,success:function(F){var E=createJson(F);if(E.success){C.style.display="block";if(E.id==-1){alert("配送地址不能超过4个");window.location.reload();return }if(B=="添加"||B=="修改"){reSetReadAddress(D);setRWText(1,D);if(B=="添加"){newAddressId=E.id;document.getElementById("new_tip").innerHTML="<h4>填写完毕后，请点击确定按钮</h4>";document.getElementById("new_bottom_command").innerHTML='<image src="/template/images/market/menu/menu_qd.jpg" onclick="addOrUpdateAddress(\'new\',2,this)"> <image src="/template/images/market/menu/menu_qx.jpg"   onclick="setRWText(1,\'new\')">'}}else{newAddressId=E.id;selectAddressId=newAddressId;nextShoping1()}}else{if(B==0){B="添加"}alert(B+"地址失败，请稍后再试");C.style.display="block"}},error:function(E){if(B==0){B="添加"}alert(B+"地址失败，请稍后再试");C.style.display="block"}})}function checkConsigneeInfo(){if(document.getElementById("new_realrname").value.trim2()==""||(document.getElementById("new_mobile").value.trim2()==""&&document.getElementById("new_phone").value.trim2()=="")){return false}return true}function updateConsigneeInfo(B,C){B.style.display="none";var A="USERNAME="+escape(document.getElementById("new_realrname").value.trim2())+"&MOBILE="+escape(document.getElementById("new_mobile").value.trim2())+"&PHONE="+escape(document.getElementById("new_phone").value.trim2());jQuery.ajax({type:"POST",url:"/ajax/market/updateconsigneeinfo.php",data:A,success:function(E){var D=createJson(E);if(D.success){B.style.display="block";nextShoping1()}else{alert("添加提货人信息失败，请稍后再试");B.style.display="block"}},error:function(D){alert("添加提货人信息失败，请稍后再试");B.style.display="block"}})}function checkNewAddress(B){var A="";var C=new validator();if(document.getElementById(B+"_A_USERNAME").value.trim2()==""){alert("请填写收货人姓名");return false}if(C.chLen(document.getElementById(B+"_A_USERNAME").value)>100){alert("收货人姓名字符数不能超过100");return false}if(document.getElementById(B+"_1").selectedIndex==0||document.getElementById(B+"_2").selectedIndex==0||document.getElementById(B+"_3").selectedIndex==0){alert("请选择地区");return false}if(document.getElementById(B+"_A_ADDRESS").value.trim2()==""){alert("请填写收货地址");return false}if(C.chLen(document.getElementById(B+"_A_ADDRESS").value)>300){alert("收货人姓名字符数不能超过300");return false}if(!C.isTel(document.getElementById(B+"_A_POSTCODE").value.trim2())){if(!C.isTel(document.getElementById(B+"_A_POSTCODE").value.trim2())){alert("请填写正确的邮编");return false}}if(document.getElementById(B+"_A_MOBILE").value.trim2()==""&&document.getElementById(B+"_A_PHONE").value.trim2()==""){alert("请填写移动电话或者固定电话");return false}if(document.getElementById(B+"_A_MOBILE").value.trim2()!=""&&!C.isTel(document.getElementById(B+"_A_MOBILE").value.trim2())){alert("请填写正确的移动电话");return false}if(document.getElementById(B+"_A_PHONE").value.trim2()!=""&&!C.isTel(document.getElementById(B+"_A_PHONE").value.trim2())){alert("请填写正确的固定电话");return false}return true}function applyAddress(B){var A=document.getElementById("tbody_address").getElementsByTagName("TABLE");for(var C=0;C<A.length;C++){A[C].parentNode.className="noselectedAddress"}document.getElementById("table_"+B).parentNode.className="selectedAddress";selectAddressId=B;if(B=="new"){selectAddressId=newAddressId}}function initShoping2(){setConfirmIdFromCookie();selectPayId=dPayId;if(document.getElementById("r_pay_"+selectPayId)){document.getElementById("r_pay_"+selectPayId).checked=true}if(document.getElementById("step2_1button")){document.getElementById("step2_1button").style.display="block"}if(document.getElementById("step2_2button")){document.getElementById("step2_2button").style.display="block"}}function changePayModel(A){selectPayId=A.getAttribute("value")}