var newIndex={
    defaultLindId:"1",
    defaultLind:function(id){
        if(this.defaultLindId == id){
            return;
        }else{
            if(id == "1"){
                $(".s1").css("display","block");
                $(".s2").css("display","none");
            }else{
                $(".s1").css("display","none");
                $(".s2").css("display","block");
            }            
            this.defaultLindId = id;
        }
    }
}
var login = {
    userReg:function(usernameid,emailid,pwdid,type){   
        var username = $("#"+usernameid).val();
        var email = $("#"+emailid).val();
        var password = $("#"+pwdid).val();
        var password2 = $("#tbRegisterPassword2").val();
        var yzm = $("#txtyzm").val();
        if(type==3){          
            if(username==""){
                $("#userName").html("<div class='error'>用户名不能为空!</div>");
                return false;
            }
            if(email == ""){
                $("#userEmail").html("<div class='error'>用户邮箱不能为空!</div>");
                return false;
            }
            if(password == ""){
                 $("#userPwd").html("<div class='error'>用户密码不能为空!</div>");
                return false;
            }
             var reg = /^\w{6,20}$/;
             if(!reg.test(password)){
                 $("#userPwd").html("<div class='error'>密码请设为6-16位字母或数字!</div>");
             }
             if(password !=password2){
                $("#userPwd2").html("<div class='error'>两次密码输入不一至!</div>");
             }     
             if(yzm ==""){
                 $("#useryzm").html("<div class='error'>验证码不能为空!</div>");
             }      
        }else if(type==2){
            if(email == ""){
                return;
            }else if(!Utils.isEmail(email)){
                 $("#userEmail").html("<div class='error'>邮箱格式不正确!</div>");
                 return;
            }
        }else if(type==4){
             if(password == ""){
                 $("#userPwd").html("<div class='error'>用户密码不能为空!</div>");
                return false;
            }
             var reg = /^\w{6,20}$/;
             if(!reg.test(password)){
                 $("#userPwd").html("<div class='error'>密码请设为6-16位字母或数字!</div>");
             }else{
                $("#userPwd").html("");
             }
        }else if(type==5){
            if(password !=password2){
                $("#userPwd2").html("<div class='error'>两次密码输入不一至!</div>");
             }else{
                $("#userPwd2").html("");
             } 
        }else if(type==6){          
            if(yzm ==""){
                $("#useryzm").html("<div class='error'>验证码不能为空!</div>");
             }else{
                $("#useryzm").html("");
             } 
        }   
        $.ajax({
            url:"/ajax/userReg.ashx",
            cache:false,
            data:{
                username:username,
                email:email,
                password:password,
                type:type
            },
            async:type!=3,
            success:function(msg)
            {
               // alert(msg);
                login.userRegSuccess(msg);
            }
        });
        
        return login.userLz;
    },
    userLz:false,
    userRegSuccess:function(responseText){
       var str = responseText.split('|');
       login.userLz = false;   
   //    alert(str[1]);
       switch(str[0]){
            case "0":
            case "4":
            case "7":
                  $("#userName").html(str[1]);
                  break;
            case "1":
            case "6":
                  $("#userEmail").html(str[1]);
                   break;
            case "2":           
            case "5":         
                  $("#userName").html("");              
                  $("#userEmail").html(str[1]);
                   break;
            case "3":
                  login.userLz = true;              
                  break;
       }   
    }    
}
var cart = {
    updateCart:function(target){
       target = $(target);      
       var num = target.val();     
       var lvalue = target.attr("lvalue");
       if(lvalue == num){
            return;
       }
       if(!Utils.isNumber(num)){
         target.val(lvalue);
         return;
       }   
       else
       {    
           var id = target.attr("lid");
           $.ajax({
                url:"/Assistant/Flow.ashx",
                cache:false,
                data:{
                    Act:"updateCart",
                    num:num,
                    id:id
                },
                success:function(msg)
                {              
                    if(msg=="0"){
                        alert('购物车更新失败!');
                        return;
                    }                    
                    target.attr("lvalue",num);     
                    var str = msg.split('|');                           
                    $("#sl").html(str[0]);  
                    $("#js").html(str[1]);  
                    $("#jf").html(str[3]);  
                    $("#je").html(str[2]);  
                    $("#price_num").html(str[2]);  
                    var off = target.offset();
                    $("#div_show").css("display","block").css("top",off.top-105).css("left",off.left-60);                    
                }
           });
       }
    },
    div_show_close:function(){
        $("#div_show").css("display","none");
    },
    cartNext:function(userid,url){   
         if($("#hidcount").val()=="0"){
            alert('请您先选择产品!');
            return false;
         }   
         if(userid<=0){
            if(url=="-"){
                url = "/flow/Consignee.aspx";
            }                    
            Demo('会员登录','/UsreLogin.aspx?ReturnUrl='+encodeURIComponent(url),'300','200'); 
            return false;
         }else{
            if(url!="-"){
                location.href=url;
                return false;
            }
         }
    },
    UserAddressShow:function(){    
         $.ajax({
                url:"/ajax/useraddress.ashx",
                 data:{
                    Act:"select"
                },
                cache:false,              
                success:function(msg)
                {                              
                    if(msg==""){                       
                        return;
                    }                         
                    $("#shxx").html(msg);                    
                },
                error:function(msg){
                    alert(msg);
                }
           });
    },
    DeleteAddress:function(addressid){
         $.ajax({
                url:"/ajax/useraddress.ashx",
                 data:{
                    Act:"delete",
                    addressid:addressid
                },
                cache:false,              
                success:function(msg)
                {                              
                    if(msg==""){                       
                        return;
                    }                         
                    $("#shxx").html(msg);                    
                },
                error:function(msg){
                    alert(msg);
                }
           });
    },
    EditAddress:function(addressid){
        location.href='/flow/consignee.aspx?addressid='+addressid;
    },
    UserAddressCityShow:function(){
        var hfCountry = $("#hfCountry");      
        if(hfCountry.val()!=""){
              var hfProvince = $("#hfProvince");
              var hfCity = $("#hfCity");
            $("#dllCountry").val(hfCountry.val());
            GetNextStep('dllCountry',false);         
            $("#dllProvince").val(hfProvince.val());              
           GetNextStep('dllProvince',false);
           $("#dllCity").val(hfCity.val());
        }
    },
    SelectedAddress:function(addressid){
        location.href='/flow/Shopping_DeliveryType.aspx?addressId='+addressid;
    },
    LPayid:null,
    SelectPay:function(payid){       
        if(!cart.LPayid){
            cart.LPayid = parseInt($("#hidpayid").val());
        }                 
        if(cart.LPayid == payid){        
            return ;
        }      
       // alert(cart.LPayid +"|"+ payid)          
        $("#rd_pay_"+payid).css("display","block");
        $("#rd_pay_"+cart.LPayid).css("display","none");
        cart.LPayid = payid;
    }
}
var pro={
    show_bigImg:function(src){
        
        $("#bigImg").attr("src",src.replace("_t.jpg","_g.jpg"));        //.attr("src","/images/07.gif")
    },
    showbigTImg:function(obj){
        $("#ifram1").css("visibility","inherit");
        var showID=document.getElementById('bigTImg')
        if(obj.onmouseout==null){
            obj.onmouseout=function(){               
                showID.parentNode.style.display='none';
                 showID.src='/images/07.gif';
                 $("#ifram1").css("visibility","hidden");
            }
        }               
        if(showID.src.indexOf('.jpg')<0){         
            showID.src=obj.src.replace('_g.jpg','.jpg');        
            showID.parentNode.style.display='';      
            showID.style.marginLeft=(showID.parentNode.offsetWidth-showID.offsetWidth)/2+'px';
            showID.style.marginTop=(showID.parentNode.offsetHeight-showID.offsetHeight)/2+'px';
            
        }
        
      
        
        var x=event.offsetX;
        var y=event.offsetY;  
        mx=x-obj.parentNode.offsetWidth/2;
        my=y-obj.parentNode.offsetHeight/2;
        
        l=(showID.parentNode.offsetWidth-showID.offsetWidth)/2;
        y=(showID.parentNode.offsetHeight-showID.offsetHeight)/2        
        nLeft=(l-mx);
        nTop=(y-my);
    
        if(nLeft>0) nLeft=0;
        if(nLeft<showID.parentNode.offsetWidth-showID.offsetWidth) nLeft=showID.parentNode.offsetWidth-showID.offsetWidth;
        if(nTop>0) nTop=0;
        if(nTop<showID.parentNode.offsetHeight-showID.offsetHeight) nTop=showID.parentNode.offsetHeight-showID.offsetHeight;
        
        showID.style.marginLeft=nLeft+'px';
        showID.style.marginTop=nTop+'px';
    },
    show_content:function(list,id,type){
        if(type==2){
            $(".product_body1[id^='"+list+"']").css("display","none"); 
        }else
        {
            $(".product_body[id^='"+list+"']").css("display","none");        
        }
       $(".productmain_title a[id^='a_"+list+"']").removeClass("productmain_hover");
       $("#a_"+id).addClass("productmain_hover");
        $("#"+id).css("display","block");  
        if(list =="prot_6_"){
            if(id=="prot_6_1"){
                $("#tbs").css("display","block");
            }else{
                $("#tbs").css("display","none");
            }
        }
    },
    scrollList:function(e,width,p,fun)
    {
        e.scrollLeft += p*width/100;    
        if((width < 0 && e.scrollLeft == 0) || (width > 0 && (e.scrollLeft + parseInt(e.style.width)) == e.scrollWidth))
        {
            if(fun)
               fun(width>0?1:-1);
            return;
        }
        
        if(Math.abs(width) <= 1)
        {
            e.scrollLeft += width;
            
            if(fun)
            {
                if((width < 0 && e.scrollLeft == 0) || (width > 0 && (e.scrollLeft + parseInt(e.style.width)) == e.scrollWidth))
                    fun(width>0?1:-1);
                else
                    fun(0);
            }
            return;
        }    
        setTimeout(function(){pro.scrollList(e,(1-p/100)*width,p,fun);},80);             
    }
  
}

