
function g(id){return document.getElementById(id);}
function n(name){return document.getElementsByName(name);}
function showObj(id,type){
if(type==0){g(id).style.display='none';}
else{g(id).style.display='block';}}
function getTipsId(str){
return "tips_"+str;}
function setTips(el,bool,str){
if(bool)
g(getTipsId(el.id)).className="tips_pass";
else{
g(getTipsId(el.id)).className="tips_false";}
g(getTipsId(el.id)).innerHTML=str;}
function chk_Name(el){
var name=el.value.Trim();
if(name==""){
setTips(el,false,'姓名不能为空');
return false;}
if(name.length<2||name.length>10){
setTips(el,false,'姓名长度最大为10位,最少2位');
return false;}
var reg=/^[\u4e00-\u9fa5]*$/;
if(reg.test(name)){
setTips(el,true,'姓名已输入');
return true;}
else{
setTips(el,false,'姓名只能为中文');
return false;}}
function chk_Email(el){
var email=el.value.Trim();
if(email=="")
return true;
if(email.length<6){
setTips(el,false,'邮件地址最少6个字符');
return false;}
var reg=/^\s*([\w-]+(\.\w+)*@([\w-]+\.)+\w{2,3})\s*$/;
if(reg.test(email)){
setTips(el,true,'邮件地址已输入');
return true;}
else{
setTips(el,false,'邮件地址格式错误');
return false;}}
function chk_Mobile(el){
var mobile=el.value.Trim();
if(mobile==""){
setTips(el,false,'手机号码不能为空');
return false;}
var reg=/^(13|15|18)+\d{9}$/;
if(reg.test(mobile)){
setTips(el,true,'手机号码已输入');
return true;}
else{
setTips(el,false,'手机号码有误');
return false;}}
function chk_Address(el){
var address=el.value.Trim();
if(address==""){
setTips(el,false,'地址不能为空');
return false;}
if(address.length<6){
setTips(el,false,'地址长度不能少于6位,请填写详细地址');
return false;}
setTips(el,true,'地址已输入');
return true;}
function chk_Tel(el){
var tel=el.value.Trim();
if(tel!=""){
setTips(el,true,'固话已输入');
return true;}
return true;}
function chk_Zipcode(el){
var zipcode=el.value.Trim();
if(zipcode=="")
return true;
var reg=/^\d{6}$/;
if(reg.test(zipcode)){
setTips(el,true,'邮编已输入');
return true;}
else{
setTips(el,false,'邮编有误');
return false;}}
var arrTips=new Array(
"",
"请填写详细地址以保障能快速准确送货",
"填写手机号便于接收发货通知短信及送货前确认",
"如：020-12345678，固话与手机至少填写一项",
"用来接收订单提醒邮件，便于您及时了解订单状态",
"有助于快速确定送货地址")
function initTips(){
g('tips_name').innerHTML=arrTips[0];
g('tips_address').innerHTML=arrTips[1];
g('tips_mobile').innerHTML=arrTips[2];
g('tips_tel').innerHTML=arrTips[3];
g('tips_email').innerHTML=arrTips[4];
g('tips_zipcode').innerHTML=arrTips[5];}
function getTextValue(id){
var obj=g(id);
return obj.value.Trim();}
function getRadioValue(radioObj){
var re='';
for(var i=0;i<radioObj.length;i++){
if(radioObj[i].checked){
re=radioObj[i].value;}}
return re;}
function setRadioValue_0(radioObj,v){
if(v==''){return;}
for(var i=0;i<radioObj.length;i++){
if(v=radioObj[i].value){
radioObj[i].checked="checked";}}}
function setSelectValue(objSelect,strValue){
for(i=0;i<objSelect.options.length;i++){
if(objSelect.options[i].value==strValue){
objSelect.options[i].selected=true;
break;}}}
function setRadioValue(objSelect,strValue){
if(strValue=="")return;
for(i=0;i<objSelect.length;i++){
if(objSelect[i].value==strValue){
objSelect[i].checked=true;
break;}}}
function checkAll(){
if(!chk_Name(g('name'))){alert('姓名未按要求填写');return false;}
if(!chk_Address(g('address'))){alert('详细地址未按要求填写');return false;}
if(!chk_Mobile(g('mobile'))){alert('手机号码未按要求填写');return false;}
if(!chk_Tel(g('tel'))){alert('固话未按要求填写');return false;}
if(!chk_Email(g('email'))){alert('Email未按要求填写');return false;}
if(!chk_Zipcode(g('zipcode'))){alert('邮编未按要求填写');return false;}
var city=g('City').options[g('City').selectedIndex].value;
if(city=='0'){alert('请选择所在地区');return false;}
var deliver=getRadioValue(n('rbtDeliver'));
if(deliver==''){alert('未选择配送方式');return false;}
var pay=getRadioValue(n('rbtPayWay'));
if(pay==''){alert('未选择支付方式');return false;}
var bill=getRadioValue(n('rbtReceipt'));
if(bill=='1'){
if(getTextValue('txtTaitou').length<2){alert('请填写发票抬头');return false;}}
return true;}
function saveInfo(){
var name=g('name').value.Trim();
var address=g('address').value.Trim();
var mobile=g('mobile').value.Trim();
var tel=g('tel').value.Trim();
var email=g('email').value.Trim();
var zipcode=g('zipcode').value.Trim();
var memo=g('txtmemo').value.Trim();
var taitou=g('txtTaitou').value.Trim();
var deliverType=getRadioValue(n('rbtDeliver'));
var payway=getRadioValue(n('rbtPayWay'));
var hid_DeliverName='';
var hid_DeliverCharge='';
var hid_DeliverMemo='';
var hid_DeliverNeedTime='';
var hid_PaymentName='';
var hid_PaymentTips='';
var hid_PaymentMemo='';
if(deliverType!=''){
hid_DeliverName=g('hid_DeliverName_'+getRadioValue(n('rbtDeliver'))).value;
hid_DeliverCharge=g('hid_DeliverCharge_'+getRadioValue(n('rbtDeliver'))).value;
hid_DeliverMemo=g('hid_DeliverMemo_'+getRadioValue(n('rbtDeliver'))).value;
hid_DeliverNeedTime=g('hid_DeliverNeedTime_'+getRadioValue(n('rbtDeliver'))).value;}
if(payway!=''){
hid_PaymentName=g('hid_PaymentName_'+getRadioValue(n('rbtPayWay'))).value;
hid_PaymentTips=g('hid_PaymentTips_'+getRadioValue(n('rbtPayWay'))).value;
hid_PaymentMemo=g('hid_PaymentMemo_'+getRadioValue(n('rbtPayWay'))).value;}
var info=new Array(
name,
address,
mobile,
tel,
email,
zipcode,
g('Province').options[g('Province').selectedIndex].value,
g('City').options[g('City').selectedIndex].value,
g('District').options[g('District').selectedIndex].value,
deliverType,
g('selDeliverTime').options[g('selDeliverTime').selectedIndex].value,
payway,
getRadioValue(n('rbtReceipt')),
taitou,
memo,
g('selBillContent').options[g('selBillContent').selectedIndex].value,
g('Province').options[g('Province').selectedIndex].text,
g('City').options[g('City').selectedIndex].text,
g('District').options[g('District').selectedIndex].text,
g('selDeliverTime').options[g('selDeliverTime').selectedIndex].text,
hid_DeliverName,
hid_DeliverCharge,
hid_DeliverMemo,
hid_DeliverNeedTime,
hid_PaymentName,
hid_PaymentTips,
hid_PaymentMemo)
var re=MyAjax.SaveInfo(info).value;}
function gotoConfirmOrder(){
var re=MyAjax.CheckCartHasAny().value;
if(re){
if(!checkAll()){return;}
saveInfo();
location.href='/order/Confirm.aspx';}
else{
alert('当前购物车为空，请先选择商品！');
gobacktoCart();}}
function gobacktoCart(){
saveInfo();
location.href='/order/cart.aspx';}
function setInfo(){
var arr=MyAjax.GetInfo().value;
if(arr.length==1){return false;}
g('name').value=arr[0];
g('address').value=arr[1];
g('mobile').value=arr[2];
g('tel').value=arr[3];
g('email').value=arr[4];
g('zipcode').value=arr[5];
g('txtmemo').value=arr[14];
g('txtTaitou').value=arr[13];
setSelectValue(g('Province'),arr[6]);
if(arr[6]!='0'){
ChangeProvince();}
setSelectValue(g('City'),arr[7]);
if(arr[7]!='0'){
test();}
setSelectValue(g('District'),arr[8]);
setSelectValue(g('selDeliverTime'),arr[10]);
setSelectValue(g('selBillContent'),arr[15]);
setRadioValue(n('rbtDeliver'),arr[9]);
setRadioValue(n('rbtPayWay'),arr[11]);
setRadioValue(n('rbtReceipt'),arr[12]);
if(arr[12]=='1'){
showObj('BillContent',1);}}

