﻿ $(function(){
 
    $(".txtIntr img").LoadImage(true,600,600);

        $.ajax({
            type: "post",
            url: "/ashx/clicknum.ashx",
            data: "namedb=1",datatype: "json",
            success: function(msg) {//请求成功
                $('#clicknum').html(msg);
            },
            error: function(s) {//请求出错
                alert('出错啦....');
            }
        });
 $(".chkBtn").click(function(){
        if($('#name_reg').val()==''){alert('请填写用户名！');return;}
        $.ajax({
            type: "post",
            url: "/ashx/isnull.ashx",
            data: "namedb=" + $('#name_reg').val(),datatype: "json",
            success: function(msg) {//请求成功
                switch (msg) {
                   case '1':
                        alert('此用户名可以注册');
                   break; 
                   case '2':
                        alert('此用户名已被注册');
                   break;  
                }
            },
            error: function(s) {//请求出错
                alert('出错啦....');
            }
        }); 
 })
 $("#regurl").click(function(){location='userlogin.aspx';})
 
 
     $("#firlogin").click(function(){
        $.ajax({
            type: "post",
            url: "/ashx/firlogin.ashx",
            data: "namedb=" + $('#firname').val() + "&pwddb=" + $('#firpwd').val() + "&checkcode=" + $('#checkcode').val(),datatype: "json",
            success: function(msg) {//请求成功
                switch (msg) {
                   case '1':
                        alert('用户名或密码不正确或此用户已禁止登录！');
                   break; 
                   case '2':
                        location='userinfo.aspx';
                   break;  
                }
            },
            error: function(s) {//请求出错
                alert('出错啦....');
            }
        });  
    }) 
    $("#login").click(function(){
        $.ajax({
            type: "post",
            url: "/ashx/login.ashx",
            data: "namedb=" + $('#name').val() + "&pwddb=" + $('#pwd').val() + "&checkcode=" + $('#checkcode').val(),datatype: "json",
            success: function(msg) {//请求成功
                switch (msg) {
                   case '0':
                        alert('验证码出错！');
                   break;
                   case '1':
                        alert('用户名或密码不正确或此用户已禁止登录');
                   break; 
                   case '2':
                        location='userinfo.aspx';
                   break;  
                }
            },
            error: function(s) {//请求出错
                alert('出错啦....');
            }
        });  
    }) 
    
    $("#reg").click(function(){
        var name_reg = $('#name_reg').val();
        var checkcode_reg = $('#checkcode_reg').val();
        var pwd = $('#pwd_reg').val();
        var pwd2 = $('#pwd2_reg').val();
        if(pwd != pwd2){
            alert('两次密码不一致，请重新输入！');
            return;
        }else{
            $.ajax({
                type: "post",
                url: "/ashx/reg.ashx",
                data: "name_reg=" + name_reg + "&pwd_reg=" + pwd + "&checkcode_reg=" + checkcode_reg,datatype: "json",
                success: function(msg) {//请求成功
                    switch (msg) {
                       case '0':
                            alert('验证码出错！');
                       break;
                       case '1':
                            alert('用户名或密码不正确！');
                       break; 
                       case '2':
                            alert('此用户名已存在，请重新输入！');
                       break;  
                       case '3':
                            alert('恭喜您，注册成功！');
                            location='userinfo.aspx';
                       break;                   
                    }
                },
                error: function(s) {//请求出错
                    alert('出错啦....');
                }
            }); 
        } 
    })    
    
    
//搜索
function SearchAsk(content)
{   
    location.href="/search.aspx?s="+escape(content);
}
    $("#searchtxt").keyup(function(event) { 
        if (event.keyCode == 13) { 
            if ($("#searchtxt").val() == '') { 
                alert('请输入你要搜索的内容！'); 
            } else { 
                SearchAsk($(this).val()); 
            } 
            return false; 
        } 
    })

    $('#searchtxt').click(function(){if($(this).val()=='升钟湖')$(this).val('');})   
        $('#clicksearch').click(function(){
        if($('#searchtxt').val()=='升钟湖' || $('#searchtxt').val()=='')
        {
            alert('请输入你要搜索的内容！'); 
            $('#searchtxt').val('');
        }else
        {
            SearchAsk($('#searchtxt').val());
        }
    }) 
    
     $("#Quit").click(function(){   
            $.ajax({
                type: "post",
                url: "/ashx/Quit.ashx",
                data: "",datatype: "json",
                success: function(msg) {//请求成功
                    if(msg=="1")
                    {
                         alert('您已成功退出！');
                           window.location.reload();
                    }
                },
                error: function(s) {//请求出错
                    alert('出错啦....');
                }
            });         
        })            
 })
 
 
 
 
jQuery.fn.LoadImage=function(scaling,width,height,loadpic){
    if(loadpic==null)loadpic="load3.gif";
    return this.each(function(){
    var t=$(this);
    var src=$(this).attr("src")
    var img=new Image();
    //alert("Loading")
    img.src=src;
    // 自动缩放图片
    var autoScaling=function(){
    if(scaling){
     
    if(img.width>0 && img.height>0){
    if(img.width/img.height>=width/height){
    if(img.width>width){
    t.width(width);
    t.height((img.height*width)/img.width);
    }else{
    t.width(img.width);
    t.height(img.height);
    }
    }
    else{
    if(img.height>height){
    t.height(height);
    t.width((img.width*height)/img.height);
    }else{
    t.width(img.width);
    t.height(img.height);
    }
    }
    }
    }
    }
    //处理ff下会自动读取缓存图片
    if(img.complete){
    //alert("getToCache!");
    autoScaling();
    return;
    }
    $(this).attr("src","");
    var loading=$("<img title='图片加载中' src='' alt='加载中' />");
     
    t.hide();
    t.after(loading);
    $(img).load(function(){
    autoScaling();
    loading.remove();
    t.attr("src",this.src);
    t.show();
    //alert("finally!")
    });
     
    });
}
