﻿$(document).ready(function(){Main.OnLoad();});
var Main = {
    OnLoad:function(){
        $("#viewer").imageScroller({
			next:"turn_right",
			prev:"turn_left",
			frame:"viewerFrame",
			child:"li",
			auto:false
		}); 
		Main.StaticScroll("#kefu_btn");  
        Main.StaticScroll("#kefu_show");
    },
     //静态控件
    StaticScroll:function(control){
        var menuYloc = $(control).offset().top;  
        $(window).scroll(function (){  
            var offsetTop = menuYloc + $(window).scrollTop() +"px";  
            $(control).animate({top : offsetTop },{ duration:600 , queue:false });
        }); 
    },
    //控件透明度
    ChangeTouMin:function(control,type){
		if(type){
			control.style.filter="alpha(opacity='40')";
			control.style.opacity=".40";
			return;
		}
		control.style.filter="alpha(opacity='0')";
		control.style.opacity=".0";
    },
    //静态控件
    StaticScroll:function(control){
        var menuYloc = $(control).offset().top;  
        $(window).scroll(function (){  
            var offsetTop = menuYloc + $(window).scrollTop() +"px";  
            $(control).animate({top : offsetTop },{ duration:600 , queue:false });
        }); 
    },
    //设置区域
    SetArea:function(area){
        $.ajax({   
            type: "POST",   
            url: "Ajax.aspx",   
            cache: false,   
            async: true,   
            datatype:"text",   
            data:{
                FunctionName:"SetArea",
                Area:area       
            },   
            success: function(msg){                
                if(msg.indexOf("Success")==-1){
                    alert(msg);
                    return;
                }
                window.location.href=window.location.href;
            }
        });
    },
    Login:function(){
        var UserName=$("#txt_UserName").val().replace(/ /g,"");
        var UserPassword=$("#txt_Password").val().replace(/ /g,"");
        if(UserName==""||UserName==null)
        {
            $("#message").html("用户名不能为空");
            $("#message").css("display","");
            $("#txt_UserName").focus();
            return;            
        }
        if(UserPassword==""||UserPassword==null)
        {
            $("#message").html("密码不能为空");
            $("#message").css("display","");
            $("#txt_Password").focus();
            return;            
        }
        $("#message").html("正在验证……");
        $("#message").css("display","");
        $.ajax({   
            type: "POST",   
            url: "Ajax.aspx",   
            cache: false,   
            async: true,   
            datatype:"text",   
            data:{
                FunctionName:"CheckMemberLogin",
                UserName:UserName,
                UserPassword:UserPassword           
            },   
            success: function(msg){                
                if(msg.indexOf("Success")=-1){
                    $("#message").html("密码错误，请重新输入");
                    $("#message").css("display",""); 
                    $("#txt_Password").focus();
                    return;
                }
                window.location.href="Default.aspx";
            }
        });
    },
    //注销登录
    EndLogin:function(){
        if(confirm('确定要注销吗？'))
        {
             $.ajax({   
                type: "POST",   
                url: "Ajax.aspx",   
                cache: false,   
                async: true,   
                datatype:"text",   
                data:{
                    FunctionName:"EndMemberLogin"            
                },   
                success: function(msg){
                    if(msg.indexOf("Success")!=-1){
                        window.parent.location.href="Default.aspx";                           
                    }
                }
            });        
        }        
    },
    //改变数量
    ChangeNumber:function(){
        var number=$("#txt_number").val();
        if(/\D/.test(number)){
            alert("数量必须为数字");
            $("#txt_number").focus();
            return;
         }
         if(number<1){
            alert("数量必须大于0");
            $("#txt_number").focus();
            return;
         }
         $("#total").html("￥"+Math.round(parseFloat($("#price").html().substr(1,$("#price").html().length-1)*number)*100)/100);
    },
    //点击滚动
    Scroll:function(control,control1,control2){
        var speed=20;
        $(control2).html($(control1).html());                       
        function Marquee(){ 
            var left=$(control).attr("scrollLeft");
            if(left<$(control2).attr("offsetWidth")){
                $(control).attr("scrollLeft",left+1);
            }else{
                $(control).attr("scrollLeft",0);                
            }
        }
        var MyMar=setInterval(Marquee,speed) ;
        $(control).mouseover(function() {clearInterval(MyMar);})
        $(control).mouseout(function() {MyMar=setInterval(Marquee,speed);}) 
    },
    //添加到购物车
    GoodsAddToCar:function(id){
        var number=$("#txt_number").val();
        Main.AddToCar(id,number);
    },
    //添加到购物车
    AddToCar:function(id,number){
        if(!number){
            number=1
        }
        $.ajax({   
            type: "POST",   
            url: "Ajax.aspx",   
            cache: false,   
            async: true,   
            datatype:"text",   
            data:{
                FunctionName:"AddToCar",
                id:id ,
                number:number      
            },   
            success: function(msg){                
                if(msg.indexOf("Success")!=-1){
                    alert("商品已加入购物车！");
                    $("#number").html($("#number").html()*1+1);
                    return;
                }
                alert("请先登录！");
                window.location.href="RegisterAndLogin.aspx";
            }
        });
    },
    //删除订单
    DeleteOrderGood:function(index){
         $.ajax({   
            type: "POST",   
            url: "Ajax.aspx",   
            cache: false,   
            async: true,   
            datatype:"text",   
            data:{
                FunctionName:"DeleteOrderGood",
                index:index       
            },   
            success: function(msg){        
                window.location.href=window.location.href;
            }
        });
    },
    //编辑订单
    EditOrderGood:function(index,number){
         var ynumber=$("#txt_"+index).val();
         if(/\D/.test(ynumber)){
            alert("数量必须为数字");
            $("#txt_"+index).focus();
            return;
         }
         number+=ynumber*1;
         if(number<1){
            alert("数量必须大于0");
            $("#txt_"+index).focus();
            return;
         }
         $.ajax({   
            type: "POST",   
            url: "Ajax.aspx",   
            cache: false,   
            async: true,   
            datatype:"text",   
            data:{
                FunctionName:"EditOrderGood",
                index:index ,
                number: number     
            },   
            success: function(msg){        
                window.location.href=window.location.href;
            }
        });
    },
    SkipEnter:function()
    { 
        $("input[type='text']").each(function(){ 
            this.onkeydown = function(){if(window.event.keyCode==13){window.event.keyCode=9;}}; 
        });
        $("input[type='password']").each(function(){ 
            this.onkeydown = function(){if(window.event.keyCode==13){window.event.keyCode=9;}}; 
        });

    },
    CancelOrder:function(id){    
        $.ajax({   
            type: "POST",   
            url: "Ajax.aspx",   
            cache: false,   
            async: true,   
            datatype:"text",   
            data:{
                FunctionName:"CancelOrder",
                id:id  
            },   
            success: function(msg){
                window.location.href=window.location.href;
            }
        });
    },
    AlreadyPaid:function(id){
        $.ajax({   
            type: "POST",   
            url: "Ajax.aspx",   
            cache: false,   
            async: true,   
            datatype:"text",   
            data:{
                FunctionName:"AlreadyPaid",
                id:id  
            },   
            success: function(msg){        
                window.location.href=window.location.href;
            }
        });
    },
    GoodsReceived:function(id){
        $.ajax({   
            type: "POST",   
            url: "Ajax.aspx",   
            cache: false,   
            async: true,   
            datatype:"text",   
            data:{
                FunctionName:"GoodsReceived",
                id:id  
            },   
            success: function(msg){        
                window.location.href=window.location.href;
            }
        });
    },
    DeliveryChange:function(id){
        $.ajax({   
            type: "POST",   
            url: "Ajax.aspx",   
            cache: false,   
            async: true,   
            datatype:"text",   
            data:{
                FunctionName:"DeliveryChange",
                id:id  
            },   
            success: function(msg){    
                 $("#span_extraamount").html(msg);
                 $("#span_extraamountc").html(msg);
                 $("#span_total").html(Math.round(parseFloat($("#span_price").html())*100)/100+(Math.round(parseFloat(msg))));    
            }
        });
    },
    //改变图片
    ChangeImg:function(id,url){
        $("[id$='show_pic_link']").attr("href","ShowPic.aspx?type=2&id="+id);
        $("[id$='show_pic']").attr("src",url);
    },
    //显示Div
    ShowDiv:function(control){
        $("#light").html($("#light_"+control).html());
        $("#light").attr("style","display:block");
        $("#fade").attr("style","display:block");
        var browser=navigator.appName;
        var b_version=navigator.appVersion;
        var version=b_version.split(";");
        var trim_Version=version[1].replace(/[ ]/g,"");
        if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0"){
            $("#light").attr("style","display:block;position:absolute;");
            Public.goTop();
        }
    },
    //隐藏Div
    HideDiv:function(){
        $("#light").attr("style","display:hidden");
        $("#fade").attr("style","display:hidden");
        $("#light").hide();
    },    
    //改变图片
    ChangePic:function(src){
        $("#img_Pic").attr("src",src);
    },
    //提交留言
    LiuYan:function(){
        var Asker=$("#txt_Asker").val().replace(/ /g,"");
        var Phone=$("#txt_Phone").val().replace(/ /g,"");
        var Sex=1;
        if($("#rbl_Sex_0").attr("checked")){
             Sex=0;
        }
        var AskTitle=$("#txt_AskTitle").val().replace(/ /g,"");
        var AskContent=$("#txt_AskContent").val().replace(/ /g,"");
        if(Asker==""||Asker==null)
        {
            alert("您的姓名不能为空。");
            $("#txt_Asker").focus();
            return;            
        }
        if(Phone==""||Phone==null)
        {
            alert("您的联系方式不能为空。");
            $("#txt_Phone").focus();
            return;            
        }
        if(AskTitle==""||AskTitle==null)
        {
            alert("下单主题不能为空。");
            $("#txt_AskTitle").focus();
            return;            
        }
        if(AskContent==""||AskContent==null)
        {
            alert("下单内容不能为空。");
            $("#txt_AskContent").focus();
            return;            
        }
        $.ajax({   
            type: "POST",   
            url: "Ajax.aspx",   
            cache: false,   
            async: true,   
            datatype:"text",   
            data:{
                FunctionName:"LiuYanSubmit",
                Asker :Asker,
                Sex:Sex,
                AskTitle:AskTitle,
                AskContent:AskContent,
                Phone:Phone    
            },   
            success: function(msg){
                if(msg.indexOf("Success")!=-1){
                    alert("提交成功！请等待管理员回复……");
                    Main.HideDiv()
                    return;
                }                
                alert(msg);
            }
        });
    },
    Yuyue:function(doctorName){        
        Main.ShowDiv('2');
        $("#txt_DoctorName").val(doctorName);    
    },
    YuyueSubmit:function(){
        var DoctorName=$("#txt_DoctorName").val().replace(/ /g,"");
        var ReservationTime=$("#txt_ReservationTime").val();
        var CustomerName=$("#txt_CustomerName").val().replace(/ /g,"");
        var CustomerAge=$("#txt_CustomerAge").val().replace(/ /g,"");
        var CustomerSex=1;
        if($("#rbl_CustomerSex_0").attr("checked")){
             CustomerSex=0;
        }
        var CustomerPhone=$("#txt_CustomerPhone").val().replace(/ /g,"");
        var CustomerAddress=$("#txt_CustomerAddress").val().replace(/ /g,"");
        if(ReservationTime==""||ReservationTime==null)
        {
            alert("预约时间不能为空。");
            $("#txt_ReservationTime").focus();
            return;            
        }
        if(CustomerName==""||CustomerName==null)
        {
            alert("您的名字不能为空。");
            $("#txt_CustomerName").focus();
            return;            
        }        
        if(CustomerAge==""||CustomerAge==null)
        {
            alert("您的年龄不能为空。");
            $("#txt_CustomerAge").focus();
            return;            
        }
        if(CustomerPhone==""||CustomerPhone==null)
        {
            alert("您的电话不能为空。");
            $("#txt_CustomerPhone").focus();
            return;            
        }
        if(CustomerAddress==""||CustomerAddress==null)
        {
            alert("您的地址不能为空。");
            $("#txt_CustomerAddress").focus();
            return;            
        }
        $.ajax({   
            type: "POST",   
            url: "Ajax.aspx",   
            cache: false,   
            async: true,   
            datatype:"text",   
            data:{
                FunctionName:"Yuyue",
                DoctorName :DoctorName,
                ReservationTime:ReservationTime,
                CustomerName:CustomerName,
                CustomerSex:CustomerSex,
                CustomerAge:CustomerAge,
                CustomerPhone:CustomerPhone,
                CustomerAddress:CustomerAddress      
            },   
            success: function(msg){
                if(msg.indexOf("Success")!=-1){
                    alert("提交成功！我们会尽快回复您，请耐心等待……");
                    Main.HideDiv()
                    return;
                }                
                alert("提交失败！请直接QQ联系或电话联系……");
            }
        });
    },
    Showkefu:function(){
        $("#kefu_show").attr("style","visibility:visible;");
        $("#kefu_btn").attr("style","visibility:hidden");
        var menuYloc = $("#kefu_show").offset().top;  
        var offsetTop = menuYloc + $(window).scrollTop() +"px";  
        $("#kefu_show").css("top",offsetTop);
    },
    Hidekefu:function(){
        $("#kefu_btn").attr("style","visibility:visible;");
        $("#kefu_show").attr("style","visibility:hidden");
        var menuYloc = $("#kefu_btn").offset().top;  
        var offsetTop = menuYloc + $(window).scrollTop() +"px";  
        $("#kefu_btn").css("top",offsetTop);
    }
}



