function ReplaceAll(str, sptr, sptr1){
    while (str.indexOf(sptr) >= 0){
        str = str.replace(sptr, sptr1);
    }
    return str;
}
function radioCheck(){
   var array=document.getElementsByName("radio");
   for(var i=0;i<array.length;i++){
        if(array[i].checked){
            document.getElementById("li"+array[i].id).style.backgroundColor="#FDF2C9";
            document.getElementById("li"+array[i].id).style.border="1px solid #FBEBAD";
        }else{
            document.getElementById("li"+array[i].id).style.backgroundColor="#ffffff";
            document.getElementById("li"+array[i].id).style.border="1px solid #ffffff";
        }
   }
}
function onradioCheck(r){
    r.checked=true;
    radioCheck();
}
function val(){
    var flag=false;
    var re =/^[0-9]+?[0-9]*$/;
    var address=ReplaceAll(document.getElementById("txt_address").value," ","");
    var name=ReplaceAll(document.getElementById("txt_name").value," ","");
    var pcode=ReplaceAll(document.getElementById("txt_postalcode").value," ","");
    var qu=ReplaceAll(document.getElementById("txt_qu").value," ","");
    var code=ReplaceAll(document.getElementById("txt_code").value," ","");
    var fen=ReplaceAll(document.getElementById("txt_fen").value," ","");
    var tphone=qu+code+fen;
    var tphone2=qu+code;
    var phone=ReplaceAll(document.getElementById("txt_phone").value," ","");
    if(address==""){
        document.getElementById("msg_address").style.display="block";
        document.getElementById("msg_address").innerHTML="请填写收货地址";
        flag=false;
    }else{
        document.getElementById("msg_address").style.display="none";
        flag=true;
    }
    if(name==""){
        document.getElementById("msg_name").style.display="block";
        document.getElementById("msg_name").innerHTML="请填写收货人姓名";
        flag=false;
    }else{
        document.getElementById("msg_name").style.display="none";
        flag=true;
    }
    if(pcode==""){
        document.getElementById("msg_pcode").style.display="block";
        document.getElementById("msg_pcode").innerHTML="请填写邮政编码";
        flag=false;
    }else{
        if(!re.test(pcode)){
            document.getElementById("msg_pcode").style.display="block";
            document.getElementById("msg_pcode").innerHTML="邮政编码必须为数字";
            flag=false;
        }else{
            if(pcode.length==6){
                document.getElementById("msg_pcode").style.display="none";
                flag=true;
            }else{
                document.getElementById("msg_pcode").style.display="block";
                document.getElementById("msg_pcode").innerHTML="邮政编码必须为6位数字";
                flag=false;
            }
        }
    }
    if((tphone2=="")&&(phone=="")){
        document.getElementById("msg_phone").style.display="block";
        document.getElementById("msg_phone").innerHTML="电话和手机请至少填写一项";
        flag=false;
    }else{
        if(tphone!=""){
            if(fen==""){
                if(((qu=="")&&(code!=""))||((qu!="")&&(code==""))){
                    document.getElementById("msg_phone").style.display="block";
                    document.getElementById("msg_phone").innerHTML="请完整填写区号和电话号码";
                    flag=false;
                }else{
                    if(!re.test(tphone)){
                        document.getElementById("msg_phone").style.display="block";
                        document.getElementById("msg_phone").innerHTML="电话号和手机号必须为数字";
                        flag=false;
                    }else{
                        document.getElementById("msg_address").style.display="none";
                        flag2=true;
                    }
                }
            }else{
                if((qu!="")||(code!="")){
                    if(!re.test(tphone)){
                        document.getElementById("msg_phone").style.display="block";
                        document.getElementById("msg_phone").innerHTML="电话号和手机号必须为数字";
                        flag=false;
                    }else{
                        document.getElementById("msg_phone").style.display="none";
                        flag=true;
                    }
                }else{
                    document.getElementById("msg_phone").style.display="block";
                    document.getElementById("msg_phone").innerHTML="请完整填写区号和电话号码";
                    flag=false;
                }
            }
        }
        if(phone!=""){
           if(!re.test(phone)){
                document.getElementById("msg_phone").style.display="block";
                document.getElementById("msg_phone").innerHTML="电话号和手机号必须为数字";
                flag=false;
            }else{
                document.getElementById("msg_address").style.display="none";
                flag2=true;
            }
        }
    }
    return flag;
}
function opendiv(){
    document.getElementById("add_f").style.display="block";
}
function closediv(){
    document.getElementById("add_f").style.display="none";
    document.getElementById("msg_address").style.display="none";
    document.getElementById("msg_name").style.display="none";
    document.getElementById("msg_pcode").style.display="none";
    document.getElementById("msg_phone").style.display="none";
}