﻿ // 执行保存操作
    function doSave()
    {
        var city = $.trim($('#City').val());
        var districName = $.trim($('#DistricName').val());
        var addres = $.trim($('#Addres').val());
        var pcode = $.trim($('#Pcode').val());
        var recname = $.trim($('#Recname').val());
        var mobile = $.trim($('#Mobile').val());
        var telephone = $.trim($('#Telephone').val());
        var email = $.trim($('#Email').val());
        var remark = $.trim($('#Remark').val()); 
        //区验证
        if ('-1' == districName) 
        {
            document.getElementById("disMSG").style.display="inline";
            $('#DistricName').focus();
            return;
        }
        document.getElementById("disMSG").style.display="none";
        //详细地址验证
        if(''==addres)   
        { 
            document.getElementById("adMSG").style.display="inline";         
            $('#Addres').focus();   
            return ;
        }           
        document.getElementById("adMSG").style.display="none";
        if(''==pcode)   
        {
            document.getElementById("posMSG").innerText="请输入邮编。";
            document.getElementById("posMSG").style.display="inline";            
            $('#Pcode').focus();
            return;
        }         
        if(!checkPostCodeRegex(pcode))
        {
            document.getElementById("posMSG").innerText="邮编格式不正确。";
            document.getElementById("posMSG").style.display="inline";
            $('#Pcode').select();
            return;
        }
        document.getElementById("posMSG").style.display="none";
        //姓名验证
        var cname=/^[u4E00-u9FA5]+$/;
        if(''==recname)   
        {
            document.getElementById("cnMSG").innerText="请输入姓名。";
            document.getElementById("cnMSG").style.display="inline";
            $('#Recname').focus();
            return;
        }         
        if(cname.test(recname))
        {
            document.getElementById("cnMSG").innerText="只能是中文。";
            document.getElementById("cnMSG").style.display="inline";
            $('#Recname').select();
            return;
        }
        document.getElementById("cnMSG").style.display="none";
        
        //手机号码验证
        if (''== mobile)
        {
            document.getElementById("mobMSG").innerText="手机号码作为您最重要的联系方式，请务必填写。";
            document.getElementById("mobMSG").style.display="inline";
            $('#Mobile').focus();
            return;
        }

        document.getElementById("mobMSG").style.display="none";      
        if(!checkMobileRegex(mobile))
        {
            document.getElementById("mobMSG").innerText="手机号码无效，请重新输入。";
            document.getElementById("mobMSG").style.display="inline";
            $('#Mobile').select();
            return;
        }
        
        //联系电话验证        
        if(''!=telephone)
        {
            var result=telephone.match(/\d{7,8}/);
            if(result==null)
            {                
                document.getElementById("telMSG").style.display="inline";
                $('#Telephone').select();
                return;
            }
        }
        document.getElementById("telMSG").style.display="none";
        
        //邮箱验证   
        //var regemail = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        if(''!=email)
        {
            if(!checkEmailRegex(email))
            {                
                document.getElementById("emlMSG").style.display="inline";
                $('#Email').select();
                return ;
            }
        }
        
        document.getElementById("emlMSG").style.display="none";
        //保存
        $.get("Handler/CatalogAdd.ashx", {City:city,DistricName:districName,Addres:addres,Pcode:pcode,Recname:recname,Mobile:mobile,Telephone:telephone,Email:email,Remark:remark},
            function(data){
                if ('1' == data) {
		            alert("索取成功。");
		            window.location.href = '/Index.aspx';                                        
	            } else if ("-1" == data) {
		            alert("索取失败，服务器内部错误。");
	            } else {
	                alert("索取失败，无权限。"); 
	            }                            
         });                                           
    }   
    
    function doDownLoad()
    {        
        var customerCode=$('#CustomerCode').val();
        var loginName=$('#LoginName').val();
        var customerIP=$('#CustomerIP').val();
        $.get("Handler/CatalogDownLog.ashx",{CustomerCode:customerCode,LoginName:loginName,CustomerIP:customerIP},
            function(data){                
                });       
    }
     

 //删除单个收藏夹中的商品
    function UpdateFavorites(ProductCode){
        if (!confirm('确定删除该收藏商品吗？'))
	        {
		        return;		        
	        }
        $.post('Handler/MyFavorites.ashx',
        {ProductCode:ProductCode,Type:'del'},
        function(data) {                                 
             if(data == '-1')
             {
                alert('删除收藏商品失败。');
             }
             else
             {
                alert("删除收藏商品成功。");                
                window.location.href = '/Account/MyFavorites.aspx';           
             };
        });
    };
    
 
    //删除多个收藏夹中的商品
    function doDel()
    {
        var checkedCodes = "";
        $("[id='chkDel'][checked]").each(function(){ 
             checkedCodes += $(this).val() + ','; 
          });  
        if ("" == checkedCodes)
        {
            alert('请至少选择一个收藏商品后再删除。');
        }
        else
        {
	        if (!confirm('确定删除选中的收藏商品吗？'))
	        {
		        return;		        
	        }
	        checkedCodes = checkedCodes.substr(0,checkedCodes.length -1);
	        $.post('Handler/MyFavorites.ashx',{CheckedCodes:checkedCodes,Type:'delch'},
            function(data) {                                 
             if(data == '-1')
             {
                alert('删除收藏商品失败！');
             }
             else
             {
                alert("删除收藏商品成功！");                  
                window.location.href = '/Account/MyFavorites.aspx';           
             };
        });	
      }            
    }
    
    //全选按钮实现全选
    function doCheck() {
         if ($('#chkAll').attr("checked") == true) { 	       
	         $("input[id='chkDel']").each(function(){
	             $(this).attr("checked", true); 
	         });  
          } else { 
              
              $("input[id='chkDel']").each(function() {
	              $(this).attr("checked", false); 
	          }); 
          }
    } 
    
    //清空收藏夹
    function doClear(){
        if (!confirm('确定清空收藏夹吗？'))
	        {
		        return;		        
	        }
        $.post('Handler/MyFavorites.ashx',{Type:'clear'}, function(data){
             if(data == '-1')
             {
                alert('收藏夹清空失败。');
             }
             else
             {
                alert("收藏夹清空成功。");                  
                window.location.href = '/Account/MyFavorites.aspx';           
             }
        });
    }
    
    
    

    
 