﻿
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)
{var fee=obj.attributes['fee'].value;document.getElementById('yunfeicash').innerHTML=fee;var zongcash=document.getElementById('procash').innerHTML;var quancash=document.getElementById('quancash').innerHTML;if (quancash.indexOf('未使用') > 0)
{quancash =0;var zongcash=parseInt((parseFloat(zongcash.replace('￥','').replace('元','')) + parseFloat(fee.replace('￥','').replace('元','')))*100)/100;}
else
{var zongcash=parseInt((parseFloat(zongcash.replace('￥','').replace('元','')) + parseFloat(fee.replace('￥','').replace('元','')) - parseFloat(quancash))*100)/100;}
document.getElementById("zongcash").innerHTML='￥'+ zongcash +'元';}
function countquan(value)
{document.getElementById('quancash').innerHTML=value;var zongcash=document.getElementById('procash').innerHTML;var yunfeicash=document.getElementById('yunfeicash').innerHTML;if (yunfeicash.indexOf('未选择') > 0)
{yunfeicash =0;var zongcash=parseInt((parseFloat(zongcash.replace('￥','').replace('元','')) - value)*100)/100;}
else
{var zongcash=parseInt((parseFloat(zongcash.replace('￥','').replace('元','')) + parseFloat(yunfeicash.replace('￥','').replace('元','')) - value)*100)/100;}
document.getElementById("zongcash").innerHTML='￥'+ zongcash +'元';} function addticket(){var series=document.forms['theForm'].elements['newseries'].value;Ajax.call('flow.php?step=addticket', 'series=' + series , addticketResponse, 'GET', 'JSON');}
function addticketResponse(result){if(result.error)
{alert(result.error);return false;}
try
{var goods_all=document.getElementById('procash').innerHTML;var zongcash=parseFloat(goods_all.replace('￥','').replace('元',''));document.getElementById('addtic_text').style.display='';if(zongcash > result.content.need){document.getElementById('addtic_text').innerHTML='添加成功';countquan(result.content.value);}else{document.getElementById('addtic_text').innerHTML='添加成功<font color="#999999">（<font color="#666666">暂时不可用</font>&nbsp;原因：订单金额小于此抵金券的要求金额）</font>';}
var tr=document.getElementById('tic_list').insertRow(2);tr.style.backgroundColor="#fdfd9f";td0=tr.insertCell(0);td0.align="center";td0.height='25';td0.style.color='#666666';td1=tr.insertCell(1);td1.align="center";td2=tr.insertCell(2);td2.align="left";td3=tr.insertCell(3);td3.align="center";td4=tr.insertCell(4);td4.align="center";if(zongcash > result.content.need){td0.innerHTML="<input name=\"bonus\" checked=\"checked\" value=\"" + result.content.series + "\" onclick=\"countquan(" + result.content.value + ");\" type=\"radio\">";}else{td0.innerHTML="未满限额";}
td1.innerHTML=result.content.series;td2.innerHTML="￥" + result.content.value + "元(<font style=\"color:#FF0000\">" + result.content.nstr + "</font>)";td3.innerHTML=result.content.type==2 ? '达券' : '活力券';td4.innerHTML=result.content.end;}
catch (ex) { }
}
function selectPayment(obj)
{if(document.getElementById("adinfo_key").innerHTML=='[关闭]')
{alert('请先填写收货信息 并点击上方“保存收货人信息”！');obj.checked=false;try{document.getElementById("consignee_0").focus();}catch (ex) { }
return false;}
if(selectedPayment==obj)
{return;}
else
{cancle_check(obj);var nid=obj.attributes['nid'].value;var iscod=obj.attributes['isCod'].value;document.getElementById('paydesc_'+nid).style.display='';var adinfo=obj.form.adinfo;coun=adinfo.attributes['country'].value;prov=adinfo.attributes['provinces'].value;city=adinfo.attributes['city'].value;dist=adinfo.attributes['district'].value;}
Ajax.call('flow.php?step=show_shipping', 'country=' + coun + '&province=' + prov + '&city=' + city + '&district=' + dist + '&iscod=' + iscod +'&d=' + Math.random(), orderShippingResponse, 'GET', 'JSON');}
function orderShippingResponse(result)
{if(result.error)
{alert(result.error);location.href='./';}
try
{document.getElementById("kdselect").style.display='';var layer=document.getElementById("shippingshow");layer.innerHTML=result;var _obj=document.getElementsByName('shipping'); for(i=0; i < _obj.length; i++){if(_obj[i].checked){selectShipping(_obj[i]); } }
}
catch (ex) { }
}
function new_selectPayment(obj,province1)
{if(document.getElementById("adinfo_key").innerHTML=='[关闭]')
{alert('请先填写收货信息 并点击上方“保存收货人信息”！');obj.checked=false;try{document.getElementById("consignee_0").focus();}catch (ex) { }
return false;}
cancle_check(obj);var nid=obj.attributes['nid'].value;document.getElementById('paydesc_'+nid).style.display='';var iscod=obj.attributes['isCod'].value;var adinfo=obj.form.adinfo;coun=adinfo.attributes['country'].value;prov=adinfo.attributes['provinces'].value;city=adinfo.attributes['city'].value;dist=adinfo.attributes['district'].value;flowType=document.getElementById("flowType").value;flowTypeId=document.getElementById("flowTypeId").value;flowGoodsPrice=document.getElementById("flowGoodsPrice").value;waitComplete.again();addNumber("GET",'flow.php?new=1&step=show_shipping&country=' + coun + '&province=' + prov + '&province1=' + province1 + '&city=' + city + '&district=' + dist + '&iscod=' + iscod + '&flowType=' + flowType + '&flowTypeId=' + flowTypeId + '&flowGoodsPrice=' + flowGoodsPrice + '&d=' + Math.random(),true,new_orderShippingResponse);}
function new_orderShippingResponse(xmlHttp,parameter,Unsuccessful)
{waitComplete.wait(xmlHttp,parameter,Unsuccessful,orderShippingResponse_display);}
function orderShippingResponse_display(xmlHttp,parameter,Condition){var layer=document.getElementById("shippingshow");if(Condition){layer.innerHTML=xmlHttp.responseText;var _obj=document.getElementsByName('shipping'); for(i=0; i < _obj.length; i++){if(_obj[i].checked){selectShipping(_obj[i]); } }
}else{layer.innerHTML='<div style="background:url(\'new_images/indicator_waitanim.gif\') no-repeat scroll 100px center transparent;height:116px;"></div>';}
}
function edit_adinfo(self)
{if (self.innerHTML=='[修改]')
{self.innerHTML='[关闭]';waitComplete.again();addNumber("GET",'flow.php?step=edit_adinfo',true,editAdinfoResponse);}
else if(self.innerHTML=='[关闭]')
{document.getElementById("adinfotable").style.display='';document.getElementById("edinfotable").style.display='none';self.innerHTML='[更改]';}
else if(self.innerHTML=='[更改]')
{if(document.getElementById("edinfotable").innerHTML.length > 10){document.getElementById("edinfotable").style.display='';document.getElementById("adinfotable").style.display='none';self.innerHTML='[关闭]';}else{self.innerHTML='[关闭]';waitComplete.again();addNumber("GET",'flow.php?step=edit_adinfo',true,editAdinfoResponse);}
}
}
function editAdinfoResponse(xmlHttp,parameter,Unsuccessful)
{waitComplete.wait(xmlHttp,parameter,Unsuccessful,open_display);}
function open_display(xmlHttp,parameter,Condition){var layere=document.getElementById("edinfotable");if(Condition){if(xmlHttp.responseText.length > 10){layere.innerHTML=xmlHttp.responseText;}else{addNumber("GET",'flow.php?step=edit_adinfo',true,editAdinfoResponse);}
}else{document.getElementById("adinfotable").style.display='none';layere.innerHTML='<div style="background:url(\'new_images/indicator_waitanim.gif\') no-repeat scroll 80px center transparent;height:130px;"></div>';}
}
function Isemail(email){var reyx= /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;return(reyx.test(email));}
var option_consignee=1;var option_provin=1;var option_address=1;var option_phone=1;function check_consignee(){if (document.getElementById("consignee_0").value=='')
{document.getElementById('show_consi').style.display='none';document.getElementById('alert_consi').style.display='';option_consignee=0;}
else{document.getElementById('show_consi').style.display='';document.getElementById('alert_consi').style.display='none';option_consignee=1;}
}
function check_provin(){if (document.getElementById("selCountries_0").value=='' || document.getElementById("selProvinces_0").value=='' || document.getElementById("selCities_0").value=='' || document.getElementById("selDistricts_0").value=='' || document.getElementById("selCountries_0").value==0 || document.getElementById("selProvinces_0").value==0 || document.getElementById("selCities_0").value==0 || document.getElementById("selDistricts_0").value==0)
{document.getElementById('show_provin').style.display='none';document.getElementById('alert_provin').style.display='';option_provin=0;}
else{document.getElementById('show_provin').style.display='';document.getElementById('alert_provin').style.display='none';option_provin=1;}
}
function check_address(){if (document.getElementById("address_0").value=='' || document.getElementById("address_0").length<=3)
{document.getElementById('show_addr').style.display='none';document.getElementById('alert_addr').style.display='';option_address=0;}
else{document.getElementById('show_addr').style.display='';document.getElementById('alert_addr').style.display='none';option_address=1;}
}
function check_phone(){if (document.getElementById("mobile_0").value=='')
{if (document.getElementById("tel_0").value != '' && document.getElementById("tel_0").value.length > 7)
{document.getElementById('alert_tel').style.display='none';document.getElementById('alert_mobile').style.display='none';document.getElementById('show_tel').style.display='';document.getElementById('show_mobile').style.display='';option_phone=1;}
else{document.getElementById('alert_tel').style.display='';document.getElementById('alert_mobile').style.display='';document.getElementById('show_tel').style.display='none';document.getElementById('show_mobile').style.display='none';option_phone=0
}
}
else{document.getElementById('alert_tel').style.display='none';document.getElementById('alert_mobile').style.display='none';document.getElementById('show_tel').style.display='';document.getElementById('show_mobile').style.display='';option_phone=1;}
}
function updateAddr()
{var err='';var empty=0;check_consignee();check_provin();check_address();check_phone();if (document.getElementById("zipcode_0").value != '')
{if (document.getElementById("zipcode_0").value.length != 6 || isNaN(document.getElementById("zipcode_0").value))
{err += '邮编格式不正确\n';}
}
if (err != '')
{alert(err);return false;}else if(option_consignee==0 || option_provin==0 || option_address==0 || option_phone==0){return false;}
var address_id=document.getElementById("address_id_0").value;var consignee=document.getElementById("consignee_0").value;var country=document.getElementById("selCountries_0").value;var province=document.getElementById("selProvinces_0").value;var city=document.getElementById("selCities_0").value;var district=document.getElementById("selDistricts_0").value;var address=document.getElementById("address_0").value;var zipcode=document.getElementById("zipcode_0").value;var tel=document.getElementById("tel_0").value;var mobile=document.getElementById("mobile_0").value;var cou=document.getElementById("selCountries_0");var coutext=cou.options[cou.selectedIndex].text;var pro=document.getElementById("selProvinces_0");var protext=pro.options[pro.selectedIndex].text;var cit=document.getElementById("selCities_0");var cittext=cit.options[cit.selectedIndex].text;var dis=document.getElementById("selDistricts_0");var distext=dis.options[dis.selectedIndex].text;Ajax.call('flow.php?step=update_consignee', 'address_id='+ encodeURI(address_id) +'&consignee='+ encodeURI(consignee) +'&country='+encodeURI(country)+'&province='+encodeURI(province)+'&city='+encodeURI(city)+'&district='+encodeURI(district)+'&address='+encodeURI(address)+'&zipcode='+encodeURI(zipcode)+'&tel='+encodeURI(tel)+'&mobile='+encodeURI(mobile)+'&cou='+encodeURI(coutext)+'&pro='+encodeURI(protext)+'&cit='+encodeURI(cittext)+'&dis='+encodeURI(distext)+'&d=' + Math.random(), null, 'GET', 'JSON');document.getElementById("show_consignee").innerHTML=consignee;document.getElementById("show_place").innerHTML=protext +'&nbsp;'+cittext+'&nbsp;'+distext;document.getElementById("show_address").innerHTML=address;document.getElementById("show_zipcode").innerHTML=zipcode;document.getElementById("show_tel").innerHTML=tel;document.getElementById("show_mobile").innerHTML=mobile;var adinfo=document.getElementById("adinfo");adinfo.attributes['country'].value=country;adinfo.attributes['provinces'].value=province;adinfo.attributes['city'].value=city;adinfo.attributes['district'].value=district;cancle_check(adinfo);var theForm=adinfo.form;for (i=0; i < theForm.elements.length; i ++ )
{if (theForm.elements[i].name=='payment')
{theForm.elements[i].checked=false;}
}
document.getElementById("shippingshow").innerHTML='请先选择支付方式';document.getElementById("adinfotable").style.display='';document.getElementById("edinfotable").style.display='none';document.getElementById("adinfo_key").innerHTML='[更改]';}
function handchange(goodsid)
{var goods=document.getElementById("goods_number_"+goodsid);var goodsnum=parseInt(goods.value);var dosth=document.getElementById("cartnum");dosth.attributes['goods'].value=goodsid;dosth.attributes['dosth'].value='hand';Ajax.call('flow.php?step=cartnumber', 'goods_number['+ goodsid +']=' + goodsnum, CartNum, 'GET', 'JSON');}
function reduceone(goodsid)
{var goods=document.getElementById("goods_number_"+goodsid);var goodsnum=parseInt(goods.value)-1;var dosth=document.getElementById("cartnum");dosth.attributes['goods'].value=goodsid;dosth.attributes['dosth'].value='reduce';Ajax.call('flow.php?step=cartnumber', 'goods_number['+ goodsid +']=' + goodsnum, CartNum, 'GET', 'JSON');}
function increaseone(goodsid)
{var goods=document.getElementById("goods_number_"+goodsid);var goodsnum=parseInt(goods.value)+1;var dosth=document.getElementById("cartnum");dosth.attributes['goods'].value=goodsid;dosth.attributes['dosth'].value='increase';Ajax.call('flow.php?step=cartnumber', 'goods_number['+ goodsid +']=' + goodsnum, CartNum, 'GET', 'JSON');}
function CartNum(result)
{if (result.error) {var dosth=document.getElementById("cartnum");var dosthIds=dosth.attributes['goods'].value; alert(result.error);document.getElementById("goods_number_"+dosthIds).value=result.oldnumber; }
else{ try { if (result.message=='更新完成') {var dosth=document.getElementById("cartnum");var dosthIds=dosth.attributes['goods'].value;var dosthWhat=dosth.attributes['dosth'].value;var goodsprice=document.getElementById("goodsprice_"+dosthIds).innerHTML;var frm=document.getElementById("formCart");document.getElementById("goodsprice_"+dosthIds).innerHTML=parseInt(result.goods_price);document.getElementById("goods_number_"+dosthIds).value=result.number;var alltotal=0;for (i=0; i < frm.elements.length; i ++ )
{if (frm.elements[i].name.substr(0,12)=='goods_number')
{var goodsid=frm.elements[i].name.replace('goods_number[','').replace(']','');var goodsprice=document.getElementById("goodsprice_"+goodsid).innerHTML;var goodsnum=document.getElementById("goods_number_"+goodsid).value;alltotal=parseInt(parseFloat((alltotal +parseInt(parseFloat(goodsprice)*parseInt(goodsnum)*100)/100)*100))/100;document.getElementById("subtotal_"+goodsid).innerHTML= parseInt(parseFloat(goodsprice)*parseInt(goodsnum)*100)/100;}
}
document.getElementById("allmoney").innerHTML='￥'+ alltotal +'元'; } else if (result.message=='超出库存') { alert('对不起，数量超出库存'); } var layere=document.getElementById("edinfotable"); layere.innerHTML=result; } catch (ex) { }
}
}
function checkOrderForm(frm)
{ var paymentSelected=false; var shippingSelected=false;if (document.getElementById('submenub2').style.display != 'none'){if(document.getElementById('inv_payee').value.replace(/\s+/g,'')==''){alert('发票抬头不能为空!');return 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 (frm.elements[i].value==2){var selectedBC=-1;for (a=0; a<frm.elements.length; a++){if (frm.elements[a].name=='bchange' && frm.elements[a].checked)
{selectedBC=a;}
}
if (selectedBC<0){alert("您还没有选择要转帐到的银行！");return false;}
}
else if (frm.elements[i].value==6){var selectedBC=-1;for (a=0; a<frm.elements.length; a++){if (frm.elements[a].name=='olpay' && frm.elements[a].checked)
{selectedBC=a;}
}
if (selectedBC<0){alert("您还没有选择网上银行付款所使用的银行！");return false;}
} } } if ( ! shippingSelected) { alert(flow_no_shipping); return false; } if ( ! paymentSelected) { alert(flow_no_payment); return false; } frm.action=frm.action + '?step=done'; return true;}
function cancle_check(obj)
{ var theForm=obj.form; for (i=0; i < theForm.elements.length; i ++ ) { if (theForm.elements[i].name=='payment') {document.getElementById('paydesc_'+theForm.elements[i].value).style.display='none';} }
}
function changeSurplus(val)
{val=parseInt(val);if(val=='NaN'){val=0;} 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').value=parseInt(document.getElementById('ECS_SURPLUS').value);document.getElementById('ECS_SURPLUS').value=(document.getElementById('ECS_SURPLUS').value=='NaN')?0:document.getElementById('ECS_SURPLUS').value;document.getElementById("ECS_SURPLUS_NOTICE").innerHTML=''; } catch (ex) { } }
}
function checkSurplus(checkbox,surplus,amount){if(amount){_zongcash=parseInt(document.getElementById("zongcash").innerHTML.replace(/^[\D]*/i, ''));}else{_zongcash=amount;}
if(checkbox.checked==true){if(surplus > _zongcash){document.getElementById("yfu").innerHTML=_zongcash;document.getElementById("sy").innerHTML='0';checkbox.value=_zongcash;}else{document.getElementById("yfu").innerHTML=surplus;document.getElementById("sy").innerHTML=(parseInt(_zongcash*100-surplus*100)/100);checkbox.value=surplus;}
}else{document.getElementById("yfu").innerHTML='0';document.getElementById("sy").innerHTML=_zongcash;}
}
