/* $id : shopping_flow.js 4865 2007-01-31 14:04:10z paulgao $ */ var selectedshipping = null; var selectedpayment = null; var selectedpack = null; var selectedcard = null; var selectedsurplus = ''; var selectedbonus = 0; var selectedintegral = 0; var selectedoos = null; var alertedsurplus = false; var groupbuyshipping = null; var groupbuypayment = null; /* * * 改变配送方式 */ function selectshipping(obj) { if (selectedshipping == obj) { return; } else { selectedshipping = obj; } var supportcod = obj.attributes['supportcod'].value + 0; var theform = obj.form; /* for (i = 0; i < theform.elements.length; i ++ ) { if (theform.elements[i].name == 'payment' && theform.elements[i].attributes['iscod'].value == '1') { if (supportcod == 0) { theform.elements[i].checked = false; theform.elements[i].disabled = true; } else { theform.elements[i].disabled = false; } } } */ if (obj.attributes['insure'].value + 0 == 0) { document.getelementbyid('ecs_needinsure').checked = false; document.getelementbyid('ecs_needinsure').disabled = true; } else { document.getelementbyid('ecs_needinsure').checked = false; document.getelementbyid('ecs_needinsure').disabled = false; } var now = new date(); ajax.call('flow.php?step=select_shipping', 'shipping=' + obj.value, ordershippingselectedresponse, 'get', 'json'); } /** * */ function ordershippingselectedresponse(result) { if (result.need_insure) { try { document.getelementbyid('ecs_needinsure').checked = true; } catch (ex) { alert(ex.message); } } try { if (document.getelementbyid('ecs_codfee') != undefined) { document.getelementbyid('ecs_codfee').innerhtml = result.cod_fee; } } catch (ex) { alert(ex.message); } orderselectedresponse(result); } /* * * 改变支付方式 */ function selectpayment(obj) { if (selectedpayment == obj) { return; } else { selectedpayment = obj; } ajax.call('flow.php?step=select_payment', 'payment=' + obj.value, orderselectedresponse, 'get', 'json'); } /* * * 团购购物流程 --> 改变配送方式 */ function handlegroupbuyshipping(obj) { if (groupbuyshipping == obj) { return; } else { groupbuyshipping = obj; } var supportcod = obj.attributes['supportcod'].value + 0; var theform = obj.form; for (i = 0; i < theform.elements.length; i ++ ) { if (theform.elements[i].name == 'payment' && theform.elements[i].attributes['iscod'].value == '1') { if (supportcod == 0) { theform.elements[i].checked = false; theform.elements[i].disabled = true; } else { theform.elements[i].disabled = false; } } } if (obj.attributes['insure'].value + 0 == 0) { document.getelementbyid('ecs_needinsure').checked = false; document.getelementbyid('ecs_needinsure').disabled = true; } else { document.getelementbyid('ecs_needinsure').checked = false; document.getelementbyid('ecs_needinsure').disabled = false; } ajax.call('group_buy.php?act=select_shipping', 'shipping=' + obj.value, orderselectedresponse, 'get'); } /* * * 团购购物流程 --> 改变支付方式 */ function handlegroupbuypayment(obj) { if (groupbuypayment == obj) { return; } else { groupbuypayment = obj; } ajax.call('group_buy.php?act=select_payment', 'payment=' + obj.value, orderselectedresponse, 'get'); } /* * * 改变商品包装 */ function selectpack(obj) { if (selectedpack == obj) { return; } else { selectedpack = obj; } ajax.call('flow.php?step=select_pack', 'pack=' + obj.value, orderselectedresponse, 'get', 'json'); } /* * * 改变祝福贺卡 */ function selectcard(obj) { if (selectedcard == obj) { return; } else { selectedcard = obj; } ajax.call('flow.php?step=select_card', 'card=' + obj.value, orderselectedresponse, 'get', 'json'); } /* * * 选定了配送保价 */ function selectinsure(needinsure) { needinsure = needinsure ? 1 : 0; ajax.call('flow.php?step=select_insure', 'insure=' + needinsure, orderselectedresponse, 'get', 'json'); } /* * * 团购购物流程 --> 选定了配送保价 */ function handlegroupbuyinsure(needinsure) { needinsure = needinsure ? 1 : 0; ajax.call('group_buy.php?act=select_insure', 'insure=' + needinsure, orderselectedresponse, 'get', 'json'); } /* * * 回调函数 */ function orderselectedresponse(result) { if (result.error) { alert(result.error); location.href = './'; } try { var layer = document.getelementbyid("ecs_ordertotal"); layer.innerhtml = (typeof result == "object") ? result.content : result; if (result.payment != undefined) { var surplusobj = document.forms['theform'].elements['surplus']; if (surplusobj != undefined) { surplusobj.disabled = result.pay_code == 'balance'; } } } catch (ex) { } } /* * * 改变余额 */ function changesurplus(val) { if (selectedsurplus == val) { return; } else { selectedsurplus = val; } ajax.call('flow.php?step=change_surplus', 'surplus=' + val, changesurplusresponse, 'get', 'json'); } /* * * 改变余额回调函数 */ function changesurplusresponse(obj) { if (obj.error) { try { document.getelementbyid("ecs_surplus_notice").innerhtml = obj.error; document.getelementbyid('ecs_surplus').value = '0'; document.getelementbyid('ecs_surplus').focus(); } catch (ex) { } } else { try { document.getelementbyid("ecs_surplus_notice").innerhtml = ''; } catch (ex) { } orderselectedresponse(obj.content); } } /* * * 改变积分 */ function changeintegral(val) { if (selectedintegral == val) { return; } else { selectedintegral = val; } ajax.call('flow.php?step=change_integral', 'points=' + val, changeintegralresponse, 'get', 'json'); } /* * * 改变积分回调函数 */ function changeintegralresponse(obj) { if (obj.error) { try { document.getelementbyid('ecs_integral_notice').innerhtml = obj.error; document.getelementbyid('ecs_integral').value = '0'; document.getelementbyid('ecs_integral').focus(); } catch (ex) { } } else { try { document.getelementbyid('ecs_integral_notice').innerhtml = ''; } catch (ex) { } orderselectedresponse(obj.content); } } /* * * 改变红包 */ function changebonus(val) { if (selectedbonus == val) { return; } else { selectedbonus = val; } ajax.call('flow.php?step=change_bonus', 'bonus=' + val, changebonusresponse, 'get', 'json'); } /* * * 改变红包的回调函数 */ function changebonusresponse(obj) { if (obj.error) { alert(obj.error); try { document.getelementbyid('ecs_bonus').value = '0'; } catch (ex) { } } else { orderselectedresponse(obj.content); } } /** * 验证红包序列号 * @param string bonussn 红包序列号 */ function validatebonus(bonussn) { ajax.call('flow.php?step=validate_bonus', 'bonus_sn=' + bonussn, validatebonusresponse, 'get', 'json'); } function validatebonusresponse(obj) { if (obj.error) { alert(obj.error); orderselectedresponse(obj.content); try { document.getelementbyid('ecs_bonusn').value = '0'; } catch (ex) { } } else { orderselectedresponse(obj.content); } } /* * * 改变发票的方式 */ function changeneedinv() { var obj = document.getelementbyid('ecs_needinv'); var objtype = document.getelementbyid('ecs_invtype'); var objpayee = document.getelementbyid('ecs_invpayee'); var objcontent = document.getelementbyid('ecs_invcontent'); var needinv = obj.checked ? 1 : 0; var invtype = obj.checked ? (objtype != undefined ? objtype.value : '') : ''; var invpayee = obj.checked ? objpayee.value : ''; var invcontent = obj.checked ? objcontent.value : ''; objtype.disabled = objpayee.disabled = objcontent.disabled = ! obj.checked; if(objtype != null) { objtype.disabled = ! obj.checked; } ajax.call('flow.php?step=change_needinv', 'need_inv=' + needinv + '&inv_type=' + encodeuricomponent(invtype) + '&inv_payee=' + encodeuricomponent(invpayee) + '&inv_content=' + encodeuricomponent(invcontent), orderselectedresponse, 'get'); } /* * * 改变发票的方式 */ function groupbuychangeneedinv() { var obj = document.getelementbyid('ecs_needinv'); var objpayee = document.getelementbyid('ecs_invpayee'); var objcontent = document.getelementbyid('ecs_invcontent'); var needinv = obj.checked ? 1 : 0; var invpayee = obj.checked ? objpayee.value : ''; var invcontent = obj.checked ? objcontent.value : ''; objpayee.disabled = objcontent.disabled = ! obj.checked; ajax.call('group_buy.php?act=change_needinv', 'need_idv=' + needinv + '&payee=' + invpayee + '&content=' + invcontent, null, 'get'); } /* * * 改变缺货处理时的处理方式 */ function changeoos(obj) { if (selectedoos == obj) { return; } else { selectedoos = obj; } ajax.call('flow.php?step=change_oos', 'oos=' + obj.value, null, 'get'); } /* * * 检查提交的订单表单 */ function checkorderform(frm) { var paymentselected = false; var shippingselected = false; // 检查是否选择了支付配送方式 for (i = 0; i < frm.elements.length; i ++ ) { if (frm.elements[i].name == 'shipping' && frm.elements[i].checked) { shippingselected = true; } if (frm.elements[i].name == 'payment' && frm.elements[i].checked) { paymentselected = true; } } if ( ! shippingselected) { alert(flow_no_shipping); return false; } if ( ! paymentselected) { alert(flow_no_payment); return false; } // 检查用户输入的余额 if (document.getelementbyid("ecs_surplus")) { var surplus = document.getelementbyid("ecs_surplus").value; var error = utils.trim(ajax.call('flow.php?step=check_surplus', 'surplus=' + surplus, null, 'get', 'text', false)); if (error) { try { document.getelementbyid("ecs_surplus_notice").innerhtml = error; } catch (ex) { } return false; } } // 检查用户输入的积分 if (document.getelementbyid("ecs_integral")) { var integral = document.getelementbyid("ecs_integral").value; var error = utils.trim(ajax.call('flow.php?step=check_integral', 'integral=' + integral, null, 'get', 'text', false)); if (error) { return false; try { document.getelementbyid("ecs_integral_notice").innerhtml = error; } catch (ex) { } } } frm.action = frm.action + '?step=done'; return true; } /* * * 检查收货地址信息表单中填写的内容 */ function checkconsignee(frm) { var msg = new array(); var err = false; if (frm.elements['country'] && frm.elements['country'].value == 0) { msg.push(country_not_null); err = true; } if (frm.elements['province'] && frm.elements['province'].value == 0 && frm.elements['province'].length > 1) { err = true; msg.push(province_not_null); } if (frm.elements['city'] && frm.elements['city'].value == 0 && frm.elements['city'].length > 1) { err = true; msg.push(city_not_null); } if (frm.elements['district'] && frm.elements['district'].length > 1) { if (frm.elements['district'].value == 0) { err = true; msg.push(district_not_null); } } if (utils.isempty(frm.elements['consignee'].value)) { err = true; msg.push(consignee_not_null); } if ( ! utils.isemail(frm.elements['email'].value)) { err = true; msg.push(invalid_email); } if (frm.elements['address'] && utils.isempty(frm.elements['address'].value)) { err = true; msg.push(address_not_null); } if (frm.elements['zipcode'] && frm.elements['zipcode'].value.length > 0 && (!utils.isnumber(frm.elements['zipcode'].value))) { err = true; msg.push(zip_not_num); } if (utils.isempty(frm.elements['tel'].value) && utils.isempty(frm.elements['mobile'].value)) { err = true; msg.push(tele_or_mob_not_null); } else { if (frm.elements['tel'] && frm.elements['tel'].value.length > 0 && !utils.istel(frm.elements['tel'].value)) { err = true; msg.push(tele_invaild); } if (frm.elements['mobile'] && frm.elements['mobile'].value.length > 0 && (!utils.ismobile(frm.elements['mobile'].value))) { err = true; msg.push(mobile_invaild); } } if (err) { message = msg.join("\n"); alert(message); } return ! err; }